efi32.asm

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· 汇编 代码 · 共 582 行 · 第 1/2 页

ASM
582
字号
;;      Calling EIP
;;      Error code or 0
;;      Int num or 0ffh for unknown int num
;;      eax
;;      ecx
;;      edx
;;      ebx
;;      esp
;;      ebp
;;      esi
;;      edi <------- ESP, EBP
;;      

    call    ClearScreen
    mov     esi, offset String1
    call    PrintString
    mov     eax, [ebp + 32]     ;; move Int number into EAX 
    cmp     eax, 19
    ja      PrintDefaultString
PrintExceptionString:
    shl     eax, 2              ;; multiply by 4 to get offset from StringTable to actual string address
    add     eax, offset StringTable
    mov     esi, [eax]
    jmp     PrintTheString
PrintDefaultString:
    mov     esi, offset IntUnknownString
    ; patch Int number
    mov     edx, eax
    call    A2C
    mov     [esi + 1], al
    mov     eax, edx
    shr     eax, 4
    call    A2C
    mov     [esi], al
PrintTheString:        
    call    PrintString
    mov     esi, offset String2
    call    PrintString
    mov     eax, [ebp+44]          ; CS
    call    PrintDword
    mov     al, ':'
    mov     byte ptr [edi], al
    add     edi, 2
    mov     eax, [ebp+40]          ; EIP
    call    PrintDword
    mov     esi, offset String3
    call    PrintString
    
    mov     edi, 0b8140h
    
    mov     esi, offset StringEax     ; eax
    call    PrintString
    mov     eax, [ebp+28]
    call    PrintDword
    
    mov     esi, offset StringEbx     ; ebx
    call    PrintString
    mov     eax, [ebp+16]
    call    PrintDword
    
    mov     esi, offset StringEcx     ; ecx
    call    PrintString
    mov     eax, [ebp+24]
    call    PrintDword
    
    mov     esi, offset StringEdx     ; edx
    call    PrintString
    mov     eax, [ebp+20]
    call    PrintDword
    
    mov     esi, offset StringEcode   ; error code
    call    PrintString
    mov     eax, [ebp+36]
    call    PrintDword
    
    mov     edi, 0b81e0h
    
    mov     esi, offset StringEsp     ; esp
    call    PrintString
    mov     eax, [ebp+12]
    call    PrintDword
    
    mov     esi, offset StringEbp     ; ebp
    call    PrintString
    mov     eax, [ebp+8]
    call    PrintDword
    
    mov     esi, offset StringEsi     ; esi
    call    PrintString
    mov     eax, [ebp+4]
    call    PrintDword
    
    mov     esi, offset StringEdi    ; edi
    call    PrintString
    mov     eax, [ebp]
    call    PrintDword
    
    mov     esi, offset StringEflags ; eflags
    call    PrintString
    mov     eax, [ebp+48]
    call    PrintDword
    
    mov     edi, 0b8320h

    mov     esi, ebp
    add     esi, 52
    mov     ecx, 8

    
OuterLoop:
    push    ecx
    mov     ecx, 8
    mov     edx, edi

InnerLoop:
    mov     eax, [esi]
    call    PrintDword
    add     esi, 4
    mov     al, ' '
    mov     [edi], al
    add     edi, 2
    loop    InnerLoop

    pop     ecx
    add     edx, 0a0h
    mov     edi, edx
    loop    OuterLoop


    mov     edi, 0b8960h

    mov     eax, [ebp+40]  ; EIP
    sub     eax, 32 * 4
    mov     esi, eax        ; esi = eip - 32 DWORD linear (total 64 DWORD)

    mov     ecx, 8
    
OuterLoop1:
    push    ecx
    mov     ecx, 8
    mov     edx, edi

InnerLoop1:
    mov     eax, [esi]
    call    PrintDword
    add     esi, 4
    mov     al, ' '
    mov     [edi], al
    add     edi, 2
    loop    InnerLoop1

    pop     ecx
    add     edx, 0a0h
    mov     edi, edx
    loop    OuterLoop1



    wbinvd
@@:    
    jmp     @b
;
; return
;
    mov     esp, ebp
    popad
    add     esp, 8 ; error code and INT number
    
    iretd


PrintString:
    push    eax
@@:
    mov     al, byte ptr [esi]
    cmp     al, 0
    je      @f
    mov     byte ptr [edi], al
    inc     esi
    add     edi, 2
    jmp     @b
@@:
    pop     eax
    ret
        
;; EAX contains dword to print
;; EDI contains memory location (screen location) to print it to
PrintDword:
    push    ecx
    push    ebx
    push    eax
    
    mov     ecx, 8
looptop:
    rol     eax, 4
    mov     bl, al
    and     bl, 0fh
    add     bl, '0'
    cmp     bl, '9'
    jle     @f
    add     bl, 7
@@:
    mov     byte ptr [edi], bl
    add     edi, 2
    loop    looptop
    wbinvd
    
    pop     eax
    pop     ebx
    pop     ecx
    ret

ClearScreen:
    push    eax
    push    ecx
    
    mov     al, ' '
    mov     ah, 0ch
    mov     edi, 0b8000h
    mov     ecx, 80 * 24
@@:
    mov     word ptr [edi], ax
    add     edi, 2
    loop    @b
    mov     edi, 0b8000h
    
    pop     ecx
    pop     eax

    ret                
        
A2C:
    and     al, 0fh
    add     al, '0'
    cmp     al, '9'
    jle     @f
    add     al, 7
@@:
    ret
        
String1           db  "*** INT ",0

Int0String        db  "00h Divide by 0 -",0
Int1String        db  "01h Debug exception -",0
Int2String        db  "02h NMI -",0
Int3String        db  "03h Breakpoint -",0
Int4String        db  "04h Overflow -",0
Int5String        db  "05h Bound -",0
Int6String        db  "06h Invalid opcode -",0
Int7String        db  "07h Device not available -",0
Int8String        db  "08h Double fault -",0
Int9String        db  "09h Coprocessor seg overrun (reserved) -",0
Int10String       db  "0Ah Invalid TSS -",0
Int11String       db  "0Bh Segment not present -",0
Int12String       db  "0Ch Stack fault -",0
Int13String       db  "0Dh General protection fault -",0
Int14String       db  "0Eh Page fault -",0
Int15String       db  "0Fh (Intel reserved) -",0
Int16String       db  "10h Floating point error -",0
Int17String       db  "11h Alignment check -",0
Int18String       db  "12h Machine check -",0
Int19String       db  "13h SIMD Floating-Point Exception -",0
IntUnknownString  db  "??h Unknown interrupt -",0

StringTable       dd  offset Int0String, offset Int1String, offset Int2String, offset Int3String, 
                      offset Int4String, offset Int5String, offset Int6String, offset Int7String,
                      offset Int8String, offset Int9String, offset Int10String, offset Int11String,
                      offset Int12String, offset Int13String, offset Int14String, offset Int15String,
                      offset Int16String, offset Int17String, offset Int18String, offset Int19String

String2           db  " HALT!! *** (",0
String3           db  ")",0
StringEax         db  "EAX=",0
StringEbx         db  " EBX=",0
StringEcx         db  " ECX=",0
StringEdx         db  " EDX=",0
StringEcode       db  " ECODE=",0
StringEsp         db  "ESP=",0
StringEbp         db  " EBP=",0
StringEsi         db  " ESI=",0
StringEdi         db  " EDI=",0
StringEflags      db  " EFLAGS=",0

Idtr        df  0

    org 21ffeh
BlockSignature:
    dw      0aa55h
    
    end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?