1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/syscall.c Thu Jan 11 12:14:11 2007 +0000
1.5 + * $Id: syscall.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
1.7 + * Routines to add hook functions that are callable from the SH4
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.24 +#include "syscall.h"
1.25 +#include "sh4/sh4core.h"
1.28 +struct syscall_hook {
1.29 + syscall_hook_func_t hook;
1.31 +} syscall_hooks[256];
1.33 +void syscall_add_hook( uint32_t hook_id, syscall_hook_func_t hook )
1.36 + if( syscall_hooks[hook_id].hook != NULL )
1.37 + WARN( "Overwriting existing hook %02X", hook_id );
1.38 + syscall_hooks[hook_id].hook = hook;
1.39 + syscall_hooks[hook_id].vector = 0;
1.42 +void syscall_add_hook_vector( uint32_t hook_id, uint32_t vector_addr,
1.43 + syscall_hook_func_t hook )
1.46 + syscall_add_hook( hook_id, hook );
1.47 + syscall_hooks[hook_id].vector = vector_addr;
1.48 + sh4_write_long( vector_addr, 0xFFFFFF00 + hook_id );
1.51 +void syscall_invoke( uint32_t hook_id )
1.54 + syscall_hook_func_t hook = syscall_hooks[hook_id].hook;
1.55 + if( hook == NULL ) {
1.56 + WARN( "Invoked non-existent hook %02X", hook_id );
1.62 +void syscall_repatch_vectors( )
1.65 + for( i=0; i<256; i++ ) {
1.66 + if( syscall_hooks[i].hook != NULL &&
1.67 + syscall_hooks[i].vector != 0 ) {
1.68 + sh4_write_long( syscall_hooks[i].vector, 0xFFFFFF00 + i );