devices utility app
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 4m29s
Build documentation / build-and-deploy (push) Successful in 3m51s

This commit is contained in:
2026-04-03 02:33:47 +02:00
parent 9a16029f4e
commit d79556a58f
10 changed files with 87 additions and 1 deletions

6
devices/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
*.o
*.json
docs/
.cache/
*.map
devices

10
devices/Makefile Normal file
View File

@@ -0,0 +1,10 @@
include ../make/ufuncs.mk
$(eval $(call add_lib,libstring))
$(eval $(call add_lib,libprocess))
$(eval $(call add_lib,libaux))
$(eval $(call add_lib,libmalloc))
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
include ../make/user.mk

1
devices/app.mk Normal file
View File

@@ -0,0 +1 @@
app := devices

50
devices/devices.c Normal file
View File

@@ -0,0 +1,50 @@
#include <device_info.h>
#include <devices.h>
#include <malloc.h>
#include <mprintf.h>
#include <process_self.h>
#include <status.h>
#include <string.h>
#include <system.h>
static const char* device_types_str[] = {
[DEVICE_TYPE_DEBUGCONSOLE] = "Debug console", [DEVICE_TYPE_TERMINAL] = "System terminal",
[DEVICE_TYPE_KEYBOARD] = "Keyboard", [DEVICE_TYPE_DRIVE] = "Drive",
[DEVICE_TYPE_USB_CTRL] = "USB controller",
};
static void list_all_devices (void) {
struct device_info* infos = malloc (sizeof (struct device_info) * 1024);
memset (infos, 0, sizeof (struct device_info) * 1024);
int device_count = get_device_info (infos, 1024);
mprintf ("%-30s %-20s\n", "NAME", "TYPE");
for (int dev = 0; dev < device_count; dev++) {
struct device_info* info = &infos[dev];
mprintf ("%-30s %-20s\n", info->key, device_types_str[info->type]);
}
}
void app_main (void) {
libprocess_self_init ();
char commandbuf[32];
memset (commandbuf, 0, sizeof (commandbuf));
if (env_get (process_get_pgid (), "help", (void*)commandbuf, sizeof (commandbuf)) == ST_OK) {
mprintf ("devices -C command\n");
mprintf ("commands: list_all\n");
return;
}
if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) != ST_OK) {
mprintf ("ERROR C=???. No command provided\n");
return;
}
if (strcmp (commandbuf, "list_all") == 0) {
list_all_devices ();
}
}

3
devices/src.mk Normal file
View File

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

View File

@@ -1,9 +1,12 @@
#ifndef _DEVICE_INFO_H #ifndef _DEVICE_INFO_H
#define _DEVICE_INFO_H #define _DEVICE_INFO_H
#include <stdint.h>
struct device_info { struct device_info {
int type; int type;
char key[0x100]; char key[0x100];
uint64_t flags;
}; };
#endif // _DEVICE_INFO_H #endif // _DEVICE_INFO_H

View File

@@ -7,6 +7,12 @@
#define DEVICE_TYPE_DRIVE 3 #define DEVICE_TYPE_DRIVE 3
#define DEVICE_TYPE_USB_CTRL 4 #define DEVICE_TYPE_USB_CTRL 4
/* Device flags */
#define DEVICE_FLAG_PCI (1 << 0)
#define DEVICE_FLAG_ISA (1 << 1)
#define DEVICE_FLAG_USB (1 << 2)
#define DEVICE_FLAG_VIRT (1 << 3)
/* debugconsole device */ /* debugconsole device */
#define DEBUGCONSOLE_PUTSTR 0 #define DEBUGCONSOLE_PUTSTR 0

View File

@@ -134,6 +134,7 @@ static void debugconsole_device_init (void) {
static device_op_func_t ops[] = { static device_op_func_t ops[] = {
[DEBUGCONSOLE_PUTSTR] = &debugconsole_putstr, [DEBUGCONSOLE_PUTSTR] = &debugconsole_putstr,
}; };
device_create (DEVICE_TYPE_DEBUGCONSOLE, "debugconsole", ops, lengthof (ops), &debugconsole_init, device_create (DEVICE_TYPE_DEBUGCONSOLE, "debugconsole", ops, lengthof (ops), &debugconsole_init,
&debugconsole_fini, NULL, thiscpu->kproc, &rctx); &debugconsole_fini, NULL, thiscpu->kproc, &rctx);
} }
@@ -146,6 +147,7 @@ static void terminal_device_init (void) {
[TERMINAL_PUTSTR] = &terminal_putstr, [TERMINAL_PUTSTR] = &terminal_putstr,
[TERMINAL_DIMENSIONS] = &terminal_dimensions, [TERMINAL_DIMENSIONS] = &terminal_dimensions,
}; };
device_create (DEVICE_TYPE_TERMINAL, "terminal", ops, lengthof (ops), &terminal_init, device_create (DEVICE_TYPE_TERMINAL, "terminal", ops, lengthof (ops), &terminal_init,
&terminal_fini, NULL, thiscpu->kproc, &rctx); &terminal_fini, NULL, thiscpu->kproc, &rctx);
} }
@@ -191,6 +193,7 @@ static void sys_device_init (void) {
.sector_size = 512, .sector_size = 512,
.buffer = unpack_buffer, .buffer = unpack_buffer,
}; };
device_create (DEVICE_TYPE_DRIVE, "sys0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, device_create (DEVICE_TYPE_DRIVE, "sys0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init,
thiscpu->kproc, &rctx); thiscpu->kproc, &rctx);
@@ -213,6 +216,7 @@ static void temp_device_init (void) {
.total_size = 1024 * 1024 * 20, .total_size = 1024 * 1024 * 20,
.sector_size = 512, .sector_size = 512,
}; };
device_create (DEVICE_TYPE_DRIVE, "temp0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init, device_create (DEVICE_TYPE_DRIVE, "temp0", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init,
thiscpu->kproc, &rctx); thiscpu->kproc, &rctx);
} }
@@ -225,6 +229,7 @@ static void ps2kb_device_init (void) {
device_op_func_t ops[] = { device_op_func_t ops[] = {
[KB_READ_KEY] = &ps2kb_read_key, [KB_READ_KEY] = &ps2kb_read_key,
}; };
device_create (DEVICE_TYPE_KEYBOARD, "kb", ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL, device_create (DEVICE_TYPE_KEYBOARD, "kb", ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL,
thiscpu->kproc, &rctx); thiscpu->kproc, &rctx);
} }

View File

@@ -58,6 +58,7 @@ static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx,
.irq = probe.irq, .irq = probe.irq,
.irqs_support = probe.irqs_support, .irqs_support = probe.irqs_support,
}; };
struct device* ide = device_create (DEVICE_TYPE_DRIVE, device_key, ops, lengthof (ops), struct device* ide = device_create (DEVICE_TYPE_DRIVE, device_key, ops, lengthof (ops),
&idedrv_init, &idedrv_fini, &init, proc, rctx); &idedrv_init, &idedrv_fini, &init, proc, rctx);
device_probe_partitions (proc, rctx, ide); device_probe_partitions (proc, rctx, ide);

View File

@@ -4,7 +4,8 @@ apps := \
ce \ ce \
sdutil \ sdutil \
usb \ usb \
mailtest mailtest \
devices
all_apps: all_apps:
@for d in $(apps); do make -C $$d platform=$(platform) all; done @for d in $(apps); do make -C $$d platform=$(platform) all; done