日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

[ATF]-ATF的RT_SVC的详解(runtime service)

發(fā)布時(shí)間:2025/3/21 c/c++ 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [ATF]-ATF的RT_SVC的详解(runtime service) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

        • 1、RT_SVC的分類
        • 2、RT_SVC的注冊(cè)
        • 3、rt_svc定義的原理和rt_svc的請(qǐng)求實(shí)現(xiàn)


★★★ 鏈接 : 個(gè)人博客導(dǎo)讀首頁—點(diǎn)擊此處 ★★★


1、RT_SVC的分類

在SCC文檔中對(duì)rt_svc進(jìn)行了定義和分類,具體形式如下:

  • ARM Architecture Calls
  • CPU Service Calls
  • SiP Service Calls
  • OEM Service Calls
  • Standard Secure Service Calls
  • Standard Hypervisor Service Calls
  • Vendor Specific Hypervisor Service Calls
  • Trusted Application Calls
  • Trusted OS Calls

目前我們?cè)贏TF中常用的主要是Trusted OS Calls,如果是在MTK平臺(tái)上SiP Service Calls也常使用的.

2、RT_SVC的注冊(cè)

在ATF中有多種類型的rt_svc, 不同的rt_svc為不同的場景服務(wù). 我們下面舉三個(gè)例子詳細(xì)說明:

(1)、Trusted OS Calls
我們以optee os為例,在ATF中注冊(cè)一個(gè)rt_svc,為linux和optee_os交互服務(wù).

例如在opteed_main.c中,定義了一個(gè)service,該servic call ranges是OEN_TOS_START–OEN_TOS_END,正好落在50-63之間, 對(duì)應(yīng)的就是Trusted OS Calls

DECLARE_RT_SVC(opteed_fast,OEN_TOS_START,OEN_TOS_END,SMC_TYPE_FAST,opteed_setup,opteed_smc_handler );

那么我們?cè)趌inux kernel程序中,想和optee os通信,需要通過ATF中的這類rt_svc才行,所以呢我們?cè)趌inux kernel中構(gòu)造的smc cmdid的bit29:24需為50–63之間,才能調(diào)起ATF中的該服務(wù)。 同樣,在optee發(fā)起返回linux kernel的smc call的smcid也需在50–63之間

(2)、ARM Architecture Calls
例如在arm_arch_svc_setup.c中,定義了一個(gè)service,它的call類型是OEN_ARM_START–OEN_ARM_END,落在0-0之間,對(duì)應(yīng)的恰好是ARM Architecture Calls

/* Register Standard Service Calls as runtime service */ DECLARE_RT_SVC(arm_arch_svc,OEN_ARM_START,OEN_ARM_END,SMC_TYPE_FAST,NULL,arm_arch_svc_smc_handler );

那么我們?cè)趌inux kernel中,調(diào)用smc時(shí)的smc id的bit29:24需要等于0,此次的smc調(diào)用才會(huì)調(diào)用到這個(gè)runtime service的handler程序

(3)、SiP Service Calls
例如在mtk_sip_svc.c中,定義了一個(gè)service,它的call類型是OEN_SIP_START–OEN_SIP_END,落在2-2之間,對(duì)應(yīng)的恰好是SiP Service Calls

/* Define a runtime service descriptor for fast SMC calls */ DECLARE_RT_SVC(mediatek_sip_svc,OEN_SIP_START,OEN_SIP_END,SMC_TYPE_FAST,NULL,sip_smc_handler );

那么我們?cè)趌inux kernel中,調(diào)用smc時(shí)的smc id的bit29:24需要等于2,那么此次的smc調(diào)用才會(huì)調(diào)用到這個(gè)runtime service的handler程序

3、rt_svc定義的原理和rt_svc的請(qǐng)求實(shí)現(xiàn)

**(1)、定義實(shí)現(xiàn) **
在runtime_svc.h中,DECLARE_RT_SVC宏其實(shí)就是在section(“rt_svc_descs”)段中定義了一個(gè)全局變量.

/** Convenience macros to declare a service descriptor*/ #define DECLARE_RT_SVC(_name, _start, _end, _type, _setup, _smch) \static const rt_svc_desc_t __svc_desc_ ## _name \__section("rt_svc_descs") __used = { \.start_oen = (_start), \.end_oen = (_end), \.call_type = (_type), \.name = #_name, \.init = (_setup), \.handle = (_smch) \}

section “rt_svc_descs”在RT_SVC_DESCS宏中

#define RT_SVC_DESCS \. = ALIGN(STRUCT_ALIGN); \__RT_SVC_DESCS_START__ = .; \KEEP(*(rt_svc_descs)) \__RT_SVC_DESCS_END__ = .;

