📄 nucloada.lst
字号:
1 [BITS 16]
2
3 [GLOBAL _ReadCHS]
4 [GLOBAL _CopyToExt]
5 [GLOBAL _EnterKernel]
6 [GLOBAL _enable_A20]
7 [GLOBAL _disable_A20]
8 [GLOBAL _detect_A20_type]
9
10 [EXTERN _PrintString]
11
12 ; - Compile switches begin -------------
13 %define USE_REAL_DELAY 1
14 %define USE_MSG_DELAY 0
15 ; - Compile switches end ---------------
16
17 [SECTION .data]
18
19 ; Function pointers initialized by A20 detection code
20 times ($$-$) & 3 nop
21 00000000 00000000 _ena_A20_vec dd 0
22 00000004 00000000 _dis_A20_vec dd 0
23
24 ; This is the *real* GDT that gets loaded before jumping to kernel
25 [GLOBAL gdtr]
26 times ($$-$) & 3 nop
27 00000008 0000 dw 0
28 gdtr:
29 0000000A 2700 dw gdt_end-gdt-1 ; Limit
30 0000000C [10000000] dd gdt ; Linear address
31
32 times ($$-$) & 7 nop
33 gdt:
34 00000010 00000000 dd 0
35 00000014 00000000 dd 0
36
37 code4g_gdt: ; Code descriptor: 4 GB
38 00000018 FFFF dw 0xFFFF ; Limit = 4 GB
39 0000001A 0000 dw 0x0000 ; Base 0-15
40 0000001C 00 db 0x00 ; Base 16-23
41 0000001D 9A db 0x9A ; Code
42 0000001E CF db 0xCF ; Page granularity
43 0000001F 00 db 0x00 ; Base 24-31
44
45 data4g_gdt: ; Data descriptor: 4 GB
46 00000020 FFFF dw 0xFFFF ; Limit = 4 GB
47 00000022 0000 dw 0x0000 ; base Bits 0-15
48 00000024 00 db 0x00 ; base Bits 16-23
49 00000025 93 db 0x93 ; Data segment
50 00000026 CF db 0xCF ; Page granularity
51 00000027 00 db 0x00 ; base Bits 24-31
52
53 code64k_gdt:
54 00000028 FFFF dw 0xFFFF ; Limit = 64 KB
55 0000002A 0000 dw 0x0000 ; Base 0-15
56 0000002C 00 db 0x00 ; Base 16-23
57 0000002D 9A db 0x9A ; Code
58 0000002E 00 db 0x00 ; Byte granularity
59 0000002F 00 db 0x00 ; Base 24-31
60
61 data64k_gdt:
62 00000030 FFFF dw 0xFFFF ; Limit = 64 KB
63 00000032 0000 dw 0x0000 ; base Bits 0-15
64 00000034 00 db 0x00 ; base Bits 16-23
65 00000035 93 db 0x93 ; Data segment
66 00000036 00 db 0x00 ; Byte granularity
67 00000037 00 db 0x00 ; base Bits 24-31
68
69 gdt_end:
70
71 [SECTION .text]
72
73 ; ------------------
74 %macro safemsg 1+
75 %if 1
76 jmp %%overtext
77 %%msg: db 10,%1,10,0
78 %%overtext:
79 pushad
80 o32 push es
81 mov ax,0xb800
82 mov es,ax
83 mov esi,%%msg
84 xor di,di
85 %%another:
86 lodsb
87 cmp al,0
88 jz %%done
89 stosb
90 mov al,7
91 stosb
92 jmp %%another
93 %%done:
94
95 mov ax,0x0800
96 %%another2:
97 stosw
98 cmp di,80*2
99 jb %%another2
100
101 %if USE_MSG_DELAY
102 mov ecx,200000000
103 %else
104 mov ecx,1
105 %endif
106
107 %%spin:
108 dec ecx
109 jnz %%spin
110
111 o32 pop es
112 popad
113 %endif
114 %endmacro
115
116 ; ------------------
117 %macro safemsg_pm 1+
118 %if 1
119 jmp %%overtext
120 %%msg db 10,%1,10,0
121 %%overtext:
122 pushad
123 mov esi,%%msg
124 mov edi,0xB8000
125 %%another:
126 lodsb
127 cmp al,0
128 jz %%done
129 stosb
130 mov al,7
131 stosb
132 jmp %%another
133 %%done:
134
135 mov ax,0x0800
136 %%another2:
137 stosw
138 cmp edi,0xB8000 + 80*2
139 jb %%another2
140
141 %if USE_MSG_DELAY
142 mov ecx,200000000
143 %else
144 mov ecx,1
145 %endif
146
147 %%spin:
148 dec ecx
149 jnz %%spin
150
151 popad
152 %endif
153 %endmacro
154
155 ; ------------------
156 ; // Returns true on success
157 ; STATIC word ReadCHS(void *dest, dword drv, dword c, dword h, dword s)
158 _ReadCHS:
159 00000000 6655 push ebp
160 00000002 6689E5 mov ebp,esp
161 00000005 6683EC04 sub esp,4
162 00000009 6653 push ebx
163 0000000B 6656 push esi
164 0000000D 6657 push edi
165
166 ; 5 retries
167 0000000F C746FC0500 mov word [bp-4],5
168
169 .retry:
170 00000014 8B5E08 mov bx,[bp+8] ; mem
171 00000017 8A560C mov dl,[bp+12] ; drive
172 0000001A 8A6E10 mov ch,[bp+16] ; cylinder
173 0000001D 8A7614 mov dh,[bp+20] ; head
174 00000020 8A4E18 mov cl,[bp+24] ; sector
175 00000023 B80102 mov ax,0x0201 ; read sector
176 00000026 CD13 int 0x13 ; Disk BIOS
177 00000028 7306 jnc .ok
178 0000002A FF4EFC dec word [bp-4] ; Retry counter
179 0000002D 75E5 jnz .retry
180 0000002F F9 stc
181 .ok:
182 00000030 0F93C0 setnc al
183 00000033 660FB6C0 movzx eax,al
184
185 00000037 665F pop edi
186 00000039 665E pop esi
187 0000003B 665B pop ebx
188 0000003D 66C9 o32 leave
189 0000003F 66C3 o32 ret
190
191 ; ------------------
192 _CopyToExt:
193 00000041 6655 push ebp
194 00000043 6689E5 mov ebp,esp
195
196 00000046 6653 push ebx
197 00000048 6656 push esi
198 0000004A 6657 push edi
199 0000004C 6655 push ebp
200
201 0000004E 66E8C2010000 call dword _enable_A20
202
203 00000054 66B8[0A000000] mov eax,gdtr
204 0000005A 670F0110 lgdt [eax]
205
206 0000005E 0F20C0 mov eax,cr0
207 ; Enable native FPU exception handling and enable protected mode
208 00000061 6683C821 or eax,0x00000021
209 00000065 0F22C0 mov cr0,eax
210
211 00000068 EB01 jmp .clear_pfq
212 0000006A 90 nop
213 .clear_pfq:
214
215 0000006B 668B7608 mov esi,[bp+8]
216 0000006F 668B7E0C mov edi,[bp+12]
217 00000073 668B4E10 mov ecx,[bp+16]
218
219 00000077 66EA[80000000]0800 jmp dword 0x0008:.pmode
220 ; push dword 8
221 ; push dword .pmode
222 ;o32 retf
223
224 0000007F 90 nop
225 .pmode:
226 [BITS 32]
227 ; Protected mode
228
229 00000080 B810000000 mov eax,0x10
230 00000085 8ED8 mov ds,ax
231 00000087 8EC0 mov es,ax
232 00000089 8ED0 mov ss,ax
233
234 safemsg_pm "In protected mode"
235 <1> %if 1
236 0000008B EB14 <1> jmp %%overtext
237 0000008D 0A496E2070726F7465- <1> %%msg db 10,%1,10,0
238 00000096 63746564206D6F6465- <1>
239 0000009F 0A00 <1>
240 <1> %%overtext:
241 000000A1 60 <1> pushad
242 000000A2 BE[8D000000] <1> mov esi,%%msg
243 000000A7 BF00800B00 <1> mov edi,0xB8000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -