Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use osdk for the build system #133

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.ko
*.obj
*.elf
.osdk/

# Linker output
*.ilk
Expand Down
19 changes: 10 additions & 9 deletions compile_flags.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
-std=gnu2x
-D__brutal__
-DSYSTEM_BRUTAL
-Wall
-Wextra
-Werror
-Wnewline-eof
-Wignored-attributes
-Wunknown-attributes
-Wimplicit-fallthrough
-Isources/
-Isources/apps
-Isources/srvs
-Isources/utils
-Isources/libs
-Isources/libs/hw
-Isources/libs/stdc-ansi
-Isources/libs/stdc-posix
-Isources/libs/stdc-ext
-Isrc/
-Isrc/apps
-Isrc/srvs
-Isrc/utils
-Isrc/libs
-Isrc/libs/hw
-Isrc/libs/stdc-ansi
-Isrc/libs/stdc-posix
-Isrc/libs/stdc-ext
-Ibin/generated
-Ibin/generated/headers
-Ithirdparty
Expand Down
105 changes: 105 additions & 0 deletions meta/plugins/boot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import os



from osdk.context import loadAllComponents
from osdk import utils, shell, builder
from osdk.cmds import Cmd, append
from osdk.args import Args


def kvmAvailable() -> bool:
if os.path.exists("/dev/kvm") and os.access("/dev/kvm", os.R_OK):
return True
return False



def buildPkgs(binDir: str, debug: bool) -> list[str]:
pkgs = [p.id for p in loadAllComponents() if "src/srvs" in p.dirname()]

for pkg in pkgs:
elf = builder.build(pkg, "brutal-x86_64:debug")
shell.cp(elf, f"{binDir}/{os.path.basename(elf)[:-4]}")



return pkgs


def limineGenConfig(bootDir: str, pkgs: list[str]) -> None:
with open(f"{bootDir}/limine.cfg", "w") as cfg:
cfg.write(
"TIMEOUT=0\n:Munix\nPROTOCOL=limine\nKERNEL_PATH=boot:///boot/kernel.elf\n"
)

for pkg in pkgs:
cfg.write(f"MODULE_PATH=boot:///bin/{pkg}")


def copySysroot(sysrootDir: str, imageDir: str) -> None:
for root, _, files in os.walk(sysrootDir):
for f in files:
shell.mkdir(f"{imageDir}/{os.path.relpath(root, sysrootDir)}")
shell.cp(os.path.join(root, f), f"{imageDir}/{os.path.relpath(root, sysrootDir)}/{f}")

def bootCmd(args: Args) -> None:
debug = "debug" in args.opts
imageDir = shell.mkdir(".osdk/images/efi-x86_64")
efiBootDir = shell.mkdir(f"{imageDir}/EFI/BOOT")
binDir = shell.mkdir(f"{imageDir}/bin")
bootDir = shell.mkdir(f"{imageDir}/boot")

ovmf = shell.wget("https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd")

brutal = builder.build("core", "kernel-x86_64:debug")
loader = builder.build("loader-brutal", "loader-x86_64:debug")


shell.cp(brutal, f"{bootDir}/kernel.elf")
shell.cp(loader, f"{efiBootDir}/BOOTX64.EFI")


copySysroot("./sysroot", f"{imageDir}")
buildPkgs(f"{imageDir}/pkgs", debug)




qemuCmd: list[str] = [
"qemu-system-x86_64",
"-machine",
"q35",
"-no-reboot",
"-no-shutdown",
# "-d", "guest_errors,cpu_reset,int",
# "-S", "-s",
"-serial",
"mon:stdio",
"-bios",
ovmf,
"-m",
"4G",
"-smp",
"4",
"-drive",
f"file=fat:rw:{imageDir},media=disk,format=raw",
]

if kvmAvailable():
qemuCmd += ["-enable-kvm"]
else:
print("KVM not available, using QEMU-TCG")

shell.exec(*qemuCmd)

def protocolBuild(args: Args) -> None:
elf = builder.build("idgen", "host-x86_64:debug")

pkgs = loadAllComponents()
for pkg in pkgs:
if "" in pkg.dirname():
shell.exec(elf, pkg.id, f"{pkg.dirname()}/protocol.h")

append(Cmd("p", "protocols", "Build protocols headers", buildPkgs))
append(Cmd("s", "start", "Boot the system", bootCmd))
82 changes: 82 additions & 0 deletions meta/targets/brutal-x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"id": "brutal-x86_64",
"type": "target",
"props": {
"toolchain": "clang",
"arch": "x86_64",
"bits": "64",
"sys": "brutal",
"abi": "sysv",
"loader": "brutal-loader",
"encoding": "utf8",
"freestanding": false,
"host": false
},
"tools": {
"cc": {
"cmd": [
"@latest",
"clang"
],
"args": [
"-target",
"x86_64-none-elf",
"-D__brutal__",
"-ffreestanding",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-sse",
"-mno-sse2"
]
},
"cxx": {
"cmd": [
"@latest",
"clang++"
],
"args": [
"-target",
"x86_64-none-elf",
"-D__brutal__",
"-ffreestanding",
"-mno-80387",
"-mno-mmx",
"-mno-3dnow",
"-mno-sse",
"-mno-sse2"
]
},
"ld": {
"cmd": [
"@latest",
"ld.lld"
],
"args": [
"-m",
"elf_x86_64",
"-Tmeta/targets/brutal-x86_64.ld",
"-z",
"max-page-size=0x1000"
],
"files": [
"meta/targets/brutal-x86_64.ld"
]
},
"ar": {
"cmd": [
"@latest",
"llvm-ar"
],
"args": [
"rcs"
]
},
"as": {
"cmd": "nasm",
"args": [
"-f elf64"
]
}
}
}
File renamed without changes.
64 changes: 64 additions & 0 deletions meta/targets/host-x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"id": "host-x86_64",
"type": "target",
"props": {
"toolchain": "clang",
"arch": "x86_64",
"bits": "64",
"sys": [
"@uname",
"sysname"
],
"abi": "sysv",
"encoding": "utf8",
"freestanding": false,
"host": true
},
"tools": {
"cc": {
"cmd": [
"@latest",
"clang"
],
"args": [
"-std=gnu2x",
"-D__linux__"
]
},
"cxx": {
"cmd": [
"@latest",
"clang++"
],
"args": [
"-std=gnu2x",
"-D__linux__"
]
},
"ld": {
"cmd": [
"@latest",
"clang"
],
"args": [
],
"files": [
]
},
"ar": {
"cmd": [
"@latest",
"llvm-ar"
],
"args": [
"rcs"
]
},
"as": {
"cmd": "nasm",
"args": [
"-f elf64"
]
}
}
}
27 changes: 27 additions & 0 deletions meta/targets/host-x86_64.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ENTRY(_start)

SECTIONS
{
. = 4M;

.text : ALIGN(4K)
{
*(.text)
}

.rodata : ALIGN(4K)
{
*(.rodata)
}

.data : ALIGN(4K)
{
*(.data)
}

.bss : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
Loading