Make aarch64 compilable

This commit is contained in:
Alex 2023-04-04 19:36:45 +03:00
parent 74dab6c44e
commit b265b4aced
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
6 changed files with 96 additions and 36 deletions

View File

@ -0,0 +1,36 @@
/* Based on this tutorial:
https://github.com/s-matyukevich/raspberry-pi-os */
.section ".text.boot"
.extern _bss_start
.extern _bss_end
.extern arm64Entry
memzero:
str xzr, [x0], #8
subs x1, x1, #8
b.gt memzero
ret
.global _start
_start:
mrs x0, mpidr_el1
and x0, x0, #0xFF
cbz x0, _start2
b CPU_Loop
_start2:
adr x0, _bss_start
adr x1, _bss_end
sub x1, x1, x0
bl memzero
mov sp, #0x200000
bl arm64Entry
Halt:
wfe
b Halt
CPU_Loop:
b CPU_Loop

View File

@ -50,6 +50,8 @@ CPUData *GetCurrentCPU()
namespace SMP
{
int CPUCores = 0;
void Initialize(void *madt)
{
fixme("SMP::Initialize() is not implemented!");

View File

@ -19,7 +19,15 @@ ENTRY(_start)
SECTIONS
{
. = 0x80000;
.text.boot :
{
*(.text.boot)
. += CONSTANT(MAXPAGESIZE);
_bss_start = .;
*(.text.bss)
_bss_end = .;
}
_kernel_start = .;
.text :
{
@ -43,6 +51,22 @@ SECTIONS
. = ALIGN(4096);
_kernel_rodata_end = .;
.init_array :
{
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(.init_array .ctors))
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP(*(.fini_array .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.bss :
{
*(.bss .bss.*)

View File

@ -1,17 +1,17 @@
.section ".text.boot"
// .section ".text.boot"
.global _start
.org 0x80000
_start:
ldr x5, =_start
mov sp, x5
ldr x5, =_kernel_rodata_end
ldr w6, =_bss_size
1: cbz w6, 2f
str xzr, [x5], #8
sub w6, w6, #1
cbnz w6, 1b
2: bl arm64Entry
Halt:
wfe
b Halt
// .global _start
// .org 0x80000
// _start:
// ldr x5, =_start
// mov sp, x5
// ldr x5, =_kernel_rodata_end
// ldr w6, =_bss_size
// 1: cbz w6, 2f
// str xzr, [x5], #8
// sub w6, w6, #1
// cbnz w6, 1b
// 2: bl arm64Entry
// Halt:
// wfe
// b Halt

View File

@ -1,13 +1,13 @@
.section .init
.global _init
.type _init, @function
_init:
// .section .init
// .global _init
// .type _init, @function
// _init:
// push %rbp
// movq %rsp, %rbp
.section .fini
.global _fini
.type _fini, @function
_fini:
// .section .fini
// .global _fini
// .type _fini, @function
// _fini:
// push %rbp
// movq %rsp, %rbp

View File

@ -92,9 +92,13 @@ LDFLAGS += -TArchitecture/i386/linker.ld \
else ifeq ($(OSARCH), aarch64)
CFLAGS += -pipe -fno-builtin -fPIC -Wstack-protector -Daa64
CFLAG_STACK_PROTECTOR := -fstack-protector-all -fstack-clash-protection
LDFLAGS += -TArchitecture/aarch64/linker.ld -fPIC
CFLAGS += -pipe -fno-builtin -Wstack-protector -Daa64 -fPIC -mno-outline-atomics
CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -TArchitecture/aarch64/linker.ld -fPIC -pie \
-Wl,-static,--no-dynamic-linker,-ztext \
-nostdlib -nodefaultlibs -nolibc \
-zmax-page-size=0x1000 \
-Wl,-Map kernel.map -static
endif
@ -166,13 +170,7 @@ endif
%.o: %.S
$(info Compiling $<)
ifeq ($(OSARCH), amd64)
$(AS) -c $< -o $@
else ifeq ($(OSARCH), i386)
$(AS) -c $< -o $@
else ifeq ($(OSARCH), aarch64)
$(AS) -c $< -o $@
endif
%.o: %.psf
ifeq ($(OSARCH), amd64)