-
Hi, I'm auditing a Computer Architecture course and I found an issue #34, dear author @mortbopet mentioned "the use of a0 for environment calls is to match what Is there any suggestion to implement Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @asahsieh
The As such, if you have registered a compiler in Ripes and compile a simple program such as the following: #include <stdlib.h>
volatile int* a;
int main() {
a = malloc(5);
return 0;
} you'll see that the C standard library code which is linked into the executable will use
One caveat though; the implementation of the
Yes! i assume you're talking about an assembly implementation here. .data
# Here goes all of your static data...
a: .word 1
b: .word 2
c: .word 3
d: .word 4
brk_ptr: .word 0
# Define a symbol at the end of your static data segment. This will be where
# your heap will grow from.
_brk_start:
.text
# In your entry point to your program you need to setup your
# dynamic memory management. This also happens in a C program
# when initializing the standard library
_start:
la t0 _brk_start
la t1 brk_ptr
sw t0 0 t1
j main
main:
nop
# ...
sbrk:
# Load the current brk_ptr
# store it in a temporary reg
# modify it according to the argument in a0
# return the temporary reg (brk ptr before modification) |
Beta Was this translation helpful? Give feedback.
-
In theory, one can implement whatever you want inside those system calls;
|
Beta Was this translation helpful? Give feedback.
Hi @asahsieh
Thank you for using Ripes!
Venus' use of
sbrk
as ecall code 9 is a bit unconventional and (as far as i am aware of) Venus is the only simulator that actually does this. As mentioned in the issue, Ripes/RARS/... follow the riscv-proxy kernel ABI (as does the GCC toolchain) for system calls (https://github.com/riscv-software-src/riscv-pk/blob/master/pk/syscall.h).The
brk
syscall is implemented in Ripes here. This is what is used by the C standard library to implementmalloc
As such, if you have registered a compiler in Ripes and compile a simple program such as the following: