summaryrefslogtreecommitdiffstats
path: root/utils/rk27utils/rk27load/stage2/crt0.S
blob: d931123f9507277ce626f36983d91c27e757a08b (plain)
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
/*
 * startup code
 *
 */

#define PSR_MODE        0x0000001f
#define PSR_USR_MODE    0x00000010
#define PSR_IRQ_MODE    0x00000012
#define PSR_SVC_MODE    0x00000013

#define PSR_INT_MASK    0x000000c0
#define PSR_FIQ_DIS     0x00000040
#define PSR_IRQ_DIS     0x00000080

.section .init.text,"ax",%progbits
.global start
.extern _interrupt_disable

/* -----------------------------------------------------
 *  startup code (setup stacks, branch to main)
 * -----------------------------------------------------
 */
start:
    /* setup IRQ stack */
    mov    r0,#(PSR_IRQ_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS)
    msr    cpsr,r0
    ldr    sp,=irqstackend

    /* setup SVC stack */
    mov    r0,#(PSR_SVC_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS)
    msr    cpsr,r0
    ldr    sp,=stackend

    /* disbale interrupts */
    mrs    r0,cpsr
    orr    r0,r0,#0xc0
    msr    cpsr_c, r0

    /* remap */
    mov    r0,#0x18000000
    add    r0,r0,#0x1C000
    ldr    r1,=0xdeadbeef
    str    r1,[r0,#4]

    /* relocate itself */
    ldr    r0,=_relocstart
    ldr    r1,=_relocend
    ldr    r2,=0x0
1:
    cmp    r1,r0
    ldrhi  r3,[r0],#4
    strhi  r3,[r2],#4
    bhi    1b
    
    /* continue running in SVC (supervisor mode) */
    ldr    pc,=0x0