blob: 990dd39cb4c8860698ff9fc178f4e450faa69108 [file] [log] [blame]
# Copyright 2019 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("$zx/kernel/params.gni")
import("$zx/public/gn/toolchain/environment.gni")
if (current_toolchain == default_toolchain) {
# Define a special environment for building code that runs in physical
# memory with the MMU disabled, at early boot.
environment("physmem") {
cpu = "arm64"
globals = {
is_kernel = true
}
configs += standard_fuchsia_configs + [ ":physmem_config" ]
tags = [
"standalone",
"strict-align",
]
exclude_variant_tags = [ "instrumented" ]
}
} else {
# This is the top config for the physmem environment.
config("physmem_config") {
configs = [
"$zx/kernel:headers",
"$zx/kernel:standalone",
"$zx/kernel:warnings",
"$zx/public/gn/config:no_sanitizers",
]
cflags = [
"-fpie",
# With the MMU disabled, alignment checking is always enabled. So make
# sure the compiler doesn't use any unaligned memory accesses.
"-mstrict-align",
]
if (!is_gcc) {
# TODO(TC-237): cflags += [ "-mcmodel=tiny" ]
}
include_dirs = [ "include" ]
}
# These set the ABI contract between C++ and assembly code.
# This is kept consistent between the kernel proper and phys
# so (pure PIC) code should be callable from the kernel proper.
config("abi") {
# x15 is reserved so we can use it to point at the per-CPU structure.
cflags = [ "-ffixed-x15" ]
if (!is_gcc) {
# Use the right thread-pointer ABI for the kernel.
cflags += [ "-mtp=el1" ]
}
}
# This is used pervasively throughout the kernel on arm64.
config("kernel") {
cflags = []
if (!is_gcc) {
cflags += [
# Use shadow-call-stack rather than safe-stack for the kernel,
# regardless of the compiler's default.
"-fno-sanitize=safe-stack",
"-fsanitize=shadow-call-stack",
]
}
# Assembly code needs to use `#if __has_feature(...)` so make sure
# it always sees all the same `-fsanitize=...` flags and the like.
asmflags = cflags
ldflags = cflags
defines = [ "ARCH_ARM64" ]
# For #include <arch/foo.h>.
include_dirs = [ "include" ]
configs = [
# <arch/current_thread.h> has #include <lib/arch/intrin.h>.
"$zx/kernel/lib/arch/arm64:headers.config",
]
# Align the kernel's segments to 64k so it can use "combined pages" to
# reduce the TLB load.
ldflags += [ "-Wl,-z,max-page-size=65536" ]
}
source_set("arm64") {
sources = [
"arch.cc",
"asm.S",
"cache-ops.S",
"dap.cc",
"debugger.cc",
"exceptions.S",
"exceptions_c.cc",
"feature.cc",
"fpu.cc",
"mexec.S",
"mmu.cc",
"mp.cc",
"perf_mon.cc",
"periphmap.cc",
"registers.cc",
"smccc.S",
"spinlock.cc",
"start.S",
"sysreg.cc",
"thread.cc",
"user_copy.S",
"user_copy_c.cc",
"uspace_entry.S",
]
deps = [
":boot-mmu",
"$zx/kernel/dev/interrupt/arm_gic/common",
"$zx/kernel/dev/iommu/dummy",
"$zx/kernel/lib/arch",
"$zx/kernel/lib/cmdline",
"$zx/kernel/lib/console",
"$zx/kernel/lib/counters",
"$zx/kernel/lib/crashlog",
"$zx/kernel/lib/ktl",
"$zx/kernel/lib/perfmon",
"$zx/kernel/lib/syscalls",
"$zx/kernel/object",
"$zx/kernel/vm",
"$zx/system/ulib/bitmap",
"$zx/system/ulib/pretty",
]
}
source_set("boot-mmu") {
visibility = [ ":*" ]
sources = [ "boot-mmu.cc" ]
deps = [ "$zx/kernel/vm" ]
# Everything in this file runs too early to use the full ABI. Per-function
# attribute suppression of sanitizer modes doesn't work for C++ lambda.
configs += [
"$zx/public/gn/config:no_safestack",
"$zx/public/gn/config:no-shadow-call-stack",
]
}
}