From 8df1646c6158b53d2a9e64c69185ed616c45a08b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 18 Mar 2022 21:55:38 -0400 Subject: [PATCH] Add initial HULK source and linker script --- Rsconscript | 35 +++++++++++++---------------------- src/hulk/hulk.d | 16 ++++++++++++++++ src/hulk/hulk.ld | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 src/hulk/hulk.d create mode 100644 src/hulk/hulk.ld diff --git a/Rsconscript b/Rsconscript index b3725bf..b686cde 100644 --- a/Rsconscript +++ b/Rsconscript @@ -45,32 +45,10 @@ class FontGen < Builder end end -# FontGen Environment fontgen_env = env "fontgen", use: "freetype" do |env| env.Program("^/fontgen", glob("src/fontgen/**/*.c")) end -## Kernel Environment -#kernel_env = env "kernel" do |env| -# env.add_builder(Image) -# env.add_builder(FontGen) -# env["OBJDUMP"] = "x86_64-elf-objdump" -# env["SIZE"] = "x86_64-elf-size" -# env["CCFLAGS"] += %w[-ffreestanding -Wall -O2] -# env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld] -# env["LDFLAGS"] += %W[-Wl,-Map,${_TARGET}.map] -# env["LIBS"] += %w[gcc] -# env.FontGen("^/kfont/kfont.c", "font/Hack-Regular.ttf", -# "fontgen" => fontgen_env.expand("^/fontgen")) -# env.barrier -# env["CPPPATH"] += ["#{env.build_root}/kfont"] -# env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/kfont/kfont.c"]) -# env.depends("#{env.build_root}/hos.elf", "src/link.ld") -# env.Disassemble("^/hos.elf.txt", "^/hos.elf") -# env.Size("^/hos.elf.size", "^/hos.elf") -# env.Image("^/hos.img", %w[^/hos.elf]) -#end - hello_env = env "hello", use: %w[ldc2 x86_64-w64-mingw32-gcc] do |env| env.add_builder(Image) env["sources"] = glob("src/hello/**/*.d") @@ -86,6 +64,19 @@ hello_env = env "hello", use: %w[ldc2 x86_64-w64-mingw32-gcc] do |env| env.Image("^/hos.img", "^/BOOTX64.EFI") end +hulk_env = env "hulk", use: %w[ldc2 x86_64-elf-gcc] do |env| + env["sources"] = glob("src/hulk/**/*.d") + env["DFLAGS"] += %w[-mtriple=x86_64-unknown-elf --betterC -release -O3 --wi --enable-cross-module-inlining] + env["D_IMPORT_PATH"] += %w[src/hulk src/common] + env["LD"] = "x86_64-elf-gcc" + env["LDFLAGS"] += %w[-nostdlib -Tsrc/hulk/hulk.ld -Wl,-Map,${_TARGET}.map] + env["LDCMD"] = %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}] + env["OBJDUMP"] = "x86_64-elf-objdump" + env.Program("^/hulk.elf", "${sources}") + env.depends("^/hulk.elf", "src/hulk/hulk.ld") + env.Disassemble("^/hulk.txt", "^/hulk.elf") +end + task "run", desc: "Run HOS in QEMU" do Dir.mktmpdir do |tmpdir| img = hello_env.expand("^/hos.img") diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d new file mode 100644 index 0000000..15a34df --- /dev/null +++ b/src/hulk/hulk.d @@ -0,0 +1,16 @@ +import hulk.bootinfo; +import hos.memory; +import ldc.attributes; + +@(ldc.attributes.section(".hulk_start")) +extern(C) void hulk_start(BootInfo * bootinfo) +{ + for (size_t y = 100u; y < 120u; y++) + { + memset32(&bootinfo.fb.buffer[y * bootinfo.fb.stride + 20u], 0xFF8800u, 20u); + } + + for (;;) + { + } +} diff --git a/src/hulk/hulk.ld b/src/hulk/hulk.ld new file mode 100644 index 0000000..672da53 --- /dev/null +++ b/src/hulk/hulk.ld @@ -0,0 +1,33 @@ +ENTRY(hulk_start) + +SECTIONS +{ + . = 0x0000800000000000; + _hulk_mem_start = .; + + .text BLOCK(4K) : ALIGN(4K) + { + *(.hulk_start) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } + + . = ALIGN(4K); + + _hulk_mem_end = .; +}