diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 96b8645..f0b855a 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,8 +28,8 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -void installServiceProvider(char *name, void(provider)(void *)) { - syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, void(provider)(void *)) { + return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -74,3 +74,11 @@ void subscribeInterrupt(uint32_t intNo, void *handler) { syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } + +void requestName(char *service, char *provider, void *data, uint32_t size) { + uint32_t serviceId = getService(service); + uint32_t providerId = getProvider(serviceId, provider); + request(serviceId, providerId, data, size); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 96b8645..f0b855a 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,8 +28,8 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -void installServiceProvider(char *name, void(provider)(void *)) { - syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, void(provider)(void *)) { + return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -74,3 +74,11 @@ void subscribeInterrupt(uint32_t intNo, void *handler) { syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } + +void requestName(char *service, char *provider, void *data, uint32_t size) { + uint32_t serviceId = getService(service); + uint32_t providerId = getProvider(serviceId, provider); + request(serviceId, providerId, data, size); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 61e3989..5569b1f 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); loadFromInitrd("pic"); diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 96b8645..f0b855a 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,8 +28,8 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -void installServiceProvider(char *name, void(provider)(void *)) { - syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, void(provider)(void *)) { + return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -74,3 +74,11 @@ void subscribeInterrupt(uint32_t intNo, void *handler) { syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } + +void requestName(char *service, char *provider, void *data, uint32_t size) { + uint32_t serviceId = getService(service); + uint32_t providerId = getProvider(serviceId, provider); + request(serviceId, providerId, data, size); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 61e3989..5569b1f 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); loadFromInitrd("pic"); diff --git a/src/userland/log/main.c b/src/userland/log/main.c index c03e8fd..e71e38a 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -1,17 +1,10 @@ #include #include -void writeParallel(uint8_t data) { - uint8_t control; - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } - ioOut(0x378, data, sizeof(uint8_t)); +uint32_t outService, outProvider; - control = ioIn(0x37A, sizeof(uint8_t)); - ioOut(0x37A, control | 1, sizeof(uint8_t)); - ioOut(0x37A, control, sizeof(uint8_t)); - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } +void writeParallel(uint8_t data) { + request(outService, outProvider, PTR(data), 0); } void handleLog(void *data, uint32_t dataLength) { @@ -23,9 +16,13 @@ writeParallel('\n'); } +void registerOut(uint32_t *service, uint32_t provider) { + outService = *service; + outProvider = provider; +} + int32_t main() { - installServiceProvider("log", handleLog); - char *message = "logger initialized"; - handleLog(message, strlen(message)); + installServiceProvider("log", (void *)handleLog); + installServiceProvider("registerOut", (void *)registerOut); return 0; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 96b8645..f0b855a 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,8 +28,8 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -void installServiceProvider(char *name, void(provider)(void *)) { - syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, void(provider)(void *)) { + return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -74,3 +74,11 @@ void subscribeInterrupt(uint32_t intNo, void *handler) { syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } + +void requestName(char *service, char *provider, void *data, uint32_t size) { + uint32_t serviceId = getService(service); + uint32_t providerId = getProvider(serviceId, provider); + request(serviceId, providerId, data, size); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 61e3989..5569b1f 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); loadFromInitrd("pic"); diff --git a/src/userland/log/main.c b/src/userland/log/main.c index c03e8fd..e71e38a 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -1,17 +1,10 @@ #include #include -void writeParallel(uint8_t data) { - uint8_t control; - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } - ioOut(0x378, data, sizeof(uint8_t)); +uint32_t outService, outProvider; - control = ioIn(0x37A, sizeof(uint8_t)); - ioOut(0x37A, control | 1, sizeof(uint8_t)); - ioOut(0x37A, control, sizeof(uint8_t)); - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } +void writeParallel(uint8_t data) { + request(outService, outProvider, PTR(data), 0); } void handleLog(void *data, uint32_t dataLength) { @@ -23,9 +16,13 @@ writeParallel('\n'); } +void registerOut(uint32_t *service, uint32_t provider) { + outService = *service; + outProvider = provider; +} + int32_t main() { - installServiceProvider("log", handleLog); - char *message = "logger initialized"; - handleLog(message, strlen(message)); + installServiceProvider("log", (void *)handleLog); + installServiceProvider("registerOut", (void *)registerOut); return 0; } diff --git a/src/userland/parallel/Makefile b/src/userland/parallel/Makefile new file mode 100644 index 0000000..308795d --- /dev/null +++ b/src/userland/parallel/Makefile @@ -0,0 +1,31 @@ +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) + +NAME = parallel + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(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 76cffc8..f517ea2 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -7,8 +7,8 @@ #define PTR(x) ((void *)(uintptr_t)x) #define U32(x) ((uint32_t)(uintptr_t)x) -extern void installServiceProvider(char *name, - void(provider)(void *, uint32_t)); +extern uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)); extern uint32_t strlen(char *string); extern uint32_t ioIn(uint16_t port, uint8_t size); extern void ioOut(uint16_t port, uint32_t value, uint8_t size); @@ -24,5 +24,10 @@ void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); extern uint32_t getService(char *name); +extern void requestName(char *service, char *provider, void *data, + uint32_t size); +extern void request(uint32_t service, uint32_t provider, void *data, + uint32_t size); +extern uint32_t getServiceId(); #endif diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b1cbc3..6427a98 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -59,6 +59,8 @@ provider->name = providerName; provider->address = PTR(call->parameters[1]); provider->service = call->service; + call->returnValue = listCount(service->providers); + // todo make listAdd return the new index listAdd(&service->providers, provider); } @@ -221,6 +223,17 @@ listAdd(&event->subscriptions, provider); } +void handleGetServiceIdSyscall(Syscall *call) { + uint32_t i = 0; + foreach (services, Service *, service, { + if (service == call->service) { + call->returnValue = i; + } + i++; + }) + ; +} + void (*syscallHandlers[])(Syscall *) = { 0, (void *)handleInstallSyscall, @@ -235,4 +248,5 @@ (void *)handleGetEventSyscall, (void *)handleFireEventSyscall, (void *)handleSubscribeEventSyscall, + (void *)handleGetServiceIdSyscall, }; diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 8f618db..8c27ac7 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -18,6 +18,7 @@ SYS_GET_EVENT = 10, SYS_FIRE_EVENT = 11, SYS_SUBSCRIBE_EVENT = 12, + SYS_GET_SERVICE_ID = 13, } SyscallIds; #endif diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 96b8645..f0b855a 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -28,8 +28,8 @@ syscall(SYS_REQUEST, module, function, U32(data), size); } -void installServiceProvider(char *name, void(provider)(void *)) { - syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); +uint32_t installServiceProvider(char *name, void(provider)(void *)) { + return syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } uint32_t strlen(char *string) { @@ -74,3 +74,11 @@ void subscribeInterrupt(uint32_t intNo, void *handler) { syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); } + +void requestName(char *service, char *provider, void *data, uint32_t size) { + uint32_t serviceId = getService(service); + uint32_t providerId = getProvider(serviceId, provider); + request(serviceId, providerId, data, size); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 61e3989..5569b1f 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -3,6 +3,7 @@ int32_t main() { loadFromInitrd("log"); + loadFromInitrd("parallel"); log("hello world"); log("honey os is alive :)"); loadFromInitrd("pic"); diff --git a/src/userland/log/main.c b/src/userland/log/main.c index c03e8fd..e71e38a 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -1,17 +1,10 @@ #include #include -void writeParallel(uint8_t data) { - uint8_t control; - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } - ioOut(0x378, data, sizeof(uint8_t)); +uint32_t outService, outProvider; - control = ioIn(0x37A, sizeof(uint8_t)); - ioOut(0x37A, control | 1, sizeof(uint8_t)); - ioOut(0x37A, control, sizeof(uint8_t)); - while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { - } +void writeParallel(uint8_t data) { + request(outService, outProvider, PTR(data), 0); } void handleLog(void *data, uint32_t dataLength) { @@ -23,9 +16,13 @@ writeParallel('\n'); } +void registerOut(uint32_t *service, uint32_t provider) { + outService = *service; + outProvider = provider; +} + int32_t main() { - installServiceProvider("log", handleLog); - char *message = "logger initialized"; - handleLog(message, strlen(message)); + installServiceProvider("log", (void *)handleLog); + installServiceProvider("registerOut", (void *)registerOut); return 0; } diff --git a/src/userland/parallel/Makefile b/src/userland/parallel/Makefile new file mode 100644 index 0000000..308795d --- /dev/null +++ b/src/userland/parallel/Makefile @@ -0,0 +1,31 @@ +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) + +NAME = parallel + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(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/parallel/main.c b/src/userland/parallel/main.c new file mode 100644 index 0000000..7838a3e --- /dev/null +++ b/src/userland/parallel/main.c @@ -0,0 +1,31 @@ +#include + +uint32_t event0, event1; + +void parallelOut(void *data, uint32_t dataLength) { + uint8_t control; + while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { + } + ioOut(0x378, U32(data), sizeof(uint8_t)); + + control = ioIn(0x37A, sizeof(uint8_t)); + ioOut(0x37A, control | 1, sizeof(uint8_t)); + ioOut(0x37A, control, sizeof(uint8_t)); + while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { + } +} + +int32_t parallelIn(void *data, uint32_t dataLength) { + // todo + return 0; +} + +int32_t main() { + uint32_t provider = installServiceProvider("out", (void *)parallelOut); + installServiceProvider("writeParallel", (void *)parallelOut); + event0 = createEvent("in"); + event1 = createEvent("parallelIn"); + uint32_t thisService = getServiceId(); + requestName("log", "registerOut", &thisService, provider); + return 0; +}