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,6 +23,7 @@ typedef int int32_t;
#define SYS_EXEC 7
#define SYS_GETENV 8
#define SYS_SETENV 9
#define SYS_READDIR 10
static inline int32_t syscall0(int num) {
int32_t ret;
@@ -91,6 +92,17 @@ static inline int32_t setenv(const char *key, const char *value) {
return syscall2(SYS_SETENV, (uint32_t)key, (uint32_t)value);
}
/**
* Read a directory entry.
* @param path Directory path.
* @param idx Entry index (0-based).
* @param name Buffer for entry name (128 bytes min).
* @return Entry type (1=file, 2=dir) on success, -1 at end.
*/
static inline int32_t readdir(const char *path, uint32_t idx, char *name) {
return syscall3(SYS_READDIR, (uint32_t)path, idx, (uint32_t)name);
}
/* Basic string operations for user-space */
static inline uint32_t strlen(const char *s) {
uint32_t len = 0;

36
apps/ls/ls.c Normal file
View File

@@ -0,0 +1,36 @@
/**
* @file ls.c
* @brief List directory contents.
*
* Lists entries in the current working directory (from the CWD
* environment variable). Uses the SYS_READDIR syscall to enumerate
* directory entries.
*/
#include "syscalls.h"
int main(void) {
/* Get the current working directory */
char cwd[128];
if (getenv("CWD", cwd, sizeof(cwd)) < 0) {
/* Default to root if CWD not set */
cwd[0] = '/';
cwd[1] = '\0';
}
char name[128];
uint32_t idx = 0;
int32_t type;
while ((type = readdir(cwd, idx, name)) >= 0) {
puts(name);
if (type == 2) {
/* Directory: append / indicator */
putchar('/');
}
putchar('\n');
idx++;
}
return 0;
}