This source file includes following definitions.
- copy_and_restart
1
2
3
4
5
6
7
8 #define LED_AF (void*)0xC02200B4
9 #define DELAY 5000000
10
11 void __attribute__((noreturn)) copy_and_restart(void *dst_void, const void *src_void, long length) {
12
13 {
14
15 volatile long *p = (void*)LED_AF;
16
17 int counter;
18
19
20 counter = DELAY; *p = 0x46; while (counter--) { asm("nop\n nop\n"); };
21 counter = DELAY; *p = 0x44; while (counter--) { asm("nop\n nop\n"); };
22
23 char *dst = dst_void;
24 const char *src = src_void;
25
26 if (src < dst && dst < src + length)
27 {
28
29 src += length;
30 dst += length;
31 while (length--)
32 {
33 *--dst = *--src;
34 }
35 }
36 else
37 {
38 while (length--)
39 {
40 *dst++ = *src++;
41 }
42 }
43 }
44
45 asm volatile (
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 "MRS R0, CPSR\n"
61 "BIC R0, R0, #0x3F\n"
62 "ORR R0, R0, #0xD3\n"
63 "MSR CPSR, R0\n"
64 "LDR R1, =0xC0200000\n"
65 "MVN R0, #0\n"
66 "STR R0, [R1,#0x10C]\n"
67 "STR R0, [R1,#0xC]\n"
68 "STR R0, [R1,#0x1C]\n"
69 "STR R0, [R1,#0x2C]\n"
70 "STR R0, [R1,#0x3C]\n"
71 "STR R0, [R1,#0x4C]\n"
72 "STR R0, [R1,#0x5C]\n"
73 "STR R0, [R1,#0x6C]\n"
74 "STR R0, [R1,#0x7C]\n"
75 "STR R0, [R1,#0x8C]\n"
76 "STR R0, [R1,#0x9C]\n"
77 "STR R0, [R1,#0xAC]\n"
78 "STR R0, [R1,#0xBC]\n"
79 "STR R0, [R1,#0xCC]\n"
80 "STR R0, [R1,#0xDC]\n"
81 "STR R0, [R1,#0xEC]\n"
82 "CMP R4, #7\n"
83 "STR R0, [R1,#0xFC]\n"
84 "LDMEQFD SP!, {R4,PC}\n"
85 "MOV R0, #0x78\n"
86 "MCR p15, 0, R0,c1,c0\n"
87 "MOV R0, #0\n"
88 "MCR p15, 0, R0,c7,c10, 4\n"
89 "MCR p15, 0, R0,c7,c5\n"
90 "MCR p15, 0, R0,c7,c6\n"
91 "MOV R0, #0x80000006\n"
92 "MCR p15, 0, R0,c9,c1\n"
93 "MCR p15, 0, R0,c9,c1, 1\n"
94 "MRC p15, 0, R0,c1,c0\n"
95 "ORR R0, R0, #0x50000\n"
96 "MCR p15, 0, R0,c1,c0\n"
97 "LDR R0, =0x12345678\n"
98 "MOV R1, #0x80000000\n"
99 "STR R0, [R1,#0xFFC]\n"
100
101 "MOV R0, %0\n"
102 "LDMFD SP!, {R4,LR}\n"
103 "BX R0\n"
104 : : "r"(dst_void) : "memory","r0","r1","r2","r3","r4");
105
106 while(1);
107 }