fd子系统3

This commit is contained in:
2026-04-18 12:36:32 +08:00
parent caf948f4f6
commit e83b51f220
6 changed files with 47 additions and 18 deletions

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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");

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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;
}
}