Compare commits

...

2 Commits

10 changed files with 155 additions and 264 deletions

7
.gitignore vendored
View File

@ -31,10 +31,11 @@ Temporary Items
.vscode
# Dependencies
limine/
limine.h
u-boot/
# Build
bin/
obj/
asagiri.iso
yukari.bin
yukari.uimg
asagiri.img

View File

@ -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

View File

@ -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')

View File

@ -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 = .;
}

166
compile-toolchain.sh Normal file → Executable file
View File

@ -1,83 +1,83 @@
#!/bin/sh
set -euo pipefail
export PREFIX="$HOME/cross-aarch64"
export TARGET="aarch64-none-elf"
export PATH="$PREFIX/bin:$PATH"
# Get thread count
if [ "$(uname)" == "Darwin" ]; then
export NPROC="sysctl -n hw.physicalcpu"
else
export NPROC="nproc"
fi
existGCC=0
existBIN=0
if [ -e binutils-2.41.tar.gz ]; then
existBIN=1
fi
if [ -e gcc-13.2.0.tar.gz ]; then
existGCC=1
fi
startLoc=$(pwd)
# Create prefix path
mkdir -p $PREFIX
# Create compilation directory
cd /tmp
rm -rf toolchain
mkdir -p toolchain
cd toolchain
# Get sources
if [[ "${existBIN}" != "1" ]]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.gz
else
cp "${startLoc}/binutils-2.41.tar.gz" .
fi
if [[ "${existGCC}" != "1" ]]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
else
cp "${startLoc}/gcc-13.2.0.tar.gz" .
fi
# Build binutils for aarch64
# might need texinfo
mkdir -p binutils-src
tar -xvf binutils-2.41.tar.gz -C binutils-src/
mkdir -p binutils
cd binutils
../binutils-src/*/configure --target=$TARGET --prefix=$PREFIX --libexecdir=$PREFIX/lib \
--enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --enable-__cxa_atexit \
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-plugin \
--disable-linker-build-id --enable-lto --enable-install-libiberty --with-linker-hash-style=gnu --with-gnu-ld\
--enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie \
--enable-default-ssp --enable-gnu-unique-object --with-zstd=no --with-arch=armv8-a --enable-fix-cortex-a53-835769 \
--enable-fix-cortex-a53-843419
make -j$($NPROC)
make install
# Build gcc for aarch64
cd ..
mkdir -p gcc-src
tar -xvf gcc-13.2.0.tar.gz -C gcc-src/
cd gcc-src/*/
./contrib/download_prerequisites
cd ../../
mkdir -p gcc
cd gcc
../gcc-src/*/configure --target=$TARGET --prefix=$PREFIX --disable-shared --disable-nls --disable-threads --disable-tls \
--enable-checking=release --enable-languages=c,c++ --with-newlib --with-gnu-as --with-gnu-ld
make -j$($NPROC) all-gcc
make install-gcc
make -j$($NPROC) all-target-libgcc
make install-target-libgcc
cd
rm -rf /tmp/toolchain
echo "Toolchain installation is complete!"
echo "Please add this to your bashrc or zshrc or whatever"
echo "export PATH=\"$PREFIX/bin:\$PATH\""
#!/bin/sh
set -euo pipefail
export PREFIX="$HOME/cross-aarch64"
export TARGET="aarch64-none-elf"
export PATH="$PREFIX/bin:$PATH"
# Get thread count
if [ "$(uname)" == "Darwin" ]; then
export NPROC="sysctl -n hw.physicalcpu"
else
export NPROC="nproc"
fi
existGCC=0
existBIN=0
if [ -e binutils-2.41.tar.gz ]; then
existBIN=1
fi
if [ -e gcc-13.2.0.tar.gz ]; then
existGCC=1
fi
startLoc=$(pwd)
# Create prefix path
mkdir -p $PREFIX
# Create compilation directory
cd /tmp
rm -rf toolchain
mkdir -p toolchain
cd toolchain
# Get sources
if [[ "${existBIN}" != "1" ]]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.gz
else
cp "${startLoc}/binutils-2.41.tar.gz" .
fi
if [[ "${existGCC}" != "1" ]]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
else
cp "${startLoc}/gcc-13.2.0.tar.gz" .
fi
# Build binutils for aarch64
# might need texinfo
mkdir -p binutils-src
tar -xvf binutils-2.41.tar.gz -C binutils-src/
mkdir -p binutils
cd binutils
../binutils-src/*/configure --target=$TARGET --prefix=$PREFIX --libexecdir=$PREFIX/lib \
--enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --enable-__cxa_atexit \
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-plugin \
--disable-linker-build-id --enable-lto --enable-install-libiberty --with-linker-hash-style=gnu --with-gnu-ld\
--enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie \
--enable-default-ssp --enable-gnu-unique-object --with-zstd=no --with-arch=armv8-a --enable-fix-cortex-a53-835769 \
--enable-fix-cortex-a53-843419
make -j$($NPROC)
make install
# Build gcc for aarch64
cd ..
mkdir -p gcc-src
tar -xvf gcc-13.2.0.tar.gz -C gcc-src/
cd gcc-src/*/
./contrib/download_prerequisites
cd ../../
mkdir -p gcc
cd gcc
../gcc-src/*/configure --target=$TARGET --prefix=$PREFIX --disable-shared --disable-nls --disable-threads --disable-tls \
--enable-checking=release --enable-languages=c,c++ --with-newlib --with-gnu-as --with-gnu-ld
make -j$($NPROC) all-gcc
make install-gcc
make -j$($NPROC) all-target-libgcc
make install-target-libgcc
cd
rm -rf /tmp/toolchain
echo "Toolchain installation is complete!"
echo "Please add this to your bashrc or zshrc or whatever"
echo "export PATH=\"$PREFIX/bin:\$PATH\""

View 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')

View File

@ -1,4 +0,0 @@
TIMEOUT=3
:Limine Barebones
PROTOCOL=limine
KERNEL_PATH=boot:///yukari

30
toolchain.mk Normal file
View 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

View File

@ -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 $@
@ -65,8 +38,4 @@ obj/%.S.o: src/%.S Makefile
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf bin obj
.PHONY: distclean
distclean: clean
rm -f src/include/limine.h
rm -rf bin obj

View File

@ -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();
}