1/* 2 * Copyright 2018, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#include <string.h> 14#include <byteswap.h> 15 16/* argc and argv are exported in cake.S */ 17extern unsigned int argc; 18extern char **argv; 19 20void ffiget_arg_count(unsigned char *c, long clen, unsigned char *a, long alen) { 21 uint16_t result = bswap_16(argc); 22 memcpy(a, &result, sizeof(result)); 23} 24 25void ffiget_arg_length(unsigned char *c, long clen, unsigned char *a, long alen) { 26 uint16_t arg; 27 memcpy(&arg, a, sizeof(arg)); 28 arg = bswap_16(arg); 29 uint16_t len_result = bswap_16(strlen(argv[arg])); 30 memcpy(a, &len_result, sizeof(len_result)); 31} 32 33void ffiget_arg(unsigned char *c, long clen, unsigned char *a, long alen) { 34 uint16_t arg; 35 memcpy(&arg, a, sizeof(arg)); 36 arg = bswap_16(arg); 37 strcpy(a, argv[arg]); 38} 39