From 6a0e38c0d5e0a7f8982fdd27d2a1385bfc18e55e Mon Sep 17 00:00:00 2001 From: asterix Date: Fri, 24 Apr 2009 16:46:26 +0000 Subject: [PATCH] Fix kernel bug: process on arm never exit. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2666 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/arm/hw/switch_ctx_arm.S | 10 +++++++++- bertos/cpu/frame.h | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bertos/cpu/arm/hw/switch_ctx_arm.S b/bertos/cpu/arm/hw/switch_ctx_arm.S index bde843cd..39e9f46a 100644 --- a/bertos/cpu/arm/hw/switch_ctx_arm.S +++ b/bertos/cpu/arm/hw/switch_ctx_arm.S @@ -42,6 +42,13 @@ .globl asm_switch_context asm_switch_context: mrs r2, cpsr /* Save status. */ + + /* + * To work correctly the lr should point to proc_exit, so when process finish + * could be return + */ + push {lr} /* Add one element on stack, for next switching */ + stmfd sp!, {r2, r4-r11, lr} /* Save registers. */ str sp, [r1] /* Save old stack pointer. */ @@ -50,4 +57,5 @@ asm_switch_context: ldmfd sp!, {r2, r4-r11, lr} /* Load new registers. */ msr cpsr, r2 /* restore flags reg. */ - mov pc, lr + pop {r0} /* pop on stack address of the process that we want to jump */ + mov pc, r0 diff --git a/bertos/cpu/frame.h b/bertos/cpu/frame.h index c9635156..1a80fa1d 100644 --- a/bertos/cpu/frame.h +++ b/bertos/cpu/frame.h @@ -58,7 +58,7 @@ #elif CPU_ARM - #define CPU_SAVED_REGS_CNT 9 + #define CPU_SAVED_REGS_CNT 10 #define CPU_STACK_GROWS_UPWARD 0 #define CPU_SP_ON_EMPTY_SLOT 0 @@ -74,7 +74,14 @@ * - ARM state. * - CPU in Supervisor Mode (SVC). */ - #define CPU_REG_INIT_VALUE(reg) (reg == (CPU_SAVED_REGS_CNT - 1) ? 0x13 : 0) + #define CPU_REG_INIT_VALUE(reg) \ + ({ int a = 0; \ + if(reg == 0) \ + a = (int)proc_exit; \ + else if(reg == (CPU_SAVED_REGS_CNT - 1)) \ + a = 0x13; \ + a; \ + }) #elif CPU_PPC -- 2.25.1