Page 1 of 1
"Hello" kernel
Posted: Wed Jun 19, 2002 11:00 pm
by Michael Morrison
Hello
In the OSDEV developer guide there is a small nugget of code that is supposed to display a "Hi" message to the screen. I took the following steps:
1) create kernel.asm file with the following code
[BITS 32]
mov byte [es:0xb8f9c],'H'
mov byte [es:0xb8f9e],'i'
retf
2) assemble kernel32.asm with the following line:
nasm -f aout -o kernel32.o kernel32.asm
3) link kernel32.asm with the following:
ld -Ttext 0x100000 --oformat binary -o kernel32.bin kernel32.o
4) Next I run the following command to copy kernel32.bin to the boot sector of a floppy disk..
dd if=kernel32.bin o=/dev/fd0 bs=512 count=1
5) Lastly, i reboot my system with floppy inserted. I get a bios generated message, but no "Hi" message is displayed.
I would like to know what i am doing wrong, how can i generate the greeting.
Thanks for your time
Michael Morrison
RE: Hello kernel
Posted: Thu Jun 20, 2002 11:00 pm
by carbonBased
If you're going to write something directly to the floppy, it must be 16-bit code (it'll be the boot sector) and flagged by 0xAA55 @ offest 510 into the sector.
The code you've used is 32-bit pmode code, and assumes ES has been set to a descriptor with base of 0x0 and presumably spans the full 4GB.
As was mentioned before, if you want to load in a 32-bit "kernel", you're going to have to use a boot-loader (such as GRUB). However, if you're using GRUB, you'll have to define data in your kernel to meet the multiboot standard (for one, you'll have to define your GDT with a valid descriptor for ES).
Jeff
RE: Hello Kernel - try this
Posted: Thu Jun 20, 2002 11:00 pm
by carbonBased
If you really want to just get some code in memory, you can write it to the boot sector. Keep in mind, however, that this code _must_ be 16-bit real mode code in order to be executed properly, and the boot sector must end with 0xAA55. Also, the PC will only load the first sector into memory, which means your code cannot exceed 512 bytes.
In other words, its one of the easiest way to get your code loaded, but it's very limited.
Try the following code (altered version of your previous code to work in real mode, as a boot sector):
[BITS 16]
; set the es register to point to video memory
mov ax, 0xb800
mov es, ax
' move letters H and i to video memory at offests f9c and f9e
mov byte [es:0x0f9c],'H'
mov byte [es:0x0f9e],'i'
' loop continuously so user can read result.
pause:
jmp pause
' ret will never be reached...
ret
; make sure the bios sees this sector as bootable
times 510-($-$$) db 0
dw 0xAA55
Now try assembling that and writting it to the boot sector of a floppy.
nasm -f bin file.asm -o file.bin
dd if=file.bin of=/dev/fd0 bs=512 size=1
Jeff
Thanks
Posted: Thu Jun 20, 2002 11:00 pm
by Michael Morrison
carbonBased,
Thanks for your help, i was very excited to get this working, i really, really appreciate your time and advice. I have read through you responses to other people as well, you give extremely clear and useful advice. If you ever decide to publish literature on this stuff i want to be the first to know.
Thank You
Michael Morrison
RE:Thanks
Posted: Thu Jun 20, 2002 11:00 pm
by carbonBased
Cheers!
Thank you! I appreciate the response, and I hope everything works out.
I do, actually, intend to write a few "articles" (whatever you wanna call them
in time, and in a few days (once the paycheque clears
I intend to setup a web site about programming (specifically language and OS development, and Linux/X11 graphics/3d programming).
I did, actually, write some articles a few years back under the 'guise of code^x software, but many need to be updated, and will also appear of my web site (I'll let everyone on this list know once I've secured a domain name, and all's well).
Anyway, thanks again,
Jeff