macsim/src/arch/riscv.c
// push the command line arguments on the stack
// argbuf is the concatination of argc zero-terminated strings
push the command line arguments on the stack
argbuf is the concatination of argc zero-terminated strings
push the command line arguments on the stack argbuf is the concatination of argc zero - terminated strings
void riscv_set_argv(node_t *node, int argc, char *argbuf)
{
    uint_fast64_t i, len=0;
    for (i=0; i<argc; i++) {
        while (argbuf[len]!=0) len++;
        len++;
    }
    addr_t sp = (RISCV_STACK_END - 8*(argc+2) - len) & RISCV_STACK_ALIGN_MASK;
    addr_t argbuf_addr = sp+8*(argc+2);
    addr_t ofs = 0;
    generic_memory_store(node, MA_64le, sp, argc);
    for (i=0; i<argc; i++) {
        generic_memory_store(node, MA_64le, sp+8+8*i, argbuf_addr+ofs);
        while (argbuf[ofs]!=0) ofs++;
        ofs++;
    }
    generic_memory_store(node, MA_64le, sp+8+8*argc, 0); 
    memory_write(node, argbuf_addr, (uint8_t *)argbuf, len);
    node->core.riscv.reg[2] = sp;
}
void riscv_set_argv ( node_t * node , int argc , char * argbuf ) { uint_fast64_t i , len = 0 ; for ( i = 0 ; i < argc ; i ++ ) { while ( argbuf [ len ] != 0 ) len ++ ; len ++ ; } addr_t sp = ( RISCV_STACK_END - 8 * ( argc + 2 ) - len ) & RISCV_STACK_ALIGN_MASK ; addr_t argbuf_addr = sp + 8 * ( argc + 2 ) ; addr_t ofs = 0 ; generic_memory_store ( node , MA_64le , sp , argc ) ; for ( i = 0 ; i < argc ; i ++ ) { generic_memory_store ( node , MA_64le , sp + 8 + 8 * i , argbuf_addr + ofs ) ; while ( argbuf [ ofs ] != 0 ) ofs ++ ; ofs ++ ; } generic_memory_store ( node , MA_64le , sp + 8 + 8 * argc , 0 ) ; memory_write ( node , argbuf_addr , ( uint8_t * ) argbuf , len ) ; node -> core . riscv . reg [ 2 ] = sp ; }
push the command line arguments on the stack
argbuf is the concatination of argc zero-terminated strings
push the command line arguments on the stack argbuf is the concatination of argc zero - terminated strings
// argv[argc] = 0