diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 196bbe4..7ca1032 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -120,6 +120,7 @@ putInt(write, x); } } +uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { uintptr_t size = 0; @@ -145,6 +146,9 @@ write++; } va_end(valist); - log(data); + + uintptr_t id = insertString(data); + request(ioManager, logFunction, id, 0); + discardString(id); free(data); } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 196bbe4..7ca1032 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -120,6 +120,7 @@ putInt(write, x); } } +uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { uintptr_t size = 0; @@ -145,6 +146,9 @@ write++; } va_end(valist); - log(data); + + uintptr_t id = insertString(data); + request(ioManager, logFunction, id, 0); + discardString(id); free(data); } diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index f1c0a9a..0a13b8e 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -8,7 +8,7 @@ uint32_t mainService, mainOut, globalService, globalOut; -uint32_t focusService; +uint32_t focusService, focusServiceKeyHandler; uint32_t currentKeyConsumerService, currentKeyConsumerFunction; void writeString(char *string) { @@ -22,14 +22,16 @@ while (lock) { syscall(-1, 0, 0, 0, 0); } - lock = true; if (callerId == focusService) { + lock = true; readString(stringId, buffer); for (uint32_t i = 0; buffer[i]; i++) { request(mainService, mainOut, buffer[i], 0); } + lock = false; return; } + lock = true; writeString("[ "); readString(caller, buffer); writeString(buffer); @@ -45,17 +47,26 @@ lock = false; } -extern uint32_t logService, logFunction; +extern uint32_t ioManager, logFunction, keyCallback; -void setForeground(uint32_t service) { focusService = service; } +void setForeground(uint32_t service) { + focusService = service; + focusServiceKeyHandler = 0; +} + +void handleKey(uint32_t keycode, uint32_t stringId) { + focusServiceKeyHandler = getFunction(focusService, "onKey"); + request(focusService, focusServiceKeyHandler, keycode, stringId); +} int32_t main() { - logService = getServiceId(); + ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); + keyCallback = createFunction("", (void *)handleKey); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); - globalOut = getFunction(mainService, "writeChar"); + globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); loadFromInitrd("pic"); loadFromInitrd("keyboard"); diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 196bbe4..7ca1032 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -120,6 +120,7 @@ putInt(write, x); } } +uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { uintptr_t size = 0; @@ -145,6 +146,9 @@ write++; } va_end(valist); - log(data); + + uintptr_t id = insertString(data); + request(ioManager, logFunction, id, 0); + discardString(id); free(data); } diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index f1c0a9a..0a13b8e 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -8,7 +8,7 @@ uint32_t mainService, mainOut, globalService, globalOut; -uint32_t focusService; +uint32_t focusService, focusServiceKeyHandler; uint32_t currentKeyConsumerService, currentKeyConsumerFunction; void writeString(char *string) { @@ -22,14 +22,16 @@ while (lock) { syscall(-1, 0, 0, 0, 0); } - lock = true; if (callerId == focusService) { + lock = true; readString(stringId, buffer); for (uint32_t i = 0; buffer[i]; i++) { request(mainService, mainOut, buffer[i], 0); } + lock = false; return; } + lock = true; writeString("[ "); readString(caller, buffer); writeString(buffer); @@ -45,17 +47,26 @@ lock = false; } -extern uint32_t logService, logFunction; +extern uint32_t ioManager, logFunction, keyCallback; -void setForeground(uint32_t service) { focusService = service; } +void setForeground(uint32_t service) { + focusService = service; + focusServiceKeyHandler = 0; +} + +void handleKey(uint32_t keycode, uint32_t stringId) { + focusServiceKeyHandler = getFunction(focusService, "onKey"); + request(focusService, focusServiceKeyHandler, keycode, stringId); +} int32_t main() { - logService = getServiceId(); + ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); + keyCallback = createFunction("", (void *)handleKey); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); - globalOut = getFunction(mainService, "writeChar"); + globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); loadFromInitrd("pic"); loadFromInitrd("keyboard"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8d1cc9e..791330b 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,5 @@ #define ALLOC_MAIN + #include #include @@ -53,6 +54,8 @@ return scancode; } +extern uint32_t ioManager, keyCallback; + void onKey() { uint8_t scancode = getScancode(); if (scancode == 0xE0) { @@ -60,7 +63,7 @@ if (scancode & 0x80) { return; } - printf("key press %s detected\n", altKeycodes[scancode]); + request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); return; } if (scancode & 0x80) { @@ -84,7 +87,7 @@ } else { data = keycodes[scancode]; } - printf("key press %c detected\n", data); + request(ioManager, keyCallback, data, 0); } int32_t main() { diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 196bbe4..7ca1032 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -120,6 +120,7 @@ putInt(write, x); } } +uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { uintptr_t size = 0; @@ -145,6 +146,9 @@ write++; } va_end(valist); - log(data); + + uintptr_t id = insertString(data); + request(ioManager, logFunction, id, 0); + discardString(id); free(data); } diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index f1c0a9a..0a13b8e 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -8,7 +8,7 @@ uint32_t mainService, mainOut, globalService, globalOut; -uint32_t focusService; +uint32_t focusService, focusServiceKeyHandler; uint32_t currentKeyConsumerService, currentKeyConsumerFunction; void writeString(char *string) { @@ -22,14 +22,16 @@ while (lock) { syscall(-1, 0, 0, 0, 0); } - lock = true; if (callerId == focusService) { + lock = true; readString(stringId, buffer); for (uint32_t i = 0; buffer[i]; i++) { request(mainService, mainOut, buffer[i], 0); } + lock = false; return; } + lock = true; writeString("[ "); readString(caller, buffer); writeString(buffer); @@ -45,17 +47,26 @@ lock = false; } -extern uint32_t logService, logFunction; +extern uint32_t ioManager, logFunction, keyCallback; -void setForeground(uint32_t service) { focusService = service; } +void setForeground(uint32_t service) { + focusService = service; + focusServiceKeyHandler = 0; +} + +void handleKey(uint32_t keycode, uint32_t stringId) { + focusServiceKeyHandler = getFunction(focusService, "onKey"); + request(focusService, focusServiceKeyHandler, keycode, stringId); +} int32_t main() { - logService = getServiceId(); + ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); + keyCallback = createFunction("", (void *)handleKey); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); - globalOut = getFunction(mainService, "writeChar"); + globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); loadFromInitrd("pic"); loadFromInitrd("keyboard"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8d1cc9e..791330b 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,5 @@ #define ALLOC_MAIN + #include #include @@ -53,6 +54,8 @@ return scancode; } +extern uint32_t ioManager, keyCallback; + void onKey() { uint8_t scancode = getScancode(); if (scancode == 0xE0) { @@ -60,7 +63,7 @@ if (scancode & 0x80) { return; } - printf("key press %s detected\n", altKeycodes[scancode]); + request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); return; } if (scancode & 0x80) { @@ -84,7 +87,7 @@ } else { data = keycodes[scancode]; } - printf("key press %c detected\n", data); + request(ioManager, keyCallback, data, 0); } int32_t main() { diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index aead40a..7763f2b 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -7,8 +7,7 @@ loadFromInitrd("ioManager"); printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); - loadFromInitrd("crashTest"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); - requestName("shell", "main", 0, 0); + request(id, 0, 0, 0); } diff --git a/src/userland/hlib/main.c b/src/userland/hlib/main.c index 8ec79a2..0f558b1 100644 --- a/src/userland/hlib/main.c +++ b/src/userland/hlib/main.c @@ -32,14 +32,6 @@ return syscall(SYS_LOAD_INITRD, id, 0, 0, 0); } -uint32_t logService, logFunction; - -void log(char *message) { - uintptr_t id = insertString(message); - request(logService, logFunction, id, 0); - discardString(id); -} - void requestName(char *service, char *provider, uintptr_t data1, uintptr_t data2) { uint32_t serviceId = getService(service); diff --git a/src/userland/hlib/stdio.c b/src/userland/hlib/stdio.c index 196bbe4..7ca1032 100644 --- a/src/userland/hlib/stdio.c +++ b/src/userland/hlib/stdio.c @@ -120,6 +120,7 @@ putInt(write, x); } } +uint32_t ioManager, logFunction, keyCallback; void _printf(void *(malloc)(uint32_t), const char *format, ...) { uintptr_t size = 0; @@ -145,6 +146,9 @@ write++; } va_end(valist); - log(data); + + uintptr_t id = insertString(data); + request(ioManager, logFunction, id, 0); + discardString(id); free(data); } diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index f1c0a9a..0a13b8e 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -8,7 +8,7 @@ uint32_t mainService, mainOut, globalService, globalOut; -uint32_t focusService; +uint32_t focusService, focusServiceKeyHandler; uint32_t currentKeyConsumerService, currentKeyConsumerFunction; void writeString(char *string) { @@ -22,14 +22,16 @@ while (lock) { syscall(-1, 0, 0, 0, 0); } - lock = true; if (callerId == focusService) { + lock = true; readString(stringId, buffer); for (uint32_t i = 0; buffer[i]; i++) { request(mainService, mainOut, buffer[i], 0); } + lock = false; return; } + lock = true; writeString("[ "); readString(caller, buffer); writeString(buffer); @@ -45,17 +47,26 @@ lock = false; } -extern uint32_t logService, logFunction; +extern uint32_t ioManager, logFunction, keyCallback; -void setForeground(uint32_t service) { focusService = service; } +void setForeground(uint32_t service) { + focusService = service; + focusServiceKeyHandler = 0; +} + +void handleKey(uint32_t keycode, uint32_t stringId) { + focusServiceKeyHandler = getFunction(focusService, "onKey"); + request(focusService, focusServiceKeyHandler, keycode, stringId); +} int32_t main() { - logService = getServiceId(); + ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); + keyCallback = createFunction("", (void *)handleKey); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); - globalOut = getFunction(mainService, "writeChar"); + globalOut = getFunction(globalService, "writeChar"); loadFromInitrd("log"); loadFromInitrd("pic"); loadFromInitrd("keyboard"); diff --git a/src/userland/keyboard/main.c b/src/userland/keyboard/main.c index 8d1cc9e..791330b 100644 --- a/src/userland/keyboard/main.c +++ b/src/userland/keyboard/main.c @@ -1,4 +1,5 @@ #define ALLOC_MAIN + #include #include @@ -53,6 +54,8 @@ return scancode; } +extern uint32_t ioManager, keyCallback; + void onKey() { uint8_t scancode = getScancode(); if (scancode == 0xE0) { @@ -60,7 +63,7 @@ if (scancode & 0x80) { return; } - printf("key press %s detected\n", altKeycodes[scancode]); + request(ioManager, keyCallback, 0, U32(altKeycodes[scancode])); return; } if (scancode & 0x80) { @@ -84,7 +87,7 @@ } else { data = keycodes[scancode]; } - printf("key press %c detected\n", data); + request(ioManager, keyCallback, data, 0); } int32_t main() { diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index aead40a..7763f2b 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -7,8 +7,7 @@ loadFromInitrd("ioManager"); printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); - loadFromInitrd("crashTest"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); - requestName("shell", "main", 0, 0); + request(id, 0, 0, 0); } diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 69df12e..71c2e63 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -3,4 +3,12 @@ #include #include -int32_t main() { printf("HONEY-OS - made by Lukas Eisenhauer\n"); } +char inputBuffer[256]; +uint8_t inputBufferPosition; + +void onKeyInput(uint32_t keycode, uint32_t stringId) { printf("%c", keycode); } + +int32_t main() { + createFunction("onKey", (void *)onKeyInput); + printf("HONEY-OS - made by Lukas Eisenhauer\n> "); +}