Implement debug console device
This commit is contained in:
33
kernel/device/debugconsole.c
Normal file
33
kernel/device/debugconsole.c
Normal 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;
|
||||
}
|
||||
17
kernel/device/debugconsole.h
Normal file
17
kernel/device/debugconsole.h
Normal 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
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <proc/reschedule.h>
|
||||
|
||||
struct device;
|
||||
struct device_op_ctx;
|
||||
|
||||
bool terminal_init (struct device* device, void* arg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user