aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/user/syscall.c6
-rw-r--r--src/lib/include/gip.h2
-rw-r--r--src/lib/libkogata/gip.c19
-rw-r--r--src/lib/libkogata/mainloop.c4
-rw-r--r--src/sysbin/giosrv/main.c8
-rw-r--r--src/sysbin/login/main.c48
6 files changed, 64 insertions, 23 deletions
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index 15b0851..3a67350 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -60,7 +60,11 @@ static uint32_t dbg_print_sc(sc_args_t args) {
char* msg = sc_copy_string_x(args.a, args.b);
if (msg == 0) return -1;
- dbg_print(msg);
+ if (strchr(msg, '\n')) {
+ dbg_printf("[%d] %s", current_process()->pid, msg);
+ } else {
+ dbg_print(msg);
+ }
free(msg);
return 0;
diff --git a/src/lib/include/gip.h b/src/lib/include/gip.h
index 98b4655..c2167c4 100644
--- a/src/lib/include/gip.h
+++ b/src/lib/include/gip.h
@@ -10,7 +10,7 @@
typedef struct gip_handler gip_handler_t;
typedef void (*noarg_gip_callback_t)(gip_handler_t *s, gip_msg_header *m);
-typedef void (*gip_reply_callback_t)(gip_handler_t *s, gip_msg_header *m, void* data);
+typedef void (*gip_reply_callback_t)(gip_handler_t *s, gip_msg_header *m, void* msg_data, void* cb_data);
typedef struct {
noarg_gip_callback_t
diff --git a/src/lib/libkogata/gip.c b/src/lib/libkogata/gip.c
index 3b6084c..7fa1cca 100644
--- a/src/lib/libkogata/gip.c
+++ b/src/lib/libkogata/gip.c
@@ -123,30 +123,34 @@ bool gip_notify(gip_handler_t *h, gip_msg_header *msg, void* msg_data) {
// ---- Message handlers
-void giph_got_reply(gip_handler_t *h, gip_msg_header *msg) {
+void giph_got_reply(gip_handler_t *h, gip_msg_header *msg, void* msg_data) {
gip_cmd_t *c = (gip_cmd_t*)hashtbl_find(h->requests_in_progress, (void*)msg->req_id);;
if (c != 0) {
- c->cb(h, msg, c->data);
+ ASSERT(c->cb != 0);
+ c->cb(h, msg, msg_data, c->data);
hashtbl_remove(h->requests_in_progress, (void*)msg->req_id);
}
}
void giph_msg_header(mainloop_fd_t *fd) {
gip_handler_t *h = (gip_handler_t*)fd->data;
+ ASSERT(fd == &h->mainloop_item);
int code = h->msg_buf.code;
+ dbg_printf("Got GIP header, code %d\n", code);
+
noarg_gip_callback_t use_cb = 0;
if (code == GIPC_RESET) {
use_cb = h->cb->reset;
} else if (code == GIPR_INITIATE) {
use_cb = h->cb->initiate;
- giph_got_reply(h, &h->msg_buf);
+ giph_got_reply(h, &h->msg_buf, 0);
} else if (code == GIPR_OK) {
use_cb = h->cb->ok;
- giph_got_reply(h, &h->msg_buf);
+ giph_got_reply(h, &h->msg_buf, 0);
} else if (code == GIPR_FAILURE) {
use_cb = h->cb->failure;
- giph_got_reply(h, &h->msg_buf);
+ giph_got_reply(h, &h->msg_buf, 0);
} else if (code == GIPC_ENABLE_FEATURES) {
use_cb = h->cb->enable_features;
} else if (code == GIPC_DISABLE_FEATURES) {
@@ -161,8 +165,6 @@ void giph_msg_header(mainloop_fd_t *fd) {
mainloop_expect(fd, &h->buffer_info_msg_buf, sizeof(gip_buffer_info_msg), giph_buffer_info);
} else if (code == GIPR_MODE_INFO) {
mainloop_expect(fd, &h->mode_info_msg_buf, sizeof(gip_mode_info_msg), giph_mode_info);
- // this is a reply but we cannot call giph_got_reply immediately since more data is needed
- // giph_got_reply(h, id);
} else if (code == GIPN_BUFFER_DAMAGE) {
mainloop_expect(fd, &h->buffer_damage_msg_buf, sizeof(gip_buffer_damage_msg), giph_buffer_damage);
} else {
@@ -184,8 +186,7 @@ void giph_mode_info(mainloop_fd_t *fd) {
gip_handler_t *h = (gip_handler_t*)fd->data;
if (h->cb->mode_info) h->cb->mode_info(h, &h->msg_buf, &h->mode_info_msg_buf);
-
- // call giph_got_reply with more data ?
+ giph_got_reply(h, &h->msg_buf, &h->mode_info_msg_buf);
mainloop_expect(&h->mainloop_item, &h->msg_buf, sizeof(gip_msg_header), giph_msg_header);
}
diff --git a/src/lib/libkogata/mainloop.c b/src/lib/libkogata/mainloop.c
index d3c0c50..d8890e7 100644
--- a/src/lib/libkogata/mainloop.c
+++ b/src/lib/libkogata/mainloop.c
@@ -99,12 +99,14 @@ void mainloop_run() {
int i = 0;
for (mainloop_fd_t *fd = mainloop_fds; fd != 0 && !mainloop_fds_change; fd = fd->next) {
if (sel_arg[i].got_flags & SEL_ERROR) {
+ ASSERT(fd->on_error != 0);
fd->on_error(fd);
} else if ((sel_arg[i].got_flags & SEL_READ) && fd->rd_buf != 0) {
fd->rd_buf_filled +=
read(fd->fd, 0, fd->rd_buf_expect_size - fd->rd_buf_filled, fd->rd_buf + fd->rd_buf_filled);
if (fd->rd_buf_filled == fd->rd_buf_expect_size) {
fd->rd_buf_filled = 0;
+ ASSERT(fd->rd_on_full != 0);
fd->rd_on_full(fd);
}
} else if ((sel_arg[i].got_flags & SEL_WRITE) && fd->wr_bufs[0].buf != 0) {
@@ -118,7 +120,7 @@ void mainloop_run() {
for (int i = 1; i < MAINLOOP_MAX_WR_BUFS; i++) {
fd->wr_bufs[i-1] = fd->wr_bufs[i];
}
- memset(&fd->wr_bufs[MAINLOOP_MAX_WR_BUFS-1].buf, 0, sizeof(mainloop_wr_buf_t));
+ fd->wr_bufs[MAINLOOP_MAX_WR_BUFS-1].buf = 0;
}
}
i++;
diff --git a/src/sysbin/giosrv/main.c b/src/sysbin/giosrv/main.c
index 9dfd697..19d01f7 100644
--- a/src/sysbin/giosrv/main.c
+++ b/src/sysbin/giosrv/main.c
@@ -11,7 +11,6 @@
typedef struct {
framebuffer_info_t mode;
fd_t fd;
- uint32_t features;
} giosrv_t;
void reset(gip_handler_t *s, gip_msg_header *p);
@@ -72,9 +71,10 @@ void send_buffer_info(gip_handler_t *h, giosrv_t *s) {
msg_data.geom = s->mode;
if (!gen_token(s->fd, &msg_data.tok)) {
- dbg_printf("Could not generate token for buffer_info_msg.\n");
+ dbg_printf("[giosrv] Could not generate token for buffer_info_msg.\n");
} else {
- dbg_printf("Token: %x %x\n", ((uint32_t*)&msg_data.tok)[0], ((uint32_t*)&msg_data.tok)[1]);
+ dbg_printf("[giosrv] Generated token: %x %x\n",
+ ((uint32_t*)&msg_data.tok)[0], ((uint32_t*)&msg_data.tok)[1]);
gip_notify(h, &msg, &msg_data);
}
}
@@ -82,8 +82,6 @@ void send_buffer_info(gip_handler_t *h, giosrv_t *s) {
void reset(gip_handler_t *h, gip_msg_header *p) {
giosrv_t *s = (giosrv_t*)h->data;
- s->features = 0;
-
// ---- Send initiate message
gip_msg_header msg = {
.code = GIPR_INITIATE,
diff --git a/src/sysbin/login/main.c b/src/sysbin/login/main.c
index b836eec..1d5da8a 100644
--- a/src/sysbin/login/main.c
+++ b/src/sysbin/login/main.c
@@ -1,22 +1,26 @@
#include <string.h>
#include <malloc.h>
-
+#include <user_region.h>
#include <debug.h>
#include <gip.h>
typedef struct {
framebuffer_info_t mode;
+
+ size_t fb_size;
void* map;
+
fd_t fd;
- uint32_t features;
+
+ uint32_t sv_features, cl_features;
} loginc_t;
void c_buffer_info(gip_handler_t *s, gip_msg_header *p, gip_buffer_info_msg *m);
void c_unknown_msg(gip_handler_t *s, gip_msg_header *p);
void c_fd_error(gip_handler_t *s);
-void c_async_initiate(gip_handler_t *s, gip_msg_header *p, void* data);
+void c_async_initiate(gip_handler_t *s, gip_msg_header *p, void* msgdata, void* hdata);
gip_handler_callbacks_t loginc_cb = {
.reset = 0,
@@ -56,7 +60,36 @@ int main(int argc, char **argv) {
void c_buffer_info(gip_handler_t *s, gip_msg_header *p, gip_buffer_info_msg *m) {
dbg_printf("[login] Got buffer info msg\n");
- // TODO
+
+ loginc_t *c = (loginc_t*)s->data;
+
+ if (c->fd != 0) close(c->fd);
+ if (c->map != 0) {
+ munmap(c->map);
+ region_free(c->map);
+ }
+
+ c->fd = use_token(&m->tok);
+ if (c->fd != 0) {
+ memcpy(&c->mode, &m->geom, sizeof(framebuffer_info_t));
+
+ dbg_printf("[login] Got buffer on FD %d, %dx%dx%d\n",
+ c->fd, c->mode.width, c->mode.height, c->mode.bpp);
+
+ c->fb_size = c->mode.pitch * c->mode.height;
+
+ c->map = region_alloc(c->fb_size, "Framebuffer");
+ if (c->map != 0) {
+ bool ok = mmap_file(c->fd, 0, c->map, c->fb_size, MM_READ | MM_WRITE);
+ if (ok) {
+ memset(c->map, 0, c->fb_size);
+ } else {
+ dbg_printf("[login] Could not mmap buffer.\n");
+ region_free(c->map);
+ c->map = 0;
+ }
+ }
+ }
}
void c_unknown_msg(gip_handler_t *s, gip_msg_header *p) {
@@ -67,8 +100,11 @@ void c_fd_error(gip_handler_t *s) {
// TODO
}
-void c_async_initiate(gip_handler_t *s, gip_msg_header *p, void* data) {
- dbg_printf("[login] Got initiate reply to reset request.\n");
+void c_async_initiate(gip_handler_t *s, gip_msg_header *p, void* msgdata, void* hdata) {
+ loginc_t *c = (loginc_t*)s->data;
+ c->sv_features = p->arg;
+
+ dbg_printf("[login] Got initiate reply to reset request (features 0x%p).\n", c->sv_features);
}
/* vim: set ts=4 sw=4 tw=0 noet :*/