aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2021-03-14 16:12:44 +0100
committerGitHub2021-03-14 16:12:44 +0100
commit268f3ccdb90ab4b9bd70ca176478797aae97ca05 (patch)
tree2dbc3e52d90dab4aae8021773f09b6b72a74b8cb /apps
parent4309322f9d2b3e31421a3cc5399ab1f4368e0652 (diff)
parent6dec7db5158447b66f31a3f786ce2916cab83cec (diff)
Added memory management using paging
This was quite a roller-coaster and most things are slower now, but it works and is way more secure. I still need to implement things like shared memory for the WM/GUI system but other than that everything is supported.
Diffstat (limited to 'apps')
-rw-r--r--apps/Makefile2
-rw-r--r--apps/idle.c7
-rw-r--r--apps/init.c8
-rw-r--r--apps/test.c6
-rw-r--r--apps/window.c4
-rw-r--r--apps/wm.c79
6 files changed, 54 insertions, 52 deletions
diff --git a/apps/Makefile b/apps/Makefile
index 8426b9c..2c6c643 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -1,6 +1,6 @@
# MIT License, Copyright (c) 2020 Marvin Borner
-COBJS = init.o wm.o test.o window.o #mandelbrot.o window.o exec.o files.o test.o cc.o browser.o server.o
+COBJS = init.o idle.o wm.o test.o window.o #mandelbrot.o window.o exec.o files.o test.o cc.o browser.o server.o
CC = ccache ../cross/opt/bin/i686-elf-gcc
LD = ccache ../cross/opt/bin/i686-elf-ld
OC = ccache ../cross/opt/bin/i686-elf-objcopy
diff --git a/apps/idle.c b/apps/idle.c
new file mode 100644
index 0000000..3f10c3e
--- /dev/null
+++ b/apps/idle.c
@@ -0,0 +1,7 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+int main(void)
+{
+ while (1)
+ ;
+}
diff --git a/apps/init.c b/apps/init.c
index 87f0d82..c59e3bf 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -6,12 +6,14 @@
#include <str.h>
#include <sys.h>
+#include <cpu.h>
+
int main(int argc, char **argv)
{
- (void)argc;
- log("%s loaded\n", argv[0]);
+ UNUSED(argc);
+ UNUSED(argv);
- int wm = exec("/bin/wm", "wm", argv[1], NULL);
+ int wm = exec("/bin/wm", "wm", NULL);
int test = exec("/bin/window", "test", NULL);
return wm + test;
diff --git a/apps/test.c b/apps/test.c
index 80f24ad..d64e224 100644
--- a/apps/test.c
+++ b/apps/test.c
@@ -82,11 +82,7 @@ int main(void)
else
log("All tests passed\n");
- // Try emulator shutdown
- outw(0xB004, 0x2000);
- outw(0x604, 0x2000);
- outw(0x4004, 0x3400);
+ boot(SYS_BOOT_SHUTDOWN);
- loop();
return 0;
}
diff --git a/apps/window.c b/apps/window.c
index ac29ba1..90a414c 100644
--- a/apps/window.c
+++ b/apps/window.c
@@ -8,6 +8,9 @@ int main(void)
{
struct gui_window win = { 0 };
assert(gui_new_window(&win) > 0);
+ while (1)
+ ;
+#if 0
gfx_fill(win.ctx, COLOR_GREEN);
// Professional testing
for (int i = 0; i < 12; i++) {
@@ -16,5 +19,6 @@ int main(void)
}
assert(gui_redraw_window(win.id) > 0);
log("%d\n", win.ctx->size.x);
+#endif
return 0;
}
diff --git a/apps/wm.c b/apps/wm.c
index becbf0a..ecc7cb2 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -5,8 +5,10 @@
#include <gfx.h>
#include <gui.h>
#include <input.h>
+#include <ioctl.h>
#include <keymap.h>
#include <list.h>
+#include <msg.h>
#include <random.h>
#include <vesa.h>
@@ -307,46 +309,34 @@ static void handle_event_mouse(struct event_mouse *event)
window_redraw(cursor);
}
-static void handle_message_new_window(struct message *msg)
+static void handle_message_new_window(struct message_new_window *msg)
{
- if (!msg->data) {
- msg_send(msg->src, GUI_NEW_WINDOW | MSG_FAILURE, NULL);
- return;
- }
- struct gui_window *buf = msg->data;
- struct window *win = window_new((struct client){ .pid = msg->src }, "idk", vec2(500, 600),
- vec2(600, 400), 0);
- buf->id = win->id;
- buf->ctx = &win->ctx;
- buf->pos = &win->pos;
- msg_send(msg->src, GUI_NEW_WINDOW | MSG_SUCCESS, NULL);
+ struct window *win = window_new((struct client){ .pid = msg->header.src }, "idk",
+ vec2(500, 600), vec2(600, 400), 0);
+ msg->ctx = win->ctx;
+ msg->id = win->id;
+ msg_send(msg->header.src, GUI_NEW_WINDOW | MSG_SUCCESS, msg, sizeof(*msg));
/* window_redraw(win); */
}
-static void handle_message_redraw_window(struct message *msg)
+static void handle_message_redraw_window(struct message_redraw_window *msg)
{
- if (!msg->data) {
- msg_send(msg->src, GUI_REDRAW_WINDOW | MSG_FAILURE, NULL);
- return;
- }
- u32 id = *(u32 *)msg->data;
+ u32 id = msg->id;
struct window *win = window_find(id);
if (!win) {
- msg_send(msg->src, GUI_REDRAW_WINDOW | MSG_FAILURE, NULL);
+ msg_send(msg->header.src, GUI_REDRAW_WINDOW | MSG_FAILURE, NULL,
+ sizeof(msg->header));
return;
}
- msg_send(msg->src, GUI_REDRAW_WINDOW | MSG_SUCCESS, NULL);
+ msg_send(msg->header.src, GUI_REDRAW_WINDOW | MSG_SUCCESS, NULL, sizeof(msg->header));
window_redraw(win);
}
-static void handle_message(struct message *msg)
+static void handle_message(void *msg)
{
- if (msg->magic != MSG_MAGIC) {
- log("Message magic doesn't match!\n");
- return;
- }
+ struct message_header *header = msg;
- switch (msg->type) {
+ switch (header->type) {
case GUI_NEW_WINDOW:
handle_message_new_window(msg);
break;
@@ -354,18 +344,19 @@ static void handle_message(struct message *msg)
handle_message_redraw_window(msg);
break;
default:
- log("Message type %d not implemented!\n", msg->type);
- msg_send(msg->src, MSG_FAILURE, NULL);
+ log("Message type %d not implemented!\n", header->type);
+ msg_send(header->src, MSG_FAILURE, NULL, sizeof(*header));
}
}
int main(int argc, char **argv)
{
- (void)argc;
- screen = *(struct vbe *)argv[1];
+ UNUSED(argc);
+ UNUSED(argv);
+ assert(ioctl("/dev/fb", IO_FB_GET, &screen) == 0);
+ log("WM loaded: %dx%d\n", screen.width, screen.height);
wm_client = (struct client){ .pid = getpid() };
bypp = (screen.bpp >> 3);
- log("WM loaded: %dx%d\n", screen.width, screen.height);
windows = list_new();
keymap = keymap_parse("/res/keymaps/en.keymap");
@@ -387,32 +378,34 @@ int main(int argc, char **argv)
gfx_load_wallpaper(&cursor->ctx, "/res/cursor.png");
window_redraw(wallpaper);
- struct message msg = { 0 };
+ u8 msg[1024] = { 0 };
struct event_keyboard event_keyboard = { 0 };
struct event_mouse event_mouse = { 0 };
- const char *listeners[] = { "/dev/kbd", "/dev/mouse", "/proc/self/msg" };
+ const char *listeners[] = { "/dev/kbd", "/dev/mouse", "/proc/self/msg", NULL };
while (1) {
int poll_ret = 0;
if ((poll_ret = poll(listeners)) >= 0) {
if (poll_ret == 0) {
if (read(listeners[poll_ret], &event_keyboard, 0,
- sizeof(event_keyboard)) > 0)
+ sizeof(event_keyboard)) > 0) {
handle_event_keyboard(&event_keyboard);
- continue;
+ continue;
+ }
} else if (poll_ret == 1) {
if (read(listeners[poll_ret], &event_mouse, 0,
- sizeof(event_mouse)) > 0)
+ sizeof(event_mouse)) > 0) {
handle_event_mouse(&event_mouse);
- continue;
+ continue;
+ }
} else if (poll_ret == 2) {
- if (read(listeners[poll_ret], &msg, 0, sizeof(msg)) > 0)
- handle_message(&msg);
- continue;
+ if (msg_receive(msg, 1024) > 0) {
+ handle_message(msg);
+ continue;
+ }
}
- } else {
- err(1, "POLL ERROR!\n");
}
- };
+ panic("Poll/read error!\n");
+ }
// TODO: Execute?
free(keymap);