]> git.corax.cc Git - corax/commitdiff
Add a simple kbd binary to the initfs for testing purposes
authorMatthias Kruk <m@m10k.eu>
Mon, 4 May 2020 08:53:31 +0000 (17:53 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 4 May 2020 08:53:31 +0000 (17:53 +0900)
sys/kbd/Makefile [new file with mode: 0644]
sys/kbd/main.c [new file with mode: 0644]

diff --git a/sys/kbd/Makefile b/sys/kbd/Makefile
new file mode 100644 (file)
index 0000000..bff75f8
--- /dev/null
@@ -0,0 +1,26 @@
+OBJECTS = main.o
+OUTPUT = kbd
+MODULE = kbd.ko
+
+INCLUDES = -I../../include -I../..
+CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding \
+        -nostdinc -fno-builtin -fno-builtin-memcpy
+LIBS = ../../libc/libc.a
+CFLAGS += $(INCLUDES)
+
+ASFLAGS = $(CFLAGS)
+PHONY = clean
+
+all: $(MODULE)
+
+$(MODULE): $(OUTPUT)
+       ld -r --oformat=elf32-i386 -m elf_i386 -b binary -o $@ $<
+       cp $@ ../
+
+$(OUTPUT): $(OBJECTS)
+       gcc -static $(CFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+       rm -f $(OBJECTS) $(OUTPUT)
+
+.PHONY: $(PHONY)
diff --git a/sys/kbd/main.c b/sys/kbd/main.c
new file mode 100644 (file)
index 0000000..ab9bd86
--- /dev/null
@@ -0,0 +1,66 @@
+#include <crxstd.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+
+void _kbd_int_handler(int);
+
+#define INT_KEYBOARD 0x41
+
+int _int_register(void)
+{
+       struct sigaction sa;
+       int ret_val;
+
+       memset(&sa, 0, sizeof(sa));
+
+       sa.sa_handler = _kbd_int_handler;
+       sigemptyset(&(sa.sa_mask));
+       sigaddset(&(sa.sa_mask), INT_KEYBOARD);
+
+       if(sigaction(SIGHWINT, &sa, NULL) < 0) {
+               ret_val = -errno;
+       } else {
+               ret_val = 0;
+       }
+
+       return(ret_val);
+}
+
+static int _intr_rcvd;
+
+void _kbd_int_handler(int signal)
+{
+       _intr_rcvd = 1;
+       return;
+}
+
+int main(int argc, char *argv[])
+{
+       struct cxmsg msg;
+       int err;
+
+       _intr_rcvd = 0;
+
+       err = _int_register();
+
+       if(!err) {
+               static const char *m0 = "Keyboard interrupt handler registered\n";
+
+               debug(m0, strlen(m0));
+
+               while(1) {
+                       if(_intr_rcvd) {
+                               static const char *m1 = "Interrupt received!\n";
+
+                               debug(m1, strlen(m1));
+                               _intr_rcvd = 0;
+                       }
+               }
+       } else {
+               static const char *m2 = "Could not register keyboard interrupt handler\n";
+               debug(m2, strlen(m2));
+       }
+
+       return(0);
+}