optee:kernel space调用user space进程时候的硬件行为
生活随笔
收集整理的這篇文章主要介紹了
optee:kernel space调用user space进程时候的硬件行为
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 1、先看kernel調(diào)用userspace所需的的參數(shù)
- 2、先看kernel mode切換user mode的寄存器行為
★★★ 鏈接 : 個人博客導(dǎo)讀首頁—點擊此處 ★★★
我們以optee為例,看下kernel space調(diào)用user space時有哪些硬件行為
1、先看kernel調(diào)用userspace所需的的參數(shù)
- 函數(shù)入庫
- session
- 函數(shù)參數(shù)
- cmd
- usr_stack //該應(yīng)用程序的棧地址
- enrty_func
- is_32bit //該參數(shù)只是在kernel中使用
- panicked
- panic_code
2、先看kernel mode切換user mode的寄存器行為
將usr_stack地址,同時寫入到了x13(R13/sp_usr)、和SP_EL0, 也就是在此處,程序并不需要知道你的userspace是32位或64位
FUNC __thread_enter_user_mode , :ldr x8, [sp]/** Create the and fill in the struct thread_user_mode_rec*/sub sp, sp, #THREAD_USER_MODE_REC_SIZEstore_xregs sp, THREAD_USER_MODE_REC_EXIT_STATUS0_PTR, 7, 8store_xregs sp, THREAD_USER_MODE_REC_X19, 19, 30/** Switch to SP_EL1* Disable exceptions* Save kern sp in x19*/msr daifset, #DAIFBIT_ALLmov x19, spmsr spsel, #1/** Save the kernel stack pointer in the thread context*//* get pointer to current thread context */get_thread_ctx sp, 21, 20, 22/** Save kernel stack pointer to ensure that el0_svc() uses* correct stack pointer*/str x19, [x21, #THREAD_CTX_KERN_SP]/** Initialize SPSR, ELR_EL1, and SP_EL0 to enter user mode*/msr spsr_el1, x6/* Set user sp */mov x13, x4 /* Used when running TA in Aarch32 */msr sp_el0, x4 /* Used when running TA in Aarch64 *//* Set user function */msr elr_el1, x5/* Set frame pointer (user stack can't be unwound past this point) */mov x29, #0/* Jump into user mode */store_xregs sp, THREAD_CORE_LOCAL_X0, 0, 1b eret_to_el0 END_FUNC __thread_enter_user_mode總結(jié)
以上是生活随笔為你收集整理的optee:kernel space调用user space进程时候的硬件行为的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [思考]-32位的应用程序和64位的应用
- 下一篇: optee userpace TA程序中