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