blob: 0be35ddaebffedce6413fde4522b5812109e4358 [file] [log] [blame]
# Copyright 2020 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
import("//build/config/zircon/standard.gni")
import("//build/info/info.gni")
import("//build/toolchain/toolchain_environment.gni")
import("//build/toolchain/zircon/zircon_toolchain_suite.gni")
import("//build/zircon/zircon_cpu.gni")
import("//zircon/kernel/arch/$zircon_cpu/phys/phys.gni")
import("//zircon/kernel/params.gni")
import("zbi_executable.gni")
if (current_toolchain == default_toolchain) {
# Default toolchain (current_cpu == "") just defines the phys environment.
# Note: see //zircon/kernel/arch/x86/phys:kernel.phys32 too.
foreach(cpu, standard_fuchsia_cpus) {
kernel_cpu = cpu
if (kernel_cpu == "x64") {
kernel_cpu = "x86"
}
zircon_toolchain_suite("kernel.phys_$cpu") {
cpu = cpu
os = "fuchsia"
environment = "kernel.phys"
with_shared = false
toolchain_tags = [ "kernel" ]
configs = [ "//zircon/kernel/phys:phys_config" ] + phys_configs
# Always enable frame pointers. This works because frame_pointers
# is added as part of :phys_config below.
remove_common_configs = [ "//build/config:default_frame_pointers" ]
exclude_variant_tags = [
# There is no possibility of fancy runtimes like ASan for phys.
"instrumentation-runtime",
]
# Append the arch-specific lists. The phys/phys.gni file in each
# arch subdirectory defines phys_* lists to append to the parameters.
toolchain_tags += phys_tags
exclude_variant_tags += phys_exclude_variant_tags
}
}
} else if (toolchain_environment == "kernel.phys") {
kernel_cpu = current_cpu
if (current_cpu == "x64") {
kernel_cpu = "x86"
}
config("phys_config") {
configs = [
"//zircon/kernel:standalone",
"//zircon/kernel:warnings",
"//zircon/kernel/arch/$kernel_cpu:abi",
":defines",
# Don't emit extra code making static initializers thread-safe (we don't
# have threads or any of the corresponding library support.)
"//build/config/zircon:no_threadsafe_statics",
# All physmem code is inherently sensitive and in a position for
# any bug to be unusually dangerous. So compile with minimal
# undefined behavior checking in all builds, regardless of variant.
"//build/config/zircon/instrumentation:ubsan-trap",
]
# Always enable frame pointers.
configs += [ "//build/config:frame_pointers" ]
}
group("phys_config_deps") {
deps = [ "//src/lib/trivial-allocator:panic-delete" ]
}
}
if (toolchain_environment == "kernel.phys" ||
toolchain_environment == "kernel.phys32" ||
toolchain_environment == "kernel.efi") {
# All the code gets built here in the phys environment.
source_set("trampoline-boot") {
visibility = [
"./*",
# Required for legacy-boot-shim
"//zircon/kernel/arch/x86/*",
]
sources = [ "trampoline-boot.cc" ]
public = [ "include/phys/trampoline-boot.h" ]
public_deps = [ ":boot-zbi" ]
deps = [
":page-table",
":symbolize",
"//zircon/kernel/lib/arch",
"//zircon/kernel/phys/lib/memalloc",
]
public_configs = [ ":includes" ]
}
config("defines") {
# Always enable tests and asserts in phys code.
defines = [ "LK_DEBUGLEVEL=2" ]
}
config("load-pic") {
# ZBI executables can be loaded anywhere, so they are linked at 0.
ldflags = [ "-Wl,-defsym,PHYS_LOAD_ADDRESS=0" ]
}
source_set("symbolize") {
public = [
"include/phys/frame-pointer.h",
"include/phys/symbolize.h",
]
sources = [
"frame-pointer.cc",
"panic.cc",
"stack.cc",
"symbolize.cc",
]
deps = [
"//src/lib/symbolizer-markup",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/pretty",
]
public_deps = [
# "symbolize.h" has #include <phys/main.h>.
":main",
# "symbolize.h" has #include <lib/symbolizer-markup/writer.h>.
"//src/lib/symbolizer-markup",
]
public_configs = [ ":includes" ]
}
# This is used implicitly by phys_executable() targets,
# including zbi_executable() targets.
source_set("phys_executable.deps") {
deps = [
":symbolize",
"//zircon/kernel/arch/$zircon_cpu/phys",
]
}
# This is used implicitly by zbi_executable() targets.
source_set("zbi_executable.deps") {
sources = [
"exception.cc",
"zbi-header.S",
"zbi-main.cc",
]
deps = [
":main",
":stdio",
":uart",
":zbi-memory",
"//zircon/kernel/lib/arch",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/crypto:crypto-entropy-src",
"//zircon/system/ulib/uart",
"//zircon/system/ulib/zbitl",
]
}
source_set("kernel-package") {
public = [ "include/phys/kernel-package.h" ]
public_deps = [
":allocation",
":handoff",
"//zircon/kernel/lib/ktl",
"//zircon/system/ulib/zbitl",
]
public_configs = [ ":includes" ]
sources = [ "kernel-package.cc" ]
deps = [
":stdio",
":symbolize",
":zbitl-allocation",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/pretty",
]
}
# Transitive dependencies for the <phys/main.h> header.
static_library("main") {
public = [
"include/phys/exception.h",
"include/phys/main.h",
"include/phys/stack.h",
]
public_deps = [
# "main.h" has #include <lib/arch/ticks.h>.
"//zircon/kernel/lib/arch",
# "main.h" has #include <lib/mempool/range.h>.
"//zircon/kernel/phys/lib/memalloc",
]
public_configs = [ ":includes" ]
if (toolchain_environment != "kernel.efi") {
sources = [ "self-relocation.cc" ]
deps = [ "//src/lib/elfldltl" ]
}
}
# Transitive dependencies for the <phys/page-table.h> header.
source_set("page-table") {
public = [ "include/phys/page-table.h" ]
sources = [ "page-table.cc" ]
public_configs = [ ":includes" ]
public_deps = [
"//zircon/kernel/lib/ktl",
# "page-table.h" has #include <lib/page-table/builder-interface.h>
# "page-table.h" has #include <lib/page-table/types.h>
"//zircon/kernel/phys/lib/page-table",
]
deps = [
":stdio",
":uart",
"//zircon/kernel/phys/lib/memalloc",
"//zircon/system/ulib/uart",
]
}
source_set("stdio") {
public = [ "include/phys/stdio.h" ]
public_configs = [ ":includes" ]
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
]
deps = [ "//zircon/kernel/lib/boot-options" ]
sources = [ "stdio.cc" ]
}
source_set("acpi") {
sources = [ "acpi.cc" ]
public = [ "include/phys/acpi.h" ]
public_deps = [
"//zircon/kernel/lib/acpi_lite",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/zxc",
]
public_configs = [ ":includes" ]
deps = [
":symbolize",
"//zircon/system/ulib/fbl",
]
}
source_set("uart") {
public = [ "include/phys/uart.h" ]
public_configs = [ ":includes" ]
sources = [ "uart.cc" ]
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/uart",
]
deps = [
":stdio",
"//zircon/system/ulib/uart",
]
}
# This is linked into the special-case phys_executable() tests that
# are run directly as QEMU kernels.
source_set("qemu-header") {
sources = [ "qemu-header.S" ]
public_configs = [ "//zircon/kernel/arch/$zircon_cpu/phys:qemu.config" ]
}
source_set("allocation") {
public = [ "include/phys/allocation.h" ]
if (toolchain_environment != "kernel.efi") {
sources = [
"//zircon/kernel/arch/$zircon_cpu/phys/include/phys/arch/arch-allocation.h",
"allocation.cc",
]
deps = [
":main",
"//zircon/kernel/phys/lib/memalloc",
"//zircon/kernel/phys/lib/page-table",
]
}
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
# allocation.h has #include <lib/memalloc/pool.h>.
# allocation.h has #include <lib/memalloc/range.h>.
"//zircon/kernel/phys/lib/memalloc",
# allocation.h has #include <fbl/alloc_checker.h>.
"//zircon/system/ulib/fbl",
# allocation.h has #include <lib/fitx/result.h>.
"//zircon/system/ulib/zxc",
# allocation.h has #include <lib/memalloc/range.h>
# allocation.h has #include <lib/memalloc/pool.h>
"//zircon/kernel/phys/lib/memalloc",
]
public_configs = [ ":includes" ]
}
source_set("new") {
public = [ "include/phys/new.h" ]
public_deps = [
# <phys/new.h> has #include <phys/allocation.h>.
":allocation",
# <phys/new.h> has #include <lib/trivial-allocator/new.h>
"//src/lib/trivial-allocator",
]
}
source_set("zbitl-allocation") {
public = [ "include/phys/zbitl-allocation.h" ]
sources = [ "zbitl-allocation.cc" ]
deps = [
":allocation",
"//zircon/system/ulib/fbl",
]
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
# zbitl-allocation.h has #include "allocation.h".
":allocation",
# zbitl-allocation.h has #include <lib/zbitl/storage-traits.h>.
"//zircon/system/ulib/zbitl",
# zbitl-allocation.h has #include <lib/fitx/result.h>.
"//zircon/system/ulib/zxc",
]
public_configs = [ ":includes" ]
}
# This is a little library instead of a source_set() so it can be included
# implicitly by zbi_executable() without adding bloat to the tiny tests that
# don't use it.
static_library("zbi-memory") {
sources = [
"zbi-init-memory.cc",
"zbi-memory.cc",
]
deps = [
":allocation",
":main",
":page-table",
":symbolize",
"//zircon/kernel/arch/$zircon_cpu/phys:address-space",
"//zircon/kernel/lib/arch",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/phys/lib/memalloc",
"//zircon/kernel/phys/lib/page-table",
"//zircon/system/ulib/zbitl",
]
public_deps = [
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
# allocation.h has #include <fbl/alloc_checker.h>.
"//zircon/system/ulib/fbl",
]
}
source_set("boot-zbi") {
public = [ "include/phys/boot-zbi.h" ]
sources = [ "boot-zbi.cc" ]
public_deps = [
":allocation",
":stdio",
":symbolize",
"//zircon/kernel/lib/arch",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/pretty",
"//zircon/system/ulib/zbitl",
"//zircon/system/ulib/zxc",
]
}
source_set("handoff-entropy") {
sources = [ "handoff-entropy.cc" ]
public = [ "handoff-entropy.h" ]
public_deps = [
":stdio",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/crypto:crypto-entropy-src",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/zbitl",
]
deps = [ "//zircon/system/ulib/explicit-memory" ]
}
# Split out so that the definition of arch-specific methods can include
# handoff-prep.h without introducing a dependency cycle.
source_set("handoff-prep.h") {
public = [ "handoff-prep.h" ]
public_deps = [
":handoff",
":zbitl-allocation",
"//src/lib/trivial-allocator",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/zbitl",
]
}
source_set("handoff-prep") {
sources = [
"handoff-prep-zbi.cc",
"handoff-prep.cc",
]
public_deps = [ ":handoff-prep.h" ]
deps = [
":allocation",
":handoff",
":handoff-entropy",
":symbolize",
":zbitl-allocation",
"//src/lib/llvm-profdata",
"//zircon/kernel/arch/$zircon_cpu/phys:arch-handoff-prep",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/phys/lib/memalloc",
"//zircon/system/ulib/zbitl",
]
}
}
config("includes") {
include_dirs = [
"include",
"//zircon/kernel/arch/${zircon_cpu}/phys/include",
]
}
group("tests") {
testonly = true
deps = [
"boot-shim:tests",
"efi:tests",
"test",
"//zircon/kernel/arch/$zircon_cpu/phys:tests",
]
if (build_info_product != "bringup") {
# The following target includes tests that cannot be run on the bringup
# product.
deps += [ "lib:tests" ]
}
}
zbi_executable("physboot") {
sources = [ "physboot.cc" ]
deps = [
":allocation",
":boot-zbi",
":handoff",
":handoff-prep",
":kernel-package",
":main",
":stdio",
":symbolize",
":trampoline-boot",
":uart",
"//zircon/kernel/arch/$zircon_cpu/code-patches",
"//zircon/kernel/lib/arch",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/code-patching",
"//zircon/kernel/lib/ktl",
"//zircon/kernel/lib/libc",
"//zircon/system/ulib/zbitl",
]
# TODO(fxbug.dev/79992): Work around LTO compilation bugs.
# Remove this when the compiler issues are resolved.
if (current_cpu == "arm64") {
exclude_toolchain_tags = [ "lto" ]
}
# Used as a bias when patching kernel code.
defines = [ "KERNEL_LINK_ADDRESS=${kernel_base}" ]
}
if (is_kernel) {
source_set("handoff") {
public = [
"//zircon/kernel/arch/${zircon_cpu}/phys/include/phys/arch/arch-handoff.h",
"include/phys/handoff-ptr.h",
"include/phys/handoff.h",
]
public_deps = [
# handoff.h has #include <lib/arch/ticks.h>.
"//zircon/kernel/lib/arch",
# handoff.h has #include <lib/uart/all.h>.
"//zircon/system/ulib/uart",
# handoff.h has #include <lib/crypto/entropy_pool.h>
"//zircon/kernel/lib/crypto:crypto-entropy-src",
]
public_configs = [ ":includes" ]
}
}