而在rodata_common的宏中,定義了RT_SVC_DESCS

#define RODATA_COMMON \RT_SVC_DESCS \FCONF_POPULATOR \PMF_SVC_DESCS \PARSER_LIB_DESCS \CPU_OPS \GOT \BASE_XLAT_TABLE_RO

在bl31.ld.S中,將RODATA_COMMON放入了rodata段

.rodata . : {__RODATA_START__ = .;*(SORT_BY_ALIGNMENT(.rodata*))RODATA_COMMON/* Place pubsub sections for events */. = ALIGN(8); #include <lib/el3_runtime/pubsub_events.h>. = ALIGN(PAGE_SIZE);__RODATA_END__ = .;} >RAM

(2)、請(qǐng)求RT_SVC

在linux/optee中調(diào)用smc call后,觸發(fā)同步異常,進(jìn)入smc_handler64程序,然后跳轉(zhuǎn)到對(duì)應(yīng)的rt_svc

完整代碼和注釋如下

smc_handler64:/* NOTE: The code below must preserve x0-x4 *//** Save general purpose and ARMv8.3-PAuth registers (if enabled).* If Secure Cycle Counter is not disabled in MDCR_EL3 when* ARMv8.5-PMU is implemented, save PMCR_EL0 and disable Cycle Counter.*/bl save_gp_pmcr_pauth_regs#if ENABLE_PAUTH/* Load and program APIAKey firmware key */bl pauth_load_bl31_apiakey #endif/** Populate the parameters for the SMC handler.* We already have x0-x4 in place. x5 will point to a cookie (not used* now). x6 will point to the context structure (SP_EL3) and x7 will* contain flags we need to pass to the handler.*/mov x5, xzrmov x6, sp/** Restore the saved C runtime stack value which will become the new* SP_EL0 i.e. EL3 runtime stack. It was saved in the 'cpu_context'* structure prior to the last ERET from EL3.*/ldr x12, [x6, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP]/* Switch to SP_EL0 */msr spsel, #MODE_SP_EL0/** Save the SPSR_EL3, ELR_EL3, & SCR_EL3 in case there is a world* switch during SMC handling.* TODO: Revisit if all system registers can be saved later.*/mrs x16, spsr_el3mrs x17, elr_el3mrs x18, scr_el3stp x16, x17, [x6, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3]str x18, [x6, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3]/* Copy SCR_EL3.NS bit to the flag to indicate caller's security */bfi x7, x18, #0, #1mov sp, x12/* Get the unique owning entity number */ubfx x16, x0, #FUNCID_OEN_SHIFT, #FUNCID_OEN_WIDTH ---------------- 獲取FUNCID_OEN_SHIFT,對(duì)應(yīng)第一節(jié)中的OEN_TOS_STARTubfx x15, x0, #FUNCID_TYPE_SHIFT, #FUNCID_TYPE_WIDTH ---------------- 獲取FUNCID_TYPE_SHIFT,對(duì)應(yīng)第一節(jié)中的SMC_TYPE_FAST(fast還是yield,yield其實(shí)就是standard)orr x16, x16, x15, lsl #FUNCID_OEN_WIDTH/* Load descriptor index from array of indices */adrp x14, rt_svc_descs_indices ----runtime_svc_init()中會(huì)將所有的section rt_svc_descs段放入rt_svc_descs_indices數(shù)組,這里獲取該數(shù)組地址add x14, x14, :lo12:rt_svc_descs_indicesldrb w15, [x14, x16] ---找到rt_svc在rt_svc_descs_indices數(shù)組中的index/* Any index greater than 127 is invalid. Check bit 7. */tbnz w15, 7, smc_unknown/** Get the descriptor using the index* x11 = (base + off), w15 = index -------------------------重要的注釋** handler = (base + off) + (index << log2(size)) ------ 這句注釋特別重要,整段匯編看不懂沒關(guān)系,這句注釋看懂就行*/adr x11, (__RT_SVC_DESCS_START__ + RT_SVC_DESC_HANDLE)lsl w10, w15, #RT_SVC_SIZE_LOG2ldr x15, [x11, w10, uxtw] ------------------------------這句話對(duì)應(yīng)的就是上述注釋:handler = (base + off) + (index << log2(size))/** Call the Secure Monitor Call handler and then drop directly into* el3_exit() which will program any remaining architectural state* prior to issuing the ERET to the desired lower EL.*/ #if DEBUGcbz x15, rt_svc_fw_critical_error #endifblr x15 -------------------------------------跳轉(zhuǎn)到handlerb el3_exit

總結(jié)

以上是生活随笔為你收集整理的[ATF]-ATF的RT_SVC的详解(runtime service)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。