Make better use of toolchains in the build.
This allows building for different platforms without having to retarget
the build. The configuration is also better checked by the assertions in
the toolchain templates.
A future change will redirect the root build rule to allow BSPs to
fully control their own build and configuration.
Change-Id: Iaae725d3bd000bc0ce7b9ef0f8f083350a73bd16
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 0b4ea31..008315a 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -12,14 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Hypervisor specific code.
-source_set("src") {
+import("//build/image/image.gni")
+
+# The hypervisor image.
+hypervisor("hafnium") {
+ sources = [
+ "layout.c",
+ ]
+ deps = [
+ ":src_not_testable_yet",
+ "//src/arch/${arch}",
+ ]
+}
+
+# Hypervisor specific code that isn't. One day it will be testable and both the
+# src targets will merge!
+source_set("src_not_testable_yet") {
sources = [
"cpio.c",
"load.c",
"main.c",
]
- sources += [ "layout.c" ]
deps = [
":src_testable",
]
diff --git a/src/arch/aarch64/BUILD.gn b/src/arch/aarch64/BUILD.gn
index 520a97d..1588e18 100644
--- a/src/arch/aarch64/BUILD.gn
+++ b/src/arch/aarch64/BUILD.gn
@@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import("//build/arch/aarch64.gni")
-import("//build/image/generate_offsets.gni")
+import("args.gni")
# Hypervisor specific code.
source_set("aarch64") {
@@ -33,14 +32,6 @@
deps = [
":entry",
- ":offsets",
- ]
-}
-
-# Calculate struct field offsets for hypervisor_entry.S.
-generate_offsets("offsets") {
- sources = [
- "offsets.c",
]
}
diff --git a/src/arch/aarch64/args.gni b/src/arch/aarch64/args.gni
new file mode 100644
index 0000000..eabe6d4
--- /dev/null
+++ b/src/arch/aarch64/args.gni
@@ -0,0 +1,18 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+declare_args() {
+ # Whether to include the PrimeCell UART (PL011) driver.
+ arch_aarch64_use_pl011 = false
+}
diff --git a/src/arch/aarch64/offsets.c b/src/arch/aarch64/offsets.c
index 558b956..2cf5be8 100644
--- a/src/arch/aarch64/offsets.c
+++ b/src/arch/aarch64/offsets.c
@@ -14,13 +14,19 @@
* limitations under the License.
*/
-#ifndef GEN_OFFSETS
#include "offsets.h"
-#endif /* GEN_OFFSETS */
+
+#include <assert.h>
#include "hf/cpu.h"
-#include "hf/decl_offsets.h"
-DECL(CPU_STACK_BOTTOM, struct cpu, stack_bottom);
-DECL(VCPU_REGS, struct vcpu, regs);
-DECL(VCPU_LAZY, struct vcpu, regs.lazy);
+#define CHECK_OFFSET(name, type, field) \
+ CHECK_OFFSET_1(#name, name, offsetof(type, field))
+#define CHECK_OFFSET_1(name, actual, expected) \
+ static_assert((actual) == (expected), \
+ "Offset " name " should be " #expected \
+ " and not " #actual)
+
+CHECK_OFFSET(CPU_STACK_BOTTOM, struct cpu, stack_bottom);
+CHECK_OFFSET(VCPU_REGS, struct vcpu, regs);
+CHECK_OFFSET(VCPU_LAZY, struct vcpu, regs.lazy);
diff --git a/src/arch/aarch64/offsets.h b/src/arch/aarch64/offsets.h
new file mode 100644
index 0000000..e967fe4
--- /dev/null
+++ b/src/arch/aarch64/offsets.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2018 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+/* These are checked in offset.c. */
+#define CPU_STACK_BOTTOM 8
+#define VCPU_REGS 32
+#define VCPU_LAZY (VCPU_REGS + 264)
diff --git a/src/arch/fake/inc/hf/arch/mm.h b/src/arch/fake/inc/hf/arch/mm.h
index c99bf92..8033f46 100644
--- a/src/arch/fake/inc/hf/arch/mm.h
+++ b/src/arch/fake/inc/hf/arch/mm.h
@@ -38,7 +38,6 @@
typedef uint64_t pte_t;
#define PAGE_LEVEL_BITS 9
-#define PL011_BASE 0x11
/**
* Returns the encoding of a page table entry that isn't present.
diff --git a/src/cpu.c b/src/cpu.c
index 4c6a18b..b9de38d 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -27,6 +27,8 @@
#include "vmapi/hf/call.h"
+#define STACK_SIZE PAGE_SIZE
+
/* The stack to be used by the CPUs. */
alignas(2 * sizeof(uintreg_t)) static char callstacks[MAX_CPUS][STACK_SIZE];