Search
lxdream.org :: lxdream/src/syscall.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/syscall.c
changeset 102:844a3f2a76ff
next561:533f6b478071
next586:2a3ba82cf243
author nkeynes
date Mon Mar 13 12:38:39 2006 +0000 (18 years ago)
permissions -rw-r--r--
last change Refactor bios into more generic syscall structure. Add initial hooks for
dc-load functions
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/syscall.c Mon Mar 13 12:38:39 2006 +0000
1.3 @@ -0,0 +1,68 @@
1.4 +/**
1.5 + * $Id: syscall.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
1.6 + *
1.7 + * Routines to add hook functions that are callable from the SH4
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
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.15 + *
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.20 + */
1.21 +
1.22 +#include "dream.h"
1.23 +#include "mem.h"
1.24 +#include "syscall.h"
1.25 +#include "sh4/sh4core.h"
1.26 +
1.27 +
1.28 +struct syscall_hook {
1.29 + syscall_hook_func_t hook;
1.30 + sh4addr_t vector;
1.31 +} syscall_hooks[256];
1.32 +
1.33 +void syscall_add_hook( uint32_t hook_id, syscall_hook_func_t hook )
1.34 +{
1.35 + hook_id &= 0xFF;
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.40 +}
1.41 +
1.42 +void syscall_add_hook_vector( uint32_t hook_id, uint32_t vector_addr,
1.43 + syscall_hook_func_t hook )
1.44 +{
1.45 + hook_id &= 0xFF;
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.49 +}
1.50 +
1.51 +void syscall_invoke( uint32_t hook_id )
1.52 +{
1.53 + hook_id &= 0xFF;
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.57 + } else {
1.58 + hook(hook_id);
1.59 + }
1.60 +}
1.61 +
1.62 +void syscall_repatch_vectors( )
1.63 +{
1.64 + int i;
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 );
1.69 + }
1.70 + }
1.71 +}
.