在16位模式下使用GDB [英] Using GDB in 16-bit mode

查看:645
本文介绍了在16位模式下使用GDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,其中我想实现一个使用BIOS功能,打印字符串的函数:

I have the following code, where I am trying to implement a function that prints string using the BIOS functions:

int printString(char* string)
{
 int i = 0;
 while (*(string + i) != '\0')
   {
    char al = *(string + i);
    char ah = 0xe;
    int ax = ah * 256 + al;
    interrupt(0x10,ax,0,0,0);
    i++;
   }
 return i;
}

功能中断组装实现的。它调用相应的BIOS中断,由第一个参数给出,用含有分别AX,BX,CX和DX寄存器内容的其余参数:

The function interrupt is implemented in assembly. It calls the appropriate BIOS interrupt, as given by the first argument, with rest of the arguments containing the contents for ax,bx,cx and dx register respectively:

.global _interrupt
_interrupt:
push bp
mov bp, sp
push si
push ds
mov ax, #0x100
mov ds, ax
mov ax, [bp + 0x4]
mov si, #intr
mov [si + 1], al
pop ds
mov ax, [bp + 0x6]
mov bx, [bp + 0x8]
mov cx, [bp + 0xa]
mov dx, [bp + 0xc]
intr: int #0x0
pop si
pop bp
ret

由于我使用的BIOS中断我使用16位模式编译此code。我用下面的命令:

Since I am using BIOS interrupts I am using 16-bit mode to compile this code. I used the following command:

bcc -ansi -c -o printString.o printString.c

我要测试在此GDB code,但是当我尝试使用这个printString.o文件加载到GDB:

I want to test this code in GDB, but when I try to load this printString.o file into gdb using:

gdb printString.o

我收到以下错误:

I get the following error:

/家/克恩/ printString.o:不是可执行格式:文件格式无法识别。

"/home/kern/printString.o": not in executable format: File format not recognized

我也尝试过使用改变了GDB到16位格式:

I also tried changing the GDB to 16-bit format using:

set architecture i8086

不过还是这个错误即将到来。我怎样才能加载16位code到GDB?

But still this error is coming. How can I load a 16-bit code into GDB?

推荐答案

由于杰斯特说,在评论你不能运行 GDB 目标文件。

As Jester says in comments you cannot run object file with gdb.

和则不能运行16位可执行文件或16bit组装code与 GDB 。您必须像 QEMU 来运行$在仿真的CPU和c $ C连接到它使用 GDB ,也可以使用 DOSBox中 才能运行code和DOS的使用调试程序。记得使用BIOS中断是一个错误是现代操作系统如Linux,因为在启动这些操作系统禁用BIOS中断。

And you can not run 16bit executable file or 16bit assembly code with gdb. you must you something like qemu to run your code on emulated cpu and connect to it using gdb or you can use dosbox in order to run your code and use debug program on dos. and remember using BIOS interrupts is a error is modern OS like linux because at start up these operating systems disable BIOS interrupts.

这篇关于在16位模式下使用GDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