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