User:Johnburger/Demo/Boot/Entry

From OSDev Wiki
Jump to: navigation, search

On entry to my code, different BIOSes have different values for CS:IP. I want to use CS-relative addressing, so the very first thing I do is make sure that CS is where I want it!

Then I fix the Stack so that it is no longer clobbering the Real Mode IVT...

Memory Map

After this code, the Memory Map will look like this:

Address Usage
0000_0000h Interrupt Vector Table
0000_0400h BIOS Data Area
0000_0500h Available
0000_0600h Master Boot Record (MBR) *
0000_0800h Available
0000_7C00h SS:SP Stack Top
0000_7C00h BIOS-loaded Boot Sector
0000_7E00h Available
0009_F???h ** Extended BIOS Data Area
000A_0000h Adapter / ROM Area
000B_8000h Text Video Memory
000F_0000h BIOS ROM
0010_0000h High Memory ***

* The MBR only exists here if the PC has booted from a Hard Drive.
** An INT 12h will help identify this value.
*** Note that this memory is only accessible in Protected Mode - except for the first 64 kiB (less 16 bytes), which you can access with a Segment Register set to 0FFFFh as long as the A20 Gate is off. By the way: DON'T DO THIS!

Demo/Boot/Entry.inc

;
; Boot/Entry.inc
;
 
                ORG             0000h
 
; On Entry, different BIOSes have different values for CS:IP.
; I want to use CS-relative addressing, so make sure CS is where I want it!
Boot.Entry:
                JMP             (BIOS.Entry>>4) : .Start ; Go to known location
.Start:
                XOR             AX,AX           ; Initialise the stack
                MOV             SS,AX           ; The BIOS's place is ludicrous
                MOV             ESP,BIOS.Entry  ; So put ESP somewhere sane
; Note we can now use 32-bit addressing with [ESP] to access the stack
Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox