1: 问题: 移植汇编函数:OSStartHighRdy, 如下,但发现只要OS_TaskIdle一个使命时,都不能正确运转。
.globl OSStartHighRdy
.type OSStartHighRdy, %function
OSStartHighRdy:
/* C variable OSRunning = TRUE */
mov r0, #1
ldr r1, =OSRunning
str r0, [r1]
/* get the stack pointer of task that will be running. */
ldr r5, =OSTCBHighRdy /* R0= the address of pointer variable OSTCBHighRdy */
ldr r6, [r5] /* R1= the the value of pointer variable OSTCBHighRdy= OS_TCB(TaskIdle) */
ldr r7, [r6] /* R2= the value of pointer variable OS_TCB->OSTCBStkPtr, the value is address*/
/*ldr r8, [r7]*/ /* R3= the value of pointer*/
mov sp, r7 /* restore SP*/
ldr r1, [sp, #0]
msr cpsr, r1 /* restore CPSR */
add sp, sp, #4 /* pointer to R0 location */
ldmia sp!,{r0-r12, lr, pc} /* restore R0-R12, LR, PC */
2:试验,删掉如下代码(OSRunning=1,即上面赤色部分代码)后,体系正常。
3:剖析
阐明体系是在履行OSRunning=1对应的汇编代码出现异常,所以检查变量OSRunning的界说:
ucos_ii.h:451:OS_EXT BOOLEAN OSRunning;
再检查BOOLEAN的原始类型:
os_cpu.h:42:typedef unsigned char BOOLEAN;
即变量OSRunning是unsigned char类型,至此,问题的原因现已找到,即过错的运用了汇编指令。
由于汇编拜访C言语的变量时,需求依据变量的类型,而确认其汇编指令,这儿应该运用:ldrb/strb
4: 修正后的代码
mov r0, #1
ldrb r1, =OSRunning
strb r0, [r1]
5: 总结
汇编在拜访C言语的变量时,需求根绝变量的类型运用不同的汇编指令:
unsigned char ———————–> LDRB/STRB
unsigned short ———————–> LDRH/STRH
unsigned int ———————–> LDR/STR
char ———————–> LDRSB/STRSB
short ———————–> LDRSH/STRSH