summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHesham ALMatary <heshamelmatary@gmail.com>2014-09-15 17:33:28 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2014-09-16 09:52:56 -0500
commiteb14fc2b2ea49aa8a7b4f464de9360a129845b73 (patch)
tree7e420a6627016c823c7fc905c160f3c9cc9d3f67
parentsptests/sp07: Minimize thread dispatch latency (diff)
downloadrtems-eb14fc2b2ea49aa8a7b4f464de9360a129845b73.tar.bz2
OpenRISC: Account for red-zone (fixup printf bug).
This patch allocate a space in the stack to account for red-zone that gcc may utilize for the use of leaf functions. Care must be taken to handle this red-zone from many places: 1- Upon creation of a new thread stack. 2- Once an interrupt entred. Also moving the enable-thread-dispach() and increment ISR level before checking if dispatch needed was required. The previous modifications solved the printf bug which disabled ticker to output strings after context switches that arise from Thread_Delay_ended.
-rw-r--r--c/src/lib/libbsp/or1k/or1ksim/start/start.S2
-rw-r--r--cpukit/score/cpu/or1k/or1k-context-initialize.c3
-rw-r--r--cpukit/score/cpu/or1k/or1k-exception-handler-low.S38
3 files changed, 23 insertions, 20 deletions
diff --git a/c/src/lib/libbsp/or1k/or1ksim/start/start.S b/c/src/lib/libbsp/or1k/or1ksim/start/start.S
index 6942b5217f..4d911d4a41 100644
--- a/c/src/lib/libbsp/or1k/or1ksim/start/start.S
+++ b/c/src/lib/libbsp/or1k/or1ksim/start/start.S
@@ -16,7 +16,7 @@
*/
#define EXCEPTION_SETUP(vector) \
l.nop ;\
- l.addi r1, r1, -4 ;\
+ l.addi r1, r1, -200 ;\
l.sw 0(r1), r3; \
l.addi r3, r0, vector; \
l.j _ISR_Handler; \
diff --git a/cpukit/score/cpu/or1k/or1k-context-initialize.c b/cpukit/score/cpu/or1k/or1k-context-initialize.c
index 7ac2875ce7..1c9cdd7b5e 100644
--- a/cpukit/score/cpu/or1k/or1k-context-initialize.c
+++ b/cpukit/score/cpu/or1k/or1k-context-initialize.c
@@ -29,7 +29,8 @@ void _CPU_Context_Initialize(
void *tls_area
)
{
- uint32_t stack = (uint32_t) stack_area_begin;
+ /* Decrement 200 byte to account for red-zone */
+ uint32_t stack = ((uint32_t) stack_area_begin) - 200;
uint32_t sr;
sr = _OR1K_mfspr(CPU_OR1K_SPR_SR);
diff --git a/cpukit/score/cpu/or1k/or1k-exception-handler-low.S b/cpukit/score/cpu/or1k/or1k-exception-handler-low.S
index 7108ff65b5..3a0425b6d5 100644
--- a/cpukit/score/cpu/or1k/or1k-exception-handler-low.S
+++ b/cpukit/score/cpu/or1k/or1k-exception-handler-low.S
@@ -93,7 +93,7 @@ PUBLIC(_ISR_Handler)
l.sw 0(r8), r7
/* Save interrupted task stack pointer */
- l.addi r4, r1, 144
+ l.addi r4, r1, 340
l.sw 4(r1), r4
/* Save interrupted task r3 (first arg) value */
@@ -118,7 +118,7 @@ PUBLIC(_ISR_Handler)
/* Do not switch stacks if we are in a nested interrupt. At
* this point r5 should be holding ISR_NEST_LEVEL value.
*/
- l.sfgtui r5, 2
+ l.sfgtui r5, 1
l.bf jump_to_c_handler
l.nop
@@ -134,6 +134,21 @@ jump_to_c_handler:
/* Switch back to the interrupted task stack */
l.add r1, r14, r0
+ /* Decrement nesting level */
+ l.movhi r6, hi(ISR_NEST_LEVEL)
+ l.ori r6, r6, lo(ISR_NEST_LEVEL)
+
+ /* Enable multitasking */
+ l.movhi r8, hi(THREAD_DISPATCH_DISABLE_LEVEL)
+ l.ori r8, r8, lo(THREAD_DISPATCH_DISABLE_LEVEL)
+
+ l.lwz r5, 0(r6)
+ l.lwz r7, 0(r8)
+ l.addi r5, r5, -1
+ l.addi r7, r7, -1
+ l.sw 0(r6), r5
+ l.sw 0(r8), r7
+
/* Check if dispatch needed */
l.movhi r31, hi(DISPATCH_NEEDED)
l.ori r31, r31, lo(DISPATCH_NEEDED)
@@ -163,21 +178,6 @@ jump_to_c_handler:
l.lwz r13, 136(r1)
l.mtspr r0, r13, CPU_OR1K_SPR_ESR0
- /* Increment nesting level */
- l.movhi r6, hi(ISR_NEST_LEVEL)
- l.ori r6, r6, lo(ISR_NEST_LEVEL)
-
- /* Disable multitasking */
- l.movhi r8, hi(THREAD_DISPATCH_DISABLE_LEVEL)
- l.ori r8, r8, lo(THREAD_DISPATCH_DISABLE_LEVEL)
-
- l.lwz r5, 0(r6)
- l.lwz r7, 0(r8)
- l.addi r5, r5, -1
- l.addi r7, r7, -1
- l.sw 0(r6), r5
- l.sw 0(r8), r7
-
l.lwz r2, 8(r1)
l.lwz r3, 12(r1)
l.lwz r4, 16(r1)
@@ -209,9 +209,11 @@ jump_to_c_handler:
l.lwz r30, 120(r1)
l.lwz r31, 124(r1)
+ /* Unwind exception frame */
l.addi r1, r1, 140
- l.addi r1, r1, 4
+ /* Red-zone */
+ l.addi r1, r1, 200
l.rfe
l.nop