Skip to content

Commit 9ca6de1

Browse files
committed
Perform more work in boot.s
1 parent 37ff520 commit 9ca6de1

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

real_mode/src/boot.s

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,88 @@ _start:
2222
# initialize stack
2323
mov sp, 0x7c00
2424

25+
enable_a20:
26+
# enable A20-Line via IO-Port 92, might not work on all motherboards
27+
in al, 0x92
28+
test al, 2
29+
jnz enable_a20_after
30+
or al, 2
31+
and al, 0xFE
32+
out 0x92, al
33+
enable_a20_after:
34+
35+
enter_protected_mode:
36+
# clear interrupts
37+
cli
38+
push ds
39+
push es
40+
41+
lgdt [gdt32info]
42+
43+
mov eax, cr0
44+
or al, 1 # set protected mode bit
45+
mov cr0, eax
46+
47+
jmp protected_mode # tell 386/486 to not crash
48+
49+
protected_mode:
50+
mov bx, 0x10
51+
mov ds, bx # set data segment
52+
mov es, bx # set extra segment
53+
54+
and al, 0xfe # clear protected mode bit
55+
mov cr0, eax
56+
57+
unreal_mode:
58+
pop es # get back old extra segment
59+
pop ds # get back old data segment
60+
sti
61+
62+
# back to real mode, but internal data segment register is still loaded
63+
# with gdt segment -> we can access the full 4GiB of memory
64+
65+
mov bx, 0x0f01 # attrib/char of smiley
66+
mov eax, 0xb8f00 # note 32 bit offset
67+
mov word ptr ds:[eax], bx
68+
69+
check_int13h_extensions:
70+
mov ah, 0x41
71+
mov bx, 0x55aa
72+
# dl contains drive number
73+
int 0x13
74+
jc no_int13h_extensions
75+
76+
rust:
77+
push dx # pass disk number as argument
2578
call rust_main
2679

2780
spin:
2881
hlt
2982
jmp spin
83+
84+
gdt32info:
85+
.word gdt32_end - gdt32 - 1 # last byte in table
86+
.word gdt32 # start of table
87+
88+
gdt32:
89+
# entry 0 is always unused
90+
.quad 0
91+
codedesc:
92+
.byte 0xff
93+
.byte 0xff
94+
.byte 0
95+
.byte 0
96+
.byte 0
97+
.byte 0x9a
98+
.byte 0xcf
99+
.byte 0
100+
datadesc:
101+
.byte 0xff
102+
.byte 0xff
103+
.byte 0
104+
.byte 0
105+
.byte 0
106+
.byte 0x92
107+
.byte 0xcf
108+
.byte 0
109+
gdt32_end:

0 commit comments

Comments
 (0)