blob: 7be141c0adc421192447dcc44777de10fa6af768 [file]
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
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" ]
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" ]
}
# This is used pervasively throughout the kernel on arm64.
config("kernel") {
# x15 is reserved so we can use it to point at the per-CPU structure.
cflags = [ "-ffixed-x15" ]
if (!is_gcc) {
cflags += [
# Clang needs -mcmodel=kernel to tell it to use the right
# thread-pointer ABI for the kernel.
"-mcmodel=kernel",
# 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",
"KERNEL_ASPACE_BASE=$kernel_aspace_base",
"KERNEL_ASPACE_SIZE=0x0001000000000000",
"USER_ASPACE_BASE=0x0000000001000000",
"USER_ASPACE_SIZE=0x0000fffffe000000",
]
# For #include <arch/foo.h>.
include_dirs = [ "include" ]
}
source_set("arm64") {
sources = [
"arch.cc",
"asm.S",
"boot-mmu.cc",
"cache-ops.S",
"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 = [
"$zx/kernel/dev/interrupt/arm_gic/common",
"$zx/kernel/dev/iommu/dummy",
"$zx/kernel/lib/cmdline",
"$zx/kernel/lib/console",
"$zx/kernel/lib/counters",
"$zx/kernel/lib/crashlog",
"$zx/kernel/lib/perfmon",
"$zx/kernel/object",
"$zx/kernel/syscalls:syscall-abi",
"$zx/kernel/vm",
"$zx/system/ulib/bitmap",
]
public_configs = [ "$zx/public/gn/config:Wno-unused-function" ]
}
}