Fix UTM display: remove required framebuffer tag, add serial output, ls app

Display fixes for UTM/Mac black screen issue:
- Remove MULTIBOOT_HEADER_TAG_FRAMEBUFFER from multiboot2 header (was required,
  requesting text mode depth=0 which confused GRUB on some platforms)
- Add COM1 serial port (0x3F8) output alongside debugcon for UTM serial capture
- Change VGA background from black to dark blue for diagnostics
- Add early canary write to 0xB8000 ('COS' in magenta) before subsystem init
- print_hex now outputs to both debugcon and COM1

New ls command and SYS_READDIR syscall:
- SYS_READDIR (10): reads directory entries via VFS
- VFS root listing: vfs_readdir handles '/' by iterating mount table
- apps/ls: lists CWD contents, appends '/' for directories
- apps/libc/syscalls.h: readdir() wrapper
This commit is contained in:
AI
2026-02-23 13:36:34 +00:00
parent 993cf05712
commit e3d011da2f
9 changed files with 146 additions and 22 deletions

View File

@@ -23,10 +23,31 @@
/* Global framebuffer info, parsed from multiboot2 tags. */
framebuffer_info_t fb_info;
/**
* Initialize COM1 serial port for debug output.
* Baud rate: 115200, 8N1.
*/
static void serial_init(void) {
outb(0x3F8 + 1, 0x00); /* Disable interrupts */
outb(0x3F8 + 3, 0x80); /* Enable DLAB */
outb(0x3F8 + 0, 0x01); /* Divisor low: 115200 baud */
outb(0x3F8 + 1, 0x00); /* Divisor high */
outb(0x3F8 + 3, 0x03); /* 8 bits, no parity, 1 stop */
outb(0x3F8 + 2, 0xC7); /* Enable FIFO */
outb(0x3F8 + 4, 0x03); /* RTS/DSR set */
}
static void serial_putc(char c) {
/* Wait for transmit buffer empty */
while (!(inb(0x3F8 + 5) & 0x20));
outb(0x3F8, c);
}
void offset_print(const char *str)
{
while (*str) {
outb(0xE9, *str);
outb(0xE9, *str); /* debugcon */
serial_putc(*str); /* COM1 serial */
str++;
}
}
@@ -34,15 +55,30 @@ void offset_print(const char *str)
void print_hex(uint32_t val)
{
const char *hex = "0123456789ABCDEF";
outb(0xE9, '0');
outb(0xE9, 'x');
outb(0xE9, '0'); serial_putc('0');
outb(0xE9, 'x'); serial_putc('x');
for (int i = 28; i >= 0; i -= 4) {
outb(0xE9, hex[(val >> i) & 0xF]);
char c = hex[(val >> i) & 0xF];
outb(0xE9, c);
serial_putc(c);
}
outb(0xE9, '\n');
outb(0xE9, '\n'); serial_putc('\n');
}
void kernel_main(uint32_t magic, uint32_t addr) {
/* Initialize serial port first so all debug output goes to COM1 too */
serial_init();
/* Early canary: write directly to VGA text buffer at 0xB8000.
* If the display is in text mode, this will show a bright magenta 'C'
* in the top-left corner before any subsystem is initialized. */
{
volatile uint16_t *vga = (volatile uint16_t *)0xB8000;
vga[0] = (uint16_t)'C' | (0x5F << 8); /* magenta on magenta = visible block */
vga[1] = (uint16_t)'O' | (0x5F << 8);
vga[2] = (uint16_t)'S' | (0x5F << 8);
}
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) {
offset_print("Invalid magic number: ");
print_hex(magic);