Replace ldr pseudo-instruction with adrp/add

pull/110/head
Andre Richter 3 years ago
parent f81eb7428d
commit b4ed84dd77
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -84,20 +84,32 @@ diff -uNr 01_wait_forever/src/_arch/aarch64/cpu/boot.rs 02_runtime_init/src/_arc
diff -uNr 01_wait_forever/src/_arch/aarch64/cpu/boot.s 02_runtime_init/src/_arch/aarch64/cpu/boot.s
--- 01_wait_forever/src/_arch/aarch64/cpu/boot.s
+++ 02_runtime_init/src/_arch/aarch64/cpu/boot.s
@@ -3,6 +3,12 @@
@@ -3,6 +3,24 @@
// Copyright (c) 2021 Andre Richter <andre.o.richter@gmail.com>
//--------------------------------------------------------------------------------------------------
+// Definitions
+//--------------------------------------------------------------------------------------------------
+
+// Load the address of a symbol into a register, PC-relative.
+//
+// The symbol must lie within +/- 4 GiB of the Program Counter.
+//
+// # Resources
+//
+// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
+.macro ADR_REL register, symbol
+ adrp \register, \symbol
+ add \register, \register, #:lo12:\symbol
+.endm
+
+.equ _core_id_mask, 0b11
+
+//--------------------------------------------------------------------------------------------------
// Public Code
//--------------------------------------------------------------------------------------------------
.section .text._start
@@ -11,6 +17,22 @@
@@ -11,6 +29,22 @@
// fn _start()
//------------------------------------------------------------------------------
_start:
@ -111,7 +123,7 @@ diff -uNr 01_wait_forever/src/_arch/aarch64/cpu/boot.s 02_runtime_init/src/_arch
+ // If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
+
+ // Set the stack pointer.
+ ldr x0, =__boot_core_stack_end_exclusive
+ ADR_REL x0, __boot_core_stack_end_exclusive
+ mov sp, x0
+
+ // Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -179,20 +179,38 @@ diff -uNr 05_drivers_gpio_uart/Makefile 06_uart_chainloader/Makefile
diff -uNr 05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s 06_uart_chainloader/src/_arch/aarch64/cpu/boot.s
--- 05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s
+++ 06_uart_chainloader/src/_arch/aarch64/cpu/boot.s
@@ -22,20 +22,31 @@
@@ -18,6 +18,17 @@
add \register, \register, #:lo12:\symbol
.endm
+// Load the address of a symbol into a register, absolute.
+//
+// # Resources
+//
+// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
+.macro ADR_ABS register, symbol
+ movz \register, #:abs_g2:\symbol
+ movk \register, #:abs_g1_nc:\symbol
+ movk \register, #:abs_g0_nc:\symbol
+.endm
+
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@@ -34,20 +45,31 @@
and x1, x1, _core_id_mask
ldr x2, BOOT_CORE_ID // provided by bsp/__board_name__/cpu.rs
cmp x1, x2
- b.ne 1f
+ b.ne 2f
+
+ // If execution reaches here, it is the boot core.
- // If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
+ // If execution reaches here, it is the boot core.
+
+ // Next, relocate the binary.
+ adr x0, __binary_nonzero_start // The address the binary got loaded to.
+ ldr x1, =__binary_nonzero_start // The address the binary was linked to.
+ ldr x2, =__binary_nonzero_end_exclusive
+ ADR_REL x0, __binary_nonzero_start // The address the binary got loaded to.
+ ADR_ABS x1, __binary_nonzero_start // The address the binary was linked to.
+ ADR_ABS x2, __binary_nonzero_end_exclusive
+
+1: ldr x3, [x0], #8
+ str x3, [x1], #8
@ -200,13 +218,14 @@ diff -uNr 05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s 06_uart_chainloader/
+ b.lo 1b
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
- ADR_REL x0, __boot_core_stack_end_exclusive
+ ADR_ABS x0, __boot_core_stack_end_exclusive
mov sp, x0
- // Jump to Rust code.
- b _start_rust
+ // Jump to the relocated Rust code.
+ ldr x1, =_start_rust
+ ADR_ABS x1, _start_rust
+ br x1
// Infinitely wait for events (aka "park the core").

@ -6,6 +6,29 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
// Load the address of a symbol into a register, absolute.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_ABS register, symbol
movz \register, #:abs_g2:\symbol
movk \register, #:abs_g1_nc:\symbol
movk \register, #:abs_g0_nc:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,9 +50,9 @@ _start:
// If execution reaches here, it is the boot core.
// Next, relocate the binary.
adr x0, __binary_nonzero_start // The address the binary got loaded to.
ldr x1, =__binary_nonzero_start // The address the binary was linked to.
ldr x2, =__binary_nonzero_end_exclusive
ADR_REL x0, __binary_nonzero_start // The address the binary got loaded to.
ADR_ABS x1, __binary_nonzero_start // The address the binary was linked to.
ADR_ABS x2, __binary_nonzero_end_exclusive
1: ldr x3, [x0], #8
str x3, [x1], #8
@ -37,11 +60,11 @@ _start:
b.lo 1b
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_ABS x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to the relocated Rust code.
ldr x1, =_start_rust
ADR_ABS x1, _start_rust
br x1
// Infinitely wait for events (aka "park the core").

