1
+
1
2
pub const PERIPHERAL_BASE = if (build_options .subarch >= 7 ) 0x3F000000 else 0x20000000 ;
2
3
3
4
var already_panicking : bool = false ;
@@ -28,8 +29,12 @@ pub fn io(comptime StructType: type, offset: u32) *volatile StructType {
28
29
29
30
pub fn hang (comptime format : []const u8 , args : ... ) noreturn {
30
31
log (format , args );
32
+ var time = milliseconds .read ();
33
+ while (! serial .isOutputQueueEmpty ()) {
34
+ serial .loadOutputFifo ();
35
+ }
31
36
while (true ) {
32
- if (build_options .subarch >= 7 ) {
37
+ if (build_options .subarch >= 7 ) {
33
38
v7 .wfe ();
34
39
}
35
40
}
@@ -47,25 +52,25 @@ pub const v7 = struct {
47
52
}
48
53
};
49
54
50
- pub fn sp () u32 {
55
+ pub fn sp () usize {
51
56
var word = asm ("mov %[word], sp"
52
57
: [word ] "=r" (- > usize ));
53
58
return word ;
54
59
}
55
60
56
- pub fn cpsr () u32 {
61
+ pub fn cpsr () usize {
57
62
var word = asm ("mrs %[word], cpsr"
58
63
: [word ] "=r" (- > usize ));
59
64
return word ;
60
65
}
61
66
62
- pub fn spsr () u32 {
67
+ pub fn spsr () usize {
63
68
var word = asm ("mrs %[word], spsr"
64
69
: [word ] "=r" (- > usize ));
65
70
return word ;
66
71
}
67
72
68
- pub fn sctlr () u32 {
73
+ pub fn sctlr () usize {
69
74
var word = asm ("mrc p15, 0, %[word], c1, c0, 0"
70
75
: [word ] "=r" (- > usize ));
71
76
return word ;
@@ -89,38 +94,72 @@ pub fn dsbSt() void {
89
94
}
90
95
91
96
pub fn setVectorBaseAddressRegister (address : u32 ) void {
92
- asm volatile ("mcr p15, 0, %[address], cr12, cr0, 0"
93
- :
94
- : [address ] "{r0}" (address )
95
- );
97
+ if (build_options .subarch >= 8 ) {
98
+ asm volatile ("mcr p15, 0, %[address], cr12, cr0, 0"
99
+ :
100
+ : [address ] "{x0}" (address )
101
+ );
102
+ } else {
103
+ asm volatile ("mcr p15, 0, %[address], cr12, cr0, 0"
104
+ :
105
+ : [address ] "{r0}" (address )
106
+ );
107
+ }
96
108
}
97
109
98
110
pub fn setCntfrq (word : u32 ) void {
99
- asm volatile ("mcr p15, 0, %[word], c14, c0, 0"
100
- :
101
- : [word ] "{r0}" (word )
102
- );
111
+ if (build_options .subarch >= 8 ) {
112
+ asm volatile ("msr cntfrq_el0, %[word]"
113
+ :
114
+ : [word ] "{x0}" (word )
115
+ );
116
+ } else {
117
+ asm volatile ("mcr p15, 0, %[word], c14, c0, 0"
118
+ :
119
+ : [word ] "{r0}" (word )
120
+ );
121
+ }
103
122
}
104
123
105
124
pub fn cntfrq () u32 {
106
- var word = asm ("mrc p15, 0, %[word], c14, c0, 0"
107
- : [word ] "=r" (- > usize ));
108
- return word ;
125
+ var word : usize = undefined ;
126
+ if (build_options .subarch >= 8 ) {
127
+ word = asm volatile ("mrs %[word], cntfrq_el0"
128
+ : [word ] "=r" (- > usize )
129
+ );
130
+ } else {
131
+ word = asm ("mrc p15, 0, %[word], c14, c0, 0"
132
+ : [word ] "=r" (- > usize )
133
+ );
134
+ }
135
+ return @truncate (u32 , word );
109
136
}
110
137
111
138
pub fn cntpct32 () u32 {
112
- return asm ("mrrc p15, 0, %[cntpct_low], r1, c14"
113
- : [cntpct_low ] "=r" (- > usize )
114
- :
115
- : "r1"
116
- );
139
+ var word : usize = undefined ;
140
+ if (build_options .subarch >= 8 ) {
141
+ word = asm volatile ("mrs %[word], cntpct_el0"
142
+ : [word ] "=r" (- > usize )
143
+ );
144
+ } else {
145
+ word = asm ("mrrc p15, 0, %[cntpct_low], r1, c14"
146
+ : [cntpct_low ] "=r" (- > usize )
147
+ :
148
+ : "r1"
149
+ );
150
+ }
151
+ return @truncate (u32 , word );
117
152
}
118
153
119
154
// Loop count times in a way that the compiler won't optimize away.
120
155
pub fn delay (count : usize ) void {
121
156
var i : usize = 0 ;
122
157
while (i < count ) : (i += 1 ) {
123
- asm volatile ("mov r0, r0" );
158
+ if (build_options .subarch >= 8 ) {
159
+ asm volatile ("mov x0, x0" );
160
+ } else {
161
+ asm volatile ("mov r0, r0" );
162
+ }
124
163
}
125
164
}
126
165
@@ -166,14 +205,15 @@ pub fn setBssToZero() void {
166
205
@memset ((* volatile [1 ]u8 )(& __bss_start ), 0 , @ptrToInt (& __bss_end ) - @ptrToInt (& __bss_start ));
167
206
}
168
207
208
+
169
209
comptime {
170
210
asm (
171
211
\\.section .text.boot // .text.boot to keep this in the first portion of the binary
172
212
\\.globl _start
173
213
\\_start:
174
214
);
175
215
176
- if (build_options .subarch > = 7 ) {
216
+ if (build_options .subarch = = 7 ) {
177
217
asm (
178
218
\\ mrc p15, 0, r0, c0, c0, 5
179
219
\\ and r0,#3
@@ -188,24 +228,79 @@ comptime {
188
228
);
189
229
}
190
230
191
- asm (
192
- \\ cps #0x1f // enter system mode
193
- \\ mov sp,#0x08000000
194
- \\ bl kernelMain
195
- \\
196
- \\.section .text.exception_vector_table
197
- \\.balign 0x80
198
- \\exception_vector_table:
199
- \\ b exceptionEntry0x00
200
- \\ b exceptionEntry0x01
201
- \\ b exceptionEntry0x02
202
- \\ b exceptionEntry0x03
203
- \\ b exceptionEntry0x04
204
- \\ b exceptionEntry0x05
205
- \\ b exceptionEntry0x06
206
- \\ b exceptionEntry0x07
207
- );
231
+ if (build_options .subarch <= 7 ) {
232
+ asm (
233
+ \\ cps #0x1f // enter system mode
234
+ \\ mov sp,#0x08000000
235
+ \\ bl kernelMain
236
+ \\
237
+ \\.section .text.exception_vector_table
238
+ \\.balign 0x80
239
+ \\exception_vector_table:
240
+ \\ b exceptionEntry0x00
241
+ \\ b exceptionEntry0x01
242
+ \\ b exceptionEntry0x02
243
+ \\ b exceptionEntry0x03
244
+ \\ b exceptionEntry0x04
245
+ \\ b exceptionEntry0x05
246
+ \\ b exceptionEntry0x06
247
+ \\ b exceptionEntry0x07
248
+ );
249
+ } else {
250
+ asm (
251
+ \\ mrs x0,mpidr_el1
252
+ \\ mov x1,#0xC1000000
253
+ \\ bic x0,x0,x1
254
+ \\ cbz x0,master
255
+ \\hang:
256
+ \\ wfe
257
+ \\ b hang
258
+ \\master:
259
+ \\ mov sp,#0x08000000
260
+ \\ mov x0,#0x1000 //exception_vector_table
261
+ \\ msr vbar_el3,x0
262
+ \\ msr vbar_el2,x0
263
+ \\ msr vbar_el1,x0
264
+ \\ bl kernelMain
265
+ \\.balign 0x800
266
+ \\.section .text.exception_vector_table
267
+ \\exception_vector_table:
268
+ \\.balign 0x80
269
+ \\ b exceptionEntry0x00
270
+ \\.balign 0x80
271
+ \\ b exceptionEntry0x01
272
+ \\.balign 0x80
273
+ \\ b exceptionEntry0x02
274
+ \\.balign 0x80
275
+ \\ b exceptionEntry0x03
276
+ \\.balign 0x80
277
+ \\ b exceptionEntry0x04
278
+ \\.balign 0x80
279
+ \\ b exceptionEntry0x05
280
+ \\.balign 0x80
281
+ \\ b exceptionEntry0x06
282
+ \\.balign 0x80
283
+ \\ b exceptionEntry0x07
284
+ \\.balign 0x80
285
+ \\ b exceptionEntry0x08
286
+ \\.balign 0x80
287
+ \\ b exceptionEntry0x09
288
+ \\.balign 0x80
289
+ \\ b exceptionEntry0x0A
290
+ \\.balign 0x80
291
+ \\ b exceptionEntry0x0B
292
+ \\.balign 0x80
293
+ \\ b exceptionEntry0x0C
294
+ \\.balign 0x80
295
+ \\ b exceptionEntry0x0D
296
+ \\.balign 0x80
297
+ \\ b exceptionEntry0x0E
298
+ \\.balign 0x80
299
+ \\ b exceptionEntry0x0F
300
+ );
301
+ }
208
302
}
209
303
210
304
const build_options = @import ("build_options" );
211
- const log = @import ("serial.zig" ).log ;
305
+ const log = serial .log ;
306
+ const serial = @import ("serial.zig" );
0 commit comments