From b4ed84dd77196a7eb9f599dc6cd55d87888ea4e4 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Mon, 22 Mar 2021 22:54:08 +0100 Subject: [PATCH] Replace ldr pseudo-instruction with adrp/add --- 02_runtime_init/README.md | 18 +++++++-- 02_runtime_init/src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- 04_safe_globals/src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- 06_uart_chainloader/README.md | 35 ++++++++++++++---- 06_uart_chainloader/demo_payload_rpi3.img | Bin 6840 -> 6840 bytes 06_uart_chainloader/demo_payload_rpi4.img | Bin 6680 -> 6680 bytes .../src/_arch/aarch64/cpu/boot.s | 33 ++++++++++++++--- 07_timestamps/README.md | 35 ++++++++++++++---- 07_timestamps/src/_arch/aarch64/cpu/boot.s | 14 ++++++- 08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s | 14 ++++++- 09_privilege_level/README.md | 12 +++--- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- .../src/_arch/aarch64/cpu/boot.s | 14 ++++++- X1_JTAG_boot/jtag_boot_rpi3.img | Bin 8176 -> 8176 bytes X1_JTAG_boot/jtag_boot_rpi4.img | Bin 6848 -> 6848 bytes X1_JTAG_boot/src/_arch/aarch64/cpu/boot.s | 14 ++++++- 22 files changed, 272 insertions(+), 43 deletions(-) diff --git a/02_runtime_init/README.md b/02_runtime_init/README.md index 64e36440..81143304 100644 --- a/02_runtime_init/README.md +++ b/02_runtime_init/README.md @@ -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 //-------------------------------------------------------------------------------------------------- +// 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. diff --git a/02_runtime_init/src/_arch/aarch64/cpu/boot.s b/02_runtime_init/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/02_runtime_init/src/_arch/aarch64/cpu/boot.s +++ b/02_runtime_init/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/03_hacky_hello_world/src/_arch/aarch64/cpu/boot.s b/03_hacky_hello_world/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/03_hacky_hello_world/src/_arch/aarch64/cpu/boot.s +++ b/03_hacky_hello_world/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/04_safe_globals/src/_arch/aarch64/cpu/boot.s b/04_safe_globals/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/04_safe_globals/src/_arch/aarch64/cpu/boot.s +++ b/04_safe_globals/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s b/05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s +++ b/05_drivers_gpio_uart/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/06_uart_chainloader/README.md b/06_uart_chainloader/README.md index 457a96cd..89a4c796 100644 --- a/06_uart_chainloader/README.md +++ b/06_uart_chainloader/README.md @@ -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"). diff --git a/06_uart_chainloader/demo_payload_rpi3.img b/06_uart_chainloader/demo_payload_rpi3.img index 91602b45b02de681e2e3f0706864f16396592fa9..203ebb7652369e33837c1da09e9b7b7998e4bcf4 100755 GIT binary patch delta 53 zcmdmCy2DgwA%n$LMHYuiPK*o@_6$s~7cww}FfcGo0OE=AK+ML#AQG>@eD(kT|Kb~U GdZYk}WDh|A delta 53 zcmdmCy2DgwA%n$LMHYuiPK*o@_6$s~8yOfv7BDbG$TKiZWM^OyiC190`v3obaRvqs JhK)KsQUIEt4*>uG diff --git a/06_uart_chainloader/demo_payload_rpi4.img b/06_uart_chainloader/demo_payload_rpi4.img index b1060665b4af3eadced31cec72de42265985d110..b06166dcbae527c6f1cc42c11d9200ed60f9dabf 100755 GIT binary patch delta 53 zcmbPXGQ&h?A%n$LMHYuiPK*o@_6$s~7cww}FfcGo0OE=AK+ML#AQG>@eD(kT|Kb~U H-bexfe7z4| delta 53 zcmbPXGQ&h?A%n$LMHYuiPK*o@_6$s~8yOfv7BDbG$TKiZWM^OyiC190`v3obaRvqs JhK)LJBms^14;}yj diff --git a/06_uart_chainloader/src/_arch/aarch64/cpu/boot.s b/06_uart_chainloader/src/_arch/aarch64/cpu/boot.s index 4f45ebd1..10aebb34 100644 --- a/06_uart_chainloader/src/_arch/aarch64/cpu/boot.s +++ b/06_uart_chainloader/src/_arch/aarch64/cpu/boot.s @@ -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"). diff --git a/07_timestamps/README.md b/07_timestamps/README.md index b115dc09..b898aa40 100644 --- a/07_timestamps/README.md +++ b/07_timestamps/README.md @@ -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 diff --git a/07_timestamps/src/_arch/aarch64/cpu/boot.s b/07_timestamps/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/07_timestamps/src/_arch/aarch64/cpu/boot.s +++ b/07_timestamps/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s b/08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s +++ b/08_hw_debug_JTAG/src/_arch/aarch64/cpu/boot.s @@ -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. diff --git a/09_privilege_level/README.md b/09_privilege_level/README.md index b8af3021..b786bf33 100644 --- a/09_privilege_level/README.md +++ b/09_privilege_level/README.md @@ -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. diff --git a/09_privilege_level/src/_arch/aarch64/cpu/boot.s b/09_privilege_level/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/09_privilege_level/src/_arch/aarch64/cpu/boot.s +++ b/09_privilege_level/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/cpu/boot.s b/10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/cpu/boot.s +++ b/10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/11_exceptions_part1_groundwork/src/_arch/aarch64/cpu/boot.s b/11_exceptions_part1_groundwork/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/11_exceptions_part1_groundwork/src/_arch/aarch64/cpu/boot.s +++ b/11_exceptions_part1_groundwork/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/12_integrated_testing/src/_arch/aarch64/cpu/boot.s b/12_integrated_testing/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/12_integrated_testing/src/_arch/aarch64/cpu/boot.s +++ b/12_integrated_testing/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/boot.s b/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/boot.s +++ b/13_exceptions_part2_peripheral_IRQs/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/cpu/boot.s b/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/cpu/boot.s index be81b20a..5696220d 100644 --- a/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/cpu/boot.s +++ b/14_virtual_mem_part2_mmio_remap/src/_arch/aarch64/cpu/boot.s @@ -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(). diff --git a/X1_JTAG_boot/jtag_boot_rpi3.img b/X1_JTAG_boot/jtag_boot_rpi3.img index 8eed7dba0e7d56b27a14d14f981f77b599d9b6c3..53be6bb3a5207dad2a75a526053ad11b367272c0 100755 GIT binary patch delta 53 zcmexh|G{2oA%n$LMHYuiPK*o@_6$s~7cww}FfcGo0OE=AK+ML#AQG>@eD(kT|Kb~U Hj>rQ5q?Hf? delta 53 zcmexh|G{2oA%n$LMHYuiPK*o@_6$s~8yOfv7BDbG$TKiZWM^OyiC190`v3obaRvqs JhK)K$wN55fQd diff --git a/X1_JTAG_boot/jtag_boot_rpi4.img b/X1_JTAG_boot/jtag_boot_rpi4.img index cbdd1b808832df622e2be50a4bb24e5437756355..5e1e1bf7d6716daa5b88a735299e89c268faf47d 100755 GIT binary patch delta 53 zcmX?Ldcag?A%n$LMHYuiPK*o@_6$s~7cww}FfcGo0OE=AK+ML#AQG>@eD(kT|Kb~U Hrbqz*jI<9~ delta 53 zcmX?Ldcag?A%n$LMHYuiPK*o@_6$s~8yOfv7BDbG$TKiZWM^OyiC190`v3obaRvqs JhK)K?qyU}o4;cUe diff --git a/X1_JTAG_boot/src/_arch/aarch64/cpu/boot.s b/X1_JTAG_boot/src/_arch/aarch64/cpu/boot.s index ad4a2689..bfa94abf 100644 --- a/X1_JTAG_boot/src/_arch/aarch64/cpu/boot.s +++ b/X1_JTAG_boot/src/_arch/aarch64/cpu/boot.s @@ -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.