Introduce intermediate build target for std.

This gives a place for common functions to be defined.

Change-Id: Ifac38e647ab1042a00d224a58e28a0e6807fa60c
diff --git a/inc/hf/std.h b/inc/hf/std.h
new file mode 100644
index 0000000..bb71a9d
--- /dev/null
+++ b/inc/hf/std.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2019 The Hafnium Authors.
+ *
+ * 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
+
+#include "hf/arch/std.h"
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 6bdf1af..8ec1f92 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -59,8 +59,8 @@
   deps = [
     ":fdt",
     ":memiter",
+    ":std",
     "//src/arch/${plat_arch}",
-    "//src/arch/${plat_arch}:std",
   ]
 
   if (is_debug) {
@@ -68,6 +68,13 @@
   }
 }
 
+# Standard library functions.
+source_set("std") {
+  deps = [
+    "//src/arch/${plat_arch}:std",
+  ]
+}
+
 # Debug code that is not specific to a certain image so can be shared.
 source_set("dlog") {
   sources = [
@@ -75,8 +82,8 @@
   ]
 
   deps = [
+    ":std",
     "//src/arch/${plat_arch}:putchar",
-    "//src/arch/${plat_arch}:std",
   ]
 }
 
@@ -87,7 +94,7 @@
   ]
 
   deps = [
-    "//src/arch/${plat_arch}:std",
+    ":std",
   ]
 
   if (is_debug) {
diff --git a/src/api.c b/src/api.c
index ad566e2..cd46073 100644
--- a/src/api.c
+++ b/src/api.c
@@ -17,13 +17,13 @@
 #include "hf/api.h"
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/timer.h"
 
 #include "hf/assert.h"
 #include "hf/dlog.h"
 #include "hf/mm.h"
 #include "hf/spinlock.h"
+#include "hf/std.h"
 #include "hf/vm.h"
 
 #include "vmapi/hf/call.h"
diff --git a/src/arch/aarch64/cpu.c b/src/arch/aarch64/cpu.c
index 56ada32..b1280a6 100644
--- a/src/arch/aarch64/cpu.c
+++ b/src/arch/aarch64/cpu.c
@@ -20,9 +20,8 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/addr.h"
+#include "hf/std.h"
 
 void arch_irq_disable(void)
 {
diff --git a/src/cpio.c b/src/cpio.c
index 6f2442d..61a82d6 100644
--- a/src/cpio.c
+++ b/src/cpio.c
@@ -18,7 +18,7 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 #pragma pack(push, 1)
 struct cpio_header {
diff --git a/src/cpu.c b/src/cpu.c
index 3cc15be..b2213d1 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -19,10 +19,10 @@
 #include <stdalign.h>
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 
 #include "hf/api.h"
 #include "hf/dlog.h"
+#include "hf/std.h"
 #include "hf/vm.h"
 
 #include "vmapi/hf/call.h"
diff --git a/src/dlog.c b/src/dlog.c
index 7874cab..cd1247b 100644
--- a/src/dlog.c
+++ b/src/dlog.c
@@ -20,9 +20,9 @@
 #include <stddef.h>
 
 #include "hf/arch/console.h"
-#include "hf/arch/std.h"
 
 #include "hf/spinlock.h"
+#include "hf/std.h"
 
 /* Keep macro alignment */
 /* clang-format off */
diff --git a/src/fdt.c b/src/fdt.c
index 3859b46..b781a72 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -18,9 +18,8 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/dlog.h"
+#include "hf/std.h"
 
 struct fdt_header {
 	uint32_t magic;
diff --git a/src/fdt_handler.c b/src/fdt_handler.c
index 97cdd2b..0a0b294 100644
--- a/src/fdt_handler.c
+++ b/src/fdt_handler.c
@@ -16,14 +16,13 @@
 
 #include "hf/fdt_handler.h"
 
-#include "hf/arch/std.h"
-
 #include "hf/boot_params.h"
 #include "hf/cpu.h"
 #include "hf/dlog.h"
 #include "hf/fdt.h"
 #include "hf/layout.h"
 #include "hf/mm.h"
+#include "hf/std.h"
 
 static uint64_t convert_number(const char *data, uint32_t size)
 {
diff --git a/src/layout.c b/src/layout.c
index f74f7c2..e53361b 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -16,7 +16,7 @@
 
 #include "hf/layout.h"
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 /**
  * Get the address the .text section begins at.
diff --git a/src/load.c b/src/load.c
index 1208eda..7eea3dc 100644
--- a/src/load.c
+++ b/src/load.c
@@ -18,8 +18,6 @@
 
 #include <stdbool.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/api.h"
 #include "hf/assert.h"
 #include "hf/boot_params.h"
@@ -27,6 +25,7 @@
 #include "hf/layout.h"
 #include "hf/memiter.h"
 #include "hf/mm.h"
+#include "hf/std.h"
 #include "hf/vm.h"
 
 #include "vmapi/hf/call.h"
diff --git a/src/main.c b/src/main.c
index 02fc0a8..1df1802 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,7 +18,6 @@
 #include <stddef.h>
 
 #include "hf/arch/init.h"
-#include "hf/arch/std.h"
 
 #include "hf/api.h"
 #include "hf/boot_params.h"
@@ -29,6 +28,7 @@
 #include "hf/mm.h"
 #include "hf/mpool.h"
 #include "hf/panic.h"
+#include "hf/std.h"
 #include "hf/vm.h"
 
 #include "vmapi/hf/call.h"
diff --git a/src/memiter.c b/src/memiter.c
index b629ebc..7ec3c94 100644
--- a/src/memiter.c
+++ b/src/memiter.c
@@ -16,7 +16,7 @@
 
 #include "hf/memiter.h"
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 /**
  * Initialises the given memory iterator.
diff --git a/src/vm.c b/src/vm.c
index 8eafd09..a58886e 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -16,10 +16,9 @@
 
 #include "hf/vm.h"
 
-#include "hf/arch/std.h"
-
 #include "hf/api.h"
 #include "hf/cpu.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/hftest/BUILD.gn b/test/hftest/BUILD.gn
index 787a77d..a18a252 100644
--- a/test/hftest/BUILD.gn
+++ b/test/hftest/BUILD.gn
@@ -45,8 +45,8 @@
     "//src:dlog",
     "//src:memiter",
     "//src:panic",
+    "//src:std",
     "//src/arch/${plat_arch}:entry",
-    "//src/arch/${plat_arch}:std",
     "//src/arch/${plat_arch}/hftest:entry",
     "//src/arch/${plat_arch}/hftest:hf_call",
     "//src/arch/${plat_arch}/hftest:power_mgmt",
@@ -112,6 +112,6 @@
   deps = [
     "//src:memiter",
     "//src:panic",
-    "//src/arch/${plat_arch}:std",
+    "//src:std",
   ]
 }
diff --git a/test/hftest/hftest_common.c b/test/hftest/hftest_common.c
index 5a3b348..e1b4602 100644
--- a/test/hftest/hftest_common.c
+++ b/test/hftest/hftest_common.c
@@ -16,10 +16,10 @@
 
 #include "hftest_common.h"
 
-#include "hf/arch/std.h"
 #include "hf/arch/vm/power_mgmt.h"
 
 #include "hf/memiter.h"
+#include "hf/std.h"
 
 #include "hftest.h"
 
diff --git a/test/hftest/hftest_service.c b/test/hftest/hftest_service.c
index 743e087..b110cb5 100644
--- a/test/hftest/hftest_service.c
+++ b/test/hftest/hftest_service.c
@@ -17,10 +17,9 @@
 #include <stdalign.h>
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/memiter.h"
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/hftest/inc/hftest_impl.h b/test/hftest/inc/hftest_impl.h
index 328f664..a86069c 100644
--- a/test/hftest/inc/hftest_impl.h
+++ b/test/hftest/inc/hftest_impl.h
@@ -18,9 +18,8 @@
 
 #include <stdnoreturn.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #define HFTEST_MAX_TESTS 50
 
diff --git a/test/vmapi/gicv3/busy_secondary.c b/test/vmapi/gicv3/busy_secondary.c
index f694031..1a3cf52 100644
--- a/test/vmapi/gicv3/busy_secondary.c
+++ b/test/vmapi/gicv3/busy_secondary.c
@@ -15,11 +15,11 @@
  */
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/gicv3/gicv3.c b/test/vmapi/gicv3/gicv3.c
index dc0a081..7e90790 100644
--- a/test/vmapi/gicv3/gicv3.c
+++ b/test/vmapi/gicv3/gicv3.c
@@ -17,11 +17,11 @@
 #include "gicv3.h"
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/gicv3/interrupts.c b/test/vmapi/gicv3/interrupts.c
index b174010..1b8d532 100644
--- a/test/vmapi/gicv3/interrupts.c
+++ b/test/vmapi/gicv3/interrupts.c
@@ -15,10 +15,10 @@
  */
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/gicv3/services/timer.c b/test/vmapi/gicv3/services/timer.c
index 2daf2b9..871603d 100644
--- a/test/vmapi/gicv3/services/timer.c
+++ b/test/vmapi/gicv3/services/timer.c
@@ -17,11 +17,11 @@
 #include "hf/arch/vm/timer.h"
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/events.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/interrupts.c b/test/vmapi/primary_with_secondaries/interrupts.c
index eaee542..187304e 100644
--- a/test/vmapi/primary_with_secondaries/interrupts.c
+++ b/test/vmapi/primary_with_secondaries/interrupts.c
@@ -16,7 +16,7 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/mailbox.c b/test/vmapi/primary_with_secondaries/mailbox.c
index 287767e..7a45dfa 100644
--- a/test/vmapi/primary_with_secondaries/mailbox.c
+++ b/test/vmapi/primary_with_secondaries/mailbox.c
@@ -16,9 +16,8 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/memory_sharing.c b/test/vmapi/primary_with_secondaries/memory_sharing.c
index 8d8bb47..c74d6f3 100644
--- a/test/vmapi/primary_with_secondaries/memory_sharing.c
+++ b/test/vmapi/primary_with_secondaries/memory_sharing.c
@@ -16,9 +16,8 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index 39ed12f..b6e27be 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -17,10 +17,9 @@
 #include <stdalign.h>
 #include <stdint.h>
 
-#include "hf/arch/std.h"
-
 #include "hf/assert.h"
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/run_race.c b/test/vmapi/primary_with_secondaries/run_race.c
index efb33e8..c41387d 100644
--- a/test/vmapi/primary_with_secondaries/run_race.c
+++ b/test/vmapi/primary_with_secondaries/run_race.c
@@ -17,11 +17,11 @@
 #include <stdalign.h>
 #include <stdint.h>
 
-#include "hf/arch/std.h"
 #include "hf/arch/vm/power_mgmt.h"
 
 #include "hf/assert.h"
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/abort.c b/test/vmapi/primary_with_secondaries/services/abort.c
index 9e6b14c..e37d7e9 100644
--- a/test/vmapi/primary_with_secondaries/services/abort.c
+++ b/test/vmapi/primary_with_secondaries/services/abort.c
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
-
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/check_state.c b/test/vmapi/primary_with_secondaries/services/check_state.c
index e467f52..2379d9f 100644
--- a/test/vmapi/primary_with_secondaries/services/check_state.c
+++ b/test/vmapi/primary_with_secondaries/services/check_state.c
@@ -14,9 +14,10 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
 #include "hf/arch/vm/state.h"
 
+#include "hf/std.h"
+
 #include "vmapi/hf/call.h"
 
 #include "hftest.h"
diff --git a/test/vmapi/primary_with_secondaries/services/echo.c b/test/vmapi/primary_with_secondaries/services/echo.c
index bc33a25..e72622c 100644
--- a/test/vmapi/primary_with_secondaries/services/echo.c
+++ b/test/vmapi/primary_with_secondaries/services/echo.c
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
-
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
index 424e3ab..f278851 100644
--- a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
+++ b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
@@ -15,10 +15,10 @@
  */
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible.c b/test/vmapi/primary_with_secondaries/services/interruptible.c
index 523eaca..2053088 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -15,10 +15,10 @@
  */
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 #include "vmapi/hf/spci.h"
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
index 036566c..5f79433 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
@@ -15,10 +15,10 @@
  */
 
 #include "hf/arch/cpu.h"
-#include "hf/arch/std.h"
 #include "hf/arch/vm/interrupts_gicv3.h"
 
 #include "hf/dlog.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/memory.c b/test/vmapi/primary_with_secondaries/services/memory.c
index babb911..5802429 100644
--- a/test/vmapi/primary_with_secondaries/services/memory.c
+++ b/test/vmapi/primary_with_secondaries/services/memory.c
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
-
 #include "hf/mm.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/relay.c b/test/vmapi/primary_with_secondaries/services/relay.c
index 7ac7ade..30ce25e 100644
--- a/test/vmapi/primary_with_secondaries/services/relay.c
+++ b/test/vmapi/primary_with_secondaries/services/relay.c
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/services/spci_check.c b/test/vmapi/primary_with_secondaries/services/spci_check.c
index 2550a45..4f4ce6e 100644
--- a/test/vmapi/primary_with_secondaries/services/spci_check.c
+++ b/test/vmapi/primary_with_secondaries/services/spci_check.c
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#include "hf/arch/std.h"
-
 #include "hf/spci.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"
 
diff --git a/test/vmapi/primary_with_secondaries/spci.c b/test/vmapi/primary_with_secondaries/spci.c
index 5c7a5b4..1e0c8a1 100644
--- a/test/vmapi/primary_with_secondaries/spci.c
+++ b/test/vmapi/primary_with_secondaries/spci.c
@@ -18,7 +18,7 @@
 
 #include <stdint.h>
 
-#include "hf/arch/std.h"
+#include "hf/std.h"
 
 #include "vmapi/hf/call.h"