-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.asm
83 lines (67 loc) · 1.48 KB
/
boot.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
ORG 0x7c00
BITS 16
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start
_start:
jmp short start
nop
times 33 db 0
start:
jmp 0:step2
step2:
cli ; clear interrupts
mov ax, 0x00
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
sti ; enables interrupts
.load_protected:
cli
lgdt[gdt_descriptor]
mov eax, cr0
or eax, 0x1
mov cr0, eax
jmp CODE_SEG:load32
;GDT
gdt_start:
gdt_start:
dd 0x0
dd 0x0
; offset 0x0
gdt_code: ; cs should point to this
dw 0xffff ; segment limit first 0-15 bits
dw 0 ; base 0 to 15 bits
db 0 ; base 16 to 23 bits
db 0x9a ; access byte
db 11001111b ; high 4 bit flags and low 4 bit flags
db 0 ; base 24 to 31 bits
; offset 0x10
gdt_data: ; DS, SS, ES, FS, GS
dw 0xffff ; segment limit first 0-15 bits
dw 0 ; base 0 to 15 bits
db 0 ; base 16 to 23 bits
db 0x92 ; access byte
db 11001111b ; high 4 bit flags and low 4 bit flags
db 0 ; base 24 to 31 bits
gdt_end:
gdt_descriptor:
dw gdt_end - gdt_start-1
dd gdt_start
[BITS 32]
load32:
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ebp, 0x00200000
mov esp, ebp
; Enable a20 line
in al, 0x92
or al, 2
out 0x92, al
jmp $
times 510-($ - $$) db 0
dw 0xAA55