diff options
author | Luis R. Rodriguez <mcgrof@kernel.org> | 2015-10-29 05:14:06 -0700 |
---|---|---|
committer | Luis R. Rodriguez <mcgrof@kernel.org> | 2016-02-11 08:42:16 -0800 |
commit | 4592db832826aa309534241259e7be0184d39d47 (patch) | |
tree | 23e5057162dc49dcfea3566af07280d51318b78f | |
parent | f4f49e1679169e5383762e36958fbd1a67718b8d (diff) | |
download | linker-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-- | Makefile | 2 | ||||
-rw-r--r-- | init.c | 8 | ||||
-rw-r--r-- | kasan.c | 17 | ||||
-rw-r--r-- | kasan.h | 4 | ||||
-rw-r--r-- | main.c | 20 | ||||
-rw-r--r-- | xen-driver.c | 26 | ||||
-rw-r--r-- | xen.c | 18 | ||||
-rw-r--r-- | xen.h | 2 |
8 files changed, 93 insertions, 4 deletions
@@ -24,6 +24,8 @@ OBJS = sort-init.o \ init.o \ pci.o \ driver.o \ + xen.o \ + xen-driver.o \ main.o main: $(OBJS) @@ -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 @@ -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, }; @@ -0,0 +1,4 @@ +#include <stdbool.h> + +int setup_kasan_bare_metal(void); +bool is_kasan_setup(void); @@ -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", +}; @@ -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; +} @@ -0,0 +1,2 @@ +bool booting_xen(void); +int xen_start(void); |