Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bootloader/start.S
1471 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
.section .text._start
18
.arm
19
20
.extern _reloc_ipl
21
.type _reloc_ipl, %function
22
23
.extern memset
24
.type memset, %function
25
26
.extern _irq_setup
27
.type _irq_setup, %function
28
29
.globl _start
30
.type _start, %function
31
_start:
32
ADR R0, _start
33
LDR R1, =__ipl_start
34
CMP R0, R1
35
BEQ _real_start
36
37
/* If we are not in the right location already, copy a relocator to upper IRAM. */
38
ADR R2, _reloc_ipl
39
LDR R3, =0x4003FF00
40
MOV R4, #(_real_start - _reloc_ipl)
41
_copy_loop:
42
LDMIA R2!, {R5}
43
STMIA R3!, {R5}
44
SUBS R4, #4
45
BNE _copy_loop
46
47
/* Use the relocator to copy ourselves into the right place. */
48
LDR R2, =__ipl_end
49
SUB R2, R2, R1
50
LDR R3, =_real_start
51
LDR R4, =0x4003FF00
52
BX R4
53
54
_reloc_ipl:
55
LDMIA R0!, {R4-R7}
56
STMIA R1!, {R4-R7}
57
SUBS R2, #0x10
58
BNE _reloc_ipl
59
/* Jump to the relocated entry. */
60
BX R3
61
62
_real_start:
63
/* Initially, we place our stack under relocator but will move it to under the payload. */
64
/* This depends on application scope. */
65
LDR SP, =0x4003FF00
66
LDR R0, =__bss_start
67
EOR R1, R1, R1
68
LDR R2, =__bss_end
69
SUB R2, R2, R0
70
BL memset
71
BL _irq_setup
72
B .
73
74
.globl pivot_stack
75
.type pivot_stack, %function
76
pivot_stack:
77
MOV SP, R0
78
BX LR
79
80