试图修复bug但没成功+CLeonOS Wine

This commit is contained in:
2026-04-12 21:13:50 +08:00
parent 901b63b9ba
commit 8f10d6a16c
10 changed files with 1974 additions and 83 deletions

View File

@@ -160,7 +160,6 @@ void clks_fb_scroll_up(u32 pixel_rows, u32 fill_rgb) {
usize row_bytes;
usize move_bytes;
u32 y;
u32 x;
if (clks_fb.ready == CLKS_FALSE) {
return;
@@ -189,8 +188,11 @@ void clks_fb_scroll_up(u32 pixel_rows, u32 fill_rgb) {
);
for (y = clks_fb.info.height - pixel_rows; y < clks_fb.info.height; y++) {
volatile u32 *row_ptr = (volatile u32 *)(clks_fb.address + ((usize)y * row_bytes));
u32 x;
for (x = 0U; x < clks_fb.info.width; x++) {
clks_fb_put_pixel(x, y, fill_rgb);
row_ptr[x] = fill_rgb;
}
}
}
@@ -202,11 +204,21 @@ void clks_fb_draw_char(u32 x, u32 y, char ch, u32 fg_rgb, u32 bg_rgb) {
u32 cols;
u32 rows;
u32 row_stride;
u32 draw_cols;
u32 draw_rows;
if (clks_fb.ready == CLKS_FALSE || clks_fb.font == CLKS_NULL) {
return;
}
if (clks_fb.info.bpp != 32) {
return;
}
if (x >= clks_fb.info.width || y >= clks_fb.info.height) {
return;
}
glyph = clks_psf_glyph(clks_fb.font, (u32)(u8)ch);
cols = clks_fb.glyph_width;
@@ -234,14 +246,26 @@ void clks_fb_draw_char(u32 x, u32 y, char ch, u32 fg_rgb, u32 bg_rgb) {
return;
}
for (row = 0U; row < rows; row++) {
const u8 *row_bits = glyph + ((usize)row * (usize)row_stride);
draw_cols = cols;
if (x + draw_cols > clks_fb.info.width) {
draw_cols = clks_fb.info.width - x;
}
for (col = 0U; col < cols; col++) {
draw_rows = rows;
if (y + draw_rows > clks_fb.info.height) {
draw_rows = clks_fb.info.height - y;
}
for (row = 0U; row < draw_rows; row++) {
const u8 *row_bits = glyph + ((usize)row * (usize)row_stride);
volatile u32 *dst_row = (volatile u32 *)(
clks_fb.address + ((usize)(y + row) * (usize)clks_fb.info.pitch) + ((usize)x * 4U)
);
for (col = 0U; col < draw_cols; col++) {
u8 bits = row_bits[col >> 3U];
u8 mask = (u8)(0x80U >> (col & 7U));
u32 color = (bits & mask) != 0U ? fg_rgb : bg_rgb;
clks_fb_put_pixel(x + col, y + row, color);
dst_row[col] = (bits & mask) != 0U ? fg_rgb : bg_rgb;
}
}
}
@@ -266,3 +290,4 @@ u32 clks_fb_cell_width(void) {
u32 clks_fb_cell_height(void) {
return clks_fb.glyph_height == 0U ? 8U : clks_fb.glyph_height;
}

View File

@@ -7,5 +7,7 @@ void clks_exec_init(void);
clks_bool clks_exec_run_path(const char *path, u64 *out_status);
u64 clks_exec_request_count(void);
u64 clks_exec_success_count(void);
clks_bool clks_exec_is_running(void);
#endif
#endif

View File

@@ -15,6 +15,7 @@ extern u64 clks_exec_call_on_stack_x86_64(void *entry_ptr, void *stack_top);
static u64 clks_exec_requests = 0ULL;
static u64 clks_exec_success = 0ULL;
static u32 clks_exec_running_depth = 0U;
static clks_bool clks_exec_invoke_entry(void *entry_ptr, u64 *out_ret) {
if (entry_ptr == CLKS_NULL || out_ret == CLKS_NULL) {
@@ -45,6 +46,7 @@ static clks_bool clks_exec_invoke_entry(void *entry_ptr, u64 *out_ret) {
void clks_exec_init(void) {
clks_exec_requests = 0ULL;
clks_exec_success = 0ULL;
clks_exec_running_depth = 0U;
clks_log(CLKS_LOG_INFO, "EXEC", "PATH EXEC FRAMEWORK ONLINE");
}
@@ -100,12 +102,20 @@ clks_bool clks_exec_run_path(const char *path, u64 *out_status) {
clks_log_hex(CLKS_LOG_INFO, "EXEC", "ENTRY", info.entry);
clks_log_hex(CLKS_LOG_INFO, "EXEC", "PHNUM", (u64)info.phnum);
clks_exec_running_depth++;
if (clks_exec_invoke_entry(entry_ptr, &run_ret) == CLKS_FALSE) {
if (clks_exec_running_depth > 0U) {
clks_exec_running_depth--;
}
clks_log(CLKS_LOG_WARN, "EXEC", "EXEC RUN INVOKE FAILED");
clks_log(CLKS_LOG_WARN, "EXEC", path);
clks_elf64_unload(&loaded);
return CLKS_FALSE;
}
if (clks_exec_running_depth > 0U) {
clks_exec_running_depth--;
}
clks_log(CLKS_LOG_INFO, "EXEC", "RUN RETURNED");
clks_log(CLKS_LOG_INFO, "EXEC", path);
@@ -128,3 +138,8 @@ u64 clks_exec_request_count(void) {
u64 clks_exec_success_count(void) {
return clks_exec_success;
}
clks_bool clks_exec_is_running(void) {
return (clks_exec_running_depth > 0U) ? CLKS_TRUE : CLKS_FALSE;
}

View File

@@ -1,3 +1,4 @@
#include <clks/exec.h>
#include <clks/keyboard.h>
#include <clks/log.h>
#include <clks/shell.h>
@@ -105,6 +106,18 @@ static clks_bool clks_keyboard_shell_input_enabled(void) {
return (clks_tty_active() == 0U) ? CLKS_TRUE : CLKS_FALSE;
}
static clks_bool clks_keyboard_should_pump_shell_now(void) {
if (clks_keyboard_shell_input_enabled() == CLKS_FALSE) {
return CLKS_FALSE;
}
if (clks_exec_is_running() == CLKS_TRUE) {
return CLKS_FALSE;
}
return CLKS_TRUE;
}
static char clks_keyboard_translate_scancode(u8 code) {
clks_bool shift_active = (clks_kbd_lshift_down == CLKS_TRUE || clks_kbd_rshift_down == CLKS_TRUE)
? CLKS_TRUE
@@ -174,7 +187,9 @@ void clks_keyboard_handle_scancode(u8 scancode) {
clks_kbd_e0_prefix = CLKS_FALSE;
if (ext != '\0' && clks_keyboard_shell_input_enabled() == CLKS_TRUE) {
(void)clks_keyboard_queue_push(ext);
if (clks_keyboard_queue_push(ext) == CLKS_TRUE && clks_keyboard_should_pump_shell_now() == CLKS_TRUE) {
clks_shell_pump_input(1U);
}
}
return;
@@ -202,7 +217,9 @@ void clks_keyboard_handle_scancode(u8 scancode) {
char translated = clks_keyboard_translate_scancode(code);
if (translated != '\0' && clks_keyboard_shell_input_enabled() == CLKS_TRUE) {
(void)clks_keyboard_queue_push(translated);
if (clks_keyboard_queue_push(translated) == CLKS_TRUE && clks_keyboard_should_pump_shell_now() == CLKS_TRUE) {
clks_shell_pump_input(1U);
}
}
}
}

View File

@@ -43,6 +43,8 @@ static u64 clks_shell_cmd_total = 0ULL;
static u64 clks_shell_cmd_ok = 0ULL;
static u64 clks_shell_cmd_fail = 0ULL;
static u64 clks_shell_cmd_unknown = 0ULL;
static clks_bool clks_shell_pending_command = CLKS_FALSE;
static char clks_shell_pending_line[CLKS_SHELL_LINE_MAX];
extern void clks_rusttest_hello(void);
@@ -1358,6 +1360,16 @@ static void clks_shell_execute_line(const char *line) {
}
}
static void clks_shell_process_pending_command(void) {
if (clks_shell_ready == CLKS_FALSE || clks_shell_pending_command == CLKS_FALSE) {
return;
}
clks_shell_pending_command = CLKS_FALSE;
clks_shell_execute_line(clks_shell_pending_line);
clks_shell_pending_line[0] = '\0';
}
static void clks_shell_handle_char(char ch) {
if (ch == '\r') {
return;
@@ -1367,7 +1379,14 @@ static void clks_shell_handle_char(char ch) {
clks_shell_write_char('\n');
clks_shell_line[clks_shell_line_len] = '\0';
clks_shell_history_push(clks_shell_line);
clks_shell_execute_line(clks_shell_line);
if (clks_shell_pending_command == CLKS_FALSE) {
clks_shell_copy_line(clks_shell_pending_line, sizeof(clks_shell_pending_line), clks_shell_line);
clks_shell_pending_command = CLKS_TRUE;
} else {
clks_shell_writeln("shell: command queue busy");
}
clks_shell_reset_line();
clks_shell_history_cancel_nav();
clks_shell_prompt();
@@ -1496,6 +1515,8 @@ void clks_shell_init(void) {
clks_shell_cmd_ok = 0ULL;
clks_shell_cmd_fail = 0ULL;
clks_shell_cmd_unknown = 0ULL;
clks_shell_pending_command = CLKS_FALSE;
clks_shell_pending_line[0] = '\0';
if (clks_tty_ready() == CLKS_FALSE) {
clks_shell_ready = CLKS_FALSE;
@@ -1539,5 +1560,6 @@ void clks_shell_pump_input(u32 max_chars) {
void clks_shell_tick(u64 tick) {
(void)tick;
clks_shell_drain_input(CLKS_SHELL_INPUT_BUDGET);
clks_shell_process_pending_command();
}

View File

@@ -145,6 +145,67 @@ static void clks_tty_put_visible(u32 tty_index, u32 row, u32 col, char ch) {
}
}
static void clks_tty_put_char_raw(u32 tty_index, char ch) {
u32 row = clks_tty_cursor_row[tty_index];
u32 col = clks_tty_cursor_col[tty_index];
if (ch == '\r') {
clks_tty_cursor_col[tty_index] = 0U;
return;
}
if (ch == '\n') {
clks_tty_cursor_col[tty_index] = 0U;
clks_tty_cursor_row[tty_index]++;
if (clks_tty_cursor_row[tty_index] >= clks_tty_rows) {
clks_tty_scroll_up(tty_index);
clks_tty_cursor_row[tty_index] = clks_tty_rows - 1U;
}
return;
}
if (ch == '\b') {
if (col == 0U && row == 0U) {
return;
}
if (col == 0U) {
row--;
col = clks_tty_cols - 1U;
} else {
col--;
}
clks_tty_put_visible(tty_index, row, col, ' ');
clks_tty_cursor_row[tty_index] = row;
clks_tty_cursor_col[tty_index] = col;
return;
}
if (ch == '\t') {
clks_tty_put_char_raw(tty_index, ' ');
clks_tty_put_char_raw(tty_index, ' ');
clks_tty_put_char_raw(tty_index, ' ');
clks_tty_put_char_raw(tty_index, ' ');
return;
}
clks_tty_put_visible(tty_index, row, col, ch);
clks_tty_cursor_col[tty_index]++;
if (clks_tty_cursor_col[tty_index] >= clks_tty_cols) {
clks_tty_cursor_col[tty_index] = 0U;
clks_tty_cursor_row[tty_index]++;
if (clks_tty_cursor_row[tty_index] >= clks_tty_rows) {
clks_tty_scroll_up(tty_index);
clks_tty_cursor_row[tty_index] = clks_tty_rows - 1U;
}
}
}
void clks_tty_init(void) {
struct clks_framebuffer_info info;
u32 tty;
@@ -202,8 +263,6 @@ void clks_tty_init(void) {
void clks_tty_write_char(char ch) {
u32 tty_index;
u32 row;
u32 col;
if (clks_tty_is_ready == CLKS_FALSE) {
return;
@@ -212,88 +271,30 @@ void clks_tty_write_char(char ch) {
clks_tty_hide_cursor();
tty_index = clks_tty_active_index;
row = clks_tty_cursor_row[tty_index];
col = clks_tty_cursor_col[tty_index];
if (ch == '\r') {
clks_tty_cursor_col[tty_index] = 0;
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
return;
}
if (ch == '\n') {
clks_tty_cursor_col[tty_index] = 0;
clks_tty_cursor_row[tty_index]++;
if (clks_tty_cursor_row[tty_index] >= clks_tty_rows) {
clks_tty_scroll_up(tty_index);
clks_tty_cursor_row[tty_index] = clks_tty_rows - 1;
}
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
return;
}
if (ch == '\b') {
if (col == 0U && row == 0U) {
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
return;
}
if (col == 0U) {
row--;
col = clks_tty_cols - 1U;
} else {
col--;
}
clks_tty_put_visible(tty_index, row, col, ' ');
clks_tty_cursor_row[tty_index] = row;
clks_tty_cursor_col[tty_index] = col;
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
return;
}
if (ch == '\t') {
clks_tty_write_char(' ');
clks_tty_write_char(' ');
clks_tty_write_char(' ');
clks_tty_write_char(' ');
return;
}
clks_tty_put_visible(tty_index, row, col, ch);
clks_tty_cursor_col[tty_index]++;
if (clks_tty_cursor_col[tty_index] >= clks_tty_cols) {
clks_tty_cursor_col[tty_index] = 0;
clks_tty_cursor_row[tty_index]++;
if (clks_tty_cursor_row[tty_index] >= clks_tty_rows) {
clks_tty_scroll_up(tty_index);
clks_tty_cursor_row[tty_index] = clks_tty_rows - 1;
}
}
clks_tty_put_char_raw(tty_index, ch);
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
}
void clks_tty_write(const char *text) {
usize i = 0;
usize i = 0U;
u32 tty_index;
if (clks_tty_is_ready == CLKS_FALSE) {
if (clks_tty_is_ready == CLKS_FALSE || text == CLKS_NULL) {
return;
}
clks_tty_hide_cursor();
tty_index = clks_tty_active_index;
while (text[i] != '\0') {
clks_tty_write_char(text[i]);
clks_tty_put_char_raw(tty_index, text[i]);
i++;
}
clks_tty_draw_cursor();
clks_tty_reset_blink_timer();
}
void clks_tty_switch(u32 tty_index) {
@@ -360,4 +361,4 @@ u32 clks_tty_count(void) {
clks_bool clks_tty_ready(void) {
return clks_tty_is_ready;
}
}