aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2015-10-29 05:14:06 -0700
committerLuis R. Rodriguez <mcgrof@kernel.org>2016-02-11 08:42:16 -0800
commit4592db832826aa309534241259e7be0184d39d47 (patch)
tree23e5057162dc49dcfea3566af07280d51318b78f
parentf4f49e1679169e5383762e36958fbd1a67718b8d (diff)
downloadlinker-tables-4592db832826aa309534241259e7be0184d39d47.tar.gz
add simple xen simulation framework
To simulate booting xen just pass any parameter to main, for instance; ./main -x Right now this fails as there is no kasan set up developed yet for Xen. Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
-rw-r--r--Makefile2
-rw-r--r--init.c8
-rw-r--r--kasan.c17
-rw-r--r--kasan.h4
-rw-r--r--main.c20
-rw-r--r--xen-driver.c26
-rw-r--r--xen.c18
-rw-r--r--xen.h2
8 files changed, 93 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index c7dffa6..b679798 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,8 @@ OBJS = sort-init.o \
init.o \
pci.o \
driver.o \
+ xen.o \
+ xen-driver.o \
main.o
main: $(OBJS)
diff --git a/init.c b/init.c
index 4ea39c4..502894c 100644
--- a/init.c
+++ b/init.c
@@ -19,8 +19,10 @@ int early_init(void)
printf("Initializing %s ...\n", init_fn->name);
ret = init_fn->early_init();
if (ret) {
- if (init_fn->critical)
+ if (init_fn->critical) {
+ printf("Failed to initialize %s on early init\n", init_fn->name);
return ret;
+ }
printf("Failed to initialize %s on early init, but its not critical\n", init_fn->name);
} else
@@ -43,8 +45,10 @@ int late_init(void)
printf("Running late init for %s ...\n", init_fn->name);
ret = init_fn->late_init();
if (ret) {
- if (init_fn->critical)
+ if (init_fn->critical) {
+ printf("Failed to initialize %s on late init\n", init_fn->name);
return ret;
+ }
printf("Failed to initialize %s on late init, but its not critical\n", init_fn->name);
} else
diff --git a/kasan.c b/kasan.c
index bd5765b..a07fbcd 100644
--- a/kasan.c
+++ b/kasan.c
@@ -1,10 +1,26 @@
#include <stdio.h>
#include <unistd.h>
+#include <errno.h>
#include "init.h"
+static bool __is_kasan_setup = false;
+
+int setup_kasan_bare_metal(void) {
+ __is_kasan_setup = true;
+ return 0;
+}
+
+bool is_kasan_setup(void)
+{
+ return __is_kasan_setup;
+}
+
static int init_kasan(void) {
sleep(1);
+ if (!is_kasan_setup())
+ return -EINVAL;
+
return 0;
}
@@ -16,4 +32,5 @@ struct init_fn kasan_init_fn __init_fn(INIT_EARLY) = {
.detect = detect_kasan,
.early_init = init_kasan,
.name = "Kasan",
+ .critical = true,
};
diff --git a/kasan.h b/kasan.h
new file mode 100644
index 0000000..81e76de
--- /dev/null
+++ b/kasan.h
@@ -0,0 +1,4 @@
+#include <stdbool.h>
+
+int setup_kasan_bare_metal(void);
+bool is_kasan_setup(void);
diff --git a/main.c b/main.c
index bb5cafa..0e4888b 100644
--- a/main.c
+++ b/main.c
@@ -1,15 +1,31 @@
#include <stdio.h>
+#include <stdbool.h>
#include <unistd.h>
#include "tables.h"
#include "init.h"
+#include "xen.h"
+#include "kasan.h"
extern struct init_fn __tbl[], __tbl_end[];
-int main(void)
+int bare_metal_start(void)
{
int ret;
- printf("Initializing world\n");
+ printf("Initializing bare metal world\n");
+ ret = setup_kasan_bare_metal();
+
+ return ret;
+}
+
+int main(int arg, char *argc[])
+{
+ int ret;
+
+ if (arg > 1)
+ xen_start();
+ else
+ bare_metal_start();
sort_table(__tbl, __tbl_end);
check_table_entries(__tbl, __tbl_end);
diff --git a/xen-driver.c b/xen-driver.c
new file mode 100644
index 0000000..a5f3656
--- /dev/null
+++ b/xen-driver.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <unistd.h>
+
+#include "init.h"
+#include "pci.h"
+#include "xen.h"
+
+static int early_xen_init_driver(void) {
+ sleep(2);
+
+ return 0;
+}
+
+static int detect_xen_driver(void) {
+ if (!booting_xen())
+ return 0;
+
+ return 1;
+}
+
+struct init_fn driver_xen_init_fn __init_fn(INIT_NORMAL) = {
+ .detect = detect_xen_driver,
+ .depend = detect_pci,
+ .early_init = early_xen_init_driver,
+ .name = "Xen Driver",
+};
diff --git a/xen.c b/xen.c
new file mode 100644
index 0000000..bcae856
--- /dev/null
+++ b/xen.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdbool.h>
+
+static bool __booting_xen = false;
+
+bool booting_xen(void)
+{
+ return __booting_xen;
+}
+
+int xen_start(void)
+{
+ __booting_xen = true;
+
+ printf("Initializing Xen guest\n");
+
+ return 0;
+}
diff --git a/xen.h b/xen.h
new file mode 100644
index 0000000..66e54e2
--- /dev/null
+++ b/xen.h
@@ -0,0 +1,2 @@
+bool booting_xen(void);
+int xen_start(void);