📌 置頂: 請把任何比你弱勢的用路人當作你的至親對待。跟前車保持安全車距 (2秒以上)。

ARM Semihosting 簡介與範例

In

Tags:



by

前言 – What is semihosting?

Semihosting 是 ARM 中的一個機制,使得 ARM target 可以藉由運行 debugger 的 host computer 的 Input/Output 裝置來進行溝通。

Semihost 的實作是透過使用定義好的軟體中斷 (SVCs),使程式在執行過程中產生中斷。一旦目標系統上的程式呼叫到對應的指令 (semihosting call),便產生軟體中斷,接著 Debug Agent 就會負責處理此中斷,進行與主機的溝通。[1]

Semihosting Interface

Semihosting 透過 SVC 指令來調用相關的命令, 以下為三種不同的使用方式:

SVC 0x123456

In ARM state for all architectures.

SVC 0xAB

In ARM state and Thumb state, excluding ARMv6-M and ARMv7-M. This behavior is not guaranteed on all debug targets from ARM or from third parties.

BKPT 0xAB

For ARMv6-M and ARMv7-M, Thumb state only.

同時,Operations type 被存放於 R0 暫存器,parameters 之位置存放於 R1 暫存器

可用的 semihosting operation number 如下列表:

0x00-0x31

Used by ARM.

0x32-0xFF

Reserved for future use by ARM.

0x100-0x1FF

Reserved for user applications. These are not used by ARM.

If you are writing your own SVC operations, however, you are advised to use a different SVC number rather than using the semihosted SVC number and these operation type numbers.

0x200-0xFFFFFFFF

Undefined and currently unused. It is recommended that you do not use these.

範例

以下範例可用於 Cortex-M4 系列之 ARM CPU

Reference

[1] Lab7: On-Chip Debugger + semihosting, http://wiki.csie.ncku.edu.tw/embedded/Lab7

[2] debug.h, https://github.com/zhiyb/SRAMLoader/blob/0d38d09c973e88df3a9060dbbe02c2f5020e99bc/debug.h

[3] Semihosting on ARM with GCC and OpenOCD, http://bgamari.github.io/posts/2014-10-31-semihosting.html

[4]: What is semihosting?, http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bacbedji.html


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.