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