]>
Commit | Line | Data |
---|---|---|
c69dd9df | 1 | ;------------------------------------------------------------------------------\r |
2 | ;*\r | |
3 | ;* Copyright 2006, Intel Corporation \r | |
4 | ;* All rights reserved. This program and the accompanying materials \r | |
5 | ;* are licensed and made available under the terms and conditions of the BSD License \r | |
6 | ;* which accompanies this distribution. The full text of the license may be found at \r | |
7 | ;* http://opensource.org/licenses/bsd-license.php \r | |
8 | ;* \r | |
9 | ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | ;* \r | |
12 | ;* efi64.asm\r | |
13 | ;* \r | |
14 | ;* Abstract:\r | |
15 | ;*\r | |
16 | ;------------------------------------------------------------------------------\r | |
17 | \r | |
18 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r | |
19 | ; Now in 64-bit long mode.\r | |
20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r | |
21 | \r | |
22 | .486\r | |
23 | .model flat \r | |
24 | .stack\r | |
25 | .code\r | |
26 | org 21000h\r | |
27 | \r | |
28 | DEFAULT_HANDLER_SIZE EQU INT1 - INT0\r | |
29 | \r | |
30 | JmpCommonIdtEntry macro\r | |
31 | ; jmp commonIdtEntry - this must be hand coded to keep the assembler from\r | |
32 | ; using a 8 bit reletive jump when the entries are\r | |
33 | ; within 255 bytes of the common entry. This must\r | |
34 | ; be done to maintain the consistency of the size\r | |
35 | ; of entry points...\r | |
36 | db 0e9h ; jmp 16 bit reletive \r | |
37 | dd commonIdtEntry - $ - 4 ; offset to jump to\r | |
38 | endm \r | |
39 | \r | |
40 | \r | |
41 | Start: \r | |
42 | \r | |
43 | mov esp,0001fffe8h ; make final stack aligned\r | |
44 | \r | |
45 | ; set OSFXSR and OSXMMEXCPT because some code will use XMM register\r | |
46 | db 0fh\r | |
47 | db 20h\r | |
48 | db 0e0h\r | |
49 | ; mov rax, cr4\r | |
50 | bts eax, 9\r | |
51 | bts eax, 0ah\r | |
52 | db 0fh\r | |
53 | db 22h\r | |
54 | db 0e0h\r | |
55 | ; mov cr4, rax\r | |
56 | \r | |
57 | call ClearScreen\r | |
58 | \r | |
59 | ; Populate IDT with meaningful offsets for exception handlers...\r | |
60 | mov eax, offset Idtr\r | |
61 | sidt fword ptr [eax] ; get fword address of IDT\r | |
62 | \r | |
63 | mov eax, offset Halt\r | |
64 | mov ebx, eax ; use bx to copy 15..0 to descriptors\r | |
65 | shr eax, 16 ; use ax to copy 31..16 to descriptors \r | |
66 | ; 63..32 of descriptors is 0\r | |
67 | mov ecx, 78h ; 78h IDT entries to initialize with unique entry points (exceptions)\r | |
68 | mov esi, [offset Idtr + 2]\r | |
69 | mov edi, [esi]\r | |
70 | \r | |
71 | @@: ; loop through all IDT entries exception handlers and initialize to default handler\r | |
72 | mov word ptr [edi], bx ; write bits 15..0 of offset\r | |
73 | mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT\r | |
74 | mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present\r | |
75 | mov word ptr [edi+6], ax ; write bits 31..16 of offset\r | |
76 | mov dword ptr [edi+8], 0 ; write bits 63..32 of offset\r | |
77 | add edi, 16 ; move up to next descriptor\r | |
78 | add bx, DEFAULT_HANDLER_SIZE ; move to next entry point\r | |
79 | loop @b ; loop back through again until all descriptors are initialized\r | |
80 | \r | |
81 | ;; at this point edi contains the offset of the descriptor for INT 20\r | |
82 | ;; and bx contains the low 16 bits of the offset of the default handler\r | |
83 | ;; so initialize all the rest of the descriptors with these two values...\r | |
84 | ; mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)\r | |
85 | ;@@: ; loop through all IDT entries exception handlers and initialize to default handler\r | |
86 | ; mov word ptr [edi], bx ; write bits 15..0 of offset\r | |
87 | ; mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT\r | |
88 | ; mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present\r | |
89 | ; mov word ptr [edi+6], ax ; write bits 31..16 of offset\r | |
90 | ; mov dword ptr [edi+8], 0 ; write bits 63..32 of offset\r | |
91 | ; add edi, 16 ; move up to next descriptor\r | |
92 | ; loop @b ; loop back through again until all descriptors are initialized\r | |
93 | \r | |
94 | \r | |
95 | ;; DUMP location of IDT and several of the descriptors\r | |
96 | ; mov ecx, 8\r | |
97 | ; mov eax, [offset Idtr + 2]\r | |
98 | ; mov eax, [eax]\r | |
99 | ; mov edi, 0b8000h\r | |
100 | ; call PrintQword\r | |
101 | ; mov esi, eax\r | |
102 | ; mov edi, 0b80a0h\r | |
103 | ; jmp OuterLoop\r | |
104 | \r | |
105 | ;; \r | |
106 | ;; just for fun, let's do a software interrupt to see if we correctly land in the exception handler...\r | |
107 | ; mov eax, 011111111h\r | |
108 | ; mov ebx, 022222222h\r | |
109 | ; mov ecx, 033333333h\r | |
110 | ; mov edx, 044444444h\r | |
111 | ; mov ebp, 055555555h\r | |
112 | ; mov esi, 066666666h\r | |
113 | ; mov edi, 077777777h\r | |
114 | ; push 011111111h\r | |
115 | ; push 022222222h\r | |
116 | ; push 033333333h\r | |
117 | ; int 119\r | |
118 | \r | |
119 | mov esi,022000h ; esi = 22000\r | |
120 | mov eax,[esi+014h] ; eax = [22014]\r | |
121 | add esi,eax ; esi = 22000 + [22014] = Base of EFILDR.C\r | |
122 | mov ebp,[esi+03ch] ; ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C\r | |
123 | add ebp,esi\r | |
124 | mov edi,[ebp+030h] ; edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)\r | |
125 | mov eax,[ebp+028h] ; eax = [[22000 + [22014] + 3c] + 24] = EntryPoint\r | |
126 | add eax,edi ; eax = ImageBase + EntryPoint\r | |
127 | mov ebx, offset EfiLdrOffset\r | |
128 | mov dword ptr [ebx],eax ; Modify far jump instruction for correct entry point\r | |
129 | \r | |
130 | mov bx,word ptr[ebp+6] ; bx = Number of sections\r | |
131 | xor eax,eax\r | |
132 | mov ax,word ptr[ebp+014h] ; ax = Optional Header Size\r | |
133 | add ebp,eax\r | |
134 | add ebp,018h ; ebp = Start of 1st Section\r | |
135 | \r | |
136 | SectionLoop:\r | |
137 | push esi ; Save Base of EFILDR.C\r | |
138 | push edi ; Save ImageBase\r | |
139 | add esi,[ebp+014h] ; esi = Base of EFILDR.C + PointerToRawData\r | |
140 | add edi,[ebp+00ch] ; edi = ImageBase + VirtualAddress\r | |
141 | mov ecx,[ebp+010h] ; ecs = SizeOfRawData\r | |
142 | \r | |
143 | cld\r | |
144 | shr ecx,2\r | |
145 | rep movsd\r | |
146 | \r | |
147 | pop edi ; Restore ImageBase\r | |
148 | pop esi ; Restore Base of EFILDR.C\r | |
149 | \r | |
150 | add bp,028h ; ebp = ebp + 028h = Pointer to next section record\r | |
151 | db 66h\r | |
152 | db 0ffh\r | |
153 | db 0cbh\r | |
154 | ; dec bx\r | |
155 | cmp bx,0\r | |
156 | jne SectionLoop\r | |
157 | \r | |
158 | mov edx, offset Idtr\r | |
159 | movzx eax, word ptr [edx] ; get size of IDT\r | |
160 | db 0ffh\r | |
161 | db 0c0h\r | |
162 | ; inc eax\r | |
163 | add eax, dword ptr [edx + 2] ; add to base of IDT to get location of memory map...\r | |
164 | xor ecx, ecx\r | |
165 | mov ecx, eax ; put argument to RCX\r | |
166 | \r | |
167 | db 48h\r | |
168 | db 0c7h\r | |
169 | db 0c0h\r | |
170 | EfiLdrOffset:\r | |
171 | dd 000401000h ; Offset of EFILDR\r | |
172 | ; mov rax, 401000h\r | |
173 | db 50h\r | |
174 | ; push rax\r | |
175 | \r | |
176 | ; ret\r | |
177 | db 0c3h\r | |
178 | \r | |
179 | ; db "**** DEFAULT IDT ENTRY ***",0\r | |
180 | align 02h\r | |
181 | Halt:\r | |
182 | INT0:\r | |
183 | push 0h ; push error code place holder on the stack\r | |
184 | push 0h\r | |
185 | JmpCommonIdtEntry\r | |
186 | ; db 0e9h ; jmp 16 bit reletive \r | |
187 | ; dd commonIdtEntry - $ - 4 ; offset to jump to\r | |
188 | \r | |
189 | INT1:\r | |
190 | push 0h ; push error code place holder on the stack\r | |
191 | push 1h\r | |
192 | JmpCommonIdtEntry\r | |
193 | \r | |
194 | INT2:\r | |
195 | push 0h ; push error code place holder on the stack\r | |
196 | push 2h\r | |
197 | JmpCommonIdtEntry\r | |
198 | \r | |
199 | INT3:\r | |
200 | push 0h ; push error code place holder on the stack\r | |
201 | push 3h\r | |
202 | JmpCommonIdtEntry\r | |
203 | \r | |
204 | INT4:\r | |
205 | push 0h ; push error code place holder on the stack\r | |
206 | push 4h\r | |
207 | JmpCommonIdtEntry\r | |
208 | \r | |
209 | INT5:\r | |
210 | push 0h ; push error code place holder on the stack\r | |
211 | push 5h\r | |
212 | JmpCommonIdtEntry\r | |
213 | \r | |
214 | INT6:\r | |
215 | push 0h ; push error code place holder on the stack\r | |
216 | push 6h\r | |
217 | JmpCommonIdtEntry\r | |
218 | \r | |
219 | INT7:\r | |
220 | push 0h ; push error code place holder on the stack\r | |
221 | push 7h\r | |
222 | JmpCommonIdtEntry\r | |
223 | \r | |
224 | INT8:\r | |
225 | ; Double fault causes an error code to be pushed so no phony push necessary\r | |
226 | nop\r | |
227 | nop\r | |
228 | push 8h\r | |
229 | JmpCommonIdtEntry\r | |
230 | \r | |
231 | INT9:\r | |
232 | push 0h ; push error code place holder on the stack\r | |
233 | push 9h\r | |
234 | JmpCommonIdtEntry\r | |
235 | \r | |
236 | INT10:\r | |
237 | ; Invalid TSS causes an error code to be pushed so no phony push necessary\r | |
238 | nop\r | |
239 | nop\r | |
240 | push 10\r | |
241 | JmpCommonIdtEntry\r | |
242 | \r | |
243 | INT11:\r | |
244 | ; Segment Not Present causes an error code to be pushed so no phony push necessary\r | |
245 | nop\r | |
246 | nop\r | |
247 | push 11\r | |
248 | JmpCommonIdtEntry\r | |
249 | \r | |
250 | INT12:\r | |
251 | ; Stack fault causes an error code to be pushed so no phony push necessary\r | |
252 | nop\r | |
253 | nop\r | |
254 | push 12\r | |
255 | JmpCommonIdtEntry\r | |
256 | \r | |
257 | INT13:\r | |
258 | ; GP fault causes an error code to be pushed so no phony push necessary\r | |
259 | nop\r | |
260 | nop\r | |
261 | push 13\r | |
262 | JmpCommonIdtEntry\r | |
263 | \r | |
264 | INT14:\r | |
265 | ; Page fault causes an error code to be pushed so no phony push necessary\r | |
266 | nop\r | |
267 | nop\r | |
268 | push 14\r | |
269 | JmpCommonIdtEntry\r | |
270 | \r | |
271 | INT15:\r | |
272 | push 0h ; push error code place holder on the stack\r | |
273 | push 15\r | |
274 | JmpCommonIdtEntry\r | |
275 | \r | |
276 | INT16:\r | |
277 | push 0h ; push error code place holder on the stack\r | |
278 | push 16\r | |
279 | JmpCommonIdtEntry\r | |
280 | \r | |
281 | INT17:\r | |
282 | ; Alignment check causes an error code to be pushed so no phony push necessary\r | |
283 | nop\r | |
284 | nop\r | |
285 | push 17\r | |
286 | JmpCommonIdtEntry\r | |
287 | \r | |
288 | INT18:\r | |
289 | push 0h ; push error code place holder on the stack\r | |
290 | push 18\r | |
291 | JmpCommonIdtEntry\r | |
292 | \r | |
293 | INT19:\r | |
294 | push 0h ; push error code place holder on the stack\r | |
295 | push 19\r | |
296 | JmpCommonIdtEntry\r | |
297 | \r | |
298 | INTUnknown:\r | |
299 | REPEAT (78h - 20)\r | |
300 | push 0h ; push error code place holder on the stack\r | |
301 | ; push xxh ; push vector number\r | |
302 | db 06ah\r | |
303 | db ( $ - INTUnknown - 3 ) / 9 + 20 ; vector number\r | |
304 | JmpCommonIdtEntry\r | |
305 | ENDM\r | |
306 | \r | |
307 | commonIdtEntry:\r | |
308 | push eax\r | |
309 | push ecx\r | |
310 | push edx\r | |
311 | push ebx\r | |
312 | push esp\r | |
313 | push ebp\r | |
314 | push esi\r | |
315 | push edi\r | |
316 | db 41h\r | |
317 | db 50h\r | |
318 | ; push r8\r | |
319 | db 41h\r | |
320 | db 51h\r | |
321 | ; push r9\r | |
322 | db 41h\r | |
323 | db 52h\r | |
324 | ; push r10\r | |
325 | db 41h\r | |
326 | db 53h\r | |
327 | ; push r11\r | |
328 | db 41h\r | |
329 | db 54h\r | |
330 | ; push r12\r | |
331 | db 41h\r | |
332 | db 55h\r | |
333 | ; push r13\r | |
334 | db 41h\r | |
335 | db 56h\r | |
336 | ; push r14\r | |
337 | db 41h\r | |
338 | db 57h\r | |
339 | ; push r15\r | |
340 | db 48h\r | |
341 | mov ebp, esp\r | |
342 | ; mov rbp, rsp\r | |
343 | \r | |
344 | ;;\r | |
345 | ;; At this point the stack looks like this:\r | |
346 | ;;\r | |
347 | ;; Calling SS\r | |
348 | ;; Calling RSP\r | |
349 | ;; rflags\r | |
350 | ;; Calling CS\r | |
351 | ;; Calling RIP\r | |
352 | ;; Error code or 0\r | |
353 | ;; Int num or 0ffh for unknown int num\r | |
354 | ;; rax\r | |
355 | ;; rcx\r | |
356 | ;; rdx\r | |
357 | ;; rbx\r | |
358 | ;; rsp\r | |
359 | ;; rbp\r | |
360 | ;; rsi\r | |
361 | ;; rdi\r | |
362 | ;; r8\r | |
363 | ;; r9\r | |
364 | ;; r10\r | |
365 | ;; r11\r | |
366 | ;; r12\r | |
367 | ;; r13\r | |
368 | ;; r14\r | |
369 | ;; r15 <------- RSP, RBP\r | |
370 | ;; \r | |
371 | \r | |
372 | call ClearScreen\r | |
373 | mov esi, offset String1\r | |
374 | call PrintString\r | |
375 | db 48h\r | |
376 | mov eax, [ebp + 16*8] ;; move Int number into RAX \r | |
377 | db 48h\r | |
378 | cmp eax, 18\r | |
379 | ja PrintDefaultString\r | |
380 | PrintExceptionString:\r | |
381 | shl eax, 3 ;; multiply by 8 to get offset from StringTable to actual string address\r | |
382 | add eax, offset StringTable\r | |
383 | mov esi, [eax]\r | |
384 | jmp PrintTheString\r | |
385 | PrintDefaultString:\r | |
386 | mov esi, offset IntUnknownString\r | |
387 | ; patch Int number\r | |
388 | mov edx, eax\r | |
389 | call A2C\r | |
390 | mov [esi + 1], al\r | |
391 | mov eax, edx\r | |
392 | shr eax, 4\r | |
393 | call A2C\r | |
394 | mov [esi], al\r | |
395 | PrintTheString: \r | |
396 | call PrintString\r | |
397 | mov esi, offset String2\r | |
398 | call PrintString\r | |
399 | db 48h\r | |
400 | mov eax, [ebp+19*8] ; CS\r | |
401 | call PrintQword\r | |
402 | mov al, ':'\r | |
403 | mov byte ptr [edi], al\r | |
404 | add edi, 2\r | |
405 | db 48h\r | |
406 | mov eax, [ebp+18*8] ; RIP\r | |
407 | call PrintQword\r | |
408 | mov esi, offset String3\r | |
409 | call PrintString\r | |
410 | \r | |
411 | mov edi, 0b8140h\r | |
412 | \r | |
413 | mov esi, offset StringRax ; rax\r | |
414 | call PrintString\r | |
415 | db 48h\r | |
416 | mov eax, [ebp+15*8]\r | |
417 | call PrintQword\r | |
418 | \r | |
419 | mov esi, offset StringRcx ; rcx\r | |
420 | call PrintString\r | |
421 | db 48h\r | |
422 | mov eax, [ebp+14*8]\r | |
423 | call PrintQword\r | |
424 | \r | |
425 | mov esi, offset StringRdx ; rdx\r | |
426 | call PrintString\r | |
427 | db 48h\r | |
428 | mov eax, [ebp+13*8]\r | |
429 | call PrintQword\r | |
430 | \r | |
431 | mov edi, 0b81e0h\r | |
432 | \r | |
433 | mov esi, offset StringRbx ; rbx\r | |
434 | call PrintString\r | |
435 | db 48h\r | |
436 | mov eax, [ebp+12*8]\r | |
437 | call PrintQword\r | |
438 | \r | |
439 | mov esi, offset StringRsp ; rsp\r | |
440 | call PrintString\r | |
441 | db 48h\r | |
442 | mov eax, [ebp+21*8]\r | |
443 | call PrintQword\r | |
444 | \r | |
445 | mov esi, offset StringRbp ; rbp\r | |
446 | call PrintString\r | |
447 | db 48h\r | |
448 | mov eax, [ebp+10*8]\r | |
449 | call PrintQword\r | |
450 | \r | |
451 | mov edi, 0b8280h\r | |
452 | \r | |
453 | mov esi, offset StringRsi ; rsi\r | |
454 | call PrintString\r | |
455 | db 48h\r | |
456 | mov eax, [ebp+9*8]\r | |
457 | call PrintQword\r | |
458 | \r | |
459 | mov esi, offset StringRdi ; rdi\r | |
460 | call PrintString\r | |
461 | db 48h\r | |
462 | mov eax, [ebp+8*8]\r | |
463 | call PrintQword\r | |
464 | \r | |
465 | mov esi, offset StringEcode ; error code\r | |
466 | call PrintString\r | |
467 | db 48h\r | |
468 | mov eax, [ebp+17*8]\r | |
469 | call PrintQword\r | |
470 | \r | |
471 | mov edi, 0b8320h\r | |
472 | \r | |
473 | mov esi, offset StringR8 ; r8\r | |
474 | call PrintString\r | |
475 | db 48h\r | |
476 | mov eax, [ebp+7*8]\r | |
477 | call PrintQword\r | |
478 | \r | |
479 | mov esi, offset StringR9 ; r9\r | |
480 | call PrintString\r | |
481 | db 48h\r | |
482 | mov eax, [ebp+6*8]\r | |
483 | call PrintQword\r | |
484 | \r | |
485 | mov esi, offset StringR10 ; r10\r | |
486 | call PrintString\r | |
487 | db 48h\r | |
488 | mov eax, [ebp+5*8]\r | |
489 | call PrintQword\r | |
490 | \r | |
491 | mov edi, 0b83c0h\r | |
492 | \r | |
493 | mov esi, offset StringR11 ; r11\r | |
494 | call PrintString\r | |
495 | db 48h\r | |
496 | mov eax, [ebp+4*8]\r | |
497 | call PrintQword\r | |
498 | \r | |
499 | mov esi, offset StringR12 ; r12\r | |
500 | call PrintString\r | |
501 | db 48h\r | |
502 | mov eax, [ebp+3*8]\r | |
503 | call PrintQword\r | |
504 | \r | |
505 | mov esi, offset StringR13 ; r13\r | |
506 | call PrintString\r | |
507 | db 48h\r | |
508 | mov eax, [ebp+2*8]\r | |
509 | call PrintQword\r | |
510 | \r | |
511 | mov edi, 0b8460h\r | |
512 | \r | |
513 | mov esi, offset StringR14 ; r14\r | |
514 | call PrintString\r | |
515 | db 48h\r | |
516 | mov eax, [ebp+1*8]\r | |
517 | call PrintQword\r | |
518 | \r | |
519 | mov esi, offset StringR15 ; r15\r | |
520 | call PrintString\r | |
521 | db 48h\r | |
522 | mov eax, [ebp+0*8]\r | |
523 | call PrintQword\r | |
524 | \r | |
525 | mov esi, offset StringSs ; ss\r | |
526 | call PrintString\r | |
527 | db 48h\r | |
528 | mov eax, [ebp+22*8]\r | |
529 | call PrintQword\r | |
530 | \r | |
531 | mov edi, 0b8500h\r | |
532 | \r | |
533 | mov esi, offset StringRflags ; rflags\r | |
534 | call PrintString\r | |
535 | db 48h\r | |
536 | mov eax, [ebp+20*8]\r | |
537 | call PrintQword\r | |
538 | \r | |
539 | mov edi, 0b8640h\r | |
540 | \r | |
541 | mov esi, ebp\r | |
542 | add esi, 23*8\r | |
543 | mov ecx, 4\r | |
544 | \r | |
545 | \r | |
546 | OuterLoop:\r | |
547 | push ecx\r | |
548 | mov ecx, 4\r | |
549 | db 48h\r | |
550 | mov edx, edi\r | |
551 | \r | |
552 | InnerLoop:\r | |
553 | db 48h\r | |
554 | mov eax, [esi]\r | |
555 | call PrintQword\r | |
556 | add esi, 8\r | |
557 | mov al, ' '\r | |
558 | mov [edi], al\r | |
559 | add edi, 2\r | |
560 | loop InnerLoop\r | |
561 | \r | |
562 | pop ecx\r | |
563 | add edx, 0a0h\r | |
564 | mov edi, edx\r | |
565 | loop OuterLoop\r | |
566 | \r | |
567 | \r | |
568 | mov edi, 0b8960h\r | |
569 | \r | |
570 | db 48h\r | |
571 | mov eax, [ebp+18*8] ; RIP\r | |
572 | sub eax, 8 * 8\r | |
573 | db 48h\r | |
574 | mov esi, eax ; esi = rip - 8 QWORD linear (total 16 QWORD)\r | |
575 | \r | |
576 | mov ecx, 4\r | |
577 | \r | |
578 | OuterLoop1:\r | |
579 | push ecx\r | |
580 | mov ecx, 4\r | |
581 | mov edx, edi\r | |
582 | \r | |
583 | InnerLoop1:\r | |
584 | db 48h\r | |
585 | mov eax, [esi]\r | |
586 | call PrintQword\r | |
587 | add esi, 8\r | |
588 | mov al, ' '\r | |
589 | mov [edi], al\r | |
590 | add edi, 2\r | |
591 | loop InnerLoop1\r | |
592 | \r | |
593 | pop ecx\r | |
594 | add edx, 0a0h\r | |
595 | mov edi, edx\r | |
596 | loop OuterLoop1\r | |
597 | \r | |
598 | \r | |
599 | \r | |
c5dfb477 | 600 | ;wbinvd\r |
c69dd9df | 601 | @@: \r |
602 | jmp @b\r | |
603 | \r | |
604 | ;\r | |
605 | ; return\r | |
606 | ;\r | |
607 | mov esp, ebp\r | |
608 | ; mov rsp, rbp\r | |
609 | db 41h\r | |
610 | db 5fh\r | |
611 | ; pop r15\r | |
612 | db 41h\r | |
613 | db 5eh\r | |
614 | ; pop r14\r | |
615 | db 41h\r | |
616 | db 5dh\r | |
617 | ; pop r13\r | |
618 | db 41h\r | |
619 | db 5ch\r | |
620 | ; pop r12\r | |
621 | db 41h\r | |
622 | db 5bh\r | |
623 | ; pop r11\r | |
624 | db 41h\r | |
625 | db 5ah\r | |
626 | ; pop r10\r | |
627 | db 41h\r | |
628 | db 59h\r | |
629 | ; pop r9\r | |
630 | db 41h\r | |
631 | db 58h\r | |
632 | ; pop r8\r | |
633 | pop edi\r | |
634 | pop esi\r | |
635 | pop ebp\r | |
636 | pop eax ; esp\r | |
637 | pop ebx\r | |
638 | pop edx\r | |
639 | pop ecx\r | |
640 | pop eax\r | |
641 | \r | |
642 | db 48h\r | |
643 | db 83h\r | |
644 | db 0c4h\r | |
645 | db 10h \r | |
646 | ; add esp, 16 ; error code and INT number\r | |
647 | \r | |
648 | db 48h\r | |
649 | db 0cfh\r | |
650 | ; iretq\r | |
651 | \r | |
652 | PrintString:\r | |
653 | push eax\r | |
654 | @@:\r | |
655 | mov al, byte ptr [esi]\r | |
656 | cmp al, 0\r | |
657 | je @f\r | |
658 | mov byte ptr [edi], al\r | |
659 | db 0ffh\r | |
660 | db 0c6h\r | |
661 | ; inc esi\r | |
662 | add edi, 2\r | |
663 | jmp @b\r | |
664 | @@:\r | |
665 | pop eax\r | |
666 | ret\r | |
667 | \r | |
668 | ;; RAX contains qword to print\r | |
669 | ;; RDI contains memory location (screen location) to print it to\r | |
670 | PrintQword:\r | |
671 | push ecx\r | |
672 | push ebx\r | |
673 | push eax\r | |
674 | \r | |
675 | db 48h\r | |
676 | db 0c7h\r | |
677 | db 0c1h\r | |
678 | dd 16\r | |
679 | ; mov rcx, 16\r | |
680 | looptop:\r | |
681 | db 48h\r | |
682 | rol eax, 4\r | |
683 | mov bl, al\r | |
684 | and bl, 0fh\r | |
685 | add bl, '0'\r | |
686 | cmp bl, '9'\r | |
687 | jle @f\r | |
688 | add bl, 7\r | |
689 | @@:\r | |
690 | mov byte ptr [edi], bl\r | |
691 | add edi, 2\r | |
692 | loop looptop\r | |
c5dfb477 | 693 | ;wbinvd\r |
c69dd9df | 694 | \r |
695 | pop eax\r | |
696 | pop ebx\r | |
697 | pop ecx\r | |
698 | ret\r | |
699 | \r | |
700 | ClearScreen:\r | |
701 | push eax\r | |
702 | push ecx\r | |
703 | \r | |
704 | mov al, ' '\r | |
705 | mov ah, 0ch\r | |
706 | mov edi, 0b8000h\r | |
707 | mov ecx, 80 * 24\r | |
708 | @@:\r | |
709 | mov word ptr [edi], ax\r | |
710 | add edi, 2\r | |
711 | loop @b\r | |
712 | mov edi, 0b8000h\r | |
713 | \r | |
714 | pop ecx\r | |
715 | pop eax\r | |
716 | \r | |
717 | ret \r | |
718 | \r | |
719 | A2C:\r | |
720 | and al, 0fh\r | |
721 | add al, '0'\r | |
722 | cmp al, '9'\r | |
723 | jle @f\r | |
724 | add al, 7\r | |
725 | @@:\r | |
726 | ret\r | |
727 | \r | |
728 | String1 db "*** INT ",0\r | |
729 | \r | |
730 | Int0String db "00h Divide by 0 -",0\r | |
731 | Int1String db "01h Debug exception -",0\r | |
732 | Int2String db "02h NMI -",0\r | |
733 | Int3String db "03h Breakpoint -",0\r | |
734 | Int4String db "04h Overflow -",0\r | |
735 | Int5String db "05h Bound -",0\r | |
736 | Int6String db "06h Invalid opcode -",0\r | |
737 | Int7String db "07h Device not available -",0\r | |
738 | Int8String db "08h Double fault -",0\r | |
739 | Int9String db "09h Coprocessor seg overrun (reserved) -",0\r | |
740 | Int10String db "0Ah Invalid TSS -",0\r | |
741 | Int11String db "0Bh Segment not present -",0\r | |
742 | Int12String db "0Ch Stack fault -",0\r | |
743 | Int13String db "0Dh General protection fault -",0\r | |
744 | Int14String db "0Eh Page fault -",0\r | |
745 | Int15String db "0Fh (Intel reserved) -",0\r | |
746 | Int16String db "10h Floating point error -",0\r | |
747 | Int17String db "11h Alignment check -",0\r | |
748 | Int18String db "12h Machine check -",0\r | |
749 | Int19String db "13h SIMD Floating-Point Exception -",0\r | |
750 | IntUnknownString db "??h Unknown interrupt -",0\r | |
751 | \r | |
752 | StringTable dq offset Int0String, offset Int1String, offset Int2String, offset Int3String, \r | |
753 | offset Int4String, offset Int5String, offset Int6String, offset Int7String,\r | |
754 | offset Int8String, offset Int9String, offset Int10String, offset Int11String,\r | |
755 | offset Int12String, offset Int13String, offset Int14String, offset Int15String,\r | |
756 | offset Int16String, offset Int17String, offset Int18String, offset Int19String\r | |
757 | \r | |
758 | String2 db " HALT!! *** (",0\r | |
759 | String3 db ")",0\r | |
760 | StringRax db "RAX=",0\r | |
761 | StringRcx db " RCX=",0\r | |
762 | StringRdx db " RDX=",0\r | |
763 | StringRbx db "RBX=",0\r | |
764 | StringRsp db " RSP=",0\r | |
765 | StringRbp db " RBP=",0\r | |
766 | StringRsi db "RSI=",0\r | |
767 | StringRdi db " RDI=",0\r | |
768 | StringEcode db " ECODE=",0\r | |
769 | StringR8 db "R8 =",0\r | |
770 | StringR9 db " R9 =",0\r | |
771 | StringR10 db " R10=",0\r | |
772 | StringR11 db "R11=",0\r | |
773 | StringR12 db " R12=",0\r | |
774 | StringR13 db " R13=",0\r | |
775 | StringR14 db "R14=",0\r | |
776 | StringR15 db " R15=",0\r | |
777 | StringSs db " SS =",0\r | |
778 | StringRflags db "RFLAGS=",0\r | |
779 | \r | |
780 | Idtr df 0\r | |
781 | df 0\r | |
782 | \r | |
783 | org 21ffeh\r | |
784 | BlockSignature:\r | |
785 | dw 0aa55h\r | |
786 | \r | |
787 | end\r |