Switching to real mode

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
chorakm
Posts: 14
Joined: Fri Dec 08, 2006 12:07 am

Switching to real mode

Post 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
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post 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
chorakm
Posts: 14
Joined: Fri Dec 08, 2006 12:07 am

Post by chorakm »

Otter, I must say that is a pretty clever idea. That may just do the trick. Thanks!
Post Reply