]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BootSector/efi64.S
fcb31013b549eed6a5bf0faf5e5d506ab6b2684e
[mirror_edk2.git] / DuetPkg / BootSector / efi64.S
1 #------------------------------------------------------------------------------
2 #*
3 #* Copyright 2006, Intel Corporation
4 #* All rights reserved. This program and the accompanying materials
5 #* are licensed and made available under the terms and conditions of the BSD License
6 #* which accompanies this distribution. The full text of the license may be found at
7 #* http://opensource.org/licenses/bsd-license.php
8 #*
9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 #*
12 #* efi64.asm
13 #*
14 #* Abstract:
15 #*
16 #------------------------------------------------------------------------------
17
18 ##############################################################################
19 # Now in 64-bit long mode.
20 ##############################################################################
21
22 .486:
23 .stack:
24 .code:
25 .org 0x21000
26
27 .equ DEFAULT_HANDLER_SIZE, INT1 - INT0
28
29 .macro jmpCommonIdtEntry
30 # jmp commonIdtEntry - this must be hand coded to keep the assembler from
31 # using a 8 bit reletive jump when the entries are
32 # within 255 bytes of the common entry. This must
33 # be done to maintain the consistency of the size
34 # of entry points...
35 .byte 0xe9 # jmp 16 bit relative
36 .long commonIdtEntry - . - 4 # offset to jump to
37 .endm
38
39
40 Start:
41
42 movl $0x001fffe8,%esp # make final stack aligned
43
44 # set OSFXSR and OSXMMEXCPT because some code will use XMM register
45 .byte 0xf
46 .byte 0x20
47 .byte 0xe0
48 # mov rax, cr4
49 btsl $9,%eax
50 btsl $0xa,%eax
51 .byte 0xf
52 .byte 0x22
53 .byte 0xe0
54 # mov cr4, rax
55
56 call ClearScreen
57
58 # Populate IDT with meaningful offsets for exception handlers...
59 sidt Idtr
60
61
62 movl Halt, %eax
63 movl %eax,%ebx # use bx to copy 15..0 to descriptors
64 shrl $16,%eax # use ax to copy 31..16 to descriptors
65 # 63..32 of descriptors is 0
66 movl $0x78,%ecx # 78h IDT entries to initialize with unique entry points (exceptions)
67 movl (Idtr + 2), %esi
68 movl (%esi),%edi
69
70 LOOP_1: # loop through all IDT entries exception handlers and initialize to default handler
71 movw %bx, (%edi) # write bits 15..0 of offset
72 movw $0x38, 2(%edi) # SYS_CODE_SEL64 from GDT
73 movw $(0x0e00 | 0x8000), 4(%edi) # type = 386 interrupt gate, present
74 movw %ax, 6(%edi) # write bits 31..16 of offset
75 movl $0, 8(%edi) # write bits 31..16 of offset
76 addl $16, %edi # move up to next descriptor
77 addw DEFAULT_HANDLER_SIZE, %bx # move to next entry point
78 loopl LOOP_1 # loop back through again until all descriptors are initialized
79
80 ## at this point edi contains the offset of the descriptor for INT 20
81 ## and bx contains the low 16 bits of the offset of the default handler
82 ## so initialize all the rest of the descriptors with these two values...
83 # mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
84 #@@: ; loop through all IDT entries exception handlers and initialize to default handler
85 # mov word ptr [edi], bx ; write bits 15..0 of offset
86 # mov word ptr [edi+2], 38h ; SYS_CODE64_SEL from GDT
87 # mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
88 # mov word ptr [edi+6], ax ; write bits 31..16 of offset
89 # mov dword ptr [edi+8], 0 ; write bits 63..32 of offset
90 # add edi, 16 ; move up to next descriptor
91 # loop @b ; loop back through again until all descriptors are initialized
92
93
94 ## DUMP location of IDT and several of the descriptors
95 # mov ecx, 8
96 # mov eax, [offset Idtr + 2]
97 # mov eax, [eax]
98 # mov edi, 0b8000h
99 # call PrintQword
100 # mov esi, eax
101 # mov edi, 0b80a0h
102 # jmp OuterLoop
103
104 ##
105 ## just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
106 # mov eax, 011111111h
107 # mov ebx, 022222222h
108 # mov ecx, 033333333h
109 # mov edx, 044444444h
110 # mov ebp, 055555555h
111 # mov esi, 066666666h
112 # mov edi, 077777777h
113 # push 011111111h
114 # push 022222222h
115 # push 033333333h
116 # int 119
117
118 movl $0x22000,%esi # esi = 22000
119 movl 0x14(%esi),%eax # eax = [22014]
120 addl %eax,%esi # esi = 22000 + [22014] = Base of EFILDR.C
121 movl 0x3c(%esi),%ebp # ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
122 addl %esi,%ebp
123 movl 0x30(%ebp),%edi # edi = [[22000 + [22014] + 3c] + 2c] = ImageBase (63..32 is zero, ignore)
124 movl 0x28(%ebp),%eax # eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
125 addl %edi,%eax # eax = ImageBase + EntryPoint
126 movl %ebx, EfiLdrOffset
127 movl %eax, (%ebx) # Modify far jump instruction for correct entry point
128
129 movw 6(%ebp), %bx # bx = Number of sections
130 xorl %eax,%eax
131 movw 0x14(%ebp), %ax # ax = Optional Header Size
132 addl %eax,%ebp
133 addl $0x18,%ebp # ebp = Start of 1st Section
134
135 SectionLoop:
136 pushl %esi # Save Base of EFILDR.C
137 pushl %edi # Save ImageBase
138 addl 0x14(%ebp),%esi # esi = Base of EFILDR.C + PointerToRawData
139 addl 0x0c(%ebp),%edi # edi = ImageBase + VirtualAddress
140 movl 0x10(%ebp),%ecx # ecs = SizeOfRawData
141
142 cld
143 shrl $2,%ecx
144 rep
145 movsl
146
147 popl %edi # Restore ImageBase
148 popl %esi # Restore Base of EFILDR.C
149
150 addw $0x28,%bp # ebp = ebp + 028h = Pointer to next section record
151 .byte 0x66
152 .byte 0xff
153 .byte 0xcb
154 # dec bx
155 cmpw $0,%bx
156 jne SectionLoop
157
158 movl (Idtr), %eax # get size of IDT
159 movzx (%edx), %eax
160 .byte 0xff
161 .byte 0xc0
162 # inc eax
163 addl 2(%edx), %eax # add to base of IDT to get location of memory map...
164 xorl %ecx,%ecx
165 movl %eax,%ecx # put argument to RCX
166
167 .byte 0x48
168 .byte 0xc7
169 .byte 0xc0
170 EfiLdrOffset:
171 .long 0x00401000 # Offset of EFILDR
172 # mov rax, 401000h
173 .byte 0x50
174 # push rax
175
176 # ret
177 .byte 0xc3
178
179 # db "**** DEFAULT IDT ENTRY ***",0
180 .p2align 1
181 Halt:
182 INT0:
183 pushl $0x0 # push error code place holder on the stack
184 pushl $0x0
185 jmpCommonIdtEntry
186 # db 0e9h ; jmp 16 bit reletive
187 # dd commonIdtEntry - $ - 4 ; offset to jump to
188
189 INT1:
190 pushl $0x0 # push error code place holder on the stack
191 pushl $0x1
192 jmpCommonIdtEntry
193
194 INT2:
195 pushl $0x0 # push error code place holder on the stack
196 pushl $0x2
197 jmpCommonIdtEntry
198
199 INT3:
200 pushl $0x0 # push error code place holder on the stack
201 pushl $0x3
202 jmpCommonIdtEntry
203
204 INT4:
205 pushl $0x0 # push error code place holder on the stack
206 pushl $0x4
207 jmpCommonIdtEntry
208
209 INT5:
210 pushl $0x0 # push error code place holder on the stack
211 pushl $0x5
212 jmpCommonIdtEntry
213
214 INT6:
215 pushl $0x0 # push error code place holder on the stack
216 pushl $0x6
217 jmpCommonIdtEntry
218
219 INT7:
220 pushl $0x0 # push error code place holder on the stack
221 pushl $0x7
222 jmpCommonIdtEntry
223
224 INT8:
225 # Double fault causes an error code to be pushed so no phony push necessary
226 nop
227 nop
228 pushl $0x8
229 jmpCommonIdtEntry
230
231 INT9:
232 pushl $0x0 # push error code place holder on the stack
233 pushl $0x9
234 jmpCommonIdtEntry
235
236 INT10:
237 # Invalid TSS causes an error code to be pushed so no phony push necessary
238 nop
239 nop
240 pushl $10
241 jmpCommonIdtEntry
242
243 INT11:
244 # Segment Not Present causes an error code to be pushed so no phony push necessary
245 nop
246 nop
247 pushl $11
248 jmpCommonIdtEntry
249
250 INT12:
251 # Stack fault causes an error code to be pushed so no phony push necessary
252 nop
253 nop
254 pushl $12
255 jmpCommonIdtEntry
256
257 INT13:
258 # GP fault causes an error code to be pushed so no phony push necessary
259 nop
260 nop
261 pushl $13
262 jmpCommonIdtEntry
263
264 INT14:
265 # Page fault causes an error code to be pushed so no phony push necessary
266 nop
267 nop
268 pushl $14
269 jmpCommonIdtEntry
270
271 INT15:
272 pushl $0x0 # push error code place holder on the stack
273 pushl $15
274 jmpCommonIdtEntry
275
276 INT16:
277 pushl $0x0 # push error code place holder on the stack
278 pushl $16
279 jmpCommonIdtEntry
280
281 INT17:
282 # Alignment check causes an error code to be pushed so no phony push necessary
283 nop
284 nop
285 pushl $17
286 jmpCommonIdtEntry
287
288 INT18:
289 pushl $0x0 # push error code place holder on the stack
290 pushl $18
291 jmpCommonIdtEntry
292
293 INT19:
294 pushl $0x0 # push error code place holder on the stack
295 pushl $19
296 jmpCommonIdtEntry
297
298 INTUnknown:
299 # The following segment repeats (0x78 - 20) times:
300 # No. 1
301 pushl $0x0 # push error code place holder on the stack
302 # push xxh ; push vector number
303 .byte 0x6a
304 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
305 jmpCommonIdtEntry
306 # No. 2
307 pushl $0x0 # push error code place holder on the stack
308 # push xxh ; push vector number
309 .byte 0x6a
310 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
311 jmpCommonIdtEntry
312 # No. 3
313 pushl $0x0 # push error code place holder on the stack
314 # push xxh ; push vector number
315 .byte 0x6a
316 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
317 jmpCommonIdtEntry
318 # No. 4
319 pushl $0x0 # push error code place holder on the stack
320 # push xxh ; push vector number
321 .byte 0x6a
322 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
323 jmpCommonIdtEntry
324 # No. 5
325 pushl $0x0 # push error code place holder on the stack
326 # push xxh ; push vector number
327 .byte 0x6a
328 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
329 jmpCommonIdtEntry
330 # No. 6
331 pushl $0x0 # push error code place holder on the stack
332 # push xxh ; push vector number
333 .byte 0x6a
334 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
335 jmpCommonIdtEntry
336 # No. 7
337 pushl $0x0 # push error code place holder on the stack
338 # push xxh ; push vector number
339 .byte 0x6a
340 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
341 jmpCommonIdtEntry
342 # No. 8
343 pushl $0x0 # push error code place holder on the stack
344 # push xxh ; push vector number
345 .byte 0x6a
346 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
347 jmpCommonIdtEntry
348 # No. 9
349 pushl $0x0 # push error code place holder on the stack
350 # push xxh ; push vector number
351 .byte 0x6a
352 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
353 jmpCommonIdtEntry
354 # No. 10
355 pushl $0x0 # push error code place holder on the stack
356 # push xxh ; push vector number
357 .byte 0x6a
358 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
359 jmpCommonIdtEntry
360 # No. 11
361 pushl $0x0 # push error code place holder on the stack
362 # push xxh ; push vector number
363 .byte 0x6a
364 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
365 jmpCommonIdtEntry
366 # No. 12
367 pushl $0x0 # push error code place holder on the stack
368 # push xxh ; push vector number
369 .byte 0x6a
370 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
371 jmpCommonIdtEntry
372 # No. 13
373 pushl $0x0 # push error code place holder on the stack
374 # push xxh ; push vector number
375 .byte 0x6a
376 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
377 jmpCommonIdtEntry
378 # No. 14
379 pushl $0x0 # push error code place holder on the stack
380 # push xxh ; push vector number
381 .byte 0x6a
382 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
383 jmpCommonIdtEntry
384 # No. 15
385 pushl $0x0 # push error code place holder on the stack
386 # push xxh ; push vector number
387 .byte 0x6a
388 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
389 jmpCommonIdtEntry
390 # No. 16
391 pushl $0x0 # push error code place holder on the stack
392 # push xxh ; push vector number
393 .byte 0x6a
394 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
395 jmpCommonIdtEntry
396 # No. 17
397 pushl $0x0 # push error code place holder on the stack
398 # push xxh ; push vector number
399 .byte 0x6a
400 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
401 jmpCommonIdtEntry
402 # No. 18
403 pushl $0x0 # push error code place holder on the stack
404 # push xxh ; push vector number
405 .byte 0x6a
406 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
407 jmpCommonIdtEntry
408 # No. 19
409 pushl $0x0 # push error code place holder on the stack
410 # push xxh ; push vector number
411 .byte 0x6a
412 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
413 jmpCommonIdtEntry
414 # No. 20
415 pushl $0x0 # push error code place holder on the stack
416 # push xxh ; push vector number
417 .byte 0x6a
418 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
419 jmpCommonIdtEntry
420 # No. 21
421 pushl $0x0 # push error code place holder on the stack
422 # push xxh ; push vector number
423 .byte 0x6a
424 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
425 jmpCommonIdtEntry
426 # No. 22
427 pushl $0x0 # push error code place holder on the stack
428 # push xxh ; push vector number
429 .byte 0x6a
430 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
431 jmpCommonIdtEntry
432 # No. 23
433 pushl $0x0 # push error code place holder on the stack
434 # push xxh ; push vector number
435 .byte 0x6a
436 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
437 jmpCommonIdtEntry
438 # No. 24
439 pushl $0x0 # push error code place holder on the stack
440 # push xxh ; push vector number
441 .byte 0x6a
442 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
443 jmpCommonIdtEntry
444 # No. 25
445 pushl $0x0 # push error code place holder on the stack
446 # push xxh ; push vector number
447 .byte 0x6a
448 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
449 jmpCommonIdtEntry
450 # No. 26
451 pushl $0x0 # push error code place holder on the stack
452 # push xxh ; push vector number
453 .byte 0x6a
454 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
455 jmpCommonIdtEntry
456 # No. 27
457 pushl $0x0 # push error code place holder on the stack
458 # push xxh ; push vector number
459 .byte 0x6a
460 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
461 jmpCommonIdtEntry
462 # No. 28
463 pushl $0x0 # push error code place holder on the stack
464 # push xxh ; push vector number
465 .byte 0x6a
466 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
467 jmpCommonIdtEntry
468 # No. 29
469 pushl $0x0 # push error code place holder on the stack
470 # push xxh ; push vector number
471 .byte 0x6a
472 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
473 jmpCommonIdtEntry
474 # No. 30
475 pushl $0x0 # push error code place holder on the stack
476 # push xxh ; push vector number
477 .byte 0x6a
478 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
479 jmpCommonIdtEntry
480 # No. 31
481 pushl $0x0 # push error code place holder on the stack
482 # push xxh ; push vector number
483 .byte 0x6a
484 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
485 jmpCommonIdtEntry
486 # No. 32
487 pushl $0x0 # push error code place holder on the stack
488 # push xxh ; push vector number
489 .byte 0x6a
490 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
491 jmpCommonIdtEntry
492 # No. 33
493 pushl $0x0 # push error code place holder on the stack
494 # push xxh ; push vector number
495 .byte 0x6a
496 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
497 jmpCommonIdtEntry
498 # No. 34
499 pushl $0x0 # push error code place holder on the stack
500 # push xxh ; push vector number
501 .byte 0x6a
502 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
503 jmpCommonIdtEntry
504 # No. 35
505 pushl $0x0 # push error code place holder on the stack
506 # push xxh ; push vector number
507 .byte 0x6a
508 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
509 jmpCommonIdtEntry
510 # No. 36
511 pushl $0x0 # push error code place holder on the stack
512 # push xxh ; push vector number
513 .byte 0x6a
514 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
515 jmpCommonIdtEntry
516 # No. 37
517 pushl $0x0 # push error code place holder on the stack
518 # push xxh ; push vector number
519 .byte 0x6a
520 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
521 jmpCommonIdtEntry
522 # No. 38
523 pushl $0x0 # push error code place holder on the stack
524 # push xxh ; push vector number
525 .byte 0x6a
526 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
527 jmpCommonIdtEntry
528 # No. 39
529 pushl $0x0 # push error code place holder on the stack
530 # push xxh ; push vector number
531 .byte 0x6a
532 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
533 jmpCommonIdtEntry
534 # No. 40
535 pushl $0x0 # push error code place holder on the stack
536 # push xxh ; push vector number
537 .byte 0x6a
538 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
539 jmpCommonIdtEntry
540 # No. 41
541 pushl $0x0 # push error code place holder on the stack
542 # push xxh ; push vector number
543 .byte 0x6a
544 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
545 jmpCommonIdtEntry
546 # No. 42
547 pushl $0x0 # push error code place holder on the stack
548 # push xxh ; push vector number
549 .byte 0x6a
550 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
551 jmpCommonIdtEntry
552 # No. 43
553 pushl $0x0 # push error code place holder on the stack
554 # push xxh ; push vector number
555 .byte 0x6a
556 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
557 jmpCommonIdtEntry
558 # No. 44
559 pushl $0x0 # push error code place holder on the stack
560 # push xxh ; push vector number
561 .byte 0x6a
562 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
563 jmpCommonIdtEntry
564 # No. 45
565 pushl $0x0 # push error code place holder on the stack
566 # push xxh ; push vector number
567 .byte 0x6a
568 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
569 jmpCommonIdtEntry
570 # No. 46
571 pushl $0x0 # push error code place holder on the stack
572 # push xxh ; push vector number
573 .byte 0x6a
574 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
575 jmpCommonIdtEntry
576 # No. 47
577 pushl $0x0 # push error code place holder on the stack
578 # push xxh ; push vector number
579 .byte 0x6a
580 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
581 jmpCommonIdtEntry
582 # No. 48
583 pushl $0x0 # push error code place holder on the stack
584 # push xxh ; push vector number
585 .byte 0x6a
586 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
587 jmpCommonIdtEntry
588 # No. 49
589 pushl $0x0 # push error code place holder on the stack
590 # push xxh ; push vector number
591 .byte 0x6a
592 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
593 jmpCommonIdtEntry
594 # No. 50
595 pushl $0x0 # push error code place holder on the stack
596 # push xxh ; push vector number
597 .byte 0x6a
598 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
599 jmpCommonIdtEntry
600 # No. 51
601 pushl $0x0 # push error code place holder on the stack
602 # push xxh ; push vector number
603 .byte 0x6a
604 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
605 jmpCommonIdtEntry
606 # No. 52
607 pushl $0x0 # push error code place holder on the stack
608 # push xxh ; push vector number
609 .byte 0x6a
610 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
611 jmpCommonIdtEntry
612 # No. 53
613 pushl $0x0 # push error code place holder on the stack
614 # push xxh ; push vector number
615 .byte 0x6a
616 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
617 jmpCommonIdtEntry
618 # No. 54
619 pushl $0x0 # push error code place holder on the stack
620 # push xxh ; push vector number
621 .byte 0x6a
622 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
623 jmpCommonIdtEntry
624 # No. 55
625 pushl $0x0 # push error code place holder on the stack
626 # push xxh ; push vector number
627 .byte 0x6a
628 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
629 jmpCommonIdtEntry
630 # No. 56
631 pushl $0x0 # push error code place holder on the stack
632 # push xxh ; push vector number
633 .byte 0x6a
634 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
635 jmpCommonIdtEntry
636 # No. 57
637 pushl $0x0 # push error code place holder on the stack
638 # push xxh ; push vector number
639 .byte 0x6a
640 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
641 jmpCommonIdtEntry
642 # No. 58
643 pushl $0x0 # push error code place holder on the stack
644 # push xxh ; push vector number
645 .byte 0x6a
646 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
647 jmpCommonIdtEntry
648 # No. 59
649 pushl $0x0 # push error code place holder on the stack
650 # push xxh ; push vector number
651 .byte 0x6a
652 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
653 jmpCommonIdtEntry
654 # No. 60
655 pushl $0x0 # push error code place holder on the stack
656 # push xxh ; push vector number
657 .byte 0x6a
658 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
659 jmpCommonIdtEntry
660 # No. 61
661 pushl $0x0 # push error code place holder on the stack
662 # push xxh ; push vector number
663 .byte 0x6a
664 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
665 jmpCommonIdtEntry
666 # No. 62
667 pushl $0x0 # push error code place holder on the stack
668 # push xxh ; push vector number
669 .byte 0x6a
670 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
671 jmpCommonIdtEntry
672 # No. 63
673 pushl $0x0 # push error code place holder on the stack
674 # push xxh ; push vector number
675 .byte 0x6a
676 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
677 jmpCommonIdtEntry
678 # No. 64
679 pushl $0x0 # push error code place holder on the stack
680 # push xxh ; push vector number
681 .byte 0x6a
682 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
683 jmpCommonIdtEntry
684 # No. 65
685 pushl $0x0 # push error code place holder on the stack
686 # push xxh ; push vector number
687 .byte 0x6a
688 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
689 jmpCommonIdtEntry
690 # No. 66
691 pushl $0x0 # push error code place holder on the stack
692 # push xxh ; push vector number
693 .byte 0x6a
694 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
695 jmpCommonIdtEntry
696 # No. 67
697 pushl $0x0 # push error code place holder on the stack
698 # push xxh ; push vector number
699 .byte 0x6a
700 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
701 jmpCommonIdtEntry
702 # No. 68
703 pushl $0x0 # push error code place holder on the stack
704 # push xxh ; push vector number
705 .byte 0x6a
706 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
707 jmpCommonIdtEntry
708 # No. 69
709 pushl $0x0 # push error code place holder on the stack
710 # push xxh ; push vector number
711 .byte 0x6a
712 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
713 jmpCommonIdtEntry
714 # No. 70
715 pushl $0x0 # push error code place holder on the stack
716 # push xxh ; push vector number
717 .byte 0x6a
718 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
719 jmpCommonIdtEntry
720 # No. 71
721 pushl $0x0 # push error code place holder on the stack
722 # push xxh ; push vector number
723 .byte 0x6a
724 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
725 jmpCommonIdtEntry
726 # No. 72
727 pushl $0x0 # push error code place holder on the stack
728 # push xxh ; push vector number
729 .byte 0x6a
730 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
731 jmpCommonIdtEntry
732 # No. 73
733 pushl $0x0 # push error code place holder on the stack
734 # push xxh ; push vector number
735 .byte 0x6a
736 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
737 jmpCommonIdtEntry
738 # No. 74
739 pushl $0x0 # push error code place holder on the stack
740 # push xxh ; push vector number
741 .byte 0x6a
742 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
743 jmpCommonIdtEntry
744 # No. 75
745 pushl $0x0 # push error code place holder on the stack
746 # push xxh ; push vector number
747 .byte 0x6a
748 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
749 jmpCommonIdtEntry
750 # No. 76
751 pushl $0x0 # push error code place holder on the stack
752 # push xxh ; push vector number
753 .byte 0x6a
754 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
755 jmpCommonIdtEntry
756 # No. 77
757 pushl $0x0 # push error code place holder on the stack
758 # push xxh ; push vector number
759 .byte 0x6a
760 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
761 jmpCommonIdtEntry
762 # No. 78
763 pushl $0x0 # push error code place holder on the stack
764 # push xxh ; push vector number
765 .byte 0x6a
766 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
767 jmpCommonIdtEntry
768 # No. 79
769 pushl $0x0 # push error code place holder on the stack
770 # push xxh ; push vector number
771 .byte 0x6a
772 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
773 jmpCommonIdtEntry
774 # No. 80
775 pushl $0x0 # push error code place holder on the stack
776 # push xxh ; push vector number
777 .byte 0x6a
778 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
779 jmpCommonIdtEntry
780 # No. 81
781 pushl $0x0 # push error code place holder on the stack
782 # push xxh ; push vector number
783 .byte 0x6a
784 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
785 jmpCommonIdtEntry
786 # No. 82
787 pushl $0x0 # push error code place holder on the stack
788 # push xxh ; push vector number
789 .byte 0x6a
790 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
791 jmpCommonIdtEntry
792 # No. 83
793 pushl $0x0 # push error code place holder on the stack
794 # push xxh ; push vector number
795 .byte 0x6a
796 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
797 jmpCommonIdtEntry
798 # No. 84
799 pushl $0x0 # push error code place holder on the stack
800 # push xxh ; push vector number
801 .byte 0x6a
802 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
803 jmpCommonIdtEntry
804 # No. 85
805 pushl $0x0 # push error code place holder on the stack
806 # push xxh ; push vector number
807 .byte 0x6a
808 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
809 jmpCommonIdtEntry
810 # No. 86
811 pushl $0x0 # push error code place holder on the stack
812 # push xxh ; push vector number
813 .byte 0x6a
814 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
815 jmpCommonIdtEntry
816 # No. 87
817 pushl $0x0 # push error code place holder on the stack
818 # push xxh ; push vector number
819 .byte 0x6a
820 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
821 jmpCommonIdtEntry
822 # No. 88
823 pushl $0x0 # push error code place holder on the stack
824 # push xxh ; push vector number
825 .byte 0x6a
826 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
827 jmpCommonIdtEntry
828 # No. 89
829 pushl $0x0 # push error code place holder on the stack
830 # push xxh ; push vector number
831 .byte 0x6a
832 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
833 jmpCommonIdtEntry
834 # No. 90
835 pushl $0x0 # push error code place holder on the stack
836 # push xxh ; push vector number
837 .byte 0x6a
838 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
839 jmpCommonIdtEntry
840 # No. 91
841 pushl $0x0 # push error code place holder on the stack
842 # push xxh ; push vector number
843 .byte 0x6a
844 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
845 jmpCommonIdtEntry
846 # No. 92
847 pushl $0x0 # push error code place holder on the stack
848 # push xxh ; push vector number
849 .byte 0x6a
850 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
851 jmpCommonIdtEntry
852 # No. 93
853 pushl $0x0 # push error code place holder on the stack
854 # push xxh ; push vector number
855 .byte 0x6a
856 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
857 jmpCommonIdtEntry
858 # No. 94
859 pushl $0x0 # push error code place holder on the stack
860 # push xxh ; push vector number
861 .byte 0x6a
862 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
863 jmpCommonIdtEntry
864 # No. 95
865 pushl $0x0 # push error code place holder on the stack
866 # push xxh ; push vector number
867 .byte 0x6a
868 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
869 jmpCommonIdtEntry
870 # No. 96
871 pushl $0x0 # push error code place holder on the stack
872 # push xxh ; push vector number
873 .byte 0x6a
874 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
875 jmpCommonIdtEntry
876 # No. 97
877 pushl $0x0 # push error code place holder on the stack
878 # push xxh ; push vector number
879 .byte 0x6a
880 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
881 jmpCommonIdtEntry
882 # No. 98
883 pushl $0x0 # push error code place holder on the stack
884 # push xxh ; push vector number
885 .byte 0x6a
886 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
887 jmpCommonIdtEntry
888 # No. 99
889 pushl $0x0 # push error code place holder on the stack
890 # push xxh ; push vector number
891 .byte 0x6a
892 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
893 jmpCommonIdtEntry
894 # No. 100
895 pushl $0x0 # push error code place holder on the stack
896 # push xxh ; push vector number
897 .byte 0x6a
898 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
899 jmpCommonIdtEntry
900
901
902 commonIdtEntry:
903 pushl %eax
904 pushl %ecx
905 pushl %edx
906 pushl %ebx
907 pushl %esp
908 pushl %ebp
909 pushl %esi
910 pushl %edi
911 .byte 0x41
912 .byte 0x50
913 # push r8
914 .byte 0x41
915 .byte 0x51
916 # push r9
917 .byte 0x41
918 .byte 0x52
919 # push r10
920 .byte 0x41
921 .byte 0x53
922 # push r11
923 .byte 0x41
924 .byte 0x54
925 # push r12
926 .byte 0x41
927 .byte 0x55
928 # push r13
929 .byte 0x41
930 .byte 0x56
931 # push r14
932 .byte 0x41
933 .byte 0x57
934 # push r15
935 .byte 0x48
936 movl %esp,%ebp
937 # mov rbp, rsp
938
939 ##
940 ## At this point the stack looks like this:
941 ##
942 ## Calling SS
943 ## Calling RSP
944 ## rflags
945 ## Calling CS
946 ## Calling RIP
947 ## Error code or 0
948 ## Int num or 0ffh for unknown int num
949 ## rax
950 ## rcx
951 ## rdx
952 ## rbx
953 ## rsp
954 ## rbp
955 ## rsi
956 ## rdi
957 ## r8
958 ## r9
959 ## r10
960 ## r11
961 ## r12
962 ## r13
963 ## r14
964 ## r15 <------- RSP, RBP
965 ##
966
967 call ClearScreen
968 mov String1, %esi
969 call PrintString
970 .byte 0x48
971 movl 16*8(%ebp),%eax ## move Int number into RAX
972 .byte 0x48
973 cmpl $18,%eax
974 ja PrintDefaultString
975 PrintExceptionString:
976 shll $3,%eax ## multiply by 8 to get offset from StringTable to actual string address
977 addl StringTable, %eax
978 movl (%eax),%esi
979 jmp PrintTheString
980 PrintDefaultString:
981 movl IntUnknownString, %esi
982 # patch Int number
983 movl %eax,%edx
984 call A2C
985 movb %al,1(%esi)
986 movl %edx,%eax
987 shrl $4,%eax
988 call A2C
989 movb %al,(%esi)
990 PrintTheString:
991 call PrintString
992 movl String2, %esi
993 call PrintString
994 .byte 0x48
995 movl 19*8(%ebp),%eax # CS
996 call PrintQword
997 movb $':', %al
998 movb %al, (%edi)
999 addl $2,%edi
1000 .byte 0x48
1001 movl 18*8(%ebp),%eax # RIP
1002 call PrintQword
1003 movl String3, %esi
1004 call PrintString
1005
1006 movl $0xb8140,%edi
1007
1008 movl StringRax, %esi
1009 call PrintString
1010 .byte 0x48
1011 movl 15*8(%ebp),%eax
1012 call PrintQword
1013
1014 movl StringRcx, %esi
1015 call PrintString
1016 .byte 0x48
1017 movl 14*8(%ebp),%eax
1018 call PrintQword
1019
1020 movl StringRdx, %esi
1021 call PrintString
1022 .byte 0x48
1023 movl 13*8(%ebp),%eax
1024 call PrintQword
1025
1026 movl $0xb81e0,%edi
1027
1028 movl StringRbx, %esi
1029 call PrintString
1030 .byte 0x48
1031 movl 12*8(%ebp),%eax
1032 call PrintQword
1033
1034 movl StringRsp, %esi
1035 call PrintString
1036 .byte 0x48
1037 movl 21*8(%ebp),%eax
1038 call PrintQword
1039
1040 movl StringRbp, %esi
1041 call PrintString
1042 .byte 0x48
1043 movl 10*8(%ebp),%eax
1044 call PrintQword
1045
1046 movl $0xb8280,%edi
1047
1048 movl StringRsi, %esi
1049 call PrintString
1050 .byte 0x48
1051 movl 9*8(%ebp),%eax
1052 call PrintQword
1053
1054 movl StringRdi, %esi
1055 call PrintString
1056 .byte 0x48
1057 movl 8*8(%ebp),%eax
1058 call PrintQword
1059
1060 movl StringEcode, %esi
1061 call PrintString
1062 .byte 0x48
1063 movl 17*8(%ebp),%eax
1064 call PrintQword
1065
1066 movl $0xb8320,%edi
1067
1068 movl StringR8, %esi
1069 call PrintString
1070 .byte 0x48
1071 movl 7*8(%ebp),%eax
1072 call PrintQword
1073
1074 movl StringR9, %esi
1075 call PrintString
1076 .byte 0x48
1077 movl 6*8(%ebp),%eax
1078 call PrintQword
1079
1080 movl StringR10, %esi
1081 call PrintString
1082 .byte 0x48
1083 movl 5*8(%ebp),%eax
1084 call PrintQword
1085
1086 movl $0xb83c0,%edi
1087
1088 movl StringR11, %esi
1089 call PrintString
1090 .byte 0x48
1091 movl 4*8(%ebp),%eax
1092 call PrintQword
1093
1094 movl StringR12, %esi
1095 call PrintString
1096 .byte 0x48
1097 movl 3*8(%ebp),%eax
1098 call PrintQword
1099
1100 movl StringR13, %esi
1101 call PrintString
1102 .byte 0x48
1103 movl 2*8(%ebp),%eax
1104 call PrintQword
1105
1106 movl $0xb8460,%edi
1107
1108 movl StringR14, %esi
1109 call PrintString
1110 .byte 0x48
1111 movl 1*8(%ebp),%eax
1112 call PrintQword
1113
1114 movl StringR15, %esi
1115 call PrintString
1116 .byte 0x48
1117 movl 0*8(%ebp),%eax
1118 call PrintQword
1119
1120 movl StringSs, %esi
1121 call PrintString
1122 .byte 0x48
1123 movl 22*8(%ebp),%eax
1124 call PrintQword
1125
1126 movl $0xb8500,%edi
1127
1128 movl StringRflags, %esi
1129 call PrintString
1130 .byte 0x48
1131 movl 20*8(%ebp),%eax
1132 call PrintQword
1133
1134 movl $0xb8640,%edi
1135
1136 movl %ebp,%esi
1137 addl $23*8,%esi
1138 movl $4,%ecx
1139
1140
1141 OuterLoop:
1142 pushl %ecx
1143 movl $4,%ecx
1144 .byte 0x48
1145 movl %edi,%edx
1146
1147 InnerLoop:
1148 .byte 0x48
1149 movl (%esi),%eax
1150 call PrintQword
1151 addl $8,%esi
1152 mov $0x00, %al
1153 movb %al,(%edi)
1154 addl $2,%edi
1155 loop InnerLoop
1156
1157 popl %ecx
1158 addl $0xa0,%edx
1159 movl %edx,%edi
1160 loop OuterLoop
1161
1162
1163 movl $0xb8960,%edi
1164
1165 .byte 0x48
1166 movl 18*8(%ebp),%eax # RIP
1167 subl $8*8,%eax
1168 .byte 0x48
1169 movl %eax,%esi # esi = rip - 8 QWORD linear (total 16 QWORD)
1170
1171 movl $4,%ecx
1172
1173 OuterLoop1:
1174 pushl %ecx
1175 movl $4,%ecx
1176 movl %edi,%edx
1177
1178 InnerLoop1:
1179 .byte 0x48
1180 movl (%esi),%eax
1181 call PrintQword
1182 addl $8,%esi
1183 movb $0x00, %al
1184 movb %al,(%edi)
1185 addl $2,%edi
1186 loop InnerLoop1
1187
1188 popl %ecx
1189 addl $0xa0,%edx
1190 movl %edx,%edi
1191 loop OuterLoop1
1192
1193
1194
1195 #wbinvd
1196 LN_C1:
1197 jmp LN_C1
1198
1199 #
1200 # return
1201 #
1202 movl %ebp,%esp
1203 # mov rsp, rbp
1204 .byte 0x41
1205 .byte 0x5f
1206 # pop r15
1207 .byte 0x41
1208 .byte 0x5e
1209 # pop r14
1210 .byte 0x41
1211 .byte 0x5d
1212 # pop r13
1213 .byte 0x41
1214 .byte 0x5c
1215 # pop r12
1216 .byte 0x41
1217 .byte 0x5b
1218 # pop r11
1219 .byte 0x41
1220 .byte 0x5a
1221 # pop r10
1222 .byte 0x41
1223 .byte 0x59
1224 # pop r9
1225 .byte 0x41
1226 .byte 0x58
1227 # pop r8
1228 popl %edi
1229 popl %esi
1230 popl %ebp
1231 popl %eax # esp
1232 popl %ebx
1233 popl %edx
1234 popl %ecx
1235 popl %eax
1236
1237 .byte 0x48
1238 .byte 0x83
1239 .byte 0xc4
1240 .byte 0x10
1241 # add esp, 16 ; error code and INT number
1242
1243 .byte 0x48
1244 .byte 0xcf
1245 # iretq
1246
1247 PrintString:
1248 pushl %eax
1249 LN_C2:
1250 movb (%esi), %al
1251 cmpb $0,%al
1252 je LN_C3
1253 movb %al, (%edi)
1254 .byte 0xff
1255 .byte 0xc6
1256 # inc esi
1257 addl $2,%edi
1258 jmp LN_C2
1259 LN_C3:
1260 popl %eax
1261 ret
1262
1263 ## RAX contains qword to print
1264 ## RDI contains memory location (screen location) to print it to
1265 PrintQword:
1266 pushl %ecx
1267 pushl %ebx
1268 pushl %eax
1269
1270 .byte 0x48
1271 .byte 0xc7
1272 .byte 0xc1
1273 .long 16
1274 # mov rcx, 16
1275 looptop:
1276 .byte 0x48
1277 roll $4,%eax
1278 movb %al,%bl
1279 andb $0xf,%bl
1280 addb $'0', %bl
1281 cmpb $'9', %bl
1282 jle @f
1283 addb $7,%bl
1284 @@:
1285 movb %bl, (%edi)
1286 addl $2,%edi
1287 loop looptop
1288 #wbinvd
1289
1290 popl %eax
1291 popl %ebx
1292 popl %ecx
1293 ret
1294
1295 ClearScreen:
1296 pushl %eax
1297 pushl %ecx
1298
1299 movb $0x00, %al
1300 movb $0xc,%ah
1301 movl $0xb8000,%edi
1302 movl $80*24,%ecx
1303 LN_C4:
1304 movw %ax, (%edi)
1305 addl $2,%edi
1306 loop LN_C4
1307 movl $0xb8000,%edi
1308
1309 popl %ecx
1310 popl %eax
1311
1312 ret
1313
1314 A2C:
1315 andb $0xf,%al
1316 addb $'0', %al
1317 cmpb $'9', %al
1318 jle @f
1319 addb $7,%al
1320 LN_C5:
1321 ret
1322
1323 String1: .asciz "*** INT "
1324
1325 Int0String: .asciz "00h Divide by 0 -"
1326 Int1String: .asciz "01h Debug exception -"
1327 Int2String: .asciz "02h NMI -"
1328 Int3String: .asciz "03h Breakpoint -"
1329 Int4String: .asciz "04h Overflow -"
1330 Int5String: .asciz "05h Bound -"
1331 Int6String: .asciz "06h Invalid opcode -"
1332 Int7String: .asciz "07h Device not available -"
1333 Int8String: .asciz "08h Double fault -"
1334 Int9String: .asciz "09h Coprocessor seg overrun (reserved) -"
1335 Int10String: .asciz "0Ah Invalid TSS -"
1336 Int11String: .asciz "0Bh Segment not present -"
1337 Int12String: .asciz "0Ch Stack fault -"
1338 Int13String: .asciz "0Dh General protection fault -"
1339 Int14String: .asciz "0Eh Page fault -"
1340 Int15String: .asciz "0Fh (Intel reserved) -"
1341 Int16String: .asciz "10h Floating point error -"
1342 Int17String: .asciz "11h Alignment check -"
1343 Int18String: .asciz "12h Machine check -"
1344 Int19String: .asciz "13h SIMD Floating-Point Exception -"
1345 IntUnknownString: .asciz "??h Unknown interrupt -"
1346
1347 StringTable: .long Int0String, Int1String, Int2String, Int3String, \
1348 Int4String, Int5String, Int6String, Int7String, \
1349 Int8String, Int9String, Int10String, Int11String, \
1350 Int12String, Int13String, Int14String, Int15String,\
1351 Int16String, Int17String, Int18String, Int19String
1352
1353 String2: .asciz " HALT!! *** ("
1354 String3: .asciz ")"
1355 StringRax: .asciz "RAX="
1356 StringRcx: .asciz " RCX="
1357 StringRdx: .asciz " RDX="
1358 StringRbx: .asciz "RBX="
1359 StringRsp: .asciz " RSP="
1360 StringRbp: .asciz " RBP="
1361 StringRsi: .asciz "RSI="
1362 StringRdi: .asciz " RDI="
1363 StringEcode: .asciz " ECODE="
1364 StringR8: .asciz "R8 ="
1365 StringR9: .asciz " R9 ="
1366 StringR10: .asciz " R10="
1367 StringR11: .asciz "R11="
1368 StringR12: .asciz " R12="
1369 StringR13: .asciz " R13="
1370 StringR14: .asciz "R14="
1371 StringR15: .asciz " R15="
1372 StringSs: .asciz " SS ="
1373 StringRflags: .asciz "RFLAGS="
1374
1375 Idtr: .float 0
1376 .float 0
1377
1378 .org 0x21ffe
1379 BlockSignature:
1380 .word 0xaa55
1381