commit aeaf4505ba3fc32b2d2bad04e468b6e43fd04eba
parent a41034b590794a16c2852ec2cd7bb04c51ec5869
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 28 Mar 2024 07:48:04 +0900
save and restore context from and to the psp
Diffstat:
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/ex3/main.c b/ex3/main.c
@@ -102,6 +102,12 @@ switch_context(unsigned int r[17]) {
ptab.tail = p;
ptab.tail->next = NULL;
+ puts("next context:");
+ for (int i = 0; i < 17; i++) {
+ printh(ptab.head->r[i]);
+ puts("");
+ }
+
return ptab.head->r;
}
diff --git a/ex3/proc.s b/ex3/proc.s
@@ -4,6 +4,7 @@
proc0:
ldr r0, =msg0
bl puts
+ ldr r0, =0xdeadbeef
wfi
b proc0
@@ -44,21 +45,21 @@ isr_alarm:
sub sp, sp, #(17*4) // unsigned int r[17];
mov r1, sp
- mov r2, #(17*4 + 4) // +4 for pushed lr
+ mrs r2, psp
mov r3, #0
- ldr r0, [r1, r2] // r0
+ ldr r0, [r2, #0] // r0
str r0, [r1, r3]
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2] // r1
+ ldr r0, [r2, #0] // r1
str r0, [r1, r3]
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2] // r2
+ ldr r0, [r2, #0] // r2
str r0, [r1, r3]
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2] // r3
+ ldr r0, [r2, #0] // r3
str r0, [r1, r3]
add r3, r3, #4
@@ -85,7 +86,7 @@ isr_alarm:
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2]
+ ldr r0, [r2, #0]
str r0, [r1, r3] // r12
add r3, r3, #4
@@ -94,23 +95,23 @@ isr_alarm:
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2]
+ ldr r0, [r2, #0]
str r0, [r1, r3] // lr
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2]
+ ldr r0, [r2, #0]
str r0, [r1, r3] // ReturnAddress(ExceptionType): The next pc at interrupt.
add r2, r2, #4
add r3, r3, #4
- ldr r0, [r1, r2] // xpsr
+ ldr r0, [r2, #0] // xpsr
str r0, [r1, r3]
mov r0, r1
bl switch_context // r0 is the r[17] of the next task.
add sp, sp, #(17*4)
- add r2, sp, #4 // for the popped lr
+ mrs r2, psp
ldr r1, [r0, #(0 * 4)] // r0
str r1, [r2, #0]
ldr r1, [r0, #(1 * 4)] // r1