Search
lxdream.org :: lxdream/src/dcload.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dcload.c
changeset 106:9048bac046c3
prev102:844a3f2a76ff
next120:7e4549476110
author nkeynes
date Tue Mar 14 12:45:53 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Move driver selection out to main at long last. Add video NULL driver for
headless operation
Make dcload exit() actually exit
file annotate diff log raw
nkeynes@102
     1
/**
nkeynes@106
     2
 * $Id: dcload.c,v 1.2 2006-03-14 12:45:50 nkeynes Exp $
nkeynes@102
     3
 * 
nkeynes@102
     4
 * DC-load syscall implementation.
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@102
    19
#include <stdio.h>
nkeynes@102
    20
#include "dream.h"
nkeynes@102
    21
#include "mem.h"
nkeynes@102
    22
#include "syscall.h"
nkeynes@102
    23
#include "sh4/sh4core.h"
nkeynes@102
    24
nkeynes@102
    25
#define SYS_READ 0
nkeynes@102
    26
#define SYS_WRITE 1
nkeynes@102
    27
#define SYS_OPEN 2
nkeynes@102
    28
#define SYS_CLOSE 3
nkeynes@102
    29
#define SYS_CREAT 4
nkeynes@102
    30
#define SYS_LINK 5
nkeynes@102
    31
#define SYS_UNLINK 6
nkeynes@102
    32
#define SYS_CHDIR 7
nkeynes@102
    33
#define SYS_CHMOD 8
nkeynes@102
    34
#define SYS_LSEEK 9
nkeynes@102
    35
#define SYS_FSTAT 10
nkeynes@102
    36
#define SYS_TIME 11
nkeynes@102
    37
#define SYS_STAT 12
nkeynes@102
    38
#define SYS_UTIME 13
nkeynes@102
    39
#define SYS_ASSIGNWRKMEM 14
nkeynes@102
    40
#define SYS_EXIT 15
nkeynes@102
    41
#define SYS_OPENDIR 16
nkeynes@102
    42
#define SYS_CLOSEDIR 17
nkeynes@102
    43
#define SYS_READDIR 18
nkeynes@102
    44
#define SYS_GETHOSTINFO 19
nkeynes@102
    45
nkeynes@102
    46
#define SYS_MAGIC 0xDEADBEEF
nkeynes@102
    47
#define SYS_MAGIC_ADDR 0x8c004004
nkeynes@102
    48
#define SYSCALL_ADDR 0x8c004008
nkeynes@102
    49
nkeynes@102
    50
void dcload_syscall( uint32_t syscall_id ) 
nkeynes@102
    51
{
nkeynes@102
    52
    uint32_t syscall = sh4r.r[4];
nkeynes@102
    53
    switch( sh4r.r[4] ) {
nkeynes@102
    54
    case SYS_READ:
nkeynes@102
    55
	if( sh4r.r[5] == 0 ) {
nkeynes@102
    56
	    char *buf = mem_get_region( sh4r.r[6] );
nkeynes@102
    57
	    int length = sh4r.r[7];
nkeynes@102
    58
	    sh4r.r[0] = read( 0, buf, length );
nkeynes@102
    59
	} else {
nkeynes@102
    60
	    sh4r.r[0] = -1;
nkeynes@102
    61
	}
nkeynes@102
    62
	break;
nkeynes@102
    63
    case SYS_WRITE:
nkeynes@102
    64
	if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
nkeynes@102
    65
	    char *buf = mem_get_region( sh4r.r[6] );
nkeynes@102
    66
	    int length = sh4r.r[7];
nkeynes@102
    67
	    sh4r.r[0] = write( sh4r.r[5], buf, length );
nkeynes@102
    68
	} else {
nkeynes@102
    69
	    sh4r.r[0] = -1;
nkeynes@102
    70
	}
nkeynes@102
    71
	break;
nkeynes@102
    72
    case SYS_EXIT:
nkeynes@106
    73
	exit( sh4r.r[4] );
nkeynes@102
    74
    default:
nkeynes@102
    75
	sh4r.r[0] = -1;
nkeynes@102
    76
    }
nkeynes@102
    77
nkeynes@102
    78
}
nkeynes@102
    79
nkeynes@102
    80
void dcload_install() 
nkeynes@102
    81
{
nkeynes@102
    82
    syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
nkeynes@102
    83
    sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
nkeynes@102
    84
}
.