]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BootSector/efi32.S
Remove .rept directive to improve portability.
[mirror_edk2.git] / DuetPkg / BootSector / efi32.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 #* efi32.asm
13 #*
14 #* Abstract:
15 #*
16 #------------------------------------------------------------------------------
17
18 ##############################################################################
19 # Now in 32-bit protected mode.
20 ##############################################################################
21
22 .org 0x21000
23
24 .global _start
25 _start:
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 Start:
40 movw %ax, %ds
41 movw %ax, %es
42 movw %ax, %fs
43 movw %ax, %gs
44 movw %ax, %ss
45 movl $0x001ffff0, %esp
46
47 call ClearScreen
48
49 # Populate IDT with meaningful offsets for exception handlers...
50 sidt Idtr
51
52 movl Halt, %eax
53 movl %eax, %ebx # use bx to copy 15..0 to descriptors
54 shrl $16, %eax # use ax to copy 31..16 to descriptors
55 movl $0x78, %ecx # 78h IDT entries to initialize with unique entry points (exceptions)
56 movl (Idtr + 2), %esi
57 movl (%esi), %edi
58
59 LOOP_1: # loop through all IDT entries exception handlers and initialize to default handler
60 movw %bx, (%edi) # write bits 15..0 of offset
61 movw $0x20, 2(%edi) # SYS_CODE_SEL from GDT
62 movw $(0x0e00 | 0x8000), 4(%edi) # type = 386 interrupt gate, present
63 movw %ax, 6(%edi) # write bits 31..16 of offset
64 addl $8, %edi # move up to next descriptor
65 addw DEFAULT_HANDLER_SIZE, %bx # move to next entry point
66 loopl LOOP_1 # loop back through again until all descriptors are initialized
67
68 ## at this point edi contains the offset of the descriptor for INT 20
69 ## and bx contains the low 16 bits of the offset of the default handler
70 ## so initialize all the rest of the descriptors with these two values...
71 # mov ecx, 101 ; there are 100 descriptors left (INT 20 (14h) - INT 119 (77h)
72 #@@: ; loop through all IDT entries exception handlers and initialize to default handler
73 # mov word ptr [edi], bx ; write bits 15..0 of offset
74 # mov word ptr [edi+2], 20h ; SYS_CODE_SEL from GDT
75 # mov word ptr [edi+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
76 # mov word ptr [edi+6], ax ; write bits 31..16 of offset
77 # add edi, 8 ; move up to next descriptor
78 # loop @b ; loop back through again until all descriptors are initialized
79
80
81 ## DUMP location of IDT and several of the descriptors
82 # mov ecx, 8
83 # mov eax, [offset Idtr + 2]
84 # mov eax, [eax]
85 # mov edi, 0b8000h
86 # call PrintDword
87 # mov esi, eax
88 # mov edi, 0b80a0h
89 # jmp OuterLoop
90
91 ##
92 ## just for fun, let's do a software interrupt to see if we correctly land in the exception handler...
93 # mov eax, 011111111h
94 # mov ebx, 022222222h
95 # mov ecx, 033333333h
96 # mov edx, 044444444h
97 # mov ebp, 055555555h
98 # mov esi, 066666666h
99 # mov edi, 077777777h
100 # push 011111111h
101 # push 022222222h
102 # push 033333333h
103 # int 119
104
105
106 movl $0x22000, %esi # esi = 22000
107 movl 0x14(%esi), %eax # eax = [22014]
108 addl %eax, %esi # esi = 22000 + [22014] = Base of EFILDR.C
109 movl 0x3c(%esi), %ebp # ebp = [22000 + [22014] + 3c] = NT Image Header for EFILDR.C
110 addl %esi, %ebp
111 movl 0x34(%ebp), %edi # edi = [[22000 + [22014] + 3c] + 30] = ImageBase
112 movl 0x28(%ebp), %eax # eax = [[22000 + [22014] + 3c] + 24] = EntryPoint
113 addl %edi, %eax # eax = ImageBase + EntryPoint
114 movl %eax, EfiLdrOffset # Modify far jump instruction for correct entry point
115
116 movw 6(%ebp), %bx # bx = Number of sections
117 xorl %eax, %eax
118 movw 0x14(%ebp), %ax # ax = Optional Header Size
119 addl %eax, %ebp
120 addl $0x18, %ebp # ebp = Start of 1st Section
121
122 SectionLoop:
123 pushl %esi # Save Base of EFILDR.C
124 pushl %edi # Save ImageBase
125 addl 0x14(%ebp), %esi # esi = Base of EFILDR.C + PointerToRawData
126 addl 0x0c(%ebp), %edi # edi = ImageBase + VirtualAddress
127 movl 0x10(%ebp), %ecx # ecs = SizeOfRawData
128
129 cld
130 shrl $2, %ecx
131 rep
132 movsl
133
134 popl %edi # Restore ImageBase
135 popl %esi # Restore Base of EFILDR.C
136
137 addw $0x28, %bp # ebp = ebp + 028h = Pointer to next section record
138 decw %bx
139 cmpw $0, %bx
140 jne SectionLoop
141
142 movzwl (Idtr), %eax # get size of IDT
143 incl %eax
144 addl (Idtr + 2), %eax # add to base of IDT to get location of memory map...
145 pushl %eax # push memory map location on stack for call to EFILDR...
146
147 pushl %eax # push return address (useless, just for stack balance)
148 .byte 0xb8
149 EfiLdrOffset:
150 .long 0x00401000 # Offset of EFILDR
151 # mov eax, 401000h
152 pushl %eax
153 ret
154
155 # db "**** DEFAULT IDT ENTRY ***",0
156 .p2align 1
157 Halt:
158 INT0:
159 pushl $0x0 # push error code place holder on the stack
160 pushl $0x0
161 jmpCommonIdtEntry
162 # db 0e9h ; jmp 16 bit reletive
163 # dd commonIdtEntry - $ - 4 ; offset to jump to
164
165 INT1:
166 pushl $0x0 # push error code place holder on the stack
167 pushl $0x1
168 jmpCommonIdtEntry
169
170 INT2:
171 pushl $0x0 # push error code place holder on the stack
172 pushl $0x2
173 jmpCommonIdtEntry
174
175 INT3:
176 pushl $0x0 # push error code place holder on the stack
177 pushl $0x3
178 jmpCommonIdtEntry
179
180 INT4:
181 pushl $0x0 # push error code place holder on the stack
182 pushl $0x4
183 jmpCommonIdtEntry
184
185 INT5:
186 pushl $0x0 # push error code place holder on the stack
187 pushl $0x5
188 jmpCommonIdtEntry
189
190 INT6:
191 pushl $0x0 # push error code place holder on the stack
192 pushl $0x6
193 jmpCommonIdtEntry
194
195 INT7:
196 pushl $0x0 # push error code place holder on the stack
197 pushl $0x7
198 jmpCommonIdtEntry
199
200 INT8:
201 # Double fault causes an error code to be pushed so no phony push necessary
202 nop
203 nop
204 pushl $0x8
205 jmpCommonIdtEntry
206
207 INT9:
208 pushl $0x0 # push error code place holder on the stack
209 pushl $0x9
210 jmpCommonIdtEntry
211
212 INT10:
213 # Invalid TSS causes an error code to be pushed so no phony push necessary
214 nop
215 nop
216 pushl $10
217 jmpCommonIdtEntry
218
219 INT11:
220 # Segment Not Present causes an error code to be pushed so no phony push necessary
221 nop
222 nop
223 pushl $11
224 jmpCommonIdtEntry
225
226 INT12:
227 # Stack fault causes an error code to be pushed so no phony push necessary
228 nop
229 nop
230 pushl $12
231 jmpCommonIdtEntry
232
233 INT13:
234 # GP fault causes an error code to be pushed so no phony push necessary
235 nop
236 nop
237 pushl $13
238 jmpCommonIdtEntry
239
240 INT14:
241 # Page fault causes an error code to be pushed so no phony push necessary
242 nop
243 nop
244 pushl $14
245 jmpCommonIdtEntry
246
247 INT15:
248 pushl $0x0 # push error code place holder on the stack
249 pushl $15
250 jmpCommonIdtEntry
251
252 INT16:
253 pushl $0x0 # push error code place holder on the stack
254 pushl $16
255 jmpCommonIdtEntry
256
257 INT17:
258 # Alignment check causes an error code to be pushed so no phony push necessary
259 nop
260 nop
261 pushl $17
262 jmpCommonIdtEntry
263
264 INT18:
265 pushl $0x0 # push error code place holder on the stack
266 pushl $18
267 jmpCommonIdtEntry
268
269 INT19:
270 pushl $0x0 # push error code place holder on the stack
271 pushl $19
272 jmpCommonIdtEntry
273
274 INTUnknown:
275 # The following segment repeats (0x78 - 20) times:
276 # No. 1
277 pushl $0x0 # push error code place holder on the stack
278 # push $0xxx # push vector number
279 .byte 0x6a
280 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
281 jmpCommonIdtEntry
282 # No. 2
283 pushl $0x0 # push error code place holder on the stack
284 # push $0xxx # push vector number
285 .byte 0x6a
286 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
287 jmpCommonIdtEntry
288 # No. 3
289 pushl $0x0 # push error code place holder on the stack
290 # push $0xxx # push vector number
291 .byte 0x6a
292 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
293 jmpCommonIdtEntry
294 # No. 4
295 pushl $0x0 # push error code place holder on the stack
296 # push $0xxx # push vector number
297 .byte 0x6a
298 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
299 jmpCommonIdtEntry
300 # No. 5
301 pushl $0x0 # push error code place holder on the stack
302 # push $0xxx # push vector number
303 .byte 0x6a
304 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
305 jmpCommonIdtEntry
306 # No. 6
307 pushl $0x0 # push error code place holder on the stack
308 # push $0xxx # push vector number
309 .byte 0x6a
310 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
311 jmpCommonIdtEntry
312 # No. 7
313 pushl $0x0 # push error code place holder on the stack
314 # push $0xxx # push vector number
315 .byte 0x6a
316 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
317 jmpCommonIdtEntry
318 # No. 8
319 pushl $0x0 # push error code place holder on the stack
320 # push $0xxx # push vector number
321 .byte 0x6a
322 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
323 jmpCommonIdtEntry
324 # No. 9
325 pushl $0x0 # push error code place holder on the stack
326 # push $0xxx # push vector number
327 .byte 0x6a
328 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
329 jmpCommonIdtEntry
330 # No. 10
331 pushl $0x0 # push error code place holder on the stack
332 # push $0xxx # push vector number
333 .byte 0x6a
334 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
335 jmpCommonIdtEntry
336 # No. 11
337 pushl $0x0 # push error code place holder on the stack
338 # push $0xxx # push vector number
339 .byte 0x6a
340 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
341 jmpCommonIdtEntry
342 # No. 12
343 pushl $0x0 # push error code place holder on the stack
344 # push $0xxx # push vector number
345 .byte 0x6a
346 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
347 jmpCommonIdtEntry
348 # No. 13
349 pushl $0x0 # push error code place holder on the stack
350 # push $0xxx # push vector number
351 .byte 0x6a
352 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
353 jmpCommonIdtEntry
354 # No. 14
355 pushl $0x0 # push error code place holder on the stack
356 # push $0xxx # push vector number
357 .byte 0x6a
358 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
359 jmpCommonIdtEntry
360 # No. 15
361 pushl $0x0 # push error code place holder on the stack
362 # push $0xxx # push vector number
363 .byte 0x6a
364 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
365 jmpCommonIdtEntry
366 # No. 16
367 pushl $0x0 # push error code place holder on the stack
368 # push $0xxx # push vector number
369 .byte 0x6a
370 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
371 jmpCommonIdtEntry
372 # No. 17
373 pushl $0x0 # push error code place holder on the stack
374 # push $0xxx # push vector number
375 .byte 0x6a
376 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
377 jmpCommonIdtEntry
378 # No. 18
379 pushl $0x0 # push error code place holder on the stack
380 # push $0xxx # push vector number
381 .byte 0x6a
382 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
383 jmpCommonIdtEntry
384 # No. 19
385 pushl $0x0 # push error code place holder on the stack
386 # push $0xxx # push vector number
387 .byte 0x6a
388 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
389 jmpCommonIdtEntry
390 # No. 20
391 pushl $0x0 # push error code place holder on the stack
392 # push $0xxx # push vector number
393 .byte 0x6a
394 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
395 jmpCommonIdtEntry
396 # No. 21
397 pushl $0x0 # push error code place holder on the stack
398 # push $0xxx # push vector number
399 .byte 0x6a
400 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
401 jmpCommonIdtEntry
402 # No. 22
403 pushl $0x0 # push error code place holder on the stack
404 # push $0xxx # push vector number
405 .byte 0x6a
406 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
407 jmpCommonIdtEntry
408 # No. 23
409 pushl $0x0 # push error code place holder on the stack
410 # push $0xxx # push vector number
411 .byte 0x6a
412 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
413 jmpCommonIdtEntry
414 # No. 24
415 pushl $0x0 # push error code place holder on the stack
416 # push $0xxx # push vector number
417 .byte 0x6a
418 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
419 jmpCommonIdtEntry
420 # No. 25
421 pushl $0x0 # push error code place holder on the stack
422 # push $0xxx # push vector number
423 .byte 0x6a
424 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
425 jmpCommonIdtEntry
426 # No. 26
427 pushl $0x0 # push error code place holder on the stack
428 # push $0xxx # push vector number
429 .byte 0x6a
430 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
431 jmpCommonIdtEntry
432 # No. 27
433 pushl $0x0 # push error code place holder on the stack
434 # push $0xxx # push vector number
435 .byte 0x6a
436 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
437 jmpCommonIdtEntry
438 # No. 28
439 pushl $0x0 # push error code place holder on the stack
440 # push $0xxx # push vector number
441 .byte 0x6a
442 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
443 jmpCommonIdtEntry
444 # No. 29
445 pushl $0x0 # push error code place holder on the stack
446 # push $0xxx # push vector number
447 .byte 0x6a
448 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
449 jmpCommonIdtEntry
450 # No. 30
451 pushl $0x0 # push error code place holder on the stack
452 # push $0xxx # push vector number
453 .byte 0x6a
454 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
455 jmpCommonIdtEntry
456 # No. 31
457 pushl $0x0 # push error code place holder on the stack
458 # push $0xxx # push vector number
459 .byte 0x6a
460 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
461 jmpCommonIdtEntry
462 # No. 32
463 pushl $0x0 # push error code place holder on the stack
464 # push $0xxx # push vector number
465 .byte 0x6a
466 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
467 jmpCommonIdtEntry
468 # No. 33
469 pushl $0x0 # push error code place holder on the stack
470 # push $0xxx # push vector number
471 .byte 0x6a
472 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
473 jmpCommonIdtEntry
474 # No. 34
475 pushl $0x0 # push error code place holder on the stack
476 # push $0xxx # push vector number
477 .byte 0x6a
478 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
479 jmpCommonIdtEntry
480 # No. 35
481 pushl $0x0 # push error code place holder on the stack
482 # push $0xxx # push vector number
483 .byte 0x6a
484 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
485 jmpCommonIdtEntry
486 # No. 36
487 pushl $0x0 # push error code place holder on the stack
488 # push $0xxx # push vector number
489 .byte 0x6a
490 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
491 jmpCommonIdtEntry
492 # No. 37
493 pushl $0x0 # push error code place holder on the stack
494 # push $0xxx # push vector number
495 .byte 0x6a
496 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
497 jmpCommonIdtEntry
498 # No. 38
499 pushl $0x0 # push error code place holder on the stack
500 # push $0xxx # push vector number
501 .byte 0x6a
502 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
503 jmpCommonIdtEntry
504 # No. 39
505 pushl $0x0 # push error code place holder on the stack
506 # push $0xxx # push vector number
507 .byte 0x6a
508 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
509 jmpCommonIdtEntry
510 # No. 40
511 pushl $0x0 # push error code place holder on the stack
512 # push $0xxx # push vector number
513 .byte 0x6a
514 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
515 jmpCommonIdtEntry
516 # No. 41
517 pushl $0x0 # push error code place holder on the stack
518 # push $0xxx # push vector number
519 .byte 0x6a
520 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
521 jmpCommonIdtEntry
522 # No. 42
523 pushl $0x0 # push error code place holder on the stack
524 # push $0xxx # push vector number
525 .byte 0x6a
526 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
527 jmpCommonIdtEntry
528 # No. 43
529 pushl $0x0 # push error code place holder on the stack
530 # push $0xxx # push vector number
531 .byte 0x6a
532 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
533 jmpCommonIdtEntry
534 # No. 44
535 pushl $0x0 # push error code place holder on the stack
536 # push $0xxx # push vector number
537 .byte 0x6a
538 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
539 jmpCommonIdtEntry
540 # No. 45
541 pushl $0x0 # push error code place holder on the stack
542 # push $0xxx # push vector number
543 .byte 0x6a
544 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
545 jmpCommonIdtEntry
546 # No. 46
547 pushl $0x0 # push error code place holder on the stack
548 # push $0xxx # push vector number
549 .byte 0x6a
550 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
551 jmpCommonIdtEntry
552 # No. 47
553 pushl $0x0 # push error code place holder on the stack
554 # push $0xxx # push vector number
555 .byte 0x6a
556 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
557 jmpCommonIdtEntry
558 # No. 48
559 pushl $0x0 # push error code place holder on the stack
560 # push $0xxx # push vector number
561 .byte 0x6a
562 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
563 jmpCommonIdtEntry
564 # No. 49
565 pushl $0x0 # push error code place holder on the stack
566 # push $0xxx # push vector number
567 .byte 0x6a
568 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
569 jmpCommonIdtEntry
570 # No. 50
571 pushl $0x0 # push error code place holder on the stack
572 # push $0xxx # push vector number
573 .byte 0x6a
574 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
575 jmpCommonIdtEntry
576 # No. 51
577 pushl $0x0 # push error code place holder on the stack
578 # push $0xxx # push vector number
579 .byte 0x6a
580 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
581 jmpCommonIdtEntry
582 # No. 52
583 pushl $0x0 # push error code place holder on the stack
584 # push $0xxx # push vector number
585 .byte 0x6a
586 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
587 jmpCommonIdtEntry
588 # No. 53
589 pushl $0x0 # push error code place holder on the stack
590 # push $0xxx # push vector number
591 .byte 0x6a
592 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
593 jmpCommonIdtEntry
594 # No. 54
595 pushl $0x0 # push error code place holder on the stack
596 # push $0xxx # push vector number
597 .byte 0x6a
598 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
599 jmpCommonIdtEntry
600 # No. 55
601 pushl $0x0 # push error code place holder on the stack
602 # push $0xxx # push vector number
603 .byte 0x6a
604 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
605 jmpCommonIdtEntry
606 # No. 56
607 pushl $0x0 # push error code place holder on the stack
608 # push $0xxx # push vector number
609 .byte 0x6a
610 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
611 jmpCommonIdtEntry
612 # No. 57
613 pushl $0x0 # push error code place holder on the stack
614 # push $0xxx # push vector number
615 .byte 0x6a
616 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
617 jmpCommonIdtEntry
618 # No. 58
619 pushl $0x0 # push error code place holder on the stack
620 # push $0xxx # push vector number
621 .byte 0x6a
622 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
623 jmpCommonIdtEntry
624 # No. 59
625 pushl $0x0 # push error code place holder on the stack
626 # push $0xxx # push vector number
627 .byte 0x6a
628 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
629 jmpCommonIdtEntry
630 # No. 60
631 pushl $0x0 # push error code place holder on the stack
632 # push $0xxx # push vector number
633 .byte 0x6a
634 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
635 jmpCommonIdtEntry
636 # No. 61
637 pushl $0x0 # push error code place holder on the stack
638 # push $0xxx # push vector number
639 .byte 0x6a
640 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
641 jmpCommonIdtEntry
642 # No. 62
643 pushl $0x0 # push error code place holder on the stack
644 # push $0xxx # push vector number
645 .byte 0x6a
646 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
647 jmpCommonIdtEntry
648 # No. 63
649 pushl $0x0 # push error code place holder on the stack
650 # push $0xxx # push vector number
651 .byte 0x6a
652 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
653 jmpCommonIdtEntry
654 # No. 64
655 pushl $0x0 # push error code place holder on the stack
656 # push $0xxx # push vector number
657 .byte 0x6a
658 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
659 jmpCommonIdtEntry
660 # No. 65
661 pushl $0x0 # push error code place holder on the stack
662 # push $0xxx # push vector number
663 .byte 0x6a
664 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
665 jmpCommonIdtEntry
666 # No. 66
667 pushl $0x0 # push error code place holder on the stack
668 # push $0xxx # push vector number
669 .byte 0x6a
670 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
671 jmpCommonIdtEntry
672 # No. 67
673 pushl $0x0 # push error code place holder on the stack
674 # push $0xxx # push vector number
675 .byte 0x6a
676 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
677 jmpCommonIdtEntry
678 # No. 68
679 pushl $0x0 # push error code place holder on the stack
680 # push $0xxx # push vector number
681 .byte 0x6a
682 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
683 jmpCommonIdtEntry
684 # No. 69
685 pushl $0x0 # push error code place holder on the stack
686 # push $0xxx # push vector number
687 .byte 0x6a
688 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
689 jmpCommonIdtEntry
690 # No. 70
691 pushl $0x0 # push error code place holder on the stack
692 # push $0xxx # push vector number
693 .byte 0x6a
694 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
695 jmpCommonIdtEntry
696 # No. 71
697 pushl $0x0 # push error code place holder on the stack
698 # push $0xxx # push vector number
699 .byte 0x6a
700 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
701 jmpCommonIdtEntry
702 # No. 72
703 pushl $0x0 # push error code place holder on the stack
704 # push $0xxx # push vector number
705 .byte 0x6a
706 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
707 jmpCommonIdtEntry
708 # No. 73
709 pushl $0x0 # push error code place holder on the stack
710 # push $0xxx # push vector number
711 .byte 0x6a
712 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
713 jmpCommonIdtEntry
714 # No. 74
715 pushl $0x0 # push error code place holder on the stack
716 # push $0xxx # push vector number
717 .byte 0x6a
718 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
719 jmpCommonIdtEntry
720 # No. 75
721 pushl $0x0 # push error code place holder on the stack
722 # push $0xxx # push vector number
723 .byte 0x6a
724 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
725 jmpCommonIdtEntry
726 # No. 76
727 pushl $0x0 # push error code place holder on the stack
728 # push $0xxx # push vector number
729 .byte 0x6a
730 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
731 jmpCommonIdtEntry
732 # No. 77
733 pushl $0x0 # push error code place holder on the stack
734 # push $0xxx # push vector number
735 .byte 0x6a
736 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
737 jmpCommonIdtEntry
738 # No. 78
739 pushl $0x0 # push error code place holder on the stack
740 # push $0xxx # push vector number
741 .byte 0x6a
742 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
743 jmpCommonIdtEntry
744 # No. 79
745 pushl $0x0 # push error code place holder on the stack
746 # push $0xxx # push vector number
747 .byte 0x6a
748 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
749 jmpCommonIdtEntry
750 # No. 80
751 pushl $0x0 # push error code place holder on the stack
752 # push $0xxx # push vector number
753 .byte 0x6a
754 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
755 jmpCommonIdtEntry
756 # No. 81
757 pushl $0x0 # push error code place holder on the stack
758 # push $0xxx # push vector number
759 .byte 0x6a
760 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
761 jmpCommonIdtEntry
762 # No. 82
763 pushl $0x0 # push error code place holder on the stack
764 # push $0xxx # push vector number
765 .byte 0x6a
766 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
767 jmpCommonIdtEntry
768 # No. 83
769 pushl $0x0 # push error code place holder on the stack
770 # push $0xxx # push vector number
771 .byte 0x6a
772 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
773 jmpCommonIdtEntry
774 # No. 84
775 pushl $0x0 # push error code place holder on the stack
776 # push $0xxx # push vector number
777 .byte 0x6a
778 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
779 jmpCommonIdtEntry
780 # No. 85
781 pushl $0x0 # push error code place holder on the stack
782 # push $0xxx # push vector number
783 .byte 0x6a
784 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
785 jmpCommonIdtEntry
786 # No. 86
787 pushl $0x0 # push error code place holder on the stack
788 # push $0xxx # push vector number
789 .byte 0x6a
790 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
791 jmpCommonIdtEntry
792 # No. 87
793 pushl $0x0 # push error code place holder on the stack
794 # push $0xxx # push vector number
795 .byte 0x6a
796 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
797 jmpCommonIdtEntry
798 # No. 88
799 pushl $0x0 # push error code place holder on the stack
800 # push $0xxx # push vector number
801 .byte 0x6a
802 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
803 jmpCommonIdtEntry
804 # No. 89
805 pushl $0x0 # push error code place holder on the stack
806 # push $0xxx # push vector number
807 .byte 0x6a
808 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
809 jmpCommonIdtEntry
810 # No. 90
811 pushl $0x0 # push error code place holder on the stack
812 # push $0xxx # push vector number
813 .byte 0x6a
814 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
815 jmpCommonIdtEntry
816 # No. 91
817 pushl $0x0 # push error code place holder on the stack
818 # push $0xxx # push vector number
819 .byte 0x6a
820 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
821 jmpCommonIdtEntry
822 # No. 92
823 pushl $0x0 # push error code place holder on the stack
824 # push $0xxx # push vector number
825 .byte 0x6a
826 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
827 jmpCommonIdtEntry
828 # No. 93
829 pushl $0x0 # push error code place holder on the stack
830 # push $0xxx # push vector number
831 .byte 0x6a
832 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
833 jmpCommonIdtEntry
834 # No. 94
835 pushl $0x0 # push error code place holder on the stack
836 # push $0xxx # push vector number
837 .byte 0x6a
838 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
839 jmpCommonIdtEntry
840 # No. 95
841 pushl $0x0 # push error code place holder on the stack
842 # push $0xxx # push vector number
843 .byte 0x6a
844 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
845 jmpCommonIdtEntry
846 # No. 96
847 pushl $0x0 # push error code place holder on the stack
848 # push $0xxx # push vector number
849 .byte 0x6a
850 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
851 jmpCommonIdtEntry
852 # No. 97
853 pushl $0x0 # push error code place holder on the stack
854 # push $0xxx # push vector number
855 .byte 0x6a
856 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
857 jmpCommonIdtEntry
858 # No. 98
859 pushl $0x0 # push error code place holder on the stack
860 # push $0xxx # push vector number
861 .byte 0x6a
862 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
863 jmpCommonIdtEntry
864 # No. 99
865 pushl $0x0 # push error code place holder on the stack
866 # push $0xxx # push vector number
867 .byte 0x6a
868 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
869 jmpCommonIdtEntry
870 # No. 100
871 pushl $0x0 # push error code place holder on the stack
872 # push $0xxx # push vector number
873 .byte 0x6a
874 .long ( . - INTUnknown - 3 ) / 9 + 20 # vector number
875 jmpCommonIdtEntry
876
877
878 commonIdtEntry:
879 pushal
880 movl %esp, %ebp
881 ##
882 ## At this point the stack looks like this:
883 ##
884 ## eflags
885 ## Calling CS
886 ## Calling EIP
887 ## Error code or 0
888 ## Int num or 0ffh for unknown int num
889 ## eax
890 ## ecx
891 ## edx
892 ## ebx
893 ## esp
894 ## ebp
895 ## esi
896 ## edi <------- ESP, EBP
897 ##
898
899 call ClearScreen
900 movl String1, %esi
901 call PrintString
902 movl 32(%ebp), %eax ## move Int number into EAX
903 cmpl $19, %eax
904 ja PrintDefaultString
905 PrintExceptionString:
906 shll $2, %eax ## multiply by 4 to get offset from StringTable to actual string address
907 addl StringTable, %eax
908 movl (%eax), %esi
909 jmp PrintTheString
910 PrintDefaultString:
911 movl IntUnknownString, %esi
912 # patch Int number
913 movl %eax, %edx
914 call A2C
915 movb %al, 1(%esi)
916 movl %edx, %eax
917 shrl $4, %eax
918 call A2C
919 movb %al, (%esi)
920 PrintTheString:
921 call PrintString
922 movl String2, %esi
923 call PrintString
924 movl 44(%ebp), %eax # CS
925 call PrintDword
926 movb ':', %al
927 movb %al, (%edi)
928 addl $2, %edi
929 movl 40(%ebp), %eax # EIP
930 call PrintDword
931 movl String3, %esi
932 call PrintString
933
934 movl $0xb8140, %edi
935
936 movl StringEax, %esi # eax
937 call PrintString
938 movl 28(%ebp), %eax
939 call PrintDword
940
941 movl StringEbx, %esi # ebx
942 call PrintString
943 movl 16(%ebp), %eax
944 call PrintDword
945
946 movl StringEcx, %esi # ecx
947 call PrintString
948 movl 24(%ebp), %eax
949 call PrintDword
950
951 movl StringEdx, %esi # edx
952 call PrintString
953 movl 20(%ebp), %eax
954 call PrintDword
955
956 movl StringEcode, %esi # error code
957 call PrintString
958 movl 36(%ebp), %eax
959 call PrintDword
960
961 movl $0xb81e0, %edi
962
963 movl StringEsp, %esi # esp
964 call PrintString
965 movl 12(%ebp), %eax
966 call PrintDword
967
968 movl StringEbp, %esi # ebp
969 call PrintString
970 movl 8(%ebp), %eax
971 call PrintDword
972
973 movl StringEsi, %esi # esi
974 call PrintString
975 movl 4(%ebp), %eax
976 call PrintDword
977
978 movl StringEdi, %esi # edi
979 call PrintString
980 movl (%ebp), %eax
981 call PrintDword
982
983 movl StringEflags, %esi # eflags
984 call PrintString
985 movl 48(%ebp), %eax
986 call PrintDword
987
988 movl $0xb8320, %edi
989
990 movl %ebp, %esi
991 addl $52, %esi
992 movl $8, %ecx
993
994
995 OuterLoop:
996 pushl %ecx
997 movl $8, %ecx
998 movl %edi, %edx
999
1000 InnerLoop:
1001 movl (%esi), %eax
1002 call PrintDword
1003 addl $4, %esi
1004 movb ' ', %al
1005 movb %al, (%edi)
1006 addl $2, %edi
1007 loop InnerLoop
1008
1009 popl %ecx
1010 addl $0xa0, %edx
1011 movl %edx, %edi
1012 loop OuterLoop
1013
1014
1015 movl $0xb8960, %edi
1016
1017 movl 40(%ebp), %eax # EIP
1018 subl $32*4, %eax
1019 movl %eax, %esi # esi = eip - 32 DWORD linear (total 64 DWORD)
1020
1021 movl $8, %ecx
1022
1023 OuterLoop1:
1024 pushl %ecx
1025 movl $8, %ecx
1026 movl %edi, %edx
1027
1028 InnerLoop1:
1029 movl (%esi), %eax
1030 call PrintDword
1031 addl $4, %esi
1032 movb ' ', %al
1033 movb %al, (%edi)
1034 addl $2, %edi
1035 loop InnerLoop1
1036
1037 popl %ecx
1038 addl $0xa0, %edx
1039 movl %edx, %edi
1040 loop OuterLoop1
1041
1042
1043
1044 # wbinvd ; this intruction does not support in early than 486 arch
1045 LN_C1:
1046 jmp LN_C1
1047 #
1048 # return
1049 #
1050 movl %ebp, %esp
1051 popal
1052 addl $8, %esp # error code and INT number
1053
1054 iretl
1055
1056
1057 PrintString:
1058 pushl %eax
1059 LN_C2:
1060 movb (%esi), %al
1061 cmpb $0, %al
1062 je LN_C3
1063 movb %al, (%edi)
1064 incl %esi
1065 addl $2, %edi
1066 jmp LN_C2
1067 LN_C3:
1068 popl %eax
1069 ret
1070
1071 ## EAX contains dword to print
1072 ## EDI contains memory location (screen location) to print it to
1073 PrintDword:
1074 pushl %ecx
1075 pushl %ebx
1076 pushl %eax
1077
1078 movl $8, %ecx
1079 looptop:
1080 roll $4, %eax
1081 movb %al, %bl
1082 andb $0xf, %bl
1083 addb '0', %bl
1084 cmpb '9', %bl
1085 jle LN_C4
1086 addb $7, %bl
1087 LN_C4:
1088 movb %bl, (%edi)
1089 addl $2, %edi
1090 loop looptop
1091 #wbinvd
1092
1093 popl %eax
1094 popl %ebx
1095 popl %ecx
1096 ret
1097
1098 ClearScreen:
1099 pushl %eax
1100 pushl %ecx
1101
1102 movb $0x00, %al
1103 movb $0xc, %ah
1104 movl $0xb8000, %edi
1105 movl $80*24, %ecx
1106 LN_C5:
1107 movw %ax, (%edi)
1108 addl $2, %edi
1109 loop LN_C5
1110 movl $0xb8000, %edi
1111
1112 popl %ecx
1113 popl %eax
1114
1115 ret
1116
1117 A2C:
1118 andb $0xf, %al
1119 addb '0', %al
1120 cmpb '9', %al
1121 jle LN_C6
1122 addb $7, %al
1123 LN_C6:
1124 ret
1125
1126 String1: .asciz "*** INT "
1127
1128 Int0String: .asciz "00h Divide by 0 -"
1129 Int1String: .asciz "01h Debug exception -"
1130 Int2String: .asciz "02h NMI -"
1131 Int3String: .asciz "03h Breakpoint -"
1132 Int4String: .asciz "04h Overflow -"
1133 Int5String: .asciz "05h Bound -"
1134 Int6String: .asciz "06h Invalid opcode -"
1135 Int7String: .asciz "07h Device not available -"
1136 Int8String: .asciz "08h Double fault -"
1137 Int9String: .asciz "09h Coprocessor seg overrun (reserved) -"
1138 Int10String: .asciz "0Ah Invalid TSS -"
1139 Int11String: .asciz "0Bh Segment not present -"
1140 Int12String: .asciz "0Ch Stack fault -"
1141 Int13String: .asciz "0Dh General protection fault -"
1142 Int14String: .asciz "0Eh Page fault -"
1143 Int15String: .asciz "0Fh (Intel reserved) -"
1144 Int16String: .asciz "10h Floating point error -"
1145 Int17String: .asciz "11h Alignment check -"
1146 Int18String: .asciz "12h Machine check -"
1147 Int19String: .asciz "13h SIMD Floating-Point Exception -"
1148 IntUnknownString: .asciz "??h Unknown interrupt -"
1149
1150 StringTable: .long Int0String, Int1String, Int2String, Int3String, \
1151 Int4String, Int5String, Int6String, Int7String, \
1152 Int8String, Int9String, Int10String, Int11String, \
1153 Int12String, Int13String, Int14String, Int15String,\
1154 Int16String, Int17String, Int18String, Int19String
1155
1156 String2: .asciz " HALT!! *** ("
1157 String3: .asciz ")"
1158 StringEax: .asciz "EAX="
1159 StringEbx: .asciz "EBX="
1160 StringEcx: .asciz "ECX="
1161 StringEdx: .asciz "EDX="
1162 StringEcode: .asciz "ECODE="
1163 StringEsp: .asciz "ESP="
1164 StringEbp: .asciz "EBP="
1165 StringEsi: .asciz "ESI="
1166 StringEdi: .asciz "EDI="
1167 StringEflags: .asciz "EFLAGS="
1168
1169 Idtr: .float 0
1170
1171 .org 0x21ffe
1172 BlockSignature:
1173 .word 0xaa55
1174
1175