BIOS视频服务中断调用
我正在尝试使用 BIOS 视频中断在屏幕上显示字符。 以下是汇编代码:
mov $0x0A, %AH
mov $0x68, %AL ; to display character 'h'
int $0x10
我使用 GNU 汇编器汇编了此代码,生成一个名为 example.o 的目标文件 Sample.o 的总大小为 449 字节。现在,我手动将十六进制数字 0x55 和 0xAA 写入该目标文件的第 511 和 512 字节位置,以使其可启动。所以我相信现在我有一个 512 字节的引导扇区。我使用 qemu 尝试从该目标文件启动:
$> qemu -fda sample.o
qemu 模拟器启动并在显示“从软盘启动...”时冻结。 但我认为在检测到引导扇区后,BIOS 视频中断代码应该运行并在屏幕上显示一个字符。
我知道我正在做一些非常错误的事情。也许我错过了中断的整个概念。任何人都可以帮忙。
编辑:所以我现在使用 as86 和 ld86 来生成平面二进制文件。我使用 0x0E 而不是 AH 中的 0x0A,看起来它成功了。似乎是 BIOS 实现问题。
我感谢所有回复的人。
谢谢
I'm trying to use the bios video interrupt to display a character on the screen.
The following is the assembly code:
mov $0x0A, %AH
mov $0x68, %AL ; to display character 'h'
int $0x10
I assembled this code using GNU assembler to produce an object file called sample.o
The total size of sample.o is 449 bytes. Now I manually write to this object file the hex digits 0x55 and 0xAA at 511th and 512th byte positions in order to make it bootable. So I believe now i have a 512 bytes boot sector. I use qemu to try to boot from this object file:
gt; qemu -fda sample.o
The qemu emulator starts and freezes at the point where it says "Booting from Floppy..."
But I thought after it detects the boot sector the bios video interrupt code was supposed to run and display a character on the screen.
I know i'm doing something horribly wrong. Maybe i'm missing the whole concept of interrupts. Can anyone help.
EDIT: so i'm now using as86 and ld86 to produce just the flat binary. And instead of 0x0A in AH i'm using 0x0E and it seems like it did the trick. Seems like bios implementation issue.
I appreciate all those who replied back.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
普通的
.o
文件除了生成的二进制代码之外还包含很多内容,因此您正在做的事情不起作用也就不足为奇了(结果应该约为 10 个字节左右) )。您可以为 ld 编写一个脚本,让它生成一个平面二进制文件(我似乎记得这应该是可能的,但还没有亲自尝试过)。如果我这样做,我可能会使用 nasm 代替,因为它可以很容易地生成原始二进制输出。另一种可能性是一些旧的 MS-DOS 汇编器可以生成
.com
格式输出(这也是原始二进制文件,但您必须小心,因为它加载有点不同)。A normal
.o
file contains quite a bit other than just the resulting binary code, so it's no surprise that what you're doing doesn't work (the result from this should be around 10 bytes or so).You can either write a script for ld to get it to produce a flat binary (I seem to recall that's supposed to be possible, but haven't tried it personally). If I were doing this, I'd probably use nasm instead, since it can produce raw binary output pretty easily. Another possibility would be some old MS-DOS assembler than can produce
.com
format output (which is also raw binary, though you have to be careful, since it loads a bit differently).您需要在 BL 中传递属性值(07h 是黑底灰),在 BH 中传递页码,在 CX 中传递计数。
你说你用gas编译它并给你一个448字节的文件?你是组装成ELF文件还是什么的?我推荐 nasm -f bin,使用 BITS 16 指令。
You need to pass the attribute value in BL (07h is gray on black), page number in BH and count in CX.
You say you compiled it with gas and it gave you a 448 byte file? Are you assembling into an ELF file or something? I'd recommend nasm -f bin, using the BITS 16 directive.
正如 Jerry Coffin 所说,问题在于您的
.o
文件不是具有正确引导扇区的软盘映像。.o
文件除了代码之外还包含许多信息,例如符号名称和重定位信息。如果您使用 NASM,请使用 -f bin 生成原始二进制文件。如果您使用 LD,则可以编写链接描述文件。
要获得此类帮助,最好的地方可能是 osdev.org 及其论坛。
As Jerry Coffin said, the problem is that your
.o
file is not a floppy image with a proper boot sector. The.o
file contains a lot of information besides the code such as symbol names and relocation info.If you are using NASM, use
-f bin
to produce a raw binary. If you are using LD, you can write a linker script.For help with this kind of stuff, the best place is probably osdev.org and its forum.