Implement debug console device

This commit is contained in:
2026-03-11 15:35:36 +01:00
parent 6ce4864fd3
commit 5024870dc7
23 changed files with 161 additions and 11 deletions

View File

@@ -15,3 +15,4 @@ include make/libarena.mk
include make/libioutil.mk
include make/libmath.mk
include make/libfat.mk
include make/libdebugconsole.mk

View File

@@ -14,3 +14,4 @@ make -B all_compiledb_libarena
make -B all_compiledb_libioutil
make -B all_compiledb_libmath
make -B all_compiledb_libfat
make -B all_compiledb_libdebugconsole

View File

@@ -21,6 +21,7 @@ make -B all_libarena "$bt"
make -B all_libioutil "$bt"
make -B all_libmath "$bt"
make -B all_libfat "$bt"
make -B all_libdebugconsole "$bt"
make -B all_apps "$bt"
make -B all_dist
./aux/limine_iso_amd64.sh

View File

@@ -15,5 +15,6 @@ make -B docs_libarena
make -B docs_libioutil
make -B docs_libmath
make -B docs_libfat
make -B docs_libdebugconsole
mkdocs build

View File

@@ -14,4 +14,5 @@ make -B format_libarena
make -B format_libioutil
make -B format_libmath
make -B format_libfat
make -B format_libdebugconsole
make -B format_apps

View File

