Search
lxdream.org :: lxdream/src/syscall.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/syscall.c
changeset 736:a02d1475ccfd
prev669:ab344e42bca9
next1065:bc1cc0c54917
author nkeynes
date Fri Jul 18 11:08:30 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Fix old copy-n-paste error in INFO line
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * 
     4  * Routines to add hook functions that are callable from the SH4
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "lxdream.h"
    20 #include "mem.h"
    21 #include "syscall.h"
    22 #include "sh4/sh4.h"
    25 struct syscall_hook {
    26     syscall_hook_func_t hook;
    27     sh4addr_t vector;
    28 } syscall_hooks[256];
    30 void syscall_add_hook( uint32_t hook_id, syscall_hook_func_t hook ) 
    31 {
    32     hook_id &= 0xFF;
    33     if( syscall_hooks[hook_id].hook != NULL )
    34         WARN( "Overwriting existing hook %02X", hook_id );
    35     syscall_hooks[hook_id].hook = hook;
    36     syscall_hooks[hook_id].vector = 0;
    37 }
    39 void syscall_add_hook_vector( uint32_t hook_id, uint32_t vector_addr,
    40                               syscall_hook_func_t hook )
    41 {
    42     hook_id &= 0xFF;
    43     syscall_add_hook( hook_id, hook );
    44     syscall_hooks[hook_id].vector = vector_addr;
    45     mem_write_long( vector_addr, 0xFFFFFF00 + hook_id );
    46 }
    48 void syscall_invoke( uint32_t hook_id )
    49 {
    50     hook_id &= 0xFF;
    51     syscall_hook_func_t hook = syscall_hooks[hook_id].hook;
    52     if( hook == NULL ) {
    53         WARN( "Invoked non-existent hook %02X", hook_id );
    54     } else {
    55         hook(hook_id);
    56     }
    57 }
    59 void syscall_repatch_vectors( )
    60 {
    61     int i;
    62     for( i=0; i<256; i++ ) {
    63         if( syscall_hooks[i].hook != NULL &&
    64                 syscall_hooks[i].vector != 0 ) {
    65             mem_write_long( syscall_hooks[i].vector, 0xFFFFFF00 + i );
    66         }
    67     }
    68 }
.