Page 1 of 1

Switching to real mode

Posted: Thu Jan 25, 2007 10:29 pm
by chorakm
This question is not about how to switch to real mode, per se. The process involves jumping to code that is below the 64K mark, or FFFF. I wrote a little routine to copy all the bytes from a routine inside the kernel into a location below the 64k mark but this isn't very satisfactory. I am using nasm as my compiler, and Grub as the boot loader. Is there a good way of getting code below the 64k mark? I would prefer not to use modules, and of course the code needs to be 16 bit. Copying the bytes of the routine to low memory worked, but when I switched instructions to 16 bit and tried to do a far jump to set CS to a proper 16 bit segment, I got an error from nasm similar, can't align .text section to 16 bit, I'm sorry I can't remember the exact error. Any insight would be appreciated. Thanks

Posted: Fri Jan 26, 2007 11:45 am
by Otter
You could use the following steps:
1) Write your 16-bit kernel, don't worry about grub. Lets say your kernel will be assembled to kernel.bin
2) Write a ressource file containg your kernel.bin, for example

Code: Select all

global kernel_start,kernelEnd

kernel_start:
%incbin "kernel.bin"
kernel_end:
3) Write a simple 32-bit programm that has this ressource file linked in and copies the data between kernel_start and kernel_end to the correct position. After that, you could switch to real mode and jump to your 16-bit kernel.

If you have created a good makefile and your 32-bit-loader you can work with your 16-bit kernel without even thinking about 32-bit stuff

Posted: Fri Jan 26, 2007 11:31 pm
by chorakm
Otter, I must say that is a pretty clever idea. That may just do the trick. Thanks!