ASM language tips

Table of Contents

Position-independent Call

下面这个片段很有意思,利用ldr指令来调整pc指针位置,来曲线实现PIE
https://github.com/OP-TEE/optee_os/tree/1c832d7c41cdb2f617bffa74c3d70f7c4a5667fc/core/arch/arm/kernel/generic_entry_a64.S#L28

.macro readjust_pc
#ifdef CFG_CORE_ASLR
ldr x16, =1111f
br  x16
1111:
#endif
.endm

LOCAL_FUNC vector_std_smc_entry , : , .identity_map
readjust_pc
bl  thread_handle_std_smc
/*
 * Normally thread_handle_std_smc() should return via
 * thread_exit(), thread_rpc(), but if thread_handle_std_smc()
 * hasn't switched stack (error detected) it will do a normal "C"
 * return.
 */
mov w1, w0
ldr x0, =TEESMC_OPTEED_RETURN_CALL_DONE
smc #0
b   .   /* SMC should not return */
END_FUNC vector_std_smc_entry

inline asm

下面就是内联汇编的原型定义了,共由4部份组成,见如下

asm ( assembler template
    : output operands                  /* optional */
    : input operands                   /* optional */
    : list of clobbered registers      /* optional */
);

assembler template

这个部份用来写汇编代码的模板, 编写的模板会用来给汇编器升成最终的代码

output operands

输出参数劣别

Contact me via :)
虚怀乃若谷,水深则流缓。