Squash commits for public release

This commit is contained in:
2025-02-12 09:54:05 -05:00
commit 7118adc514
1108 changed files with 80873 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
group("bootx86_64") {
deps = [
"rawImage:rawImage",
]
}

View File

@@ -0,0 +1,92 @@
prekernel_c_flags = [
"-ffreestanding",
"-Werror",
"-Wno-address-of-packed-member",
"-fno-builtin",
"-mno-80387",
"-mno-mmx",
"-mno-sse",
"-mno-sse2",
"-fpie",
"-mno-red-zone",
"-fno-omit-frame-pointer",
]
prekernel_asm_flags = [
"-w+all",
"-Werror",
"-f",
"elf64",
]
prekernel_ld_flags = [ "-nostdlib" ]
if (kernel_symbols) {
prekernel_c_flags += [ "-ggdb" ]
}
if (host == "llvm") {
prekernel_ld_flags += [
"--oformat",
"elf64",
]
}
config("prekernel_flags") {
cflags = prekernel_c_flags
asmflags = prekernel_asm_flags
ldflags = prekernel_ld_flags
defines = [ "xOS_prekernel" ]
}
linker_script =
rebase_path("//build/boot/$target_arch/prekernel/prekernel_link.ld",
root_build_dir)
# Use a strange __EMPTY_PATH_, empty string can't be passed as an arg.
path_to_bins = "__EMPTY_PATH_"
if (host == "llvm") {
path_to_bins = llvm_bin_path
}
embed_kernel_script_args = [
rebase_path("$root_build_dir/base/boot/kernel.bin", root_build_dir),
rebase_path("$root_build_dir/tmp/boot/kernel.o", root_build_dir),
"$target_arch",
"$target_board",
"$host",
"$path_to_bins",
]
action("embed_kernel") {
script = "embed_kernel.py"
sources = [ "$root_build_dir/base/boot/kernel.bin" ]
outputs = [ "$root_build_dir/tmp/boot/kernel.o" ]
args = embed_kernel_script_args
deps = [ "//build/kernel:kernel_build" ]
}
executable("prekernelx86_64") {
output_name = "prekernelx86_64.bin"
inputs = [ "$root_build_dir/tmp/boot/kernel.o" ]
sources = [
"//boot/libboot/elf/elf_lite.c",
"//boot/libboot/log/log.c",
"//boot/libboot/mem/alloc.c",
"//boot/libboot/mem/mem.c",
"//boot/x86_64/prekernel/drivers/uart.c",
"//boot/x86_64/prekernel/main.c",
"//boot/x86_64/prekernel/mboot1.S",
"//boot/x86_64/prekernel/vm.c",
]
deps = [ ":embed_kernel" ]
include_dirs = [ "//boot" ]
configs = [ ":prekernel_flags" ]
ldflags = [
# Embeding kernel elf file into rawimage.
rebase_path("$root_out_dir/tmp/boot/kernel.o", ""),
"-T$linker_script",
]
}

View File

@@ -0,0 +1,30 @@
import sys
import os
import subprocess
prekernel_path = sys.argv[1]
out_path = sys.argv[2]
arch = sys.argv[3]
board = sys.argv[4]
host = sys.argv[5]
path_to_bins = sys.argv[6]
if path_to_bins == "__EMPTY_PATH_":
path_to_bins = ""
if len(path_to_bins) != 0:
if path_to_bins[-1] != '/':
path_to_bins += "/"
if host == "gnu":
OBJCOPY_TOOL = "{0}x86_64-elf-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-x86-64"
elif host == "llvm":
OBJCOPY_TOOL = "{0}llvm-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-x86-64"
else:
print("Unsupported host {0}".format(host))
exit(0)
cmd = "{0} -I binary -O {1} --rename-section .data=.kernelelf {2} {3}".format(
OBJCOPY_TOOL, OBJCOPY_TARGET, prekernel_path, out_path)
output = subprocess.check_output(cmd, shell=True)

View File

@@ -0,0 +1,59 @@
/* PIC */
_pa_base = 1M;
/* ENTRY(_pa_base) */
SECTIONS
{
. = _pa_base;
PREKERNEL_START = .;
.multiboot :
{
*(.multiboot)
}
.text :
{
*(.xos_boot_text)
*(.text)
*(.text.*)
}
.rodata :
{
*(.rodata)
*(.rodata.*)
}
.data :
{
*(.data)
*(.data.*)
}
.bss :
{
*(.bss)
*(.bss.*)
*(COMMON)
}
.stack ALIGN(4K) :
{
PREKERNEL_STACK_BASE = .;
. += 0x1000;
PREKERNEL_STACK_TOP = .;
}
PREKERNEL_END = .;
.kernelelf ALIGN(4K) :
{
EMBED_KERNEL_START = .;
*(.kernelelf)
EMBED_KERNEL_END = .;
}
RAWIMAGE_END = .;
}

View File

@@ -0,0 +1,23 @@
if (target_arch == "x86_64") {
path_to_bins = "__EMPTY_PATH_"
if (host == "llvm") {
path_to_bins = llvm_bin_path
}
make_raw_image_script_args = [
rebase_path("$root_build_dir/prekernelx86_64.bin", root_build_dir),
rebase_path("$root_build_dir/rawImage.elf", root_build_dir),
"$target_arch",
"$target_board",
"$host",
"$path_to_bins",
]
action("rawImage") {
script = "make_raw_image.py"
sources = [ "$root_build_dir/prekernelx86_64.bin" ]
outputs = [ "$root_build_dir/rawImage.elf" ]
args = make_raw_image_script_args
deps = [ "//build/boot/x86_64/prekernel:prekernelx86_64" ]
}
}

View File

@@ -0,0 +1,30 @@
import sys
import os
import subprocess
prekernel_path = sys.argv[1]
out_path = sys.argv[2]
arch = sys.argv[3]
board = sys.argv[4]
host = sys.argv[5]
path_to_bins = sys.argv[6]
if path_to_bins == "__EMPTY_PATH_":
path_to_bins = ""
if len(path_to_bins) != 0:
if path_to_bins[-1] != '/':
path_to_bins += "/"
if host == "gnu":
OBJCOPY_TOOL = "{0}x86_64-elf-objcopy".format(path_to_bins)
elif host == "llvm":
OBJCOPY_TOOL = "{0}llvm-objcopy".format(path_to_bins)
else:
print("Unsupported host {0}".format(host))
exit(0)
# rawImage for x86 is a multiboot-capable elf file. Since qemu does not
# implement support for multiboot2 specs, which could load elf64, we have
# to change the type of the elf file to elf32-i686.
output = subprocess.check_output(
"{0} -O elf32-i386 {1} {2}".format(OBJCOPY_TOOL, prekernel_path, out_path), shell=True)