Search
lxdream.org :: lxdream :: r102:844a3f2a76ff
lxdream 0.9.1
released Jun 29
Download Now
changeset102:844a3f2a76ff
parent101:5a22f3699b67
child103:9b9cfc5855e0
authornkeynes
dateMon Mar 13 12:38:39 2006 +0000 (13 years ago)
Refactor bios into more generic syscall structure. Add initial hooks for
dc-load functions
src/bios.c
src/bios.h
src/dcload.c
src/sh4/sh4core.c
src/syscall.c
src/syscall.h
1.1 --- a/src/bios.c Mon Mar 13 12:37:06 2006 +0000
1.2 +++ b/src/bios.c Mon Mar 13 12:38:39 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: bios.c,v 1.1 2006-01-22 22:40:53 nkeynes Exp $
1.6 + * $Id: bios.c,v 1.2 2006-03-13 12:38:34 nkeynes Exp $
1.7 *
1.8 * "Fake" BIOS functions, for operation without the actual BIOS.
1.9 *
1.10 @@ -18,7 +18,7 @@
1.11
1.12 #include "dream.h"
1.13 #include "mem.h"
1.14 -#include "bios.h"
1.15 +#include "syscall.h"
1.16 #include "sh4/sh4core.h"
1.17
1.18 #define COMMAND_QUEUE_LENGTH 16
1.19 @@ -117,16 +117,6 @@
1.20 return &gdrom_cmd_queue[id];
1.21 }
1.22
1.23 -void bios_install( void )
1.24 -{
1.25 - bios_gdrom_init();
1.26 - sh4_write_long( 0x8C0000B0, 0xFFFFFFB0 );
1.27 - sh4_write_long( 0x8C0000B4, 0xFFFFFFB4 );
1.28 - sh4_write_long( 0x8C0000B8, 0xFFFFFFB8 );
1.29 - sh4_write_long( 0x8C0000BC, 0xFFFFFFBC );
1.30 - sh4_write_long( 0x8C0000E0, 0xFFFFFFE0 );
1.31 -}
1.32 -
1.33 /**
1.34 * Syscall list courtesy of Marcus Comstedt
1.35 */
1.36 @@ -211,3 +201,13 @@
1.37 }
1.38 }
1.39 }
1.40 +
1.41 +void bios_install( void )
1.42 +{
1.43 + bios_gdrom_init();
1.44 + syscall_add_hook_vector( 0xB0, 0x8C0000B0, bios_syscall );
1.45 + syscall_add_hook_vector( 0xB4, 0x8C0000B4, bios_syscall );
1.46 + syscall_add_hook_vector( 0xB8, 0x8C0000B8, bios_syscall );
1.47 + syscall_add_hook_vector( 0xBC, 0x8C0000BC, bios_syscall );
1.48 + syscall_add_hook_vector( 0xE0, 0x8C0000E0, bios_syscall );
1.49 +}
2.1 --- a/src/bios.h Mon Mar 13 12:37:06 2006 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,45 +0,0 @@
2.4 -/**
2.5 - * $Id: bios.h,v 1.1 2006-01-22 22:40:53 nkeynes Exp $
2.6 - *
2.7 - * "Fake" BIOS support, to allow basic functionality without the BIOS
2.8 - * actually being present.
2.9 - *
2.10 - * Copyright (c) 2005 Nathan Keynes.
2.11 - *
2.12 - * This program is free software; you can redistribute it and/or modify
2.13 - * it under the terms of the GNU General Public License as published by
2.14 - * the Free Software Foundation; either version 2 of the License, or
2.15 - * (at your option) any later version.
2.16 - *
2.17 - * This program is distributed in the hope that it will be useful,
2.18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.20 - * GNU General Public License for more details.
2.21 - */
2.22 -#ifndef dream_bios_H
2.23 -#define dream_bios_H 1
2.24 -
2.25 -#include <stdint.h>
2.26 -#include <glib/gtypes.h>
2.27 -
2.28 -#ifdef __cplusplus
2.29 -extern "C" {
2.30 -#endif
2.31 -
2.32 -/**
2.33 - * Execute a BIOS syscall identified by a syscall ID (currently the last
2.34 - * byte of the vector).
2.35 - */
2.36 -void bios_syscall( uint32_t syscallid );
2.37 -
2.38 -/**
2.39 - * Install the BIOS emu hack into ram (sets the vectors at 8C0000B0 through
2.40 - * 8C0000C0)
2.41 - */
2.42 -void bios_install( void );
2.43 -
2.44 -
2.45 -#ifdef __cplusplus
2.46 -}
2.47 -#endif
2.48 -#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/dcload.c Mon Mar 13 12:38:39 2006 +0000
3.3 @@ -0,0 +1,87 @@
3.4 +/**
3.5 + * $Id: dcload.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
3.6 + *
3.7 + * DC-load syscall implementation.
3.8 + *
3.9 + * Copyright (c) 2005 Nathan Keynes.
3.10 + *
3.11 + * This program is free software; you can redistribute it and/or modify
3.12 + * it under the terms of the GNU General Public License as published by
3.13 + * the Free Software Foundation; either version 2 of the License, or
3.14 + * (at your option) any later version.
3.15 + *
3.16 + * This program is distributed in the hope that it will be useful,
3.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.19 + * GNU General Public License for more details.
3.20 + */
3.21 +
3.22 +#include <stdio.h>
3.23 +#include "dream.h"
3.24 +#include "mem.h"
3.25 +#include "syscall.h"
3.26 +#include "sh4/sh4core.h"
3.27 +
3.28 +#define SYS_READ 0
3.29 +#define SYS_WRITE 1
3.30 +#define SYS_OPEN 2
3.31 +#define SYS_CLOSE 3
3.32 +#define SYS_CREAT 4
3.33 +#define SYS_LINK 5
3.34 +#define SYS_UNLINK 6
3.35 +#define SYS_CHDIR 7
3.36 +#define SYS_CHMOD 8
3.37 +#define SYS_LSEEK 9
3.38 +#define SYS_FSTAT 10
3.39 +#define SYS_TIME 11
3.40 +#define SYS_STAT 12
3.41 +#define SYS_UTIME 13
3.42 +#define SYS_ASSIGNWRKMEM 14
3.43 +#define SYS_EXIT 15
3.44 +#define SYS_OPENDIR 16
3.45 +#define SYS_CLOSEDIR 17
3.46 +#define SYS_READDIR 18
3.47 +#define SYS_GETHOSTINFO 19
3.48 +
3.49 +#define SYS_MAGIC 0xDEADBEEF
3.50 +#define SYS_MAGIC_ADDR 0x8c004004
3.51 +#define SYSCALL_ADDR 0x8c004008
3.52 +
3.53 +void dcload_syscall( uint32_t syscall_id )
3.54 +{
3.55 + uint32_t syscall = sh4r.r[4];
3.56 + switch( sh4r.r[4] ) {
3.57 + case SYS_READ:
3.58 + if( sh4r.r[5] == 0 ) {
3.59 + char *buf = mem_get_region( sh4r.r[6] );
3.60 + int length = sh4r.r[7];
3.61 + sh4r.r[0] = read( 0, buf, length );
3.62 + } else {
3.63 + sh4r.r[0] = -1;
3.64 + }
3.65 + break;
3.66 + case SYS_WRITE:
3.67 + if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
3.68 + char *buf = mem_get_region( sh4r.r[6] );
3.69 + int length = sh4r.r[7];
3.70 + sh4r.r[0] = write( sh4r.r[5], buf, length );
3.71 + } else {
3.72 + sh4r.r[0] = -1;
3.73 + }
3.74 + break;
3.75 + case SYS_EXIT:
3.76 + dreamcast_stop();
3.77 + sh4_stop();
3.78 + sh4r.r[0] = 0;
3.79 + break;
3.80 + default:
3.81 + sh4r.r[0] = -1;
3.82 + }
3.83 +
3.84 +}
3.85 +
3.86 +void dcload_install()
3.87 +{
3.88 + syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
3.89 + sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
3.90 +}
4.1 --- a/src/sh4/sh4core.c Mon Mar 13 12:37:06 2006 +0000
4.2 +++ b/src/sh4/sh4core.c Mon Mar 13 12:38:39 2006 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: sh4core.c,v 1.20 2006-02-15 12:38:50 nkeynes Exp $
4.6 + * $Id: sh4core.c,v 1.21 2006-03-13 12:38:39 nkeynes Exp $
4.7 *
4.8 * SH4 emulation core, and parent module for all the SH4 peripheral
4.9 * modules.
4.10 @@ -25,7 +25,7 @@
4.11 #include "sh4/intc.h"
4.12 #include "mem.h"
4.13 #include "clock.h"
4.14 -#include "bios.h"
4.15 +#include "syscall.h"
4.16
4.17 /* CPU-generated exception code/vector pairs */
4.18 #define EXC_POWER_RESET 0x000 /* vector special */
4.19 @@ -333,7 +333,7 @@
4.20 pc = sh4r.pc;
4.21 if( pc > 0xFFFFFF00 ) {
4.22 /* SYSCALL Magic */
4.23 - bios_syscall( pc & 0xFF );
4.24 + syscall_invoke( pc );
4.25 sh4r.in_delay_slot = 1;
4.26 pc = sh4r.pc = sh4r.pr;
4.27 sh4r.new_pc = sh4r.pc + 2;
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/syscall.c Mon Mar 13 12:38:39 2006 +0000
5.3 @@ -0,0 +1,68 @@
5.4 +/**
5.5 + * $Id: syscall.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
5.6 + *
5.7 + * Routines to add hook functions that are callable from the SH4
5.8 + *
5.9 + * Copyright (c) 2005 Nathan Keynes.
5.10 + *
5.11 + * This program is free software; you can redistribute it and/or modify
5.12 + * it under the terms of the GNU General Public License as published by
5.13 + * the Free Software Foundation; either version 2 of the License, or
5.14 + * (at your option) any later version.
5.15 + *
5.16 + * This program is distributed in the hope that it will be useful,
5.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.19 + * GNU General Public License for more details.
5.20 + */
5.21 +
5.22 +#include "dream.h"
5.23 +#include "mem.h"
5.24 +#include "syscall.h"
5.25 +#include "sh4/sh4core.h"
5.26 +
5.27 +
5.28 +struct syscall_hook {
5.29 + syscall_hook_func_t hook;
5.30 + sh4addr_t vector;
5.31 +} syscall_hooks[256];
5.32 +
5.33 +void syscall_add_hook( uint32_t hook_id, syscall_hook_func_t hook )
5.34 +{
5.35 + hook_id &= 0xFF;
5.36 + if( syscall_hooks[hook_id].hook != NULL )
5.37 + WARN( "Overwriting existing hook %02X", hook_id );
5.38 + syscall_hooks[hook_id].hook = hook;
5.39 + syscall_hooks[hook_id].vector = 0;
5.40 +}
5.41 +
5.42 +void syscall_add_hook_vector( uint32_t hook_id, uint32_t vector_addr,
5.43 + syscall_hook_func_t hook )
5.44 +{
5.45 + hook_id &= 0xFF;
5.46 + syscall_add_hook( hook_id, hook );
5.47 + syscall_hooks[hook_id].vector = vector_addr;
5.48 + sh4_write_long( vector_addr, 0xFFFFFF00 + hook_id );
5.49 +}
5.50 +
5.51 +void syscall_invoke( uint32_t hook_id )
5.52 +{
5.53 + hook_id &= 0xFF;
5.54 + syscall_hook_func_t hook = syscall_hooks[hook_id].hook;
5.55 + if( hook == NULL ) {
5.56 + WARN( "Invoked non-existent hook %02X", hook_id );
5.57 + } else {
5.58 + hook(hook_id);
5.59 + }
5.60 +}
5.61 +
5.62 +void syscall_repatch_vectors( )
5.63 +{
5.64 + int i;
5.65 + for( i=0; i<256; i++ ) {
5.66 + if( syscall_hooks[i].hook != NULL &&
5.67 + syscall_hooks[i].vector != 0 ) {
5.68 + sh4_write_long( syscall_hooks[i].vector, 0xFFFFFF00 + i );
5.69 + }
5.70 + }
5.71 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/src/syscall.h Mon Mar 13 12:38:39 2006 +0000
6.3 @@ -0,0 +1,71 @@
6.4 +/**
6.5 + * $Id: syscall.h,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
6.6 + *
6.7 + * Generic syscall support - ability to add hooks into SH4 code to call out
6.8 + * to the emu.
6.9 + *
6.10 + * Copyright (c) 2005 Nathan Keynes.
6.11 + *
6.12 + * This program is free software; you can redistribute it and/or modify
6.13 + * it under the terms of the GNU General Public License as published by
6.14 + * the Free Software Foundation; either version 2 of the License, or
6.15 + * (at your option) any later version.
6.16 + *
6.17 + * This program is distributed in the hope that it will be useful,
6.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.20 + * GNU General Public License for more details.
6.21 + */
6.22 +#ifndef dream_syscall_H
6.23 +#define dream_syscall_H 1
6.24 +
6.25 +#include <stdint.h>
6.26 +#include <glib/gtypes.h>
6.27 +
6.28 +#ifdef __cplusplus
6.29 +extern "C" {
6.30 +#endif
6.31 +
6.32 +
6.33 +typedef void (*syscall_hook_func_t)( uint32_t hook_id );
6.34 +
6.35 +
6.36 +/**
6.37 + * Define a new hook without an indirect vector
6.38 + */
6.39 +void syscall_add_hook( uint32_t hook_id, syscall_hook_func_t hook );
6.40 +
6.41 +/**
6.42 + * Define a new hook which indirects through the specified vector address
6.43 + * (which must be somewhere in main SH4 ram).
6.44 + */
6.45 +void syscall_add_hook_vector( uint32_t hook_id, uint32_t vector_addr,
6.46 + syscall_hook_func_t hook );
6.47 +
6.48 +/**
6.49 + * Invoke a syscall from the SH4
6.50 + */
6.51 +void syscall_invoke( uint32_t hook_id );
6.52 +
6.53 +/**
6.54 + * Repatch all syscall vectors (eg in case of system reset)
6.55 + */
6.56 +void syscall_repatch_vectors( );
6.57 +
6.58 +/************************ Standard syscall hacks ************************/
6.59 +
6.60 +/**
6.61 + * Install the BIOS emu hack into ram (sets the vectors at 8C0000B0 through
6.62 + * 8C0000C0)
6.63 + */
6.64 +void bios_install( void );
6.65 +
6.66 +/**
6.67 + * Install the DCLoad syscall hack
6.68 + */
6.69 +void dcload_install( void );
6.70 +
6.71 +#ifdef __cplusplus
6.72 +}
6.73 +#endif
6.74 +#endif
.