From d848bf4e17e4aff7063712c9a29f55cb2f7bb650 Mon Sep 17 00:00:00 2001 From: an7s <an7s@git.zephyr-software.com> Date: Thu, 5 Mar 2015 19:07:58 +0000 Subject: [PATCH] bring up to date -- stuff got lost in zipr transition --- .gitattributes | 1 + inferfn/infer.c | 95 ++++++++++++++++++++++++++++------------- inferfn/infer.h | 10 +++-- inferfn/infercallback.c | 15 +++---- inferfn/inferutil.h | 31 ++++++++++++++ 5 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 inferfn/inferutil.h diff --git a/.gitattributes b/.gitattributes index 763a7a1..2700a80 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,6 +10,7 @@ inferfn/Makefile.in -text inferfn/infer.c -text inferfn/infer.h -text inferfn/infercallback.c -text +inferfn/inferutil.h -text lib/Makefile.in -text lib/crt32.s -text lib/crt64.s -text diff --git a/inferfn/infer.c b/inferfn/infer.c index 9eade64..523360e 100644 --- a/inferfn/infer.c +++ b/inferfn/infer.c @@ -1,32 +1,15 @@ -#include "infer.h" +#include <stdint.h> +#include <syscall.h> #include <null.h> -static void clear_argument(struct argument *arg) -{ - if (!arg) return; - arg->type = ARG_NONE; -} - -static void clear_request(struct request *req) -{ - if (!req) return; - req->command = CMD_NONE; - req->num_args = 0; - clear_argument(&req->arg1); - clear_argument(&req->arg2); - clear_argument(&req->arg3); - clear_argument(&req->arg4); - req->outarg_type = ARG_NONE; -} +#include "infer.h" +#include "inferutil.h" -static void clear_response(struct response *res) +void print_str2(char *s) { - if (!res) return; - res->ok = 0; - res->outarg.type = ARG_NONE; + write(1,s,strlen(s)); } - static void send_response(const int fd, struct response *res) { cgc_transmit(fd, res, sizeof(struct response)); @@ -145,7 +128,6 @@ static void handleCall(struct request *req, struct response *res) retval = (*fn)(fa1, fa2, fa3); if (req->outarg_type == ARG_INT) { -// printf("return value = %d\n", retval); res->ok = 1; res->outarg.type = ARG_INT; res->outarg.val.num = retval; @@ -154,51 +136,90 @@ static void handleCall(struct request *req, struct response *res) res->ok = 1; res->outarg.type = ARG_PTR; res->outarg.val.addr = retval; - // printf("return value(addr) = %p\n", retval); return; - } + } else if (req->outarg_type == ARG_NONE) { + res->ok = 1; + res->outarg.type = ARG_NONE; + res->outarg.val.num = retval; + } } } static int handleCommand(const int fd, struct request *req, struct response *res) { + char buf[1024]; + print_str2("handleCommand(): enter\n"); clear_response(res); switch(req->command) { case CMD_ALLOC: + print_str2("handleCommand(): CMD_ALLOC\n"); handleAlloc(req, res); + + print_str2("ALLOC address:"); + itox(res->outarg.val.addr, buf); + print_str2(buf); + print_str2("\n"); + send_response(fd, res); return 0; break; case CMD_CALL: + itox(req->arg1.val.num, buf); + print_str2("handleCommand(): CMD_CALL arg1: "); + print_str2(buf); + + itox(req->arg2.val.num, buf); + print_str2(" arg2: "); + print_str2(buf); + + itox(req->arg3.val.num, buf); + print_str2(" arg3: "); + print_str2(buf); + + itox(req->arg4.val.num, buf); + print_str2(" arg4: "); + print_str2(buf); + + print_str2("\n"); + handleCall(req, res); send_response(fd, res); return 0; break; case CMD_READ: + print_str2("handleCommand(): CMD_READ\n"); handleRead(req, res); send_response(fd, res); return 0; break; case CMD_WRITE: + print_str2("handleCommand(): CMD_WRITE\n"); handleWrite(req, res); send_response(fd, res); return 0; break; case CMD_QUIT: - default: + print_str2("handleCommand(): CMD_QUIT\n"); return 1; + case CMD_NONE: + print_str2("handleCommand(): CMD_NONE\n"); + return 0; + break; + default: + return 0; break; } + print_str2("handleCommand(): exit\n"); return 1; } void commandLoop() { - int fdin = 0; // stdin - int fdout = 1; // stdout + int fdin = CINDERELLA_READ; + int fdout = CINDERELLA_WRITE; int done = 0; int bytes_read; char buf[sizeof(struct request) + 1024]; @@ -206,9 +227,23 @@ void commandLoop() struct request req; struct response res; + print_str2("commandLoop(): enter here\n"); + + char s[1024]; + do { clear_request(&req); - cgc_receive(fdin, &req, sizeof(struct request)); + int bytes_read = cgc_receive(fdin, &req, sizeof(struct request)); + itox(bytes_read, s); + + print_str2("commandLoop(): ... bytes read: \n"); + print_str2(s); + print_str2("\n"); + done = handleCommand(fdout, &req, &res); + + done = 0; } while (!done); + + print_str2("commandLoop(): exit\n"); } diff --git a/inferfn/infer.h b/inferfn/infer.h index 121e392..4586aed 100644 --- a/inferfn/infer.h +++ b/inferfn/infer.h @@ -1,11 +1,15 @@ #ifndef _INFER_FN_ #define _INFER_FN_ -#include <stdint.h> -#include <syscall.h> - #define MAX_NUM_BYTES 512 + +// 886..887 888..889 +#define CINDERELLA_DRIVER_READ 888 +#define CINDERELLA_DRIVER_WRITE 887 +#define CINDERELLA_READ 886 +#define CINDERELLA_WRITE 889 + /* * void* ALLOC <size> <value> * outarg CALL <fn*> [arg] [arg] [arg] diff --git a/inferfn/infercallback.c b/inferfn/infercallback.c index e7c597b..a4dae27 100644 --- a/inferfn/infercallback.c +++ b/inferfn/infercallback.c @@ -18,8 +18,11 @@ * */ +#include <stdint.h> #include "infer.h" +#define DEBUG 1 + #ifdef DEBUG #define print_str_debug print_str #define print_int_debug print_int @@ -32,8 +35,7 @@ #ifdef DEBUG -#if 0 // figure out a way to link these funcs iff someone needs them? -#define write_fd 2 +#define write_fd 1 void print_str(char *s) { write(write_fd,s,strlen(s)); @@ -45,7 +47,6 @@ void print_int(int x) write(write_fd,buf,strlen(buf)); } #endif -#endif @@ -63,14 +64,12 @@ typedef struct } reg_values_t; -void inference_handler(volatile int p_retaddress, volatile int p_address, volatile int p_exitPolicy, reg_values_t rv) +void inference_handler(volatile int p_retaddress, reg_values_t rv) { -#ifdef DEBUG - print_str("infer_handler() invoked\n"); -#endif + print_str("inference_handler(): enter\n"); commandLoop(); - + while(1); cgc_terminate(3); } diff --git a/inferfn/inferutil.h b/inferfn/inferutil.h new file mode 100644 index 0000000..77c7c5b --- /dev/null +++ b/inferfn/inferutil.h @@ -0,0 +1,31 @@ +#ifndef _INFERUTIL_FN_ +#define _INFERUTIL_FN_ + +#include "infer.h" + +void clear_argument(struct argument *arg) +{ + if (!arg) return; + arg->type = ARG_NONE; +} + +void clear_request(struct request *req) +{ + if (!req) return; + req->command = CMD_NONE; + req->num_args = 0; + clear_argument(&req->arg1); + clear_argument(&req->arg2); + clear_argument(&req->arg3); + clear_argument(&req->arg4); + req->outarg_type = ARG_NONE; +} + +void clear_response(struct response *res) +{ + if (!res) return; + res->ok = 0; + res->outarg.type = ARG_NONE; +} + +#endif -- GitLab