optee内核中栈的介绍(一)
快速鏈接:
.
👉👉👉 個(gè)人博客筆記導(dǎo)讀目錄(全部) 👈👈👈
相關(guān)推薦:
1、optee的棧指針和棧內(nèi)存的介紹
2、optee aarch64體系下棧的設(shè)計(jì)(sp_el0/sp_el1)
文章目錄
- 1、optee內(nèi)核的反匯編文件
- 2、optee中的內(nèi)核棧的定義
- 3、optee中的內(nèi)核棧的設(shè)置
1、optee內(nèi)核的反匯編文件
內(nèi)核棧定義在nozi段
out/arm-plat-xxxx/core/tee.elf: file format elf64-littleaarch64 out/arm-plat-xxxx/core/tee.elf architecture: aarch64, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0000000080020000Program Header:LOAD off 0x0000000000010000 vaddr 0x0000000080020000 paddr 0x0000000080020000 align 2**16filesz 0x0000000000051538 memsz 0x00000000003d0b80 flags rwxSTACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw- private flags = 0:Sections: Idx Name Size VMA LMA File off Algn0 .text 00042e00 0000000080020000 0000000080020000 00010000 2**11 ---------- 代碼段CONTENTS, ALLOC, LOAD, READONLY, CODE1 .rodata 0000bd08 0000000080062e00 0000000080062e00 00052e00 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA2 .data 00002538 000000008006f000 000000008006f000 0005f000 2**3CONTENTS, ALLOC, LOAD, DATA3 .bss 00019270 0000000080071540 0000000080071540 00061538 2**5ALLOC4 .heap1 00301850 000000008008a7b0 000000008008a7b0 00061538 2**0 ---------- 堆,malloc就使用的這里的內(nèi)存ALLOC5 .nozi 00064b80 000000008038c000 000000008038c000 00061538 2**12 ----------non zero initialized, optee的內(nèi)核棧在這里ALLOC6 .debug_info 000e1253 0000000000000000 0000000000000000 00061538 2**0CONTENTS, READONLY, DEBUGGING7 .debug_abbrev 00023d00 0000000000000000 0000000000000000 0014278b 2**0CONTENTS, READONLY, DEBUGGING8 .debug_loc 000c0b5d 0000000000000000 0000000000000000 0016648b 2**0CONTENTS, READONLY, DEBUGGING9 .debug_aranges 00008110 0000000000000000 0000000000000000 00226ff0 2**4CONTENTS, READONLY, DEBUGGING10 .debug_ranges 0000da30 0000000000000000 0000000000000000 0022f100 2**4CONTENTS, READONLY, DEBUGGING11 .debug_line 00028b2a 0000000000000000 0000000000000000 0023cb30 2**0CONTENTS, READONLY, DEBUGGING12 .debug_str 0001117d 0000000000000000 0000000000000000 0026565a 2**0CONTENTS, READONLY, DEBUGGING13 .debug_frame 00011998 0000000000000000 0000000000000000 002767d8 2**3CONTENTS, READONLY, DEBUGGING2、optee中的內(nèi)核棧的定義
通過上述分析,我們知道m(xù)alloc從堆中分配內(nèi)存,且堆的大小是固定的,那么除去代碼端、section段、堆之后,剩余的空間都是什么呢?
剩余的空間都是.nozi段,optee中的棧就定義在此段,包含stack_tmp、stack_abt、stack_thread棧
optee內(nèi)核中定義三個(gè)棧 : stack_tmp、stack_abt、stack_thread:
DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE, STACK_TMP_SIZE, static); //aarch32下給atf用的棧
DECLARE_STACK(stack_abt, CFG_TEE_CORE_NB_CORE, STACK_ABT_SIZE, static); //異常棧
DECLARE_STACK(stack_thread, CFG_NUM_THREADS, STACK_THREAD_SIZE, static); //optee內(nèi)核棧
棧的大小
#define STACK_TMP_SIZE (3072 + STACK_TMP_OFFS) #define STACK_THREAD_SIZE 8192 #define STACK_ABT_SIZE 3072這三個(gè)棧都定義在nozi_stack段,而nozi_stack又在nozi段中
#define DECLARE_STACK(name, num_stacks, stack_size, linkage) \ linkage uint32_t name[num_stacks] \[ROUNDUP(stack_size + STACK_CANARY_SIZE, STACK_ALIGNMENT) / \sizeof(uint32_t)] \__attribute__((section(".nozi_stack"), \aligned(STACK_ALIGNMENT))) .nozi (NOLOAD) : {__nozi_start = .;ASSERT(!(__nozi_start & (16 * 1024 - 1)), "align nozi to 16kB");KEEP(*(.nozi .nozi.*)). = ALIGN(16);__nozi_end = .;__nozi_stack_start = .;KEEP(*(.nozi_stack)). = ALIGN(8);__nozi_stack_end = .;}3、optee中的內(nèi)核棧的設(shè)置
在generic_entry_a64.S中_start函數(shù)中,調(diào)用 set_sp 宏找到optee中的內(nèi)核棧(stack_thread)的地址,然后將其寫入到sp_el1中
.macro set_spbl __get_core_poscmp x0, #CFG_TEE_CORE_NB_CORE/* Unsupported CPU, park it before it breaks something */bge unhandled_cpuadr x1, stack_tmp_strideldr w1, [x1]mul x1, x0, x1adrp x0, stack_tmp_exportadd x0, x0, :lo12:stack_tmp_exportldr x0, [x0]msr spsel, #0add sp, x1, x0bl thread_get_core_local //-----------------獲取stack_thread棧的地址-msr spsel, #1mov sp, x0msr spsel, #0.endmstruct thread_core_local *thread_get_core_local(void) {uint32_t cpu_id = get_core_pos();/** Foreign interrupts must be disabled before playing with core_local* since we otherwise may be rescheduled to a different core in the* middle of this function.*/assert(thread_get_exceptions() & THREAD_EXCP_FOREIGN_INTR);assert(cpu_id < CFG_TEE_CORE_NB_CORE);return &thread_core_local[cpu_id]; //------------------------返回stack_thread棧的地址 }總結(jié)
以上是生活随笔為你收集整理的optee内核中栈的介绍(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [hypervisor]-AArch64
- 下一篇: optee堆Virtualization