ucOS-II移植到S3C2410筆記之一
.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:實(shí)驗(yàn),刪掉如下代碼(OSRunning=1,即上面紅色部分代碼)后,系統(tǒng)正常。
3:分析
說明系統(tǒng)是在執(zhí)行OSRunning=1對(duì)應(yīng)的匯編代碼出現(xiàn)異常,于是查看變量OSRunning的定義:
ucos_ii.h:451:OS_EXT BOOLEAN OSRunning;
再查看BOOLEAN的原始類型:
os_cpu.h:42:typedef unsigned char BOOLEAN;
即變量OSRunning是unsigned char類型,至此,問題的原因已經(jīng)找到,即錯(cuò)誤的使用了匯編指令。
因?yàn)閰R編訪問C語言的變量時(shí),需要根據(jù)變量的類型,而確定其匯編指令,這里應(yīng)該使用:ldrb/strb
4: 修正后的代碼
mov r0, #1
ldrb r1, =OSRunning
strb r0, [r1]
5: 總結(jié)
匯編在訪問C語言的變量時(shí),需要根絕變量的類型使用不同的匯編指令:
unsigned char -----------------------> LDRB/STRB
unsigned short -----------------------> LDRH/STRH
unsigned int -----------------------> LDR/STR
char -----------------------> LDRSB/STRSB
short -----------------------> LDRSH/STRSH
評(píng)論