Compare commits
2 Commits
6c39867556
...
f33f707b32
Author | SHA1 | Date | |
---|---|---|---|
f33f707b32 | |||
c234e90c90 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -31,10 +31,11 @@ Temporary Items
|
||||
.vscode
|
||||
|
||||
# Dependencies
|
||||
limine/
|
||||
limine.h
|
||||
u-boot/
|
||||
|
||||
# Build
|
||||
bin/
|
||||
obj/
|
||||
asagiri.iso
|
||||
yukari.bin
|
||||
yukari.uimg
|
||||
asagiri.img
|
||||
|
44
Makefile
44
Makefile
@ -1,21 +1,16 @@
|
||||
override MAKEFLAGS += -rR
|
||||
override IMAGE_NAME := asagiri
|
||||
override ARCH := aarch64
|
||||
|
||||
override CC := aarch64-none-elf-gcc
|
||||
override LD := aarch64-none-elf-ld
|
||||
override DEFAULT_HOST_CFLAGS := -g -O3 -pipe
|
||||
include toolchain.mk
|
||||
|
||||
.PHONY: all
|
||||
all: $(IMAGE_NAME).iso
|
||||
all: $(IMAGE_NAME).img
|
||||
|
||||
.PHONY: run
|
||||
run: $(IMAGE_NAME).iso
|
||||
qemu-system-aarch64 -M raspi3b -drive file=asagiri.iso,if=sd,format=raw -serial stdio -boot d
|
||||
run: $(IMAGE_NAME).img
|
||||
qemu-system-aarch64 -M raspi3b -kernel $(IMAGE_NAME).img -serial null -serial stdio
|
||||
|
||||
limine:
|
||||
git clone https://github.com/limine-bootloader/limine.git --branch=v5.x-branch-binary --depth=1
|
||||
$(MAKE) -C limine
|
||||
uboot:
|
||||
git clone https://github.com/u-boot/u-boot.git --branch=v2023.10 --depth=1 2>/dev/null | true
|
||||
$(MAKE) -C u-boot rpi_3_defconfig ARCH=arm CROSS_COMPILE=aarch64-none-elf-
|
||||
$(MAKE) -C u-boot all ARCH=arm CROSS_COMPILE=aarch64-none-elf-
|
||||
|
||||
.PHONY: hal
|
||||
hal:
|
||||
@ -25,31 +20,16 @@ hal:
|
||||
yukari:
|
||||
$(MAKE) -C yukari
|
||||
|
||||
$(IMAGE_NAME).iso: limine hal libc yukari
|
||||
rm -rf iso_root
|
||||
mkdir -p iso_root
|
||||
cp -v yukari/bin/yukari \
|
||||
limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
|
||||
mkdir -p iso_root/EFI/BOOT
|
||||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
|
||||
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/
|
||||
xorriso -as mkisofs -b limine-bios-cd.bin \
|
||||
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
||||
--efi-boot limine-uefi-cd.bin \
|
||||
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
||||
iso_root -o $(IMAGE_NAME).iso
|
||||
./limine/limine bios-install $(IMAGE_NAME).iso
|
||||
qemu-img resize $(IMAGE_NAME).iso 4M
|
||||
rm -rf iso_root
|
||||
$(IMAGE_NAME).img: uboot hal libc yukari
|
||||
./u-boot/tools/mkimage -A arm64 -C none -O linux -T kernel -d yukari/bin/yukari -a 0x100000 -e 0x100000 yukari.uimg
|
||||
cat ./u-boot/u-boot.bin yukari.uimg > $(IMAGE_NAME).img
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf iso_root $(IMAGE_NAME).iso $(IMAGE_NAME).hdd
|
||||
$(MAKE) -C yukari clean
|
||||
$(MAKE) -C arch/$(ARCH) clean
|
||||
$(MAKE) -C libc clean
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
rm -rf limine ovmf
|
||||
$(MAKE) -C yukari distclean
|
||||
rm -rf u-boot
|
||||
|
@ -1,30 +1,4 @@
|
||||
override MAKEFLAGS += -rR
|
||||
override ARCH := aarch64
|
||||
|
||||
override CC := aarch64-elf-gcc
|
||||
override LD := aarch64-elf-ld
|
||||
override CFLAGS := -g -O3 -pipe
|
||||
|
||||
override CFLAGS += \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-std=c99 \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-lto \
|
||||
-fPIE \
|
||||
-march=native
|
||||
|
||||
override LDFLAGS += \
|
||||
-m aarch64elf \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-pie \
|
||||
--no-dynamic-linker \
|
||||
-z text \
|
||||
-z max-page-size=0x1000 \
|
||||
-T linker.ld
|
||||
include ../../toolchain.mk
|
||||
|
||||
override CFILES := $(shell find -L * -type f -name '*.c')
|
||||
override ASFILES := $(shell find -L * -type f -name '*.S')
|
||||
|
@ -2,41 +2,12 @@ ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000;
|
||||
. = 0x100000;
|
||||
__start = .;
|
||||
__text_start = .;
|
||||
.text :
|
||||
{
|
||||
KEEP(*(.text.boot))
|
||||
*(.text)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__text_end = .;
|
||||
|
||||
__rodata_start = .;
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__rodata_end = .;
|
||||
|
||||
__data_start = .;
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__data_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss :
|
||||
{
|
||||
bss = .;
|
||||
*(.bss)
|
||||
}
|
||||
. = ALIGN(4096); /* align to page size */
|
||||
__bss_end = .;
|
||||
__bss_size = __bss_end - __bss_start;
|
||||
__end = .;
|
||||
.text : { *(.text) }
|
||||
.rodata : { *(.rodata) }
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss) }
|
||||
. = . + 0x1000; /* 4kB of stack memory */
|
||||
stack_top = .;
|
||||
}
|
0
compile-toolchain.sh
Normal file → Executable file
0
compile-toolchain.sh
Normal file → Executable file
@ -1,32 +1,10 @@
|
||||
override MAKEFLAGS += -rR
|
||||
|
||||
override CC := aarch64-elf-gcc
|
||||
override LD := aarch64-elf-ld
|
||||
override CFLAGS := -g -O3 -pipe
|
||||
|
||||
override INCLUDES := -Isrc/include \
|
||||
-I../arch/aarch64
|
||||
include ../toolchain.mk
|
||||
|
||||
override CFLAGS += \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-std=c99 \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-lto \
|
||||
-fPIE \
|
||||
-march=native \
|
||||
$(INCLUDES)
|
||||
-Isrc/include \
|
||||
-I../arch/aarch64
|
||||
|
||||
override LDFLAGS += \
|
||||
-m aarch64elf \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-pie \
|
||||
--no-dynamic-linker \
|
||||
-z text \
|
||||
-z max-page-size=0x1000 \
|
||||
-T ../arch/aarch64/linker.ld
|
||||
|
||||
override CFILES := $(shell cd src && find * -type f -name '*.c')
|
||||
|
@ -1,4 +0,0 @@
|
||||
TIMEOUT=3
|
||||
:Limine Barebones
|
||||
PROTOCOL=limine
|
||||
KERNEL_PATH=boot:///yukari
|
30
toolchain.mk
Normal file
30
toolchain.mk
Normal file
@ -0,0 +1,30 @@
|
||||
override MAKEFLAGS += -rR
|
||||
override IMAGE_NAME := asagiri
|
||||
override ARCH := aarch64
|
||||
override KERNEL := yukari
|
||||
|
||||
override CC := aarch64-none-elf-gcc
|
||||
override LD := aarch64-none-elf-ld
|
||||
override OBJCOPY = aarch64-none-elf-objcopy
|
||||
|
||||
override CFLAGS := -g -O3 -pipe
|
||||
|
||||
override CFLAGS += \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-std=c99 \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-lto \
|
||||
-fPIE \
|
||||
-march=armv8-a
|
||||
|
||||
override LDFLAGS += \
|
||||
-m aarch64elf \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-pie \
|
||||
--no-dynamic-linker \
|
||||
-z text \
|
||||
-z max-page-size=0x1000
|
@ -1,49 +1,22 @@
|
||||
override MAKEFLAGS += -rR
|
||||
override KERNEL := yukari
|
||||
include ../toolchain.mk
|
||||
|
||||
override CC := aarch64-elf-gcc
|
||||
override LD := aarch64-elf-ld
|
||||
override CFLAGS := -g -O3 -pipe
|
||||
|
||||
override INCLUDES := -Isrc/include \
|
||||
override CFLAGS += \
|
||||
-Isrc/include \
|
||||
-I../arch/aarch64 \
|
||||
-I../libc/src/include
|
||||
|
||||
override CFLAGS += \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-std=c99 \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-lto \
|
||||
-fPIE \
|
||||
-march=native \
|
||||
$(INCLUDES)
|
||||
|
||||
override LDFLAGS += \
|
||||
-m aarch64elf \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-pie \
|
||||
--no-dynamic-linker \
|
||||
-z text \
|
||||
-z max-page-size=0x1000 \
|
||||
-T ../arch/aarch64/linker.ld
|
||||
|
||||
override CFILES := $(shell cd src && find * -type f -name '*.c')
|
||||
override ASFILES := $(shell cd src && find * -type f -name '*.S')
|
||||
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o))
|
||||
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
|
||||
# teaks gonna kill me
|
||||
override OBJDEPS := $(addprefix ../arch/aarch64/obj/,$(shell cd ../arch/aarch64/obj && find * -type f -name '*.S.o'))
|
||||
override OBJDEPS := $(shell find ../arch/aarch64/obj/* -type f -name '*.S.o')
|
||||
|
||||
.PHONY: all
|
||||
all: bin/$(KERNEL)
|
||||
|
||||
src/include/limine.h:
|
||||
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h
|
||||
|
||||
# Link rules for the final kernel executable.
|
||||
bin/$(KERNEL): Makefile ../arch/aarch64/linker.ld $(OBJ)
|
||||
mkdir -p "$$(dirname $@)"
|
||||
@ -53,7 +26,7 @@ bin/$(KERNEL): Makefile ../arch/aarch64/linker.ld $(OBJ)
|
||||
-include $(HEADER_DEPS)
|
||||
|
||||
# Compilation rules for *.c files.
|
||||
obj/%.c.o: src/%.c Makefile src/include/limine.h
|
||||
obj/%.c.o: src/%.c Makefile
|
||||
mkdir -p "$$(dirname $@)"
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
@ -66,7 +39,3 @@ obj/%.S.o: src/%.S Makefile
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf bin obj
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
rm -f src/include/limine.h
|
@ -16,27 +16,19 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <limine.h>
|
||||
#include <hal.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static volatile struct limine_framebuffer_request framebuffer_request = {
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||
.revision = 0
|
||||
};
|
||||
volatile unsigned int * const UART0DR = (unsigned int *)0x101f1000;
|
||||
|
||||
void print_uart0(const char *s) {
|
||||
while(*s != '\0') { /* Loop until end of string */
|
||||
*UART0DR = *s; /* Transmit char */
|
||||
s++; /* Next char */
|
||||
}
|
||||
}
|
||||
|
||||
void _start(void) {
|
||||
if (framebuffer_request.response == NULL
|
||||
|| framebuffer_request.response->framebuffer_count < 1) {
|
||||
hcf();
|
||||
}
|
||||
|
||||
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];
|
||||
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
volatile uint32_t *fb_ptr = framebuffer->address;
|
||||
fb_ptr[i * (framebuffer->pitch / 4) + i] = 0xffffff;
|
||||
}
|
||||
|
||||
print_uart0("Hello world!\n");
|
||||
hcf();
|
||||
}
|
Loading…
Reference in New Issue
Block a user