From 8fe903a9ff94d423d3dd836afbd7528bcaaa0d84 Mon Sep 17 00:00:00 2001 From: jn Date: Mon, 30 Jan 2023 21:28:33 +0100 Subject: [PATCH] kernel/vfs: Don't ignore buffer length in read(stream) --- applications/sh/main.asm | 2 +- applications/terminal/main.asm | 4 +++- applications/terminal/stream.asm | 2 ++ kernel/vfs.asm | 28 ++++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/applications/sh/main.asm b/applications/sh/main.asm index 67f58a5..c743c33 100644 --- a/applications/sh/main.asm +++ b/applications/sh/main.asm @@ -8,6 +8,7 @@ shell_task_return: call shell_clear_buffer call shell_print_prompt shell_task_loop: + mov r0, 1 mov r1, [shell_terminal_stream_struct_ptr] mov r2, shell_char_buffer call read @@ -16,7 +17,6 @@ shell_task_loop: cmp.8 r0, 0 ifnz call shell_task_parse_key - call yield_task rjmp shell_task_loop shell_task_parse_key: diff --git a/applications/terminal/main.asm b/applications/terminal/main.asm index bac675e..8fd4276 100644 --- a/applications/terminal/main.asm +++ b/applications/terminal/main.asm @@ -40,7 +40,9 @@ event_loop_end: call is_task_id_used ifz jmp close_window call yield_task - mov.8 [read_buffer], 0 + cmp.8 [read_buffer_ack], 1 + ifz mov.8 [read_buffer], 0 + ifz mov.8 [read_buffer_ack], 0 rjmp event_loop mouse_down: diff --git a/applications/terminal/stream.asm b/applications/terminal/stream.asm index afcd796..5cca348 100644 --- a/applications/terminal/stream.asm +++ b/applications/terminal/stream.asm @@ -9,6 +9,8 @@ stream_write_to_terminal: stream_get_input: mov r0, [read_buffer] + mov [read_buffer_ack], 1 ret read_buffer: data.32 0 +read_buffer_ack: data.32 0 diff --git a/kernel/vfs.asm b/kernel/vfs.asm index 4d45785..531cbac 100644 --- a/kernel/vfs.asm +++ b/kernel/vfs.asm @@ -53,11 +53,11 @@ tell: ; read specified number of bytes into the specified buffer ; inputs: -; r0: number of bytes to read (ignored if file struct is a stream) +; r0: number of bytes to read ; r1: pointer to file struct -; r2: pointer to destination buffer (always 4 bytes if file struct is a stream) +; r2: pointer to destination buffer ; outputs: -; none +; r0: number of bytes left to read (streams can read short) read: push r3 push r1 @@ -73,6 +73,26 @@ read: pop r3 ret stream_read: + push r1 + push r2 + +stream_read_loop: + call stream_read_char + call yield_task + + cmp.8 [r2], 0 + ifz jmp stream_read_out + + inc r2 + dec r0 + ifnz jmp stream_read_loop + +stream_read_out: + pop r2 + pop r1 + ret + +stream_read_char: push r0 push r1 push r2 @@ -83,7 +103,7 @@ stream_read: ; put the result into [r2] pop r2 - mov [r2], r0 + mov.8 [r2], r0 pop r1 pop r0