From 32407e728971006ed3d0885e01c22fb66c8adc57 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 15 Jul 2016 23:12:14 +0200 Subject: Move stuff around, again --- src/lib/include/draw.h | 64 --------------------------------------- src/lib/include/gip.h | 56 ---------------------------------- src/lib/include/keyboard.h | 39 ------------------------ src/lib/include/kogata/draw.h | 64 +++++++++++++++++++++++++++++++++++++++ src/lib/include/kogata/gip.h | 56 ++++++++++++++++++++++++++++++++++ src/lib/include/kogata/keyboard.h | 39 ++++++++++++++++++++++++ src/lib/include/kogata/mainloop.h | 47 ++++++++++++++++++++++++++++ src/lib/include/kogata/syscall.h | 63 ++++++++++++++++++++++++++++++++++++++ src/lib/include/mainloop.h | 47 ---------------------------- src/lib/include/proto/gip.h | 2 +- src/lib/include/stdio.h | 2 +- src/lib/include/stdlib.h | 2 +- src/lib/include/syscall.h | 63 -------------------------------------- 13 files changed, 272 insertions(+), 272 deletions(-) delete mode 100644 src/lib/include/draw.h delete mode 100644 src/lib/include/gip.h delete mode 100644 src/lib/include/keyboard.h create mode 100644 src/lib/include/kogata/draw.h create mode 100644 src/lib/include/kogata/gip.h create mode 100644 src/lib/include/kogata/keyboard.h create mode 100644 src/lib/include/kogata/mainloop.h create mode 100644 src/lib/include/kogata/syscall.h delete mode 100644 src/lib/include/mainloop.h delete mode 100644 src/lib/include/syscall.h (limited to 'src/lib/include') diff --git a/src/lib/include/draw.h b/src/lib/include/draw.h deleted file mode 100644 index 5296b92..0000000 --- a/src/lib/include/draw.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include - -// ---- Generic drawing functions - -// ---- Data structures - -typedef struct { - fb_info_t geom; - - fd_t fd; - uint8_t* data; -} fb_t; - -typedef struct font font_t; - -typedef uint32_t color_t; // a color is always linked to a FB on which it is to be applied - -// ---- Buffer creation - -fb_t *g_fb_from_file(fd_t file, fb_info_t *geom); -fb_t *g_fb_from_mem(uint8_t* region, fb_info_t *geom); - -void g_delete_fb(fb_t *fb); - -// ---- Color manipulation - -color_t g_color_rgb(fb_t *f, uint8_t r, uint8_t g, uint8_t b); - -// ---- Drawing primitives - -void g_plot(fb_t *fb, int x, int y, color_t c); - -void g_hline(fb_t *fb, int x, int y, int w, color_t c); // horizontal line -void g_vline(fb_t *fb, int x, int y, int h, color_t c); // vertical line -void g_line(fb_t *fb, int x1, int y1, int x2, int y2, color_t c); - -void g_rect(fb_t *fb, int x, int y, int w, int h, color_t c); -void g_fillrect(fb_t *fb, int x, int y, int w, int h, color_t c); -void g_rect_r(fb_t *fb, fb_region_t reg, color_t c); -void g_fillrect_r(fb_t *fb, fb_region_t reg, color_t c); - -void g_circle(fb_t *fb, int cx, int cy, int r, color_t c); -void g_fillcircle(fb_t *fb, int cx, int cy, int r, color_t c); - -void g_blit(fb_t *dst, int x, int y, fb_t *src); -void g_blit_region(fb_t *dst, int x, int y, fb_t *src, fb_region_t reg); - -void g_scroll_up(fb_t *fb, int l); - -// ---- Text manipulation - -font_t *g_load_font(const char* fontname); -void g_free_font(font_t *f); - -int g_text_width(font_t *f, const char* text); -int g_text_height(font_t *f, const char* text); - -void g_write(fb_t *fb, int x, int y, const char* text, font_t *font, color_t c); - - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/gip.h b/src/lib/include/gip.h deleted file mode 100644 index 9c66091..0000000 --- a/src/lib/include/gip.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -// Not thread safe - -#include - -#include -#include - -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* msg_data, void* cb_data); - -typedef struct { - noarg_gip_callback_t - reset, initiate, ok, failure, - enable_features, disable_features, - query_mode, set_mode, switch_buffer, - key_down, key_up; - void (*buffer_info)(gip_handler_t *s, gip_msg_header *m, gip_buffer_info_msg *i); - void (*mode_info)(gip_handler_t *s, gip_msg_header *m, gip_mode_info_msg *i); - void (*buffer_damage)(gip_handler_t *s, gip_msg_header *m, gip_buffer_damage_msg *i); - void (*unknown_msg)(gip_handler_t *s, gip_msg_header *m); - void (*fd_error)(gip_handler_t *s); -} gip_handler_callbacks_t; - -typedef struct gip_handler { - gip_handler_callbacks_t* cb; - void* data; - - gip_msg_header msg_buf; - gip_buffer_info_msg buffer_info_msg_buf; - gip_mode_info_msg mode_info_msg_buf; - gip_buffer_damage_msg buffer_damage_msg_buf; - - hashtbl_t *requests_in_progress; - uint32_t next_req_id; - - mainloop_fd_t mainloop_item; -} gip_handler_t; - -gip_handler_t *new_gip_handler(gip_handler_callbacks_t *cb, void* data); -void delete_gip_handler(gip_handler_t *h); - -// GIP send messages - -bool gip_cmd(gip_handler_t *h, gip_msg_header *msg, void* msg_data, gip_reply_callback_t cb, void* cb_data); - -bool gip_reply(gip_handler_t *h, gip_msg_header *orig_request, gip_msg_header *msg, void* msg_data); -bool gip_reply_fail(gip_handler_t *h, gip_msg_header *o); -bool gip_reply_ok(gip_handler_t *h, gip_msg_header *o); - -bool gip_notify(gip_handler_t *h, gip_msg_header *msg, void* msg_data); - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/keyboard.h b/src/lib/include/keyboard.h deleted file mode 100644 index 63c6c2c..0000000 --- a/src/lib/include/keyboard.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include - -#define KBD_CHAR 0x01 -#define KBD_ALT 0x02 -#define KBD_CTRL 0x04 -#define KBD_SUPER 0x08 -#define KBD_SHIFT 0x10 -#define KBD_CAPS 0x20 -#define KBD_MOD 0x40 - -typedef struct { - union { - int chr; // if flags & KBD_CHAR, chr is a character number - int key; // if !(flags & KBD_CHAR), key is one of KBD_CODE_* defined in - }; - uint32_t flags; // one of kbd_* -} key_t; - -typedef struct { - keymap_t km; - int key_char[256]; - uint32_t status; // mask of alt/ctrl/super -} keyboard_t; - -keyboard_t *init_keyboard(); -void free_keyboard(keyboard_t *t); - -bool load_keymap(keyboard_t *kb, const char* kmname); - -key_t keyboard_press(keyboard_t *t, int scancode); // what key is pressed? -key_t keyboard_release(keyboard_t *t, int scancode); // what key is released? - - - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/kogata/draw.h b/src/lib/include/kogata/draw.h new file mode 100644 index 0000000..fb9fe05 --- /dev/null +++ b/src/lib/include/kogata/draw.h @@ -0,0 +1,64 @@ +#pragma once + +#include +#include + +// ---- Generic drawing functions + +// ---- Data structures + +typedef struct { + fb_info_t geom; + + fd_t fd; + uint8_t* data; +} fb_t; + +typedef struct font font_t; + +typedef uint32_t color_t; // a color is always linked to a FB on which it is to be applied + +// ---- Buffer creation + +fb_t *g_fb_from_file(fd_t file, fb_info_t *geom); +fb_t *g_fb_from_mem(uint8_t* region, fb_info_t *geom); + +void g_delete_fb(fb_t *fb); + +// ---- Color manipulation + +color_t g_color_rgb(fb_t *f, uint8_t r, uint8_t g, uint8_t b); + +// ---- Drawing primitives + +void g_plot(fb_t *fb, int x, int y, color_t c); + +void g_hline(fb_t *fb, int x, int y, int w, color_t c); // horizontal line +void g_vline(fb_t *fb, int x, int y, int h, color_t c); // vertical line +void g_line(fb_t *fb, int x1, int y1, int x2, int y2, color_t c); + +void g_rect(fb_t *fb, int x, int y, int w, int h, color_t c); +void g_fillrect(fb_t *fb, int x, int y, int w, int h, color_t c); +void g_rect_r(fb_t *fb, fb_region_t reg, color_t c); +void g_fillrect_r(fb_t *fb, fb_region_t reg, color_t c); + +void g_circle(fb_t *fb, int cx, int cy, int r, color_t c); +void g_fillcircle(fb_t *fb, int cx, int cy, int r, color_t c); + +void g_blit(fb_t *dst, int x, int y, fb_t *src); +void g_blit_region(fb_t *dst, int x, int y, fb_t *src, fb_region_t reg); + +void g_scroll_up(fb_t *fb, int l); + +// ---- Text manipulation + +font_t *g_load_font(const char* fontname); +void g_free_font(font_t *f); + +int g_text_width(font_t *f, const char* text); +int g_text_height(font_t *f, const char* text); + +void g_write(fb_t *fb, int x, int y, const char* text, font_t *font, color_t c); + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/kogata/gip.h b/src/lib/include/kogata/gip.h new file mode 100644 index 0000000..1d1725a --- /dev/null +++ b/src/lib/include/kogata/gip.h @@ -0,0 +1,56 @@ +#pragma once + +// Not thread safe + +#include +#include + +#include + +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* msg_data, void* cb_data); + +typedef struct { + noarg_gip_callback_t + reset, initiate, ok, failure, + enable_features, disable_features, + query_mode, set_mode, switch_buffer, + key_down, key_up; + void (*buffer_info)(gip_handler_t *s, gip_msg_header *m, gip_buffer_info_msg *i); + void (*mode_info)(gip_handler_t *s, gip_msg_header *m, gip_mode_info_msg *i); + void (*buffer_damage)(gip_handler_t *s, gip_msg_header *m, gip_buffer_damage_msg *i); + void (*unknown_msg)(gip_handler_t *s, gip_msg_header *m); + void (*fd_error)(gip_handler_t *s); +} gip_handler_callbacks_t; + +typedef struct gip_handler { + gip_handler_callbacks_t* cb; + void* data; + + gip_msg_header msg_buf; + gip_buffer_info_msg buffer_info_msg_buf; + gip_mode_info_msg mode_info_msg_buf; + gip_buffer_damage_msg buffer_damage_msg_buf; + + hashtbl_t *requests_in_progress; + uint32_t next_req_id; + + mainloop_fd_t mainloop_item; +} gip_handler_t; + +gip_handler_t *new_gip_handler(gip_handler_callbacks_t *cb, void* data); +void delete_gip_handler(gip_handler_t *h); + +// GIP send messages + +bool gip_cmd(gip_handler_t *h, gip_msg_header *msg, void* msg_data, gip_reply_callback_t cb, void* cb_data); + +bool gip_reply(gip_handler_t *h, gip_msg_header *orig_request, gip_msg_header *msg, void* msg_data); +bool gip_reply_fail(gip_handler_t *h, gip_msg_header *o); +bool gip_reply_ok(gip_handler_t *h, gip_msg_header *o); + +bool gip_notify(gip_handler_t *h, gip_msg_header *msg, void* msg_data); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/kogata/keyboard.h b/src/lib/include/kogata/keyboard.h new file mode 100644 index 0000000..63c6c2c --- /dev/null +++ b/src/lib/include/kogata/keyboard.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include + +#define KBD_CHAR 0x01 +#define KBD_ALT 0x02 +#define KBD_CTRL 0x04 +#define KBD_SUPER 0x08 +#define KBD_SHIFT 0x10 +#define KBD_CAPS 0x20 +#define KBD_MOD 0x40 + +typedef struct { + union { + int chr; // if flags & KBD_CHAR, chr is a character number + int key; // if !(flags & KBD_CHAR), key is one of KBD_CODE_* defined in + }; + uint32_t flags; // one of kbd_* +} key_t; + +typedef struct { + keymap_t km; + int key_char[256]; + uint32_t status; // mask of alt/ctrl/super +} keyboard_t; + +keyboard_t *init_keyboard(); +void free_keyboard(keyboard_t *t); + +bool load_keymap(keyboard_t *kb, const char* kmname); + +key_t keyboard_press(keyboard_t *t, int scancode); // what key is pressed? +key_t keyboard_release(keyboard_t *t, int scancode); // what key is released? + + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/kogata/mainloop.h b/src/lib/include/kogata/mainloop.h new file mode 100644 index 0000000..2b447ef --- /dev/null +++ b/src/lib/include/kogata/mainloop.h @@ -0,0 +1,47 @@ +#pragma once + +// These functions are not thread safe, their purpose +// is to multiplex several IO operations on a +// single thread. + +#include + +#define MAINLOOP_MAX_WR_BUFS 4 + +typedef struct mainloop_fd mainloop_fd_t; + +typedef void (*buf_full_callback_t)(mainloop_fd_t *fd); +typedef void (*fd_error_callback_t)(mainloop_fd_t *fd); + +typedef struct { + size_t size, written; + void* buf; + bool must_free; +} mainloop_wr_buf_t; + +typedef struct mainloop_fd { + fd_t fd; + + size_t rd_buf_expect_size, rd_buf_filled; + void* rd_buf; + + mainloop_wr_buf_t wr_bufs[MAINLOOP_MAX_WR_BUFS]; + + void* data; + + buf_full_callback_t rd_on_full; + fd_error_callback_t on_error; + + mainloop_fd_t *next; +} mainloop_fd_t; + +void mainloop_add_fd(mainloop_fd_t* fd); +void mainloop_rm_fd(mainloop_fd_t* fd); + +void mainloop_expect(mainloop_fd_t *fd, void* buf, size_t size, buf_full_callback_t cb); +bool mainloop_nonblocking_write(mainloop_fd_t *fd, void* buf, size_t size, bool must_free_buf); + +void mainloop_run(); +void mainloop_exit(); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/kogata/syscall.h b/src/lib/include/kogata/syscall.h new file mode 100644 index 0000000..378dda2 --- /dev/null +++ b/src/lib/include/kogata/syscall.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +#include + +typedef void (*entry_t)(void*); + +void dbg_print(const char* str); +void yield(); +void exit(int code); +void usleep(int usecs); +bool sys_new_thread(void* eip, void* esp); +void exit_thread(); + +bool mmap(void* addr, size_t size, int mode); +bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode); +bool mchmap(void* addr, int mode); +bool munmap(void* addr); + +bool create(const char* name, int type); +bool delete(const char* name); +bool move(const char* oldname, const char* newname); +bool stat(const char* name, stat_t *s); + +fd_t open(const char* name, int mode); +void close(fd_t file); +size_t read(fd_t file, size_t offset, size_t len, char *buf); +size_t write(fd_t file, size_t offset, size_t len, const char* buf); +bool readdir(fd_t file, size_t ent_no, dirent_t *d); +bool stat_open(fd_t file, stat_t *s); +int ioctl(fd_t file, int command, void* data); +int fctl(fd_t file, int command, void* data); +bool select(sel_fd_t* fds, size_t nfds, int timeout); + +fd_pair_t make_channel(bool blocking); +fd_t make_shm(size_t size); +bool gen_token(fd_t file, token_t *tok); +fd_t use_token(token_t *tok); + +bool make_fs(const char* name, const char* driver, fd_t source, const char* options); +bool fs_add_source(const char* fs, fd_t source, const char* options); +bool fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes); +void fs_remove(const char* name); + +pid_t new_proc(); +bool bind_fs(pid_t pid, const char* new_name, const char* fs); +bool bind_subfs(pid_t pid, const char* new_name, const char* fs, const char* root, int ok_modes); +bool bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options); +bool bind_fd(pid_t pid, fd_t new_fd, fd_t fd); +bool proc_exec(pid_t pid, const char* file); +bool proc_status(pid_t pid, proc_status_t *s); +bool proc_kill(pid_t pid, proc_status_t *s); +void proc_wait(pid_t pid, bool wait, proc_status_t *s); + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/mainloop.h b/src/lib/include/mainloop.h deleted file mode 100644 index 1e71ffb..0000000 --- a/src/lib/include/mainloop.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -// These functions are not thread safe, their purpose -// is to multiplex several IO operations on a -// single thread. - -#include - -#define MAINLOOP_MAX_WR_BUFS 4 - -typedef struct mainloop_fd mainloop_fd_t; - -typedef void (*buf_full_callback_t)(mainloop_fd_t *fd); -typedef void (*fd_error_callback_t)(mainloop_fd_t *fd); - -typedef struct { - size_t size, written; - void* buf; - bool must_free; -} mainloop_wr_buf_t; - -typedef struct mainloop_fd { - fd_t fd; - - size_t rd_buf_expect_size, rd_buf_filled; - void* rd_buf; - - mainloop_wr_buf_t wr_bufs[MAINLOOP_MAX_WR_BUFS]; - - void* data; - - buf_full_callback_t rd_on_full; - fd_error_callback_t on_error; - - mainloop_fd_t *next; -} mainloop_fd_t; - -void mainloop_add_fd(mainloop_fd_t* fd); -void mainloop_rm_fd(mainloop_fd_t* fd); - -void mainloop_expect(mainloop_fd_t *fd, void* buf, size_t size, buf_full_callback_t cb); -bool mainloop_nonblocking_write(mainloop_fd_t *fd, void* buf, size_t size, bool must_free_buf); - -void mainloop_run(); -void mainloop_exit(); - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/proto/gip.h b/src/lib/include/proto/gip.h index ca8b868..5cf0166 100644 --- a/src/lib/include/proto/gip.h +++ b/src/lib/include/proto/gip.h @@ -2,7 +2,7 @@ #include -#include +#include /* Definition of the GIP protocol (Graphics Initiation Protocol). diff --git a/src/lib/include/stdio.h b/src/lib/include/stdio.h index f46add4..1e75270 100644 --- a/src/lib/include/stdio.h +++ b/src/lib/include/stdio.h @@ -2,7 +2,7 @@ #include -#include +#include extern fd_t stdio; diff --git a/src/lib/include/stdlib.h b/src/lib/include/stdlib.h index 29d8661..30da9a6 100644 --- a/src/lib/include/stdlib.h +++ b/src/lib/include/stdlib.h @@ -1,6 +1,6 @@ #pragma once -#include "malloc.h" +#include #define EXIT_SUCCESS 0 #define EXIT_FAILURE 255 diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h deleted file mode 100644 index 07defdb..0000000 --- a/src/lib/include/syscall.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include -#include - -#include - -typedef void (*entry_t)(void*); - -void dbg_print(const char* str); -void yield(); -void exit(int code); -void usleep(int usecs); -bool sys_new_thread(void* eip, void* esp); -void exit_thread(); - -bool mmap(void* addr, size_t size, int mode); -bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode); -bool mchmap(void* addr, int mode); -bool munmap(void* addr); - -bool create(const char* name, int type); -bool delete(const char* name); -bool move(const char* oldname, const char* newname); -bool stat(const char* name, stat_t *s); - -fd_t open(const char* name, int mode); -void close(fd_t file); -size_t read(fd_t file, size_t offset, size_t len, char *buf); -size_t write(fd_t file, size_t offset, size_t len, const char* buf); -bool readdir(fd_t file, size_t ent_no, dirent_t *d); -bool stat_open(fd_t file, stat_t *s); -int ioctl(fd_t file, int command, void* data); -int fctl(fd_t file, int command, void* data); -bool select(sel_fd_t* fds, size_t nfds, int timeout); - -fd_pair_t make_channel(bool blocking); -fd_t make_shm(size_t size); -bool gen_token(fd_t file, token_t *tok); -fd_t use_token(token_t *tok); - -bool make_fs(const char* name, const char* driver, fd_t source, const char* options); -bool fs_add_source(const char* fs, fd_t source, const char* options); -bool fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes); -void fs_remove(const char* name); - -pid_t new_proc(); -bool bind_fs(pid_t pid, const char* new_name, const char* fs); -bool bind_subfs(pid_t pid, const char* new_name, const char* fs, const char* root, int ok_modes); -bool bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options); -bool bind_fd(pid_t pid, fd_t new_fd, fd_t fd); -bool proc_exec(pid_t pid, const char* file); -bool proc_status(pid_t pid, proc_status_t *s); -bool proc_kill(pid_t pid, proc_status_t *s); -void proc_wait(pid_t pid, bool wait, proc_status_t *s); - -/* vim: set ts=4 sw=4 tw=0 noet :*/ -- cgit v1.2.3