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 namespace SMP
{ {
int CPUCores = 0;
void Initialize(void *madt) void Initialize(void *madt)
{ {
fixme("SMP::Initialize() is not implemented!"); fixme("SMP::Initialize() is not implemented!");

View File

@ -19,7 +19,15 @@ ENTRY(_start)
SECTIONS SECTIONS
{ {
. = 0x80000; .text.boot :
{
*(.text.boot)
. += CONSTANT(MAXPAGESIZE);
_bss_start = .;
*(.text.bss)
_bss_end = .;
}
_kernel_start = .; _kernel_start = .;
.text : .text :
{ {
@ -43,6 +51,22 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
_kernel_rodata_end = .; _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 .bss.*) *(.bss .bss.*)

View File

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

View File

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

View File

@ -66,8 +66,8 @@ SIMD_FLAGS := -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -mavx51
ifeq ($(OSARCH), amd64) ifeq ($(OSARCH), amd64)
CFLAGS += -fno-pic -fno-pie \ CFLAGS += -fno-pic -fno-pie \
-mno-red-zone -march=core2 -pipe \ -mno-red-zone -march=core2 -pipe \
-mcmodel=kernel -fno-builtin -Da64 -mcmodel=kernel -fno-builtin -Da64
CFLAG_STACK_PROTECTOR := -fstack-protector-all CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -TArchitecture/amd64/linker.ld \ LDFLAGS += -TArchitecture/amd64/linker.ld \
@ -92,9 +92,13 @@ LDFLAGS += -TArchitecture/i386/linker.ld \
else ifeq ($(OSARCH), aarch64) else ifeq ($(OSARCH), aarch64)
CFLAGS += -pipe -fno-builtin -fPIC -Wstack-protector -Daa64 CFLAGS += -pipe -fno-builtin -Wstack-protector -Daa64 -fPIC -mno-outline-atomics
CFLAG_STACK_PROTECTOR := -fstack-protector-all -fstack-clash-protection CFLAG_STACK_PROTECTOR := -fstack-protector-all
LDFLAGS += -TArchitecture/aarch64/linker.ld -fPIC 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 endif
@ -166,13 +170,7 @@ endif
%.o: %.S %.o: %.S
$(info Compiling $<) $(info Compiling $<)
ifeq ($(OSARCH), amd64)
$(AS) -c $< -o $@ $(AS) -c $< -o $@
else ifeq ($(OSARCH), i386)
$(AS) -c $< -o $@
else ifeq ($(OSARCH), aarch64)
$(AS) -c $< -o $@
endif
%.o: %.psf %.o: %.psf
ifeq ($(OSARCH), amd64) ifeq ($(OSARCH), amd64)