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