riscv-software-src / opensbi

RISC-V Open Source Supervisor Binary Interface
Other
1.04k stars 513 forks source link

semihosting_write bug in generic #339

Open zxtxin opened 11 months ago

zxtxin commented 11 months ago

semihosting_write is called in semihosting_puts which expects that semihosting_write returns the length it writes. Length minus the return value of syswrite trap which is normally the true length the syscall writes according to the convention is returned in the implementation of semihosting_write. So semihosting_write returns zero actually.

When I am debuging the opensbi with a debugger attached, I get infinite loop of printing 'OpenSBI 1.3.1'.

wxjstz commented 11 months ago

syscall normally return the number of bytes that are not written semihosting_write in opensbi normally return the number of bytes that has been written semihosting_puts in opensbi normally return the number of bytes that has been written

Regards, Xiang W

zxtxin commented 11 months ago

In linux, the syscall write returns the true length it writes. I don't know why there is a difference in the implementation of openocd.

zxtxin commented 11 months ago

I'm using the cklink from t-head to debug a riscv core C908. Its implementation complys with the convention of linux write

wxjstz commented 11 months ago

Its implementation complys with the convention of linux write

opensbi not running on linux. It running on debugger. You need to know how this debugger implements syscall. Like this: https://github.com/openocd-org/openocd/blob/master/src/target/semihosting_common.c#L1365

cp0613 commented 10 months ago

You can download the latest XuanTie Debug Server from https://www.xrvm.cn/ and add the -ls parameter at startup to use semihosting, such as # DebugServerConsole - prereset - ls

wxjstz commented 10 months ago

XuanTie implements a strange SYS_WRITE. Is this weird stuff going to spread to all software?