-
Notifications
You must be signed in to change notification settings - Fork 219
/
intermezzo.S
56 lines (42 loc) · 1.04 KB
/
intermezzo.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Payload launcher stub.
//
.globl _start
.section ".text"
_start:
// First, we'll need to move ourselves _out_ of the target area.
// We'll copy down into the start of the IRAM.
ldr r0, =post_relocation
ldr r1, =START_OF_IRAM
ldr r2, =intermezzo_end
sub r2, r2, r0
bl copy
// Jump to the start of RAM, which should now contain the post-relocation code.
ldr r0, =START_OF_IRAM
bx r0
.align 4
post_relocation:
// Next, we'll copy our payload down to the appropriate relocaiton address.
ldr r0, =LOAD_BLOCK_START
ldr r1, =RELOCATION_TARGET
ldr r2, =LOAD_BLOCK_LENGTH
bl copy
// Finally, jump into the relocated target.
ldr r0, =RELOCATION_TARGET
bx r0
//
// Simple block copy.
// r0 = source address
// r1 = destination address
// r2 = length in bytes
// Destroys r3.
//
copy:
// Copy the word...
ldr r3, [r0], #4
str r3, [r1], #4
// And continue while we have words left to copy.
subs r2, r2, #4
bne copy
// Once we're done, return.
bx lr