From 21694dafb13ff3e766a30de97fd457656127d208 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Mon, 4 May 2020 17:53:31 +0900 Subject: [PATCH] Add a simple kbd binary to the initfs for testing purposes --- sys/kbd/Makefile | 26 +++++++++++++++++++ sys/kbd/main.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 sys/kbd/Makefile create mode 100644 sys/kbd/main.c diff --git a/sys/kbd/Makefile b/sys/kbd/Makefile new file mode 100644 index 0000000..bff75f8 --- /dev/null +++ b/sys/kbd/Makefile @@ -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 index 0000000..ab9bd86 --- /dev/null +++ b/sys/kbd/main.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +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); +} -- 2.47.3