views:

36

answers:

3

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:

$> 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

A: 

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.

ninjalj
+2  A: 

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).

Jerry Coffin
ok.. now i'm using as86 and ld86 tools from the bin86. after assembling with the as86 if I use the ld86 with a -d option it produces the flat binary file which is just 8 bytes.. So again i manually write to the 511th and 512th byte with 0x55 and 0xAA. qemu still freezes at the "Booting from Floppy..."
Raja
now its working.. i changed ah to 0x0e
Raja
A: 

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.

Zifre