Home > other >  RISCV printf under variable parameters of resolving problems
RISCV printf under variable parameters of resolving problems

Time:05-28

In debugging riscv recently, no use printf function under the tool chain, transform the printf function, but found during debugging, needs to be formatted output characters in pintf has been unable to find, but the string can be normal output, the minimalist demo is as follows:
Int printf_s (const char * FMT,... )
{
Va_list vaArgP;

//
//Start the varargs processing.
//
Va_start (vaArgP, FMT);

Va_end (vaArgP);

return 0;
}
I now know is variable parameter parsing va_start find function parameters will be used within the stack address, in general, FMT and vaArgP stack is continuous, the inside address and the address of the variable parameter vaArgP said, this usage under the arm is functioning, but found that under the riscv the printf function can be correctly, under the same way, vaArgP said variable parameters correctly is no longer part of the data,

The disassembly see assembly code as follows:

Own definition printf_s function parameter stack pressure action, a0, a1 is pressed into the different stack address, a0, a1 just said is printf_s function parameters,
Because the two address is not continuous address, so using va_start the stack pointer has not got the address of parameter correctly,

The variable parameter function argument parsing looked at normal usage under the arm, but now cannot be used correctly under riscv,
So want to please bosses to look at, the parameters of the variable parameter function under riscv resolve how to get the correct parameters,
Thank you ~ ~
  • Related