rp2040

RP2040 Programming without SDK
Log | Files | Refs

commit 8814a540561ad066ba6155aeaccae86900bac2a8
parent fffa152122240112565655f51547ef6c5a6c0a57
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  8 Mar 2024 14:26:06 +0900

wip

Diffstat:
Mex3/main.c | 12+++++++++++-
Mex3/memmap.ld | 2++
Mex3/proc.s | 2+-
Mex3/start.s | 16++++++++++++++++
4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/ex3/main.c b/ex3/main.c @@ -3,7 +3,7 @@ int puts(char *); void printh(void *); void set_alarm(unsigned int); -extern void *proc0; +extern void proc0_start, proc0_size; // A proc represents a process in execution. typedef struct proc { @@ -31,6 +31,16 @@ main(void) { proc *p0 = (proc *) 0x20041000, *p1 = (proc *) 0x20041100; // sram5 + printh(&proc0_start); + puts("a"); + printh(&proc0_size); + puts("b"); + + memcpy((void *)0x20000000, (void *)&proc0_start, (long) &proc0_size); + proc0(); + + puts("c"); + p0->r[13] = (void *) 0x20000100; // sp p0->r[14] = (void *) 0xdeadbeef; // lr p0->r[15] = (void *) 0x20000000; // pc diff --git a/ex3/memmap.ld b/ex3/memmap.ld @@ -28,6 +28,8 @@ SECTIONS .proc0 0x20000000 : { *(.proc0) } > SRAM AT > FLASH + proc0_start = LOADADDR(.proc0); + proc0_size = SIZEOF(.proc0); .proc1 0x20000100 : { *(.proc1) } > SRAM AT > FLASH diff --git a/ex3/proc.s b/ex3/proc.s @@ -3,7 +3,7 @@ proc0: ldr r0, msg0 bl puts - b proc0 + bx lr msg0: .asciz "proc0" diff --git a/ex3/start.s b/ex3/start.s @@ -234,6 +234,22 @@ puts_end: mov r0, #0 // return value pop {r4, pc} + // void *memcpy(void *s1, void *s2, long n); + // Memcpy copies n bytes from memory area s2 to s1. It returns s1. + // TODO: Use ldr instead of ldrb. + .global memcpy +memcpy: + push {r4, lr} + mov r4, #0 +memcpy_loop: + ldrb r3, [r1, r4] + strb r3, [r0, r4] + add r4, #1 + cmp r4, r2 + blt memcpy_loop + pop {r4, pc} + + putbyte: ldr r3, uart0_base mov r1, #1