-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.S
75 lines (62 loc) · 1.46 KB
/
custom.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/******************************************************************************
File: custom.S
Description: Harmony Custom C Code Booter
(C) Copyright 2016 - Chris Walton, Fred Quimby, Darrell Spice Jr
******************************************************************************/
/* Start in ARM mode */
.arm
/* Put code in boot section */
.section .boot,"ax",%progbits
/* Entry Point */
.global Custom
.func Custom
Custom:
/* Switch to THUMB mode */
add r0, pc, #1
bx r0
.thumb
/* Fetch value from CU header */
ldr r0, =0x10000024
ldr r2, [r0]
/* Skip if data already copied */
cmp r2, #0
bmi SkipCopy
add r2, #1
str r2,[r0]
cmp r2, #1
bne SkipCopy
/* Clear BSS section */
mov r0, #0
ldr r1, =_ebss
ldr r2, =_sbss
sub r1, r1, r2
ClearBssLoop:
sub r1, #4
bmi EndClearBss
str r0, [r2, +r1]
bne ClearBssLoop
EndClearBss:
/* Copy C data section to RAM */
ldr r0, =_etext
ldr r1, =_edata
ldr r2, =_sdata
sub r1, r1, r2
CopyLoop:
sub r1, #4
bmi SkipCopy
ldr r3, [r0, +r1]
str r3, [r2, +r1]
bne CopyLoop
SkipCopy:
/* Push return addess on stack */
push {lr}
/* Put ReturnToBUS address in LR */
ldr r0, =ReturnToBUS+1
mov lr, r0
/* Jump to main in C code */
ldr r0, =main
bx r0
ReturnToBUS:
/* Return to BUS (switch to ARM mode) */
pop {r0}
bx r0