mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 02:16:58 +00:00
FIX: cpuinfo stack overflow and add GUI tab character support
This commit is contained in:
@@ -415,10 +415,18 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = uy + font_manager_get_font_ascent_scaled(font, font->pixel_height) - 2;
|
||||
int cur_x = ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, font->pixel_height, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, font->pixel_height);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, font->pixel_height);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', font->pixel_height) * 4;
|
||||
} else {
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, font->pixel_height, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, font->pixel_height);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string(ux, uy, kernel_str, color);
|
||||
@@ -430,10 +438,18 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = win->y + uy + font_manager_get_font_ascent_scaled(font, font->pixel_height) - 2;
|
||||
int cur_x = win->x + ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, font->pixel_height, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, font->pixel_height);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, font->pixel_height);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', font->pixel_height) * 4;
|
||||
} else {
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, font->pixel_height, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, font->pixel_height);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string(win->x + ux, win->y + uy, kernel_str, color);
|
||||
@@ -519,10 +535,18 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = uy + font_manager_get_font_ascent_scaled(font, scale) - 2;
|
||||
int cur_x = ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, scale, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, scale);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', scale) * 4;
|
||||
} else {
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, scale, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string_scaled(ux, uy, kernel_str, color, scale);
|
||||
@@ -534,10 +558,18 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = win->y + uy + font_manager_get_font_ascent_scaled(font, scale) - 2;
|
||||
int cur_x = win->x + ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, scale, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, scale);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', scale) * 4;
|
||||
} else {
|
||||
font_manager_render_char_scaled(font, cur_x, baseline, codepoint, color, scale, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string_scaled(win->x + ux, win->y + uy, kernel_str, color, scale);
|
||||
@@ -595,11 +627,19 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = uy + font_manager_get_font_ascent_scaled(font, scale) - 2;
|
||||
int cur_x = ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
extern void font_manager_render_char_sloped(ttf_font_t *font, int x, int y, uint32_t codepoint, uint32_t color, float scale, float slope, void (*put_pixel_fn)(int, int, uint32_t));
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_sloped(font, cur_x, baseline, codepoint, color, scale, slope, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, scale);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', scale) * 4;
|
||||
} else {
|
||||
font_manager_render_char_sloped(font, cur_x, baseline, codepoint, color, scale, slope, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string_scaled_sloped(ux, uy, kernel_str, color, scale, slope);
|
||||
@@ -611,11 +651,19 @@ static uint64_t syscall_handler_inner(registers_t *regs) {
|
||||
int baseline = win->y + uy + font_manager_get_font_ascent_scaled(font, scale) - 2;
|
||||
int cur_x = win->x + ux;
|
||||
const char *s = kernel_str;
|
||||
int start_x = cur_x;
|
||||
while (*s) {
|
||||
extern void font_manager_render_char_sloped(ttf_font_t *font, int x, int y, uint32_t codepoint, uint32_t color, float scale, float slope, void (*put_pixel_fn)(int, int, uint32_t));
|
||||
uint32_t codepoint = utf8_decode(&s);
|
||||
font_manager_render_char_sloped(font, cur_x, baseline, codepoint, color, scale, slope, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
if (codepoint == '\n') {
|
||||
cur_x = start_x;
|
||||
baseline += font_manager_get_font_line_height_scaled(font, scale);
|
||||
} else if (codepoint == '\t') {
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, ' ', scale) * 4;
|
||||
} else {
|
||||
font_manager_render_char_sloped(font, cur_x, baseline, codepoint, color, scale, slope, put_pixel);
|
||||
cur_x += font_manager_get_codepoint_width_scaled(font, codepoint, scale);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
draw_string_scaled_sloped(win->x + ux, win->y + uy, kernel_str, color, scale, slope);
|
||||
|
||||
@@ -132,8 +132,9 @@ static int read_pci_bus(char *buf, int size, int offset) {
|
||||
|
||||
// --- CPU System Implementation ---
|
||||
static int read_cpu_info(char *buf, int size, int offset) {
|
||||
char out[2048];
|
||||
k_memset(out, 0, 2048);
|
||||
char *out = (char*)kmalloc(16384);
|
||||
if (!out) return 0;
|
||||
out[0] = 0;
|
||||
|
||||
char vendor[16];
|
||||
char model[64];
|
||||
@@ -147,34 +148,105 @@ static int read_cpu_info(char *buf, int size, int offset) {
|
||||
|
||||
uint32_t cpu_count = smp_cpu_count();
|
||||
|
||||
k_strcpy(out, "Vendor: ");
|
||||
k_strcpy(out + k_strlen(out), vendor);
|
||||
k_strcpy(out + k_strlen(out), "\nModel: ");
|
||||
k_strcpy(out + k_strlen(out), model);
|
||||
k_strcpy(out + k_strlen(out), "\nCores: ");
|
||||
char c_s[16]; k_itoa(cpu_count, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\nCPU Family: ");
|
||||
k_itoa(info.family, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\nModel Number: ");
|
||||
k_itoa(info.model, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\nStepping: ");
|
||||
k_itoa(info.stepping, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\nCache Size: ");
|
||||
k_itoa(info.cache_size, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), " KB\nSpeed: ~3.00 GHz\nFlags: ");
|
||||
k_strcpy(out + k_strlen(out), flags);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
for (uint32_t i = 0; i < cpu_count; i++) {
|
||||
char c_s[32];
|
||||
|
||||
k_strcpy(out + k_strlen(out), "processor\t: ");
|
||||
k_itoa(i, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "vendor_id\t: ");
|
||||
k_strcpy(out + k_strlen(out), vendor);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "cpu family\t: ");
|
||||
k_itoa(info.family, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "model\t\t: ");
|
||||
k_itoa(info.model, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "model name\t: ");
|
||||
k_strcpy(out + k_strlen(out), model);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "stepping\t: ");
|
||||
k_itoa(info.stepping, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "microcode\t: 0x");
|
||||
char hex[16];
|
||||
int temp = info.microcode;
|
||||
int hex_pos = 0;
|
||||
for (int j = 7; j >= 0; j--) {
|
||||
int digit = (temp >> (j * 4)) & 0xF;
|
||||
hex[hex_pos++] = digit < 10 ? '0' + digit : 'a' + (digit - 10);
|
||||
}
|
||||
hex[hex_pos] = '\0';
|
||||
k_strcpy(out + k_strlen(out), hex);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "cache size\t: ");
|
||||
k_itoa(info.cache_size, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), " KB\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "physical id\t: 0\n");
|
||||
k_strcpy(out + k_strlen(out), "siblings\t: ");
|
||||
k_itoa(cpu_count, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "core id\t\t: ");
|
||||
k_itoa(i, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "cpu cores\t: ");
|
||||
k_itoa(cpu_count, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "apicid\t\t: ");
|
||||
k_itoa(i, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "initial apicid\t: ");
|
||||
k_itoa(i, c_s);
|
||||
k_strcpy(out + k_strlen(out), c_s);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "fpu\t\t: yes\n");
|
||||
k_strcpy(out + k_strlen(out), "fpu_exception\t: yes\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "cpuid level\t: 13\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "wp\t\t: yes\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "flags\t\t: ");
|
||||
k_strcpy(out + k_strlen(out), flags);
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
|
||||
k_strcpy(out + k_strlen(out), "bugs\t\t: \n");
|
||||
k_strcpy(out + k_strlen(out), "bogomips\t: 4800.00\n");
|
||||
|
||||
if (i < cpu_count - 1) {
|
||||
k_strcpy(out + k_strlen(out), "\n");
|
||||
}
|
||||
}
|
||||
|
||||
int len = (int)k_strlen(out);
|
||||
if (offset >= len) return 0;
|
||||
if (offset >= len) { kfree(out); return 0; }
|
||||
int to_copy = len - offset;
|
||||
if (to_copy > size) to_copy = size;
|
||||
k_memcpy(buf, out + offset, to_copy);
|
||||
kfree(out);
|
||||
return to_copy;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user