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

257
build/kernel/BUILD.gn Normal file
View File

@@ -0,0 +1,257 @@
import("//build/security/SIGN_TEMPLATE.gni")
kernel_out_path = "base/boot"
kernel_c_flags = [
"-std=gnu11",
"-ffreestanding",
"-Werror",
"-Wno-address-of-packed-member",
"-fpie",
]
kernel_asm_flags = []
kernel_ld_flags = []
if (debug_build) {
kernel_c_flags += [ "-DDEBUG_KERNEL" ]
}
if (kernel_symbols) {
kernel_c_flags += [ "-ggdb" ]
}
if (optimize) {
kernel_c_flags += [ "-Os" ]
if (host == "llvm") {
kernel_c_flags += [ "-flto" ]
if (target_arch == "x86_64") {
kernel_c_flags += [
"-mllvm",
"-code-model=large",
]
}
}
}
if (target_arch == "x86" && kernel_preempt) {
kernel_c_flags += [ "-DPREEMPT_KERNEL" ]
}
if (device_type == "desktop") {
kernel_c_flags += [ "-DTARGET_DESKTOP" ]
}
if (device_type == "mobile") {
kernel_c_flags += [ "-DTARGET_MOBILE" ]
}
if (target_arch == "x86") {
kernel_c_flags += [
"-mno-80387",
"-mno-mmx",
"-mno-sse",
"-mno-sse2",
]
kernel_asm_flags += [
"-w+all",
"-Werror",
"-f",
"elf",
]
kernel_ld_flags += [
"--oformat",
"elf32-i386",
]
}
if (target_arch == "x86_64") {
kernel_c_flags += [
"-mno-80387",
"-mno-mmx",
"-mno-sse",
"-mno-sse2",
"-mno-red-zone",
"-fno-omit-frame-pointer",
"-mcmodel=large",
]
kernel_asm_flags += [
"-w+all",
"-Werror",
"-f",
"elf64",
]
if (host == "llvm") {
kernel_ld_flags += [
"--oformat",
"elf64",
]
}
}
if (target_arch == "arm32") {
kernel_c_flags += [
"-fno-builtin",
"-march=armv7-a",
"-mfpu=neon-vfpv4",
"-mfloat-abi=soft",
]
kernel_asm_flags += [
"-march=armv7-a",
"-mfpu=neon-vfpv4",
"-mfloat-abi=softfp",
"-mcpu=cortex-a15",
]
kernel_ld_flags += [ "-nostdlib" ]
if (host == "gnu") {
kernel_ld_flags += [
"-nostdinc",
"-nodefaultlibs",
"-nostartfiles",
"-lgcc",
]
}
if (host == "llvm") {
kernel_ld_flags += [
"--oformat",
"elf32-littlearm",
rebase_path("//toolchains/llvm_runtime/11.1.0/libclang_rt.builtins-arm.a",
root_build_dir),
]
}
}
if (target_arch == "arm64") {
kernel_c_flags += [
"-fno-builtin",
"-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc",
]
kernel_asm_flags += [ "-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc" ]
kernel_ld_flags += [ "-nostdlib" ]
if (host == "gnu") {
kernel_ld_flags += [
"-nostdinc",
"-nodefaultlibs",
"-nostartfiles",
"-lgcc",
]
}
if (host == "llvm") {
kernel_ld_flags += [
"--oformat",
"elf64-littlearm",
]
}
# Qemu virt is used as a test platform.
if (target_board == "qemu_virt") {
kernel_c_flags += [ "-DTARGET_QEMU_VIRT" ]
kernel_asm_flags += [ "-DTARGET_QEMU_VIRT" ]
}
if (target_board == "apl") {
kernel_c_flags += [ "-DTARGET_APL" ]
kernel_asm_flags += [ "-DTARGET_APL" ]
}
# Enabling KASAN only for GCC builds as LLVM has fixed KASAN shadow bases
# which are incompatible with xOS layout.
if (debug_build && host == "gnu") {
kernel_c_flags += [
"-fsanitize=kernel-address",
"-DKASAN_ENABLED",
]
}
}
if (target_arch == "riscv64") {
kernel_c_flags += [
"-fno-builtin",
"-march=rv64ima",
"-mabi=lp64",
"-mcmodel=medany",
]
kernel_asm_flags += [
"-mcmodel=medany",
"-march=rv64ima",
"-mabi=lp64",
]
kernel_ld_flags += [ "-nostdlib" ]
if (host == "gnu") {
kernel_ld_flags += [
"-nostdinc",
"-nodefaultlibs",
"-nostartfiles",
rebase_path("//toolchains/gcc_runtime/10.2.1/riscv64-libgcc.a",
root_build_dir),
]
}
if (host == "llvm") {
kernel_ld_flags += [
"--oformat",
"elf64",
rebase_path("//toolchains/gcc_runtime/10.2.1/riscv64-libgcc.a",
root_build_dir),
]
}
}
config("kernel_flags") {
cflags = kernel_c_flags
asmflags = kernel_asm_flags
ldflags = kernel_ld_flags
defines = [ "xOS_kernel" ]
}
kernel_src = exec_script("get_kernel_files.py",
[
rebase_path("//src", root_build_dir),
target_arch,
],
"list lines")
linker_script =
rebase_path("//build/kernel/$target_arch/kernel_link.ld", root_build_dir)
action("kernel_config") {
script = "//build/kernel/gen_config.py"
outputs = [ "$root_out_dir/base/boot/kernel.config" ]
args = [
rebase_path("$root_out_dir/base/boot/kernel.config", root_build_dir),
"$target_arch",
"$host",
]
}
executable("kernel_build") {
deps = [ ":kernel_config" ]
output_name = "$kernel_out_path/kernel.bin"
sources = kernel_src
include_dirs = [ "//kernel/include" ]
configs = [ ":kernel_flags" ]
ldflags = [
# See comment at EXEC_TEMPLATE.gni about elfsign_section.o.
# It is required to sign a binary.
rebase_path("$root_out_dir/tmp/elfsign_section.o", ""),
"-T$linker_script",
]
}
xOS_signexec("kernel") {
binpath = "boot/kernel.bin"
}
group("kernel") {
deps = [
":kernel_build",
":sign_kernel",
]
}

