commit aa67863a9cea46760e13bed997af3455b63be28f
parent 59737698a76411d4fd1d407846b70c03309d4125
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 13 Mar 2024 10:06:29 +0900
fix alignment error.
can't get right address of proc0
Diffstat:
4 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/ex3/main.c b/ex3/main.c
@@ -6,6 +6,7 @@ void proc0(void);
void halt(void);
void *get_sp(void);
void wfi(void);
+void *memcpy(void *s1, void *s2, long n);
extern void proc0_start, proc0_size;
extern void proc1_start, proc1_size;
@@ -36,21 +37,29 @@ int
main(void) {
init();
proc p0, p1;
+ puts("main");
+ puts("main2");
- memcpy((void *)0x20000000, (void *)&proc0_start, (long) &proc0_size);
- memcpy((void *)0x20000100, (void *)&proc1_start, (long) &proc1_size);
+ printh(&proc0_start);
+ printh(&proc0_size);
+ printh((void*)0x10002000);
+ //memcpy((void *)0x20000000, (void *)&proc0_start, (long) &proc0_size);
+ puts("main2.5");
+ //memcpy((void *)0x20000100, (void *)&proc1_start, (long) &proc1_size);
+ puts("main3");
p0.r[13] = (void *) 0x20000100; // sp
p0.r[14] = (void *) 0xdeadbeef; // lr
p0.r[15] = (void *) 0x20000000; // pc
+ puts("main4");
p1.r[13] = (void *) 0x20000200; // sp
p1.r[14] = (void *) 0xdeadbeef; // lr
p1.r[15] = (void *) 0x20000100; // pc
+ puts("main5");
for (;;) {
wfi();
- setreg();
}
return 0;
@@ -62,21 +71,10 @@ save_context(proc *p)
void
restore_context(proc *p)
-{
-
-}
+{}
void
scheduler(void) {
- int *sp1, *sp0;
- sp1 = (int *)get_sp();
- sp0 = sp1 + 16;
- for (; sp1 <= sp0; sp1++) {
- printh(sp1);
- printh(*sp1);
- puts("");
- }
- puts("");
puts("scheduler called");
}
diff --git a/ex3/memmap.ld b/ex3/memmap.ld
@@ -16,13 +16,12 @@ SECTIONS
kernel_start = .;
*(.text)
} > SRAM4 AT > FLASH
- .data : {
+ .data : ALIGN(4) {
*(.data)
} > SRAM4 AT > FLASH
- .rodata : {
+ .rodata : ALIGN(4) {
*(.rodata)
kernel_end = .;
- . = ALIGN(4);
} > SRAM4 AT > FLASH
prog_start = LOADADDR(.text);
prog_size = kernel_end - kernel_start;
diff --git a/ex3/proc.s b/ex3/proc.s
@@ -1,4 +1,3 @@
- .align 1
.section .proc0, "a"
.global proc0
proc0:
@@ -6,24 +5,21 @@ proc0:
bl puts
b proc0
- .align 4
.global msg0
msg0:
.asciz "proc0"
- .align 1
.section .proc1, "a"
.global proc1
proc1:
ldr r0, msg1
bl puts
b proc1
- .align 2
+
.global msg1
msg1:
.asciz "proc1"
- .align 1
.section .text
// void *get_sp(void);
// Get_sp returns the current stack pointer.
@@ -32,7 +28,6 @@ get_sp:
mov r0, sp
bx lr
- .align 1
// Set_reg sets registers for debugging.
// Modified registers are:
// ReturnAddress(), LR, R12, R3, R2, R1 and R0.
@@ -47,5 +42,5 @@ setreg:
mov r1, #1
mov r2, #2
mov r3, #3
- bl printh // BUG: some alignment fault?
+ nop
pop {pc}
diff --git a/ex3/start.s b/ex3/start.s
@@ -336,6 +336,8 @@ bled:
bl delay
pop {r0, r1, r2, r3, r4, r5, pc}
+ // void delay(void);
+ .global delay
delay:
push {r0}
mov r0, #1