From 48c1c4dcc449d05e9950a861e165f456e0d583a1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 10 Mar 2015 16:12:03 +0100 Subject: Rename & cleanup. --- src/common/include/framebuffer.h | 19 -------- src/common/include/fs.h | 62 -------------------------- src/common/include/mmap.h | 7 --- src/common/include/proc.h | 25 ----------- src/common/include/proto/fb.h | 33 ++++++++++++++ src/common/include/proto/fs.h | 62 ++++++++++++++++++++++++++ src/common/include/proto/mmap.h | 7 +++ src/common/include/proto/proc.h | 25 +++++++++++ src/common/include/proto/syscall.h | 89 ++++++++++++++++++++++++++++++++++++++ src/common/include/proto/token.h | 11 +++++ src/common/include/syscallproto.h | 89 -------------------------------------- src/common/include/token.h | 11 ----- src/kernel/dev/vesa.c | 37 +++++++++++++--- src/kernel/include/ipc.h | 3 +- src/kernel/include/process.h | 4 +- src/kernel/include/sct.h | 2 +- src/kernel/include/vfs.h | 2 +- src/lib/include/syscall.h | 8 ++-- 18 files changed, 269 insertions(+), 227 deletions(-) delete mode 100644 src/common/include/framebuffer.h delete mode 100644 src/common/include/fs.h delete mode 100644 src/common/include/mmap.h delete mode 100644 src/common/include/proc.h create mode 100644 src/common/include/proto/fb.h create mode 100644 src/common/include/proto/fs.h create mode 100644 src/common/include/proto/mmap.h create mode 100644 src/common/include/proto/proc.h create mode 100644 src/common/include/proto/syscall.h create mode 100644 src/common/include/proto/token.h delete mode 100644 src/common/include/syscallproto.h delete mode 100644 src/common/include/token.h (limited to 'src') diff --git a/src/common/include/framebuffer.h b/src/common/include/framebuffer.h deleted file mode 100644 index febbfaa..0000000 --- a/src/common/include/framebuffer.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -typedef struct { - uint32_t width, height; - uint32_t pitch; // bytes per line - uint32_t bpp; -} framebuffer_info_t; - -typedef struct { - int mode_number; - framebuffer_info_t geom; -} fbdev_mode_info_t; - -#define IOCTL_FBDEV_GET_MODE_INFO 10 -#define IOCTL_FBDEV_SET_MODE 11 - -#define IOCTL_FB_GET_INFO 12 - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/fs.h b/src/common/include/fs.h deleted file mode 100644 index e70ff55..0000000 --- a/src/common/include/fs.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include -#include - -typedef int fd_t; - -#define FT_REGULAR 0 // no flags = regular file -#define FT_DIR (0x01) -#define FT_DEV (0x02) -#define FT_BLOCKDEV (0x04) -#define FT_CHARDEV (0x08) -#define FT_CHANNEL (0x10) // dual-pipe -#define FT_FRAMEBUFFER (0x20) - -// FM_* enum describes modes for opening a file as well as authorized operations in stat_t -// (some flags are used only for open() or only in stat_t.access) -#define FM_READ (0x01) -#define FM_WRITE (0x02) -#define FM_READDIR (0x04) -#define FM_MMAP (0x08) -#define FM_CREATE (0x10) -#define FM_TRUNC (0x20) -#define FM_APPEND (0x40) -#define FM_IOCTL (0x100) -#define FM_BLOCKING (0x200) -#define FM_DCREATE (0x1000) // create file in directory -#define FM_DMOVE (0x2000) // move file from directory -#define FM_DDELETE (0x4000) // delete file from directory - -#define FM_ALL_MODES (0xFFFF) - - -typedef struct { - int type; - int access; - size_t size; - // TODO : times & more metadata -} stat_t; - -#define DIR_MAX 128 // maximum length for a filename - -typedef struct { - char name[DIR_MAX]; - stat_t st; -} dirent_t; - - -#define IOCTL_BLOCKDEV_GET_BLOCK_SIZE 40 -#define IOCTL_BLOCKDEV_GET_BLOCK_COUNT 41 - - -#define SEL_READ 0x01 -#define SEL_WRITE 0x02 -#define SEL_ERROR 0x04 - -typedef struct { - fd_t fd; - uint16_t req_flags, got_flags; // rq_flags : what caller is interested in -} sel_fd_t; - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/mmap.h b/src/common/include/mmap.h deleted file mode 100644 index 3134403..0000000 --- a/src/common/include/mmap.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#define MM_READ (0x01) -#define MM_WRITE (0x02) -#define MM_EXEC (0x04) - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proc.h b/src/common/include/proc.h deleted file mode 100644 index 29b5b91..0000000 --- a/src/common/include/proc.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -typedef int pid_t; - -#define PS_LOADING 1 -#define PS_RUNNING 2 -#define PS_FINISHED 3 -#define PS_FAILURE 4 // exception or segfault or stuff -#define PS_KILLED 5 - -#define FAIL_EXCEPTION 1 // unhandled processor exception -#define FAIL_ZEROPTR 2 // segfault at < 4k -#define FAIL_SEGFAULT 3 -#define FAIL_SC_SEGFAULT 4 // failed to validate parameter for system call - -typedef struct { - int pid; - int status; // one of PS_* - int exit_code; // an error code if state == PS_FAILURE -} proc_status_t; - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/fb.h b/src/common/include/proto/fb.h new file mode 100644 index 0000000..0519554 --- /dev/null +++ b/src/common/include/proto/fb.h @@ -0,0 +1,33 @@ +#pragma once + +// Framebuffer-related data structures + +#include +#include + +#define FB_MM_RGB16 1 // 2 bytes (16 bits) per pixel, blue 0-4, green 5-9, red 10-14 +#define FB_MM_BGR16 2 // 2 bytes (16 bits) per pixel, red 0-4, green 5-9, blue 10-14 +#define FB_MM_RGB24 3 // 3 bytes (24 bits) per pixel, blue 0-7, green 8-15, red 16-23 +#define FB_MM_BGR24 4 // 3 bytes (24 bits) per pixel, red 0-7, green 8-15, blue 16-23 +#define FB_MM_RGB32 5 // 4 bytes (32 bits) per pixel, blue 0-7, green 8-15, red 16-23 +#define FB_MM_BGR32 6 // 4 bytes (32 bits) per pixel, red 0-7, green 8-15, blue 16-23 +#define FB_MM_GREY8 10 // 1 byte (8 bits) per pixel greyscale + +typedef struct { + uint32_t width, height; + uint32_t pitch; // bytes per line + uint32_t bpp; + uint32_t memory_model; +} framebuffer_info_t; + +typedef struct { + int mode_number; + framebuffer_info_t geom; +} fbdev_mode_info_t; + +#define IOCTL_FBDEV_GET_MODE_INFO 10 +#define IOCTL_FBDEV_SET_MODE 11 + +#define IOCTL_FB_GET_INFO 12 + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/fs.h b/src/common/include/proto/fs.h new file mode 100644 index 0000000..e70ff55 --- /dev/null +++ b/src/common/include/proto/fs.h @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +typedef int fd_t; + +#define FT_REGULAR 0 // no flags = regular file +#define FT_DIR (0x01) +#define FT_DEV (0x02) +#define FT_BLOCKDEV (0x04) +#define FT_CHARDEV (0x08) +#define FT_CHANNEL (0x10) // dual-pipe +#define FT_FRAMEBUFFER (0x20) + +// FM_* enum describes modes for opening a file as well as authorized operations in stat_t +// (some flags are used only for open() or only in stat_t.access) +#define FM_READ (0x01) +#define FM_WRITE (0x02) +#define FM_READDIR (0x04) +#define FM_MMAP (0x08) +#define FM_CREATE (0x10) +#define FM_TRUNC (0x20) +#define FM_APPEND (0x40) +#define FM_IOCTL (0x100) +#define FM_BLOCKING (0x200) +#define FM_DCREATE (0x1000) // create file in directory +#define FM_DMOVE (0x2000) // move file from directory +#define FM_DDELETE (0x4000) // delete file from directory + +#define FM_ALL_MODES (0xFFFF) + + +typedef struct { + int type; + int access; + size_t size; + // TODO : times & more metadata +} stat_t; + +#define DIR_MAX 128 // maximum length for a filename + +typedef struct { + char name[DIR_MAX]; + stat_t st; +} dirent_t; + + +#define IOCTL_BLOCKDEV_GET_BLOCK_SIZE 40 +#define IOCTL_BLOCKDEV_GET_BLOCK_COUNT 41 + + +#define SEL_READ 0x01 +#define SEL_WRITE 0x02 +#define SEL_ERROR 0x04 + +typedef struct { + fd_t fd; + uint16_t req_flags, got_flags; // rq_flags : what caller is interested in +} sel_fd_t; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/mmap.h b/src/common/include/proto/mmap.h new file mode 100644 index 0000000..3134403 --- /dev/null +++ b/src/common/include/proto/mmap.h @@ -0,0 +1,7 @@ +#pragma once + +#define MM_READ (0x01) +#define MM_WRITE (0x02) +#define MM_EXEC (0x04) + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/proc.h b/src/common/include/proto/proc.h new file mode 100644 index 0000000..29b5b91 --- /dev/null +++ b/src/common/include/proto/proc.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +typedef int pid_t; + +#define PS_LOADING 1 +#define PS_RUNNING 2 +#define PS_FINISHED 3 +#define PS_FAILURE 4 // exception or segfault or stuff +#define PS_KILLED 5 + +#define FAIL_EXCEPTION 1 // unhandled processor exception +#define FAIL_ZEROPTR 2 // segfault at < 4k +#define FAIL_SEGFAULT 3 +#define FAIL_SC_SEGFAULT 4 // failed to validate parameter for system call + +typedef struct { + int pid; + int status; // one of PS_* + int exit_code; // an error code if state == PS_FAILURE +} proc_status_t; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/syscall.h b/src/common/include/proto/syscall.h new file mode 100644 index 0000000..a671c65 --- /dev/null +++ b/src/common/include/proto/syscall.h @@ -0,0 +1,89 @@ +#pragma once + +#include +#include + +typedef struct { fd_t a, b; } fd_pair_t; + +#define SC_MAX 128 // maximum number of syscalls + +#define SC_DBG_PRINT 0 // args: msg, msg_strlen +#define SC_EXIT 1 // args: code +#define SC_YIELD 2 // args: () +#define SC_USLEEP 3 // args: usecs +#define SC_NEW_THREAD 4 // args: eip, esp +#define SC_EXIT_THREAD 5 // args: () + +#define SC_MMAP 10 // args: addr, size, mode +#define SC_MMAP_FILE 11 // args: handle, offset, addr, size, mode +#define SC_MCHMAP 12 // args: addr, new_mode +#define SC_MUNMAP 13 // args: addr + +#define SC_CREATE 20 // args: file, file_strlen, type +#define SC_DELETE 21 // args: file, file_strlen +#define SC_MOVE 22 // args: old_file, old_file_strlen, new_file, new_file_strlen +#define SC_STAT 23 // args: file, file_strlen, out stat_t* data + +#define SC_OPEN 30 // args: file, file_strlen, mode +#define SC_CLOSE 31 // args: fd +#define SC_READ 32 // args: fd, offset, size, out char* data +#define SC_WRITE 33 // args: fd, offset, size, data +#define SC_READDIR 34 // args: fd, ent_no, out dirent_t *data +#define SC_STAT_OPEN 35 // args: fd, out stat_t *data -- stat on open file handle +#define SC_IOCTL 36 // args: fd, command, out void* data +#define SC_GET_MODE 37 // args: fd -- get mode for open file handle +#define SC_SELECT 38 // args: sel_fd_t*, count, timeout + +#define SC_MK_CHANNEL 40 // args: blocking?, (int, int)* +#define SC_GEN_TOKEN 41 // args: fd, token_t* +#define SC_USE_TOKEN 42 // args: token_t* + +#define SC_MAKE_FS 50 // args: sc_make_fs_args_t +#define SC_FS_ADD_SRC 51 // args: fs_name, fs_name_strlen, fd, opts, opts_strlen +#define SC_SUBFS 52 // args: sc_subfs_args_t +#define SC_RM_FS 53 // args: fs_name, fs_name_strlen +// TODO : how do we enumerate filesystems ? + +#define SC_NEW_PROC 60 // args: nothing ? +#define SC_BIND_FS 61 // args: pid, new_name, new_name_strlen, fs_name, fs_name_strlen -- bind FS to child process +#define SC_BIND_SUBFS 62 // args: sc_subfs_args_t -- subfs & bind to child process +#define SC_BIND_MAKE_FS 63 // args: sc_make_fs_args_t +#define SC_BIND_FD 64 // args: pid, new_fd, local_fd -- copy a file descriptor to child process +#define SC_PROC_EXEC 65 // args: pid, exec_name, exec_name_strlen -- execute binary in process +#define SC_PROC_STATUS 66 // args: pid, proc_status_t* +#define SC_PROC_KILL 67 // args: pid, proc_status_t* -- inconditionnally kill child process +#define SC_PROC_WAIT 68 // args: pid?, block?, proc_status_t* + +#define INVALID_PID 0 // do a wait with this PID to wayt for any child + +typedef struct { + const char* driver; + size_t driver_strlen; + + const char* fs_name; + size_t fs_name_strlen; + + fd_t source_fd; + + const char* opts; + size_t opts_strlen; + + pid_t bind_to_pid; // zero = bind to current proc +} sc_make_fs_args_t; + +typedef struct { + const char* new_name; + size_t new_name_strlen; + + const char* from_fs; + size_t from_fs_strlen; + + const char* root; + size_t root_strlen; + + int ok_modes; + + pid_t bind_to_pid; // 0 = bind to current proc +} sc_subfs_args_t; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/proto/token.h b/src/common/include/proto/token.h new file mode 100644 index 0000000..9ec1aff --- /dev/null +++ b/src/common/include/proto/token.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +#define TOKEN_LENGTH 16 +typedef struct { + char bytes[TOKEN_LENGTH]; +} token_t; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/syscallproto.h b/src/common/include/syscallproto.h deleted file mode 100644 index 9f300d3..0000000 --- a/src/common/include/syscallproto.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include -#include - -typedef struct { fd_t a, b; } fd_pair_t; - -#define SC_MAX 128 // maximum number of syscalls - -#define SC_DBG_PRINT 0 // args: msg, msg_strlen -#define SC_EXIT 1 // args: code -#define SC_YIELD 2 // args: () -#define SC_USLEEP 3 // args: usecs -#define SC_NEW_THREAD 4 // args: eip, esp -#define SC_EXIT_THREAD 5 // args: () - -#define SC_MMAP 10 // args: addr, size, mode -#define SC_MMAP_FILE 11 // args: handle, offset, addr, size, mode -#define SC_MCHMAP 12 // args: addr, new_mode -#define SC_MUNMAP 13 // args: addr - -#define SC_CREATE 20 // args: file, file_strlen, type -#define SC_DELETE 21 // args: file, file_strlen -#define SC_MOVE 22 // args: old_file, old_file_strlen, new_file, new_file_strlen -#define SC_STAT 23 // args: file, file_strlen, out stat_t* data - -#define SC_OPEN 30 // args: file, file_strlen, mode -#define SC_CLOSE 31 // args: fd -#define SC_READ 32 // args: fd, offset, size, out char* data -#define SC_WRITE 33 // args: fd, offset, size, data -#define SC_READDIR 34 // args: fd, ent_no, out dirent_t *data -#define SC_STAT_OPEN 35 // args: fd, out stat_t *data -- stat on open file handle -#define SC_IOCTL 36 // args: fd, command, out void* data -#define SC_GET_MODE 37 // args: fd -- get mode for open file handle -#define SC_SELECT 38 // args: sel_fd_t*, count, timeout - -#define SC_MK_CHANNEL 40 // args: blocking?, (int, int)* -#define SC_GEN_TOKEN 41 // args: fd, token_t* -#define SC_USE_TOKEN 42 // args: token_t* - -#define SC_MAKE_FS 50 // args: sc_make_fs_args_t -#define SC_FS_ADD_SRC 51 // args: fs_name, fs_name_strlen, fd, opts, opts_strlen -#define SC_SUBFS 52 // args: sc_subfs_args_t -#define SC_RM_FS 53 // args: fs_name, fs_name_strlen -// TODO : how do we enumerate filesystems ? - -#define SC_NEW_PROC 60 // args: nothing ? -#define SC_BIND_FS 61 // args: pid, new_name, new_name_strlen, fs_name, fs_name_strlen -- bind FS to child process -#define SC_BIND_SUBFS 62 // args: sc_subfs_args_t -- subfs & bind to child process -#define SC_BIND_MAKE_FS 63 // args: sc_make_fs_args_t -#define SC_BIND_FD 64 // args: pid, new_fd, local_fd -- copy a file descriptor to child process -#define SC_PROC_EXEC 65 // args: pid, exec_name, exec_name_strlen -- execute binary in process -#define SC_PROC_STATUS 66 // args: pid, proc_status_t* -#define SC_PROC_KILL 67 // args: pid, proc_status_t* -- inconditionnally kill child process -#define SC_PROC_WAIT 68 // args: pid?, block?, proc_status_t* - -#define INVALID_PID 0 // do a wait with this PID to wayt for any child - -typedef struct { - const char* driver; - size_t driver_strlen; - - const char* fs_name; - size_t fs_name_strlen; - - fd_t source_fd; - - const char* opts; - size_t opts_strlen; - - pid_t bind_to_pid; // zero = bind to current proc -} sc_make_fs_args_t; - -typedef struct { - const char* new_name; - size_t new_name_strlen; - - const char* from_fs; - size_t from_fs_strlen; - - const char* root; - size_t root_strlen; - - int ok_modes; - - pid_t bind_to_pid; // 0 = bind to current proc -} sc_subfs_args_t; - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/token.h b/src/common/include/token.h deleted file mode 100644 index 9ec1aff..0000000 --- a/src/common/include/token.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include -#include - -#define TOKEN_LENGTH 16 -typedef struct { - char bytes[TOKEN_LENGTH]; -} token_t; - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/dev/vesa.c b/src/kernel/dev/vesa.c index 1880740..2a7b876 100644 --- a/src/kernel/dev/vesa.c +++ b/src/kernel/dev/vesa.c @@ -1,6 +1,6 @@ #include -#include // common header +#include #include #include @@ -184,9 +184,9 @@ typedef struct { uint8_t memory_model, bank_size, image_pages; uint8_t reserved0; - uint8_t red_mask, red_position; - uint8_t green_mask, green_position; - uint8_t blue_mask, blue_position; + uint8_t red_mask_sz, red_position; + uint8_t green_mask_sz, green_position; + uint8_t blue_mask_sz, blue_position; uint8_t rsv_mask, rsv_position; uint8_t directcolor_attributes; @@ -241,6 +241,19 @@ fs_node_ops_t vesa_fs_ops = { .dispose = 0, }; +static struct fb_memory_model { + int bpp, rp, gp, bp, rs, gs, bs, mm; +} fb_memory_models[8] = { + { 15, 10, 5, 0, 5, 5, 5, FB_MM_RGB16 }, + { 16, 10, 5, 0, 5, 5, 5, FB_MM_RGB16 }, + { 15, 0, 5, 10, 5, 5, 5, FB_MM_BGR16 }, + { 16, 0, 5, 10, 5, 5, 5, FB_MM_BGR16 }, + { 24, 16, 8, 0, 8, 8, 8, FB_MM_RGB24 }, + { 24, 0, 8, 16, 8, 8, 8, FB_MM_BGR24 }, + { 32, 16, 8, 0, 8, 8, 8, FB_MM_RGB32 }, + { 32, 0, 8, 16, 8, 8, 8, FB_MM_BGR32 }, +}; + void vesa_detect(fs_t *iofs) { if (!v86_begin_session()) return; @@ -280,13 +293,27 @@ void vesa_detect(fs_t *iofs) { if (!v86_bios_int(0x10) || v86_regs.ax != 0x004F) continue; if ((mi->attributes & 0x90) != 0x90) continue; // not linear framebuffer - if (mi->memory_model != 4 && mi->memory_model != 6) continue; + if (mi->memory_model != 6) continue; int x = mode_data_c; mode_data[x].info.width = mi->Xres; mode_data[x].info.height = mi->Yres; mode_data[x].info.bpp = mi->bpp; mode_data[x].info.pitch = mi->pitch; + + mode_data[x].info.memory_model = 0; + for (int j = 0; j < 8; j++) { + struct fb_memory_model m = fb_memory_models[j]; + if (mi->bpp == m.bpp + && mi->red_mask_sz == m.rs && mi->red_position == m.rp + && mi->green_mask_sz == m.gs && mi->green_position == m.gp + && mi->blue_mask_sz == m.bs && mi->blue_position == m.bp) + mode_data[x].info.memory_model = m.mm; + } + if (mode_data[x].info.memory_model == 0) continue; + + dbg_printf("VESA mode: %dx%dx%d (%d)\n", mi->Xres, mi->Yres, mi->bpp, mode_data[x].info.memory_model); + mode_data[x].phys_fb_addr = (void*)mi->physbase; mode_data[x].vesa_mode_id = *mode; mode_data_c++; diff --git a/src/kernel/include/ipc.h b/src/kernel/include/ipc.h index 0feddf2..05d14a8 100644 --- a/src/kernel/include/ipc.h +++ b/src/kernel/include/ipc.h @@ -1,6 +1,7 @@ #pragma once -#include +#include + #include // ---- Communication channels diff --git a/src/kernel/include/process.h b/src/kernel/include/process.h index 3b98451..d4fcfc3 100644 --- a/src/kernel/include/process.h +++ b/src/kernel/include/process.h @@ -17,8 +17,8 @@ #include #include -#include // common header for mmaps -#include // common header defining process statuses +#include +#include #define USERSTACK_ADDR 0xB8000000 #define USERSTACK_SIZE 0x00020000 // 32 KB - it is allocated on demand so no worries diff --git a/src/kernel/include/sct.h b/src/kernel/include/sct.h index 2d6acd5..8f675b1 100644 --- a/src/kernel/include/sct.h +++ b/src/kernel/include/sct.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include void setup_syscall_table(); diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h index 3d225c5..c22ec9a 100644 --- a/src/kernel/include/vfs.h +++ b/src/kernel/include/vfs.h @@ -6,7 +6,7 @@ #include #include -#include // common header +#include #include diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h index 79e930f..f66b759 100644 --- a/src/lib/include/syscall.h +++ b/src/lib/include/syscall.h @@ -4,12 +4,12 @@ #include #include -#include -#include +#include +#include +#include +#include -#include #include -#include typedef void (*entry_t)(void*); -- cgit v1.2.3