From e83b51f220c704d41e7e61c37cb9c9c9de9dc354 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 18 Apr 2026 12:36:32 +0800 Subject: [PATCH] =?UTF-8?q?fd=E5=AD=90=E7=B3=BB=E7=BB=9F3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cleonos/c/apps/cmd_runtime.c | 18 ++++++++++++++++-- cleonos/c/apps/hello_main.c | 2 +- cleonos/c/apps/shell/shell_input.c | 18 ++++++++++++------ cleonos/c/apps/shell/shell_util.c | 16 ++++++++++++++-- cleonos/c/apps/spin_main.c | 2 +- cleonos/c/apps/top_main.c | 9 +++------ 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/cleonos/c/apps/cmd_runtime.c b/cleonos/c/apps/cmd_runtime.c index 869f77d..47d93c2 100644 --- a/cleonos/c/apps/cmd_runtime.c +++ b/cleonos/c/apps/cmd_runtime.c @@ -221,6 +221,8 @@ void ush_parse_line(const char *line, char *out_cmd, u64 cmd_size, char *out_arg void ush_write(const char *text) { u64 len; + const char *cursor; + u64 left; if (text == (const char *)0) { return; @@ -232,11 +234,23 @@ void ush_write(const char *text) { return; } - (void)cleonos_sys_tty_write(text, len); + cursor = text; + left = len; + + while (left > 0ULL) { + u64 wrote = cleonos_sys_fd_write(1ULL, cursor, left); + + if (wrote == 0ULL || wrote == (u64)-1) { + break; + } + + cursor += wrote; + left -= wrote; + } } void ush_write_char(char ch) { - (void)cleonos_sys_tty_write_char(ch); + (void)cleonos_sys_fd_write(1ULL, &ch, 1ULL); } void ush_writeln(const char *text) { diff --git a/cleonos/c/apps/hello_main.c b/cleonos/c/apps/hello_main.c index d41bf16..405f9c8 100644 --- a/cleonos/c/apps/hello_main.c +++ b/cleonos/c/apps/hello_main.c @@ -2,6 +2,6 @@ int cleonos_app_main(void) { static const char msg[] = "[USER][HELLO] Hello world from /hello.elf\n"; - (void)cleonos_sys_tty_write(msg, (u64)(sizeof(msg) - 1U)); + (void)cleonos_sys_fd_write(1ULL, msg, (u64)(sizeof(msg) - 1U)); return 0; } diff --git a/cleonos/c/apps/shell/shell_input.c b/cleonos/c/apps/shell/shell_input.c index 93c6fa4..4deeda7 100644 --- a/cleonos/c/apps/shell/shell_input.c +++ b/cleonos/c/apps/shell/shell_input.c @@ -326,13 +326,19 @@ static void ush_render_emit(const char *buffer, u64 length) { while (offset < length) { u64 chunk = length - offset; + u64 written; if (chunk > USH_RENDER_EMIT_CHUNK) { chunk = USH_RENDER_EMIT_CHUNK; } - (void)cleonos_sys_tty_write(buffer + offset, chunk); - offset += chunk; + written = cleonos_sys_fd_write(1ULL, buffer + offset, chunk); + + if (written == 0ULL || written == (u64)-1) { + break; + } + + offset += written; } } @@ -466,11 +472,11 @@ static void ush_history_down(ush_state *sh) { } static char ush_read_char_blocking(void) { - for (;;) { - u64 ch = cleonos_sys_kbd_get_char(); + char ch = '\0'; - if (ch != (u64)-1) { - return (char)(ch & 0xFFULL); + for (;;) { + if (cleonos_sys_fd_read(0ULL, &ch, 1ULL) == 1ULL) { + return ch; } __asm__ volatile("pause"); diff --git a/cleonos/c/apps/shell/shell_util.c b/cleonos/c/apps/shell/shell_util.c index 98e424f..1e28bb6 100644 --- a/cleonos/c/apps/shell/shell_util.c +++ b/cleonos/c/apps/shell/shell_util.c @@ -341,7 +341,19 @@ void ush_write(const char *text) { } if (should_write_tty != 0) { - (void)cleonos_sys_tty_write(text, len); + const char *cursor = text; + u64 left = len; + + while (left > 0ULL) { + u64 wrote = cleonos_sys_fd_write(1ULL, cursor, left); + + if (wrote == 0ULL || wrote == (u64)-1) { + break; + } + + cursor += wrote; + left -= wrote; + } } } @@ -365,7 +377,7 @@ void ush_write_char(char ch) { } if (should_write_tty != 0) { - (void)cleonos_sys_tty_write_char(ch); + (void)cleonos_sys_fd_write(1ULL, &ch, 1ULL); } } diff --git a/cleonos/c/apps/spin_main.c b/cleonos/c/apps/spin_main.c index dd744a7..416bb7f 100644 --- a/cleonos/c/apps/spin_main.c +++ b/cleonos/c/apps/spin_main.c @@ -5,7 +5,7 @@ int cleonos_app_main(void) { "spin: busy loop started (test Alt+Ctrl+C force stop)\n"; volatile u64 noise = 0xC1E0C1E0ULL; - (void)cleonos_sys_tty_write(banner, (u64)(sizeof(banner) - 1U)); + (void)cleonos_sys_fd_write(1ULL, banner, (u64)(sizeof(banner) - 1U)); for (;;) { noise ^= (noise << 7); diff --git a/cleonos/c/apps/top_main.c b/cleonos/c/apps/top_main.c index 054a5a1..1df3388 100644 --- a/cleonos/c/apps/top_main.c +++ b/cleonos/c/apps/top_main.c @@ -147,18 +147,15 @@ static void ush_top_render_frame(u64 frame_index, u64 delay_ticks) { static int ush_top_sleep_or_quit(u64 delay_ticks) { u64 i; + char ch = '\0'; if (delay_ticks == 0ULL) { delay_ticks = 1ULL; } for (i = 0ULL; i < delay_ticks; i++) { - u64 ch = cleonos_sys_kbd_get_char(); - - if (ch != (u64)-1) { - char c = (char)(ch & 0xFFULL); - - if (c == 'q' || c == 'Q') { + if (cleonos_sys_fd_read(0ULL, &ch, 1ULL) == 1ULL) { + if (ch == 'q' || ch == 'Q') { return 1; } }