# i386 architecture

Prerequisites: arch

The i386 kernel source code is xcomp/i386/kernel.fs. Register roles:

PSP: ESI
RSP: ESP
PSP Top: EAX
A register: EBX
S register: EDX

All other registers are free.

## Memory layout

PS lives at the end of x86 conventional memory, that is $80000.

RS lives at $f800. It needs to live below the $10000 line so that we don't have
to save/restore ESP when doing the int13h call in real mode. If we have it live
over this line, the 64K wrap-up makes int13h push to unexpected places in
memory.

The bootloader is loaded at $7c00 but moves itself right away to $fc00 so that
it leaves some breathing space for its payload. It then begins loading the
payload at $500. Then, we jump to the kernel which makes "here" start at $10000.
From there, the boot code begins interpreting itself.

The bootloader contains the Global Descriptor Table (GDT) at $fd80.

$f800-f9ff is used by the int13h driver as a sector buffer.

During higher level initialization, we're expected to deal with the A20 gate,
stop needing int13h, and then make "here" jump to its final playground, that is
$100000 and above.
