diff options
-rw-r--r-- | apps/init.c | 3 | ||||
-rw-r--r-- | apps/test.c | 4 | ||||
-rw-r--r-- | apps/wm.c | 5 | ||||
-rw-r--r-- | kernel/drivers/mouse.c | 10 | ||||
-rw-r--r-- | kernel/features/proc.c | 60 | ||||
-rw-r--r-- | kernel/inc/proc.h | 12 | ||||
-rw-r--r-- | libc/inc/def.h | 1 | ||||
-rw-r--r-- | libc/inc/print.h | 10 | ||||
-rw-r--r-- | libc/inc/sys.h | 4 | ||||
-rw-r--r-- | libc/mem.c | 14 | ||||
-rw-r--r-- | libc/print.c | 107 | ||||
-rw-r--r-- | libc/sys.c | 4 | ||||
-rw-r--r-- | libgui/inc/gfx.h | 2 | ||||
-rw-r--r-- | libgui/inc/gui.h | 2 | ||||
-rwxr-xr-x | run | 4 |
15 files changed, 183 insertions, 59 deletions
diff --git a/apps/init.c b/apps/init.c index 3cb4527..bb9a556 100644 --- a/apps/init.c +++ b/apps/init.c @@ -9,8 +9,7 @@ int main(int argc, char **argv) { (void)argc; - /* printf("ARGC: %d\n", argc); */ - /* printf("[%s loaded]\n", argv[0]); */ + log("%s loaded\n", argv[0]); int wm = exec("/bin/wm", "wm", argv[1], NULL); int exec = exec("/bin/exec", "test", NULL); diff --git a/apps/test.c b/apps/test.c index c47e060..101c215 100644 --- a/apps/test.c +++ b/apps/test.c @@ -24,8 +24,8 @@ void pass_or_fail(const char *file_name, int line_num, const char *func, const c const char *second, int success) { failed += success ? 0 : 1; - printf("\x1B[%s\x1B[0m %s:%d: %s: %s == %s\n", success ? "32m[PASS]" : "31m[FAIL]", - file_name, line_num, func, first, second); + log("\x1B[%s\x1B[0m %s:%d: %s: %s == %s\n", success ? "32m[PASS]" : "31m[FAIL]", file_name, + line_num, func, first, second); } void test_malloc() @@ -264,7 +264,7 @@ int main(int argc, char **argv) (void)argc; int pid = getpid(); vbe = *(struct vbe *)argv[1]; - /* printf("VBE: %dx%d\n", vbe.width, vbe.height); */ + log("WM loaded: %dx%d\n", vbe.width, vbe.height); keymap = keymap_parse("/res/keymaps/en.keymap"); @@ -307,8 +307,7 @@ int main(int argc, char **argv) continue; } } else { - printf("POLL ERROR!\n"); - return 1; + err(1, "POLL ERROR!\n"); } switch (msg.type) { diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c index b03ed50..1e7fd1a 100644 --- a/kernel/drivers/mouse.c +++ b/kernel/drivers/mouse.c @@ -136,8 +136,9 @@ void mouse_install(void) mouse_serial_write(0xF2); mouse_serial_read(); status = (u8)mouse_serial_read(); - if (status == 3) - printf("Scrollwheel support!\n"); + if (status == 3) { + }; + /* printf("Scrollwheel support!\n"); */ // Activate 4th and 5th mouse buttons mouse_serial_write(0xF2); @@ -158,8 +159,9 @@ void mouse_install(void) mouse_serial_write(0xF2); mouse_serial_read(); status = (u8)mouse_serial_read(); - if (status == 4) - printf("4th and 5th mouse button support!\n"); + if (status == 4) { + }; + /* printf("4th and 5th mouse button support!\n"); */ /* TODO: Fix mouse laggyness mouse_serial_write(0xE8); diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 0f88e60..9c7fcdc 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -228,7 +228,6 @@ struct proc *proc_make(void) } // TODO: Procfs needs a simpler interface structure (memcmp and everything sucks) -// TODO: Handle stream overflows const char *procfs_parse_path(const char **path, u32 *pid) { @@ -248,19 +247,19 @@ const char *procfs_parse_path(const char **path, u32 *pid) return *path; } -struct stream *procfs_get_stream(const char *path, struct proc *proc) +enum stream_defaults procfs_stream(const char *path) { - struct stream *stream = NULL; if (!memcmp(path, "in", 3)) { - stream = &proc->streams[STREAM_IN]; + return STREAM_IN; } else if (!memcmp(path, "out", 4)) { - stream = &proc->streams[STREAM_IN]; + return STREAM_OUT; } else if (!memcmp(path, "err", 4)) { - stream = &proc->streams[STREAM_IN]; + return STREAM_ERR; } else if (!memcmp(path, "log", 4)) { - stream = &proc->streams[STREAM_LOG]; + return STREAM_LOG; + } else { + return STREAM_UNKNOWN; } - return stream; } s32 procfs_write(const char *path, void *buf, u32 offset, u32 count, struct device *dev) @@ -279,15 +278,20 @@ s32 procfs_write(const char *path, void *buf, u32 offset, u32 count, struct devi return count; } else if (!memcmp(path, "io/", 3)) { path += 3; - struct stream *stream = procfs_get_stream(path, p); - if (stream) { - memcpy((char *)(stream->data + stream->pos), buf, count); - stream->pos += count; - proc_enable_waiting(dev->id, PROC_WAIT_DEV); - return count; - } else { + enum stream_defaults id = procfs_stream(path); + if (id == STREAM_UNKNOWN) return -1; - } + + // Put proc log/err messages to serial console for debugging + if (id == STREAM_LOG || id == STREAM_ERR) + print_app(id, p->name, (char *)buf); + + struct stream *stream = &p->streams[id]; + assert(stream->offset_write + count < STREAM_MAX_SIZE); // TODO: Resize + memcpy((char *)(stream->data + stream->offset_write), buf, count); + stream->offset_write += count; + proc_enable_waiting(dev->id, PROC_WAIT_DEV); + return count; } } @@ -329,15 +333,13 @@ s32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struct devic } } else if (!memcmp(path, "io/", 3)) { path += 3; - struct stream *stream = procfs_get_stream(path, p); - - if (stream) { - memcpy(buf, stream->data + stream->offset, count); - stream->offset += count; - return count; - } else { + enum stream_defaults id = procfs_stream(path); + if (id == STREAM_UNKNOWN) return -1; - } + struct stream *stream = &p->streams[id]; + memcpy(buf, stream->data + stream->offset_read, count); + stream->offset_read += count; + return count; } } @@ -372,13 +374,11 @@ u8 procfs_ready(const char *path, struct device *dev) return stack_empty(p->messages) == 0; } else if (!memcmp(path, "io/", 3)) { path += 3; - struct stream *stream = procfs_get_stream(path, p); - - if (stream) { - return stream->data[stream->offset] != 0; - } else { + enum stream_defaults id = procfs_stream(path); + if (id == STREAM_UNKNOWN) return -1; - } + struct stream *stream = &p->streams[id]; + return stream->data[stream->offset_read] != 0; } } diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 9f78a3e..593141b 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -19,10 +19,8 @@ #define PROC_MAX_WAIT_IDS 16 -#define STREAM_IN 0 -#define STREAM_OUT 1 -#define STREAM_ERR 2 -#define STREAM_LOG 3 +#define STREAM_MAX_SIZE 4096 +enum stream_defaults { STREAM_IN, STREAM_OUT, STREAM_ERR, STREAM_LOG, STREAM_UNKNOWN = -1 }; enum proc_state { PROC_RUNNING, PROC_SLEEPING }; enum proc_wait_type { PROC_WAIT_DEV }; @@ -35,9 +33,9 @@ struct proc_wait { }; struct stream { - u32 offset; - u32 pos; - char data[4096]; + u32 offset_read; + u32 offset_write; + char data[STREAM_MAX_SIZE]; }; struct proc { diff --git a/libc/inc/def.h b/libc/inc/def.h index 2c77203..a6e3210 100644 --- a/libc/inc/def.h +++ b/libc/inc/def.h @@ -23,6 +23,7 @@ typedef unsigned long long u64; * Macros */ +#define EOF (-1) #define NULL ((void *)0) #define U8_MAX 255 diff --git a/libc/inc/print.h b/libc/inc/print.h index 04668b2..575cc5f 100644 --- a/libc/inc/print.h +++ b/libc/inc/print.h @@ -11,4 +11,14 @@ int vprintf(const char *format, va_list ap); int vsprintf(char *str, const char *format, va_list ap); int print(const char *str); +#ifdef userspace +int vfprintf(const char *path, const char *format, va_list ap); +int fprintf(const char *path, const char *format, ...); +int log(const char *format, ...); +int err(int code, const char *format, ...); +#else +#include <proc.h> +int print_app(enum stream_defaults id, const char *proc_name, const char *str); +#endif + #endif diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 231a0e2..d7e5e3d 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -28,8 +28,6 @@ enum sys { SYS_NET_RECEIVE, // Receive data from socket }; -enum event_type { EVENT_KEYBOARD, EVENT_MOUSE, EVENT_MAX }; - struct message { int src; int type; @@ -70,7 +68,7 @@ int sys5(enum sys num, int d1, int d2, int d3, int d4, int d5); int sysv(enum sys num, ...); /** - * Wrappers + * Syscall wrappers */ #define loop() sys0(SYS_LOOP) @@ -364,6 +364,11 @@ void _free(void *ptr) void *malloc_debug(u32 size, const char *file, int line, const char *func, const char *inp) { void *ret = _malloc(size); + + (void)file; + (void)line; + (void)func; + (void)inp; /* #ifdef kernel */ /* printf("K"); */ /* #else */ @@ -375,12 +380,17 @@ void *malloc_debug(u32 size, const char *file, int line, const char *func, const void free_debug(void *ptr, const char *file, int line, const char *func, const char *inp) { + if (ptr) + _free(ptr); + + (void)file; + (void)line; + (void)func; + (void)inp; /* #ifdef kernel */ /* printf("K"); */ /* #else */ /* printf("U"); */ /* #endif */ /* printf("FREE\t%s:%d: %s: 0x%x (%s)\n", file, line, func, ptr, inp); */ - if (ptr) - _free(ptr); } diff --git a/libc/print.c b/libc/print.c index e98fca6..a66692e 100644 --- a/libc/print.c +++ b/libc/print.c @@ -63,6 +63,8 @@ int vsprintf(char *str, const char *format, va_list ap) } else if (buf == 'c') { str[i] = (char)va_arg(ap, int); i++; + } else { + assert(0); } } else { if (*format == '%') @@ -79,15 +81,35 @@ int vsprintf(char *str, const char *format, va_list ap) return strlen(str); } -int vprintf(const char *format, va_list ap) +#ifdef userspace + +#include <sys.h> +#define PATH_OUT "/proc/self/io/out" +#define PATH_LOG "/proc/self/io/log" +#define PATH_ERR "/proc/self/io/err" + +int vfprintf(const char *path, const char *format, va_list ap) { char buf[1024] = { 0 }; int len = vsprintf(buf, format, ap); - serial_print(buf); // TODO: Remove temporary serial print + return write(path, buf, 0, len); +} + +int vprintf(const char *format, va_list ap) +{ + return vfprintf(PATH_OUT, format, ap); +} + +int fprintf(const char *path, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int len = vfprintf(path, format, ap); + va_end(ap); + return len; } -// TODO: Fix printf for *very* large strings (serial works) int printf(const char *format, ...) { va_list ap; @@ -98,8 +120,87 @@ int printf(const char *format, ...) return len; } +int log(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int len = vfprintf(PATH_LOG, format, ap); + va_end(ap); + + return len; +} + +int err(int code, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vfprintf(PATH_ERR, format, ap); + va_end(ap); + exit(code); +} + int print(const char *str) { + return write(PATH_OUT, str, 0, strlen(str)); +} + +#else + +// The kernel prints everything into the serial console +#include <proc.h> + +#define RED "\x1B[1;31m" +#define GRN "\x1B[1;32m" +#define YEL "\x1B[1;33m" +#define BLU "\x1B[1;34m" +#define MAG "\x1B[1;35m" +#define CYN "\x1B[1;36m" +#define WHT "\x1B[1;37m" +#define RES "\x1B[0m" + +void print_kernel(const char *str) +{ + serial_print(RED); + serial_print("[KER] "); + serial_print(str); + serial_print(RES); +} + +int vprintf(const char *format, va_list ap) +{ + char buf[1024] = { 0 }; + int len = vsprintf(buf, format, ap); + print_kernel(buf); + return len; +} + +int printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int len = vprintf(format, ap); + va_end(ap); + + return len; +} + +int print_app(enum stream_defaults id, const char *proc_name, const char *str) +{ + if (id == STREAM_LOG) + serial_print(CYN "[LOG] to "); + else if (id == STREAM_ERR) + serial_print(YEL "[ERR] to "); + serial_print(proc_name); + serial_print(": "); serial_print(str); + serial_print(RES); + return 1; +} + +int print(const char *str) +{ + print_kernel(str); return strlen(str); } + +#endif @@ -4,6 +4,8 @@ #include <arg.h> #include <sys.h> +#if defined(userspace) + /** * Definitions */ @@ -69,3 +71,5 @@ int sysv(enum sys num, ...) return sys5(num, args[0], args[1], args[2], args[3], args[4]); } + +#endif diff --git a/libgui/inc/gfx.h b/libgui/inc/gfx.h index 718fd28..4998d30 100644 --- a/libgui/inc/gfx.h +++ b/libgui/inc/gfx.h @@ -42,7 +42,7 @@ enum font_type { FONT_8, FONT_12, FONT_16, FONT_24, FONT_32, FONT_64 }; -enum message_type { GFX_NEW_CONTEXT = EVENT_MAX + 1, GFX_REDRAW, GFX_REDRAW_FOCUSED, GFX_MAX }; +enum message_type { GFX_NEW_CONTEXT, GFX_REDRAW, GFX_REDRAW_FOCUSED, GFX_MAX }; // Generalized font struct struct font { diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h index 331d8b1..8de1f51 100644 --- a/libgui/inc/gui.h +++ b/libgui/inc/gui.h @@ -13,7 +13,7 @@ #define MAX_INPUT_LENGTH 100 // TODO: Improve event types (maybe as struct header) -enum window_event_type { GUI_KILL, GUI_KEYBOARD = GFX_MAX + 1, GUI_MOUSE, GUI_RESIZE, GUI_MAX }; +enum window_event_type { GUI_KILL, GUI_KEYBOARD, GUI_MOUSE, GUI_RESIZE, GUI_MAX }; enum element_type { GUI_TYPE_ROOT, GUI_TYPE_CONTAINER, @@ -85,7 +85,8 @@ make_cross() { } make_disk() { - rm -rf disk && mkdir -p disk/font/ + rm -rf disk && mkdir -p disk/font/ && mkdir -p disk/conf/ + echo "Hallo" > disk/conf/test cp -r res/ disk/ @@ -140,6 +141,7 @@ make_build() { $SUDO mount build/disk.img mnt/ fi $SUDO cp -r disk/* mnt/ + $SUDO chmod -R 0 mnt/conf/ $SUDO cp -r build/apps/ mnt/bin/ $SUDO cp build/load.bin mnt/ $SUDO cp build/kernel.bin mnt/ |