aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2016-03-05 16:19:50 -0800
committerAndrew Waterman <waterman@cs.berkeley.edu>2016-03-05 16:19:50 -0800
commit33ed6c6c5e28f016bcfa341479ce97bf80d7d104 (patch)
tree95e1c9de234426b7508be85b509d9f881765018f
parent80447e5711461fa58cf61d17a6a1b79f7dcd5294 (diff)
downloadriscv-pk-33ed6c6c5e28f016bcfa341479ce97bf80d7d104.zip
riscv-pk-33ed6c6c5e28f016bcfa341479ce97bf80d7d104.tar.gz
riscv-pk-33ed6c6c5e28f016bcfa341479ce97bf80d7d104.tar.bz2
get rid of struct mainvars
-rw-r--r--pk/bbl.c2
-rw-r--r--pk/boot.h7
-rw-r--r--pk/init.c34
-rw-r--r--pk/pk.c20
4 files changed, 33 insertions, 30 deletions
diff --git a/pk/bbl.c b/pk/bbl.c
index 031fa08..5ace350 100644
--- a/pk/bbl.c
+++ b/pk/bbl.c
@@ -13,7 +13,7 @@ static void enter_entry_point()
__builtin_unreachable();
}
-void run_loaded_program(struct mainvars* args)
+void run_loaded_program(size_t argc, char** argv)
{
if (!current.is_supervisor)
die("bbl can't run user binaries; try using pk instead");
diff --git a/pk/boot.h b/pk/boot.h
index d0d97d6..d66cc11 100644
--- a/pk/boot.h
+++ b/pk/boot.h
@@ -8,11 +8,6 @@
#include <stdint.h>
#include <stddef.h>
-struct mainvars {
- uint64_t argc;
- uint64_t argv[127]; // this space is shared with the arg strings themselves
-};
-
typedef struct {
int phent;
int phnum;
@@ -36,7 +31,7 @@ typedef struct {
extern elf_info current;
void prepare_supervisor_mode();
-void run_loaded_program(struct mainvars*);
+void run_loaded_program(size_t argc, char** argv);
void boot_loader();
void boot_other_hart();
void load_elf(const char* fn, elf_info* info);
diff --git a/pk/init.c b/pk/init.c
index 6a459f9..11e17bd 100644
--- a/pk/init.c
+++ b/pk/init.c
@@ -44,31 +44,39 @@ static void handle_option(const char* s)
}
}
-static struct mainvars* parse_args(struct mainvars* args)
+#define MAX_ARGS 64
+typedef union {
+ uint64_t buf[MAX_ARGS];
+ char* argv[MAX_ARGS];
+} arg_buf;
+
+static size_t parse_args(arg_buf* args)
{
long r = frontend_syscall(SYS_getmainvars, (uintptr_t)args, sizeof(*args), 0, 0, 0, 0, 0);
kassert(r == 0);
+ uint64_t* pk_argv = &args->buf[1];
+ // pk_argv[0] is the proxy kernel itself. skip it and any flags.
+ size_t pk_argc = args->buf[0], arg = 1;
+ for ( ; arg < pk_argc && *(char*)(uintptr_t)pk_argv[arg] == '-'; arg++)
+ handle_option((const char*)(uintptr_t)pk_argv[arg]);
- // argv[0] is the proxy kernel itself. skip it and any flags.
- unsigned a0 = 1;
- for ( ; a0 < args->argc && *(char*)(uintptr_t)args->argv[a0] == '-'; a0++)
- handle_option((const char*)(uintptr_t)args->argv[a0]);
- args->argv[a0-1] = args->argc - a0;
- return (struct mainvars*)&args->argv[a0-1];
+ for (size_t i = 0; arg + i < pk_argc; i++)
+ args->argv[i] = (char*)(uintptr_t)pk_argv[arg + i];
+ return pk_argc - arg;
}
void boot_loader()
{
- struct mainvars arg_buffer;
- struct mainvars *args = parse_args(&arg_buffer);
+ arg_buf args;
+ size_t argc = parse_args(&args);
+ if (!argc)
+ panic("tell me what ELF to load!");
// load program named by argv[0]
long phdrs[128];
current.phdr = (uintptr_t)phdrs;
current.phdr_size = sizeof(phdrs);
- if (!args->argc)
- panic("tell me what ELF to load!");
- load_elf((char*)(uintptr_t)args->argv[0], &current);
+ load_elf(args.argv[0], &current);
- run_loaded_program(args);
+ run_loaded_program(argc, args.argv);
}
diff --git a/pk/pk.c b/pk/pk.c
index 8a0e588..6318963 100644
--- a/pk/pk.c
+++ b/pk/pk.c
@@ -3,7 +3,7 @@
#include "vm.h"
#include "elf.h"
-void run_loaded_program(struct mainvars* args)
+void run_loaded_program(size_t argc, char** argv)
{
if (current.is_supervisor)
panic("pk can't run kernel binaries; try using bbl instead");
@@ -25,11 +25,11 @@ void run_loaded_program(struct mainvars* args)
current.phdr = stack_top;
// copy argv to user stack
- for (size_t i = 0; i < args->argc; i++) {
- size_t len = strlen((char*)(uintptr_t)args->argv[i])+1;
+ for (size_t i = 0; i < argc; i++) {
+ size_t len = strlen((char*)(uintptr_t)argv[i])+1;
stack_top -= len;
- memcpy((void*)stack_top, (void*)(uintptr_t)args->argv[i], len);
- args->argv[i] = stack_top;
+ memcpy((void*)stack_top, (void*)(uintptr_t)argv[i], len);
+ argv[i] = (void*)stack_top;
}
stack_top &= -sizeof(void*);
@@ -49,18 +49,18 @@ void run_loaded_program(struct mainvars* args)
// place argc, argv, envp, auxp on stack
#define PUSH_ARG(type, value) do { \
- *((type*)sp) = value; \
+ *((type*)sp) = (type)value; \
sp += sizeof(type); \
} while (0)
#define STACK_INIT(type) do { \
unsigned naux = sizeof(aux)/sizeof(aux[0]); \
- stack_top -= (1 + args->argc + 1 + 1 + 2*naux) * sizeof(type); \
+ stack_top -= (1 + argc + 1 + 1 + 2*naux) * sizeof(type); \
stack_top &= -16; \
long sp = stack_top; \
- PUSH_ARG(type, args->argc); \
- for (unsigned i = 0; i < args->argc; i++) \
- PUSH_ARG(type, args->argv[i]); \
+ PUSH_ARG(type, argc); \
+ for (unsigned i = 0; i < argc; i++) \
+ PUSH_ARG(type, argv[i]); \
PUSH_ARG(type, 0); /* argv[argc] = NULL */ \
PUSH_ARG(type, 0); /* envp[0] = NULL */ \
for (unsigned i = 0; i < naux; i++) { \