rustsbi/rustsbi-qemu

rustsbi and opensbi getchar differences

PorterLu opened this issue · 1 comments

I found that opensbi and rustsbi have different getchar implemenation. Opensbi will return -1(or we can say 255) if it does not receive a char, but rustsbi will wait until getting char.

legacy::LEGACY_CONSOLE_GETCHAR => {
    ret.error = unsafe { UART.lock().assume_init_mut() }.receive() as _;
    ret.value = a1;
}

The above is the implementation of rustsbi, and I found the implementation of receive as shown below. So the implementations of opensbi and rustsbi are totally different.

pub fn receive(&mut self) -> u8 {
        let self_data = self.data.load(Ordering::Relaxed);
        unsafe {
            wait_for!(self.line_sts().contains(LineStsFlags::INPUT_FULL));
            self_data.read()
        }
    }

But the following sbi doc describes that we should return -1 when error. So what I want to ask is whether this is a difference or mistake.

5.3. Extension: Console Getchar (EID #0x02)
long sbi_console_getchar(void)
Read a byte from debug console.

The SBI call returns the byte on success, or -1 for failure.

Is anyone here? I found this in rCore code. If it's not that matter, I will skip it and take it as a feature difference.