From 31e6ef567c51c25d50c78ad18e033c265f4b9a3f Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 28 Jul 2020 22:19:33 +0900 Subject: [PATCH] sys/io: Add dummy IO process --- sys/initfs.c | 17 ++++++++++-- sys/io/Makefile | 26 +++++++++++++++++++ sys/io/main.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 sys/io/Makefile create mode 100644 sys/io/main.c diff --git a/sys/initfs.c b/sys/initfs.c index c7f4d1f..13de1c4 100644 --- a/sys/initfs.c +++ b/sys/initfs.c @@ -13,21 +13,34 @@ extern const char _binary_vga_start[]; extern const unsigned long _binary_vga_size; #endif /* FEATURE(VGA) */ +#if FEATURE(IO) +extern const char _binary_io_end[]; +extern const char _binary_io_start[]; +extern const unsigned long _binary_io_size; +#endif /* FEATURE(VGA) */ + static struct initfs_entry _ifs_entries[] = { +#if FEATURE(IO) + { + .ife_name = "io", + .ife_base = &_binary_io_start, + .ife_limit = (unsigned long)&_binary_io_size + }, +#endif /* FEATURE(IO) */ #if FEATURE(KBD) { .ife_name = "kbd", .ife_base = &_binary_kbd_start, .ife_limit = (unsigned long)&_binary_kbd_size }, -#endif +#endif /* FEATURE(KBD) */ #if FEATURE(VGA) { .ife_name = "vga", .ife_base = &_binary_vga_start, .ife_limit = (unsigned long)&_binary_vga_size }, -#endif +#endif /* FEATURE(VGA) */ }; struct initfs initfs = { diff --git a/sys/io/Makefile b/sys/io/Makefile new file mode 100644 index 0000000..9c599f7 --- /dev/null +++ b/sys/io/Makefile @@ -0,0 +1,26 @@ +OBJECTS = main.o #globals.o open.o close.o read.o write.o +OUTPUT = io +MODULE = io.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/io/main.c b/sys/io/main.c new file mode 100644 index 0000000..07cd1bc --- /dev/null +++ b/sys/io/main.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include + +/* +int cxio_read(struct cxmsg*); +int cxio_write(struct cxmsg*); +int cxio_open(struct cxmsg*); +int cxio_close(struct cxmsg*); +*/ + +int main(int argc, char *argv[]) +{ + struct cxmsg msg; + int err; + + while(1) { + char str[64]; + int len; + + len = snprintf(str, sizeof(str), "[IO] Waiting for messages...\n"); + debug(str, len); + + err = cxrecv(PID_ANY, &msg); + + len = snprintf(str, sizeof(str), "[IO] Received a message from %u\n", msg.cm_src); + debug(str, len); + + if(err < 0) { + continue; + } + + switch(msg.cm_type) { +#if 0 + case CXIO_READ: + err = cxio_read(&msg); + break; + + case CXIO_WRITE: + err = cxio_write(&msg); + break; + + case CXIO_OPEN: + err = cxio_open(&msg); + break; + + case CXIO_CLOSE: + err = cxio_close(&msg); + break; +#endif /* 0 */ + case CXIO_PIPE: + memset(str, 0, sizeof(str)); + len = snprintf(str, sizeof(str), "CXIO_PIPE from 0x%x.\n", msg.cm_src); + debug(str, len); + break; + + default: + memset(str, 0, sizeof(str)); + len = snprintf(str, sizeof(str), "0x%x from 0x%x.\n", msg.cm_type, msg.cm_src); + debug(str, len); + break; + } + } + + return(0); +} -- 2.47.3