diff --git a/Kernel/arch/aarch64/bootstrap/boot.S b/Kernel/arch/aarch64/bootstrap/boot.S
index bcd2fc42..c9f0697a 100644
--- a/Kernel/arch/aarch64/bootstrap/boot.S
+++ b/Kernel/arch/aarch64/bootstrap/boot.S
@@ -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 .
+*/
+
+.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
diff --git a/Kernel/arch/aarch64/bootstrap/init.c b/Kernel/arch/aarch64/bootstrap/init.c
new file mode 100644
index 00000000..9ad979d1
--- /dev/null
+++ b/Kernel/arch/aarch64/bootstrap/init.c
@@ -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 .
+*/
+
+#include
+
+__attribute__((section(".bootstrap.text"))) void _aarch64_start(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
+{
+ while (1)
+ ;
+}
diff --git a/Kernel/arch/aarch64/linker.ld b/Kernel/arch/aarch64/linker.ld
index d50030f6..26b6db49 100644
--- a/Kernel/arch/aarch64/linker.ld
+++ b/Kernel/arch/aarch64/linker.ld
@@ -20,43 +20,60 @@ OUTPUT_ARCH(aarch64)
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
{
+ . = 0x80000;
_bootstrap_start = .;
- .text.boot :
+ .bootstrap :
{
- *(.text.boot)
- . += CONSTANT(MAXPAGESIZE);
- _bss_start = .;
- *(.text.bss)
- _bss_end = .;
- }
+ *(.bootstrap.boot .bootstrap.boot.*)
+ *(.bootstrap .bootstrap.*)
+ } :bootstrap
_bootstrap_end = .;
_kernel_start = .;
_kernel_text_start = .;
.text :
{
- KEEP(*(.text.boot))
*(.text .text.*)
- }
- . = ALIGN(4096);
+ } :text
_kernel_text_end = .;
_kernel_data_start = .;
.data :
{
*(.data .data.*)
- }
- . = ALIGN(4096);
+ } :data
+
+ .eh_frame :
+ {
+ KEEP (*(.eh_frame .eh_frame.*))
+ } :data
+
+ .gcc_except_table :
+ {
+ KEEP (*(.gcc_except_table .gcc_except_table.*))
+ } :data
_kernel_data_end = .;
_kernel_rodata_start = .;
.rodata :
{
*(.rodata .rodata.*)
- }
- . = ALIGN(4096);
+ } :rodata
.init_array :
{
@@ -64,7 +81,7 @@ SECTIONS
KEEP(*(.init_array .ctors))
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
PROVIDE_HIDDEN (__init_array_end = .);
- }
+ } :rodata
.fini_array :
{
@@ -72,18 +89,33 @@ SECTIONS
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.fini_array .dtors))
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_bss_start = .;
.bss :
{
+ *(COMMON)
*(.bss .bss.*)
- }
- . = ALIGN(4096);
+ } :bss
_kernel_bss_end = .;
+ _kernel_bss_size = SIZEOF(.bss);
_kernel_end = .;
- _bss_size = _kernel_end - _kernel_rodata_end;
/DISCARD/ :
{