View File

@@ -0,0 +1,83 @@
_pa_base = 0x80100000;
_va_base = 0xc0000000;
ENTRY(_va_base)
SECTIONS
{
. = _va_base;
__text_start = .;
.text ALIGN(4K) : AT (ADDR(.text) - _va_base + _pa_base)
{
*(.interrupt_vector_table)
*(.text)
*(.text.*)
}
__text_end = .;
__rodata_start = .;
.rodata ALIGN(4K) : AT (ADDR(.rodata) - _va_base + _pa_base)
{
*(.rodata)
*(.rodata.*)
}
.rodata.driver_init ALIGN(4K) : AT (ADDR(.rodata.driver_init) - _va_base + _pa_base)
{
_drivers_init_start = .;
*(SORT_BY_NAME(.driver_init_sections.*))
_drivers_init_end = .;
}
__rodata_end = .;
__data_start = .;
.data ALIGN(4K) : AT (ADDR(.data) - _va_base + _pa_base)
{
*(.data)
*(.data.*)
}
__data_end = .;
__bss_start = .;
.bss ALIGN(4K) : AT (ADDR(.bss) - _va_base + _pa_base)
{
*(.bss)
*(.bss.*)
*(COMMON)
}
__bss_end = .;
__stack_start = .;
.stack ALIGN(4K) : AT (ADDR(.stack) - _va_base + _pa_base)
{
STACK_SECONDARY_BASE = .;
. += 0x1000;
STACK_SECONDARY_TOP = .;
STACK_BASE = .;
. += 0x1000;
STACK_TOP = .;
STACK_SVC_BASE = .;
. += 0x1000;
STACK_SVC_TOP = .;
STACK_IRQ_BASE = .;
. += 0x1000;
STACK_IRQ_TOP = .;
STACK_ABORT_BASE = .;
. += 0x1000;
STACK_ABORT_TOP = .;
STACK_UNDEFINED_BASE = .;
. += 0x1000;
STACK_UNDEFINED_TOP = .;
}
__stack_end = .;
.ARM.exidx : { *(.ARM.exidx) }
__end = .;
}

View File

@@ -0,0 +1,67 @@
_pa_base = 0x0;
_va_base = 0xffffff8000000000;
ENTRY(_va_base)
SECTIONS
{
. = _va_base;
__text_start = .;
.text ALIGN(4K) : AT (ADDR(.text) - _va_base + _pa_base)
{
*(.xos_kernel_boot)
*(.text)
*(.text.*)
}
__text_end = .;
__rodata_start = .;
.rodata ALIGN(4K) : AT (ADDR(.rodata) - _va_base + _pa_base)
{
*(.rodata)
*(.rodata.*)
}
.rodata.driver_init ALIGN(4K) : AT (ADDR(.rodata.driver_init) - _va_base + _pa_base)
{
_drivers_init_start = .;
*(SORT_BY_NAME(.driver_init_sections.*))
_drivers_init_end = .;
}
__rodata_end = .;
__data_start = .;
.data ALIGN(4K) : AT (ADDR(.data) - _va_base + _pa_base)
{
*(.data)
*(.data.*)
}
__data_end = .;
__bss_start = .;
.bss ALIGN(4K) : AT (ADDR(.bss) - _va_base + _pa_base)
{
*(.bss)
*(.bss.*)
*(COMMON)
}
__bss_end = .;
__stack_start = .;
.stack ALIGN(4K) : AT (ADDR(.stack) - _va_base + _pa_base)
{
STACK_SECONDARY_BASE = .;
. += 0x1000;
STACK_SECONDARY_TOP = .;
STACK_BASE = .;
. += 0x1000;
STACK_TOP = .;
}
__stack_end = .;
.ARM.exidx : { *(.ARM.exidx) }
__end = .;
}

