]>
Commit | Line | Data |
---|---|---|
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 | .stack: \r | |
24 | .code: \r | |
25 | .org 0x21000\r | |
26 | \r | |
27 | .equ DEFAULT_HANDLER_SIZE, INT1 - INT0\r | |
28 | \r | |
29 | .macro jmpCommonIdtEntry \r | |
30 | # jmp commonIdtEntry - this must be hand coded to keep the assembler from\r | |
31 | # using a 8 bit reletive jump when the entries are\r | |
32 | # within 255 bytes of the common entry. This must\r | |
33 | # be done to maintain the consistency of the size\r | |
34 | # of entry points...\r | |
35 | .byte 0xe9 # jmp 16 bit relative\r | |
36 | .long commonIdtEntry - . - 4 # offset to jump to\r | |
37 | .endm\r | |
38 | \r | |
39 | \r | |
40 | Start: \r | |
41 | \r | |
42 | movl $0x001fffe8,%esp # make final stack aligned\r | |
43 | \r | |
44 | # set OSFXSR and OSXMMEXCPT because some code will use XMM register\r | |
45 | .byte 0xf\r | |
46 | .byte 0x20\r | |
47 | .byte 0xe0\r | |
48 | # mov rax, cr4\r | |
49 | btsl $9,%eax\r | |
50 | btsl $0xa,%eax\r | |
51 | .byte 0xf\r | |
52 | .byte 0x22\r | |
53 | .byte 0xe0\r | |
54 | # mov cr4, rax\r | |
55 | \r | |
56 | call ClearScreen\r | |
57 | \r | |
58 | # Populate IDT with meaningful offsets for exception handlers...\r | |
59 | sidt Idtr \r | |
60 | \r | |
61 | \r | |
62 | movl Halt, %eax\r | |
63 | movl %eax,%ebx # use bx to copy 15..0 to descriptors\r | |
64 | shrl $16,%eax # use ax to copy 31..16 to descriptors \r | |
65 | # 63..32 of descriptors is 0\r | |
66 | movl $0x78,%ecx # 78h IDT entries to initialize with unique entry points (exceptions)\r | |
67 | movl (Idtr + 2), %esi\r | |
68 | movl (%esi),%edi\r | |
69 | \r | |
70 | LOOP_1: # loop through all IDT entries exception handlers and initialize to default handler\r | |
71 | movw %bx, (%edi) # write bits 15..0 of offset\r | |
72 | movw $0x38, 2(%edi) # SYS_CODE_SEL64 from GDT\r | |
73 | movw $(0x0e00 | 0x8000), 4(%edi) # type = 386 interrupt gate, present\r | |
74 | movw %ax, 6(%edi) # write bits 31..16 of offset\r | |
75 | movl $0, 8(%edi) # write bits 31..16 of offset \r | |
76 | addl $16, %edi # move up to next descriptor\r | |
77 | addw DEFAULT_HANDLER_SIZE, %bx # move to next entry point\r | |
78 | loopl LOOP_1 # loop back through again until all descriptors are initialized\r | |
79 | \r | |
80 | ## at this point edi contains the offset of the descriptor for INT 20\r | |
81 | ## and bx contains the low 16 bits of the offset of the default handler\r | |
82 | ## so initialize all the rest of the descriptors with these two values...\r | |
83 | # mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)\r | |
84 | #@@: ; loop through all IDT entries exception handlers and initialize to default handler\r | |
85 | # mov word ptr [edi], bx ; write bits 15..0 of offset\r | |
86 | # mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT\r | |
87 | # mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present\r | |
88 | # mov word ptr [edi+6], ax ; write bits 31..16 of offset\r | |
89 | # mov dword ptr [edi+8], 0 ; write bits 63..32 of offset\r | |
90 | # add edi, 16 ; move up to next descriptor\r | |
91 | # loop @b ; loop back through again until all descriptors are initialized\r | |
92 | \r | |
93 | \r | |
94 | ## DUMP location of IDT and several of the descriptors\r | |
95 | # mov ecx, 8\r | |
96 | # mov eax, [offset Idtr + 2]\r | |
97 | # mov eax, [eax]\r | |
98 | # mov edi, 0b8000h\r | |
99 | # call PrintQword\r | |
100 | # mov esi, eax\r | |
101 | # mov edi, 0b80a0h\r | |
102 | # jmp OuterLoop\r | |
103 | \r | |
104 | ## \r | |
105 | ## just for fun, let's do a software interrupt to see if we correctly land in the exception handler...\r | |
106 | # mov eax, 011111111h\r | |
107 | # mov ebx, 022222222h\r | |
108 | # mov ecx, 033333333h\r | |
109 | # mov edx, 044444444h\r | |
110 | # mov ebp, 055555555h\r | |
111 | # mov esi, 066666666h\r | |
112 | # mov edi, 077777777h\r | |
113 | # push 011111111h\r | |
114 | # push 022222222h\r | |
115 | # push 033333333h\r | |
116 | # int 119\r | |
117 | \r | |
118 | movl $0x22000,%esi # esi = 22000\r | |
119 | movl 0x14(%esi),%eax # eax = [22014]\r | |
120 | addl %eax,%esi # esi = 22000 + [22014] = Base of EFILDR.C\r | |
121 | movl 0x3c(%esi),%ebp # ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C\r | |
122 | addl %esi,%ebp\r | |
123 | movl 0x30(%ebp),%edi # edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)\r | |
124 | movl 0x28(%ebp),%eax # eax = [[22000 + [22014] + 3c] + 24] = EntryPoint\r | |
125 | addl %edi,%eax # eax = ImageBase + EntryPoint\r | |
126 | movl %ebx, EfiLdrOffset \r | |
127 | movl %eax, (%ebx) # Modify far jump instruction for correct entry point\r | |
128 | \r | |
129 | movw 6(%ebp), %bx # bx = Number of sections\r | |
130 | xorl %eax,%eax\r | |
131 | movw 0x14(%ebp), %ax # ax = Optional Header Size\r | |
132 | addl %eax,%ebp\r | |
133 | addl $0x18,%ebp # ebp = Start of 1st Section\r | |
134 | \r | |
135 | SectionLoop: \r | |
136 | pushl %esi # Save Base of EFILDR.C\r | |
137 | pushl %edi # Save ImageBase\r | |
138 | addl 0x14(%ebp),%esi # esi = Base of EFILDR.C + PointerToRawData\r | |
139 | addl 0x0c(%ebp),%edi # edi = ImageBase + VirtualAddress\r | |
140 | movl 0x10(%ebp),%ecx # ecs = SizeOfRawData\r | |
141 | \r | |
142 | cld\r | |
143 | shrl $2,%ecx\r | |
144 | rep\r | |
145 | movsl\r | |
146 | \r | |
147 | popl %edi # Restore ImageBase\r | |
148 | popl %esi # Restore Base of EFILDR.C\r | |
149 | \r | |
150 | addw $0x28,%bp # ebp = ebp + 028h = Pointer to next section record\r | |
151 | .byte 0x66\r | |
152 | .byte 0xff\r | |
153 | .byte 0xcb\r | |
154 | # dec bx\r | |
155 | cmpw $0,%bx\r | |
156 | jne SectionLoop\r | |
157 | \r | |
158 | movl (Idtr), %eax # get size of IDT\r | |
159 | movzx (%edx), %eax\r | |
160 | .byte 0xff\r | |
161 | .byte 0xc0\r | |
162 | # inc eax\r | |
163 | addl 2(%edx), %eax # add to base of IDT to get location of memory map...\r | |
164 | xorl %ecx,%ecx\r | |
165 | movl %eax,%ecx # put argument to RCX\r | |
166 | \r | |
167 | .byte 0x48\r | |
168 | .byte 0xc7\r | |
169 | .byte 0xc0\r | |
170 | EfiLdrOffset: \r | |
171 | .long 0x00401000 # Offset of EFILDR\r | |
172 | # mov rax, 401000h\r | |
173 | .byte 0x50\r | |
174 | # push rax\r | |
175 | \r | |
176 | # ret\r | |
177 | .byte 0xc3\r | |
178 | \r | |
179 | # db "**** DEFAULT IDT ENTRY ***",0\r | |
180 | .p2align 1\r | |
181 | Halt: \r | |
182 | INT0: \r | |
183 | pushl $0x0 # push error code place holder on the stack\r | |
184 | pushl $0x0\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 | pushl $0x0 # push error code place holder on the stack\r | |
191 | pushl $0x1\r | |
192 | jmpCommonIdtEntry \r | |
193 | \r | |
194 | INT2: \r | |
195 | pushl $0x0 # push error code place holder on the stack\r | |
196 | pushl $0x2\r | |
197 | jmpCommonIdtEntry \r | |
198 | \r | |
199 | INT3: \r | |
200 | pushl $0x0 # push error code place holder on the stack\r | |
201 | pushl $0x3\r | |
202 | jmpCommonIdtEntry \r | |
203 | \r | |
204 | INT4: \r | |
205 | pushl $0x0 # push error code place holder on the stack\r | |
206 | pushl $0x4\r | |
207 | jmpCommonIdtEntry \r | |
208 | \r | |
209 | INT5: \r | |
210 | pushl $0x0 # push error code place holder on the stack\r | |
211 | pushl $0x5\r | |
212 | jmpCommonIdtEntry \r | |
213 | \r | |
214 | INT6: \r | |
215 | pushl $0x0 # push error code place holder on the stack\r | |
216 | pushl $0x6\r | |
217 | jmpCommonIdtEntry \r | |
218 | \r | |
219 | INT7: \r | |
220 | pushl $0x0 # push error code place holder on the stack\r | |
221 | pushl $0x7\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 | pushl $0x8\r | |
229 | jmpCommonIdtEntry \r | |
230 | \r | |
231 | INT9: \r | |
232 | pushl $0x0 # push error code place holder on the stack\r | |
233 | pushl $0x9\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 | pushl $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 | pushl $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 | pushl $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 | pushl $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 | pushl $14\r | |
269 | jmpCommonIdtEntry \r | |
270 | \r | |
271 | INT15: \r | |
272 | pushl $0x0 # push error code place holder on the stack\r | |
273 | pushl $15\r | |
274 | jmpCommonIdtEntry \r | |
275 | \r | |
276 | INT16: \r | |
277 | pushl $0x0 # push error code place holder on the stack\r | |
278 | pushl $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 | pushl $17\r | |
286 | jmpCommonIdtEntry \r | |
287 | \r | |
288 | INT18: \r | |
289 | pushl $0x0 # push error code place holder on the stack\r | |
290 | pushl $18\r | |
291 | jmpCommonIdtEntry \r | |
292 | \r | |
293 | INT19: \r | |
294 | pushl $0x0 # push error code place holder on the stack\r | |
295 | pushl $19\r | |
296 | jmpCommonIdtEntry \r | |
297 | \r | |
298 | INTUnknown: \r | |
299 | .rept (0x78 - 20)\r | |
300 | pushl $0x0 # push error code place holder on the stack\r | |
301 | # push xxh ; push vector number\r | |
302 | .byte 0x6a\r | |
303 | .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number\r | |
304 | jmpCommonIdtEntry \r | |
305 | .endr\r | |
306 | \r | |
307 | commonIdtEntry: \r | |
308 | pushl %eax\r | |
309 | pushl %ecx\r | |
310 | pushl %edx\r | |
311 | pushl %ebx\r | |
312 | pushl %esp\r | |
313 | pushl %ebp\r | |
314 | pushl %esi\r | |
315 | pushl %edi\r | |
316 | .byte 0x41\r | |
317 | .byte 0x50\r | |
318 | # push r8\r | |
319 | .byte 0x41\r | |
320 | .byte 0x51\r | |
321 | # push r9\r | |
322 | .byte 0x41\r | |
323 | .byte 0x52\r | |
324 | # push r10\r | |
325 | .byte 0x41\r | |
326 | .byte 0x53\r | |
327 | # push r11\r | |
328 | .byte 0x41\r | |
329 | .byte 0x54\r | |
330 | # push r12\r | |
331 | .byte 0x41\r | |
332 | .byte 0x55\r | |
333 | # push r13\r | |
334 | .byte 0x41\r | |
335 | .byte 0x56\r | |
336 | # push r14\r | |
337 | .byte 0x41\r | |
338 | .byte 0x57\r | |
339 | # push r15\r | |
340 | .byte 0x48\r | |
341 | movl %esp,%ebp\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 String1, %esi \r | |
374 | call PrintString\r | |
375 | .byte 0x48\r | |
376 | movl 16*8(%ebp),%eax ## move Int number into RAX \r | |
377 | .byte 0x48\r | |
378 | cmpl $18,%eax\r | |
379 | ja PrintDefaultString\r | |
380 | PrintExceptionString: \r | |
381 | shll $3,%eax ## multiply by 8 to get offset from StringTable to actual string address\r | |
382 | addl StringTable, %eax\r | |
383 | movl (%eax),%esi\r | |
384 | jmp PrintTheString\r | |
385 | PrintDefaultString: \r | |
386 | movl IntUnknownString, %esi\r | |
387 | # patch Int number\r | |
388 | movl %eax,%edx\r | |
389 | call A2C\r | |
390 | movb %al,1(%esi)\r | |
391 | movl %edx,%eax\r | |
392 | shrl $4,%eax\r | |
393 | call A2C\r | |
394 | movb %al,(%esi)\r | |
395 | PrintTheString: \r | |
396 | call PrintString\r | |
397 | movl String2, %esi\r | |
398 | call PrintString\r | |
399 | .byte 0x48\r | |
400 | movl 19*8(%ebp),%eax # CS\r | |
401 | call PrintQword\r | |
402 | movb $':', %al\r | |
403 | movb %al, (%edi)\r | |
404 | addl $2,%edi\r | |
405 | .byte 0x48\r | |
406 | movl 18*8(%ebp),%eax # RIP\r | |
407 | call PrintQword\r | |
408 | movl String3, %esi\r | |
409 | call PrintString\r | |
410 | \r | |
411 | movl $0xb8140,%edi\r | |
412 | \r | |
413 | movl StringRax, %esi\r | |
414 | call PrintString\r | |
415 | .byte 0x48\r | |
416 | movl 15*8(%ebp),%eax\r | |
417 | call PrintQword\r | |
418 | \r | |
419 | movl StringRcx, %esi\r | |
420 | call PrintString\r | |
421 | .byte 0x48\r | |
422 | movl 14*8(%ebp),%eax\r | |
423 | call PrintQword\r | |
424 | \r | |
425 | movl StringRdx, %esi\r | |
426 | call PrintString\r | |
427 | .byte 0x48\r | |
428 | movl 13*8(%ebp),%eax\r | |
429 | call PrintQword\r | |
430 | \r | |
431 | movl $0xb81e0,%edi\r | |
432 | \r | |
433 | movl StringRbx, %esi\r | |
434 | call PrintString\r | |
435 | .byte 0x48\r | |
436 | movl 12*8(%ebp),%eax\r | |
437 | call PrintQword\r | |
438 | \r | |
439 | movl StringRsp, %esi\r | |
440 | call PrintString\r | |
441 | .byte 0x48\r | |
442 | movl 21*8(%ebp),%eax\r | |
443 | call PrintQword\r | |
444 | \r | |
445 | movl StringRbp, %esi\r | |
446 | call PrintString\r | |
447 | .byte 0x48\r | |
448 | movl 10*8(%ebp),%eax\r | |
449 | call PrintQword\r | |
450 | \r | |
451 | movl $0xb8280,%edi\r | |
452 | \r | |
453 | movl StringRsi, %esi\r | |
454 | call PrintString\r | |
455 | .byte 0x48\r | |
456 | movl 9*8(%ebp),%eax\r | |
457 | call PrintQword\r | |
458 | \r | |
459 | movl StringRdi, %esi\r | |
460 | call PrintString\r | |
461 | .byte 0x48\r | |
462 | movl 8*8(%ebp),%eax\r | |
463 | call PrintQword\r | |
464 | \r | |
465 | movl StringEcode, %esi\r | |
466 | call PrintString\r | |
467 | .byte 0x48\r | |
468 | movl 17*8(%ebp),%eax\r | |
469 | call PrintQword\r | |
470 | \r | |
471 | movl $0xb8320,%edi\r | |
472 | \r | |
473 | movl StringR8, %esi\r | |
474 | call PrintString\r | |
475 | .byte 0x48\r | |
476 | movl 7*8(%ebp),%eax\r | |
477 | call PrintQword\r | |
478 | \r | |
479 | movl StringR9, %esi\r | |
480 | call PrintString\r | |
481 | .byte 0x48\r | |
482 | movl 6*8(%ebp),%eax\r | |
483 | call PrintQword\r | |
484 | \r | |
485 | movl StringR10, %esi\r | |
486 | call PrintString\r | |
487 | .byte 0x48\r | |
488 | movl 5*8(%ebp),%eax\r | |
489 | call PrintQword\r | |
490 | \r | |
491 | movl $0xb83c0,%edi\r | |
492 | \r | |
493 | movl StringR11, %esi\r | |
494 | call PrintString\r | |
495 | .byte 0x48\r | |
496 | movl 4*8(%ebp),%eax\r | |
497 | call PrintQword\r | |
498 | \r | |
499 | movl StringR12, %esi\r | |
500 | call PrintString\r | |
501 | .byte 0x48\r | |
502 | movl 3*8(%ebp),%eax\r | |
503 | call PrintQword\r | |
504 | \r | |
505 | movl StringR13, %esi\r | |
506 | call PrintString\r | |
507 | .byte 0x48\r | |
508 | movl 2*8(%ebp),%eax\r | |
509 | call PrintQword\r | |
510 | \r | |
511 | movl $0xb8460,%edi\r | |
512 | \r | |
513 | movl StringR14, %esi\r | |
514 | call PrintString\r | |
515 | .byte 0x48\r | |
516 | movl 1*8(%ebp),%eax\r | |
517 | call PrintQword\r | |
518 | \r | |
519 | movl StringR15, %esi\r | |
520 | call PrintString\r | |
521 | .byte 0x48\r | |
522 | movl 0*8(%ebp),%eax\r | |
523 | call PrintQword\r | |
524 | \r | |
525 | movl StringSs, %esi\r | |
526 | call PrintString\r | |
527 | .byte 0x48\r | |
528 | movl 22*8(%ebp),%eax\r | |
529 | call PrintQword\r | |
530 | \r | |
531 | movl $0xb8500,%edi\r | |
532 | \r | |
533 | movl StringRflags, %esi\r | |
534 | call PrintString\r | |
535 | .byte 0x48\r | |
536 | movl 20*8(%ebp),%eax\r | |
537 | call PrintQword\r | |
538 | \r | |
539 | movl $0xb8640,%edi\r | |
540 | \r | |
541 | movl %ebp,%esi\r | |
542 | addl $23*8,%esi\r | |
543 | movl $4,%ecx\r | |
544 | \r | |
545 | \r | |
546 | OuterLoop: \r | |
547 | pushl %ecx\r | |
548 | movl $4,%ecx\r | |
549 | .byte 0x48\r | |
550 | movl %edi,%edx\r | |
551 | \r | |
552 | InnerLoop: \r | |
553 | .byte 0x48\r | |
554 | movl (%esi),%eax\r | |
555 | call PrintQword\r | |
556 | addl $8,%esi\r | |
557 | mov $0x00, %al \r | |
558 | movb %al,(%edi)\r | |
559 | addl $2,%edi\r | |
560 | loop InnerLoop\r | |
561 | \r | |
562 | popl %ecx\r | |
563 | addl $0xa0,%edx\r | |
564 | movl %edx,%edi\r | |
565 | loop OuterLoop\r | |
566 | \r | |
567 | \r | |
568 | movl $0xb8960,%edi\r | |
569 | \r | |
570 | .byte 0x48\r | |
571 | movl 18*8(%ebp),%eax # RIP\r | |
572 | subl $8*8,%eax\r | |
573 | .byte 0x48\r | |
574 | movl %eax,%esi # esi = rip - 8 QWORD linear (total 16 QWORD)\r | |
575 | \r | |
576 | movl $4,%ecx\r | |
577 | \r | |
578 | OuterLoop1: \r | |
579 | pushl %ecx\r | |
580 | movl $4,%ecx\r | |
581 | movl %edi,%edx\r | |
582 | \r | |
583 | InnerLoop1: \r | |
584 | .byte 0x48\r | |
585 | movl (%esi),%eax\r | |
586 | call PrintQword\r | |
587 | addl $8,%esi\r | |
588 | movb $0x00, %al\r | |
589 | movb %al,(%edi)\r | |
590 | addl $2,%edi\r | |
591 | loop InnerLoop1\r | |
592 | \r | |
593 | popl %ecx\r | |
594 | addl $0xa0,%edx\r | |
595 | movl %edx,%edi\r | |
596 | loop OuterLoop1\r | |
597 | \r | |
598 | \r | |
599 | \r | |
600 | #wbinvd\r | |
601 | LN_C1: \r | |
602 | jmp LN_C1\r | |
603 | \r | |
604 | #\r | |
605 | # return\r | |
606 | #\r | |
607 | movl %ebp,%esp\r | |
608 | # mov rsp, rbp\r | |
609 | .byte 0x41\r | |
610 | .byte 0x5f\r | |
611 | # pop r15\r | |
612 | .byte 0x41\r | |
613 | .byte 0x5e\r | |
614 | # pop r14\r | |
615 | .byte 0x41\r | |
616 | .byte 0x5d\r | |
617 | # pop r13\r | |
618 | .byte 0x41\r | |
619 | .byte 0x5c\r | |
620 | # pop r12\r | |
621 | .byte 0x41\r | |
622 | .byte 0x5b\r | |
623 | # pop r11\r | |
624 | .byte 0x41\r | |
625 | .byte 0x5a\r | |
626 | # pop r10\r | |
627 | .byte 0x41\r | |
628 | .byte 0x59\r | |
629 | # pop r9\r | |
630 | .byte 0x41\r | |
631 | .byte 0x58\r | |
632 | # pop r8\r | |
633 | popl %edi\r | |
634 | popl %esi\r | |
635 | popl %ebp\r | |
636 | popl %eax # esp\r | |
637 | popl %ebx\r | |
638 | popl %edx\r | |
639 | popl %ecx\r | |
640 | popl %eax\r | |
641 | \r | |
642 | .byte 0x48\r | |
643 | .byte 0x83\r | |
644 | .byte 0xc4\r | |
645 | .byte 0x10\r | |
646 | # add esp, 16 ; error code and INT number\r | |
647 | \r | |
648 | .byte 0x48\r | |
649 | .byte 0xcf\r | |
650 | # iretq\r | |
651 | \r | |
652 | PrintString: \r | |
653 | pushl %eax\r | |
654 | LN_C2: \r | |
655 | movb (%esi), %al\r | |
656 | cmpb $0,%al\r | |
657 | je LN_C3\r | |
658 | movb %al, (%edi)\r | |
659 | .byte 0xff\r | |
660 | .byte 0xc6\r | |
661 | # inc esi\r | |
662 | addl $2,%edi\r | |
663 | jmp LN_C2\r | |
664 | LN_C3: \r | |
665 | popl %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 | pushl %ecx\r | |
672 | pushl %ebx\r | |
673 | pushl %eax\r | |
674 | \r | |
675 | .byte 0x48\r | |
676 | .byte 0xc7\r | |
677 | .byte 0xc1\r | |
678 | .long 16\r | |
679 | # mov rcx, 16\r | |
680 | looptop: \r | |
681 | .byte 0x48\r | |
682 | roll $4,%eax\r | |
683 | movb %al,%bl\r | |
684 | andb $0xf,%bl\r | |
685 | addb $'0', %bl\r | |
686 | cmpb $'9', %bl\r | |
687 | jle @f\r | |
688 | addb $7,%bl\r | |
689 | @@: \r | |
690 | movb %bl, (%edi)\r | |
691 | addl $2,%edi\r | |
692 | loop looptop\r | |
693 | #wbinvd\r | |
694 | \r | |
695 | popl %eax\r | |
696 | popl %ebx\r | |
697 | popl %ecx\r | |
698 | ret\r | |
699 | \r | |
700 | ClearScreen: \r | |
701 | pushl %eax\r | |
702 | pushl %ecx\r | |
703 | \r | |
704 | movb $0x00, %al\r | |
705 | movb $0xc,%ah\r | |
706 | movl $0xb8000,%edi\r | |
707 | movl $80*24,%ecx\r | |
708 | LN_C4: \r | |
709 | movw %ax, (%edi)\r | |
710 | addl $2,%edi\r | |
711 | loop LN_C4\r | |
712 | movl $0xb8000,%edi\r | |
713 | \r | |
714 | popl %ecx\r | |
715 | popl %eax\r | |
716 | \r | |
717 | ret\r | |
718 | \r | |
719 | A2C: \r | |
720 | andb $0xf,%al\r | |
721 | addb $'0', %al\r | |
722 | cmpb $'9', %al\r | |
723 | jle @f\r | |
724 | addb $7,%al\r | |
725 | LN_C5: \r | |
726 | ret\r | |
727 | \r | |
728 | String1: .asciz "*** INT "\r | |
729 | \r | |
730 | Int0String: .asciz "00h Divide by 0 -"\r | |
731 | Int1String: .asciz "01h Debug exception -"\r | |
732 | Int2String: .asciz "02h NMI -"\r | |
733 | Int3String: .asciz "03h Breakpoint -"\r | |
734 | Int4String: .asciz "04h Overflow -"\r | |
735 | Int5String: .asciz "05h Bound -"\r | |
736 | Int6String: .asciz "06h Invalid opcode -"\r | |
737 | Int7String: .asciz "07h Device not available -"\r | |
738 | Int8String: .asciz "08h Double fault -"\r | |
739 | Int9String: .asciz "09h Coprocessor seg overrun (reserved) -"\r | |
740 | Int10String: .asciz "0Ah Invalid TSS -"\r | |
741 | Int11String: .asciz "0Bh Segment not present -"\r | |
742 | Int12String: .asciz "0Ch Stack fault -"\r | |
743 | Int13String: .asciz "0Dh General protection fault -"\r | |
744 | Int14String: .asciz "0Eh Page fault -"\r | |
745 | Int15String: .asciz "0Fh (Intel reserved) -"\r | |
746 | Int16String: .asciz "10h Floating point error -"\r | |
747 | Int17String: .asciz "11h Alignment check -"\r | |
748 | Int18String: .asciz "12h Machine check -"\r | |
749 | Int19String: .asciz "13h SIMD Floating-Point Exception -"\r | |
750 | IntUnknownString: .asciz "??h Unknown interrupt -"\r | |
751 | \r | |
752 | StringTable: .long Int0String, Int1String, Int2String, Int3String, \\r | |
753 | Int4String, Int5String, Int6String, Int7String, \\r | |
754 | Int8String, Int9String, Int10String, Int11String, \\r | |
755 | Int12String, Int13String, Int14String, Int15String,\\r | |
756 | Int16String, Int17String, Int18String, Int19String\r | |
757 | \r | |
758 | String2: .asciz " HALT!! *** ("\r | |
759 | String3: .asciz ")"\r | |
760 | StringRax: .asciz "RAX="\r | |
761 | StringRcx: .asciz " RCX="\r | |
762 | StringRdx: .asciz " RDX="\r | |
763 | StringRbx: .asciz "RBX="\r | |
764 | StringRsp: .asciz " RSP="\r | |
765 | StringRbp: .asciz " RBP="\r | |
766 | StringRsi: .asciz "RSI="\r | |
767 | StringRdi: .asciz " RDI="\r | |
768 | StringEcode: .asciz " ECODE="\r | |
769 | StringR8: .asciz "R8 ="\r | |
770 | StringR9: .asciz " R9 ="\r | |
771 | StringR10: .asciz " R10="\r | |
772 | StringR11: .asciz "R11="\r | |
773 | StringR12: .asciz " R12="\r | |
774 | StringR13: .asciz " R13="\r | |
775 | StringR14: .asciz "R14="\r | |
776 | StringR15: .asciz " R15="\r | |
777 | StringSs: .asciz " SS ="\r | |
778 | StringRflags: .asciz "RFLAGS="\r | |
779 | \r | |
780 | Idtr: .float 0\r | |
781 | .float 0\r | |
782 | \r | |
783 | .org 0x21ffe\r | |
784 | BlockSignature: \r | |
785 | .word 0xaa55\r | |
786 | \r |