summaryrefslogtreecommitdiffstats
path: root/cpukit/score/cpu/avr
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-28 23:14:23 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-28 23:14:23 +0000
commitb32020b4707a7ca532a0760621ad501aac0422c4 (patch)
tree1494c1247256e6ccb09f08c1f325a2729b2ecd56 /cpukit/score/cpu/avr
parent2009-07-28 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-b32020b4707a7ca532a0760621ad501aac0422c4.tar.bz2
2009-07-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* cpu.c, cpu_asm.S, rtems/score/cpu.h: Context switch now works well enough to run ticker to completion with the simulator clock idle task. But if you comment out the printk's in _CPU_Context_Initialize, it hangs. This remains to be investigated.
Diffstat (limited to 'cpukit/score/cpu/avr')
-rw-r--r--cpukit/score/cpu/avr/ChangeLog7
-rw-r--r--cpukit/score/cpu/avr/cpu.c49
-rw-r--r--cpukit/score/cpu/avr/cpu_asm.S123
-rw-r--r--cpukit/score/cpu/avr/rtems/score/cpu.h20
4 files changed, 103 insertions, 96 deletions
diff --git a/cpukit/score/cpu/avr/ChangeLog b/cpukit/score/cpu/avr/ChangeLog
index 2a36794e38..7a7d9a543a 100644
--- a/cpukit/score/cpu/avr/ChangeLog
+++ b/cpukit/score/cpu/avr/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-28 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * cpu.c, cpu_asm.S, rtems/score/cpu.h: Context switch now works well
+ enough to run ticker to completion with the simulator clock idle
+ task. But if you comment out the printk's in _CPU_Context_Initialize,
+ it hangs. This remains to be investigated.
+
2009-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* cpu.c, cpu_asm.S: Unsuccessful attempt to fix.
diff --git a/cpukit/score/cpu/avr/cpu.c b/cpukit/score/cpu/avr/cpu.c
index 8fe4c0e421..c4ec993eb3 100644
--- a/cpukit/score/cpu/avr/cpu.c
+++ b/cpukit/score/cpu/avr/cpu.c
@@ -71,36 +71,53 @@ void _CPU_Context_Initialize(
{
uint16_t stack;
uint16_t start;
- uint16_t *tmpsp;
+ uint8_t *tmp_sp;
+ uint8_t start_low;
+ uint8_t start_high;
/* calc stack high end */
stack = (uint16_t) (stack_base) + (uint16_t) (size);
-
/* calc stack pointer initial value */
- stack -= 2;
-
- the_context->stack_pointer = stack;
- tmpsp = (uint16_t *) stack;
+ the_context->stack_pointer = (stack - 18);
+ /* put the entry point on the stack */
start = (uint16_t) entry_point;
- *tmpsp = start;
-#if 0
- tmpsp[0] = start & 0xff;
- tmpsp[1] = (start >> 8) & 0xff;
-#endif
+ start_low = start & 0xff;
+ start_high = start >> 8;
+ tmp_sp = (uint8_t *) (stack+1);
+ tmp_sp[0] = start_high;
+ tmp_sp[1] = start_low;
- /* FIXME on level */
- if (new_level) the_context->status = 0;
- else the_context->status = 0;
+ if (new_level) the_context->status = 0x00; //interrupts are enabled
+ else the_context->status = 0x80; //interrupts are disabled
+ /*
+ * JOEL: Why if I comment out these three lines does ticker not run?
+ */
#if 1
- printk("");
+ printk( "tmp_sp=0x%04x ", ((uint16_t)tmp_sp) );
printk("the_context = 0x%x\n", the_context);
printk("entry = 0x%x\n", entry_point);
+#endif
+#if 0
printk("sp = 0x%x\n\n",stack);
+
+ { int i; uint8_t *p;
+ p = (uint8_t *)(stack - 18);
+ for( i=0 ; i<=20 ; i+=8 ) {
+ printk( "0x%04x ", ((uint16_t)&p[i]) );
+ printk(
+ "0x%02x 0x%02x 0x%02x 0x%02x ",
+ p[i + 0], p[i + 1], p[i + 2], p[i + 3]
+ );
+ printk(
+ "0x%02x 0x%02x 0x%02x 0x%02x\n",
+ p[i + 4], p[i + 5], p[i + 6], p[i + 7]
+ );
+ }
+ }
#endif
}
-
/*PAGE
*
* _CPU_ISR_Get_level
diff --git a/cpukit/score/cpu/avr/cpu_asm.S b/cpukit/score/cpu/avr/cpu_asm.S
index 9e29d7157e..39c0d3ddd3 100644
--- a/cpukit/score/cpu/avr/cpu_asm.S
+++ b/cpukit/score/cpu/avr/cpu_asm.S
@@ -208,78 +208,79 @@ SYM(_CPU_Context_restore_fp):
PUBLIC(_CPU_Context_switch)
SYM(_CPU_Context_switch):
- mov r26, r24
+ mov r26, r24 /* r26,r27 is X or current context */
mov r27, r25
- mov r24, r22
+ mov r24, r22 /* r24,r25 is heir context */
mov r25, r23
- st X+, r2
- st X+, r3
- st X+, r4
- st X+, r5
- st X+, r6
- st X+, r7
- st X+, r8
- st X+, r9
- st X+, r10
- st X+, r11
- st X+, r12
- st X+, r13
- st X+, r14
- st X+, r15
- st X+, r16
- st X+, r17
- st X+, r28
- st X+, r29
- st X+, r29
- lds r23,0x5f /*load sreg*/
- st X+, r23
- lds r23,0x5d /*spl*/
- st X+, r23
- lds r23,0x5e /*sph*/
-
+ /*save registers*/
+ push r2
+ push r3
+ push r4
+ push r5
+ push r6
+ push r7
+ push r8
+ push r9
+ push r10
+ push r11
+ push r12
+ push r13
+ push r14
+ push r15
+ push r16
+ push r17
+ push r28
+ push r29
+ /*load sreg*/
+ lds r23,0x5F /*load sreg*/
+ /*disable interrupts*/
+ cli
+ /*load stack pointer*/
+ lds r22,0x5D /*spl*/
+ lds r21,0x5E /*sph*/
+ /*save sp to context struct*/
+ /*save low then high byte --- verify this delete when verified*/
+ st X+, r22
+ st X+, r21
+ /*save sreg and sp to context struct*/
+ st X, r23
+
+
PUBLIC(_CPU_Context_restore)
SYM(_CPU_Context_restore):
mov r26,r24 /* R26/27 are X */
mov r27,r25
- ld r2, X+
- ld r3, X+
- ld r4, X+
- ld r5, X+
- ld r6, X+
- ld r7, X+
- ld r8, X+
- ld r9, X+
- ld r10, X+
- ld r11, X+
- ld r12, X+
- ld r13, X+
- ld r14, X+
- ld r15, X+
- ld r16, X+
- ld r17, X+
- ld r28, X+
- ld r29, X+
+ /*restore stack pointer*/
ld r25, X+
- sts 0x5f,r25 /*sreg*/
- ld r25, X+
- sts 0x5d,r25 /*spl*/
- ld r25, X+
- sts 0x5e ,r25 /*sph*/
+ ld r24, X+
+ sts 0x5E, r24 /*sph*/
+ sts 0x5D, r25 /*spl*/
+ /*restore registers from stack*/
+ pop r29
+ pop r28
+ pop r17
+ pop r16
+ pop r15
+ pop r14
+ pop r13
+ pop r12
+ pop r11
+ pop r10
+ pop r9
+ pop r8
+ pop r7
+ pop r6
+ pop r5
+ pop r4
+ pop r3
+ pop r2
+ /*restore status register*/
+ ld r23, X
+ sts 0x5f,r23 /*sreg*/
ret
- PUBLIC(_CPU_Push)
-SYM(_CPU_Push):
- lds r20, 0x5d /*spl*/
- lds r21, 0x5e /*sph*/
- sts 0x5d, r24 /*spl*/
- sts 0x5e, r25 /*sph*/
- push r22
- push r23
- sts 0x5d, r20 /*spl*/
- sts 0x5e, r21 /*sph*/
- ret
/*
* _CPU_Context_restore
diff --git a/cpukit/score/cpu/avr/rtems/score/cpu.h b/cpukit/score/cpu/avr/rtems/score/cpu.h
index 28d575ccf9..d23d3b3555 100644
--- a/cpukit/score/cpu/avr/rtems/score/cpu.h
+++ b/cpukit/score/cpu/avr/rtems/score/cpu.h
@@ -424,26 +424,8 @@ extern "C" {
*/
typedef struct {
- uint8_t reg2;
- uint8_t reg3;
- uint8_t reg4;
- uint8_t reg5;
- uint8_t reg6;
- uint8_t reg7;
- uint8_t reg8;
- uint8_t reg9;
- uint8_t reg10;
- uint8_t reg11;
- uint8_t reg12;
- uint8_t reg13;
- uint8_t reg14;
- uint8_t reg15;
- uint8_t reg16;
- uint8_t reg17;
- uint8_t reg28;
- uint8_t reg29;
- uint8_t status; //SREG
uint16_t stack_pointer;
+ uint8_t status; //SREG
} Context_Control;
#define _CPU_Context_Get_SP( _context ) \