From a03a60b90e7bc8fc35f797959c8b47d8dc887c3f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 6 Jul 2014 21:06:53 +0200 Subject: [PATCH] Variadic function demo --- examples/coredev_test.py | 2 +- soc/runtime/main.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/coredev_test.py b/examples/coredev_test.py index 8985515f4..dda0e4719 100644 --- a/examples/coredev_test.py +++ b/examples/coredev_test.py @@ -16,7 +16,7 @@ class CompilerTest(Experiment): prime = 0 d = d + 1 if prime == 1: - syscall("print_int", x) + syscall("rpc", 42, x) x = x + 1 self.led.set(0) diff --git a/soc/runtime/main.c b/soc/runtime/main.c index 2559815e7..c78402d86 100644 --- a/soc/runtime/main.c +++ b/soc/runtime/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -55,9 +56,17 @@ static int download_kernel(void *buffer, int maxlength) return length; } -static void print_int(int x) +static int rpc(int rpc_num, int n_args, ...) { - printf("%d\n", x); + printf("rpc_num=%d n_args=%d\n", rpc_num, n_args); + + va_list args; + va_start(args, n_args); + while(n_args--) + printf("%d\n", va_arg(args, int)); + va_end(args); + + return 1; } static void gpio_set(int channel, int level) @@ -66,7 +75,7 @@ static void gpio_set(int channel, int level) } static const struct symbol syscalls[] = { - {"__syscall_print_int", print_int}, + {"__syscall_rpc", rpc}, {"__syscall_gpio_set", gpio_set}, {NULL, NULL} }; @@ -78,7 +87,6 @@ int main(void) unsigned char kbuf[256*1024]; unsigned char kcode[256*1024]; kernel_function k = (kernel_function)kcode; - int i; int length; irq_setmask(0);