OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 10:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: "Hello" kernel
PostPosted: Wed Jun 19, 2002 11:00 pm 
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


Top
  
 
 Post subject: RE: Hello kernel
PostPosted: Thu Jun 20, 2002 11:00 pm 
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


Top
  
 
 Post subject: RE: Hello Kernel - try this
PostPosted: Thu Jun 20, 2002 11:00 pm 
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


Top
  
 
 Post subject: Thanks
PostPosted: Thu Jun 20, 2002 11:00 pm 
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


Top
  
 
 Post subject: RE:Thanks
PostPosted: Thu Jun 20, 2002 11:00 pm 
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


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group