opensbi icon indicating copy to clipboard operation
opensbi copied to clipboard

semihosting_write bug in generic

Open zxtxin opened this issue 2 years ago • 7 comments

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'.

zxtxin avatar Dec 15 '23 02:12 zxtxin

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

wxjstz avatar Dec 20 '23 13:12 wxjstz

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 avatar Dec 21 '23 06:12 zxtxin

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

zxtxin avatar Dec 21 '23 06:12 zxtxin

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

wxjstz avatar Dec 21 '23 09:12 wxjstz

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

cp0613 avatar Jan 10 '24 08:01 cp0613

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

wxjstz avatar Jan 12 '24 05:01 wxjstz