dev Utility for working with devices
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
mkalias pctl base:/bin/pctl
|
mkalias pctl base:/bin/pctl
|
||||||
mkalias tb base:/bin/tb
|
mkalias tb base:/bin/tb
|
||||||
mkalias fs base:/bin/fs
|
mkalias fs base:/bin/fs
|
||||||
|
mkalias dev base:/bin/dev
|
||||||
|
2
user/dev/.gitignore
vendored
Normal file
2
user/dev/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
dev
|
24
user/dev/Makefile
Normal file
24
user/dev/Makefile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
include $(ROOT)/mk/grabsrc.mk
|
||||||
|
include ../Makefile.inc
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
TARGET := dev
|
||||||
|
|
||||||
|
LDFLAGS += -L$(ROOT)/ulib -l:libulib.a
|
||||||
|
|
||||||
|
SRCFILES := $(call GRABSRC, .)
|
||||||
|
CFILES := $(call GET_CFILES, $(SRCFILES))
|
||||||
|
OBJ := $(call GET_OBJ, $(SRCFILES))
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJ)
|
||||||
|
$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
echo $$(realpath $(TARGET)) >> $(FILES)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ) $(TARGET)
|
20
user/dev/ls.c
Normal file
20
user/dev/ls.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
void dev_ls(void) {
|
||||||
|
size_t ndevs = devctl(NULL, DEVCTL_DEVLS_SZ, NULL, 0, 0);
|
||||||
|
uprintf("TOTAL: %zu\n", ndevs);
|
||||||
|
|
||||||
|
uprintf("%-20s %-10s\n", "DEVICE", "FUNCTIONS");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 0x100; i++) {
|
||||||
|
DevStat devstat; ZERO(&devstat);
|
||||||
|
devctl(NULL, DEVCTL_DEVLS_STAT, (uint8_t *)&devstat, i, 0);
|
||||||
|
|
||||||
|
if (!devstat.present)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uprintf("%-20s %-10zu\n", devstat.name, devstat.nfns);
|
||||||
|
}
|
||||||
|
}
|
24
user/dev/main.c
Normal file
24
user/dev/main.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
#define CMDS(X) \
|
||||||
|
X(ls)
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
if (argslen() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *cmd = args()[0];
|
||||||
|
|
||||||
|
#define X(name) if (string_strcmp(cmd, #name) == 0) { \
|
||||||
|
extern void dev_ ## name(void); \
|
||||||
|
dev_ ## name(); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
CMDS(X)
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
uprintf("dev: unknown command %s\n", cmd);
|
||||||
|
}
|
Reference in New Issue
Block a user