@@ -6,8 +6,6 @@
#include <string.h>
#include <system.h>
void putchar_ (char ch) { (void)ch; }
void mprintf (const char* fmt, ...) {
va_list args;
va_start (args, fmt);

View File

@@ -1,6 +1,9 @@
#ifndef _DEVICES_H
#define _DEVICES_H
/* debugconsole device */
#define DEBUGCONSOLE_PUTSTR 0
/* terminal device */
#define TERMINAL_PUTSTR 0
#define TERMINAL_DIMENSIONS 1

View File

@@ -4,5 +4,9 @@ $(eval $(call add_lib,libterminal))
$(eval $(call add_lib,libprocess))
$(eval $(call add_lib,libstring))
$(eval $(call add_lib,libkb))
$(eval $(call add_lib,libdebugconsole))
$(eval $(call add_lib,libaux))
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
include ../make/user.mk

View File

@@ -1,3 +1,4 @@
#include <debugconsole.h>
#include <kb.h>
#include <limits.h>
#include <process.h>
@@ -23,6 +24,8 @@ void receiver (void* arg) {
}
void app_main (void) {
debug_printf ("Init process is running. Starting user shell...\n");
int ce_pid = exec ("RD", "ce");
ce_pgid = get_procgroup (ce_pid);

View File

@@ -64,7 +64,7 @@ void bootmain (void) {
vfs_create_volume ("RD", FS_TARFS, rd0, false);
struct device* temp0 = device_find ("TEMP0");
int x = vfs_create_volume ("TEMP", FS_FAT16, temp0, true);
vfs_create_volume ("TEMP", FS_FAT16, temp0, true);
proc_pid_alloc_init ();
procgroup_pgid_alloc_init ();

View File

@@ -0,0 +1,33 @@
#include <device/debugconsole.h>
#include <device/device.h>
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
#include <status.h>
#include <sys/debug.h>
bool debugconsole_init (struct device* device, void* arg) {
(void)device, (void)arg;
return true;
}
void debugconsole_fini (struct device* device) { (void)device; }
int debugconsole_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
void* a1, void* a2, void* a3, void* a4) {
(void)a2, (void)a3, (void)a4, (void)device, (void)rctx;
char* string = (char*)a1;
size_t* len = (size_t*)a2;
if (string == NULL || len == NULL)
return -ST_BAD_ADDRESS_SPACE;
spin_lock (&proc->lock);
int pid = proc->pid;
spin_unlock (&proc->lock);
debugprintf ("(CPU %d; PID %d) %.*s\n", thiscpu->id, pid, (int)*len, string);
return ST_OK;
}

View File

@@ -0,0 +1,17 @@
#ifndef _KERNEL_DEVICE_DEBUGCONSOLE_H
#define _KERNEL_DEVICE_DEBUGCONSOLE_H
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
struct device;
bool debugconsole_init (struct device* device, void* arg);
void debugconsole_fini (struct device* device);
int debugconsole_putstr (struct device* device, struct proc* proc, struct reschedule_ctx* rctx,
void* a1, void* a2, void* a3, void* a4);
#endif // _KERNEL_DEVICE_DEBUGCONSOLE_H

View File

@@ -1,7 +1,7 @@
#include <device/debugconsole.h>
#include <device/device.h>
#include <device/partdrv.h>
#include <device/partitions.h>
#include <device/pci.h>
#include <device/ramdrv.h>
#include <device/terminal.h>
#include <devices.h>
@@ -21,6 +21,7 @@
#include <sys/debug.h>
#if defined(__x86_64__)
#include <device/pci.h>
#include <device/ps2_kb.h>
#endif
@@ -85,7 +86,14 @@ struct device* device_create (const char* key, device_op_func_t* ops, size_t ops
return device;
}
void terminal_device_init (void) {
static void debugconsole_device_init (void) {
device_op_func_t ops[] = {
[DEBUGCONSOLE_PUTSTR] = &debugconsole_putstr,
};
device_create ("DEBUGCONSOLE", ops, lengthof (ops), &debugconsole_init, &debugconsole_fini, NULL);
}
static void terminal_device_init (void) {
device_op_func_t ops[] = {
[TERMINAL_PUTSTR] = &terminal_putstr,
[TERMINAL_DIMENSIONS] = &terminal_dimensions,
@@ -93,7 +101,7 @@ void terminal_device_init (void) {
device_create ("TERMINAL", ops, lengthof (ops), &terminal_init, &terminal_fini, NULL);
}
void ramdisk_device_init (void) {
static void ramdisk_device_init (void) {
device_op_func_t ops[] = {
[XDRV_GET_SIZE] = &ramdrv_get_size,
[XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size,
@@ -136,7 +144,7 @@ void ramdisk_device_init (void) {
LZ4F_freeDecompressionContext (dctx);
}
void temp_device_init (void) {
static void temp_device_init (void) {
device_op_func_t ops[] = {
[XDRV_GET_SIZE] = &ramdrv_get_size,
[XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size,
@@ -153,7 +161,7 @@ void temp_device_init (void) {
}
#if defined(__x86_64__)
void ps2kb_device_init (void) {
static void ps2kb_device_init (void) {
device_op_func_t ops[] = {
[KB_READ_KEY] = &ps2kb_read_key,
};
@@ -167,6 +175,7 @@ void devices_init (void) {
terminal_device_init ();
ramdisk_device_init ();
temp_device_init ();
debugconsole_device_init ();
#if defined(__x86_64__)
ps2kb_device_init ();

View File

@@ -2,13 +2,15 @@ c += device/device.c \
device/terminal.c \
device/ramdrv.c \
device/partdrv.c \
device/partitions.c
device/partitions.c \
device/debugconsole.c
o += device/device.o \
device/terminal.o \
device/ramdrv.o \
device/partdrv.o \
device/partitions.o
device/partitions.o \
device/debugconsole.o
ifeq ($(platform),amd64)
c += device/ps2_kb.c \

View File

@@ -7,7 +7,6 @@
#include <proc/reschedule.h>
struct device;
struct device_op_ctx;
bool terminal_init (struct device* device, void* arg);

View File

@@ -1691,3 +1691,5 @@ int fctprintf (void (*out) (char c, void* extra_arg), void* extra_arg, const cha
va_end (args);
return ret;
}
void putchar_ (char ch) { (void)ch; }

4
libdebugconsole/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.o
*.json
docs/
.cache/

11
libdebugconsole/Makefile Normal file
View File

@@ -0,0 +1,11 @@
include ../make/ufuncs.mk
$(eval $(call add_include,libsystem))
$(eval $(call add_include,liballoc))
$(eval $(call add_include,libaux))
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
libname := libdebugconsole
include ../make/lib.mk

1
libdebugconsole/build/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.a

View File

@@ -0,0 +1,30 @@
#include <debugconsole.h>
#include <devices.h>
#include <liballoc.h>
#include <printf.h>
#include <stddef.h>
#include <system.h>
int debugconsole_print (const char* string, size_t len) {
return device_do ("DEBUGCONSOLE", DEBUGCONSOLE_PUTSTR, (void*)string, (void*)&len, NULL, NULL);
}
void debug_printf (const char* fmt, ...) {
va_list args;
va_start (args, fmt);
char* buf = malloc (DEBUG_PRINTF_MAX);
if (buf == NULL) {
va_end (args);
return;
}
buf[0] = '\0';
int len = vsnprintf (buf, DEBUG_PRINTF_MAX, fmt, args);
va_end (args);
debugconsole_print (buf, len);
free (buf);
}

View File

@@ -0,0 +1,10 @@
#ifndef _LIBDEBUGCONSOLE_DEBUGCONSOLE_H
#define _LIBDEBUGCONSOLE_DEBUGCONSOLE_H
#define DEBUG_PRINTF_MAX (16 * 1024)
int debugconsole_print (const char* string, size_t len);
void debug_printf (const char* fmt, ...);
#endif // _LIBDEBUGCONSOLE_DEBUGCONSOLE_H

3
libdebugconsole/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += debugconsole.c
o += debugconsole.o

16
make/libdebugconsole.mk Normal file
View File

@@ -0,0 +1,16 @@
all_libdebugconsole:
make -C libdebugconsole platform=$(platform) all
all_compiledb_libdebugconsole:
bear --output libdebugconsole/compile_commands.json -- make -C libdebugconsole platform=$(platform) all
clean_libdebugconsole:
make -C libdebugconsole platform=$(platform) clean
format_libdebugconsole:
make -C libdebugconsole platform=$(platform) format
docs_libdebugconsole:
make -C libdebugconsole platform=$(platform) docs
.PHONY: all_libdebugconsole clean_libdebugconsole format_libdebugconsole docs_libdebugconsole all_compiledb_libdebugconsole