mirror of https://github.com/E-Almqvist/eOS
commit
ff653f1ec9
@ -1,2 +1,37 @@ |
||||
; Utils |
||||
%include "equ/vga.asm" |
||||
%include "pm/vga/print.asm" |
||||
|
||||
; GDT & switching to PM |
||||
%include "pm/gdt.asm" ; GDT defined here |
||||
|
||||
; Switching to PM |
||||
[bits 16] |
||||
pm_preinit: |
||||
cli ; Switch interupts |
||||
|
||||
lgdt [gdt_descriptor] ; Tell the CPU about the GDT |
||||
|
||||
mov eax, cr0 ; Set first bit of the CR0 register |
||||
or eax, 0x1 ; to 1 |
||||
mov cr0, eax ; Update the control register |
||||
|
||||
; Initialize PM |
||||
jmp GDT_CODE_SEG:pm_init |
||||
|
||||
[bits 32] |
||||
; Init registers & stack when in PM |
||||
pm_init: |
||||
mov ax, GDT_DATA_SEG ; Point the segment registers to GDT_DATA_SEG |
||||
; Segment registers |
||||
mov ds, ax |
||||
mov ss, ax |
||||
mov es, ax |
||||
mov fs, ax |
||||
mov gs, ax |
||||
|
||||
mov ebp, 0x900000 ; Update the stack pointer |
||||
mov esp, ebp |
||||
|
||||
call BEGIN_PM |
||||
|
||||
|
@ -0,0 +1,43 @@ |
||||
; GDT |
||||
|
||||
gdt_start: |
||||
|
||||
gdt_null: ; NULL descriptor |
||||
dd 0x0 ; 4-bytes of |
||||
dd 0x0 ; 0x0 (0) = NULL |
||||
|
||||
gdt_code: ; Code SD |
||||
; Range: 0x0 - 0xfffff |
||||
; Flags1: 1001b (present:2 privilege:descriptor type) |
||||
; Type: 1010b (code:conforming:readable:accessed) |
||||
; Flags2: 1100b (granularity:32bit default:64bit seg:AVL) |
||||
|
||||
dw 0xffff ; Limit (bits 0-15) |
||||
dw 0x0 ; Base (bits 0-15) |
||||
db 0x0 ; Base (bits 16-23) |
||||
db 10011010b ; Flags1 : Type |
||||
db 11001111b ; Flags2 : Limit (16-19) |
||||
db 0x0 ; Base (bits 24-31) |
||||
|
||||
gdt_data: ; Data SD |
||||
; Same flags as gdt_code but different type flags |
||||
; Type: 0010b (code:expand dowm:writable:accessed) |
||||
|
||||
dw 0xffff ; Limit (bits 0-15) |
||||
dw 0x0 ; Base (bits 0-15) |
||||
db 0x0 ; Base (bits 16-23) |
||||
db 10010010b ; Flags1 : Type |
||||
db 11001111b ; Flags2 : Limit (16-19) |
||||
db 0x0 ; Base (bits 24-31) |
||||
|
||||
gdt_end: ; Mark the end so we can get the delta-memory (size of GDT) |
||||
|
||||
; GDT descriptor |
||||
gdt_descriptor: |
||||
dw gdt_end - gdt_start - 1 ; Size of GDT is always -1 of actual size (WHY?!?!?!?!??!) |
||||
dd gdt_start ; Pointer to the GDT |
||||
|
||||
|
||||
; Lazy constants |
||||
GDT_CODE_SEG equ gdt_code - gdt_start |
||||
GDT_DATA_SEG equ gdt_data - gdt_start |
Loading…
Reference in new issue