Search
lxdream.org :: lxdream/src/syscall.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/syscall.c
changeset 102:844a3f2a76ff
next561:533f6b478071
next586:2a3ba82cf243
author nkeynes
date Tue May 02 14:09:11 2006 +0000 (17 years ago)
permissions -rw-r--r--
last change Add packet.h
Implement read toc, request sense, test ready commands.
Fix failure to clear error status on new command
view annotate diff log raw
     1 /**
     2  * $Id: syscall.c,v 1.1 2006-03-13 12:38:34 nkeynes Exp $
     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 "dream.h"
    20 #include "mem.h"
    21 #include "syscall.h"
    22 #include "sh4/sh4core.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     sh4_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 	    sh4_write_long( syscall_hooks[i].vector, 0xFFFFFF00 + i );
    66 	}
    67     }
    68 }
.