View File

@@ -0,0 +1,61 @@
import os
import glob
import sys
import json
import subprocess
from datetime import datetime
OBJCOPY_TOOL = ""
OBJCOPY_TARGET = ""
def shell(cmd, cwd=None):
return subprocess.check_output(cmd, shell=True, cwd=cwd).decode("ascii")
inpath = sys.argv[1]
outpath = 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 (arch == "arm32"):
if host == "gnu":
OBJCOPY_TOOL = "{0}arm-none-eabi-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf32-littlearm"
elif host == "llvm":
OBJCOPY_TOOL = "{0}llvm-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf32-littlearm"
elif (arch == "arm64"):
if host == "gnu":
OBJCOPY_TOOL = "{0}aarch64-elf-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-littleaarch64"
elif host == "llvm":
OBJCOPY_TOOL = "{0}llvm-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-littleaarch64"
elif (arch == "riscv64"):
if host == "gnu":
OBJCOPY_TOOL = "{0}riscv64-unknown-elf-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-littleriscv"
elif host == "llvm":
OBJCOPY_TOOL = "{0}llvm-objcopy".format(path_to_bins)
OBJCOPY_TARGET = "elf64-littleriscv"
else:
print("Unsupported arch {0}".format(arch))
exit(1)
run_from = os.getcwd() + '/../utils/compilers/DevTreeCompiler'
inpath_abs = os.getcwd() + '/' + inpath
outpath_abs = os.getcwd() + '/' + outpath
obj_outpath_abs = outpath_abs + "o"
shell("python3 . {0} {1}".format(inpath_abs, outpath_abs), run_from)
shell("{0} -I binary -O {1} --rename-section .data=.odt {2} {3}".format(
OBJCOPY_TOOL, OBJCOPY_TARGET, outpath_abs, obj_outpath_abs))

View File

@@ -0,0 +1,42 @@
import os
import glob
import sys
import json
import subprocess
from datetime import datetime
def shell(cmd):
return subprocess.check_output(cmd, shell=True).decode("ascii")
outpath = sys.argv[1]
arch = sys.argv[2]
host = sys.argv[3]
branch = "{0}@{1}".format(shell("git rev-parse --short HEAD")[:-1], shell("git rev-parse --abbrev-ref HEAD")[:-1])
config = {}
config['arch'] = arch
config['host'] = host
config['branch'] = branch
config['time'] = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
# Printing to the file
def print_header(config_file):
config_file.write(
"""#
# Automatically generated file; DO NOT EDIT.
# xOS Kernel Configuration
#
""")
def print_json(config_file, rdict):
json.dump(rdict, config_file, indent = 4)
config_file = open(outpath, "w")
print_header(config_file)
print_json(config_file, config)
config_file.close()

View File

@@ -0,0 +1,77 @@
import os
import glob
import sys
# sys.argv[2] Target to generate for
target = sys.argv[2]
platforms = ['x86', 'i386', 'x86_64', 'arm',
'arm32', 'arm64', 'aarch32', 'aarch64',
'riscv', 'riscv64']
bits = ['bits32', 'bits64']
platform_to_bits = {
"x86": "bits32",
"x86_64": "bits64",
"arm32": "bits32",
"arm64": "bits64",
"riscv64": "bits64",
}
allowed_paths = {
"x86": ["x86", "i386"],
"x86_64": ["x86", "x86_64"],
"arm32": ["aarch32", "arm32", "arm"],
"arm64": ["aarch64", "arm64", "arm"],
"riscv64": ["riscv64", "riscv"]
}
ignore_platforms = []
ignore_bits = []
allowed_paths_for_target = allowed_paths.get(target, None)
if allowed_paths_for_target is None:
print("Unknown platform {0}".format(target))
exit(1)
for platform in platforms:
if not (platform in allowed_paths_for_target):
ignore_platforms.append(platform)
for bit in bits:
if platform_to_bits[target] != bit:
ignore_bits.append(bit)
def is_file_type(name, ending):
if len(name) <= len(ending):
return False
return (name[-len(ending)-1::] == '.'+ending)
def is_file_blocked(name):
global ignore_platforms
for platform in ignore_platforms:
if (name.find(platform) != -1):
return True
for bit in ignore_bits:
if (name.find(bit) != -1):
return True
return False
for path, subdirs, files in os.walk("../kernel/kernel"):
for name in files:
# It runs from out dir, at least it should
file = "//" + path[3:] + "/" + name
if not is_file_type(file, 'c') and not is_file_type(file, 's') and not is_file_type(file, 'S'):
continue
if is_file_blocked(file):
continue
print(file)
def special_paths(platform):
pass
special_paths(target)

