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 91602b45..203ebb76 100755 Binary files a/06_uart_chainloader/demo_payload_rpi3.img and b/06_uart_chainloader/demo_payload_rpi3.img differ diff --git a/06_uart_chainloader/demo_payload_rpi4.img b/06_uart_chainloader/demo_payload_rpi4.img index b1060665..b06166dc 100755 Binary files a/06_uart_chainloader/demo_payload_rpi4.img and b/06_uart_chainloader/demo_payload_rpi4.img differ 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 8eed7dba..53be6bb3 100755 Binary files a/X1_JTAG_boot/jtag_boot_rpi3.img and b/X1_JTAG_boot/jtag_boot_rpi3.img differ diff --git a/X1_JTAG_boot/jtag_boot_rpi4.img b/X1_JTAG_boot/jtag_boot_rpi4.img index cbdd1b80..5e1e1bf7 100755 Binary files a/X1_JTAG_boot/jtag_boot_rpi4.img and b/X1_JTAG_boot/jtag_boot_rpi4.img differ 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.