kernel: update boot code and linker script for aarch64

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-01-13 09:22:01 +02:00
parent 210e06429c
commit 749a1b1810
3 changed files with 115 additions and 46 deletions

View File

@ -1,36 +1,49 @@
/* Based on this tutorial:
https://github.com/s-matyukevich/raspberry-pi-os */
/*
This file is part of Fennix Kernel.
.section ".text.boot", "a"
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
.extern _bss_start
.extern _bss_end
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.extern arm64Entry
memzero:
str xzr, [x0], #8
subs x1, x1, #8
b.gt memzero
ret
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
.section ".bootstrap.boot", "a"
.extern _kernel_bss_start
.extern _kernel_bss_end
.extern _kernel_bss_size
.global _start
_start:
mrs x0, mpidr_el1
and x0, x0, #0xFF
cbz x0, _start2
b CPU_Loop
/* Keep only the main core */
mrs x1, mpidr_el1
and x1, x1, #3
cbz x1, 2f
_start2:
adr x0, _bss_start
adr x1, _bss_end
sub x1, x1, x0
bl memzero
mov sp, #0x200000
bl arm64Entry
/* Halt */
1: wfe
b 1b
Halt:
wfe
b Halt
/* Initialize the stack */
2: ldr x1, =_start
mov sp, x1
CPU_Loop:
b CPU_Loop
/* Clear the BSS */
ldr x1, =_kernel_bss_start
ldr w2, =_kernel_bss_size
3: cbz w2, 4f
str xzr, [x1], #8
sub w2, w2, #1
cbnz w2, 3b
/* Start the kernel */
4: bl _aarch64_start
b 1b