如何在16位模式下使用GDB? [英] How to use GDB in 16-bit mode?

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

问题描述

我有下面的代码,我试图实现一个使用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位模式编译此代码。我使用了下面的命令:

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中测试这段代码,但是当我尝试使用以下方法将此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:

/ home / kern / 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位代码加载到GDB中?

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

推荐答案

你不能用 gdb 运行16位可执行文件或16位汇编代码。你必须像 qemu 这样的东西来运行你的代码在仿真的CPU上并使用 gdb 连接到它,或者您可以使用 dosbox ,以便在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天全站免登陆