gpt4 book ai didi

assembly - 编写自己的SVC调用ARM汇编

转载 作者:行者123 更新时间:2023-12-02 19:52:21 28 4
gpt4 key购买 nike

我想知道在基于 ARM 的微 Controller 上编写 SVC 调用的正确方法。

到目前为止,我的理解是 ARM 有一个异常向量表,这意味着任何程序中的第一条指令都必须分支到适当的处理程序:

RESET          ;Handles reset
UNDEFINED ;Undefined instructions
SVC BL SVC_Entry
PRE_ABORT ;Prefetch abort
DAT_ABORT ;Data abort

然后,每次运行 SVC 指令时,模式都会切换到管理程序,SVC 提供的编号存储在 R0 中,程序将分支到适当的处理程序:

;== Handling SVC calls ========================================================

Max_SVC EQU 1

SVC_Entry CMP R0, #Max_SVC ;Check upper limit
BHI SVC_end ;Does nothing if unknown
ADD R0, PC, R0, LSL #2 ;Calculate table address
LDR PC, [R0, #0]

Jump_table DEFW SVC_0 ;Halt
DEFW SVC_1 ;Print string

;== SVC calls ================================================================

SVC_1 B SVC_end

SVC_end MOVS PC, LR ;Exiting

所以,如果我们有这些说明:

ADR R1, string       ;R1 points to the string
SVC 1 ;SVC_1 handles the printing

程序必须切换到管理员模式,将数字“1”存储在 R0 中,然后按照跳转表分支到 SVC_1,运行代码并切换回用户模式。

这是正确的吗?我这样做对吗?

到目前为止,我遇到的问题是我的编译器对此行显示“需要运算符”:

SVC             BL            SVC_Entry 

在互联网上很难找到有关此主题的信息,我只是想知道如何在 ARM 微 Controller 上正确使用 SVC 调用。

非常感谢。

编辑:底层处理器是 ARM9,主频约为 240 MHz。这住在AT91 微 Controller 。它所在的实验室委员会已经过修改,以满足我大学的需求。

使用定制程序通过串口将代码加载到板上。该程序还允许调试。

最佳答案

如前所述,不要使用 BL 跳转到 SVC 条目,而使用 B。首先有一个例程来确定 SVC 编号。 (我的称为 SVC_dispatcher)。你在哪所大学?我将尝试彻底解释这一点,不会假设您知道多少或不知道多少。我已经输入了正确的术语,因此如果我的评论不清楚或者您想要更深入的信息,您可以通过谷歌搜索来获取更多信息。我不确定冒号的标记方法,我习惯了旧的指令集。

祝你好运

SVC_dispatcher
PUSH {LR} ; always save your LR
LDR R14, [LR, #-4] ; its been stacked, so we can it (LR is R14)
; the link register is the line after the SVC instruction
; above, we load the instruction that is one before the
; link register (#-4 preindexed load) means instruction (SVC 1) into R14.

; Use bit clear to remove the mnemonic from the 32 bit instruction,
; leaving the data (1)
BIC R14, R14, #&FF000000

SVC_entry
CMP R14, #Max_SVC
BHI SVC_unknown
ADR R1, Jump_Table ; use this format, never add to the PC
LDR PC, [R1, R14, LSL #2]
; Beware: PC can be changed by IRQs **AT ANY TIME**

Jump_Table ; you know the drill here
DEFW SVC_0
DEFW SVC_1

SVC_0 B SVC_end

SVC_1 BL printString ; consider stacking registers that printString
B SVC_end ; will corrupt

SVC_end POP {LR} ; restore link register
MOV PC, LR

关于assembly - 编写自己的SVC调用ARM汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16156404/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com