ARC-V: Newlib: Add support of argument passing to the bare-meteal application via semihosting
Closed this issue · 2 comments
It's convenient and sometimes even necessary to pass some parameters to the application. In embedded world and bare-metal applications clearly that's not needed in mission mode, but for testing and debugging it's a handy feature to have.
And for that to happen we basically need to get those arguments in the target's memory and refer to argc
& argv
on call to main()
.
Which means before calling main()
we need to get that data, put that in the memory and populate a0
& a1
registers similarly how we implemented that for ARC Classic back in the day foss-for-synopsys-dwc-arc-processors/newlib#14 but with use of semihosting.
As of today, in Newlib's libgloss for RISC-V assumes that both argc
& argv
is already on stack and so just uses stack-pointer for initialization, see https://github.com/bminor/newlib/blob/master/libgloss/riscv/crt0.S#L62:
lw a0, 0(sp) # a0 = argc
addi a1, sp, __SIZEOF_POINTER__ # a1 = argv
slli a2, a0, 1 + __SIZEOF_POINTER__ >> 2
addi a2, a2, __SIZEOF_POINTER__
add a2, a2, a1 # a2 = envp
call main
But that requires additional actions from the host before execution starts.
Or alternatively we may use semihosting from the target for getting input arguments. Good example is Picolibc, see https://github.com/picolibc/picolibc/blob/main/picocrt/crt0.h#L103.
Implemented and pushed to arc64 branch:
@kolerov please note that ARC-V daily builds use arcvx
branch, not arc64