01.12.2014 Views

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

处 理 处 理 器 异 常<br />

; See Example 6-18 on page 6-33 for a version that works for calls from either <strong>ARM</strong> or Thumb.<br />

LDR r0,[lr,#-4] ; Calculate address of SWI instruction and load it into r0.<br />

BIC r0,r0,#0xFF000000 ; Mask off top 8 bits of instruction to give SWI number.<br />

; r0 now contains SWI number<br />

; r1 now contains pointer to stacked registers<br />

BL C_SWI_Handler ; Call C routine to handle the SWI.<br />

LDMFD sp!, {r0} ; Get spsr from stack.<br />

MSR spsr_cf, r0 ; Restore spsr.<br />

LDMFD sp!, {r0-r3,r12,pc}^ ; Restore registers and return.<br />

C 和 C++ 编 写 的 嵌 套 SWI<br />

可 用 C or C++ 汇 编 语 言 编 写 嵌 套 的 SWI。 由 <strong>ARM</strong> 编 译 程 序 生 成 的 代 码 按 需 要<br />

存 储 和 载 入 lr_SVC。<br />

6.6.4 从 应 用 程 序 调 用 SWI<br />

可 从 汇 编 语 言 或 C/C++ 调 用 SWI。<br />

在 汇 编 语 言 中 , 设 定 所 有 必 须 的 值 并 发 出 相 关 的 SWI。 例 如 :<br />

MOV r0, #65 ; load r0 with the value 65<br />

SWI 0x0 ; Call SWI 0x0 with parameter value in r0<br />

几 乎 像 所 有 的 <strong>ARM</strong> 指 令 那 样 , SWI 指 令 可 被 有 条 件 地 执 行 。<br />

从 C/C++ 中 将 SWI 声 明 为 一 个 __SWI 函 数 并 调 用 它 。 例 如 :<br />

__swi(0) void my_swi(int);<br />

.<br />

.<br />

.<br />

my_swi(65);<br />

它 确 保 了 SWI 以 内 联 方 式 进 行 编 译 , 勿 需 额 外 的 调 用 开 销 , 其 条 件 是 :<br />

• 任 何 自 变 量 只 能 被 传 递 到 r0-r3 ;<br />

• 任 何 结 果 只 能 被 返 回 到 r0-r3。<br />

6-22 © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 <strong>ARM</strong> DUI 0203BSC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!