kernel: update boot code and linker script for aarch64

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-01-13 09:22:01 +02:00
parent 210e06429c
commit 749a1b1810
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
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 Fennix Kernel is distributed in the hope that it will be useful,
.extern _bss_end 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 You should have received a copy of the GNU General Public License
memzero: along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
str xzr, [x0], #8 */
subs x1, x1, #8
b.gt memzero .section ".bootstrap.boot", "a"
ret
.extern _kernel_bss_start
.extern _kernel_bss_end
.extern _kernel_bss_size
.global _start .global _start
_start: _start:
mrs x0, mpidr_el1 /* Keep only the main core */
and x0, x0, #0xFF mrs x1, mpidr_el1
cbz x0, _start2 and x1, x1, #3
b CPU_Loop cbz x1, 2f
_start2: /* Halt */
adr x0, _bss_start 1: wfe
adr x1, _bss_end b 1b
sub x1, x1, x0
bl memzero
mov sp, #0x200000
bl arm64Entry
Halt: /* Initialize the stack */
wfe 2: ldr x1, =_start
b Halt mov sp, x1
CPU_Loop: /* Clear the BSS */
b CPU_Loop 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

View File

@ -0,0 +1,24 @@
/*
This file is part of Fennix Kernel.
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.
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.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <types.h>
__attribute__((section(".bootstrap.text"))) void _aarch64_start(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
{
while (1)
;
}

View File

@ -20,43 +20,60 @@ OUTPUT_ARCH(aarch64)
ENTRY(_start) ENTRY(_start)
PF_R = 0x4;
PF_W = 0x2;
PF_X = 0x1;
PHDRS
{
bootstrap PT_LOAD FLAGS( PF_R | PF_W /*| PF_X*/ );
text PT_LOAD FLAGS( PF_R | PF_X );
data PT_LOAD FLAGS( PF_R | PF_W );
rodata PT_LOAD FLAGS( PF_R );
bss PT_LOAD FLAGS( PF_R | PF_W );
}
SECTIONS SECTIONS
{ {
. = 0x80000;
_bootstrap_start = .; _bootstrap_start = .;
.text.boot : .bootstrap :
{ {
*(.text.boot) *(.bootstrap.boot .bootstrap.boot.*)
. += CONSTANT(MAXPAGESIZE); *(.bootstrap .bootstrap.*)
_bss_start = .; } :bootstrap
*(.text.bss)
_bss_end = .;
}
_bootstrap_end = .; _bootstrap_end = .;
_kernel_start = .; _kernel_start = .;
_kernel_text_start = .; _kernel_text_start = .;
.text : .text :
{ {
KEEP(*(.text.boot))
*(.text .text.*) *(.text .text.*)
} } :text
. = ALIGN(4096);
_kernel_text_end = .; _kernel_text_end = .;
_kernel_data_start = .; _kernel_data_start = .;
.data : .data :
{ {
*(.data .data.*) *(.data .data.*)
} } :data
. = ALIGN(4096);
.eh_frame :
{
KEEP (*(.eh_frame .eh_frame.*))
} :data
.gcc_except_table :
{
KEEP (*(.gcc_except_table .gcc_except_table.*))
} :data
_kernel_data_end = .; _kernel_data_end = .;
_kernel_rodata_start = .; _kernel_rodata_start = .;
.rodata : .rodata :
{ {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} } :rodata
. = ALIGN(4096);
.init_array : .init_array :
{ {
@ -64,7 +81,7 @@ SECTIONS
KEEP(*(.init_array .ctors)) KEEP(*(.init_array .ctors))
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
PROVIDE_HIDDEN (__init_array_end = .); PROVIDE_HIDDEN (__init_array_end = .);
} } :rodata
.fini_array : .fini_array :
{ {
@ -72,18 +89,33 @@ SECTIONS
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.fini_array .dtors)) KEEP(*(.fini_array .dtors))
PROVIDE_HIDDEN (__fini_array_end = .); PROVIDE_HIDDEN (__fini_array_end = .);
} } :rodata
.eh_frame_hdr :
{
*(.eh_frame_hdr .eh_frame_hdr.*)
} :rodata
.eh_frame :
{
KEEP (*(.eh_frame .eh_frame.*))
} :rodata
.gcc_except_table :
{
KEEP (*(.gcc_except_table .gcc_except_table.*))
} :rodata
_kernel_rodata_end = .; _kernel_rodata_end = .;
_kernel_bss_start = .; _kernel_bss_start = .;
.bss : .bss :
{ {
*(COMMON)
*(.bss .bss.*) *(.bss .bss.*)
} } :bss
. = ALIGN(4096);
_kernel_bss_end = .; _kernel_bss_end = .;
_kernel_bss_size = SIZEOF(.bss);
_kernel_end = .; _kernel_end = .;
_bss_size = _kernel_end - _kernel_rodata_end;
/DISCARD/ : /DISCARD/ :
{ {