fix unicode information loss in printing

This commit is contained in:
uosfz 2025-12-06 18:35:59 +01:00
parent 824659df88
commit 7a322b62bc
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo
3 changed files with 10 additions and 8 deletions

View file

@ -65,9 +65,7 @@ drive.img:
truncate -s 16M drive.img
clean:
rm -f $(KERNEL_OBJECTS)
rm -f $(KERNEL_DEPFILES)
rm -f $(KERNEL_TARGET)
rm -rf build/*
TEST_MEM_RANGE_DEPS=build/src/test.o build/src/mem_range.o build/src/x86_64/address.o
build/tests/test_mem_range: tests/test_mem_range.c $(TEST_MEM_RANGE_DEPS) build/tests

View file

@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "unicode.h"
/// Initializes bsp and jumps to `main()`. Does not return.
__attribute__((noreturn))
@ -27,7 +28,7 @@ struct cpu_info {
bool panicked;
// output
char linebuf[LINEBUF_SIZE];
unicode_char linebuf[LINEBUF_SIZE];
unsigned int linebuf_pos;
};

View file

@ -81,15 +81,19 @@ static void linebuf_flush(void) {
struct cpu_info *mycpu = local_cpu_data();
for (unsigned int i = 0; i < mycpu->linebuf_pos; i++) {
serial_write_char(mycpu->linebuf[i]);
cout_putc(mycpu->linebuf[i]);
unicode_char c = mycpu->linebuf[i];
// TODO here we simply ignore non-ASCII characters.
if (c < 128) {
serial_write_char(c);
}
cout_putc(c);
}
mycpu->linebuf_pos = 0;
spin_unlock(&linebuf_lock);
}
static void linebuf_putc(char c) {
static void linebuf_putc(unicode_char c) {
struct cpu_info *mycpu = local_cpu_data();
if (mycpu->linebuf_pos == LINEBUF_SIZE) {
linebuf_flush();
@ -103,7 +107,6 @@ void line_flush(void) {
linebuf_flush();
}
// NOTE: we lose unicode information here.
void putc(unicode_char c) {
if (c == '\n') {
linebuf_putc('\r');