mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-21 10:40:00 +00:00
fd子系统3
This commit is contained in:
@@ -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) {
|
void ush_write(const char *text) {
|
||||||
u64 len;
|
u64 len;
|
||||||
|
const char *cursor;
|
||||||
|
u64 left;
|
||||||
|
|
||||||
if (text == (const char *)0) {
|
if (text == (const char *)0) {
|
||||||
return;
|
return;
|
||||||
@@ -232,11 +234,23 @@ void ush_write(const char *text) {
|
|||||||
return;
|
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 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) {
|
void ush_writeln(const char *text) {
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
int cleonos_app_main(void) {
|
int cleonos_app_main(void) {
|
||||||
static const char msg[] = "[USER][HELLO] Hello world from /hello.elf\n";
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,13 +326,19 @@ static void ush_render_emit(const char *buffer, u64 length) {
|
|||||||
|
|
||||||
while (offset < length) {
|
while (offset < length) {
|
||||||
u64 chunk = length - offset;
|
u64 chunk = length - offset;
|
||||||
|
u64 written;
|
||||||
|
|
||||||
if (chunk > USH_RENDER_EMIT_CHUNK) {
|
if (chunk > USH_RENDER_EMIT_CHUNK) {
|
||||||
chunk = USH_RENDER_EMIT_CHUNK;
|
chunk = USH_RENDER_EMIT_CHUNK;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cleonos_sys_tty_write(buffer + offset, chunk);
|
written = cleonos_sys_fd_write(1ULL, buffer + offset, chunk);
|
||||||
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) {
|
static char ush_read_char_blocking(void) {
|
||||||
for (;;) {
|
char ch = '\0';
|
||||||
u64 ch = cleonos_sys_kbd_get_char();
|
|
||||||
|
|
||||||
if (ch != (u64)-1) {
|
for (;;) {
|
||||||
return (char)(ch & 0xFFULL);
|
if (cleonos_sys_fd_read(0ULL, &ch, 1ULL) == 1ULL) {
|
||||||
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
__asm__ volatile("pause");
|
__asm__ volatile("pause");
|
||||||
|
|||||||
@@ -341,7 +341,19 @@ void ush_write(const char *text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (should_write_tty != 0) {
|
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) {
|
if (should_write_tty != 0) {
|
||||||
(void)cleonos_sys_tty_write_char(ch);
|
(void)cleonos_sys_fd_write(1ULL, &ch, 1ULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ int cleonos_app_main(void) {
|
|||||||
"spin: busy loop started (test Alt+Ctrl+C force stop)\n";
|
"spin: busy loop started (test Alt+Ctrl+C force stop)\n";
|
||||||
volatile u64 noise = 0xC1E0C1E0ULL;
|
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 (;;) {
|
for (;;) {
|
||||||
noise ^= (noise << 7);
|
noise ^= (noise << 7);
|
||||||
|
|||||||
@@ -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) {
|
static int ush_top_sleep_or_quit(u64 delay_ticks) {
|
||||||
u64 i;
|
u64 i;
|
||||||
|
char ch = '\0';
|
||||||
|
|
||||||
if (delay_ticks == 0ULL) {
|
if (delay_ticks == 0ULL) {
|
||||||
delay_ticks = 1ULL;
|
delay_ticks = 1ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0ULL; i < delay_ticks; i++) {
|
for (i = 0ULL; i < delay_ticks; i++) {
|
||||||
u64 ch = cleonos_sys_kbd_get_char();
|
if (cleonos_sys_fd_read(0ULL, &ch, 1ULL) == 1ULL) {
|
||||||
|
if (ch == 'q' || ch == 'Q') {
|
||||||
if (ch != (u64)-1) {
|
|
||||||
char c = (char)(ch & 0xFFULL);
|
|
||||||
|
|
||||||
if (c == 'q' || c == 'Q') {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user