diff options
| author | Chloe M. <chloe@aptel.org> | 2026-08-20 05:53:55 +0000 |
|---|---|---|
| committer | Chloe M. <chloe@aptel.org> | 2026-08-20 05:56:44 +0000 |
| commit | ae526fa3375b708d4380d0227e27d32e06b40b92 (patch) | |
| tree | 3d8d9a448d4a9530aa4e45a75b292c1bd0b5bc0d | |
initial commit
Signed-off-by: Chloe M. <chloe@aptel.org>
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | AUTHORS | 3 | ||||
| -rw-r--r-- | LICENSE | 29 | ||||
| -rw-r--r-- | boot/Makefile | 6 | ||||
| -rw-r--r-- | boot/arch/amd64/Makefile | 6 | ||||
| -rw-r--r-- | boot/arch/amd64/mbr/Makefile | 16 | ||||
| -rw-r--r-- | boot/arch/amd64/mbr/link.ld | 21 | ||||
| -rw-r--r-- | boot/arch/amd64/mbr/mbr.S | 17 | ||||
| -rwxr-xr-x | build.sh | 41 | ||||
| -rw-r--r-- | dev/build.env | 10 | ||||
| -rw-r--r-- | dev/config.env | 2 |
11 files changed, 155 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d03a640 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/artifacts +*.o +*.d +*.bin @@ -0,0 +1,3 @@ +# Project authors + +Chloe M., <chloe@aptel.org> @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2026, the respective contributors, as shown by the AUTHORS file. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/boot/Makefile b/boot/Makefile new file mode 100644 index 0000000..8b744d3 --- /dev/null +++ b/boot/Makefile @@ -0,0 +1,6 @@ +.PHONY: all +all: machine + +.PHONY: machine +machine: + cd arch/$(CONFIG_TARGET_ARCH)/; $(MAKE) diff --git a/boot/arch/amd64/Makefile b/boot/arch/amd64/Makefile new file mode 100644 index 0000000..e92fecb --- /dev/null +++ b/boot/arch/amd64/Makefile @@ -0,0 +1,6 @@ +.PHONY: all +all: mbr + +.PHONY: mbr +mbr: + cd mbr/; $(MAKE) diff --git a/boot/arch/amd64/mbr/Makefile b/boot/arch/amd64/mbr/Makefile new file mode 100644 index 0000000..f41e5cc --- /dev/null +++ b/boot/arch/amd64/mbr/Makefile @@ -0,0 +1,16 @@ +CC = clang +CFLAGS = \ + -ffreestanding \ + -nostdlib \ + -nostdinc \ + -mno-red-zone \ + -mno-sse \ + -mno-sse2 \ + -target i386-unknown-elf + +.PHONY: all +all: mbr + +.PHONY: mbr +mbr: + clang -Tlink.ld $(CFLAGS) mbr.S -o $(GLOBAL_PROJECT_ROOT)/artifacts/mbr.bin diff --git a/boot/arch/amd64/mbr/link.ld b/boot/arch/amd64/mbr/link.ld new file mode 100644 index 0000000..6d25985 --- /dev/null +++ b/boot/arch/amd64/mbr/link.ld @@ -0,0 +1,21 @@ +OUTPUT_FORMAT(binary) + +SECTIONS { + . = 0x7C00; + + .text : { + *(.text) + } + + .data : { + *(.data) + } + + .rodata : { + *(.rodata) + } + + .bss : { + *(.bss) + } +} diff --git a/boot/arch/amd64/mbr/mbr.S b/boot/arch/amd64/mbr/mbr.S new file mode 100644 index 0000000..e071a41 --- /dev/null +++ b/boot/arch/amd64/mbr/mbr.S @@ -0,0 +1,17 @@ + .code16 +_start: + /* Normalize CS + other selectors */ + ljmp $0x00,$1f +1: xor %ax, %ax + mov %ax, %ds + mov %ax, %ss + mov %ax, %es + mov %ax, %gs + mov %ax, %fs +2: cli + hlt + jmp 2b + + .org 510 + .byte 0x55 + .byte 0xAA diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..938564f --- /dev/null +++ b/build.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +MAKE=make + +# +# Ensure that the build environment is sane +# +build_check() { + if [ -z "${GLOBAL_BUILD_SOURCED}" ] + then + echo "fatal: Please run '. dev/build.env'" + exit 1 + fi +} + +# +# Build a directory +# +# $1: Directory to build +# $2: Subsystem name +# +build_dir() { + pushd $1 + echo "[*] Building $2..." + $MAKE + popd +} + +# +# Kick off the entire build proccess +# +build() { + mkdir -p artifacts/ + + build_dir \ + boot \ + "bootloader" +} + +build_check +build diff --git a/dev/build.env b/dev/build.env new file mode 100644 index 0000000..11ac46d --- /dev/null +++ b/dev/build.env @@ -0,0 +1,10 @@ +. dev/config.env + +export GLOBAL_PROJECT_ROOT=$GLOBAL_PROJECT_ROOT +export CONFIG_TARGET_ARCH=$CONFIG_TARGET_ARCH + +if [ -z "${GLOBAL_BUILD_SOURCED}"] +then + echo "[*] Build environment ready" + export GLOBAL_BUILD_SOURCED=1 +fi diff --git a/dev/config.env b/dev/config.env new file mode 100644 index 0000000..67dc5fb --- /dev/null +++ b/dev/config.env @@ -0,0 +1,2 @@ +GLOBAL_PROJECT_ROOT=$PWD +CONFIG_TARGET_ARCH=amd64 |
