2012年2月6日 星期一

assembly call C function

UEFI BIOS在 SEC進PEI階段會由assembly code 進入C code,
除了設定好stack 外, 就是要注意assembly call C function的方法
會先把參數以反順序的方式push到stack, 然後call PEI的主程式
不過這跟一般的assembly call c function不一樣的是, UEFI BIOS
不會再回到assembly mode, 所以不需要再把esp 調整回來!
一般的assembly call C function要把esp加上參數總共size.
範例如下

global  _main

extern  _printf

section .data

text    db      "291 is the best!", 10, 0
strformat db    "%s", 0

section .code

_main
        push    dword text
        push    dword strformat
        call    _printf
        add     esp, 8
        ret

沒有留言:

張貼留言