View File

@@ -0,0 +1,60 @@
_pa_base = 0x0;
_va_base = 0xffff800000000000;
ENTRY(_va_base)
SECTIONS
{
. = _va_base;
__text_start = .;
.text ALIGN(4K) :
{
*(.xos_kernel_boot)
*(.text)
*(.text.*)
}
__text_end = .;
__rodata_start = .;
.rodata ALIGN(4K) :
{
*(.rodata)
*(.rodata.*)
}
.rodata.driver_init ALIGN(4K) :
{
_drivers_init_start = .;
*(SORT_BY_NAME(.driver_init_sections.*))
_drivers_init_end = .;
}
__rodata_end = .;
__data_start = .;
.data ALIGN(4K) :
{
*(.data)
*(.data.*)
}
__data_end = .;
__bss_start = .;
.bss ALIGN(4K) :
{
*(.bss)
*(.bss.*)
*(COMMON)
}
__bss_end = .;
__stack_start = .;
.stack ALIGN(4K) :
{
STACK_BASE = .;
. += 0x1000;
STACK_TOP = .;
}
__stack_end = .;
__end = .;
}

View File

@@ -0,0 +1,60 @@
_pa_base = 1M;
_va_base = 0xc0000000;
ENTRY(_va_base)
SECTIONS
{
. = _va_base;
__text_start = .;
.text ALIGN(4K) : AT (ADDR(.text) - _va_base + _pa_base)
{
*(.xos_kernel_boot)
*(.text)
*(.text.*)
}
__text_end = .;
__rodata_start = .;
.rodata ALIGN(4K) : AT (ADDR(.rodata) - _va_base + _pa_base)
{
*(.rodata)
*(.rodata.*)
}
.rodata.driver_init ALIGN(4K) : AT (ADDR(.rodata.driver_init) - _va_base + _pa_base)
{
_drivers_init_start = .;
*(SORT_BY_NAME(.driver_init_sections.*))
_drivers_init_end = .;
}
__rodata_end = .;
__data_start = .;
.data ALIGN(4K) : AT (ADDR(.data) - _va_base + _pa_base)
{
*(.data)
*(.data.*)
}
__data_end = .;
__bss_start = .;
.bss ALIGN(4K) : AT (ADDR(.bss) - _va_base + _pa_base)
{
*(.bss)
*(.bss.*)
*(COMMON)
}
__bss_end = .;
__stack_start = .;
.stack ALIGN(4K) : AT (ADDR(.stack) - _va_base + _pa_base)
{
STACK_BASE = .;
. += 0x1000;
STACK_TOP = .;
}
__stack_end = .;
__end = .;
}

View File

@@ -0,0 +1,60 @@
_pa_base = 0x0;
_va_base = 0xffff800000000000;
ENTRY(_va_base)
SECTIONS
{
. = _va_base;
__text_start = .;
.text ALIGN(4K) :
{
*(.xos_kernel_boot)
*(.text)
*(.text.*)
}
__text_end = .;
__rodata_start = .;
.rodata ALIGN(4K) :
{
*(.rodata)
*(.rodata.*)
}
.rodata.driver_init ALIGN(4K) :
{
_drivers_init_start = .;
*(SORT_BY_NAME(.driver_init_sections.*))
_drivers_init_end = .;
}
__rodata_end = .;
__data_start = .;
.data ALIGN(4K) :
{
*(.data)
*(.data.*)
}
__data_end = .;
__bss_start = .;
.bss ALIGN(4K) :
{
*(.bss)
*(.bss.*)
*(COMMON)
}
__bss_end = .;
__stack_start = .;
.stack ALIGN(4K) :
{
STACK_BASE = .;
. += 0x1000;
STACK_TOP = .;
}
__stack_end = .;
__end = .;
}