@ -96,19 +96,37 @@ diff -uNr 06_uart_chainloader/Makefile 07_timestamps/Makefile
diff -uNr 06_uart_chainloader/src/_arch/aarch64/cpu/boot.s 07_timestamps/src/_arch/aarch64/cpu/boot.s
--- 06_uart_chainloader/src/_arch/aarch64/cpu/boot.s
+++ 07_timestamps/src/_arch/aarch64/cpu/boot.s
@@ -22,31 +22,20 @@
@@ -18,17 +18,6 @@
add \register, \register, #:lo12:\symbol
.endm
-// Load the address of a symbol into a register, absolute.
-//
-// # Resources
-//
-// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
-.macro ADR_ABS register, symbol
- movz \register, #:abs_g2:\symbol
- movk \register, #:abs_g1_nc:\symbol
- movk \register, #:abs_g0_nc:\symbol
-.endm
-
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@@ -45,31 +34,20 @@
and x1, x1, _core_id_mask
ldr x2, BOOT_CORE_ID // provided by bsp/__board_name__/cpu.rs
cmp x1, x2
- b.ne 2f
-
- // If execution reaches here, it is the boot core.
+ b.ne 1f
- // If execution reaches here, it is the boot core.
-
- // Next, relocate the binary.
- adr x0, __binary_nonzero_start // The address the binary got loaded to.
- ldr x1, =__binary_nonzero_start // The address the binary was linked to.
- ldr x2, =__binary_nonzero_end_exclusive
- ADR_REL x0, __binary_nonzero_start // The address the binary got loaded to.
- ADR_ABS x1, __binary_nonzero_start // The address the binary was linked to.
- ADR_ABS x2, __binary_nonzero_end_exclusive
-
-1: ldr x3, [x0], #8
- str x3, [x1], #8
@ -117,11 +135,12 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/cpu/boot.s 07_timestamps/src/_ar
+ // If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
- ADR_ABS x0, __boot_core_stack_end_exclusive
+ ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
- // Jump to the relocated Rust code.
- ldr x1, =_start_rust
- ADR_ABS x1, _start_rust
- br x1
+ // Jump to Rust code.
+ b _start_rust

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

@ -273,15 +273,15 @@ diff -uNr 08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.rs 09_privilege_level/src/
diff -uNr 08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s 09_privilege_level/src/_arch/aarch64/cpu/boot.s
--- 08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s
+++ 09_privilege_level/src/_arch/aarch64/cpu/boot.s
@@ -6,6 +6,7 @@
// Definitions
//--------------------------------------------------------------------------------------------------
@@ -18,6 +18,7 @@
add \register, \register, #:lo12:\symbol
.endm
+.equ _EL2, 0x8
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@@ -17,6 +18,11 @@
@@ -29,6 +30,11 @@
// fn _start()
//------------------------------------------------------------------------------
_start:
@ -293,13 +293,13 @@ diff -uNr 08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s 09_privilege_level/src/_
// Only proceed on the boot core. Park it otherwise.
mrs x1, MPIDR_EL1
and x1, x1, _core_id_mask
@@ -26,11 +32,11 @@
@@ -38,11 +44,11 @@
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
- // Set the stack pointer.
+ // Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
- // Jump to Rust code.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _EL2, 0x8
.equ _core_id_mask, 0b11
@ -33,7 +45,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer. This ensures that any code in EL2 that needs the stack will work.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code. x0 holds the function argument provided to _start_rust().

Binary file not shown.

Binary file not shown.

@ -6,6 +6,18 @@
// Definitions
//--------------------------------------------------------------------------------------------------
// Load the address of a symbol into a register, PC-relative.
//
// The symbol must lie within +/- 4 GiB of the Program Counter.
//
// # Resources
//
// - https://sourceware.org/binutils/docs-2.36/as/AArch64_002dRelocations.html
.macro ADR_REL register, symbol
adrp \register, \symbol
add \register, \register, #:lo12:\symbol
.endm
.equ _core_id_mask, 0b11
//--------------------------------------------------------------------------------------------------
@ -27,7 +39,7 @@ _start:
// If execution reaches here, it is the boot core. Now, prepare the jump to Rust code.
// Set the stack pointer.
ldr x0, =__boot_core_stack_end_exclusive
ADR_REL x0, __boot_core_stack_end_exclusive
mov sp, x0
// Jump to Rust code.

Loading…
Cancel
Save