diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c new file mode 100644 index 0000000..f2e73ee --- /dev/null +++ b/src/userland/ioManager/main.c @@ -0,0 +1,57 @@ +#define ALLOC_MAIN + +#include +#include + +bool lock = false; +char buffer[100]; + +uint32_t mainService, mainOut, globalService, globalOut; + +uint32_t focusService; +uint32_t currentKeyConsumerService, currentKeyConsumerFunction; + +void writeString(char *string) { + for (uint32_t i = 0; string[i]; i++) { + request(globalService, globalOut, string[i], 0); + } +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + while (lock) { + syscall(-1, 0, 0, 0, 0); + } + lock = true; + if (callerId == focusService) { + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + } + writeString("[ "); + readString(caller, buffer); + writeString(buffer); + for (int32_t i = 10 - strlen(buffer); i > 0; i--) { + request(globalService, globalOut, ' ', 0); + } + writeString(" ] "); + readString(stringId, buffer); + writeString(buffer); + writeString("\r\n"); + lock = false; +} + +extern uint32_t logService, logFunction; + +int32_t main() { + logService = getServiceId(); + logFunction = createFunction("", (void *)handleLog); + mainService = loadFromInitrd("vga"); + mainOut = getFunction(mainService, "writeChar"); + globalService = loadFromInitrd("parallel"); + globalOut = getFunction(mainService, "writeChar"); + loadFromInitrd("log"); + loadFromInitrd("pic"); + loadFromInitrd("keyboard"); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c new file mode 100644 index 0000000..f2e73ee --- /dev/null +++ b/src/userland/ioManager/main.c @@ -0,0 +1,57 @@ +#define ALLOC_MAIN + +#include +#include + +bool lock = false; +char buffer[100]; + +uint32_t mainService, mainOut, globalService, globalOut; + +uint32_t focusService; +uint32_t currentKeyConsumerService, currentKeyConsumerFunction; + +void writeString(char *string) { + for (uint32_t i = 0; string[i]; i++) { + request(globalService, globalOut, string[i], 0); + } +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + while (lock) { + syscall(-1, 0, 0, 0, 0); + } + lock = true; + if (callerId == focusService) { + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + } + writeString("[ "); + readString(caller, buffer); + writeString(buffer); + for (int32_t i = 10 - strlen(buffer); i > 0; i--) { + request(globalService, globalOut, ' ', 0); + } + writeString(" ] "); + readString(stringId, buffer); + writeString(buffer); + writeString("\r\n"); + lock = false; +} + +extern uint32_t logService, logFunction; + +int32_t main() { + logService = getServiceId(); + logFunction = createFunction("", (void *)handleLog); + mainService = loadFromInitrd("vga"); + mainOut = getFunction(mainService, "writeChar"); + globalService = loadFromInitrd("parallel"); + globalOut = getFunction(mainService, "writeChar"); + loadFromInitrd("log"); + loadFromInitrd("pic"); + loadFromInitrd("keyboard"); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 16c169e..56210b4 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -4,15 +4,9 @@ #include int32_t main() { - loadFromInitrd("log"); - loadFromInitrd("vga"); - loadFromInitrd("parallel"); - log("hello world! honey os is alive :)"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); - printf("test print string: '%s', number: %i, hex: 0x%x", "hello world", - 1234, 0xB105F00D); - log("finished loading essential modules"); + loadFromInitrd("ioManager"); + printf("HONEY-OS by Lukas Eisenhauer"); + printf("finished loading all the essential modules"); loadFromInitrd("crashTest"); return 0; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c new file mode 100644 index 0000000..f2e73ee --- /dev/null +++ b/src/userland/ioManager/main.c @@ -0,0 +1,57 @@ +#define ALLOC_MAIN + +#include +#include + +bool lock = false; +char buffer[100]; + +uint32_t mainService, mainOut, globalService, globalOut; + +uint32_t focusService; +uint32_t currentKeyConsumerService, currentKeyConsumerFunction; + +void writeString(char *string) { + for (uint32_t i = 0; string[i]; i++) { + request(globalService, globalOut, string[i], 0); + } +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + while (lock) { + syscall(-1, 0, 0, 0, 0); + } + lock = true; + if (callerId == focusService) { + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + } + writeString("[ "); + readString(caller, buffer); + writeString(buffer); + for (int32_t i = 10 - strlen(buffer); i > 0; i--) { + request(globalService, globalOut, ' ', 0); + } + writeString(" ] "); + readString(stringId, buffer); + writeString(buffer); + writeString("\r\n"); + lock = false; +} + +extern uint32_t logService, logFunction; + +int32_t main() { + logService = getServiceId(); + logFunction = createFunction("", (void *)handleLog); + mainService = loadFromInitrd("vga"); + mainOut = getFunction(mainService, "writeChar"); + globalService = loadFromInitrd("parallel"); + globalOut = getFunction(mainService, "writeChar"); + loadFromInitrd("log"); + loadFromInitrd("pic"); + loadFromInitrd("keyboard"); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 16c169e..56210b4 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -4,15 +4,9 @@ #include int32_t main() { - loadFromInitrd("log"); - loadFromInitrd("vga"); - loadFromInitrd("parallel"); - log("hello world! honey os is alive :)"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); - printf("test print string: '%s', number: %i, hex: 0x%x", "hello world", - 1234, 0xB105F00D); - log("finished loading essential modules"); + loadFromInitrd("ioManager"); + printf("HONEY-OS by Lukas Eisenhauer"); + printf("finished loading all the essential modules"); loadFromInitrd("crashTest"); return 0; } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index dff007e..232efd0 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -3,8 +3,6 @@ #include #include -uint32_t services[10], functions[10], outputCount; - char *EXCEPTION_NAMES[] = {"DIVISION ERROR", "DEBUG EXCEPTION", "NON-MASKABLE-INTERRUPT", @@ -21,47 +19,9 @@ "GENERAL PROTECTION FAULT", "PAGE FAULT"}; -void writeChar(uint8_t data) { - for (uint8_t i = 0; i < outputCount; i++) { - request(services[i], functions[i], data, 0); - } -} - -void writeString(char *string) { - for (uint32_t i = 0; string[i]; i++) { - writeChar(string[i]); - } -} - -bool lock = false; char buffer[100]; -void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller) { - while (lock) { - syscall(-1, 0, 0, 0, 0); - } - lock = true; - writeString("[ "); - readString(caller, buffer); - writeString(buffer); - for (int32_t i = 10 - strlen(buffer); i > 0; i--) { - writeChar(' '); - } - writeString(" ] "); - readString(stringId, buffer); - writeString(buffer); - writeString("\r\n"); - lock = false; -} - -void registerOut(uintptr_t service, uintptr_t provider) { - services[outputCount] = service; - functions[outputCount] = provider; - outputCount++; -} - void onInitrdLoad(uint32_t programName) { - char buffer[100]; readString(programName, buffer); printf("loading '%s' from initrd", buffer); } @@ -91,8 +51,6 @@ } int32_t main() { - createFunction("log", (void *)handleLog); - createFunction("registerOut", (void *)registerOut); uint32_t eventId = getEvent(0, "loadInitrd"); subscribeEvent(0, eventId, (void *)onInitrdLoad); subscribeInterrupt(0, (void *)onException); diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c new file mode 100644 index 0000000..f2e73ee --- /dev/null +++ b/src/userland/ioManager/main.c @@ -0,0 +1,57 @@ +#define ALLOC_MAIN + +#include +#include + +bool lock = false; +char buffer[100]; + +uint32_t mainService, mainOut, globalService, globalOut; + +uint32_t focusService; +uint32_t currentKeyConsumerService, currentKeyConsumerFunction; + +void writeString(char *string) { + for (uint32_t i = 0; string[i]; i++) { + request(globalService, globalOut, string[i], 0); + } +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + while (lock) { + syscall(-1, 0, 0, 0, 0); + } + lock = true; + if (callerId == focusService) { + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + } + writeString("[ "); + readString(caller, buffer); + writeString(buffer); + for (int32_t i = 10 - strlen(buffer); i > 0; i--) { + request(globalService, globalOut, ' ', 0); + } + writeString(" ] "); + readString(stringId, buffer); + writeString(buffer); + writeString("\r\n"); + lock = false; +} + +extern uint32_t logService, logFunction; + +int32_t main() { + logService = getServiceId(); + logFunction = createFunction("", (void *)handleLog); + mainService = loadFromInitrd("vga"); + mainOut = getFunction(mainService, "writeChar"); + globalService = loadFromInitrd("parallel"); + globalOut = getFunction(mainService, "writeChar"); + loadFromInitrd("log"); + loadFromInitrd("pic"); + loadFromInitrd("keyboard"); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 16c169e..56210b4 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -4,15 +4,9 @@ #include int32_t main() { - loadFromInitrd("log"); - loadFromInitrd("vga"); - loadFromInitrd("parallel"); - log("hello world! honey os is alive :)"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); - printf("test print string: '%s', number: %i, hex: 0x%x", "hello world", - 1234, 0xB105F00D); - log("finished loading essential modules"); + loadFromInitrd("ioManager"); + printf("HONEY-OS by Lukas Eisenhauer"); + printf("finished loading all the essential modules"); loadFromInitrd("crashTest"); return 0; } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index dff007e..232efd0 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -3,8 +3,6 @@ #include #include -uint32_t services[10], functions[10], outputCount; - char *EXCEPTION_NAMES[] = {"DIVISION ERROR", "DEBUG EXCEPTION", "NON-MASKABLE-INTERRUPT", @@ -21,47 +19,9 @@ "GENERAL PROTECTION FAULT", "PAGE FAULT"}; -void writeChar(uint8_t data) { - for (uint8_t i = 0; i < outputCount; i++) { - request(services[i], functions[i], data, 0); - } -} - -void writeString(char *string) { - for (uint32_t i = 0; string[i]; i++) { - writeChar(string[i]); - } -} - -bool lock = false; char buffer[100]; -void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller) { - while (lock) { - syscall(-1, 0, 0, 0, 0); - } - lock = true; - writeString("[ "); - readString(caller, buffer); - writeString(buffer); - for (int32_t i = 10 - strlen(buffer); i > 0; i--) { - writeChar(' '); - } - writeString(" ] "); - readString(stringId, buffer); - writeString(buffer); - writeString("\r\n"); - lock = false; -} - -void registerOut(uintptr_t service, uintptr_t provider) { - services[outputCount] = service; - functions[outputCount] = provider; - outputCount++; -} - void onInitrdLoad(uint32_t programName) { - char buffer[100]; readString(programName, buffer); printf("loading '%s' from initrd", buffer); } @@ -91,8 +51,6 @@ } int32_t main() { - createFunction("log", (void *)handleLog); - createFunction("registerOut", (void *)registerOut); uint32_t eventId = getEvent(0, "loadInitrd"); subscribeEvent(0, eventId, (void *)onInitrdLoad); subscribeInterrupt(0, (void *)onException); diff --git a/src/userland/parallel/main.c b/src/userland/parallel/main.c index 0403682..f660d43 100644 --- a/src/userland/parallel/main.c +++ b/src/userland/parallel/main.c @@ -20,12 +20,4 @@ return 0; } -int32_t main() { - uint32_t provider = createFunction("out", (void *)parallelOut); - createFunction("writeParallel", (void *)parallelOut); - event0 = createEvent("in"); - event1 = createEvent("parallelIn"); - uint32_t thisService = getServiceId(); - requestName("log", "registerOut", thisService, provider); - return 0; -} +int32_t main() { createFunction("writeChar", (void *)parallelOut); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 9b11389..c1e77c9 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -21,7 +21,7 @@ extern void ioOut(uint16_t port, uint32_t value, uint8_t size); extern void log(char *); extern void subscribeInterrupt(uint32_t intNo, void *handler); -extern void loadFromInitrd(char *name); +extern uint32_t loadFromInitrd(char *name); extern uint32_t createEvent(char *name); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, @@ -44,6 +44,7 @@ extern void *requestMemory(uint32_t pageCount, void *targetAddress, void *physicalAddress); extern uint32_t lookupSymbol(uint32_t serviceId, uint32_t address); +extern uint32_t getFunction(uint32_t serviceId, char *functionName); #define MAX(x, y) (x > y ? (x) : (y)) diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index 2278a60..5b094f7 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -14,6 +14,7 @@ extern TSS tss; extern Syscall *currentSyscall; extern ListElement *callsToProcess; +extern uint32_t getServiceId(Service *service); ListElement *interruptSubscriptions[255]; @@ -29,19 +30,6 @@ ; } -uint32_t getServiceId(Service *searchService) { - uint32_t i = 0; - foreach (services, Service *, service, { - if (service == searchService) { - return i; - } - i++; - }) - ; - free(currentSyscall); - return i; -} - void onException(void *ebp, void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo, uint32_t errorCode, uint32_t eip) { foreach (interruptSubscriptions[0], ServiceFunction *, provider, { @@ -53,6 +41,8 @@ ebp)), service->nameHash, getServiceId(service)); }) + ; + free(currentSyscall); } extern void *interruptStack; diff --git a/src/kernel/multiboot/initrdSyscall.c b/src/kernel/multiboot/initrdSyscall.c index 0ff8530..c918ede 100644 --- a/src/kernel/multiboot/initrdSyscall.c +++ b/src/kernel/multiboot/initrdSyscall.c @@ -5,6 +5,7 @@ extern void loadProgram(char *name, Syscall *respondingTo); void handleLoadFromInitrdSyscall(Syscall *call) { + call->returnValue = listCount(services); char *name = retrieveString(call->parameters[0]); Service *service = call->service; loadProgram(name, (void *)call); diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index ee32b74..fd5db70 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -3,6 +3,20 @@ #include #include +extern Syscall *currentSyscall; + +uint32_t getServiceId(Service *searchService) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == searchService) { + return i; + } + i++; + }) + ; + return i; +} + void handleGetServiceIdSyscall(Syscall *call) { uint32_t i = 0; foreach (services, Service *, service, { @@ -70,7 +84,7 @@ ServiceFunction *function = listGet(providerService->functions, call->parameters[1]); scheduleFunction(function, call, call->parameters[2], call->parameters[3], - service->nameHash); + service->nameHash, getServiceId(service)); call->avoidReschedule = true; } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 653de9d..c8082c6 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -22,20 +22,16 @@ return 0; } -void loadFromInitrd(char *name) { +uint32_t loadFromInitrd(char *name) { uintptr_t id = insertString(name); - syscall(SYS_LOAD_INITRD, id, 0, 0, 0); + return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logModule = 0, logProvider; +uint32_t logService, logFunction; void log(char *message) { - if (logModule == 0) { - logModule = getService("log"); - logProvider = getFunction(logModule, "log"); - } uintptr_t id = insertString(message); - request(logModule, logProvider, id, 0); + request(logService, logFunction, id, 0); discardString(id); } diff --git a/src/userland/ioManager/Makefile b/src/userland/ioManager/Makefile new file mode 100644 index 0000000..0b0ac8e --- /dev/null +++ b/src/userland/ioManager/Makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +../../../initrd/ioManager: $(OBJS) ../../../build/hlib.o + @echo "linking user program io manager" + @$(LD) $(LD_FLAGS) -o $@ $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c new file mode 100644 index 0000000..f2e73ee --- /dev/null +++ b/src/userland/ioManager/main.c @@ -0,0 +1,57 @@ +#define ALLOC_MAIN + +#include +#include + +bool lock = false; +char buffer[100]; + +uint32_t mainService, mainOut, globalService, globalOut; + +uint32_t focusService; +uint32_t currentKeyConsumerService, currentKeyConsumerFunction; + +void writeString(char *string) { + for (uint32_t i = 0; string[i]; i++) { + request(globalService, globalOut, string[i], 0); + } +} + +void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, + uint32_t callerId) { + while (lock) { + syscall(-1, 0, 0, 0, 0); + } + lock = true; + if (callerId == focusService) { + readString(stringId, buffer); + for (uint32_t i = 0; buffer[i]; i++) { + request(mainService, mainOut, buffer[i], 0); + } + } + writeString("[ "); + readString(caller, buffer); + writeString(buffer); + for (int32_t i = 10 - strlen(buffer); i > 0; i--) { + request(globalService, globalOut, ' ', 0); + } + writeString(" ] "); + readString(stringId, buffer); + writeString(buffer); + writeString("\r\n"); + lock = false; +} + +extern uint32_t logService, logFunction; + +int32_t main() { + logService = getServiceId(); + logFunction = createFunction("", (void *)handleLog); + mainService = loadFromInitrd("vga"); + mainOut = getFunction(mainService, "writeChar"); + globalService = loadFromInitrd("parallel"); + globalOut = getFunction(mainService, "writeChar"); + loadFromInitrd("log"); + loadFromInitrd("pic"); + loadFromInitrd("keyboard"); +} diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 16c169e..56210b4 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -4,15 +4,9 @@ #include int32_t main() { - loadFromInitrd("log"); - loadFromInitrd("vga"); - loadFromInitrd("parallel"); - log("hello world! honey os is alive :)"); - loadFromInitrd("pic"); - loadFromInitrd("keyboard"); - printf("test print string: '%s', number: %i, hex: 0x%x", "hello world", - 1234, 0xB105F00D); - log("finished loading essential modules"); + loadFromInitrd("ioManager"); + printf("HONEY-OS by Lukas Eisenhauer"); + printf("finished loading all the essential modules"); loadFromInitrd("crashTest"); return 0; } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index dff007e..232efd0 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -3,8 +3,6 @@ #include #include -uint32_t services[10], functions[10], outputCount; - char *EXCEPTION_NAMES[] = {"DIVISION ERROR", "DEBUG EXCEPTION", "NON-MASKABLE-INTERRUPT", @@ -21,47 +19,9 @@ "GENERAL PROTECTION FAULT", "PAGE FAULT"}; -void writeChar(uint8_t data) { - for (uint8_t i = 0; i < outputCount; i++) { - request(services[i], functions[i], data, 0); - } -} - -void writeString(char *string) { - for (uint32_t i = 0; string[i]; i++) { - writeChar(string[i]); - } -} - -bool lock = false; char buffer[100]; -void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller) { - while (lock) { - syscall(-1, 0, 0, 0, 0); - } - lock = true; - writeString("[ "); - readString(caller, buffer); - writeString(buffer); - for (int32_t i = 10 - strlen(buffer); i > 0; i--) { - writeChar(' '); - } - writeString(" ] "); - readString(stringId, buffer); - writeString(buffer); - writeString("\r\n"); - lock = false; -} - -void registerOut(uintptr_t service, uintptr_t provider) { - services[outputCount] = service; - functions[outputCount] = provider; - outputCount++; -} - void onInitrdLoad(uint32_t programName) { - char buffer[100]; readString(programName, buffer); printf("loading '%s' from initrd", buffer); } @@ -91,8 +51,6 @@ } int32_t main() { - createFunction("log", (void *)handleLog); - createFunction("registerOut", (void *)registerOut); uint32_t eventId = getEvent(0, "loadInitrd"); subscribeEvent(0, eventId, (void *)onInitrdLoad); subscribeInterrupt(0, (void *)onException); diff --git a/src/userland/parallel/main.c b/src/userland/parallel/main.c index 0403682..f660d43 100644 --- a/src/userland/parallel/main.c +++ b/src/userland/parallel/main.c @@ -20,12 +20,4 @@ return 0; } -int32_t main() { - uint32_t provider = createFunction("out", (void *)parallelOut); - createFunction("writeParallel", (void *)parallelOut); - event0 = createEvent("in"); - event1 = createEvent("parallelIn"); - uint32_t thisService = getServiceId(); - requestName("log", "registerOut", thisService, provider); - return 0; -} +int32_t main() { createFunction("writeChar", (void *)parallelOut); } diff --git a/src/userland/vga/main.c b/src/userland/vga/main.c index 57ffe05..1431166 100644 --- a/src/userland/vga/main.c +++ b/src/userland/vga/main.c @@ -28,8 +28,6 @@ int32_t main() { videoSource = requestMemory(2, NULL, PTR(0xB8000)); - uint32_t thisService = getServiceId(); - uint32_t functionId = createFunction("writeVGA", (void *)write); - requestName("log", "registerOut", thisService, functionId); + createFunction("writeChar", (void *)write); return 0; }