Skip to content

Commit e5e0983

Browse files
committed
Use direct file read
1 parent 0c21949 commit e5e0983

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

qemu_runner/Makefile

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,45 @@ rerun_ctest:
118118
# -monitor none \
119119
# -qmp unix:/tmp/qmp.sock,server=on,wait=off
120120

121+
# rerun-qemu-eest:
122+
# which script;
123+
# @if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
124+
# @N=$$(wc -c <"$(file-name)"); \
125+
# rm -f semihost.log; \
126+
# script -qefc "{ printf '123456789_123456789_123456789_123'; printf '1 %u\n' $$N; cat '$(file-name)'; } | \
127+
# qemu-system-riscv32 -M virt -m 2G -nographic \
128+
# -bios $(BUILD_DIR)/z6m_debug \
129+
# -chardev stdio,mux=on,id=stdio0,signal=off \
130+
# -serial chardev:stdio0 \
131+
# -semihosting-config enable=on,chardev=stdio0,target=native \
132+
# -monitor none" semihost.log
133+
134+
# rerun-qemu-eest:
135+
# @if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
136+
# @N=$$(wc -c <"$(file-name)"); \
137+
# rm -f semihost.log serial.log; \
138+
# { printf "123456789_123456789_123456789_123"; printf "1 %u\n" $$N; cat "$(file-name)"; } | \
139+
# qemu-system-riscv32 -M virt -m 2G -display none \
140+
# -bios $(BUILD_DIR)/z6m_debug \
141+
# -chardev stdio,id=sh0,signal=off \
142+
# -semihosting-config enable=on,target=native,chardev=sh0 \
143+
# -serial none \
144+
# -monitor none
145+
146+
121147
rerun-qemu-eest:
122148
@if [ -z "$(file-name)" ]; then echo "Usage: make rerun-qemu-eest file-name=path/to.json"; exit 1; fi
123149
@N=$$(wc -c <"$(file-name)"); \
124-
set -e; \
125-
rm -f semihost.log serial.log stdin_payload.bin; \
126-
{ printf "123456789_123456789_123456789_123"; printf "1 %u\n" $$N; cat "$(file-name)"; } > stdin_payload.bin; \
127-
script -qec "cat stdin_payload.bin | \
128-
qemu-system-riscv32 -M virt -m 2G -nographic \
129-
-bios $(BUILD_DIR)/z6m_debug \
130-
-chardev stdio,mux=on,id=stdio0 \
131-
-serial chardev:stdio0 \
132-
-semihosting-config enable=on,chardev=stdio0 \
133-
-monitor none" semihost.log
134-
135-
# Clean build artifacts
150+
rm -f semihost.log serial.log; \
151+
{ printf "1 %u\n" $$N; cat "$(file-name)"; } > stdin_payload.bin; \
152+
qemu-system-riscv32 -M virt -m 2G -display none \
153+
-bios $(BUILD_DIR)/z6m_debug \
154+
-chardev stdio,id=sh0,signal=off \
155+
-semihosting-config enable=on,target=native,chardev=sh0 \
156+
-serial none \
157+
-monitor none
158+
159+
# # Clean build artifacts
136160
.PHONY: clean
137161
clean:
138162
rm -rf $(BUILD_DIR)

qemu_runner/src/include/semihosting.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ namespace sh
132132
return static_cast<int>(h); // -1 on failure
133133
}
134134

135+
inline int open_file_read(std::string path)
136+
{
137+
struct Args
138+
{
139+
const char* name;
140+
int mode;
141+
int name_len;
142+
} a{ path.c_str(), 0, static_cast<int>(path.size()) };
143+
144+
long h = call(SYS_OPEN, &a);
145+
return static_cast<int>(h);
146+
}
147+
135148
// ================= SYS_READ ==========================
136149
// SYS_READ (0x06) = “read N bytes from a file handle”
137150
// NOTE: Does not work without opening a file handle
@@ -166,6 +179,7 @@ namespace sh
166179
{
167180
std::size_t len = (n - off) >= block_size ? block_size : (n - off);
168181
std::size_t got = read_handle(handle, static_cast<char*>(buf) + off, len);
182+
169183
// if (got == 0)
170184
// {
171185
// sys_println("read_exact_tty - got 0, probable EOF");

qemu_runner/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main(int argc, char* argv[])
1212
std::uint32_t n = 0;
1313

1414
// Open a handle
15-
int h = sh::open_tty_read();
15+
int h = sh::open_file_read("stdin_payload.bin");
1616
if (h < 0)
1717
{
1818
sys_println("Failed to open tty_read");

0 commit comments

Comments
 (0)