diff --git a/Makefile b/Makefile index cffd1b8..a5a6d8c 100644 --- a/Makefile +++ b/Makefile @@ -340,8 +340,8 @@ endif # $(dot-config) all: arch/$(ARCH)/linker.lds uniLoader # List of main executables -main-y := main/main.o -main-y += arch/$(ARCH)/Start.o +main-y := arch/$(ARCH)/start.o \ + main/main.o # Object directories objs-y := main diff --git a/arch/Makefile b/arch/Makefile index e403bdc..e3ece6d 100644 --- a/arch/Makefile +++ b/arch/Makefile @@ -1 +1 @@ -obj-y += $(ARCH)/Start.o +obj-y += $(ARCH)/start.o diff --git a/arch/aarch64/Start.S b/arch/aarch64/Start.S deleted file mode 100644 index 316d0a6..0000000 --- a/arch/aarch64/Start.S +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2022, Ivaylo Ivanov - */ - - adr x0, dtb - adr x1, kernel - b main - -.global load_kernel -load_kernel: - br x4 diff --git a/arch/aarch64/linker.lds.S b/arch/aarch64/linker.lds.S index e145266..80aee3f 100644 --- a/arch/aarch64/linker.lds.S +++ b/arch/aarch64/linker.lds.S @@ -13,15 +13,30 @@ INPUT(DTB_PATH) SECTIONS { .boot : { - arch/aarch64/Start.o + arch/aarch64/start.o } - .dtb ALIGN(0x1000) : { + .text : { + *(.text) + } + + .bss ALIGN(4096) : { + _bss_start = .; + . = . + 4096; + _bss_end = .; + } + + .stack ALIGN(4096) : { + . = . + 4096; + _stack_end = .; + } + + .dtb ALIGN(4096) : { dtb = .; DTB_PATH } - .kernel ALIGN(0x1000) : { + .kernel ALIGN(4096) : { kernel = .; KERNEL_PATH } diff --git a/arch/aarch64/macros.h b/arch/aarch64/macros.h new file mode 100644 index 0000000..cfe341a --- /dev/null +++ b/arch/aarch64/macros.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + +.macro ENTRY name + .globl \name + .type \name, %function + .align 2 + \name: +.endm + +.macro ENDPROC name + .size \name, . - \name +.endm diff --git a/arch/aarch64/start.S b/arch/aarch64/start.S new file mode 100644 index 0000000..d63f3fe --- /dev/null +++ b/arch/aarch64/start.S @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ +.include "arch/aarch64/macros.h" + +.section .text +ENTRY _start + /* Set up the base address for the stack */ + adr x0, _stack_end + + /* Set up the stack pointer (SP) */ + mov sp, x0 + + /* Fall through */ + adr x0, dtb + adr x1, kernel + b main + +ENTRY load_kernel + br x4 +ENDPROC load_kernel diff --git a/arch/arm/linker.lds.S b/arch/arm/linker.lds.S index 90d2b76..fe7cea2 100644 --- a/arch/arm/linker.lds.S +++ b/arch/arm/linker.lds.S @@ -14,7 +14,7 @@ SECTIONS . = __start_address; .boot : { - arch/arm/Start.o + arch/arm/start.o } .dtb ALIGN(0x1000) : { diff --git a/arch/arm/Start.S b/arch/arm/start.S similarity index 100% rename from arch/arm/Start.S rename to arch/arm/start.S