Squash commits for public release
This commit is contained in:
13
build/boot/BUILD.gn
Normal file
13
build/boot/BUILD.gn
Normal file
@@ -0,0 +1,13 @@
|
||||
group("boot") {
|
||||
if (target_arch == "x86") {
|
||||
deps = [ "x86:bootx86" ]
|
||||
} else if (target_arch == "x86_64") {
|
||||
deps = [ "x86_64:bootx86_64" ]
|
||||
} else if (target_arch == "arm32") {
|
||||
deps = [ "arm32:bootarm" ]
|
||||
} else if (target_arch == "arm64") {
|
||||
deps = [ "arm64:bootarm64" ]
|
||||
} else if (target_arch == "riscv64") {
|
||||
deps = [ "riscv64:bootriscv64" ]
|
||||
}
|
||||
}
|
||||
111
build/boot/arm32/BUILD.gn
Normal file
111
build/boot/arm32/BUILD.gn
Normal file
@@ -0,0 +1,111 @@
|
||||
boot_c_flags = [
|
||||
"-ffreestanding",
|
||||
"-Werror",
|
||||
"-Wno-address-of-packed-member",
|
||||
]
|
||||
boot_asm_flags = []
|
||||
boot_ld_flags = []
|
||||
|
||||
if (kernel_symbols) {
|
||||
boot_c_flags += [ "-ggdb" ]
|
||||
}
|
||||
|
||||
boot_c_flags += [
|
||||
"-fno-builtin",
|
||||
"-march=armv7-a",
|
||||
"-mfpu=neon-vfpv4",
|
||||
"-mfloat-abi=soft",
|
||||
"-fno-pie",
|
||||
]
|
||||
boot_asm_flags += [
|
||||
"-march=armv7-a",
|
||||
"-mfpu=neon-vfpv4",
|
||||
"-mfloat-abi=softfp",
|
||||
"-mcpu=cortex-a15",
|
||||
]
|
||||
boot_ld_flags += [ "-nostdlib" ]
|
||||
|
||||
if (host == "gnu") {
|
||||
boot_ld_flags += [
|
||||
"-nostdinc",
|
||||
"-nodefaultlibs",
|
||||
"-nostartfiles",
|
||||
"-lgcc",
|
||||
]
|
||||
}
|
||||
|
||||
if (host == "llvm") {
|
||||
boot_ld_flags += [
|
||||
"--oformat",
|
||||
"elf32-littlearm",
|
||||
"/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.builtins-arm.a",
|
||||
]
|
||||
}
|
||||
|
||||
config("boot_flags") {
|
||||
cflags = boot_c_flags
|
||||
asmflags = boot_asm_flags
|
||||
ldflags = boot_ld_flags
|
||||
defines = [ "xOS_kernel" ]
|
||||
}
|
||||
|
||||
linker_script =
|
||||
rebase_path("//build/boot/$target_arch/boot_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
|
||||
}
|
||||
|
||||
devtree_compile_script_args = [
|
||||
rebase_path("//firmware/$target_arch/$target_board.odt", root_build_dir),
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
|
||||
"$target_arch",
|
||||
"$target_board",
|
||||
"$host",
|
||||
"$path_to_bins",
|
||||
]
|
||||
|
||||
action("devtree_compile") {
|
||||
script = "//build/kernel/devtree_compile.py"
|
||||
inputs = [ "//firmware/$target_arch/$target_board.odt" ]
|
||||
outputs = [
|
||||
"$root_out_dir/firmware/$target_board.obt",
|
||||
"$root_out_dir/firmware/$target_board.obto",
|
||||
]
|
||||
args = devtree_compile_script_args
|
||||
}
|
||||
|
||||
executable("bootarm") {
|
||||
deps = [ ":devtree_compile" ]
|
||||
output_name = "bootarm.bin"
|
||||
sources = [
|
||||
"//boot/arm32/drivers/pl181.c",
|
||||
"//boot/arm32/drivers/uart.c",
|
||||
"//boot/arm32/entry.s",
|
||||
"//boot/arm32/hw/ram.c",
|
||||
"//boot/arm32/main.c",
|
||||
"//boot/arm32/start_kernel.s",
|
||||
"//boot/arm32/vmm/vmm.c",
|
||||
"//boot/libboot/crypto/sha256.c",
|
||||
"//boot/libboot/crypto/signature.c",
|
||||
"//boot/libboot/crypto/uint2048.c",
|
||||
"//boot/libboot/crypto/validate.c",
|
||||
"//boot/libboot/devtree/devtree.c",
|
||||
"//boot/libboot/elf/elf_lite.c",
|
||||
"//boot/libboot/fs/ext2_lite.c",
|
||||
"//boot/libboot/log/log.c",
|
||||
"//boot/libboot/mem/alloc.c",
|
||||
"//boot/libboot/mem/mem.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "//boot" ]
|
||||
|
||||
configs = [ ":boot_flags" ]
|
||||
|
||||
ldflags = [
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obto", root_build_dir),
|
||||
"-T$linker_script",
|
||||
]
|
||||
}
|
||||
55
build/boot/arm32/boot_link.ld
Normal file
55
build/boot/arm32/boot_link.ld
Normal file
@@ -0,0 +1,55 @@
|
||||
_pa_base = 0x80010000;
|
||||
|
||||
ENTRY(_pa_base)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _pa_base;
|
||||
bootloader_start = .;
|
||||
|
||||
.text ALIGN(4K) :
|
||||
{
|
||||
*(.xos_boot_text)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
}
|
||||
|
||||
.rodata ALIGN(4K) :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
|
||||
.rodata.odt ALIGN(4K) :
|
||||
{
|
||||
_odt_phys = .;
|
||||
*(.odt)
|
||||
_odt_phys_end = .;
|
||||
}
|
||||
|
||||
.data ALIGN(4K) :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
|
||||
.bss ALIGN(4K) :
|
||||
{
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
.stack ALIGN(4K) :
|
||||
{
|
||||
STACK_SECONDARY_PHYZ_BASE = .;
|
||||
. += 0x1000;
|
||||
STACK_SECONDARY_PHYZ_TOP = .;
|
||||
|
||||
STACK_PHYZ_BASE = .;
|
||||
. += 0x1000;
|
||||
STACK_PHYZ_TOP = .;
|
||||
}
|
||||
|
||||
.ARM.exidx : { *(.ARM.exidx) }
|
||||
}
|
||||
31
build/boot/arm64/BUILD.gn
Normal file
31
build/boot/arm64/BUILD.gn
Normal file
@@ -0,0 +1,31 @@
|
||||
# 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
|
||||
}
|
||||
|
||||
devtree_compile_script_args = [
|
||||
rebase_path("//firmware/$target_arch/$target_board.odt", root_build_dir),
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
|
||||
"$target_arch",
|
||||
"$target_board",
|
||||
"$host",
|
||||
"$path_to_bins",
|
||||
]
|
||||
|
||||
action("devtree_compile") {
|
||||
script = "//build/kernel/devtree_compile.py"
|
||||
inputs = [ "//firmware/$target_arch/$target_board.odt" ]
|
||||
outputs = [
|
||||
"$root_out_dir/firmware/$target_board.obt",
|
||||
"$root_out_dir/firmware/$target_board.obto",
|
||||
]
|
||||
args = devtree_compile_script_args
|
||||
}
|
||||
|
||||
group("bootarm64") {
|
||||
deps = [
|
||||
":devtree_compile",
|
||||
"rawImage:rawImage",
|
||||
]
|
||||
}
|
||||
63
build/boot/arm64/prekernel/BUILD.gn
Normal file
63
build/boot/arm64/prekernel/BUILD.gn
Normal file
@@ -0,0 +1,63 @@
|
||||
prekernel_c_flags = [
|
||||
"-ffreestanding",
|
||||
"-Werror",
|
||||
"-Wno-address-of-packed-member",
|
||||
"-fno-builtin",
|
||||
"-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc",
|
||||
"-fpie",
|
||||
]
|
||||
prekernel_asm_flags = [ "-mcpu=cortex-a53+nofp+nosimd+nocrypto+nocrc" ]
|
||||
prekernel_ld_flags = [ "-nostdlib" ]
|
||||
|
||||
if (kernel_symbols) {
|
||||
prekernel_c_flags += [ "-ggdb" ]
|
||||
}
|
||||
|
||||
if (host == "gnu") {
|
||||
prekernel_ld_flags += [
|
||||
"-nostdinc",
|
||||
"-nodefaultlibs",
|
||||
"-nostartfiles",
|
||||
"-lgcc",
|
||||
]
|
||||
}
|
||||
|
||||
if (host == "llvm") {
|
||||
prekernel_ld_flags += [
|
||||
"--oformat",
|
||||
"binary",
|
||||
]
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
executable("prekernelarm64") {
|
||||
output_name = "prekernelarm64.bin"
|
||||
sources = [
|
||||
"//boot/arm64/prekernel/drivers/fb.c",
|
||||
"//boot/arm64/prekernel/drivers/uart.c",
|
||||
"//boot/arm64/prekernel/entry.S",
|
||||
"//boot/arm64/prekernel/main.c",
|
||||
"//boot/arm64/prekernel/vm.c",
|
||||
"//boot/libboot/devtree/devtree.c",
|
||||
"//boot/libboot/elf/elf_lite.c",
|
||||
"//boot/libboot/log/log.c",
|
||||
"//boot/libboot/mem/alloc.c",
|
||||
"//boot/libboot/mem/mem.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "//boot" ]
|
||||
|
||||
configs = [ ":prekernel_flags" ]
|
||||
|
||||
ldflags = [ "-T$linker_script" ]
|
||||
}
|
||||
45
build/boot/arm64/prekernel/prekernel_link.ld
Normal file
45
build/boot/arm64/prekernel/prekernel_link.ld
Normal file
@@ -0,0 +1,45 @@
|
||||
/* PIC */
|
||||
_pa_base = 0x0;
|
||||
|
||||
ENTRY(_pa_base)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _pa_base;
|
||||
PREKERNEL_START_OFFSET = .;
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.xos_boot_text)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
}
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
.stack ALIGN(4K) :
|
||||
{
|
||||
PREKERNEL_STACK_BASE_OFFSET = .;
|
||||
. += 0x1000;
|
||||
PREKERNEL_STACK_TOP_OFFSET = .;
|
||||
}
|
||||
|
||||
PREKERNEL_END_OFFSET = .;
|
||||
}
|
||||
22
build/boot/arm64/rawImage/BUILD.gn
Normal file
22
build/boot/arm64/rawImage/BUILD.gn
Normal file
@@ -0,0 +1,22 @@
|
||||
if (target_arch == "arm64") {
|
||||
action("rawImage") {
|
||||
script = "make_raw_image.py"
|
||||
sources = [
|
||||
"$root_build_dir/base/boot/kernel.bin",
|
||||
"$root_build_dir/prekernelarm64.bin",
|
||||
]
|
||||
outputs = [ "$root_build_dir/rawImage.bin" ]
|
||||
args = [
|
||||
rebase_path("$root_build_dir/prekernelarm64.bin", root_build_dir),
|
||||
rebase_path("$root_build_dir/base/boot/kernel.bin", root_build_dir),
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
|
||||
rebase_path("$root_build_dir/rawImage.bin", root_build_dir),
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//build/boot/arm64:devtree_compile",
|
||||
"//build/boot/arm64/prekernel:prekernelarm64",
|
||||
"//build/kernel:kernel_build",
|
||||
]
|
||||
}
|
||||
}
|
||||
77
build/boot/arm64/rawImage/make_raw_image.py
Normal file
77
build/boot/arm64/rawImage/make_raw_image.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
from construct import *
|
||||
from elftools.elf.elffile import ELFFile
|
||||
from elftools.elf.constants import SH_FLAGS
|
||||
|
||||
prekernel_path = sys.argv[1]
|
||||
kernel_path = sys.argv[2]
|
||||
devtree_path = sys.argv[3]
|
||||
out_path = sys.argv[4]
|
||||
build_dir_path = os.path.dirname(os.path.abspath(sys.argv[4]))
|
||||
tmp_dir_path = build_dir_path + "/tmp"
|
||||
rawimage_header_path = tmp_dir_path + "/rawimage_header.bin"
|
||||
|
||||
# GNU-LD can't convert ELF object format to Binary on the fly.
|
||||
# Checking if output is an ELF and convertining it to binary.
|
||||
prekernel_header = []
|
||||
with open(prekernel_path, "rb") as f:
|
||||
prekernel_header = f.read(4)
|
||||
|
||||
if prekernel_header == b'\x7fELF':
|
||||
kernel_vaddr = 0
|
||||
kernel_vaddr_end = 0
|
||||
|
||||
with open(prekernel_path, 'rb') as elffile:
|
||||
signature_section = None
|
||||
for section in ELFFile(elffile).iter_sections():
|
||||
if (section['sh_flags'] & SH_FLAGS.SHF_ALLOC) == SH_FLAGS.SHF_ALLOC:
|
||||
kernel_vaddr_end = max(
|
||||
kernel_vaddr_end, section['sh_addr'] + section['sh_size'])
|
||||
|
||||
output = subprocess.check_output(
|
||||
"aarch64-elf-objcopy -O binary {0} {0}".format(prekernel_path), shell=True)
|
||||
binary_blob_size = os.path.getsize(prekernel_path)
|
||||
assert(binary_blob_size <= kernel_vaddr_end)
|
||||
|
||||
need_to_append = kernel_vaddr_end - binary_blob_size
|
||||
with open(prekernel_path, 'r+b') as file:
|
||||
_ = file.read()
|
||||
padding = [0x0 for _ in range(need_to_append)]
|
||||
file.write(bytearray(padding))
|
||||
|
||||
|
||||
prekernel_size = os.path.getsize(prekernel_path)
|
||||
rawimage_header_size = 8 * 8
|
||||
kernel_size = os.path.getsize(kernel_path)
|
||||
devtree_size = os.path.getsize(devtree_path)
|
||||
ramdisk_size = 0
|
||||
|
||||
result = {
|
||||
"kern_off": rawimage_header_size + prekernel_size,
|
||||
"kern_size": kernel_size,
|
||||
"devtree_off": rawimage_header_size + prekernel_size + kernel_size,
|
||||
"devtree_size": devtree_size,
|
||||
"ramdisk_off": 0,
|
||||
"ramdisk_size": 0,
|
||||
"rawimage_size": rawimage_header_size + prekernel_size + kernel_size + devtree_size + ramdisk_size,
|
||||
"padding": 0,
|
||||
}
|
||||
|
||||
rawimage_header = Struct(
|
||||
"kern_off" / Int64ul,
|
||||
"kern_size" / Int64ul,
|
||||
"devtree_off" / Int64ul,
|
||||
"devtree_size" / Int64ul,
|
||||
"ramdisk_off" / Int64ul,
|
||||
"ramdisk_size" / Int64ul,
|
||||
"rawimage_size" / Int64ul,
|
||||
"padding" / Int64ul,
|
||||
).build(result)
|
||||
|
||||
with open(rawimage_header_path, "wb") as binfile:
|
||||
binfile.write(bytes(rawimage_header))
|
||||
|
||||
output = subprocess.check_output("cat {0} {1} {2} {3} > {4}".format(
|
||||
prekernel_path, rawimage_header_path, kernel_path, devtree_path, out_path), shell=True)
|
||||
5
build/boot/riscv64/BUILD.gn
Normal file
5
build/boot/riscv64/BUILD.gn
Normal file
@@ -0,0 +1,5 @@
|
||||
group("bootriscv64") {
|
||||
deps = [
|
||||
"prekernel:prekernelriscv64",
|
||||
]
|
||||
}
|
||||
125
build/boot/riscv64/prekernel/BUILD.gn
Normal file
125
build/boot/riscv64/prekernel/BUILD.gn
Normal file
@@ -0,0 +1,125 @@
|
||||
prekernel_c_flags = [
|
||||
"-ffreestanding",
|
||||
"-Werror",
|
||||
"-Wno-address-of-packed-member",
|
||||
"-fno-builtin",
|
||||
"-march=rv64ima",
|
||||
"-mabi=lp64",
|
||||
"-fpie",
|
||||
"-mcmodel=medany",
|
||||
]
|
||||
prekernel_asm_flags = [
|
||||
"-mcmodel=medany",
|
||||
"-march=rv64ima",
|
||||
"-mabi=lp64",
|
||||
]
|
||||
prekernel_ld_flags = [ "-nostdlib" ]
|
||||
|
||||
if (kernel_symbols) {
|
||||
prekernel_c_flags += [ "-ggdb" ]
|
||||
}
|
||||
|
||||
if (host == "gnu") {
|
||||
prekernel_ld_flags += [
|
||||
# "-mno-relax",
|
||||
"-nostdinc",
|
||||
"-nodefaultlibs",
|
||||
"-nostartfiles",
|
||||
"-lgcc",
|
||||
]
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
devtree_compile_script_args = [
|
||||
rebase_path("//firmware/$target_arch/$target_board.odt", root_build_dir),
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obt", root_build_dir),
|
||||
"$target_arch",
|
||||
"$target_board",
|
||||
"$host",
|
||||
"$path_to_bins",
|
||||
]
|
||||
|
||||
action("devtree_compile") {
|
||||
script = "//build/kernel/devtree_compile.py"
|
||||
inputs = [ "//firmware/$target_arch/$target_board.odt" ]
|
||||
outputs = [
|
||||
"$root_out_dir/firmware/$target_board.obt",
|
||||
"$root_out_dir/firmware/$target_board.obto",
|
||||
]
|
||||
args = devtree_compile_script_args
|
||||
}
|
||||
|
||||
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("prekernelriscv64") {
|
||||
output_name = "prekernelriscv64.bin"
|
||||
sources = [
|
||||
"//boot/libboot/devtree/devtree.c",
|
||||
"//boot/libboot/elf/elf_lite.c",
|
||||
"//boot/libboot/log/log.c",
|
||||
"//boot/libboot/mem/alloc.c",
|
||||
"//boot/libboot/mem/mem.c",
|
||||
"//boot/riscv64/prekernel/drivers/uart.c",
|
||||
"//boot/riscv64/prekernel/entry.S",
|
||||
"//boot/riscv64/prekernel/main.c",
|
||||
"//boot/riscv64/prekernel/vm.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "//boot" ]
|
||||
|
||||
inputs = [
|
||||
"$root_out_dir/firmware/$target_board.obto",
|
||||
"$root_out_dir/tmp/boot/kernel.o",
|
||||
]
|
||||
deps = [
|
||||
":devtree_compile",
|
||||
":embed_kernel",
|
||||
]
|
||||
|
||||
configs = [ ":prekernel_flags" ]
|
||||
|
||||
ldflags = [
|
||||
# Embeding kernel elf file into rawimage.
|
||||
rebase_path("$root_out_dir/firmware/$target_board.obto", ""),
|
||||
rebase_path("$root_out_dir/tmp/boot/kernel.o", ""),
|
||||
"-T$linker_script",
|
||||
]
|
||||
}
|
||||
30
build/boot/riscv64/prekernel/embed_kernel.py
Normal file
30
build/boot/riscv64/prekernel/embed_kernel.py
Normal 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}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 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)
|
||||
72
build/boot/riscv64/prekernel/prekernel_link.ld
Normal file
72
build/boot/riscv64/prekernel/prekernel_link.ld
Normal file
@@ -0,0 +1,72 @@
|
||||
_pa_base = 0x80000000;
|
||||
|
||||
ENTRY(_pa_base)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _pa_base;
|
||||
PREKERNEL_START_OFFSET = .;
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.xos_boot_text)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
}
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
.rela.text :
|
||||
{
|
||||
*(.rela.text)
|
||||
}
|
||||
|
||||
.rela.bss :
|
||||
{
|
||||
*(.rela.bss)
|
||||
}
|
||||
|
||||
.stack ALIGN(4K) :
|
||||
{
|
||||
PREKERNEL_STACK_BASE_OFFSET = .;
|
||||
. += 0x1000;
|
||||
PREKERNEL_STACK_TOP_OFFSET = .;
|
||||
}
|
||||
|
||||
PREKERNEL_END_OFFSET = .;
|
||||
|
||||
.devtree ALIGN(4K) :
|
||||
{
|
||||
EMBED_DEVTREE_START = .;
|
||||
*(.odt)
|
||||
EMBED_DEVTREE_END = .;
|
||||
}
|
||||
|
||||
DEVTREE_END = .;
|
||||
|
||||
.kernelelf ALIGN(4K) :
|
||||
{
|
||||
EMBED_KERNEL_START = .;
|
||||
*(.kernelelf)
|
||||
EMBED_KERNEL_END = .;
|
||||
}
|
||||
|
||||
RAWIMAGE_END = .;
|
||||
}
|
||||
20
build/boot/x86/BUILD.gn
Normal file
20
build/boot/x86/BUILD.gn
Normal file
@@ -0,0 +1,20 @@
|
||||
if (target_arch == "x86") {
|
||||
action("bootx86") {
|
||||
script = "make_boot_drive.py"
|
||||
sources = [
|
||||
"$root_build_dir/stage1.bin",
|
||||
"$root_build_dir/stage2.bin",
|
||||
]
|
||||
outputs = [ "$root_build_dir/os-image.bin" ]
|
||||
args = [
|
||||
rebase_path("$root_build_dir/stage1.bin", root_build_dir),
|
||||
rebase_path("$root_build_dir/stage2.bin", root_build_dir),
|
||||
rebase_path("$root_build_dir/os-image.bin", root_build_dir),
|
||||
]
|
||||
|
||||
deps = [
|
||||
"stage1:stage1",
|
||||
"stage2:stage2",
|
||||
]
|
||||
}
|
||||
}
|
||||
42
build/boot/x86/boot_link.ld
Normal file
42
build/boot/x86/boot_link.ld
Normal file
@@ -0,0 +1,42 @@
|
||||
_pa_base = 0x1000;
|
||||
|
||||
ENTRY(_pa_base)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _pa_base;
|
||||
bootloader_start = .;
|
||||
|
||||
.text ALIGN(4K) :
|
||||
{
|
||||
*(.xos_boot_text)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
}
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
.stack ALIGN(4K) :
|
||||
{
|
||||
STACK_PHYZ_BASE = .;
|
||||
. += 0x1000;
|
||||
STACK_PHYZ_TOP = .;
|
||||
}
|
||||
}
|
||||
7
build/boot/x86/make_boot_drive.py
Normal file
7
build/boot/x86/make_boot_drive.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import sys
|
||||
inf = sys.argv[1]
|
||||
outf = sys.argv[2]
|
||||
reli = sys.argv[3]
|
||||
|
||||
import subprocess
|
||||
output = subprocess.check_output("cat {0} {1} > {2}".format(inf, outf, reli), shell=True)
|
||||
21
build/boot/x86/stage1/BUILD.gn
Normal file
21
build/boot/x86/stage1/BUILD.gn
Normal file
@@ -0,0 +1,21 @@
|
||||
action("stage1") {
|
||||
script = "compile_stage1.py"
|
||||
sources = [ "//boot/x86/stage1/boot.s" ]
|
||||
outputs = [ "$root_build_dir/stage1.bin" ]
|
||||
|
||||
inputs = [
|
||||
"//boot/x86/stage1/boot.s",
|
||||
"//boot/x86/stage1/utils16/disk_load.s",
|
||||
"//boot/x86/stage1/utils16/print.s",
|
||||
"//boot/x86/stage1/utils16/smm.s",
|
||||
"//boot/x86/stage1/utils16/switch_to_pm.s",
|
||||
"//boot/x86/stage1/utils32/gdt.s",
|
||||
"//boot/x86/stage1/utils32/print.s",
|
||||
]
|
||||
|
||||
args = [
|
||||
rebase_path("//boot/x86/stage1/boot.s", root_build_dir),
|
||||
rebase_path(root_build_dir, root_build_dir),
|
||||
rebase_path("//", root_build_dir),
|
||||
]
|
||||
}
|
||||
7
build/boot/x86/stage1/compile_stage1.py
Normal file
7
build/boot/x86/stage1/compile_stage1.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import sys
|
||||
inf = sys.argv[1]
|
||||
outf = sys.argv[2]
|
||||
reli = sys.argv[3]
|
||||
|
||||
import subprocess
|
||||
output = subprocess.check_output("nasm {0} -f bin -i {2} -o {1}/stage1.bin".format(inf, outf, reli), shell=True)
|
||||
48
build/boot/x86/stage2/BUILD.gn
Normal file
48
build/boot/x86/stage2/BUILD.gn
Normal file
@@ -0,0 +1,48 @@
|
||||
linker_script =
|
||||
rebase_path("//build/boot/$target_arch/boot_link.ld", root_build_dir)
|
||||
|
||||
executable("stage2") {
|
||||
output_name = "stage2.bin"
|
||||
sources = [
|
||||
"//boot/libboot/crypto/sha256.c",
|
||||
"//boot/libboot/crypto/signature.c",
|
||||
"//boot/libboot/crypto/uint2048.c",
|
||||
"//boot/libboot/crypto/validate.c",
|
||||
"//boot/libboot/devtree/devtree.c",
|
||||
"//boot/libboot/elf/elf_lite.c",
|
||||
"//boot/libboot/fs/ext2_lite.c",
|
||||
"//boot/libboot/log/log.c",
|
||||
"//boot/libboot/mem/alloc.c",
|
||||
"//boot/libboot/mem/mem.c",
|
||||
"//boot/x86/stage2/drivers/ata.c",
|
||||
"//boot/x86/stage2/drivers/port.c",
|
||||
"//boot/x86/stage2/drivers/uart.c",
|
||||
"//boot/x86/stage2/mem/vm.c",
|
||||
"//boot/x86/stage2/stage2.c",
|
||||
"//boot/x86/stage2/stage2_entry.s",
|
||||
]
|
||||
|
||||
include_dirs = [ "//boot" ]
|
||||
|
||||
ldflags = [
|
||||
"-T$linker_script",
|
||||
"--oformat",
|
||||
"binary",
|
||||
"-Map=stage2.map",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-ffreestanding",
|
||||
"-Werror",
|
||||
"-Wno-address-of-packed-member",
|
||||
"-mno-80387",
|
||||
"-mno-mmx",
|
||||
"-mno-sse",
|
||||
"-mno-sse2",
|
||||
]
|
||||
|
||||
asmflags = [
|
||||
"-f",
|
||||
"elf",
|
||||
]
|
||||
}
|
||||
5
build/boot/x86_64/BUILD.gn
Normal file
5
build/boot/x86_64/BUILD.gn
Normal file
@@ -0,0 +1,5 @@
|
||||
group("bootx86_64") {
|
||||
deps = [
|
||||
"rawImage:rawImage",
|
||||
]
|
||||
}
|
||||
92
build/boot/x86_64/prekernel/BUILD.gn
Normal file
92
build/boot/x86_64/prekernel/BUILD.gn
Normal 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",
|
||||
]
|
||||
}
|
||||
30
build/boot/x86_64/prekernel/embed_kernel.py
Normal file
30
build/boot/x86_64/prekernel/embed_kernel.py
Normal 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)
|
||||
59
build/boot/x86_64/prekernel/prekernel_link.ld
Normal file
59
build/boot/x86_64/prekernel/prekernel_link.ld
Normal 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 = .;
|
||||
}
|
||||
23
build/boot/x86_64/rawImage/BUILD.gn
Normal file
23
build/boot/x86_64/rawImage/BUILD.gn
Normal 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" ]
|
||||
}
|
||||
}
|
||||
30
build/boot/x86_64/rawImage/make_raw_image.py
Normal file
30
build/boot/x86_64/rawImage/make_raw_image.py
Normal 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)
|
||||
Reference in New Issue
Block a user