[Prev][Next][Index][Thread]

Re: switching to real mode



Rob Savoye wrote:
> 
>   I need to switch to real mode, to execute some boot code for non Linux/FreeBSD
> systems. In digging around through OSKit, I see there is some support for
> this, but it's undocumented, and I get errors when I try to call any
> of the functions like i16_raw_switch_to_real_mode or i16_leave_pmode.

Note that if you already are in protected mode, then don't even think of
calling the i16_* functions.  They are meant to be used while still in
16 bit real mode (though you still need a x86 with x>=3).  But once you're
in real mode, these functions are the only ones you can use.

Getting back to real mode is rather simple (at least in theory).  There is
a macro do_16bit() in oskit/x86/i16.h which does that.  An example for its
use is in kern/x86/pc/i16/raw_real_int.c.  This is used in the oskit boot
loaders to call 16 bit software interrupts (like BIOS functions).  If you
never want to return to protected mode again, then you can use the other
macros in oskit/x86/i16.h: switch_to_16bit() and CODE32.  But the approx.
10 bytes of unused code in the first case hardly pay for the hassles of the
latter - see the comments in oskit/x86/i16.h.

Now a few words about the "at least in theory" above: all of the switching
code assumes that EIP < 65536 and ESP < 65536.  This basically means that
you are restricted to 64K.  This is not entirely true, as only the stack,
the switching code and all the 16 bit code needs to be below that line.
This can be achieved  by using the right order of object files when linking.

HTH

Klaus

Follow-Ups: References: