File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed
baremetal/arch/aarch64/no_bootloader Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -10419,7 +10419,13 @@ help architecture
10419
10419
10420
10420
shows ARM version up to `armv6`, so maybe `armv6` is not implemented?
10421
10421
10422
- === ARM exception level
10422
+ === ARM baremetal
10423
+
10424
+ In this section we will focus on learning ARM architecture concepts that can only learnt on baremetal setups.
10425
+
10426
+ Userland information can be found at: https://github.com/cirosantilli/arm-assembly-cheat
10427
+
10428
+ ==== ARM exception level
10423
10429
10424
10430
ARM exception levels are analogous to x86 <<ring0,rings>>.
10425
10431
@@ -10491,6 +10497,25 @@ output:
10491
10497
3
10492
10498
....
10493
10499
10500
+ ==== ARM multicore
10501
+
10502
+ TODO get working: CPU1 not waking up:
10503
+
10504
+ ....
10505
+ ./run --arch aarch64 --baremetal arch/aarch64/no_bootloader/multicore
10506
+ ....
10507
+
10508
+ Source: link:baremetal/arch/aarch64/no_bootloader/multicore.S[]
10509
+
10510
+ CPU 0 of this program enters a spinlock loop: it repeatedly checks if a given memory address is `1`.
10511
+
10512
+ So, we need CPU 1 to come to the rescue to that memory address be `1`, otherwise CPU 0 will be stuck there forever.
10513
+
10514
+ Bibliography:
10515
+
10516
+ * https://stackoverflow.com/questions/20055754/arm-start-wakeup-bringup-the-other-cpu-cores-aps-and-pass-execution-start-addre
10517
+ * https://stackoverflow.com/questions/980999/what-does-multicore-assembly-language-look-like/33651438#33651438
10518
+
10494
10519
=== How we got some baremetal stuff to work
10495
10520
10496
10521
It is nice when thing just work.
Original file line number Diff line number Diff line change
1
+ / * https://github.com/cirosantilli/linux - kernel - module - che at #arm - multicore * /
2
+
3
+ . global mystart
4
+ mystart:
5
+ / * Reset spinlock. * /
6
+ mov x0 , # 0
7
+ ldr x1 , =spinlock
8
+ str x0 , [ x1 ]
9
+
10
+ / * Read cpu id into x1. * /
11
+ mrs x1 , mpidr_el1
12
+ and x1 , x1 , # 3
13
+ cbz x1 , 1f
14
+ / * Only CPU 1 reaches this point and sets the spinlock. * /
15
+ mov x0 , # 1
16
+ ldr x1 , =spinlock
17
+ str x0 , [ x1 ]
18
+ b .
19
+ 1 :
20
+ / * Only CPU 0 reaches this point. * /
21
+ ldr x0 , spinlock
22
+ cbz x0 , 1b
23
+
24
+ / * Semihost exit. * /
25
+ mov x1 , # 0x26
26
+ movk x1 , # 2 , lsl # 16
27
+ str x1 , [ sp , # 0 ]
28
+ mov x0 , # 0
29
+ str x0 , [ sp , # 8 ]
30
+ mov x1 , sp
31
+ mov w0 , # 0x18
32
+ hlt 0xf000
33
+
34
+ spinlock:
35
+ .skip 8
Original file line number Diff line number Diff line change
1
+ / * https://github.com/cirosantilli/linux - kernel - module - che at #semihosting * /
2
+
1
3
. global mystart
2
4
mystart:
3
5
mov x1 , # 0x26
You can’t perform that action at this time.
0 commit comments