diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/io.c b/src/userland/hlib/io.c new file mode 100644 index 0000000..5a6c3f3 --- /dev/null +++ b/src/userland/hlib/io.c @@ -0,0 +1,14 @@ +#include +#include + +uint32_t ioIn(uint16_t port, uint8_t size) { + return syscall(SYS_IO_IN, size, port, 0, 0); +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + syscall(SYS_IO_OUT, size, port, value, 0); +} + +void subscribeInterrupt(uint32_t intNo, void *handler) { + syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); +} diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/io.c b/src/userland/hlib/io.c new file mode 100644 index 0000000..5a6c3f3 --- /dev/null +++ b/src/userland/hlib/io.c @@ -0,0 +1,14 @@ +#include +#include + +uint32_t ioIn(uint16_t port, uint8_t size) { + return syscall(SYS_IO_IN, size, port, 0, 0); +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + syscall(SYS_IO_OUT, size, port, value, 0); +} + +void subscribeInterrupt(uint32_t intNo, void *handler) { + syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); +} diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 292da46..2ab51fa 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -2,9 +2,6 @@ #include #include -#define PTR(x) ((void *)(uintptr_t)x) -#define U32(x) ((uint32_t)(uintptr_t)x) - uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; @@ -25,39 +22,6 @@ return 0; } -void request(uint32_t module, uint32_t function, uintptr_t data1, - uintptr_t data2) { - syscall(SYS_REQUEST, module, function, data1, data2); -} - -uint32_t installServiceProvider(char *name, - int32_t(provider)(void *, uint32_t)) { - uintptr_t id = insertString(name); - return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); -} - -uint32_t strlen(char *string) { - if (!string) { - return 0; - } - uint32_t size = 0; - while (*string) { - string++; - size++; - } - return size; -} - -uint32_t getService(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_SERVICE, id, 0, 0, 0); -} - -uint32_t getProvider(uint32_t module, char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_PROVIDER, module, id, 0, 0); -} - void loadFromInitrd(char *name) { uintptr_t id = insertString(name); syscall(SYS_LOAD_INITRD, id, 0, 0, 0); @@ -75,39 +39,9 @@ discardString(id); } -uint32_t ioIn(uint16_t port, uint8_t size) { - return syscall(SYS_IO_IN, size, port, 0, 0); -} - -void ioOut(uint16_t port, uint32_t value, uint8_t size) { - syscall(SYS_IO_OUT, size, port, value, 0); -} - -void subscribeInterrupt(uint32_t intNo, void *handler) { - syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } - -uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } - -uintptr_t insertString(char *string) { - return syscall(SYS_INSERT_STRING, U32(string), 0, 0, 0); -} - -uintptr_t getStringLength(uintptr_t stringId) { - return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); -} - -void readString(uintptr_t stringId, void *buffer) { - syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); -} - -void discardString(uintptr_t stringId) { - syscall(SYS_DISCARD_STRING, stringId, 0, 0, 0); -} diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/io.c b/src/userland/hlib/io.c new file mode 100644 index 0000000..5a6c3f3 --- /dev/null +++ b/src/userland/hlib/io.c @@ -0,0 +1,14 @@ +#include +#include + +uint32_t ioIn(uint16_t port, uint8_t size) { + return syscall(SYS_IO_IN, size, port, 0, 0); +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + syscall(SYS_IO_OUT, size, port, value, 0); +} + +void subscribeInterrupt(uint32_t intNo, void *handler) { + syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); +} diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 292da46..2ab51fa 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -2,9 +2,6 @@ #include #include -#define PTR(x) ((void *)(uintptr_t)x) -#define U32(x) ((uint32_t)(uintptr_t)x) - uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; @@ -25,39 +22,6 @@ return 0; } -void request(uint32_t module, uint32_t function, uintptr_t data1, - uintptr_t data2) { - syscall(SYS_REQUEST, module, function, data1, data2); -} - -uint32_t installServiceProvider(char *name, - int32_t(provider)(void *, uint32_t)) { - uintptr_t id = insertString(name); - return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); -} - -uint32_t strlen(char *string) { - if (!string) { - return 0; - } - uint32_t size = 0; - while (*string) { - string++; - size++; - } - return size; -} - -uint32_t getService(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_SERVICE, id, 0, 0, 0); -} - -uint32_t getProvider(uint32_t module, char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_PROVIDER, module, id, 0, 0); -} - void loadFromInitrd(char *name) { uintptr_t id = insertString(name); syscall(SYS_LOAD_INITRD, id, 0, 0, 0); @@ -75,39 +39,9 @@ discardString(id); } -uint32_t ioIn(uint16_t port, uint8_t size) { - return syscall(SYS_IO_IN, size, port, 0, 0); -} - -void ioOut(uint16_t port, uint32_t value, uint8_t size) { - syscall(SYS_IO_OUT, size, port, value, 0); -} - -void subscribeInterrupt(uint32_t intNo, void *handler) { - syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } - -uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } - -uintptr_t insertString(char *string) { - return syscall(SYS_INSERT_STRING, U32(string), 0, 0, 0); -} - -uintptr_t getStringLength(uintptr_t stringId) { - return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); -} - -void readString(uintptr_t stringId, void *buffer) { - syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); -} - -void discardString(uintptr_t stringId) { - syscall(SYS_DISCARD_STRING, stringId, 0, 0, 0); -} diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c new file mode 100644 index 0000000..8b2ed97 --- /dev/null +++ b/src/userland/hlib/service/events.c @@ -0,0 +1,30 @@ +#include +#include +#include + +uint32_t createEvent(char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uintptr_t hashString(char *string) { + uintptr_t hash = 0; + for (uintptr_t i = 0; string[i]; i++) { + hash = 257 * hash + string[i]; + } + return hash; +} + +uint32_t getEvent(uint32_t service, char *name) { + uintptr_t id = hashString(name); + return syscall(SYS_GET_EVENT, service, id, 0, 0); +} + +void fireEvent(uint32_t eventNumber) { + syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); +} + +void subscribeEvent(uint32_t service, uint32_t event, + void(handler)(void *, uint32_t)) { + syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); +} diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/io.c b/src/userland/hlib/io.c new file mode 100644 index 0000000..5a6c3f3 --- /dev/null +++ b/src/userland/hlib/io.c @@ -0,0 +1,14 @@ +#include +#include + +uint32_t ioIn(uint16_t port, uint8_t size) { + return syscall(SYS_IO_IN, size, port, 0, 0); +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + syscall(SYS_IO_OUT, size, port, value, 0); +} + +void subscribeInterrupt(uint32_t intNo, void *handler) { + syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); +} diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 292da46..2ab51fa 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -2,9 +2,6 @@ #include #include -#define PTR(x) ((void *)(uintptr_t)x) -#define U32(x) ((uint32_t)(uintptr_t)x) - uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; @@ -25,39 +22,6 @@ return 0; } -void request(uint32_t module, uint32_t function, uintptr_t data1, - uintptr_t data2) { - syscall(SYS_REQUEST, module, function, data1, data2); -} - -uint32_t installServiceProvider(char *name, - int32_t(provider)(void *, uint32_t)) { - uintptr_t id = insertString(name); - return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); -} - -uint32_t strlen(char *string) { - if (!string) { - return 0; - } - uint32_t size = 0; - while (*string) { - string++; - size++; - } - return size; -} - -uint32_t getService(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_SERVICE, id, 0, 0, 0); -} - -uint32_t getProvider(uint32_t module, char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_PROVIDER, module, id, 0, 0); -} - void loadFromInitrd(char *name) { uintptr_t id = insertString(name); syscall(SYS_LOAD_INITRD, id, 0, 0, 0); @@ -75,39 +39,9 @@ discardString(id); } -uint32_t ioIn(uint16_t port, uint8_t size) { - return syscall(SYS_IO_IN, size, port, 0, 0); -} - -void ioOut(uint16_t port, uint32_t value, uint8_t size) { - syscall(SYS_IO_OUT, size, port, value, 0); -} - -void subscribeInterrupt(uint32_t intNo, void *handler) { - syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } - -uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } - -uintptr_t insertString(char *string) { - return syscall(SYS_INSERT_STRING, U32(string), 0, 0, 0); -} - -uintptr_t getStringLength(uintptr_t stringId) { - return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); -} - -void readString(uintptr_t stringId, void *buffer) { - syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); -} - -void discardString(uintptr_t stringId) { - syscall(SYS_DISCARD_STRING, stringId, 0, 0, 0); -} diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c new file mode 100644 index 0000000..8b2ed97 --- /dev/null +++ b/src/userland/hlib/service/events.c @@ -0,0 +1,30 @@ +#include +#include +#include + +uint32_t createEvent(char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uintptr_t hashString(char *string) { + uintptr_t hash = 0; + for (uintptr_t i = 0; string[i]; i++) { + hash = 257 * hash + string[i]; + } + return hash; +} + +uint32_t getEvent(uint32_t service, char *name) { + uintptr_t id = hashString(name); + return syscall(SYS_GET_EVENT, service, id, 0, 0); +} + +void fireEvent(uint32_t eventNumber) { + syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); +} + +void subscribeEvent(uint32_t service, uint32_t event, + void(handler)(void *, uint32_t)) { + syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); +} diff --git a/src/userland/hlib/service/service.c b/src/userland/hlib/service/service.c new file mode 100644 index 0000000..05000ab --- /dev/null +++ b/src/userland/hlib/service/service.c @@ -0,0 +1,26 @@ +#include +#include +#include + +void request(uint32_t module, uint32_t function, uintptr_t data1, + uintptr_t data2) { + syscall(SYS_REQUEST, module, function, data1, data2); +} + +uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)) { + uintptr_t id = insertString(name); + return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); +} + +uint32_t getService(char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_GET_SERVICE, id, 0, 0, 0); +} + +uint32_t getProvider(uint32_t module, char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_GET_PROVIDER, module, id, 0, 0); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/hlib/events/events.c b/src/userland/hlib/events/events.c deleted file mode 100644 index 8b2ed97..0000000 --- a/src/userland/hlib/events/events.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -uint32_t createEvent(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); -} - -uintptr_t hashString(char *string) { - uintptr_t hash = 0; - for (uintptr_t i = 0; string[i]; i++) { - hash = 257 * hash + string[i]; - } - return hash; -} - -uint32_t getEvent(uint32_t service, char *name) { - uintptr_t id = hashString(name); - return syscall(SYS_GET_EVENT, service, id, 0, 0); -} - -void fireEvent(uint32_t eventNumber) { - syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); -} - -void subscribeEvent(uint32_t service, uint32_t event, - void(handler)(void *, uint32_t)) { - syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); -} diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index dc85e4b..f272a6b 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -25,4 +25,6 @@ SYS_DISCARD_STRING = 17, } SyscallIds; +extern uint32_t getProvider(uint32_t module, char *name); + #endif diff --git a/src/userland/hlib/io.c b/src/userland/hlib/io.c new file mode 100644 index 0000000..5a6c3f3 --- /dev/null +++ b/src/userland/hlib/io.c @@ -0,0 +1,14 @@ +#include +#include + +uint32_t ioIn(uint16_t port, uint8_t size) { + return syscall(SYS_IO_IN, size, port, 0, 0); +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + syscall(SYS_IO_OUT, size, port, value, 0); +} + +void subscribeInterrupt(uint32_t intNo, void *handler) { + syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); +} diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 292da46..2ab51fa 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -2,9 +2,6 @@ #include #include -#define PTR(x) ((void *)(uintptr_t)x) -#define U32(x) ((uint32_t)(uintptr_t)x) - uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { uint32_t esp; @@ -25,39 +22,6 @@ return 0; } -void request(uint32_t module, uint32_t function, uintptr_t data1, - uintptr_t data2) { - syscall(SYS_REQUEST, module, function, data1, data2); -} - -uint32_t installServiceProvider(char *name, - int32_t(provider)(void *, uint32_t)) { - uintptr_t id = insertString(name); - return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); -} - -uint32_t strlen(char *string) { - if (!string) { - return 0; - } - uint32_t size = 0; - while (*string) { - string++; - size++; - } - return size; -} - -uint32_t getService(char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_SERVICE, id, 0, 0, 0); -} - -uint32_t getProvider(uint32_t module, char *name) { - uintptr_t id = insertString(name); - return syscall(SYS_GET_PROVIDER, module, id, 0, 0); -} - void loadFromInitrd(char *name) { uintptr_t id = insertString(name); syscall(SYS_LOAD_INITRD, id, 0, 0, 0); @@ -75,39 +39,9 @@ discardString(id); } -uint32_t ioIn(uint16_t port, uint8_t size) { - return syscall(SYS_IO_IN, size, port, 0, 0); -} - -void ioOut(uint16_t port, uint32_t value, uint8_t size) { - syscall(SYS_IO_OUT, size, port, value, 0); -} - -void subscribeInterrupt(uint32_t intNo, void *handler) { - syscall(SYS_SUBSCRIBE_INTERRUPT, intNo, U32(handler), 0, 0); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); uint32_t providerId = getProvider(serviceId, provider); request(serviceId, providerId, data1, data2); } - -uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } - -uintptr_t insertString(char *string) { - return syscall(SYS_INSERT_STRING, U32(string), 0, 0, 0); -} - -uintptr_t getStringLength(uintptr_t stringId) { - return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); -} - -void readString(uintptr_t stringId, void *buffer) { - syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); -} - -void discardString(uintptr_t stringId) { - syscall(SYS_DISCARD_STRING, stringId, 0, 0, 0); -} diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c new file mode 100644 index 0000000..8b2ed97 --- /dev/null +++ b/src/userland/hlib/service/events.c @@ -0,0 +1,30 @@ +#include +#include +#include + +uint32_t createEvent(char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uintptr_t hashString(char *string) { + uintptr_t hash = 0; + for (uintptr_t i = 0; string[i]; i++) { + hash = 257 * hash + string[i]; + } + return hash; +} + +uint32_t getEvent(uint32_t service, char *name) { + uintptr_t id = hashString(name); + return syscall(SYS_GET_EVENT, service, id, 0, 0); +} + +void fireEvent(uint32_t eventNumber) { + syscall(SYS_FIRE_EVENT, eventNumber, 0, 0, 0); +} + +void subscribeEvent(uint32_t service, uint32_t event, + void(handler)(void *, uint32_t)) { + syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); +} diff --git a/src/userland/hlib/service/service.c b/src/userland/hlib/service/service.c new file mode 100644 index 0000000..05000ab --- /dev/null +++ b/src/userland/hlib/service/service.c @@ -0,0 +1,26 @@ +#include +#include +#include + +void request(uint32_t module, uint32_t function, uintptr_t data1, + uintptr_t data2) { + syscall(SYS_REQUEST, module, function, data1, data2); +} + +uint32_t installServiceProvider(char *name, + int32_t(provider)(void *, uint32_t)) { + uintptr_t id = insertString(name); + return syscall(SYS_REGISTER_FUNCTION, id, U32(provider), 0, 0); +} + +uint32_t getService(char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_GET_SERVICE, id, 0, 0, 0); +} + +uint32_t getProvider(uint32_t module, char *name) { + uintptr_t id = insertString(name); + return syscall(SYS_GET_PROVIDER, module, id, 0, 0); +} + +uint32_t getServiceId() { return syscall(SYS_GET_SERVICE_ID, 0, 0, 0, 0); } diff --git a/src/userland/hlib/strings.c b/src/userland/hlib/strings.c new file mode 100644 index 0000000..0c3b420 --- /dev/null +++ b/src/userland/hlib/strings.c @@ -0,0 +1,31 @@ +#include +#include +#include + +uint32_t strlen(char *string) { + if (!string) { + return 0; + } + uint32_t size = 0; + while (*string) { + string++; + size++; + } + return size; +} + +uintptr_t insertString(char *string) { + return syscall(SYS_INSERT_STRING, U32(string), 0, 0, 0); +} + +uintptr_t getStringLength(uintptr_t stringId) { + return syscall(SYS_GET_STRING_LENGTH, stringId, 0, 0, 0); +} + +void readString(uintptr_t stringId, void *buffer) { + syscall(SYS_READ_STRING, stringId, U32(buffer), 0, 0); +} + +void discardString(uintptr_t stringId) { + syscall(SYS_DISCARD_STRING, stringId, 0, 0, 0); +}