Jump to content

Minimal PMode Template

- - - - -

  • Please log in to reply
No replies to this topic

#1
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
This is just about the bare minimum for jumping to PMode. It doesn't set up A20, so your limited to 16MB, but its good if your trying to fit a program into a single sector.

[highlight=asm]
; I was bored, echo said to do something hardware related...

; Jump to PMODE
[BITS 16]
[ORG 0x7C00]

cli ; Disable interrupts; Cleanup registers
xor ax, ax ; zero AX
mov ds, ax ; DS is used by lgdt

lgdt [gdt_desc] ; Load the GDT
mov eax, cr0 ; Load the value of cr0 (control register) into eax (general purpose register)
or eax, 1 ; OR (|) the value of eax with 1
mov cr0, eax ; Load the value of eax into cr0
jmp 0x8:main ; Far jump (dirty value in cs)

[BITS 32]

main:
mov ax, 10h ; Store data segment (10h)
mov ds, ax ; Store valid segment in ds
mov ss, ax ; Store valid segment it ss
mov esp, 0x90000 ; Shove the stack at 0x90000

;; Make your program

jmp $
; GDT Must have 3 entries
;...Null...
gdt_null: dd 0
dd 0
;...Code segment...
gdt_code: dw 0x0FFFF ; limit low
dw 0 ; base low
db 0 ; base mid
db 10011010b ; access
db 11001111b ; granularity
db 0 ; base high
;...Data segment...
gdt_data: dw 0x0FFFF ; limit low
dw 0 ; base low
db 0 ; base mid
db 10010010b ; access
db 11001111b ; granularity
db 0 ; base high
gdt_end:

;...GDT Descripor
gdt_desc: dw gdt_end - gdt_null - 1; limit
dd gdt_null ; base

times 510-($-$$) db 0 ; Pad the file to 512 bytes
db 0x55 ; Boot signature
db 0xAA
[/highlight]

Grr, all the [ above should be [




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users