From: falcovorbis <fal...@us...> - 2024-05-11 03:33:40
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 71aa13a7edebe7c236c306f5e12abddb27f0a8f3 (commit) from 9a1358bc2e4636d1333b52160fdbef5b41131d02 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 71aa13a7edebe7c236c306f5e12abddb27f0a8f3 Author: Andy Barajas <and...@gm...> Date: Fri May 10 20:32:34 2024 -0700 Add Syscalls module (#536) * Added syscalls module and updated modules that use the syscalls --------- Co-authored-by: Falco Girgis <gyr...@gm...> Co-authored-by: Donald Haase <qu...@ya...> ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG | 1 + kernel/arch/dreamcast/hardware/Makefile | 3 + kernel/arch/dreamcast/hardware/biosfont.c | 59 ++-- kernel/arch/dreamcast/hardware/cdrom.c | 118 ++------ kernel/arch/dreamcast/hardware/flashrom.c | 17 +- kernel/arch/dreamcast/hardware/syscall_font.s | 58 ++++ kernel/arch/dreamcast/hardware/syscalls.c | 266 +++++++++++++++++ kernel/arch/dreamcast/include/dc/syscalls.h | 403 ++++++++++++++++++++++++++ kernel/arch/dreamcast/kernel/init.c | 8 +- 9 files changed, 798 insertions(+), 135 deletions(-) create mode 100644 kernel/arch/dreamcast/hardware/syscall_font.s create mode 100644 kernel/arch/dreamcast/hardware/syscalls.c create mode 100644 kernel/arch/dreamcast/include/dc/syscalls.h diff --git a/doc/CHANGELOG b/doc/CHANGELOG index cb37cfe0..252729cd 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -223,6 +223,7 @@ KallistiOS version 2.1.0 ----------------------------------------------- - DC Increased the resolution of pvr_stats_t from milli to nanoseconds [FG] - *** Added support for modifying scheduler frequency at runtime [FG] - *** Add support for worker threads [PC] +- DC Added new System Calls module [AB] KallistiOS version 2.0.0 ----------------------------------------------- - DC Broadband Adapter driver fixes [Megan Potter == MP] diff --git a/kernel/arch/dreamcast/hardware/Makefile b/kernel/arch/dreamcast/hardware/Makefile index 297c4493..f83f51db 100644 --- a/kernel/arch/dreamcast/hardware/Makefile +++ b/kernel/arch/dreamcast/hardware/Makefile @@ -12,6 +12,9 @@ ifneq ($(KOS_SUBARCH), naomi) OBJS += biosfont.o cdrom.o flashrom.o endif +# System Calls +OBJS += syscalls.o syscall_font.o + # G2 OBJS += g2dma.o diff --git a/kernel/arch/dreamcast/hardware/biosfont.c b/kernel/arch/dreamcast/hardware/biosfont.c index a8b9c3c1..328d278f 100644 --- a/kernel/arch/dreamcast/hardware/biosfont.c +++ b/kernel/arch/dreamcast/hardware/biosfont.c @@ -4,12 +4,17 @@ Copyright (C) 2000-2002 Megan Potter Japanese code Copyright (C) Kazuaki Matsumoto - Copyright (C) 2017 Donald Haase + Copyright (C) 2017, 2024 Donald Haase + Copyright (C) 2024 Andy Barajas */ #include <assert.h> + #include <dc/biosfont.h> +#include <dc/syscalls.h> + #include <kos/dbglog.h> +#include <kos/mutex.h> /* @@ -70,20 +75,26 @@ int bfont_set_32bit_mode(int on) { return rv; } -/* A little assembly that grabs the font address */ -extern uint8* get_font_address(void); -__asm__(" .text\n" - " .align 2\n" - ".globl _get_font_address\n" - "_get_font_address:\n" - " mov.l syscall_b4,r0\n" - " mov.l @r0,r0\n" - " jmp @r0\n" - " mov #0,r1\n" - "\n" - " .align 4\n" - "syscall_b4:\n" - " .long 0x8c0000b4\n"); +/* From cdrom.c */ +extern mutex_t _g1_ata_mutex; + +int lock_bfont(void) { + if(mutex_lock(&_g1_ata_mutex) == -1) return -1; + + /* Just make sure no outside system took the lock */ + while(syscall_font_lock() != 0) + thd_pass(); + + return 0; +} + +int unlock_bfont(void) { + if(mutex_unlock(&_g1_ata_mutex) == -1) return -1; + + syscall_font_unlock(); + + return 0; +} /* Shift-JIS -> JIS conversion */ uint32 sjis2jis(uint32 sjis) { @@ -114,7 +125,7 @@ uint32 euc2jis(uint32 euc) { /* Given an ASCII character, find it in the BIOS font if possible */ uint8 *bfont_find_char(uint32 ch) { - uint8 *fa = get_font_address(); + uint8 *fa = syscall_font_address(); /* By default, map to a space */ uint32 index = 72 << 2; @@ -131,7 +142,7 @@ uint8 *bfont_find_char(uint32 ch) { /* JIS -> (kuten) -> address conversion */ uint8 *bfont_find_char_jp(uint32 ch) { - uint8 *fa = get_font_address(); + uint8 *fa = syscall_font_address(); uint32 ku, ten, kuten = 0; /* Do the requested code conversion */ @@ -164,7 +175,7 @@ uint8 *bfont_find_char_jp(uint32 ch) { /* Half-width kana -> address conversion */ uint8 *bfont_find_char_jp_half(uint32 ch) { - uint8 *fa = get_font_address(); + uint8 *fa = syscall_font_address(); return fa + (32 + ch) * (BFONT_THIN_WIDTH*BFONT_HEIGHT/8); } @@ -227,9 +238,14 @@ unsigned char bfont_draw_ex(uint8 *buffer, uint32 bufwidth, uint32 fg, uint32 bg return 0; } + if(lock_bfont() < 0) { + dbglog(DBG_ERROR, "bfont_draw_ex: error requesting font access\n"); + return 0; + } + /* Translate the character */ if(bfont_code_mode == BFONT_CODE_RAW) - ch = get_font_address() + c; + ch = syscall_font_address() + c; else if(wide && ((bfont_code_mode == BFONT_CODE_EUC) || (bfont_code_mode == BFONT_CODE_SJIS))) ch = bfont_find_char_jp(c); else { @@ -258,6 +274,9 @@ unsigned char bfont_draw_ex(uint8 *buffer, uint32 bufwidth, uint32 fg, uint32 bg else buffer += ((bufwidth - BFONT_WIDE_WIDTH)*bpp)/8; } + if(unlock_bfont() < 0) + dbglog(DBG_ERROR, "bfont_draw_ex: error releasing font access\n"); + /* Return the horizontal distance covered in bytes */ if(wide) return (BFONT_WIDE_WIDTH*bpp)/8; @@ -345,6 +364,6 @@ uint8 *bfont_find_icon(uint8 icon) { int icon_offset = BFONT_VMU_DREAMCAST_SPECIFIC + (icon * BFONT_ICON_DIMEN * BFONT_ICON_DIMEN/8); - uint8 *fa = get_font_address(); + uint8 *fa = syscall_font_address(); return fa + icon_offset; } diff --git a/kernel/arch/dreamcast/hardware/cdrom.c b/kernel/arch/dreamcast/hardware/cdrom.c index abb4b028..e842e336 100644 --- a/kernel/arch/dreamcast/hardware/cdrom.c +++ b/kernel/arch/dreamcast/hardware/cdrom.c @@ -6,6 +6,7 @@ Copyright (C) 2014 Lawrence Sebald Copyright (C) 2014 Donald Haase Copyright (C) 2023 Ruslan Rostovtsev + Copyright (C) 2024 Andy Barajas */ #include <assert.h> @@ -15,6 +16,7 @@ #include <dc/cdrom.h> #include <dc/g1ata.h> +#include <dc/syscalls.h> #include <kos/thread.h> #include <kos/mutex.h> @@ -40,96 +42,16 @@ normally the case with the default options. If in doubt, decompile the output and look to make sure. XXX: This could all be done in a non-blocking way by taking advantage of -command queuing. Every call to gdc_req_cmd returns a 'request id' which -just needs to eventually be checked by cmd_stat. A non-blocking version -of all functions would simply require manual calls to check the status. -Doing this would probably allow data reading while cdda is playing without -hiccups (by severely reducing the number of gd commands being sent). +command queuing. Every call to syscall_gdrom_send_command returns a +'request id' which just needs to eventually be checked by cmd_stat. A +non-blocking version of all functions would simply require manual calls +to check the status. Doing this would probably allow data reading while +cdda is playing without hiccups (by severely reducing the number of gd +commands being sent). */ - -/* GD-Rom BIOS calls... named mostly after Marcus' code. None have more - than two parameters; R7 (fourth parameter) needs to describe - which syscall we want. */ - -#define MAKE_SYSCALL(rs, p1, p2, idx) \ - uint32_t *syscall_bc = (uint32_t *)(0x0c0000bc | MEM_AREA_P1_BASE); \ - int (*syscall)() = (int (*)())(*syscall_bc); \ - rs syscall((p1), (p2), 0, (idx)); - typedef int gdc_cmd_hnd_t; -/* Reset system functions */ -static void gdc_init_system(void) { - MAKE_SYSCALL(/**/, 0, 0, 3); -} - -/* Submit a command to the system */ -static gdc_cmd_hnd_t gdc_req_cmd(int cmd, void *param) { - MAKE_SYSCALL(return, cmd, param, 0); -} - -/* Check status on an executed command */ -static int gdc_get_cmd_stat(gdc_cmd_hnd_t hnd, void *status) { - MAKE_SYSCALL(return, hnd, status, 1); -} - -/* Execute submitted commands */ -static void gdc_exec_server(void) { - MAKE_SYSCALL(/**/, 0, 0, 2); -} - -/* Check drive status and get disc type */ -static int gdc_get_drv_stat(void *param) { - MAKE_SYSCALL(return, param, 0, 4); -} - -/* Set disc access mode */ -static int gdc_change_data_type(void *param) { - MAKE_SYSCALL(return, param, 0, 10); -} - -/* Abort the current command */ -static void gdc_abort_cmd(gdc_cmd_hnd_t hnd) { - MAKE_SYSCALL(/**/, hnd, 0, 8); -} - -/* Reset the GD-ROM syscalls */ -static void gdc_reset(void) { - MAKE_SYSCALL(/**/, 0, 0, 9); -} -#if 0 /* Not used yet */ -/* DMA end interrupt handler */ -static void gdc_dma_end(uintptr_t callback, void *param) { - MAKE_SYSCALL(/**/, callback, param, 5); -} - -/* Request DMA transfer for DMAREAD_STREAM commands */ -static int gdc_req_dma_transfer(gdc_cmd_hnd_t hnd, int *params) { - MAKE_SYSCALL(return, hnd, params, 6); -} - -/* Check DMA transfer for DMAREAD_STREAM commands */ -static int gdc_check_dma_transfer(gdc_cmd_hnd_t hnd, int *size) { - MAKE_SYSCALL(return, hnd, size, 7); -} - -/* Setup PIO transfer end callback for PIOREAD_STREAM commands */ -static void gdc_set_pio_callback(uintptr_t callback, void *param) { - MAKE_SYSCALL(/**/, callback, param, 11); -} - -/* Request PIO transfer for PIOREAD_STREAM commands */ -static int gdc_req_pio_transfer(gdc_cmd_hnd_t hnd, int *params) { - MAKE_SYSCALL(return, hnd, params, 12); -} - -/* Check PIO transfer for PIOREAD_STREAM commands */ -static int gdc_check_pio_transfer(gdc_cmd_hnd_t hnd, int *size) { - MAKE_SYSCALL(return, hnd, size, 13); -} -#endif - /* The G1 ATA access mutex */ mutex_t _g1_ata_mutex = MUTEX_INITIALIZER; @@ -144,7 +66,7 @@ int cdrom_exec_cmd(int cmd, void *param) { } int cdrom_exec_cmd_timed(int cmd, void *param, int timeout) { - int status[4] = { + int32_t status[4] = { 0, /* Error code 1 */ 0, /* Error code 2 */ 0, /* Transferred size */ @@ -159,11 +81,11 @@ int cdrom_exec_cmd_timed(int cmd, void *param, int timeout) { /* Submit the command */ for(n = 0; n < 10; ++n) { - hnd = gdc_req_cmd(cmd, param); + hnd = syscall_gdrom_send_command(cmd, param); if (hnd != 0) { break; } - gdc_exec_server(); + syscall_gdrom_exec_server(); thd_pass(); } @@ -177,16 +99,16 @@ int cdrom_exec_cmd_timed(int cmd, void *param, int timeout) { begin = timer_ms_gettime64(); } do { - gdc_exec_server(); - n = gdc_get_cmd_stat(hnd, status); + syscall_gdrom_exec_server(); + n = syscall_gdrom_check_command(hnd, status); if(n != PROCESSING && n != BUSY) { break; } if(timeout) { if((timer_ms_gettime64() - begin) >= (unsigned)timeout) { - gdc_abort_cmd(hnd); - gdc_exec_server(); + syscall_gdrom_abort_command(hnd); + syscall_gdrom_exec_server(); rv = ERR_TIMEOUT; dbglog(DBG_ERROR, "cdrom_exec_cmd_timed: Timeout exceeded\n"); break; @@ -235,7 +157,7 @@ int cdrom_get_status(int *status, int *disc_type) { } do { - rv = gdc_get_drv_stat(params); + rv = syscall_gdrom_check_drive(params); if(rv != BUSY) { break; @@ -287,7 +209,7 @@ int cdrom_change_datatype(int sector_part, int cdxa, int sector_size) { if(cdxa == -1) { /* If not overriding cdxa, check what the drive thinks we should use */ - gdc_get_drv_stat(params); + syscall_gdrom_check_drive(params); cdxa = (params[1] == 32 ? 2048 : 1024); } @@ -302,7 +224,7 @@ int cdrom_change_datatype(int sector_part, int cdxa, int sector_size) { params[1] = sector_part; /* Get Data or Full Sector */ params[2] = cdxa; /* CD-XA mode 1/2 */ params[3] = sector_size; /* sector size */ - rv = gdc_change_data_type(params); + rv = syscall_gdrom_sector_mode(params); mutex_unlock(&_g1_ata_mutex); return rv; } @@ -496,8 +418,8 @@ void cdrom_init(void) { } /* Reset system functions */ - gdc_reset(); - gdc_init_system(); + syscall_gdrom_reset(); + syscall_gdrom_init(); mutex_unlock(&_g1_ata_mutex); cdrom_reinit(); diff --git a/kernel/arch/dreamcast/hardware/flashrom.c b/kernel/arch/dreamcast/hardware/flashrom.c index 3acd338b..d2c3b9b5 100644 --- a/kernel/arch/dreamcast/hardware/flashrom.c +++ b/kernel/arch/dreamcast/hardware/flashrom.c @@ -3,6 +3,7 @@ flashrom.c Copyright (c) 2003 Megan Potter Copyright (C) 2008 Lawrence Sebald + Copyright (C) 2024 Andy Barajas */ /* @@ -17,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> #include <dc/flashrom.h> +#include <dc/syscalls.h> #include <arch/irq.h> static void strcpy_no_term(char *dest, const char *src, size_t destsize) { @@ -39,17 +41,13 @@ static void strcpy_with_term(char *dest, const char *src, size_t destsize) { dest[srclength] = '\0'; } -/* First, implementation of the syscall wrappers. */ -typedef int (*flashrom_sc)(int, void *, int, int); - int flashrom_info(int part, int * start_out, int * size_out) { - flashrom_sc sc = (flashrom_sc)(*((uint32 *)0x8c0000b8)); uint32 ptrs[2]; int old, rv; old = irq_disable(); - if(!(rv = sc(part, ptrs, 0, 0))) { + if(!(rv = syscall_flashrom_info(part, ptrs))) { *start_out = ptrs[0]; *size_out = ptrs[1]; } @@ -60,31 +58,28 @@ int flashrom_info(int part, int * start_out, int * size_out) { } int flashrom_read(int offset, void * buffer_out, int bytes) { - flashrom_sc sc = (flashrom_sc)(*((uint32 *)0x8c0000b8)); int old, rv; old = irq_disable(); - rv = sc(offset, buffer_out, bytes, 1); + rv = syscall_flashrom_read(offset, buffer_out, bytes); irq_restore(old); return rv; } int flashrom_write(int offset, void * buffer, int bytes) { - flashrom_sc sc = (flashrom_sc)(*((uint32 *)0x8c0000b8)); int old, rv; old = irq_disable(); - rv = sc(offset, buffer, bytes, 2); + rv = syscall_flashrom_write(offset, buffer, bytes); irq_restore(old); return rv; } int flashrom_delete(int offset) { - flashrom_sc sc = (flashrom_sc)(*((uint32 *)0x8c0000b8)); int old, rv; old = irq_disable(); - rv = sc(offset, 0, 0, 3); + rv = syscall_flashrom_delete(offset); irq_restore(old); return rv; } diff --git a/kernel/arch/dreamcast/hardware/syscall_font.s b/kernel/arch/dreamcast/hardware/syscall_font.s new file mode 100644 index 00000000..44507c38 --- /dev/null +++ b/kernel/arch/dreamcast/hardware/syscall_font.s @@ -0,0 +1,58 @@ + +! KallistiOS ##version## +! +! arch/dreamcast/hardware/syscall_font.s +! +! Copyright (C) 2024 Andy Barajas +! +! Assembly code for font system calls +! + .text + .globl _syscall_font_address + .globl _syscall_font_lock + .globl _syscall_font_unlock + +! +! uint8_t *syscall_font_address(void); +! + .align 2 +_syscall_font_address: + mov.l syscall_font, r0 + mov.l @r0, r0 + jmp @r0 + mov #0, r1 ! 0 is FUNC_ROMFONT_ADDRESS + + rts + nop + +! +! int syscall_font_lock(void); +! + .align 2 +_syscall_font_lock: + mov.l syscall_font, r0 + mov.l @r0, r0 + jmp @r0 + mov #1, r1 ! 1 is FUNC_ROMFONT_LOCK + + rts + nop + +! +! void syscall_font_unlock(void); +! + .align 2 +_syscall_font_unlock: + mov.l syscall_font, r0 + mov.l @r0, r0 + jmp @r0 + mov #2, r1 ! 2 is FUNC_ROMFONT_UNLOCK + + rts + nop + +! Variables + .align 4 + +syscall_font: + .long 0x8C0000B4 ! VEC_BIOFONT diff --git a/kernel/arch/dreamcast/hardware/syscalls.c b/kernel/arch/dreamcast/hardware/syscalls.c new file mode 100644 index 00000000..476e1e33 --- /dev/null ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |