首页 > 解决方案 > 'ret' 指令在不同 UEFI 实现上的行为是否不同?

问题描述

我有一个简单的打印字符串程序作为 UEFI 应用程序的一部分。我正在尝试使用输出控制台函数 OUTPUT_STRING 在屏幕上连续打印三个字符串

我正在努力的部分如下:

;--some code above this--
;Print information string
mov rcx, [CONOUT]
lea rdx, [info]
call [CONOUT_PRINT_STRING]

lea rdx, [info2]
call printString

mov rcx, [CONOUT]
lea rdx, [info3]
call [CONOUT_PRINT_STRING]

;--some code between this--

;prints a string
;rdx = the address of the string
printString:
    mov rcx, [CONOUT]
    call [CONOUT_PRINT_STRING]
    ret     
;--some code below this--

在 Qemu 中,这将正确打印所有三个字符串(位于 info、info2 和 info3)。但是,在我桌面的 BIOS 上,它将打印前两个字符串,而不打印第三个字符串。

将代码修改为以下内容会使所有三个字符串都在两台计算机上打印:

;--some code above this--
;Print information string
mov rcx, [CONOUT]
lea rdx, [info]
call [CONOUT_PRINT_STRING]

lea rdx, [info2]
call printString
next:

mov rcx, [CONOUT]
lea rdx, [info3]
call [CONOUT_PRINT_STRING]

;--some code between this--

;prints a string
;rdx = the address of the string
printString:
    mov rcx, [CONOUT]
    call [CONOUT_PRINT_STRING]
    push next
    ret     
;--some code below this--

但是,这违背了 this 作为函数的目的,因为我希望能够在我的应用程序中多次使用它。

我的问题是,为什么 ret 在我的桌面 UEFI 实现上没有做我期望它做的事情?是因为我的程序,还是 UEFI 本身?(作为参考,我的主板是 AsRock Steel Legend B450M,BIOS 版本 4.10)

如果这是我的程序问题,我该如何解决?

谢谢!

标签: assemblyx86-64nasmqemuuefi

解决方案


推荐阅读