aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/init.c1
-rw-r--r--apps/test.c15
-rw-r--r--apps/wm.c35
-rw-r--r--kernel/features/proc.c13
-rw-r--r--kernel/features/syscall.c7
-rw-r--r--kernel/inc/proc.h1
-rw-r--r--libc/inc/sys.h2
-rw-r--r--libgui/inc/gui.h13
8 files changed, 70 insertions, 17 deletions
diff --git a/apps/init.c b/apps/init.c
index f00110e..05d1a3c 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -11,5 +11,6 @@ int main(int argc, char **argv)
int wm = exec("/wm", "wm", argv[1], NULL);
int test = exec("/test", "test", NULL);
+
return wm + test;
}
diff --git a/apps/test.c b/apps/test.c
index 8004b34..b511ab3 100644
--- a/apps/test.c
+++ b/apps/test.c
@@ -5,7 +5,20 @@
int main()
{
print("[test loaded]\n");
- gui_new_window();
+ printf("TIME: %d\n", time());
+
+ /* struct window *win = gui_new_window(); */
+ msg_send(1, MSG_NEW_WINDOW, NULL);
+ struct message *msg = msg_receive_loop();
+ struct window *win = (struct window *)msg->data;
+
+ // TODO: Fix window transmitting
+ printf("\nReceived %d from %d\n", win->x, msg->src);
+ printf("Received %d from %d\n", win->y, msg->src);
+ printf("Received %d from %d\n", win->width, msg->src);
+ printf("Received %d from %d\n", win->height, msg->src);
+ printf("Received %d from %d\n", win->fb, msg->src);
+
while (1) {
};
return 0;
diff --git a/apps/wm.c b/apps/wm.c
index ffb1b4d..3984abc 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -3,11 +3,16 @@
#include <def.h>
#include <gui.h>
#include <input.h>
+#include <list.h>
+#include <mem.h>
#include <print.h>
#include <random.h>
#include <sys.h>
#include <vesa.h>
+struct vbe *vbe;
+struct list *windows;
+
void onkey(u32 scancode)
{
printf("WM KEY EVENT %d\n", scancode);
@@ -17,36 +22,46 @@ void onkey(u32 scancode)
event_resolve();
}
-int main(int argc, char **argv)
+static struct window *new_window(int x, int y, u16 width, u16 height)
{
- srand(time());
-
- printf("ARGC: %d\n", argc);
- printf("[%s loaded]\n", argv[0]);
+ struct window *win = malloc(sizeof(*win));
+ win->x = x;
+ win->y = y;
+ win->width = width;
+ win->height = height;
+ win->fb = malloc(width * height * (vbe->bpp >> 3));
+ return win;
+}
- struct vbe *vbe = (struct vbe *)argv[1];
+int main(int argc, char **argv)
+{
+ (void)argc;
+ vbe = (struct vbe *)argv[1];
+ windows = list_new();
printf("VBE: %dx%d\n", vbe->width, vbe->height);
const u32 color[3] = { 0, 0, 0 };
- const u32 text[3] = { 0xff, 0xff, 0xff };
vesa_fill(vbe, color);
gui_init("/font/spleen-16x32.psfu");
- gui_write(vbe, 50, 50, text, "hallo");
event_map(EVENT_KEYBOARD, onkey);
struct message *msg;
while (1) { // TODO: Remove continuous polling?
- if (!(msg = msg_receive()))
+ if (!(msg = msg_receive())) {
+ yield();
continue;
+ }
switch (msg->type) {
case MSG_NEW_WINDOW:
printf("New window for pid %d\n", msg->src);
+ struct window *win = new_window(50, 50, 200, 200);
+ msg_send(msg->src, MSG_NEW_WINDOW, win);
break;
default:
- printf("Unknown WM request!");
+ printf("Unknown WM request %d from pid %d", msg->type, msg->src);
}
};
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index d1a2780..1c0b443 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -17,8 +17,11 @@ u32 quantum = 0;
struct list *proc_list;
struct node *current;
+// TODO: Use less memcpy and only copy relevant registers
void scheduler(struct regs *regs)
{
+ timer_handler();
+
if (quantum == 0) {
quantum = PROC_QUANTUM;
} else {
@@ -34,8 +37,6 @@ void scheduler(struct regs *regs)
if (current)
memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs));
- timer_handler();
-
if (current && current->next)
current = current->next;
else
@@ -71,9 +72,9 @@ void scheduler(struct regs *regs)
quantum = PROC_QUANTUM;
proc->state = PROC_IN_EVENT;
- list_remove(proc->events, proc->events->head);
regs->useresp += 4;
((u32 *)regs->useresp)[1] = (u32)proc_event->data; // Huh
+ list_remove(proc->events, proc->events->head);
}
/* printf("{%d}", ((struct proc *)current->data)->pid); */
@@ -158,6 +159,12 @@ void proc_exit(struct proc *proc, int status)
hlt();
}
+// TODO: More instant yield
+void proc_yield()
+{
+ quantum = 0;
+}
+
struct proc *proc_make()
{
struct proc *proc = malloc(sizeof(*proc));
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 9bd5e9b..2a310ef 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -17,7 +17,7 @@ void syscall_handler(struct regs *r)
enum sys num = r->eax;
r->eax = 0;
- if (num != SYS_RECEIVE)
+ if (num != SYS_RECEIVE && num != SYS_YIELD)
printf("[SYSCALL] %d: ", num);
switch (num) {
@@ -69,6 +69,11 @@ void syscall_handler(struct regs *r)
proc_exit(proc_current(), r->ebx);
break;
}
+ case SYS_YIELD: {
+ /* printf("yield\n"); */
+ proc_yield();
+ break;
+ }
case SYS_TIME: {
printf("time\n");
r->eax = timer_get();
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index e9d1612..186c18e 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -48,6 +48,7 @@ struct proc_message *proc_receive(struct proc *proc);
void proc_resolve(struct proc *proc);
struct proc *proc_from_pid(u32 pid);
void proc_exit(struct proc *proc, int status);
+void proc_yield();
struct proc *proc_make();
#endif
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index dc6aaf1..8bff39b 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -12,6 +12,7 @@ enum sys {
SYS_WRITE, // Write to file
SYS_EXEC, // Execute path
SYS_EXIT, // Exit current process
+ SYS_YIELD, // Switch to next process
SYS_TIME, // Get kernel time
SYS_MAP, // Map event to function
SYS_UNMAP, // Unmap event
@@ -52,6 +53,7 @@ int sysv(enum sys num, ...);
while (1) { \
} \
}
+#define yield() (int)sys0(SYS_YIELD)
#define time() (int)sys0(SYS_TIME)
#define event_map(id, func) sys2(SYS_MAP, (int)(id), (int)(func))
diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h
index acef037..5f35372 100644
--- a/libgui/inc/gui.h
+++ b/libgui/inc/gui.h
@@ -16,12 +16,21 @@ struct font {
int char_size;
};
-void gui_write(struct vbe *vbe, int x, int y, const u32 c[3], char *text);
+struct window {
+ int x;
+ int y;
+ u16 width;
+ u16 height;
+ u8 *fb;
+};
+
void gui_init(char *font_path);
/**
* Wrappers
*/
-#define gui_new_window() msg_send(1, MSG_NEW_WINDOW, NULL);
+
+#define gui_new_window() \
+ (msg_send(1, MSG_NEW_WINDOW, NULL), (struct window *)msg_receive_loop()->data)
#endif