fps2bios: Remove fps2bios from master branch.

It's an abandoned project pretty much, if someone needs to go back and
take a look at it we have 1.4 branches and older.
This commit is contained in:
lightningterror 2019-11-16 22:06:46 +01:00
parent 89848346ae
commit dbfbc333f4
135 changed files with 1 additions and 20788 deletions

View File

@ -83,7 +83,6 @@ remove_3rdparty()
{
echo "Remove 3rdparty code"
rm -fr $LOCAL_REPO/3rdparty
rm -fr $LOCAL_REPO/fps2bios
rm -fr $LOCAL_REPO/tools
}
@ -100,7 +99,6 @@ remove_not_yet_free_plugin()
remove_remaining_non_free_file()
{
echo "Remove remaining non free file. TODO UPSTREAM"
rm -fr $LOCAL_REPO/unfree
rm -fr $LOCAL_REPO/plugins/GSdx/baseclasses
rm -f $LOCAL_REPO/plugins/zzogl-pg/opengl/Win32/aviUtil.h
rm -f $LOCAL_REPO/common/src/Utilities/x86/MemcpyFast.cpp

View File

@ -59,8 +59,7 @@ files=`git diff --name-only --diff-filter=ACMRT $diff_range -- $PWD | \
grep -v "bin/" | \
grep -v "cmake/" | \
grep -v "tools/" | \
grep -v "tests/" | \
grep -v "unfree/"
grep -v "tests/"
`
# Check remaining files are clang-format compliant

View File

@ -1,5 +0,0 @@
*.o
EXTINFO
ROMDIR
build
*.map

Binary file not shown.

View File

@ -1,27 +0,0 @@
@800
SYSMEM
LOADCORE
EXCEPMAN
INTRMAN
SSBUSC
DMACMAN
TIMRMAN
SYSCLIB
HEAPLIB
THREADMAN
VBLANK
IOMAN
MODLOAD
ROMDRV
STDIO
SIFMAN
IGREETING
SIFCMD
REBOOT
LOADFILE
CDVDMAN
CDVDFSV
SIFINIT
FILEIO
SECRMAN
EESYNC

View File

@ -1,44 +0,0 @@
VERSION = 0
BUILD = 1
CC = gcc
CFLAGS = -Wall -O2 -I.
DIRS = kernel intro loader
FILES = RESET ROMDIR ROMVER IOPBOOT EELOAD \
SYSMEM LOADCORE EXCEPMAN INTRMAN SSBUSC DMACMAN \
TIMRMAN SYSCLIB HEAPLIB THREADMAN VBLANK STDIO \
SIFMAN SIFCMD SIO2MAN LOADER INTRO IOPBTCONF FP2BLOGO
.PHONY: clean
build/fps2bios: build/ps2romgen_exe build/romdir_exe build/romver_exe | build
for i in $(DIRS); do \
make -C $$i; \
done;
cp -f FP2BLOGO build
cp -f IOPBTCONF build
(cd build; \
./romver_exe $(VERSION) $(BUILD); \
./romdir_exe $(FILES); \
./ps2romgen_exe fps2bios; \
cd ..)
build/ps2romgen_exe: ps2romgen.c | build
$(CC) $(CFLAGS) $< -o $@
build/romdir_exe: romdir.c | build
$(CC) $(CFLAGS) $< -o $@
build/romver_exe: romver.c | build
$(CC) $(CFLAGS) $< -o $@
build:
mkdir -p $@
clean:
rm -f -r *.o build
for i in $(DIRS); do \
make -C $$i clean; \
done;

View File

@ -1,5 +0,0 @@
# Free PS2 BIOS (fps2bios)
An open source (but "unfree" because of no licenses) and incomplete implementation of the PS2's boot ROM.
Requires latest PS2 toolchain from https://github.com/ps2dev/ps2toolchain
This, currently, does not work as a full replacement for the PS2's boot ROM.

View File

@ -1,199 +0,0 @@
This is a collection of notes which should help anyone looking at the PS2 BIOS. The goal is to fully document the public interface so that a free (GPL) replacement BIOS can be developed for use in emulators such as PCSX2. Where source code examples are given, these refer to the fps2bios source code and not to any original Sony code. The information contained in here has been collected from a number of sources but the main sources are the PCSX2 source code which documents the machine hardware and the open source ps2sdk found at ps2dev.org.
The PS2 BIOS is a collection of files packed into a single file. A file called ROMDIR contains the name and size of each file in the archive. The first file in the archive is called RESET and contains a minimal boot program. The ROMDIR structure is found by looking for the character sequence RESET from the start of the BIOS
# The boot process
The BIOS file is initialized to the memory address 0xBFC00000. The program counter is set to this address and execution started. This is true for both the EE and IOP and so the first few lines of code need to figure out which CPU is currently executing and branch to the relevant initialization code. This code is contained in kernel/start.c. The files kernel/eestart.c and kernel/iopstart.c contain the boot code for the EE and IOP respectively
# The IOP boot process
The IOP boot code is stored in kernel/iopstart.c. This locates the file IOPLOAD in the BIOS image and loads it to the memory address 0x80000000. It then executes the code at 0x80001000. The directory kernel/iopload contains all of the IOP releated BIOS code. Note the linkfile in this directory this is required to enforce the magic numbers described above. It makes sure that the iopirq.o object is linked at the address 0x80000000 and that iopload is linked starting at 0x80001000.
The boot code found at 0x80001000 is _start() located in iopload.c. This loads the SYSMEM file from the BIOS image and executes its defined entry point. The LOADCORE file is then loaded and its entry point executed. When the LOADCORE entry point returns, the IOP enters an endless loop waiting for an exception.
# IRX linking
The LOADCORE module is responsible mainly for managing the dynamic link relationship between IRX modules. An IRX module is a dynamically linked module it both exports and imports functions in addition to having an execution entry point. IRX dynamic linking is ordinal based rather than symbolic and, as the public interface is defined by the function export table, this makes figuring it out quite complex. Fortunately, some games have been distributed with debugging symbols and thus this allows us to associate symbolic names with the export ordinals.
The IRX export table is defined as follows:
```
struct irx_export_table {
u32 magic;
struct irx_export_table *next;
u16 version;
u16 mode;
u8 name[8];
void *fptrs[0];
};
```
Where magic is `0x41c00000` and fptrs is a list of exported functions terminated by a NULL entry.
The IRX import table definition is very similar.
```
struct irx_import_table
{
u32 magic;
struct irx_import_table *next;
u16 version;
u16 mode;
char name[8];
void *stubs[0];
}
```
The magic number for the import table is `0x41e00000` and in the same manner as the export table, the stubs list is NULL terminated. An IRX will contain an import table for each module (IRX) that it needs to link with.
To give a concrete example, an IRX that wants to import the `GetLibraryEntryTable` function from the LOADCORE module, could define the import table as follows:
```
loadcore_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "loadcore"
.align 2
.globl GetLibraryEntryTable # 0x03
GetLibraryEntryTable:
j $31
li $0, 3
.word 0
.word 0
```
The label `GetLibraryEntryTable` does not define the linkage itself this is done by the number (or ordinal) 3. The `li $0, 3` instruction defines that this entry should be linked to the 3rd function exported by the loadcore export table. The function of the LOADCORE module is to resolve the import stub functions with the export tables from the other IRX modules that have been previously registered. It does this by modifying the import table and changing the `j $31` to a `j imm` instruction where imm is the relative address of the exported function.
The LOADCORE code that actually does the linking is in `fix_imports()` and is shown below:
```
int fix_imports(struct import *imp, struct export *exp){
func *ef;
struct func_stub *fs;
int count=0;
for (ef=exp->func; *ef; ef++){
count++; //count number of exported functions
}
for (fs=imp->func; fs->jr_ra; fs++) {
int ordinal = fs->addiu0 & 0xFFFF;
if (ordinal < count) {
fs->jr_ra=(((u32)exp->func[ordinal]>>2) & 0x3FFFFFF) | INS_J;
} else {
fs->jr_ra=INS_JR_RA;
}
}
imp->flags |=FLAG_IMPORT_QUEUED;
return 0;
}
```
# Module loading
The first 2 modules loaded are SYSMEM and LOADCORE. After these have been successfully loaded, the remaining modules are loaded in the order specified in iopload.c. The IRX dynamic linking mechanism is very simple and does not account for forward references, so this list must be carefully ordered. Details of the individual modules follow.
# The Exception Manager (EXCEPMAN version 1.1)
The exception manager is the 3rd module loaded and as the name suggests is responsible for managing the exception handling code. It does not actually implement any of the exception routines but rather provides the plumbing to allow other modules to register exception handlers and to provide for exception handlers to be chained together in priority order.
The Exception Manager maintains an array of 16 pointers (one for each of the 16 possible exceptions) starting at address 0x0440. This address should be an implementation detail but it is used by some modules and so effectively is part of the public interface.
|Ordinal|Function Definition |
|-------|-----------------------------------------------------------------------------------------|
|`0x00` |`void _start()` |
|`0x01` |`int excepman_reinit()` |
|`0x02` |`int excepman_deinit()` |
|`0x03` |`void *GetExHandlersTable()` |
|`0x04` |`int RegisterExceptionHandler(int code, struct exHandler *handler)` |
|`0x05` |`int RegisterPriorityExceptionHandler(int code, int priority, struct exHandler *handler)`|
|`0x06` |`int RegisterDefaultExceptionHandler(struct exHandler *handler)` |
|`0x07` |`int ReleaseExceptionHandler(int code, struct exHandler *handler)` |
|`0x08` |`int ReleaseDefaultExceptionHandler(struct exHandler *handler)` |
# The Interrupt Manager (INTRMAN version 1.2)
The interrupt manager builds upon the services of the exception manager. Its main task is to service the interrupt exception and to call the correct interrupt service for the current interrupt. It installs an exception handler for exception code 0 (interrupt) and exception code 8 (syscall exception). It also deals with context switching of the stack which is used by the thread manager.
The interrupt table is located directly after the exception table (so starting at 0x0480) but I dont think this is important for the public interface.
|Ordinal|Function Definition |
|-------|---------------------------------------------------------------------------------|
|`0x00` |`void _start()` |
|`0x01` |`int intrmanDeinit()` |
|`0x02` | |
|`0x03` | |
|`0x04` |`int RegisterIntrHandler(int interrupt, int mode, intrh_func handler, void *arg)`|
|`0x05` |`int ReleaseIntrHandler(int interrupt)` |
|`0x06` |`int EnableIntr(int interrupt)` |
|`0x07` |`int DisableIntr(int interrupt, int *oldstat)` |
|`0x08` |`int CpuDisableIntr()` |
|`0x09` |`int CpuEnableIntr()` |
|`0x0A` |`void intrman_syscall_04()` |
|`0x0B` |`void intrman_syscall_08()` |
|`0x0C` |`int CpuGetICTRL()` |
|`0x0D` |`int CpuEnableICTRL()` |
|`0x0E` |`void intrman_syscall_0C()` |
|`0x0F` | |
|`0x10` | |
|`0x11` |`int CpuSuspendIntr(u32 *ictrl)` |
|`0x12` |`int CpuResumeIntr(u32 ictrl)` |
|`0x13` |`int CpuSuspendIntr(u32 *ictrl)` |
|`0x14` |`int CpuResumeIntr(u32 ictrl)` |
|`0x15` |`void intrman_syscall_10()` |
|`0x16` |`void intrman_syscall_14()` |
|`0x17` |`int QueryIntrContext()` |
|`0x18` |`int QueryIntrStack(int stack_pointer)` |
|`0x19` |`int iCatchMultiIntr()` |
|`0x1A` |`void retonly()` |
|`0x1B` | |
|`0x1C` |`void SetCtxSwitchHandler(func handler)` |
|`0x1D` |`func ResetCtxSwitchHandler()` |
|`0x1E` |`void SetCtxSwitchReqHandler(func handler)` |
|`0x1F` |`func ResetCtxSwitchReqHandler()` |
# Stack frame layout
The interrupt manager also handles the management of the stackframe when context switching between threads. The stack frame is a reserved area on the stack that is large enough to hold the entire processor state. This enables the processor state to be saved and restored between interrupts and context switches. For performance reasons, the entire state is not always stored an interrupt can define via the mode setting what processor registers it will not preserve and so need saving.
The stack frame contains a status field which defines how much of it is currently valid so that incremental saving and restoring from it can be achieved. In general, the layout of the stack frame could (and should) be considered as private to the interrupt manager. Given that it is exposed publicly though and the information is available to games, it is documented below.
|Offset|Stored value | | | | |
|------|----------------------|----------------------|----------------------|----------------------|------------|
|`0x00`|`FrameID` |`0xAC0000FE Mode = 0`|`0xFF00FFFE Mode = 1`|`0xFFFFFFFE Mode = 2`|`0xF0FF000C`|
|`0x04`|`AT ($1)` |x |x |x | |
|`0x08`|`V0 ($2)` |x |x |x |x |
|`0x0C`|`V1 ($3)` |x |x |x |x |
|`0x10`|`A0 ($4)` |x |x |x |x |
|`0x14`|`A1 ($5)` |x |x |x |x |
|`0x18`|`A2 ($6)` |x |x |x |x |
|`0x1C`|`A3 ($7)` |x |x |x |x |
|`0x20`|`T0 ($8)` | |x |x | |
|`0x24`|`T1 ($9)` | |x |x | |
|`0x28`|`T2 ($10)` | |x |x | |
|`0x2C`|`T3 ($11)` | |x |x | |
|`0x30`|`T4 ($12)` | |x |x | |
|`0x34`|`T5 ($13)` | |x |x | |
|`0x38`|`T6 ($14)` | |x |x | |
|`0x3C`|`T7 ($15)` | |x |x | |
|`0x40`|`S0 ($16)` | | |x | |
|`0x44`|`S1 ($17)` | | |x |x |
|`0x48`|`S2 ($18)` | | |x |x |
|`0x4C`|`S3 ($19)` | | |x |x |
|`0x50`|`S4 ($20)` | | |x |x |
|`0x54`|`S5 ($21)` | | |x |x |
|`0x58`|`S6 ($22)` | | |x |x |
|`0x5C`|`S7 ($23)` | | |x |x |
|`0x60`|`T8 ($24)` | |x |x | |
|`0x64`|`T9 ($25)` | |x |x | |
|`0x68`|`Unused (k0)` | | | | |
|`0x6C`|`Unused (k1)` | | | | |
|`0x70`|`GP` | |x |x | |
|`0x74`|`SP` |x |x |x |x |
|`0x78`|`FP` | |x |x |x |
|`0x7C`|`RA` |x |x |x |x |
|`0x80`|`HI` |x |x |x | |
|`0x84`|`LO` |x |x |x | |
|`0x88`|`COP0 STATUS` |x |x |x |x |
|`0x8C`|`EPC before exception`|x |x |x |x |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 KiB

View File

@ -1,23 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
INTRO_BIN = ../build/INTRO
EE_INCS += -Iinclude
EE_LIBS += -lmc -lpad -lc -lkernel -lm
EE_OBJS = intro.o eedebug.o crt0.o romdir.o
$(INTRO_BIN): $(EE_OBJS)
$(EE_CC) -nostartfiles -Tlinkfile $(EE_CFLAGS) \
-o $(INTRO_BIN) $(EE_OBJS) $(EE_LDFLAGS) $(EE_LIBS)
clean:
rm -f -r $(EE_OBJS) $(INTRO_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal

View File

@ -1,111 +0,0 @@
.set noat
.set noreorder
.global _start
.global FlushCache
.global Exit
.global SignalSema
.global _start
.global _exit
.text
nop
nop
FlushCache:
li $3,100
syscall
jr $31
nop
Exit:
li $3,4
syscall
jr $31
nop
SignalSema:
li $3,66
syscall
jr $31
nop
nop
nop
_start:
lui $2,%hi(_args_ptr)
addiu $2,$2, %lo(_args_ptr)
sw $4,($2)
# Clear bss
zerobss:
lui $2,%hi(_fbss)
lui $3,%hi(_end)
addiu $2,$2,%lo(_fbss)
addiu $3,$3,%lo(_end)
loop:
nop
nop
sq $0,($2)
sltu $1,$2,$3
bne $1,$0,loop
addiu $2,$2,16
# Thread
lui $4,%hi(_gp)
addiu $4,$4,%lo(_gp)
lui $5,%hi(_stack)
addiu $5,$5,%lo(_stack)
lui $6,%hi(_stack_size)
addiu $6,$6,%lo(_stack_size)
lui $7,%hi(_args)
addiu $7,$7,%lo(_args)
lui $8,%hi(_root)
addiu $8,$8,%lo(_root)
move $28,$4
addiu $3,$0,60
syscall
move $29, $2
# Heap
addiu $3,$0,61
lui $4,%hi(_end)
addiu $4,$4,%lo(_end)
lui $5,%hi(_heap_size)
addiu $5,$5,%lo(_heap_size)
syscall
nop
# Cache
jal FlushCache
move $4,$0
# Jump main
ei
lui $2,%hi(_args_ptr)
addiu $2,$2,%lo(_args_ptr)
lw $3,($2)
lui $2,%hi(_args)
addiu $2,$2,%lo(_args)
lw $4, ($2)
jal main
addiu $5, $2, 4
_root:
_exit:
# ???
# lui $2,%hi(_args_ptr)
# addiu $2,$2,%lo(_args_ptr)
# lw $3,($2)
# jal SignalSema
# lw $4,($3)
# Exit
# addiu $3,$0,35
# syscall
jr $31
nop
.bss
.align 6
_args: .space 256+16*4+4
.data
_args_ptr:
.space 4

View File

@ -1,31 +0,0 @@
#include <tamtypes.h>
#include <stdio.h>
#include <kernel.h>
void __putc(u8 c) {
while (*((u32*)0x1000f130) & 0x8000) { __asm__ ("nop\nnop\nnop\n"); }
*((u8*)0x1000f180) = c;
}
void __puts(u8 *s) {
while (*s != 0) {
__putc(*s++);
}
}
int __printf(const char *format, ...) {
char buf[4096];
va_list args;
int ret;
va_start(args, format);
ret = vsnprintf(buf, 4096, format, args);
va_end(args);
__puts((u8*)buf);
return ret;
}

View File

@ -1,12 +0,0 @@
#ifndef __EEDEBUG_H__
#define __EEDEBUG_H__
#include <tamtypes.h>
#include <kernel.h>
void __putc(u8 c);
void __puts(u8 *s);
int __printf(const char *format, ...);
#endif /* __EEDEBUG_H__ */

View File

@ -1,20 +0,0 @@
#ifndef __ROMDIR_H__
#define __ROMDIR_H__
#include <tamtypes.h>
struct romdir {
/*following variable must place in designed order*/
u8 fileName[10];
u16 extInfoSize;
u32 fileSize;
} __attribute__ ((packed));
struct rominfo {
u32 fileOffset;
u32 fileSize;
};
struct rominfo *romdirGetFile(char *name, struct rominfo *ri);
#endif /* __ROMDIR_H__ */

View File

@ -1,19 +0,0 @@
#include <tamtypes.h>
#include <stdio.h>
#include <kernel.h>
#include <math.h>
#include "eedebug.h"
#include "romdir.h"
int main() {
__printf("INTRO start\n");
__printf("INTRO end\n");
return 0;
}

View File

@ -1,52 +0,0 @@
_stack_size = 0x80000;
_heap_size = 1024*1024*10;
ENTRY(_start);
SECTIONS {
.text 0x00100008 : {
*(.text)
*(.rodata)
}
.reginfo ALIGN(128) : {
*(.reginfo)
}
.data ALIGN(128) : {
*(.data)
}
.rdata ALIGN(128) : {
*(.rdata)
}
_gp = ALIGN(128) + 0x7ff0;
.lit4 ALIGN(128) : {
*(.lit4)
}
.lit8 ALIGN(128) : {
*(.lit8)
}
.sdata ALIGN(128) : {
*(.sdata)
}
.sbss ALIGN(128) (NOLOAD) : { /* uninitialized data */
_fbss = . ;
*(.scommon)
*(.sbss)
}
.bss ALIGN(128) (NOLOAD) : { /* uninitialized data */
*(.bss)
}
.COMMON ALIGN(128) (NOLOAD) : { /* uninitialized data */
*(COMMON)
}
_end_bss = . - 4;
_stack = .;
. += _stack_size ;
_end_stack = . - 8*5;
_end = . ;
__lc_bh = . ;
. += _heap_size ;
__lc_eh = .;
}

View File

@ -1,43 +0,0 @@
/***************************************************************
* romdir.c, based over Alex Lau (http://alexlau.8k.com) RomDir *
****************************************************************/
#include "romdir.h"
struct romdir *romdirInit() {
u8 *mem;
for (mem=(u8*)0xbfc00000; (u32)mem<0xbfc01000; mem++) {
if (mem[0] == 'R' && mem[1] == 'E' &&
mem[2] == 'S' && mem[3] == 'E' &&
mem[4] == 'T')
break;
}
if ((u32)mem == 0xbfc01000) return NULL;
return (struct romdir*)mem;
}
struct rominfo *romdirGetFile(char *name, struct rominfo *ri) {
struct romdir *rd;
struct romdir *base;
int i;
base = romdirInit();
if (base == NULL) return NULL;
ri->fileOffset = 0;
for (rd = base; rd->fileName[0] != 0; rd++) {
for (i=0; i<10 && name[i] != 0; i++) {
if (rd->fileName[i] != name[i]) break;
}
if (rd->fileName[i] != name[i]) {
ri->fileOffset+= (rd->fileSize + 15) & ~0xF;
continue;
}
ri->fileSize = rd->fileSize;
return ri;
}
return NULL;
}

View File

@ -1,39 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
DIRS = eeload iopload
RESET_BIN = ../build/RESET
EE_INCS += -Iinclude
EE_OBJS = eestart.ee.o
IOP_OBJS = iopstart.iop.o romdir.iop.o start.iop.o
all: $(RESET_BIN)
for i in $(DIRS); do \
make -C $$i; \
done;
$(RESET_BIN): $(EE_OBJS) $(IOP_OBJS)
$(EE_CC) -Wl,--oformat,binary -Tlinkfile -nostartfiles $(EE_CFLAGS) \
-o $(RESET_BIN) $(EE_OBJS) $(IOP_OBJS) $(EE_LDFLAGS) $(EE_LIBS)
%.ee.o: %.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
%.iop.o: %.c
$(IOP_CC) $(IOP_CFLAGS) -c $< -o $@
clean:
for i in $(DIRS); do \
make -C $$i clean; \
done;
rm -f -r $(RESET_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,27 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
EELOAD_BIN = ../../build/EELOAD
EE_INCS += -Iinclude
EE_LIBS += -lmc -lpad -lc -lkernel
EE_OBJS = eeirq.o eedata.o eekernel.o eeinit.o eeload.o eeelf.o eedebug.o romdir.o
$(EELOAD_BIN): $(EE_OBJS) $(PS2SDK)/ee/startup/crt0.o
$(EE_CC) -nostartfiles -Wl,--oformat,binary,--Map,eeload.map -Tlinkfile $(EE_CFLAGS) \
-o $(EELOAD_BIN) $(EE_OBJS) $(EE_LDFLAGS) $(EE_LIBS)
# restrict all but the kernel registers
eeirq.o: eeirq.c
$(EE_C_COMPILE) -ffixed-2 -ffixed-3 -ffixed-4 -ffixed-5 -ffixed-6 -ffixed-7 -ffixed-8 -ffixed-9 -ffixed-10 -ffixed-11 -ffixed-12 -ffixed-13 -ffixed-14 -ffixed-15 -ffixed-16 -ffixed-17 -ffixed-18 -ffixed-19 -ffixed-20 -ffixed-21 -ffixed-22 -ffixed-23 -ffixed-24 -ffixed-25 -fcall-used-26 -fcall-used-27 -ffixed-30 $< -c -o $@
clean:
rm -f -r $(EELOAD_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal

View File

@ -1,198 +0,0 @@
// eedata.c - needed in order to assure
// that some of the kernel variables are as close to 0x80000000 as possible
// (ie, look in saveContext2)
//[made by] [RO]man, zerofrog
#include <tamtypes.h>
#include <kernel.h>
#include <stdio.h>
#include "eekernel.h"
#include "eeirq.h"
eeRegs SavedRegs __attribute((aligned(256)));
u128 SavedSP __attribute((aligned(16)));
u128 SavedRA __attribute((aligned(16)));
u128 SavedAT __attribute((aligned(16)));
u64 SavedT9 __attribute((aligned(16)));
u32 _CpuConfig_0(u32);
u32 _CpuConfig_1(u32);
u32 _CpuConfig_2(u32);
u32 _CpuConfig_3(u32);
u32 _CpuConfig_4(u32);
u32 _CpuConfig_5(u32);
u32 (*table_CpuConfig[6])(u32) = {_CpuConfig_0, _CpuConfig_1, _CpuConfig_2,
_CpuConfig_3, _CpuConfig_4, _CpuConfig_5};
u32 dmac_CHCR[10] = {
0xB0008000,
0xB0009000,
0xB000A000,
0xB000B000,
0xB000B400,
0xB000C000,
0xB000C400,
0xB000C800,
0xB000D000,
0xB000D400,
};
void (*VCRTable[14])() = {
0, 0, 0, 0,
0, 0, 0, 0,
SyscException, 0, 0, 0,
0, 0
};
void (*VIntTable[8])() = {
0, 0, DMACException, INTCException,
0, 0, 0, TIMERException,
};
void _DummyINTCHandler(int);
void _DummyDMACHandler(int);
void (*INTCTable[16])(int) = {
_DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler,
_DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler,
_DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler,
_DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler, _DummyINTCHandler };
void (*DMACTable[16])(int) = {
_DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler,
_DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler,
_DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler,
_DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler, _DummyDMACHandler };
void (*table_SYSCALL[0x80])() = {
(void (*))_RFU___, // 0x00
(void (*))_ResetEE,
(void (*))_SetGsCrt,
(void (*))_RFU___,
(void (*))_Exit, // 0x04
(void (*))_RFU005,
(void (*))_LoadPS2Exe,
(void (*))_ExecPS2,
(void (*))_RFU___, // 0x08
(void (*))_TlbWriteRandom,
(void (*))_AddSbusIntcHandler,
(void (*))_RemoveSbusIntcHandler,
(void (*))_Interrupt2Iop, // 0x0C
(void (*))_SetVTLBRefillHandler,
(void (*))_SetVCommonHandler,
(void (*))_SetVInterruptHandler,
(void (*))_AddIntcHandler, // 0x10
(void (*))_RemoveIntcHandler,
(void (*))_AddDmacHandler,
(void (*))_RemoveDmacHandler,
(void (*))__EnableIntc, // 0x14
(void (*))__DisableIntc,
(void (*))__EnableDmac,
(void (*))__DisableDmac,
(void (*))_SetAlarm, // 0x18
(void (*))_ReleaseAlarm,
(void (*))__EnableIntc,
(void (*))__DisableIntc,
(void (*))__EnableDmac, // 0x1C
(void (*))__DisableDmac,
(void (*))_SetAlarm,
(void (*))_ReleaseAlarm,
(void (*))_CreateThread, // 0x20
(void (*))_DeleteThread,
(void (*))_StartThread,
(void (*))_ExitThread,
(void (*))_ExitDeleteThread, // 0x24
(void (*))_TerminateThread,
(void (*))_iTerminateThread,
(void (*))_DisableDispatchThread,
(void (*))_EnableDispatchThread, // 0x28
(void (*))_ChangeThreadPriority,
(void (*))_iChangeThreadPriority,
(void (*))_RotateThreadReadyQueue,
(void (*))_iRotateThreadReadyQueue, // 0x2C
(void (*))_ReleaseWaitThread,
(void (*))_iReleaseWaitThread,
(void (*))_GetThreadId,
(void (*))_ReferThreadStatus, // 0x30
(void (*))_ReferThreadStatus,
(void (*))_SleepThread,
(void (*))_WakeupThread,
(void (*))_iWakeupThread,
(void (*))_CancelWakeupThread,
(void (*))_CancelWakeupThread,
(void (*))_SuspendThread,
(void (*))_SuspendThread,
(void (*))_ResumeThread,
(void (*))_iResumeThread,
(void (*))_JoinThread,
(void (*))_InitializeMainThread,
(void (*))_InitializeHeapArea,
(void (*))_EndOfHeap,
(void (*))_RFU___,
(void (*))_CreateSema, // 0x40
(void (*))_DeleteSema,
(void (*))_SignalSema,
(void (*))_iSignalSema,
(void (*))_WaitSema,
(void (*))_PollSema,
(void (*))_PollSema,
(void (*))_ReferSemaStatus,
(void (*))_ReferSemaStatus,
(void (*))_iDeleteSema,
(void (*))_SetOsdConfigParam,
(void (*))_GetOsdConfigParam,
(void (*))_GetGsHParam,
(void (*))_GetGsVParam,
(void (*))_SetGsHParam,
(void (*))_SetGsVParam,
(void (*))_CreateEventFlag, // 0x50
(void (*))_DeleteEventFlag,
(void (*))_SetEventFlag,
(void (*))_iSetEventFlag,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_RFU___,
(void (*))_EnableIntcHandler,
(void (*))_DisableIntcHandler,
(void (*))_EnableDmacHandler,
(void (*))_DisableDmacHandler,
(void (*))_KSeg0, // 0x60
(void (*))_EnableCache,
(void (*))_DisableCache,
(void (*))_GetCop0,
(void (*))_FlushCache,
(void (*))_105,
(void (*))_CpuConfig,
(void (*))_GetCop0,
(void (*))_FlushCache,
(void (*))_105,
(void (*))_CpuConfig,
(void (*))_SifStopDma, //_sceSifStopDma,
(void (*))_SetCPUTimerHandler,
(void (*))_SetCPUTimer,
(void (*))0,//_SetOsdConfigParam2,
(void (*))0,//_GetOsdConfigParam2,
(void (*))_GsGetIMR, // 0x70
(void (*))_GsPutIMR,
(void (*))_SetPgifHandler,
(void (*))_SetVSyncFlag,
(void (*))_SetSYSCALL,
(void (*))_print,
(void (*))_SifDmaStat,
(void (*))_SifSetDma,
(void (*))_SifSetDChain,
(void (*))_SifSetReg,
(void (*))_SifGetReg,
(void (*))_ExecOSD,
(void (*))_RFU___,
(void (*))_PSMode,
(void (*))_MachineType,
(void (*))_GetMemorySize
};

View File

@ -1,31 +0,0 @@
#include <tamtypes.h>
#include <stdio.h>
#include <kernel.h>
void __putc(u8 c) {
while (*((u32*)0x1000f130) & 0x8000) { __asm__ ("nop\nnop\nnop\n"); }
*((u8*)0x1000f180) = c;
}
void __puts(u8 *s) {
while (*s != 0) {
__putc(*s++);
}
}
int __printf(const char *format, ...) {
char buf[4096];
va_list args;
int ret;
va_start(args, format);
ret = vsnprintf(buf, 4096, format, args);
va_end(args);
__puts(buf);
return ret;
}

View File

@ -1,423 +0,0 @@
#include "romdir.h"
#include "eedebug.h"
typedef struct {
u8 e_ident[16]; //0x7f,"ELF" (ELF file identifier)
u16 e_type; //ELF type: 0=NONE, 1=REL, 2=EXEC, 3=SHARED, 4=CORE
u16 e_machine; //Processor: 8=MIPS R3000
u32 e_version; //Version: 1=current
u32 e_entry; //Entry point address
u32 e_phoff; //Start of program headers (offset from file start)
u32 e_shoff; //Start of section headers (offset from file start)
u32 e_flags; //Processor specific flags = 0x20924001 noreorder, mips
u16 e_ehsize; //ELF header size (0x34 = 52 bytes)
u16 e_phentsize; //Program headers entry size
u16 e_phnum; //Number of program headers
u16 e_shentsize; //Section headers entry size
u16 e_shnum; //Number of section headers
u16 e_shstrndx; //Section header stringtable index
} ELF_HEADER;
typedef struct {
u32 p_type; //see notes1
u32 p_offset; //Offset from file start to program segment.
u32 p_vaddr; //Virtual address of the segment
u32 p_paddr; //Physical address of the segment
u32 p_filesz; //Number of bytes in the file image of the segment
u32 p_memsz; //Number of bytes in the memory image of the segment
u32 p_flags; //Flags for segment
u32 p_align; //Alignment. The address of 0x08 and 0x0C must fit this alignment. 0=no alignment
} ELF_PHR;
/*
notes1
------
0=Inactive
1=Load the segment into memory, no. of bytes specified by 0x10 and 0x14
2=Dynamic linking
3=Interpreter. The array element must specify a path name
4=Note. The array element must specify the location and size of aux. info
5=reserved
6=The array element must specify location and size of the program header table.
*/
typedef struct {
u32 sh_name; //No. to the index of the Section header stringtable index
u32 sh_type; //See notes2
u32 sh_flags; //see notes3
u32 sh_addr; //Section start address
u32 sh_offset; //Offset from start of file to section
u32 sh_size; //Size of section
u32 sh_link; //Section header table index link
u32 sh_info; //Info
u32 sh_addralign; //Alignment. The adress of 0x0C must fit this alignment. 0=no alignment.
u32 sh_entsize; //Fixed size entries.
} ELF_SHR;
/*
notes 2
-------
Type:
0=Inactive
1=PROGBITS
2=SYMTAB symbol table
3=STRTAB string table
4=RELA relocation entries
5=HASH hash table
6=DYNAMIC dynamic linking information
7=NOTE
8=NOBITS
9=REL relocation entries
10=SHLIB
0x70000000=LOPROC processor specifc
0x7fffffff=HIPROC
0x80000000=LOUSER lower bound
0xffffffff=HIUSER upper bound
notes 3
-------
Section Flags: (1 bit, you may combine them like 3 = alloc & write permission)
1=Write section contains data the is be writeable during execution.
2=Alloc section occupies memory during execution
4=Exec section contains executable instructions
0xf0000000=Mask bits processor-specific
*/
typedef struct {
u32 st_name;
u32 st_value;
u32 st_size;
u8 st_info;
u8 st_other;
u16 st_shndx;
} Elf32_Sym;
#define ELF32_ST_TYPE(i) ((i)&0xf)
typedef struct {
u32 r_offset;
u32 r_info;
} Elf32_Rel;
char *sections_names;
ELF_HEADER *elfHeader;
ELF_PHR *elfProgH;
ELF_SHR *elfSectH;
u8 *elfdata;
int elfsize;
static void __memcpy(void *dest, const void *src, int n) {
const u8 *s = (u8*)src;
u8 *d = (u8*)dest;
while (n) {
*d++ = *s++; n--;
}
}
int loadHeaders() {
elfHeader = (ELF_HEADER*)elfdata;
if ((elfHeader->e_shentsize != sizeof(ELF_SHR)) && (elfHeader->e_shnum > 0)) {
return -1;
}
#ifdef ELF_LOG
ELF_LOG( "type: " );
#endif
switch( elfHeader->e_type )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown %x", elfHeader->e_type );
#endif
break;
case 0x0:
#ifdef ELF_LOG
ELF_LOG( "no file type" );
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG( "relocatable" );
#endif
break;
case 0x2:
#ifdef ELF_LOG
ELF_LOG( "executable" );
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG( "\n" );
ELF_LOG( "machine: " );
#endif
switch ( elfHeader->e_machine )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown" );
#endif
break;
case 0x8:
#ifdef ELF_LOG
ELF_LOG( "mips_rs3000" );
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("version: %d\n",elfHeader->e_version);
ELF_LOG("entry: %08x\n",elfHeader->e_entry);
ELF_LOG("flags: %08x\n",elfHeader->e_flags);
ELF_LOG("eh size: %08x\n",elfHeader->e_ehsize);
ELF_LOG("ph off: %08x\n",elfHeader->e_phoff);
ELF_LOG("ph entsiz: %08x\n",elfHeader->e_phentsize);
ELF_LOG("ph num: %08x\n",elfHeader->e_phnum);
ELF_LOG("sh off: %08x\n",elfHeader->e_shoff);
ELF_LOG("sh entsiz: %08x\n",elfHeader->e_shentsize);
ELF_LOG("sh num: %08x\n",elfHeader->e_shnum);
ELF_LOG("sh strndx: %08x\n",elfHeader->e_shstrndx);
ELF_LOG("\n");
#endif
return 0;
}
int loadProgramHeaders() {
int i;
if (elfHeader->e_phnum == 0) {
return 0;
}
if (elfHeader->e_phentsize != sizeof(ELF_PHR)) {
return -1;
}
elfProgH = (ELF_PHR*)&elfdata[elfHeader->e_phoff];
for ( i = 0 ; i < elfHeader->e_phnum ; i++ )
{
#ifdef ELF_LOG
ELF_LOG( "Elf32 Program Header\n" );
ELF_LOG( "type: " );
#endif
switch ( elfProgH[ i ].p_type )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown %x", (int)elfProgH[ i ].p_type );
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG("load");
#endif
/* if ( elfHeader->e_shnum == 0 ) {*/
if (elfProgH[ i ].p_offset < elfsize) {
int size;
if ((elfProgH[ i ].p_filesz + elfProgH[ i ].p_offset) > elfsize) {
size = elfsize - elfProgH[ i ].p_offset;
} else {
size = elfProgH[ i ].p_filesz;
}
// __printf("loading program to %x\n", elfProgH[ i ].p_paddr + elfbase);
__memcpy(elfProgH[ i ].p_paddr,
&elfdata[elfProgH[ i ].p_offset],
size);
}
#ifdef ELF_LOG
ELF_LOG("\t*LOADED*");
#endif
// }
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("offset: %08x\n",(int)elfProgH[i].p_offset);
ELF_LOG("vaddr: %08x\n",(int)elfProgH[i].p_vaddr);
ELF_LOG("paddr: %08x\n",elfProgH[i].p_paddr);
ELF_LOG("file size: %08x\n",elfProgH[i].p_filesz);
ELF_LOG("mem size: %08x\n",elfProgH[i].p_memsz);
ELF_LOG("flags: %08x\n",elfProgH[i].p_flags);
ELF_LOG("palign: %08x\n",elfProgH[i].p_align);
ELF_LOG("\n");
#endif
}
return 0;
}
int loadSectionHeaders() {
int i;
int i_st = -1;
int i_dt = -1;
if (elfHeader->e_shnum == 0) {
return -1;
}
elfSectH = (ELF_SHR*)&elfdata[elfHeader->e_shoff];
if ( elfHeader->e_shstrndx < elfHeader->e_shnum ) {
sections_names = (char *)&elfdata[elfSectH[ elfHeader->e_shstrndx ].sh_offset];
}
for ( i = 0 ; i < elfHeader->e_shnum ; i++ )
{
#ifdef ELF_LOG
ELF_LOG( "Elf32 Section Header [%x] %s", i, &sections_names[ elfSectH[ i ].sh_name ] );
#endif
/* if ( elfSectH[i].sh_flags & 0x2 ) {
if (elfSectH[i].sh_offset < elfsize) {
int size;
if ((elfSectH[i].sh_size + elfSectH[i].sh_offset) > elfsize) {
size = elfsize - elfSectH[i].sh_offset;
} else {
size = elfSectH[i].sh_size;
}
memcpy(&psM[ elfSectH[ i ].sh_addr &0x1ffffff ],
&elfdata[elfSectH[i].sh_offset],
size);
}
#ifdef ELF_LOG
ELF_LOG( "\t*LOADED*" );
#endif
}*/
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("type: ");
#endif
switch ( elfSectH[ i ].sh_type )
{
default:
#ifdef ELF_LOG
ELF_LOG("unknown %08x",elfSectH[i].sh_type);
#endif
break;
case 0x0:
#ifdef ELF_LOG
ELF_LOG("null");
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG("progbits");
#endif
break;
case 0x2:
#ifdef ELF_LOG
ELF_LOG("symtab");
#endif
break;
case 0x3:
#ifdef ELF_LOG
ELF_LOG("strtab");
#endif
break;
case 0x4:
#ifdef ELF_LOG
ELF_LOG("rela");
#endif
break;
case 0x8:
#ifdef ELF_LOG
ELF_LOG("no bits");
#endif
break;
case 0x9:
#ifdef ELF_LOG
ELF_LOG("rel");
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("flags: %08x\n", elfSectH[i].sh_flags);
ELF_LOG("addr: %08x\n", elfSectH[i].sh_addr);
ELF_LOG("offset: %08x\n", elfSectH[i].sh_offset);
ELF_LOG("size: %08x\n", elfSectH[i].sh_size);
ELF_LOG("link: %08x\n", elfSectH[i].sh_link);
ELF_LOG("info: %08x\n", elfSectH[i].sh_info);
ELF_LOG("addralign: %08x\n", elfSectH[i].sh_addralign);
ELF_LOG("entsize: %08x\n", elfSectH[i].sh_entsize);
#endif
// dump symbol table
if (elfSectH[i].sh_type == 0x02) {
i_st = i; i_dt = elfSectH[i].sh_link;
}
/*
if (elfSectH[i].sh_type == 0x01) {
int size = elfSectH[i].sh_size / 4;
u32 *ptr = (u32*)&psxM[(elfSectH[i].sh_addr + irx_addr) & 0x1fffff];
while (size) {
if (*ptr == 0x41e00000) { // import func
int ret = iopSetImportFunc(ptr+1);
size-= ret; ptr+= ret;
}
if (*ptr == 0x41c00000) { // export func
int ret = iopSetExportFunc(ptr+1);
size-= ret; ptr+= ret;
}
size--; ptr++;
}
}
*/
/* if (!strcmp(".data", &sections_names[elfSectH[i].sh_name])) {
// seems so..
psxRegs.GPR.n.gp = 0x8000 + irx_addr + elfSectH[i].sh_addr;
}*/
}
return 0;
}
u32 loadElfFile(char *filename, struct elfinfo *info) {
struct rominfo ri;
char str[256];
char str2[256];
int i;
__printf("loadElfFile: %s\n", filename);
if (romdirGetFile(filename, &ri) == NULL) {
__printf("file %s not found!!\n", filename);
return -1;
}
elfdata = (u8*)(0xbfc00000 + ri.fileOffset);
elfsize = ri.fileSize;
loadHeaders();
loadProgramHeaders();
loadSectionHeaders();
// __printf("loadElfFile: e_entry=%x\n", elfHeader->e_entry);
return elfHeader->e_entry;
}

View File

@ -1,511 +0,0 @@
// EE initialization functions
// [made by] [RO]man, zerofrog
#include <tamtypes.h>
#include <stdio.h>
#include "eekernel.h"
#include "eeirq.h"
void InitializeGS();
void InitializeGIF();
void InitializeDMAC(int code);
void InitializeVU1();
void InitializeVIF1();
void InitializeIPU();
void InitializeVIF0();
void InitializeVU0();
void InitializeFPU();
void InitializeScratchPad();
void InitializeUserMemory(u32 base);
void InitializeINTC(int a);
void InitializeTIMER();
////////////////////////////////////////////////////////////////////
//8000AA60
////////////////////////////////////////////////////////////////////
void InitializeGS()
{
}
////////////////////////////////////////////////////////////////////
//8000AB98
////////////////////////////////////////////////////////////////////
void InitializeGIF()
{
GIF_CTRL = 1;
__asm__ ("sync\n");
GIF_FIFO = 0;
}
////////////////////////////////////////////////////////////////////
//8000AD68 SYSCALL 001 ResetEE
////////////////////////////////////////////////////////////////////
int _ResetEE(int init)
{
if (init & 0x01) { __printf("# Initialize DMAC ...\n"); InitializeDMAC(0x31F); }
if (init & 0x02) { __printf("# Initialize VU1 ...\n"); InitializeVU1(); }
if (init & 0x04) { __printf("# Initialize VIF1 ...\n"); InitializeVIF1(); }
if (init & 0x08) { __printf("# Initialize GIF ...\n"); InitializeGIF(); }
if (init & 0x10) { __printf("# Initialize VU0 ...\n"); InitializeVU0(); }
if (init & 0x04) { __printf("# Initialize VIF0 ...\n"); InitializeVIF0(); }
if (init & 0x40) { __printf("# Initialize IPU ...\n"); InitializeIPU(); }
InitializeINTC(0xC);
// return (*(int*)0x1000F410 &= 0xFFFBFFFF); code never reached :)
}
////////////////////////////////////////////////////////////////////
//8000AE88
////////////////////////////////////////////////////////////////////
int Initialize()
{
__printf("# Initialize Start.\n");
__printf("# Initialize GS ...");
InitializeGS();
_SetGsCrt(1, 2, 1);
__printf("\n");
__printf("# Initialize INTC ...\n");
InitializeINTC(0xFFFF);
__printf("# Initialize TIMER ...\n");
InitializeTIMER();
ResetEE(0x7F);
__printf("# Initialize FPU ...\n");
InitializeFPU();
__printf("# Initialize User Memory ...\n");
InitializeUserMemory(0x80000);
__printf("# Initialize Scratch Pad ...\n");
InitializeScratchPad();
__printf("# Initialize Done.\n");
}
////////////////////////////////////////////////////////////////////
//8000AF50
////////////////////////////////////////////////////////////////////
int Restart()
{
__printf("# Restart.\n");
__printf("# Initialize GS ...");
INTC_STAT = 4;
while (INTC_STAT & 4) { __asm__ ("nop\nnop\nnop\n"); }
INTC_STAT = 4;
InitializeGS();
_SetGsCrt(1, 2, 1);
__printf("\n");
__printf("# Initialize INTC ...\n");
InitializeINTC(0xDFFD);
__printf("# Initialize TIMER ...\n");
InitializeTIMER();
ResetEE(0x7F);
__printf("# Initialize FPU ...\n");
InitializeFPU();
__printf("# Initialize User Memory ...\n");
InitializeUserMemory(0x82000);
__printf("# Initialize Scratch Pad ...\n");
InitializeScratchPad();
__printf("# Restart Done.\n");
//wait for syncing IOP
while (SBUS_SMFLG & SBFLG_IOPSYNC) { __asm__ ("nop\nnop\nnop\n"); }
SBUS_SMFLG=SBFLG_IOPSYNC;
}
////////////////////////////////////////////////////////////////////
//8000B0A0
////////////////////////////////////////////////////////////////////
void InitializeDMAC(int code)
{
int i;
int *addr;
for (i=0; i<10; i++) {
if (!(code & (1<<i))) continue;
addr = (int*)dmac_CHCR[i];
addr[0x80/4] = 0;
addr[0x00/4] = 0;
addr[0x30/4] = 0;
addr[0x10/4] = 0;
addr[0x50/4] = 0;
addr[0x40/4] = 0;
}
DMAC_STAT = (code & 0xFFFF) | 0xE000;
DMAC_STAT = (DMAC_STAT & 0xFFFF0000) & ((code | 0x6000) << 16);
if ((code & 0x7F) == 0x7F) {
DMAC_CTRL = 0;
DMAC_PCR = 0;
} else {
DMAC_CTRL = 0;
DMAC_PCR = DMAC_PCR & (((~code) << 16) | (~code));
}
DMAC_SQWC = 0;
DMAC_RBSR = 0;
DMAC_RBOR = 0;
}
////////////////////////////////////////////////////////////////////
//8000B1F0
////////////////////////////////////////////////////////////////////
void InitializeVU1()
{
}
////////////////////////////////////////////////////////////////////
//8000B2D8
////////////////////////////////////////////////////////////////////
void InitializeVIF1()
{
}
////////////////////////////////////////////////////////////////////
//8000B3B0
////////////////////////////////////////////////////////////////////
void InitializeIPU()
{
}
////////////////////////////////////////////////////////////////////
//8000B6F8
////////////////////////////////////////////////////////////////////
void InitializeVIF0()
{
}
////////////////////////////////////////////////////////////////////
//8000B778
////////////////////////////////////////////////////////////////////
void InitializeVU0()
{
}
////////////////////////////////////////////////////////////////////
//8000B7A8
////////////////////////////////////////////////////////////////////
void InitializeFPU()
{
__asm__ (
"mtc1 $0, $0\n"
"mtc1 $0, $1\n"
"mtc1 $0, $2\n"
"mtc1 $0, $3\n"
"mtc1 $0, $4\n"
"mtc1 $0, $5\n"
"mtc1 $0, $6\n"
"mtc1 $0, $7\n"
"mtc1 $0, $8\n"
"mtc1 $0, $9\n"
"mtc1 $0, $10\n"
"mtc1 $0, $11\n"
"mtc1 $0, $12\n"
"mtc1 $0, $13\n"
"mtc1 $0, $14\n"
"mtc1 $0, $15\n"
"mtc1 $0, $16\n"
"mtc1 $0, $17\n"
"mtc1 $0, $18\n"
"mtc1 $0, $19\n"
"mtc1 $0, $20\n"
"mtc1 $0, $21\n"
"mtc1 $0, $22\n"
"mtc1 $0, $23\n"
"mtc1 $0, $24\n"
"mtc1 $0, $25\n"
"mtc1 $0, $26\n"
"mtc1 $0, $27\n"
"mtc1 $0, $28\n"
"mtc1 $0, $29\n"
"mtc1 $0, $30\n"
"mtc1 $0, $31\n"
"adda.s $f0, $f1\n"
"sync\n"
"ctc1 $0, $31\n"
);
}
////////////////////////////////////////////////////////////////////
//8000B840
////////////////////////////////////////////////////////////////////
void InitializeScratchPad()
{
u128 *p;
for (p=(u128*)0x70000000; (u32)p<0x70004000; p++) *p=0;
}
////////////////////////////////////////////////////////////////////
//8000B878
////////////////////////////////////////////////////////////////////
void InitializeUserMemory(u32 base)
{
u128 *memsz;
u128 *p = (u128*)base;
for (memsz=(u128*)_GetMemorySize(); p<memsz; p++)
*p = 0;
}
////////////////////////////////////////////////////////////////////
//8000B8D0
////////////////////////////////////////////////////////////////////
void InitializeINTC(int a)
{
a &= 0xDFFD;
INTC_STAT &= a;
INTC_MASK &= a;
}
////////////////////////////////////////////////////////////////////
//8000B900
////////////////////////////////////////////////////////////////////
void InitializeTIMER()
{
RCNT0_MODE = 0xC00;
RCNT0_COUNT = 0;
RCNT0_TARGET = 0xFFFF;
RCNT0_HOLD = 0;
RCNT1_MODE = 0xC00;
RCNT1_COUNT = 0;
RCNT1_TARGET = 0xFFFF;
RCNT1_HOLD = 0;
RCNT2_MODE = 0xC80;
RCNT2_COUNT = 0;
RCNT2_TARGET = 0xFFFF;
RCNT3_MODE = 0xC83;
RCNT3_COUNT = 0;
RCNT3_TARGET = 0xFFFF;
InitializeINTC(0x1E00);
_InitRCNT3();
}
u32 tlb1_data[] = {
0x00000000, 0x70000000, 0x80000007, 0x00000007,
0x00006000, 0xFFFF8000, 0x00001E1F, 0x00001F1F,
0x00000000, 0x10000000, 0x00400017, 0x00400053,
0x00000000, 0x10002000, 0x00400097, 0x004000D7,
0x00000000, 0x10004000, 0x00400117, 0x00400157,
0x00000000, 0x10006000, 0x00400197, 0x004001D7,
0x00000000, 0x10008000, 0x00400217, 0x00400257,
0x00000000, 0x1000A000, 0x00400297, 0x004002D7,
0x00000000, 0x1000C000, 0x00400313, 0x00400357,
0x00000000, 0x1000E000, 0x00400397, 0x004003D7,
0x0001E000, 0x11000000, 0x00440017, 0x00440415,
0x0001E000, 0x12000000, 0x00480017, 0x00480415,
0x01FFE000, 0x1E000000, 0x00780017, 0x007C0017,
};
u32 tlb2_data[] = {
0x0007E000, 0x00080000, 0x0000201F, 0x0000301F,
0x0007E000, 0x00100000, 0x0000401F, 0x0000501F,
0x0007E000, 0x00180000, 0x0000601F, 0x0000701F,
0x001FE000, 0x00200000, 0x0000801F, 0x0000C01F,
0x001FE000, 0x00400000, 0x0001001F, 0x0001401F,
0x001FE000, 0x00600000, 0x0001801F, 0x0001C01F,
0x007FE000, 0x00800000, 0x0002001F, 0x0003001F,
0x007FE000, 0x01000000, 0x0004001F, 0x0005001F,
0x007FE000, 0x01800000, 0x0006001F, 0x0007001F,
0x0007E000, 0x20080000, 0x00002017, 0x00003017,
0x0007E000, 0x20100000, 0x00004017, 0x00005017,
0x0007E000, 0x20180000, 0x00006017, 0x00007017,
0x001FE000, 0x20200000, 0x00008017, 0x0000C017,
0x001FE000, 0x20400000, 0x00010017, 0x00014017,
0x001FE000, 0x20600000, 0x00018017, 0x0001C017,
0x007FE000, 0x20800000, 0x00020017, 0x00030017,
0x007FE000, 0x21000000, 0x00040017, 0x00050017,
0x007FE000, 0x21800000, 0x00060017, 0x00070017,
};
u32 tlb3_data[] = {
0x0007E000, 0x30100000, 0x0000403F, 0x0000503F,
0x0007E000, 0x30180000, 0x0000603F, 0x0000703F,
0x001FE000, 0x30200000, 0x0000803F, 0x0000C03F,
0x001FE000, 0x30400000, 0x0001003F, 0x0001403F,
0x001FE000, 0x30600000, 0x0001803F, 0x0001C03F,
0x007FE000, 0x30800000, 0x0002003F, 0x0003003F,
0x007FE000, 0x31000000, 0x0004003F, 0x0005003F,
0x007FE000, 0x31800000, 0x0006003F, 0x0007003F,
};
u32 tlb_config[] = {
0xD, 0x12, 8, 0,
0x80012708, 0x800127D8, 0x800128F8
};
void _TlbSet(u32 Index, u32 PageMask, u32 EntryHi, u32 EntryLo0, u32 EntryLo1) {
__asm__ (
"mtc0 $4, $0\n"
"mtc0 $5, $5\n"
"mtc0 $6, $10\n"
"mtc0 $7, $2\n"
"mtc0 $8, $3\n"
"sync\n"
"tlbwi\n"
"sync\n"
);
}
void TlbInit() {
int i, last;
u32 *ptr;
__printf("TlbInit... ");
__asm__ ("mtc0 $0, $6\n");
_TlbSet(1, 0, 0xE0000000, 0, 0);
for (i=2; i<48; i++) {
_TlbSet(i, 0, 0xE0002000, 0, 0);
}
last = tlb_config[0];
if (last > 48) {
__printf("# TLB over flow (1)\n");
}
ptr = (u32*)(tlb_config[4] + 0x10);
for (i=1; i<last; i++, ptr+= 4) {
_TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
}
last = tlb_config[1] + i;
if (last > 48) {
__printf("# TLB over flow (2)\n");
}
if (tlb_config[1]) {
ptr = (u32*)(tlb_config[5]);
for (; i<last; i++, ptr+= 4) {
_TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
}
}
__asm__ (
"mtc0 %0, $6\n"
"sync\n"
: : "r"(tlb_config[3])
);
// if (tlb_config[2] <= 0) return;
last = tlb_config[2] + i;
if (last > 48) {
__printf("# TLB over flow (3)\n");
}
ptr = (u32*)(tlb_config[6]);
for (; i<last; i++, ptr+= 4) {
_TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
}
__printf("Ok\n");
}
void DefaultINTCHandler(int n);
void DefaultDMACHandler(int n);
void rcnt3Handler();
void sbusHandler();
////////////////////////////////////////////////////////////////////
//80002050
////////////////////////////////////////////////////////////////////
int InitPgifHandler() {
int i;
_HandlersCount = 0;
for (i=0; i<15; i++) {
intcs_array[i].count = 0;
// intcs_array[-1] = ihandlers_last,first
intcs_array[i-1].l.prev = (struct ll*)&intcs_array[i-1].l.next;
intcs_array[i-1].l.next = (struct ll*)&intcs_array[i-1].l.next;
setINTCHandler(i, DefaultINTCHandler);
}
setINTCHandler(12, rcnt3Handler);
setINTCHandler(1, sbusHandler);
for (i=0; i<32; i++) {
sbus_handlers[i] = 0;
}
__EnableIntc(INTC_SBUS);
for (i=0; i<16; i++) {
dmacs_array[i].count = 0;
dmacs_array[i-1].l.prev = (struct ll*)&dmacs_array[i-1].l.next;
dmacs_array[i-1].l.next = (struct ll*)&dmacs_array[i-1].l.next;
setDMACHandler(i, DefaultDMACHandler);
}
handler_ll_free.next = &handler_ll_free;
handler_ll_free.prev = &handler_ll_free;
for (i=0; i<160; i++) {
pgifhandlers_array[i+1].handler = 0;
pgifhandlers_array[i+1].flag = 3;
LL_add(&handler_ll_free, (struct ll*)&pgifhandlers_array[i+1].next);
}
return 0x81;
}
////////////////////////////////////////////////////////////////////
//800021B0
// asme as InitPgifHandler except don't reset sbus
////////////////////////////////////////////////////////////////////
int InitPgifHandler2()
{
int i;
_HandlersCount = 0;
for(i = 0; i < 15; ++i) {
if(i != 1 ) {
intcs_array[i].count = 0;
// intcs_array[-1] = ihandlers_last,first
intcs_array[i-1].l.prev = (struct ll*)&intcs_array[i-1].l.next;
intcs_array[i-1].l.next = (struct ll*)&intcs_array[i-1].l.next;
setINTCHandler(i, DefaultINTCHandler);
}
}
setINTCHandler(12, rcnt3Handler);
for (i=0; i<16; i++) {
dmacs_array[i].count = 0;
dmacs_array[i-1].l.prev = (struct ll*)&dmacs_array[i-1].l.next;
dmacs_array[i-1].l.next = (struct ll*)&dmacs_array[i-1].l.next;
setDMACHandler(i, DefaultDMACHandler);
}
handler_ll_free.next = &handler_ll_free;
handler_ll_free.prev = &handler_ll_free;
for (i=0; i<160; i++) {
pgifhandlers_array[i+1].handler = 0;
pgifhandlers_array[i+1].flag = 3;
LL_add(&handler_ll_free, (struct ll*)&pgifhandlers_array[i+1].next);
}
return 0x81;
}

View File

@ -1,336 +0,0 @@
// EE core interrupt and exception handlers
// most functions here can only use $at, $k0, and $k1
// [made by] [RO]man, zerofrog
#include "eekernel.h"
#include "eeirq.h"
#define LOAD_KERNELSTACK \
"lui $sp, %hi(g_kernelstackend)\n" \
"addiu $sp, %lo(g_kernelstackend)\n"
__asm__(".org 0x0000");
__asm__(".set noreorder");
void CpuException0() {
__asm__ (
"lui $26, %hi(SavedT9)\n"
"sd $25, %lo(SavedT9)($26)\n"
"mfc0 $25, $13\n"
"andi $25, 0x7C\n"
"lui $26, %hi(VCRTable)\n"
"addu $26, $25\n"
"lw $26, %lo(VCRTable)($26)\n"
"lui $25, %hi(SavedT9)\n"
"jr $26\n"
"ld $25, %lo(SavedT9)($25)\n"
);
}
__asm__(".org 0x0180");
__asm__(".set noreorder");
void CpuException() {
__asm__ (
"lui $26, %hi(SavedT9)\n"
"sd $25, %lo(SavedT9)($26)\n"
"mfc0 $25, $13\n"
"andi $25, 0x7C\n"
"lui $26, %hi(VCRTable)\n"
"addu $26, $25\n"
"lw $26, %lo(VCRTable)($26)\n"
"lui $25, %hi(SavedT9)\n"
"jr $26\n"
"ld $25, %lo(SavedT9)($25)\n"
);
}
__asm__(".org 0x0200");
__asm__(".set noreorder");
__asm__(".set noat");
void CpuException2() {
__asm__ (
"lui $26, %hi(SavedSP)\n"
"sq $sp, %lo(SavedSP)($26)\n"
"lui $26, %hi(SavedRA)\n"
"sq $31, %lo(SavedRA)($26)\n"
"lui $26, %hi(SavedAT)\n"
"sq $1, %lo(SavedAT)($26)\n"
"mfc0 $1, $13\n"
"mfc0 $26, $14\n"
"and $1, $26\n"
"srl $1, 8\n"
"andi $1, 0xFF\n"
"plzcw $26, $1\n"
"andi $26, 0xFF\n"
"ori $1, $0, 0x1E\n"
"subu $1, $26\n"
"sll $1, 2\n"
"lui $26, %hi(VIntTable)\n"
"addu $26, $25\n"
"lw $26, %lo(VIntTable)($26)\n"
"jr $26\n"
"nop\n"
);
}
extern char call_used_regs[];
extern char fixed_regs[];
__asm__(".org 0x0280");
__asm__(".set noreorder");
void SyscException()
{
const register int code __asm__("$3"); // $v1
if (code < 0) {
__asm__(
"addiu $sp, -0x10\n"
"sw $31, 0($sp)\n"
"mfc0 $26, $14\n"
"addiu $26, 4\n"
"sw $26, 4($sp)\n"
"mtc0 $26, $14\n"
"sync\n");
table_SYSCALL[-code]();
__asm__(
"lw $26, 4($sp)\n"
"lw $31, 0($sp)\n"
"addiu $sp, 0x10\n"
"mtc0 $26, $14\n"
"sync\n"
"eret\n"
"nop\n");
}
if (code == 0x7c) {
_Deci2Call();
return;
}
__asm__(
"lui $26, %hi(SavedSP)\n"
"sq $sp, %lo(SavedSP)($26)\n"
"lui $26, %hi(SavedRA)\n"
"sq $31, %lo(SavedRA)($26)\n"
"lui $26, %hi(SavedAT)\n"
"sq $1, %lo(SavedAT)($26)\n"
"mfc0 $1, $12\n"
"addiu $26, $0, 0xFFE4\n"
"and $1, $26\n"
"mtc0 $1, $12\n"
"sync\n"
"move $26, $sp\n"
LOAD_KERNELSTACK
"addiu $sp, -0x10\n"
"sw $31, 0($sp)\n"
"sw $26, 4($sp)\n"
"mfc0 $26, $14\n"
"addiu $26, 4\n"
"sw $26, 8($sp)\n"
"mtc0 $26, $14\n"
"sync\n");
table_SYSCALL[code]();
__asm__(
"lw $26, 8($sp)\n"
"lw $31, 0($sp)\n"
"lw $sp, 4($sp)\n"
"mtc0 $26, $14\n"
"sync\n"
"mfc0 $26, $12\n"
"ori $26, 0x13\n"
"mtc0 $26, $12\n"
"sync\n"
"eret\n"
"nop\n");
}
void _Deci2Call() {
__puts("_Deci2Call called\n");
}
void __ThreadHandler();
void INTCException() {
u32 code;
u32 temp;
code = INTC_STAT & INTC_MASK;
if (code & 0xC0) {
int VpuStat;
__asm__("cfc2 %0, $29\n" : "=r"(VpuStat) : );
if (VpuStat & 0x202) {
__asm__(
".set noat\n"
"lui $26, %hi(SavedAT)\n"
"lq $1, %lo(SavedAT)($26)\n"
".set at\n");
__exception();
}
}
__asm__ (
"mfc0 $26, $14\n"
"li $27, 0xFFFFFFE4\n"
"and $26, $27\n"
"mtc0 $26, $14\n"
"sync\n"
LOAD_KERNELSTACK
"addiu $sp, -0x10\n"
"mfc0 $26, $14\n"
"sw $26, 0($sp)\n"
);
saveContext2();
__asm__ (
"plzcw %0, %1"
: "=r"(temp) : "r"(code)
);
temp = 0x1e - (temp & 0xff);
INTC_STAT = 1 << temp;
threadStatus = 0;
INTCTable[temp](temp);
restoreContext2();
__asm__ (
".set noat\n"
"lw $26, 0($sp)\n"
"mtc0 $26, $14\n"
"lui $26, %hi(SavedSP)\n"
"lq $sp, %lo(SavedSP)($26)\n"
"lui $26, %hi(SavedRA)\n"
"lq $31, %lo(SavedRA)($26)\n"
"lui $26, %hi(SavedAT)\n"
"lq $1, %lo(SavedAT)($26)\n"
".set at\n"
);
if (!threadStatus) {
__asm__ (
"mfc0 $26, $12\n"
"ori $26, 0x13\n"
"mtc0 $26, $12\n"
"sync\n"
"eret\n"
);
}
__asm__(LOAD_KERNELSTACK);
threadStatus = 0;
__ThreadHandler();
}
////////////////////////////////////////////////////////////////////
//800004C0
////////////////////////////////////////////////////////////////////
void DMACException() {
unsigned int code;
unsigned int temp;
code = (DMAC_STAT >> 16) | 0x8000;
code&= DMAC_STAT & 0xFFFF;
if (code & 0x80) {
//__printf("%s: code & 0x80\n", __FUNCTION__);
__asm__(
".set noat\n"
"lui $26, %hi(SavedAT)\n"
"lq $1, %lo(SavedAT)($26)\n"
".set at\n");
__exception1();
}
__asm__ (
"mfc0 $26, $14\n"
"li $27, 0xFFFFFFE4\n"
"and $26, $27\n"
"mtc0 $26, $14\n"
"sync\n"
LOAD_KERNELSTACK
"addiu $sp, -0x10\n"
"mfc0 $26, $14\n"
"sw $26, 0($sp)\n"
);
saveContext2();
__asm__ (
"plzcw %0, %1"
: "=r"(temp) : "r"(code)
);
temp = 0x1e - (temp & 0xff);
DMAC_STAT = 1 << temp;
threadStatus = 0;
DMACTable[temp](temp);
restoreContext2();
__asm__ (
".set noat\n"
"lw $26, 0($sp)\n"
"mtc0 $26, $14\n"
"lui $26, %hi(SavedSP)\n"
"lq $sp, %lo(SavedSP)($26)\n"
"lui $26, %hi(SavedRA)\n"
"lq $31, %lo(SavedRA)($26)\n"
"lui $26, %hi(SavedAT)\n"
"lq $1, %lo(SavedAT)($26)\n"
".set at\n"
);
if (!threadStatus) {
__asm__ (
"mfc0 $26, $12\n"
"ori $26, 0x13\n"
"mtc0 $26, $12\n"
"sync\n"
"eret\n"
);
}
__asm__(LOAD_KERNELSTACK);
threadStatus = 0;
__ThreadHandler();
}
////////////////////////////////////////////////////////////////////
//80000600
////////////////////////////////////////////////////////////////////
void TIMERException()
{
}
////////////////////////////////////////////////////////////////////
//80000700
////////////////////////////////////////////////////////////////////
void setINTCHandler(int n, void (*phandler)(int))
{
INTCTable[n] = phandler;
}
////////////////////////////////////////////////////////////////////
//80000780
////////////////////////////////////////////////////////////////////
void setDMACHandler(int n, void (*phandler)(int))
{
DMACTable[n] = phandler;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
#include <tamtypes.h>
#include <stdio.h>
#include "eeload.h"
#include "eeinit.h"
#include "eedebug.h"
void __attribute__((noreturn)) eeload_start() {
void (*entry)();
__puts("EELOAD start\n");
__printf("about to SifInitRpc(0)\n");
SifInitRpc(0);
__printf("done rpc\n");
entry = (void (*)())loadElfFile("INTRO");
entry();
entry = (void (*)())loadElfFile("LOADER");
entry();
for (;;);
}
void Kmemcpy(void *dest, const void *src, int n) {
const u8 *s = (u8*)src;
u8 *d = (u8*)dest;
while (n) {
*d++ = *s++; n--;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
#ifndef __EEDEBUG_H__
#define __EEDEBUG_H__
#include <tamtypes.h>
#include <kernel.h>
void __putc(u8 c);
void __puts(u8 *s);
int __printf(const char *format, ...);
#endif /* __EEDEBUG_H__ */

View File

@ -1,6 +0,0 @@
#ifndef __EEELF_H__
#define __EEELF_H__
u32 loadElfFile(char *filename);
#endif

View File

@ -1,8 +0,0 @@
#ifndef __EEINIT_H__
#define __EEINIT_H__
#include <tamtypes.h>
void TlbInit();
#endif /* __EEINIT_H__ */

View File

@ -1,17 +0,0 @@
#ifndef __EEIRQ_H__
#define __EEIRQ_H__
#include <tamtypes.h>
void CpuException0();
void CpuException();
void CpuException2();
void SyscException();
void _Deci2Call();
void INTCException();
void DMACException();
void TIMERException();
void setINTCHandler(int n, void (*phandler)(int));
void setDMACHandler(int n, void (*phandler)(int));
#endif /* __EEIRQ_H__ */

View File

@ -1,447 +0,0 @@
#ifndef __EEKERNEL_H__
#define __EEKERNEL_H__
#include <tamtypes.h>
#include <kernel.h>
#define RCNT0_COUNT *(volatile int*)0xB0000000
#define RCNT0_MODE *(volatile int*)0xB0000010
#define RCNT0_TARGET *(volatile int*)0xB0000020
#define RCNT0_HOLD *(volatile int*)0xB0000030
#define RCNT1_COUNT *(volatile int*)0xB0000800
#define RCNT1_MODE *(volatile int*)0xB0000810
#define RCNT1_TARGET *(volatile int*)0xB0000820
#define RCNT1_HOLD *(volatile int*)0xB0000830
#define RCNT2_COUNT *(volatile int*)0xB0001000
#define RCNT2_MODE *(volatile int*)0xB0001010
#define RCNT2_TARGET *(volatile int*)0xB0001020
#define RCNT3_COUNT *(volatile int*)0xB0001800
#define RCNT3_MODE *(volatile int*)0xB0001810
#define RCNT3_TARGET *(volatile int*)0xB0001820
#define GIF_CTRL *(volatile int*)0xB0003000
#define GIF_FIFO *(volatile u128*)0xB0006000
//SIF0
#define D5_CHCR *(volatile int*)0xB000C000
#define D5_MADR *(volatile int*)0xB000C010
#define D5_QWC *(volatile int*)0xB000C020
//SIF1
#define D6_CHCR *(volatile int*)0xB000C400
#define D6_MADR *(volatile int*)0xB000C410
#define D6_QWC *(volatile int*)0xB000C420
#define D6_TAG *(volatile int*)0xB000C430
#define DMAC_CTRL *(volatile int*)0xB000E000
#define DMAC_STAT *(volatile int*)0xB000E010
#define DMAC_PCR *(volatile int*)0xB000E020
#define DMAC_SQWC *(volatile int*)0xB000E030
#define DMAC_RBSR *(volatile int*)0xB000E040
#define DMAC_RBOR *(volatile int*)0xB000E050
#define DMAC_STADR *(volatile int*)0xB000E060
#define INTC_STAT *(volatile int*)0xB000F000
#define INTC_MASK *(volatile int*)0xB000F010
#define SBUS_MSFLG *(volatile int*)0xB000F220
#define SBUS_SMFLG *(volatile int*)0xB000F230
#define SBUS_F240 *(volatile int*)0xB000F240
#define DMAC_ENABLER *(volatile int*)0xB000F520
#define DMAC_ENABLEW *(volatile int*)0xB000F590
#define SBFLG_IOPALIVE 0x10000
#define SBFLG_IOPSYNC 0x40000
#define GS_PMODE *(volatile u64*)0xB2000000
#define GS_SMODE1 *(volatile u64*)0xB2000010
#define GS_SMODE2 *(volatile u64*)0xB2000020
#define GS_SRFSH *(volatile u64*)0xB2000030
#define GS_SYNCH1 *(volatile u64*)0xB2000040
#define GS_SYNCH2 *(volatile u64*)0xB2000050
#define GS_SYNCV *(volatile u64*)0xB2000060
#define GS_DISPFB1 *(volatile u64*)0xB2000070
#define GS_DISPLAY1 *(volatile u64*)0xB2000080
#define GS_DISPFB2 *(volatile u64*)0xB2000090
#define GS_DISPLAY2 *(volatile u64*)0xB20000A0
#define GS_EXTBUF *(volatile u64*)0xB20000B0
#define GS_EXTDATA *(volatile u64*)0xB20000C0
#define GS_EXTWRITE *(volatile u64*)0xB20000D0
#define GS_BGCOLOR *(volatile u64*)0xB20000E0
#define GS_CSR *(volatile u64*)0xB2001000
#define GS_IMR *(volatile u64*)0xB2001010
#define GS_BUSDIR *(volatile u64*)0xB2001040
#define GS_SIGLBLID *(volatile u64*)0xB2001080
#define INTC_GS 0
#define INTC_SBUS 1
#define INTC_VBLANK_S 2
#define INTC_VBLANK_E 3
#define INTC_VIF0 4
#define INTC_VIF1 5
#define INTC_VU0 6
#define INTC_VU1 7
#define INTC_IPU 8
#define INTC_TIM0 9
#define INTC_TIM1 10
#define INTC_TIM2 11
#define INTC_TIM3 12 //threads
//#define INTC_13 13 //not used
//#define INTC_14 14 //not used
#define DMAC_VIF0 0
#define DMAC_VIF1 1
#define DMAC_GIF 2
#define DMAC_FROM_IPU 3
#define DMAC_TO_IPU 4
#define DMAC_SIF0 5
#define DMAC_SIF1 6
#define DMAC_SIF2 7
#define DMAC_FROM_SPR 8
#define DMAC_TO_SPR 9
//#define DMAC_10 10 //not used
//#define DMAC_11 11 //not used
//#define DMAC_12 12 //not used
//#define DMAC_13 13 //not used
//#define DMAC_14 14 //not used
#define DMAC_ERROR 15
///////////////////////
// DMA TAG REGISTERS //
///////////////////////
#define DMA_TAG_REFE 0x00
#define DMA_TAG_CNT 0x01
#define DMA_TAG_NEXT 0x02
#define DMA_TAG_REF 0x03
#define DMA_TAG_REFS 0x04
#define DMA_TAG_CALL 0x05
#define DMA_TAG_RET 0x06
#define DMA_TAG_END 0x07
// Modes for DMA transfers
#define SIF_DMA_FROM_IOP 0x0
#define SIF_DMA_TO_IOP 0x1
#define SIF_DMA_FROM_EE 0x0
#define SIF_DMA_TO_EE 0x1
#define SIF_DMA_INT_I 0x2
#define SIF_DMA_INT_O 0x4
#define SIF_DMA_SPR 0x8
#define SIF_DMA_BSN 0x10 /* ? what is this? */
#define SIF_DMA_TAG 0x20
#define SIF_DMA_ERT 0x40
#define DMA_TAG_IRQ 0x80000000
#define DMA_TAG_PCE 0x0C000000
#define KSEG1_ADDR(x) (((u32)(x))|0xA0000000)
#define KUSEG_ADDR(x) (((u32)(x))&0x1FFFFFFF)
#define MAX_SEMAS 256
#define STACK_RES 0x2A0
//?
#define SRInitVal 0x70030C13
#define ConfigInitVal 0x73003
//enum {
#define THS_RUN 0x01
#define THS_READY 0x02
#define THS_WAIT 0x04
#define THS_SUSPEND 0x08
#define THS_DORMANT 0x10
//};
typedef struct {
u128 gpr[24]; // v0-t9 (skip r0,at,k0-ra)
u128 gp;
u128 fp;
u128 hi;
u128 lo;
u32 sa;
} eeRegs;
struct ThreadParam {
int status;
void (*entry)(void*);
void *stack;
int stackSize;
void *gpReg;
int initPriority;
int currentPriority;
u32 attr;
u32 option;
int waitSema; // waitType?
int waitId;
int wakeupCount;
};
struct TCB { //internal struct
struct TCB *next; //+00
struct TCB *prev; //+04
int status;//+08
void (*entry)(void*); //+0C
void *stack_res; //+10 initial $sp
void *gpReg; //+14
short currentPriority; //+18
short initPriority; //+1A
int waitSema, //+1C waitType?
semaId, //+20
wakeupCount, //+24
attr, //+28
option; //+2C
void (*entry_)(void*); //+30
int argc; //+34
char *argstring;//+38
void *stack;//+3C
int stackSize; //+40
int (*root)(); //+44
void* heap_base; //+48
};
struct threadCtx {
u128 gpr[25]; // at-t9, (skip r0,k0-ra)
u128 gp; //+190
u128 sp; //+1A0
u128 fp; //+1B0
u128 ra; //+1C0
u128 hi; //+1D0
u128 lo; //+1E0
u32 sa; //+1F0
u32 cf31;//+1F4
u32 acc; //+1F8
u32 res; //+1FC
u32 fpr[32];//+200
};
typedef struct tag_ARGS{
int argc;
char *argv[16];
char args[256];
} ARGS;
struct SemaParam {
int count;
int max_count;
int init_count;
int wait_threads;
int attr;
u32 option;
};
struct kSema { // internal struct
struct kSema *free;//+00
int count;//+04
int max_count;//+08
int attr;//+0C
int option;//+10
int wait_threads;//+14
struct TCB *wait_next,//+18
*wait_prev;//+1C
};
struct ll { struct ll *next, *prev; }; //linked list
//internal struct
struct IDhandl { //intc dmac handler
struct ll *next, //+00
*prev; //+04
int (*handler)(int); //+08
u32 gp; //+0C
void *arg; //+10
int flag; //+14
};
//internal struct
struct HCinfo{ //handler cause info
int count;
struct ll l;
};
extern u128 SavedSP;
extern u128 SavedRA;
extern u128 SavedAT;
extern u64 SavedT9;
extern eeRegs SavedRegs;
extern u32 excepRA;
extern u32 excepSP;
extern u32 (*table_CpuConfig[6])(u32);
extern void (*table_SYSCALL[0x80])();
extern void (*VCRTable[14])();
extern void (*VIntTable[8])();
extern void (*INTCTable[16])(int);
extern void (*DMACTable[16])(int);
extern int threadId;
extern int threadPrio;
extern int threadStatus;
extern u64 hvParam;
extern u32 machineType;
extern u64 gsIMR;
extern u32 memorySize;
extern u32 g_kernelstackend;
extern u32 dmac_CHCR[10];
extern int VSyncFlag0;
extern int VSyncFlag1;
extern int _HandlersCount;
extern struct ll handler_ll_free, *ihandlers_last, *ihandlers_first;
extern struct HCinfo intcs_array[14];
extern struct ll *dhandlers_last, *dhandlers_first;
extern struct HCinfo dmacs_array[15];
extern struct IDhandl pgifhandlers_array[161];
extern void (*sbus_handlers[32])(int ca);
extern int rcnt3Code;
extern int rcnt3TargetTable[0x142];
extern u8 rcnt3TargetNum[0x40];
extern int threads_count;
extern struct ll thread_ll_free;
extern struct ll thread_ll_priorities[128];
extern int semas_count;
extern struct kSema* semas_last;
extern struct TCB threads_array[256];
extern struct kSema semas_array[256];
extern char tagindex;
extern short transferscount;
extern struct TAG{
int id_qwc;
int addr;
int unk[2];
} tadrptr[31];
extern int extrastorage[(16/4) * 8][31];
extern int osdConfigParam;
// syscalls
// Every syscall is officially prefixed with _ (to avoid clashing with ps2sdk)
void _SetSYSCALL(int num, int address);
int __EnableIntc(int ch);
int __DisableIntc(int ch);
int __EnableDmac(int ch);
int __DisableDmac(int ch);
void *_SetVTLBRefillHandler(int cause, void (*handler)());
void *_SetVCommonHandler(int cause, void (*handler)());
void *_SetVInterruptHandler(int cause, void (*handler)());
void _PSMode();
u32 _MachineType();
u32 _SetMemorySize(u32 size);
u32 _GetMemorySize();
u64 _GsGetIMR();
u64 _GsPutIMR(u64 val);
int _Exit(); // 3
void _RFU___(); // 0
void _SetVSyncFlag(int flag0, int flag1);
int _AddIntcHandler(int cause, int (*handler)(int), int next, void *arg);
int _AddIntcHandler2(int cause, int (*handler)(int), int next, void *arg);
int _RemoveIntcHandler(int cause, int hid);
int _AddDmacHandler(int cause, int (*handler)(int), int next, void *arg);
int _AddDmacHandler2(int cause, int (*handler)(int), int next, void *arg);
int _RemoveDmacHandler(int code, int hid);
int _AddSbusIntcHandler(int cause, void (*handler)(int ca));
int _RemoveSbusIntcHandler(int cause);
int _Interrupt2Iop(int cause);
void _RFU005();
int _GetCop0(int reg);
int _ExecPS2(void *, void *, int, char **);
int _DeleteThread(int tid);
int _StartThread(int tid, void *arg);
int _ExitThread();
int _ExitDeleteThread();
int _SleepThread();
int _WakeupThread(int tid);
int _WaitSema(int sid);
void _ChangeThreadPriority(int tid, int prio);
int _CreateThread(struct ThreadParam *param);
int _iChangeThreadPriority(int tid, int prio);
int _GetThreadId();
int _ReferThreadStatus(int tid, struct ThreadParam *info);
int _iWakeupThread(int tid);
int _SuspendThread(int thid);
int _iResumeThread(int tid);
int _CancelWakeupThread(int tid);
int _CreateEventFlag();
int _CreateSema(struct SemaParam *sema);
int _RFU073(int sid);
int _iSignalSema(int sid);
int _PollSema(int sid);
int _ReferSemaStatus(int sid, struct SemaParam *sema);
int _DeleteEventFlag();
void*_InitializeMainThread(u32 gp, void *stack, int stack_size,
char *args, int root);
void *_InitializeHeapArea(void *heap_base, int heap_size);
void *_EndOfHeap();
int _LoadPS2Exe(char *filename, int argc, char **argv);
int _ExecOSD(int argc, char **argv);
void _SifSetDChain();
void _SifStopDma();
u32 _SifSetDma(SifDmaTransfer_t *sdd, int len);
void _SetGsCrt(short arg0, short arg1, short arg2); // 2
void _GetGsHParam(int *p0, int *p1, int *p2, int *p3);
int _GetGsVParam();
void _SetGsVParam(int VParam);
void _GetOsdConfigParam(int *result);
void _SetOsdConfigParam(int *param);
int _ResetEE(int init); // 1
int _TlbWriteRandom(u32 PageMask, u32 EntryHi, u32 EntryLo0, u32 EntryLo1);
int _SetAlarm(short a0, int a1, int a2);
void _ReleaseAlarm();
int _TerminateThread(int tid);
void _RotateThreadReadyQueue(int prio);
int _iTerminateThread(int tid);
int _DisableDispatchThread();
int _EnableDispatchThread();
int _iRotateThreadReadyQueue(int prio);
void _ReleaseWaitThread(int tid);
int _iReleaseWaitThread(int tid);
int _ResumeThread(int tid);
int _iResumeThread(int tid);
void _JoinThread();
int _DeleteSema(int sid);
int _iDeleteSema(int sid);
void _SignalSema(int sid);
void _SetGsHParam(int a0, int a1, int a2, int a3);
int _SetEventFlag(int ef, u32 bits); // bits is EF_X
int _iSetEventFlag(int ef, u32 bits);
void _EnableIntcHandler(u32 id);
void _DisableIntcHandler(u32 id);
void _EnableDmacHandler(u32 id);
void _DisableDmacHandler(u32 id);
void _KSeg0(u32 arg);
int _EnableCache(int cache);
int _DisableCache(int cache);
void _FlushCache(int op);
void _105(int op1, int op2);
u32 _CpuConfig(u32 op);
void _SetCPUTimerHandler(void (*handler)());
void _SetCPUTimer(int compval);
void _SetPgifHandler(void (*handler)(int));
void _print();
int _SifDmaStat(int id);
int _SifGetReg(int reg);
int _SifSetReg(int reg, u32 val);
////////////////////////////////////////////////////////////////////
// KERNEL BSS //
////////////////////////////////////////////////////////////////////
#endif

View File

@ -1,4 +0,0 @@
#ifndef __EELOAD_H__
#define __EELOAD_H__
#endif /* __EELOAD_H__ */

View File

@ -1,20 +0,0 @@
#ifndef __ROMDIR_H__
#define __ROMDIR_H__
#include <tamtypes.h>
struct romdir {
/*following variable must place in designed order*/
u8 fileName[10];
u16 extInfoSize;
u32 fileSize;
} __attribute__ ((packed));
struct rominfo {
u32 fileOffset;
u32 fileSize;
};
struct rominfo *romdirGetFile(char *name, struct rominfo *ri);
#endif /* __ROMDIR_H__ */

View File

@ -1,56 +0,0 @@
_stack_size = 0x80000;
_heap_size = 1024*1024*10;
ENTRY(_start);
SECTIONS {
. 0x80000000 : {
eeirq.o
}
.text 0x80001000 : {
*(.text)
*(.rodata)
}
.reginfo ALIGN(128) : {
*(.reginfo)
}
.data ALIGN(128) : {
*(.data)
}
.rdata ALIGN(128) : {
*(.rdata)
}
_gp = ALIGN(128) + 0x7ff0;
.lit4 ALIGN(128) : {
*(.lit4)
}
.lit8 ALIGN(128) : {
*(.lit8)
}
.sdata ALIGN(128) : {
*(.sdata)
}
.sbss ALIGN(128) (NOLOAD) : { /* uninitialized data */
_fbss = . ;
*(.scommon)
*(.sbss)
}
.bss ALIGN(128) (NOLOAD) : { /* uninitialized data */
*(.bss)
}
.COMMON ALIGN(128) (NOLOAD) : { /* uninitialized data */
*(COMMON)
}
_end_bss = . - 4;
_stack = .;
. += _stack_size ;
_end_stack = . - 8*5;
_end = . ;
__lc_bh = . ;
. += _heap_size ;
__lc_eh = .;
}

View File

@ -1,47 +0,0 @@
/***************************************************************
* romdir.c, based over Alex Lau (http://alexlau.8k.com) RomDir *
****************************************************************/
#include "romdir.h"
struct romdir *base = NULL;
struct romdir *romdirInit() {
u8 *mem;
for (mem=(u8*)0xbfc00000; (u32)mem<0xbfc01000; mem++) {
if (mem[0] == 'R' && mem[1] == 'E' &&
mem[2] == 'S' && mem[3] == 'E' &&
mem[4] == 'T')
break;
}
if ((u32)mem == 0xbfc01000) return NULL;
return (struct romdir*)mem;
}
struct rominfo *romdirGetFile(char *name, struct rominfo *ri) {
struct romdir *rd;
// struct romdir *base;
int i;
if (base == NULL) {
base = romdirInit();
if (base == NULL) return NULL;
}
ri->fileOffset = 0;
for (rd = base; rd->fileName[0] != 0; rd++) {
for (i=0; i<10 && name[i] != 0; i++) {
if (rd->fileName[i] != name[i]) break;
}
if (rd->fileName[i] != name[i]) {
ri->fileOffset+= (rd->fileSize + 15) & ~0xF;
continue;
}
ri->fileSize = rd->fileSize;
return ri;
}
return NULL;
}

View File

@ -1,50 +0,0 @@
#include <tamtypes.h>
#include "romdir.h"
static void Kputc(u8 c) {
*((u8*)0x1000f180) = c;
}
static void Kputs(u8 *s) {
while (*s != 0) {
Kputc(*s++);
}
}
static void Kmemcpy(void *dest, const void *src, int n) {
const u8 *s = (u8*)src;
u8 *d = (u8*)dest;
while (n > 0) {
*d++ = *s++; n--;
}
}
void _eestart() {
struct rominfo ri;
u8 *str;
romdirGetFile("ROMVER", &ri);
str = (u8*)(0xbfc00000 + ri.fileOffset);
Kputs("fps2bios v");
Kputc(str[1]); Kputc('.'); Kputc(str[3]); Kputc('\n');
romdirGetFile("EELOAD", &ri);
Kputs("loading EELOAD to 0x80000000\n");
Kmemcpy((void*)0x80000000, (void*)(0xbfc00000 + ri.fileOffset), ri.fileSize);
__asm__ (
"li $26, 0x80001000\n"
"jr $26\n");
for (;;);
}
__asm__ (
".global eestart\n"
"eestart:\n"
"li $sp, 0x80010000\n"
"j _eestart\n");

View File

@ -1,18 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
DIRS = iopboot sysmem loadcore excepman intrman stdio timrman \
dmacman sifman sifcmd ssbusc sysclib heaplib \
vblank threadman sio2man
iopload: $(OBJECTS)
for i in $(DIRS); do \
make -C $$i; \
done;
clean:
for i in $(DIRS); do \
make -C $$i clean; \
done;

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/DMACMAN
IOP_INCS += -I../include
IOP_OBJS = dmacman.o ../iopdebug.o ../libkernel/iop_loadcore.o ../libkernel/iop_intrman.o ../libkernel/iop_sysmem.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,923 +0,0 @@
//[module] DMACMAN
//[processor] IOP
//[type] ELF-IRX
//[name] dmacman
//[version] 0x101
//[memory map] 0xBF801080,0xBF801084,0xBF801088, 00 mdec in
// 0xBF801090,0xBF801094,0xBF801098, 01 mdec out
// 0xBF8010A0,0xBF8010A4,0xBF8010A8, 02 gpu
// 0xBF8010B0,0xBF8010B4,0xBF8010B8, 03 cdrom/dvd
// 0xBF8010C0,0xBF8010C4,0xBF8010C8, 0xBF8010CC, 04 spu
// 0xBF8010D0,0xBF8010D4,0xBF8010D8, 05 pio
// 0xBF8010E0,0xBF8010E4,0xBF8010E8, 06 gpu otc
//
// 0xBF8010F0,0xBF8010F4,
//
// 0xBF801500,0xBF801504,0xBF801508, 07 SPU2
// 0xBF801510,0xBF801514,0xBF801518, 08
// 0xBF801520,0xBF801524,0xBF801528, 0xBF80152C, 09 SIF0
// 0xBF801530,0xBF801534,0xBF801538, 10 SIF1
// 0xBF801540,0xBF801544,0xBF801548, 11 SIO2in
// 0xBF801550,0xBF801554,0xBF801558, 12 SIO2out
//
// 0xBF801560,0xBF801564,0xBF801568, //sifman
// sif0 sif1 spu
//
// 0xBF801570, 0xBF801574,0xBF801578,0xBF80157C, //sifman
// 0xBF8015F0
//[handlers] -
//[entry point] dmacman_start, dmacman_stub
//[made by] [RO]man (roman_ps2dev@hotmail.com)
#include <tamtypes.h>
#include "kloadcore.h"
#include "kintrman.h"
#include "kdmacman.h"
int _start(int argc, char* argv[]);
///////////////////////////////////////////////////////////////////////
void _setBF801080(unsigned int ch, int value){
*(int*)0xBF801080=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801090(unsigned int ch, int value){
*(int*)0xBF801090=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010A0(unsigned int ch, int value){
*(int*)0xBF8010A0=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010B0(unsigned int ch, int value){
*(int*)0xBF8010B0=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010C0(unsigned int ch, int value){
*(int*)0xBF8010C0=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010D0(unsigned int ch, int value){
*(int*)0xBF8010D0=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010E0(unsigned int ch, int value){
*(int*)0xBF8010E0=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801500(unsigned int ch, int value){
*(int*)0xBF801500=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801510(unsigned int ch, int value){
*(int*)0xBF801510=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801520(unsigned int ch, int value){
*(int*)0xBF801520=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801530(unsigned int ch, int value){
*(int*)0xBF801530=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801540(unsigned int ch, int value){
*(int*)0xBF801540=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801550(unsigned int ch, int value){
*(int*)0xBF801550=value;
}
///////////////////////////////////////////////////////////////////////
int _getBF801080(unsigned int ch){
return *(int*)0xBF801080;
}
///////////////////////////////////////////////////////////////////////
int _getBF801090(unsigned int ch){
return *(int*)0xBF801090;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010A0(unsigned int ch){
return *(int*)0xBF8010A0;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010B0(unsigned int ch){
return *(int*)0xBF8010B0;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010C0(unsigned int ch){
return *(int*)0xBF8010C0;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010D0(unsigned int ch){
return *(int*)0xBF8010D0;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010E0(unsigned int ch){
return *(int*)0xBF8010E0;
}
///////////////////////////////////////////////////////////////////////
int _getBF801500(unsigned int ch){
return *(int*)0xBF801500;
}
///////////////////////////////////////////////////////////////////////
int _getBF801510(unsigned int ch){
return *(int*)0xBF801510;
}
///////////////////////////////////////////////////////////////////////
int _getBF801520(unsigned int ch){
return *(int*)0xBF801520;
}
///////////////////////////////////////////////////////////////////////
int _getBF801530(unsigned int ch){
return *(int*)0xBF801530;
}
///////////////////////////////////////////////////////////////////////
int _getBF801540(unsigned int ch){
return *(int*)0xBF801540;
}
///////////////////////////////////////////////////////////////////////
int _getBF801550(unsigned int ch){
return *(int*)0xBF801550;
}
///////////////////////////////////////////////////////////////////////
void _setBF801084(unsigned int ch, int value){
*(int*)0xBF801084=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801094(unsigned int ch, int value){
*(int*)0xBF801094=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010A4(unsigned int ch, int value){
*(int*)0xBF8010A4=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010B4(unsigned int ch, int value){
*(int*)0xBF8010B4=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010C4(unsigned int ch, int value){
*(int*)0xBF8010C4=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010D4(unsigned int ch, int value){
*(int*)0xBF8010D4=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010E4(unsigned int ch, int value){
*(int*)0xBF8010E4=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801504(unsigned int ch, int value){
*(int*)0xBF801504=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801514(unsigned int ch, int value){
*(int*)0xBF801514=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801524(unsigned int ch, int value){
*(int*)0xBF801524=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801534(unsigned int ch, int value){
*(int*)0xBF801534=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801544(unsigned int ch, int value){
*(int*)0xBF801544=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801554(unsigned int ch, int value){
*(int*)0xBF801554=value;
}
///////////////////////////////////////////////////////////////////////
int _getBF801084(unsigned int ch){
return *(int*)0xBF801084;
}
///////////////////////////////////////////////////////////////////////
int _getBF801094(unsigned int ch){
return *(int*)0xBF801094;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010A4(unsigned int ch){
return *(int*)0xBF8010A4;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010B4(unsigned int ch){
return *(int*)0xBF8010B4;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010C4(unsigned int ch){
return *(int*)0xBF8010C4;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010D4(unsigned int ch){
return *(int*)0xBF8010D4;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010E4(unsigned int ch){
return *(int*)0xBF8010E4;
}
///////////////////////////////////////////////////////////////////////
int _getBF801504(unsigned int ch){
return *(int*)0xBF801504;
}
///////////////////////////////////////////////////////////////////////
int _getBF801514(unsigned int ch){
return *(int*)0xBF801514;
}
///////////////////////////////////////////////////////////////////////
int _getBF801524(unsigned int ch){
return *(int*)0xBF801524;
}
///////////////////////////////////////////////////////////////////////
int _getBF801534(unsigned int ch){
return *(int*)0xBF801534;
}
///////////////////////////////////////////////////////////////////////
int _getBF801544(unsigned int ch){
return *(int*)0xBF801544;
}
///////////////////////////////////////////////////////////////////////
int _getBF801554(unsigned int ch){
return *(int*)0xBF801554;
}
///////////////////////////////////////////////////////////////////////
void _setBF801088(unsigned int ch, int value){
*(int*)0xBF801088=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801098(unsigned int ch, int value){
*(int*)0xBF801098=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010A8(unsigned int ch, int value){
*(int*)0xBF8010A8=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010B8(unsigned int ch, int value){
*(int*)0xBF8010B8=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010C8(unsigned int ch, int value){
*(int*)0xBF8010C8=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010D8(unsigned int ch, int value){
*(int*)0xBF8010D8=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF8010E8(unsigned int ch, int value){
*(int*)0xBF8010E8=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801508(unsigned int ch, int value){
*(int*)0xBF801508=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801518(unsigned int ch, int value){
*(int*)0xBF801518=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801528(unsigned int ch, int value){
*(int*)0xBF801528=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801538(unsigned int ch, int value){
*(int*)0xBF801538=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801548(unsigned int ch, int value){
*(int*)0xBF801548=value;
}
///////////////////////////////////////////////////////////////////////
void _setBF801558(unsigned int ch, int value){
*(int*)0xBF801558=value;
}
///////////////////////////////////////////////////////////////////////
int _getBF801088(unsigned int ch){
return *(int*)0xBF801088;
}
///////////////////////////////////////////////////////////////////////
int _getBF801098(unsigned int ch){
return *(int*)0xBF801098;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010A8(unsigned int ch){
return *(int*)0xBF8010A8;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010B8(unsigned int ch){
return *(int*)0xBF8010B8;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010C8(unsigned int ch){
return *(int*)0xBF8010C8;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010D8(unsigned int ch){
return *(int*)0xBF8010D8;
}
///////////////////////////////////////////////////////////////////////
int _getBF8010E8(unsigned int ch){
return *(int*)0xBF8010E8;
}
///////////////////////////////////////////////////////////////////////
int _getBF801508(unsigned int ch){
return *(int*)0xBF801508;
}
///////////////////////////////////////////////////////////////////////
int _getBF801518(unsigned int ch){
return *(int*)0xBF801518;
}
///////////////////////////////////////////////////////////////////////
int _getBF801528(unsigned int ch){
return *(int*)0xBF801528;
}
///////////////////////////////////////////////////////////////////////
int _getBF801538(unsigned int ch){
return *(int*)0xBF801538;
}
///////////////////////////////////////////////////////////////////////
int _getBF801548(unsigned int ch){
return *(int*)0xBF801548;
}
///////////////////////////////////////////////////////////////////////
int _getBF801558(unsigned int ch){
return *(int*)0xBF801558;
}
///////////////////////////////////////////////////////////////////////
void dmacSetD_TADR(unsigned int ch, int value){
if (ch==DMAch_SPU)
*(int*)0xBF8010CC=value; else
if (ch==DMAch_SIF0)
*(int*)0xBF80152C=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetD_TADR(unsigned int ch){
if (ch==DMAch_SPU)
return *(int*)0xBF8010CC;
if (ch==DMAch_SIF0)
return *(int*)0xBF80152C;
return 0;
}
///////////////////////////////////////////////////////////////////////
void dmacSet_4_9_A(unsigned int ch, int value){
if (ch==DMAch_SPU)
*(int*)0xBF801568=value; else
if (ch==DMAch_SIF0)
*(int*)0xBF801560=value; else
if (ch==DMAch_SIF1)
*(int*)0xBF801564=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGet_4_9_A(unsigned int ch){
if (ch==DMAch_SPU)
return *(int*)0xBF801568;
if (ch==DMAch_SIF0)
return *(int*)0xBF801560;
if (ch==DMAch_SIF1)
return *(int*)0xBF801564;
return 0;
}
///////////////////////////////////////////////////////////////////////
void dmacSetDPCR(int value){
*(int*)0xBF8010F0=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetDPCR(){
return *(int*)0xBF8010F0;
}
///////////////////////////////////////////////////////////////////////
void dmacSetDPCR2(int value){
*(int*)0xBF801570=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetDPCR2(){
return *(int*)0xBF801570;
}
///////////////////////////////////////////////////////////////////////
void dmacSetDPCR3(int value){
*(int*)0xBF8015F0=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetDPCR3(){
return *(int*)0xBF8015F0;
}
///////////////////////////////////////////////////////////////////////
void dmacSetDICR(int value){
*(int*)0xBF8010F4=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetDICR(){
return *(int*)0xBF8010F4;
}
///////////////////////////////////////////////////////////////////////
void dmacSetDICR2(int value){
*(int*)0xBF801574=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetDICR2(){
return *(int*)0xBF801574;
}
///////////////////////////////////////////////////////////////////////
void dmacSetBF80157C(int value){
*(int*)0xBF80157C=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetBF80157C(){
return *(int*)0xBF80157C;
}
///////////////////////////////////////////////////////////////////////
void dmacSetBF801578(int value){
*(int*)0xBF801578=value;
}
///////////////////////////////////////////////////////////////////////
int dmacGetBF801578(){
return *(int*)0xBF801578;
}
func setD_MADR[]={
(func)_setBF801080, (func)_setBF801090, (func)_setBF8010A0, (func)_setBF8010B0,
(func)_setBF8010C0, (func)_setBF8010D0, (func)_setBF8010E0,
(func)_setBF801500, (func)_setBF801510, (func)_setBF801520,
(func)_setBF801530, (func)_setBF801540, (func)_setBF801550, 0
};
func getD_MADR[]={
(func)_getBF801080, (func)_getBF801090, (func)_getBF8010A0, (func)_getBF8010B0,
(func)_getBF8010C0, (func)_getBF8010D0, (func)_getBF8010E0,
(func)_getBF801500, (func)_getBF801510, (func)_getBF801520,
(func)_getBF801530, (func)_getBF801540, (func)_getBF801550, 0
};
func setD_BCR[]={
(func)_setBF801084, (func)_setBF801094, (func)_setBF8010A4, (func)_setBF8010B4,
(func)_setBF8010C4, (func)_setBF8010D4, (func)_setBF8010E4,
(func)_setBF801504, (func)_setBF801514, (func)_setBF801524,
(func)_setBF801534, (func)_setBF801544, (func)_setBF801554, 0
};
func getD_BCR[]={
(func)_getBF801084, (func)_getBF801094, (func)_getBF8010A4, (func)_getBF8010B4,
(func)_getBF8010C4, (func)_getBF8010D4, (func)_getBF8010E4,
(func)_getBF801504, (func)_getBF801514, (func)_getBF801524,
(func)_getBF801534, (func)_getBF801544, (func)_getBF801554, 0
};
func setD_CHCR[]={
(func)_setBF801088, (func)_setBF801098, (func)_setBF8010A8, (func)_setBF8010B8,
(func)_setBF8010C8, (func)_setBF8010D8, (func)_setBF8010E8,
(func)_setBF801508, (func)_setBF801518, (func)_setBF801528,
(func)_setBF801538, (func)_setBF801548, (func)_setBF801558, 0
};
func getD_CHCR[]={
(func)_getBF801088, (func)_getBF801098, (func)_getBF8010A8, (func)_getBF8010B8,
(func)_getBF8010C8, (func)_getBF8010D8, (func)_getBF8010E8,
(func)_getBF801508, (func)_getBF801518, (func)_getBF801528,
(func)_getBF801538, (func)_getBF801548, (func)_getBF801558, 0
};
///////////////////////////////////////////////////////////////////////
void dmacSetD_MADR(unsigned int ch, int value){
if (ch<13)
setD_MADR[ch](ch, value); //function call
}
///////////////////////////////////////////////////////////////////////
int dmacGetD_MADR(unsigned int ch){
if (ch<13)
return getD_MADR[ch](ch); //function call
return 0;
}
///////////////////////////////////////////////////////////////////////
void dmacSetD_BCR(unsigned int ch, int value){
if (ch<13)
setD_BCR[ch](ch, value); //function call
}
///////////////////////////////////////////////////////////////////////
int dmacGetD_BCR(unsigned int ch){
if (ch<13)
return getD_BCR[ch](ch); //function call
return 0;
}
///////////////////////////////////////////////////////////////////////
void dmacSetD_CHCR(unsigned int ch, int value){
if (ch<13)
setD_CHCR[ch](ch, value); //function call
}
///////////////////////////////////////////////////////////////////////
int dmacGetD_CHCR(unsigned int ch){
if (ch<13)
return getD_CHCR[ch](ch); //function call
return 0;
}
///////////////////////////////////////////////////////////////////////
int dmacDeinit(){
int x;
register int ch, value;
CpuSuspendIntr(&x); //intrman
dmacSetBF801578(0);
for (ch=0; ch<13; ch++){
value=dmacGetD_CHCR(ch);
if (value & DMAf_TR) //sysmem
Kprintf("WARNING:DMA %dch has been continued until shutdown\n", ch);
dmacSetD_CHCR(ch, value & 0xFEFFFFFF);
}
CpuResumeIntr(x); //intrman
return 1;
}
///////////////////////////////////////////////////////////////////////
int dmacSetDMA(int ch, int address, int size, int count, int dir){
if (ch<13 && ch != DMAch_GPUotc){
dmacSetD_MADR(ch, 0x00FFFFFF & address);
dmacSetD_BCR (ch, (count << 16) | (size & 0xFFFF));
dmacSetD_CHCR(ch, (dir & DMAf_DR) | DMAf_CO |
(dir == 0 ? DMAf_30 : 0));
return 1;
}
return 0;
}
///////////////////////////////////////////////////////////////////////
int dmacSetDMA_chainedSPU_SIF0(int ch, int size, int tadr){
if (ch != DMAch_SPU && ch != DMAch_SIF0)
return 0;
dmacSetD_BCR (ch, size & 0x0000FFFF);
dmacSetD_CHCR(ch, DMAf_LI | DMAf_CO | DMAf_DR); //0x601
dmacSetD_TADR (ch, tadr & 0x00FFFFFF);
return 1;
}
///////////////////////////////////////////////////////////////////////
int dmacSetDMA_SIF0(int ch, int size, int tadr){
if (ch != DMAch_SIF0)
return 0;
dmacSetD_BCR ( DMAch_SIF0, size & 0x0000FFFF);
dmacSetD_CHCR( DMAch_SIF0, DMAf_LI | DMAf_CO | DMAf_08 | DMAf_DR); //0x701
dmacSetD_TADR ( DMAch_SIF0, tadr & 0x00FFFFFF);
return 1;
}
///////////////////////////////////////////////////////////////////////
int dmacSetDMA_SIF1(int ch, int size){
if (ch != DMAch_SIF1)
return 0;
dmacSetD_BCR (DMAch_SIF1, size & 0x0000FFFF);
dmacSetD_CHCR(DMAch_SIF1, DMAf_30 | DMAf_CO | DMAf_08); //0x40000300
return 1;
}
///////////////////////////////////////////////////////////////////////
void dmacStartTransfer(int ch){
if (ch < 15)
dmacSetD_CHCR(ch, DMAf_TR | dmacGetD_CHCR(ch));
}
///////////////////////////////////////////////////////////////////////
// set 3-bit value of channel
void dmacSetVal(int ch, int value){
int x;
CpuSuspendIntr(&x); //intrman
switch (ch){
case DMAch_MDECin: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFFFF8) |
( value & 7)); break;
case DMAch_MDECout:dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFFF8F) |
(( value & 7) << 4)); break;
case DMAch_GPU: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFF8FF) |
(( value & 7) << 8)); break;
case DMAch_CD: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFF8FFF) |
(( value & 7) << 12)); break;
case DMAch_SPU: dmacSetDPCR(
(dmacGetDPCR() & 0xFFF8FFFF) |
(( value & 7) << 16)); break;
case DMAch_PIO: dmacSetDPCR(
(dmacGetDPCR() & 0xFF8FFFFF) |
(( value & 7) << 20)); break;
case DMAch_GPUotc:dmacSetDPCR(
(dmacGetDPCR() & 0xF8FFFFFF) |
(( value & 7) << 24)); break;
case DMAch_SPU2:dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFFFF8) |
( value & 7)); break;
case DMAch_8: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFFF8F) |
(( value & 7) << 4)); break;
case DMAch_SIF0: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFF8FF) |
(( value & 7) << 8)); break;
case DMAch_SIF1: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFF8FFF) |
(( value & 7) << 12)); break;
case DMAch_SIO2in: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFF8FFFF) |
(( value & 7) << 16)); break;
case DMAch_SIO2out:dmacSetDPCR2(
(dmacGetDPCR2() & 0xFF8FFFFF) |
(( value & 7) << 20)); break;
case DMAch_13: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFFFF8) |
( value & 7)); break;
case DMAch_14: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFFF8F) |
(( value & 7) << 4)); break;
case DMAch_15: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFF8FF) |
(( value & 7) << 8)); break;
case DMAch_67: dmacSetDPCR(
(dmacGetDPCR() & 0x8FFFFFFF) |
(( value & 7) << 28)); break;
case DMAch_85: dmacSetDPCR2(
(dmacGetDPCR2() & 0xF8FFFFFF) |
(( value & 7) << 24)); break;
}
CpuResumeIntr(x); //intrman
}
///////////////////////////////////////////////////////////////////////
// set 4th bit of channel
void dmacEnableDMAch(int ch){
int x;
CpuSuspendIntr(&x); //intrman
switch (ch){
case DMAch_MDECin: dmacSetDPCR(
(dmacGetDPCR() | 0x00000008)); break;
case DMAch_MDECout:dmacSetDPCR(
(dmacGetDPCR() | 0x00000080)); break;
case DMAch_GPU: dmacSetDPCR(
(dmacGetDPCR() | 0x00000800)); break;
case DMAch_CD: dmacSetDPCR(
(dmacGetDPCR() | 0x00008000)); break;
case DMAch_SPU: dmacSetDPCR(
(dmacGetDPCR() | 0x00080000)); break;
case DMAch_PIO: dmacSetDPCR(
(dmacGetDPCR() | 0x00800000)); break;
case DMAch_GPUotc:dmacSetDPCR(
(dmacGetDPCR() | 0x08000000)); break;
case DMAch_SPU2: dmacSetDPCR2(
(dmacGetDPCR2() | 0x00000008)); break;
case DMAch_8: dmacSetDPCR2(
(dmacGetDPCR2() | 0x00000080)); break;
case DMAch_SIF0: dmacSetDPCR2(
(dmacGetDPCR2() | 0x00000800)); break;
case DMAch_SIF1: dmacSetDPCR2(
(dmacGetDPCR2() | 0x00008000)); break;
case DMAch_SIO2in:dmacSetDPCR2(
(dmacGetDPCR2() | 0x00080000)); break;
case DMAch_SIO2out:dmacSetDPCR2(
(dmacGetDPCR2() | 0x00800000)); break;
case DMAch_13: dmacSetDPCR3(
(dmacGetDPCR3() | 0x00000008)); break;
case DMAch_14: dmacSetDPCR3(
(dmacGetDPCR3() | 0x00000080)); break;
case DMAch_15: dmacSetDPCR3(
(dmacGetDPCR3() | 0x00000800)); break;
case DMAch_85: dmacSetDPCR2(
(dmacGetDPCR2() | 0x08000000)); break;
}
CpuResumeIntr(x); //intrman
}
///////////////////////////////////////////////////////////////////////
// reset 4th bit of channel
void dmacDisableDMAch(int ch){
int x;
CpuSuspendIntr(&x); //intrman
switch (ch){
case DMAch_MDECin: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFFFF7)); break;
case DMAch_MDECout:dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFFF7F)); break;
case DMAch_GPU: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFFF7FF)); break;
case DMAch_CD: dmacSetDPCR(
(dmacGetDPCR() & 0xFFFF7FFF)); break;
case DMAch_SPU: dmacSetDPCR(
(dmacGetDPCR() & 0xFFF7FFFF)); break;
case DMAch_PIO: dmacSetDPCR(
(dmacGetDPCR() & 0xFF7FFFFF)); break;
case DMAch_GPUotc:dmacSetDPCR(
(dmacGetDPCR() & 0xF7FFFFFF)); break;
case DMAch_SPU2: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFFFF7)); break;
case DMAch_8: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFFF7F)); break;
case DMAch_SIF0: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFFF7FF)); break;
case DMAch_SIF1: dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFFF7FFF)); break;
case DMAch_SIO2in:dmacSetDPCR2(
(dmacGetDPCR2() & 0xFFF7FFFF)); break;
case DMAch_SIO2out:dmacSetDPCR2(
(dmacGetDPCR2() & 0xFF7FFFFF)); break;
case DMAch_13: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFFFF7)); break;
case DMAch_14: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFFF7F)); break;
case DMAch_15: dmacSetDPCR3(
(dmacGetDPCR3() & 0xFFFFF7FF)); break;
case DMAch_85: dmacSetDPCR2(
(dmacGetDPCR2() & 0xF7FFFFFF)); break;
}
CpuResumeIntr(x); //intrman
}
void _retonly(){}
//////////////////////////////entrypoint///////////////////////////////
struct export dmacman_stub={
0x41C00000,
0,
VER(1, 2), // 1.2 => 0x102
0,
"dmacman",
(func)_start, // entrypoint
(func)_retonly,
(func)dmacDeinit,
(func)_retonly,
(func)dmacSetD_MADR,
(func)dmacGetD_MADR,
(func)dmacSetD_BCR,
(func)dmacGetD_BCR,
(func)dmacSetD_CHCR,
(func)dmacGetD_CHCR,
(func)dmacSetD_TADR,
(func)dmacGetD_TADR,
(func)dmacSet_4_9_A,
(func)dmacGet_4_9_A,
(func)dmacSetDPCR,
(func)dmacGetDPCR,
(func)dmacSetDPCR2,
(func)dmacGetDPCR2,
(func)dmacSetDPCR3,
(func)dmacGetDPCR3,
(func)dmacSetDICR,
(func)dmacGetDICR,
(func)dmacSetDICR2,
(func)dmacGetDICR2,
(func)dmacSetBF80157C,
(func)dmacGetBF80157C,
(func)dmacSetBF801578,
(func)dmacGetBF801578,
(func)dmacSetDMA,
(func)dmacSetDMA_chainedSPU_SIF0,
(func)dmacSetDMA_SIF0,
(func)dmacSetDMA_SIF1,
(func)dmacStartTransfer,
(func)dmacSetVal,
(func)dmacEnableDMAch,
(func)dmacDisableDMAch,
0
};
//////////////////////////////entrypoint///////////////////////////////
int _start(int argc, char* argv[]){
int x;
register int ch;
if (RegisterLibraryEntries(&dmacman_stub)) //loadcore
return 1;
CpuSuspendIntr(&x); //intrman
dmacSetDPCR(0x07777777);
dmacSetDPCR2(0x07777777);
dmacSetDPCR3(0x00000777);
for (ch=0; ch<13; ch++){
dmacSetD_MADR(ch, 0);
dmacSetD_BCR (ch, 0);
dmacSetD_CHCR(ch, 0);
}
dmacSetD_TADR( DMAch_SPU, 0);
dmacSetD_TADR( DMAch_SIF0,0);
dmacSet_4_9_A( DMAch_SPU, 0);
dmacSet_4_9_A( DMAch_SIF0,0);
dmacSet_4_9_A( DMAch_SIF1,0);
dmacSetBF801578(1);
CpuResumeIntr(x); //intrman
return 0;
}

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/EXCEPMAN
IOP_INCS += -I../include
IOP_OBJS = excepman.o ../libkernel/iop_loadcore.o ex_handler.o ../iopdebug.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,16 +0,0 @@
.global defaultEH
.ent defaultEH
defaultEH:
.set noreorder
.set noat
.word 0
.word 0
jal defaultEHfunc
nop
cop0 0x10
nop
.end defaultEH

View File

@ -1,339 +0,0 @@
/*
* The IOP exception manager module.
*/
#include <tamtypes.h>
#include "err.h"
#include "kexcepman.h"
#include "kloadcore.h"
#include "iopdebug.h"
#define _dprintf(fmt, args...) \
__printf("excepman: " fmt, ## args)
int _start();
int excepman_reinit();
int excepman_deinit();
void *GetExHandlersTable();
int RegisterExceptionHandler(int code, struct exHandler *handler);
int RegisterPriorityExceptionHandler(int code, int priority, struct exHandler *handler);
int RegisterDefaultExceptionHandler(struct exHandler *handler);
int ReleaseExceptionHandler(int code, struct exHandler *handler);
int ReleaseDefaultExceptionHandler(struct exHandler *handler);
struct export excepman_stub __attribute__((section(".text"))) ={
0x41C00000,
0,
VER(1, 1), // 1.1 => 0x101
0,
"excepman",
(func)_start, // entrypoint
(func)excepman_reinit,
(func)excepman_deinit,
(func)GetExHandlersTable,
(func)RegisterExceptionHandler,
(func)RegisterPriorityExceptionHandler,
(func)RegisterDefaultExceptionHandler,
(func)ReleaseExceptionHandler,
(func)ReleaseDefaultExceptionHandler,
0
};
void* *extable;
struct exHandler *handlers[16];
void *defhandler;
void iopException();
extern void defaultEH();
void defaultEHfunc()
{
__printf("panic: excepman: %s\n", __FUNCTION__);
__printf("EPC=0x%x, cause: %x\n", *(u32*)0x404, *(u32*)0x40C);
__printf("EXECUTION HALTED\n");
for (;;);
}
///////////////////////////////////////////////////////////////////////
void registerEH() {
int i;
_dprintf("%s\n", __FUNCTION__);
// Set up the chain of exception handlers, making sure that each used one is terminated by the
// default exception handler.
for (i=0; i<16; i++) {
if (handlers[i]) {
struct exHandler *eh = handlers[i];
while(eh->next){
struct exHandler *p_handler = (struct exHandler *)(eh->info & ~3);
struct exHandler *p_next_handler = (struct exHandler *)(((struct exHandler *)(eh->next))->info & ~3);
p_handler->next = (void*)p_next_handler + 8;
eh = eh->next;
}
{
struct exHandler *p_handler = (struct exHandler *)(eh->info & ~3);
p_handler->next = defhandler;
}
}
}
for (i=0; i<16; i++) {
if (handlers[i]){
extable[i]=(void*)((handlers[i]->info & ~3) + 8);
} else {
extable[i]=defhandler;
}
}
}
//////////////////////////////entrypoint///////////////////////////////[00]
void Kputc(u8 c) {
*((u8*)0x1f80380c) = c;
}
void Kprintnum(unsigned int n)
{
int i = 0;
while(i < 8) {
u32 a = n>>28;
if( a < 10 ) Kputc('0'+a);
else Kputc('a'+(a-10));
n <<= 4;
++i;
}
}
int _start() {
int *src, *dst;
int i;
_dprintf("%s\n", __FUNCTION__);
for (i=0; i<16; i++){
handlers[i] = NULL;
}
defhandler=NULL;
extable = (void*)0x440;
// Install the exception handler to address 0
for (src=(int*)iopException, dst=0; (u32)dst<0x100; src++, dst++){
*dst = *src;
}
RegisterDefaultExceptionHandler((struct exHandler *)&defaultEH);
RegisterLibraryEntries(&excepman_stub);
return 0;
}
///////////////////////////////////////////////////////////////////////[02]
int excepman_deinit(){
return 0;
}
///////////////////////////////////////////////////////////////////////[01]
int excepman_reinit() {
excepman_deinit();
return _start();
}
///////////////////////////////////////////////////////////////////////[04]
int RegisterExceptionHandler(int code, struct exHandler *handler)
{
return RegisterPriorityExceptionHandler(code, 2, handler);
}
// This is a pool of containers. They form a linked list. The info member of each points
// to a registered handler.
struct exHandler _list[32];
struct exHandler *list = NULL;
void link(struct exHandler *e) {
e->next = list;
list = e;
}
struct exHandler *unlink() {
struct exHandler *e;
if (list == NULL) {
int i;
list = _list;
for (i=0; i<31; i++) {
list[i].next = &list[i+1];
}
list[i].next = 0;
}
e = list;
list = e->next;
return e;
}
///////////////////////////////////////////////////////////////////////[05]
int RegisterPriorityExceptionHandler(int code, int priority, struct exHandler *handler)
{
struct exHandler *n, *p, *p_prev;
_dprintf("%s: code = %d, pri = %d, (handler=%x)\n", __FUNCTION__, code, priority, handler);
if (code >= 16){
_dprintf("%s ERROR_BAD_EXCODE\n", __FUNCTION__);
return ERROR_BAD_EXCODE;
}
if (handler->next){
_dprintf("%s ERROR_USED_EXCODE\n", __FUNCTION__);
return ERROR_USED_EXCODE;
}
n = unlink();
priority &= 3;
n->info = ((u32)handler & ~3) | priority;
n->next = NULL;
p = handlers[code]; p_prev = NULL;
// walk along the chain starting at the handlers[code] root to find our place in the queue
while(p && ((p->info & 3) < priority)){
p_prev = p; p = p->next;
}
n->next = p;
if (p_prev == NULL){
handlers[code] = n;
} else {
p_prev->next = n;
}
registerEH();
return 0;
}
///////////////////////////////////////////////////////////////////////[06]
int RegisterDefaultExceptionHandler(struct exHandler *handler)
{
_dprintf("%s\n", __FUNCTION__);
if (handler->next){
_dprintf("%s ERROR_USED_EXCODE\n", __FUNCTION__);
return ERROR_USED_EXCODE;
}
handler->next = defhandler;
defhandler = &handler->funccode;
registerEH();
return 0;
}
///////////////////////////////////////////////////////////////////////[07]
int ReleaseExceptionHandler(int code, struct exHandler *handler)
{
struct exHandler *p, *p_prev;
_dprintf("%s: %d\n", __FUNCTION__, code);
if (code>=16) return ERROR_BAD_EXCODE;
p_prev = NULL;
for (p=handlers[code]; p != NULL; p_prev = p, p=p->next) {
if ((struct exHandler *)(p->info & ~3) == handler) {
// found it
// Mark the handler as no longer used
((struct exHandler *)(p->info & ~3))->next = NULL;
if (p == handlers[code]){
// special case, no more list
handlers[code] = NULL;
} else {
// Remove container p from the list
p_prev->next = p->next;
}
link(p); // Add the container back to the pool
registerEH();
return 0;
}
}
return ERROR_EXCODE_NOTFOUND;
}
///////////////////////////////////////////////////////////////////////[08]
int ReleaseDefaultExceptionHandler(struct exHandler *handler)
{
struct exHandler *p;
_dprintf("%s\n", __FUNCTION__);
for (p=defhandler; p->next; p=p->next-8) {
if (p->next == handler->funccode) {
p->next = handler->next;
handler->next = 0;
registerEH();
return 0;
}
}
return ERROR_EXCODE_NOTFOUND;
}
///////////////////////////////////////////////////////////////////////[03]
void *GetExHandlersTable()
{
return extable;
}
// 256 bytes of this code are copied to memory address 0 in order to install the exception handling code.
// Take careful note of the alignment of the code at 0x40 and 0x80 if you change it at all.
void iopException() {
__asm__ (
".set noat\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
/* 0x0040 */
/* This the breakpoint exception vector location. */
"sw $26, 0x0420($0)\n"
"mfc0 $27, $14\n"
"mfc0 $26, $13\n"
"sw $27, 0x0424($0)\n"
"sw $26, 0x0428($0)\n"
"mfc0 $27, $12\n"
"mfc0 $26, $7\n"
"sw $27, 0x042C($0)\n"
"sw $26, 0x0430($0)\n"
"lw $27, 0x047C($0)\n"
"mtc0 $0, $7\n"
"jr $27\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
/* 0x0080 */
/* This is the general exception vector location. */
"sw $1, 0x0400($0)\n" /* $1 saved at 0x400 */
"sw $26, 0x0410($0)\n" /* $26 saved at 0x410 */
"mfc0 $1, $14\n"
"mfc0 $26, $12\n"
"sw $1 , 0x0404($0)\n" /* EPC -> 0x404 */
"sw $26, 0x0408($0)\n" /* STATUS -> 0x408 */
"mfc0 $1, $13\n"
"sw $1, 0x040C($0)\n" /* CAUSE -> 0x40C */
"andi $1, 0x3C\n" /* Isolate EXECODE */
"lw $1, 0x0440($1)\n"
"jr $1\n" /* jump via EXECODE table at 0x440 */
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\n"
".set at\n"
);
}

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/HEAPLIB
IOP_INCS += -I../include
IOP_OBJS = heaplib.o ../iopdebug.o ../libkernel/iop_loadcore.o ../libkernel/iop_sysmem.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,206 +0,0 @@
//[module] HEAPLIB
//[processor] IOP
//[type] ELF-IRX
//[name] Heap_lib
//[version] 0x101
//[memory map] -
//[handlers] -
//[entry point] heaplib_start, heaplib_stub
//[made by] [RO]man (roman_ps2dev@hotmail.com) 26 January 2003
#include "sysmem.h"
#include "kloadcore.h"
#include "kheaplib.h"
#include "iopdebug.h"
static int debug=1;
#define _dprintf(fmt, args...) \
if (debug > 0) __printf("\033[0;32m" "heaplib: " "\033[0m" fmt, ## args)
int _start(int argc, char* argv[]);
///////////////////////////////////////////////////////////////////////
void ll_reset(struct ll *l){
l->prev=l->next=l;
}
///////////////////////////////////////////////////////////////////////
int ll_one(struct ll *l){
return (l == l->next);
// return (l ^ l->next) < 1; //l==l->next
}
///////////////////////////////////////////////////////////////////////
void ll_remove(struct ll *l){
l->next->prev=l->prev;
l->prev->next=l->next;
}
///////////////////////////////////////////////////////////////////////
/*int ll_one_two(struct ll *l){
return (l->prev ^ l->next) < 1; //l->prev==l->next
}*/
///////////////////////////////////////////////////////////////////////
void ll_add(struct ll *l, struct ll *n){
n->next=l;
n->prev=l->prev;
l->prev=n;
n->prev->next=n;
}
void HeapPrepare(void *mem, int size) {
struct Chunk *_chunk = (struct Chunk*)mem;
if (mem == NULL || size < 41) return;
_chunk->_mem=(long)mem-1;
_chunk->freesize=size;
_chunk->usedsize=0;
_chunk->mem_16 = (u32)mem+16;
_chunk->unk5=((size-16)>>3)-1;
_chunk->unk4=(long)_chunk+8+((size-16)&~7);
((struct ll*)_chunk->unk4)->next=(void*)_chunk->mem_16;
((struct ll*)_chunk->unk4)->prev=0;
}
int HeapChunkSize(void *chunk) {
// int size = (chunk[1] - 16) >> 3;
// return ((size - chunk[2]) - 1) << 3;
}
///////////////////////////////////////////////////////////////////////
void* CreateHeap(int chunkSize, int memoryType){
struct Heap *_heap;
_dprintf("%s\n", __FUNCTION__);
chunkSize = (chunkSize+3) & ~3;
_heap = AllocSysMemory(memoryType & 2 ? ALLOC_LAST : ALLOC_FIRST, chunkSize, NULL);
if (_heap == NULL) return NULL;
_heap->plus_one=(long)_heap + 1;
if (memoryType & 1) _heap->size2free=chunkSize;
else _heap->size2free=0;
_heap->size2free |= ((memoryType>>1) & 1);
ll_reset(&_heap->l);
HeapPrepare(&_heap->mem, chunkSize-4*sizeof(int));
return (void*)_heap;
}
///////////////////////////////////////////////////////////////////////
int DestroyHeap(void *heap){
register struct ll *tmp, *p;
struct Heap *_heap = (struct Heap*)heap;
if (_heap->plus_one != (long)_heap+1) return (long)_heap+1;
_heap->plus_one=0;
for (p=&_heap->l; p != &_heap->l; p=tmp){
tmp=p->next;
((int*)p)[2]=0; //p->mem
FreeSysMemory(p);
}
_heap->mem=0;
return FreeSysMemory(_heap);
}
///////////////////////////////////////////////////////////////////////
void* HeapMalloc(void *heap, int size) {
#if 0
struct Heap *_heap = (struct Heap*)heap;
void *p;
if (_heap->plus_one != (long)_heap+1) return NULL;
for (;;) {
p = HeapChunk13((u32)_heap->l.next+8, size);
if (p != NULL) return p;
if (_heap->l.next->next == _heap->l.next) break;
}
#endif
}
int HeapFree(void *heap, void *mem) {
struct Heap *_heap = (struct Heap*)heap;
struct Heap *h;
if (heap == NULL ||
_heap->plus_one != (long)_heap+1) return -4;
for (h = (struct Heap*)_heap->l.next; h != &_heap->l; h = (struct Heap*)h->l.next) {
if (HeapChunk14(h->l, mem) != NULL) continue;
break;
}
if ((struct ll*)h == &_heap->l) return 0;
if (HeapChunk12() == 0) return 0;
ll_one(h);
h->l.next = 0;
FreeSysMemory(h);
return 0;
}
int HeapSize(void *heap) {
struct Heap *_heap = (struct Heap*)heap;
if (heap == NULL ||
_heap->plus_one != (long)_heap+1) return -4;
for (;; _heap = _heap->plus_one) {
if (_heap->l.next == &_heap->l)
break;
}
return HeapChunkSize(_heap->l.next+8);
}
void HeapChunk12() {
}
void HeapChunk13() {
}
void HeapChunk14() {
}
///////////////////////////////////////////////////////////////////////
void _retonly(){}
struct export heaplib_stub={
0x41C00000,
0,
VER(1, 1), // 1.1 => 0x101
0,
"heaplib",
(func)_start, // entrypoint
(func)_retonly,
(func)_retonly,
(func)_retonly,
(func)CreateHeap,
(func)DestroyHeap,
(func)HeapMalloc,
(func)HeapFree,
(func)HeapSize,
(func)_retonly,
(func)_retonly,
(func)HeapPrepare,
(func)HeapChunk12,
(func)HeapChunk13,
(func)HeapChunk14,
(func)HeapChunkSize,
(func)_retonly,
(func)_retonly,
0
};
//////////////////////////////entrypoint///////////////////////////////
int _start(int argc, char* argv[]){
return RegisterLibraryEntries(&heaplib_stub);
}

View File

@ -1,30 +0,0 @@
#ifndef __ERR_H__
#define __ERR_H__
//#define ERR_VER 0x
#define ERROR_OK 0
#define ERROR_UNK -1
//bad exception code
#define ERROR_BAD_EXCODE -50
//no exception handler for that code
#define ERROR_EXCODE_NOTFOUND -51
//already used
#define ERROR_USED_EXCODE -52
#define ERROR_INTR_CONTEXT -100
#define ERROR_DOES_EXIST -104
#define ERROR_DOESNOT_EXIST -105
#define ERROR_NO_TIMER -150
#define ERROR_NOT_IRX -201
#define ERROR_FILE_NOT_FOUND -203
#define ERROR_FILE_ERROR -204
#define ERROR_NO_MEM -400
#define ERROR_SEMACOUNT_ZERO -400
// what should these be? Used in intrman.c
#define ERROR_ILLEGAL_INTRCODE ERROR_UNK
#define ERROR_CPUDI ERROR_UNK
#endif//__ERR_H__

View File

@ -1,143 +0,0 @@
/* errno is not a global variable, because that would make using it
non-reentrant. Instead, its address is returned by the function
__errno. */
#ifndef _SYS_ERRNO_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _SYS_ERRNO_H_
#define EPERM 1 /* Not super-user */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No children */
#define EAGAIN 11 /* No more processes */
#define ENOMEM 12 /* Not enough core */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Mount device busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* Too many open files in system */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math arg out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define ENOMSG 35 /* No message of desired type */
#define EIDRM 36 /* Identifier removed */
#define ECHRNG 37 /* Channel number out of range */
#define EL2NSYNC 38 /* Level 2 not synchronized */
#define EL3HLT 39 /* Level 3 halted */
#define EL3RST 40 /* Level 3 reset */
#define ELNRNG 41 /* Link number out of range */
#define EUNATCH 42 /* Protocol driver not attached */
#define ENOCSI 43 /* No CSI structure available */
#define EL2HLT 44 /* Level 2 halted */
#define EDEADLK 45 /* Deadlock condition */
#define ENOLCK 46 /* No record locks available */
#define EBADE 50 /* Invalid exchange */
#define EBADR 51 /* Invalid request descriptor */
#define EXFULL 52 /* Exchange full */
#define ENOANO 53 /* No anode */
#define EBADRQC 54 /* Invalid request code */
#define EBADSLT 55 /* Invalid slot */
#define EDEADLOCK 56 /* File locking deadlock error */
#define EBFONT 57 /* Bad font file fmt */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data (for no delay io) */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* The object is remote */
#define ENOLINK 67 /* The link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 74 /* Multihop attempted */
#define ELBIN 75 /* Inode is remote (not really error) */
#define EDOTDOT 76 /* Cross mount point (not really error) */
#define EBADMSG 77 /* Trying to read unreadable message */
#define EFTYPE 79 /* Inappropriate file type or format */
#define ENOTUNIQ 80 /* Given log. name not unique */
#define EBADFD 81 /* f.d. invalid for this operation */
#define EREMCHG 82 /* Remote address changed */
#define ELIBACC 83 /* Can't access a needed shared lib */
#define ELIBBAD 84 /* Accessing a corrupted shared lib */
#define ELIBSCN 85 /* .lib section in a.out corrupted */
#define ELIBMAX 86 /* Attempting to link in too many libs */
#define ELIBEXEC 87 /* Attempting to exec a shared library */
#define ENOSYS 88 /* Function not implemented */
#define ENMFILE 89 /* No more files */
#define ENOTEMPTY 90 /* Directory not empty */
#define ENAMETOOLONG 91 /* File or path name too long */
#define ELOOP 92 /* Too many symbolic links */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
#define EPROTOTYPE 107 /* Protocol wrong type for socket */
#define ENOTSOCK 108 /* Socket operation on non-socket */
#define ENOPROTOOPT 109 /* Protocol not available */
#define ESHUTDOWN 110 /* Can't send after socket shutdown */
#define ECONNREFUSED 111 /* Connection refused */
#define EADDRINUSE 112 /* Address already in use */
#define ECONNABORTED 113 /* Connection aborted */
#define ENETUNREACH 114 /* Network is unreachable */
#define ENETDOWN 115 /* Network interface is not configured */
#define ETIMEDOUT 116 /* Connection timed out */
#define EHOSTDOWN 117 /* Host is down */
#define EHOSTUNREACH 118 /* Host is unreachable */
#define EINPROGRESS 119 /* Connection already in progress */
#define EALREADY 120 /* Socket already connected */
#define EDESTADDRREQ 121 /* Destination address required */
#define EMSGSIZE 122 /* Message too long */
#define EPROTONOSUPPORT 123 /* Unknown protocol */
#define ESOCKTNOSUPPORT 124 /* Socket type not supported */
#define EADDRNOTAVAIL 125 /* Address not available */
#define ENETRESET 126
#define EISCONN 127 /* Socket is already connected */
#define ENOTCONN 128 /* Socket is not connected */
#define ETOOMANYREFS 129
#define EPROCLIM 130
#define EUSERS 131
#define EDQUOT 132
#define ESTALE 133
#define ENOTSUP 134 /* Not supported */
#define ENOMEDIUM 135 /* No medium (in tape drive) */
#define ENOSHARE 136 /* No such host or network path */
#define ECASECLASH 137 /* Filename exists with different case */
#define EILSEQ 138
#define EOVERFLOW 139 /* Value too large for defined data type */
/* From cygwin32. */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define __ELASTERROR 2000 /* Users can add values starting here */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_ERRNO_H */

View File

@ -1,11 +0,0 @@
#ifndef __IOPDEBUG_H__
#define __IOPDEBUG_H__
#include <tamtypes.h>
void __putc(u8 c);
void __puts(u8 *s);
void __printf(char *fmt, ...);
#endif /* __IOPDEBUG_H__ */

View File

@ -1,226 +0,0 @@
#ifndef __IOPELF_H__
#define __IOPELF_H__
#include "romdir.h"
#define MOD_TYPE_REL 1
#define MOD_TYPE_2 2
#define MOD_TYPE_DYN 3
#define MOD_TYPE_CORE 4
typedef struct {
char *name;
short version;
} moduleInfo;
// info about a module file
typedef struct module_info {
int type; // module type (MOD_TYPE_*)
int (*entry)(void*);// module entry point address
int gpValue; // module gp value
int progVAddr; // programs virtual address
int textSize; // size of text section
int dataSize; // size of data section
int bssSize; // size of bss section
int progMemSize; // size of program memory
int moduleInfo; // info about module ?
} MODULE_INFO;
typedef struct {
u32 ei_magic;
u8 ei_class;
u8 ei_data;
u8 ei_version;
u8 ei_pad[9];
} E_IDENT;
typedef struct {
u8 e_ident[16]; //+00 0x7f,"ELF" (ELF file identifier), E_IDENT*
u16 e_type; //+10 ELF type: 0=NONE, 1=REL, 2=EXEC, 3=SHARED, 4=CORE
u16 e_machine; //+12 Processor: 8=MIPS R3000
u32 e_version; //+14 Version: 1=current
u32 e_entry; //+18 Entry point address
u32 e_phoff; //+1C Start of program headers (offset from file start)
u32 e_shoff; //+20 Start of section headers (offset from file start)
u32 e_flags; //+24 Processor specific flags = 0x20924001 noreorder, mips
u16 e_ehsize; //+28 ELF header size (0x34 = 52 bytes)
u16 e_phentsize; //+2A Program headers entry size
u16 e_phnum; //+2C Number of program headers
u16 e_shentsize; //+2E Section headers entry size
u16 e_shnum; //+30 Number of section headers
u16 e_shstrndx; //+32 Section header stringtable index
} ELF_HEADER; //+34=sizeof
#define ET_SCE_IOPRELEXEC 0xFF80
#define PT_SCE_IOPMOD 0x70000080
#define SHT_REL 9
#define EM_MIPS 8
typedef struct tag_COFF_AOUTHDR {
short magic; //+00
short vstamp; //+02
int tsize; //+04
int dsize; //+08
int bsize; //+0C
int entry; //+10
int text_start; //+14
int data_start; //+18
int bss_start; //+1C
int field_20; //+20
int field_24; //+24
int field_28; //+28
int field_2C; //+2C
int moduleinfo; //+30
int gp_value; //+34
} COFF_AOUTHDR, COHDR; //=38
typedef struct tag_CHDR{
short f_magic; //+00
short f_nscns; //+02
int f_timdat; //+04
int f_symptr; //+08
int f_nsyms; //+0C
short f_opthdr; //+10
short f_flags; //+12
} CHDR; //=14
typedef struct tag_COFF_HEADER{ //same header as above
short f_magic; //+00
short f_nscns; //+02
int f_timdat; //+04
int f_symptr; //+08
int f_nsyms; //+0C
short f_opthdr; //+10
short f_flags; //+12
COFF_AOUTHDR opthdr; //+14
} COFF_HEADER; //=4C
typedef struct tag_COFF_scnhdr
{
char s_name[8]; //+00
int s_paddr; //+08
int s_vaddr; //+0C
int s_size; //+10
int s_scnptr; //+14
int s_relptr; //+18
int s_lnnoptr; //+1C
short s_nreloc; //+20
short s_nlnno; //+22
int s_flags; //+24
} COFF_scnhdr, SHDR; //=28
typedef struct _fileInfo
{
u32 type, //+00
entry, //+04
gp_value, //+08
p1_vaddr, //+0C
text_size, //+10
data_size, //+14
bss_size, //+18
p1_memsz; //+1C
moduleInfo *moduleinfo; //+20
} fileInfo;
typedef struct {
u32 p_type; //+00 see notes1
u32 p_offset; //+04 Offset from file start to program segment.
u32 p_vaddr; //+08 Virtual address of the segment
u32 p_paddr; //+0C Physical address of the segment
u32 p_filesz; //+10 Number of bytes in the file image of the segment
u32 p_memsz; //+14 Number of bytes in the memory image of the segment
u32 p_flags; //+18 Flags for segment
u32 p_align; //+1C Alignment. The address of 0x08 and 0x0C must fit this alignment. 0=no alignment
} ELF_PHR;
//notes1
//------
//0=Inactive
//1=Load the segment into memory, no. of bytes specified by 0x10 and 0x14
//2=Dynamic linking
//3=Interpreter. The array element must specify a path name
//4=Note. The array element must specify the location and size of aux. info
//5=reserved
//6=The array element must specify location and size of the program header table.
typedef struct {
u32 r_offset;
u32 r_info;
} ELF_REL;
typedef struct {
char* moduleinfo;
u32 entry; //+04
u32 gp_value; //+08
u32 text_size; //+0C
u32 data_size; //+10
u32 bss_size;//+14
short moduleversion;//+18
char* modulename; //+1A
} ELF_IOPMOD;
typedef struct {
u32 sh_name; //+00 No. to the index of the Section header stringtable index
u32 sh_type; //+04 See notes2
u32 sh_flags; //+08 see notes3
u32 sh_addr; //+0C Section start address
u32 sh_offset; //+10 Offset from start of file to section
u32 sh_size; //+14 Size of section
u32 sh_link; //+18 Section header table index link
u32 sh_info; //+1C Info
u32 sh_addralign; //+20 Alignment. The adress of 0x0C must fit this alignment. 0=no alignment.
u32 sh_entsize; //+24 Fixed size entries.
} ELF_SHR;
//notes 2
//-------
//Type:
//0=Inactive
//1=PROGBITS
//2=SYMTAB symbol table
//3=STRTAB string table
//4=RELA relocation entries
//5=HASH hash table
//6=DYNAMIC dynamic linking information
//7=NOTE
//8=NOBITS
//9=REL relocation entries
//10=SHLIB
//0x70000000=LOPROC processor specifc
//0x7fffffff=HIPROC
//0x80000000=LOUSER lower bound
//0xffffffff=HIUSER upper bound
//
//notes 3
//-------
//Section Flags: (1 bit, you may combine them like 3 = alloc & write permission)
//1=Write section contains data the is be writeable during execution.
//2=Alloc section occupies memory during execution
//4=Exec section contains executable instructions
//0xf0000000=Mask bits processor-specific
#define ELF32_ST_TYPE(i) ((i)&0xf)
// special header for every iop module?
typedef struct {
u32 next; //+00
char *name; //+04
short version, //+08
flags, //+0A
modid, //+0C
HE; //+0E
u32 entry, //+10
gp_value, //+14
p1_vaddr, //+18
text_size, //+1C
data_size, //+20
bss_size, //+24
H28, //+28
H2C; //+2C
} imageInfo;
// pass in the memory to load the elf file from
// elfoffset - offset to load elf file to
void* loadElfFile(ROMFILE_INFO* ri, u32 elfoffset);
#endif

View File

@ -1,18 +0,0 @@
#ifndef __IOPLOAD_H__
#define __IOPLOAD_H__
#include <tamtypes.h>
extern char *iopModules[32];
void Kmemcpy(void *dest, const void *src, int n);
#define SBUS_MSFLG *(volatile int*)0xBD00F220
#define SBUS_SMFLG *(volatile int*)0xBD00F230
#define SBUS_F240 *(volatile int*)0xBD00F240
#define SBFLG_IOPALIVE 0x10000
#define SBFLG_IOPSYNC 0x40000
#endif /* __IOPLOAD_H__ */

View File

@ -1,116 +0,0 @@
#ifndef __DMACMAN_H__
#define __DMACMAN_H__
#define DMACMAN_VER 0x101
////////////////////////////// D_CHCR - DMA Channel Control Register
#define DMAf_30 0x40000000 // unknown; set on 'to' direction
#define DMAf_TR 0x01000000 // DMA transfer
#define DMAf_LI 0x00000400 // Linked list GPU; also SPU & SIF0
#define DMAf_CO 0x00000200 // Continuous stream
#define DMAf_08 0x00000100 // unknown
#define DMAf_DR 0x00000001 // Direction to=0/from=1
// 31 24 23 16 15 8 7 0
// ÖÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ·
// º ³?³ ³ ³ ³ ³ ³Tº ³ ³ ³ ³ ³ ³ ³ º ³ ³ ³ ³ ³L³C³?º ³ ³ ³ ³ ³ ³ ³Dº
// º ³?³ ³ ³ ³ ³ ³Rº ³ ³ ³ ³ ³ ³ ³ º ³ ³ ³ ³ ³I³O³?º ³ ³ ³ ³ ³ ³ ³Rº
// ÓÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁĽ
// 30 24 10 9 8 0
////////////////////////////// DPCR - DMA Primary Control Register
// ÖÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ·
// º 67 ³ DMA 6 º DMA 5 ³ DMA 4 º DMA 3 ³ DMA 2 º DMA 1 ³ DMA 0 º 0xBF8010F0 DPCR
// ÓÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁĽ
// ÖÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ·
// º ³ DMA85 º DMA12 ³ DMA11 º DMA10 ³ DMA 9 º DMA 8 ³ DMA 7 º 0xBF801570 DPCR_
// ÓÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁĽ
// ÖÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄÒÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ·
// º ³ º ³ º ³ DMA15 º DMA14 ³ DMA13 º 0xBF8015F0 DPCR__
// ÓÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁÄÐÄÁÄÁÄÁÄÁÄÁÄÁÄÁĽ
////////// DPCR
#define DMAch_MDECin 0
#define DMAch_MDECout 1
#define DMAch_GPU 2 // SIF2 both directions
#define DMAch_CD 3
#define DMAch_SPU 4
#define DMAch_PIO 5
#define DMAch_GPUotc 6
#define DMAch_67 67 // strange
////////// DPCR_
#define DMAch_SPU2 7
#define DMAch_8 8
#define DMAch_SIF0 9 // SIFout IOP->EE
#define DMAch_SIF1 10 // SIFin EE->IOP
#define DMAch_SIO2in 11
#define DMAch_SIO2out 12
#define DMAch_85 85 // stange, very strange
////////// DPCR__
#define DMAch_13 13
#define DMAch_14 14
#define DMAch_15 15
int dmacman_start(int argc, char* argv[]); // 0
int dmacman_deinit(); // 2
void dmacman_call4_SetD_MADR(unsigned int ch, int value); // 4
int dmacman_call5_GetD_MADR(unsigned int ch); // 5
void dmacman_call6_SetD_BCR(unsigned int ch, int value); // 6
int dmacman_call7_GetD_BCR(unsigned int ch); // 7
void dmacman_call8_SetD_CHCR(unsigned int ch, int value); // 8
int dmacman_call9_GetD_CHCR(unsigned int ch); // 9
void dmacman_call10_SetD_TADR(unsigned int ch, int value); //10
int dmacman_call11_GetD_TADR(unsigned int ch); //11
void dmacman_call12_Set_4_9_A(unsigned int ch, int value); //12
int dmacman_call13_Get_4_9_A(unsigned int ch); //13
void dmacman_call14_SetDPCR(int value); //14
int dmacman_call15_GetDPCR(); //15
void dmacman_call16_SetDPCR2(int value); //16
int dmacman_call17_GetDPCR2(); //17
void dmacman_call18_SetDPCR3(int value); //18
int dmacman_call19_GetDPCR3(); //19
void dmacman_call20_SetDICR(int value); //20
int dmacman_call21_GetDICR(); //21
void dmacman_call22_SetDICR2(int value); //22
int dmacman_call23_GetDICR2(); //23
void dmacman_call24_setBF80157C(int value); //24
int dmacman_call25_getBF80157C(); //25
void dmacman_call26_setBF801578(int value); //26
int dmacman_call27_getBF801578(); //27
int dmacman_call28_SetDMA(int ch, int address, int size, int count, int dir); //28
int dmacman_call29_SetDMA_chainedSPU_SIF0(int ch, int size, int c);//29
int dmacman_call30_SetDMA_SIF0(int ch, int size, int c); //30
int dmacman_call31_SetDMA_SIF1(int ch, int size); //31
void dmacman_call32_StartTransfer(int ch); //32
void dmacman_call33_SetVal(int ch, int value); //33
void dmacman_call34_EnableDMAch(int ch); //34
void dmacman_call35_DisableDMAch(int ch); //35
//SIF2 DMA ch 2 (GPU)
#define DMAch_SIF2_MADR (*(volatile int*)0xBF8010A0)
#define DMAch_SIF2_BCR (*(volatile int*)0xBF8010A4)
#define DMAch_SIF2_BCR_size (*(volatile short*)0xBF8010A4)
#define DMAch_SIF2_BCR_count (*(volatile short*)0xBF8010A6)
#define DMAch_SIF2_CHCR (*(volatile int*)0xBF8010A8)
//SIF0 DMA ch 9
#define DMAch_SIF9_MADR (*(volatile int*)0xBF801520)
#define DMAch_SIF9_BCR (*(volatile int*)0xBF801524)
#define DMAch_SIF9_BCR_size (*(volatile short*)0xBF801524)
#define DMAch_SIF9_BCR_count (*(volatile short*)0xBF801526)
#define DMAch_SIF9_CHCR (*(volatile int*)0xBF801528)
#define DMAch_SIF9_TADR (*(volatile int*)0xBF80152C)
//SIF1 DMA ch 10 (0xA)
#define DMAch_SIFA_MADR (*(volatile int*)0xBF801530)
#define DMAch_SIFA_BCR (*(volatile int*)0xBF801534)
#define DMAch_SIFA_BCR_size (*(volatile short*)0xBF801534)
#define DMAch_SIFA_BCR_count (*(volatile short*)0xBF801536)
#define DMAch_SIFA_CHCR (*(volatile int*)0xBF801538)
#define DMAch_DPCR (*(volatile int*)0xBF8010F0)
#define DMAch_DPCR2 (*(volatile int*)0xBF801570)
#endif//__DMACMAN_H__

View File

@ -1,23 +0,0 @@
#ifndef __EXCEPMAN_H__
#define __EXCEPMAN_H__
#define EXCEPMAN_VER 0x101
#define EXCEP_MAX 16
struct exHandler {
void *next; // next points to the next funccode :/
int info;
u32 funccode[0];
};
void *GetExHandlersTable(); // 3
int RegisterExceptionHandler(int code, struct exHandler *handler); // 4
int RegisterPriorityExceptionHandler(int code, int priority,
struct exHandler *handler); // 5
int RegisterDefaultExceptionHandler(struct exHandler *handler); // 6
int ReleaseExceptionHandler(int excode, struct exHandler *handler); // 7
int ReleaseDefaultExceptionHandler(struct exHandler *handler); // 8
#endif//__EXCEPMAN_H__

View File

@ -1,30 +0,0 @@
#ifndef __HEAPLIB_H__
#define __HEAPLIB_H__
struct ll{ struct ll *next, *prev; }; //linked list
struct Heap {
long plus_one;
int size2free;
struct ll l;
void *mem;
};
struct Chunk {
u32 _mem;
int freesize;
int usedsize;
u32 mem_16;
u32 unk4;
u32 unk5;
};
void *CreateHeap(int chunkSize, int memoryType );
int DestroyHeap(void *heap);
void *HeapMalloc(void *heap, int size);
int HeapFree(void *heap, void * mem);
int HeapSize(void *heap);
#endif /* __HEAPLIB_H__ */

View File

@ -1,38 +0,0 @@
#ifndef __INTRMAN_H__
#define __INTRMAN_H__
#define INTRMAN_VER 0x102
#define INT_VBLANK 0x00
#define INT_CDROM 0x02
#define INT_RTC0 0x04
#define INT_RTC1 0x05
#define INT_RTC2 0x06
#define INT_EVBLANK 0x0B
#define INT_RTC3 0x0E
#define INT_RTC4 0x0F
#define INT_RTC5 0x10
#define INT_DMA9 0x2A //sif0
#define INT_DMA10 0x2B //sif1
#define IMODE_DMA_IRM 0x100
#define IMODE_DMA_IQE 0x200
typedef int (*intrh_func)(void*);
int RegisterIntrHandler(int interrupt, int, intrh_func intrh, void*);
//4 (13,18)
int ReleaseIntrHandler(int interrupt); //5 (18)
int EnableIntr(int interrupt); //6 (13,18)
int DisableIntr(int interrupt, int *oldstat); //7 (18)
int CpuEnableIntr(); //9 (18,21,26)
int CpuSuspendIntr(u32* ictrl); //17(05,06,07,13,14,18,26)
int CpuResumeIntr(u32 ictrl); //18(05,06,07,13,14,18,26)
int QueryIntrContext(); //23(07,13)
#endif//__INTRMAN_H__

View File

@ -1,56 +0,0 @@
#ifndef __IOMAN_H__
#define __IOMAN_H__
#define IOMAN_VER 0x102
#define STDIN 0
#define STDOUT 1
struct ioman_FUNCS{
int init(struct ioman_DRV *drv); //00
void term(struct ioman_DRV *drv); //01
int format(char *filename); //02
int open(int fd, char *filename, int flag); //03
int close(int fd); //04
int read(int fd, void *buf, int nbyte); //05
int write(int fd, void *buf, int nbyte); //06
int lseek(int fd, int offset, int whence); //07
int ioctl(int fd, int request, int arg); //08
int remove(char *filename); //09
int mkdir(char *filename); //10
int rmdir(char *filename); //11
int dopen(char *filename); //12
int dclose(int fd); //13
int dread(int fd, void *buf); //14
int getstat(char *filename, void *buf); //15
int chstat(char *filename, void *buf, unsigned int mask); //16
};
struct ioman_DRV{ //struct fileio_driver from ps2lib
char *driver; //+00
int unk1; //+04
int version; //+08
char *description; //+0C
struct ioman_FUNCS *f_list; //+10
}; //=14
int open(char *filename, int flag); // 4(26)
int close(int fd); // 5(26)
int read(int fd, void *buf, long count); // 6(17,26)
int write(int fd, void *buf, long count); // 7(17,26)
int lseek(int fd, int offset, int whence); // 8(26)
int ioctl(int fd, int request, int arg); // 9(26)
int remove(char *filename); //10(26)
int mkdir(char *filename); //11(26)
int rmdir(char *filename); //12(26)
int dopen(char *filename); //13(26)
int dclose(int fd); //14(26)
int dread(int fd, void *buf); //15(26)
int getstat(char *filename, void *buf); //16(26)
int chstat(char *filename, void *buf, unsigned int mask); //17(26)
int format(char *filename); //18(26)
int AddDrv(struct ioman_DRV *drv); //20(26)
int DelDrv(char *device); //21(26)
#endif//__IOMAN_H__

View File

@ -1,89 +0,0 @@
#ifndef __LOADCORE_H__
#define __LOADCORE_H__
#include <tamtypes.h>
#define LOADCORE_VER 0x101
typedef int (*func)();
#define VER(major, minor) ((((major) & 0xFF)<<8) + ((minor) & 0xFF))
#define MODULE_RESIDENT_END 0
#define MODULE_NO_RESIDENT_END 1
struct func_stub {
int jr_ra; //jump instruction
int addiu0; //addiu zero, number
};
// defined by irx.h in the sdk
//#define IMPORT_MAGIC 0x41E00000
//#define EXPORT_MAGIC 0x41C00000
#define FLAG_EXPORT_QUEUED 1
#define FLAG_IMPORT_QUEUED 2
#define FLAG_NO_AUTO_LINK 1
#define INS_JR 2
#define INS_ADDIU 9
#define INS_JR_RA 0x03E00008
#define INS_J 0x08000000
enum tag_BOOTUPCB_PRIO{
BOOTUPCB_FIRST = 0,
BOOTUPCB_RUN_UDNL = 1,
BOOTUPCB_NORMAL = 2,
BOOTUPCB_LAST = 3,
BOOTUPCB_PRIORITIES
} BOOTUPCB_PRIO;
struct import {
u32 magic; //0x41E00000
struct import *next;
short version; //mjmi (mj=major, mi=minor version numbers)
short flags; //=0
char name[8];
struct func_stub func[0]; //the last one is 0, 0 (i.e. nop, nop)
};
struct export {
u32 magic_link; //0x41C00000, prev
struct export *next;
short version; //mjmi (mj=major, mi=minor version numbers)
short flags; //=0
char name[8];
func func[45]; //usually module entry point (allways?)
// func1
// func2
// func3
// funcs // more functions: the services provided my module
};
struct bootmode {
short unk0;
char id;
char len;
int data[0];
};
typedef struct boot_params {
int ramMBSize; //+00/0 size of iop ram in megabytes (2 or 8)
int bootInfo; //+04/1 ==QueryBootMode(KEY_IOPbootinfo)
char* udnlString; //+08/2 points to the undl reboot string, NULL if no string
u32 firstModuleAddr;//+0C/3 the load address of the first module (sysmem)
int pos; //+10/4
int size; //+14/5
int numConfLines; //+18/6 number of lines in IOPBTCONF
u32** moduleAddrs; //+1C/7 pointer to an array of addresses to load modules from
} BOOT_PARAMS; //=20
void FlushIcache(); //4 (14)
void FlushDcache(); //5 (14,21,26)
int RegisterLibraryEntries(struct export*); //6 (05,06,07,13,14,17,18,28)
u32* QueryBootMode(int code); //12(11,21,25,26,28)
int loadcore_call20_registerFunc(int (*function)(int *, int), int a1, int *result);
//20(28)
#endif//__LOADCORE_H__

View File

@ -1,162 +0,0 @@
#ifndef __SIFCMD_H__
#define __SIFCMD_H__
#define SIFCMD_VER 0x101
#define SIF_CMDI_SYSTEM 0x80000000 // system function call
#define SIF_CMDC_CHANGE_SADDR ( SIF_CMDI_SYSTEM | 0x00000000)
#define SIF_CMDC_SET_SREG ( SIF_CMDI_SYSTEM | 0x00000001)
#define SIF_CMDC_INIT_CMD ( SIF_CMDI_SYSTEM | 0x00000002)
#define SIF_CMDC_RESET_CMD ( SIF_CMDI_SYSTEM | 0x00000003)
#define SIF_CMDC_RPC_END ( SIF_CMDI_SYSTEM | 0x00000008)
#define SIF_CMDC_RPC_BIND ( SIF_CMDI_SYSTEM | 0x00000009)
#define SIF_CMDC_RPC_CALL ( SIF_CMDI_SYSTEM | 0x0000000A)
#define SIF_CMDC_RPC_RDATA ( SIF_CMDI_SYSTEM | 0x0000000C)
typedef struct {
unsigned int psize:8; // packet size [16->112]
unsigned int dsize:24;// extra data size
unsigned int daddr; // extra data address
unsigned int fcode; // function code
unsigned int opt; // optional user parameter
} SifCmdHdr;
typedef int (*cmdh_func) (SifCmdHdr*, void*);
typedef void *(*rpch_func)(u32 code, void *param1, int param2);
typedef struct {
SifCmdHdr hdr;
void *newaddr;
} SifCmdCSData;
typedef struct {
SifCmdHdr chdr;
int rno;
unsigned int value;
} SifCmdSRData;
typedef struct {
SifCmdHdr chdr;
int size;
int flag;
char arg[80];
} SifCmdResetData;
struct sifcmd_RPC_SERVER_DATA{ //t_rpc_server_data
int command; /* 04 00 */
rpch_func func; /* 05 01 */
void *buff; /* 06 02 */
int size; /* 07 03 */
rpch_func cfunc; /* 08 04 */
void *cbuff; /* 09 05 */
int csize; /* 10 06 */
struct sifcmd_RPC_CLIENT_DATA*client; /* 11 07 */
void *pkt_addr; /* 12 08 */
int fno; /* 13 09 */
void *receive; /* 14 10 */
int rsize; /* 15 11 */
int rmode; /* 16 12 */
int rid; /* 17 13 */
struct sifcmd_RPC_SERVER_DATA*link; /* 18 14 */
struct sifcmd_RPC_SERVER_DATA*next; /* 19 15 */
struct sifcmd_RPC_DATA_QUEUE *base; /* 20 16 */
};
struct sifcmd_RPC_HEADER{ //t_rpc_header
void *pkt_addr; /* 04 00 */
u32 rpc_id; /* 05 01 */
int tid; /* 06 02 */
u32 mode; /* 07 03 */
};
struct sifcmd_RPC_CLIENT_DATA{ //t_rpc_client_data
struct sifcmd_RPC_HEADER hdr;
u32 command; /* 04 08 */
void *buff, /* 05 09 */
*cbuff; /* 06 10 */
void (*func)(void*); /* 07 11 */
void *param; /* 08 12*/
struct sifcmd_RPC_SERVER_DATA*server; /* 09 13 */
};
struct sifcmd_RPC_RECEIVE_DATA{ //t_rpc_receive_data
struct sifcmd_RPC_HEADER hdr;
void *src, /* 04 */
*dest; /* 05 */
int size; /* 06 */
};
struct sifcmd_RPC_DATA_QUEUE{ //t_rpc_data_queue
int key, /* 00 */
active; /* 01 */
struct sifcmd_RPC_SERVER_DATA*link, /* 02 */
*start, /* 03 */
*end; /* 04 */
struct sifcmd_RPC_DATA_QUEUE *next; /* 05 */
};
typedef struct {
SifCmdHdr hdr;
u32 rec_id;
void *paddr;
u32 pid;
} RPC_PACKET;
typedef struct {
RPC_PACKET packet;
struct sifcmd_RPC_CLIENT_DATA *client;
u32 command;
struct sifcmd_RPC_SERVER_DATA *server;
void *buff, *cbuff;
} RPC_PACKET_END;
typedef struct {
RPC_PACKET packet;
struct sifcmd_RPC_CLIENT_DATA *client;
u32 fno;
} RPC_PACKET_BIND;
typedef struct {
RPC_PACKET_BIND packet;
u32 size;
void *receive;
u32 rsize;
u32 rmode;
struct sifcmd_RPC_SERVER_DATA *server;
} RPC_PACKET_CALL;
typedef struct {
RPC_PACKET packet;
struct sifcmd_RPC_CLIENT_DATA *client;
void *src;
void *dst;
u32 size;
} RPC_PACKET_RDATA;
typedef struct {
cmdh_func func;
void *data;
} SifCmdData;
void SifInitCmd(); //4 (21)
void SifAddCmdHandler(int pos, cmdh_func func, void *data); //10(21)
void SifInitRpc(int mode); //14(26)
void SifRegisterRpc(struct sifcmd_RPC_SERVER_DATA *sd, u32 cmd,
rpch_func func, void *buff,
rpch_func cfunc, void *cbuff,
struct sifcmd_RPC_DATA_QUEUE *dq); //17(26)
void SifSetRpcQueue(struct sifcmd_RPC_DATA_QUEUE* dq, int thid); //19(26)
void SifRpcLoop(struct sifcmd_RPC_DATA_QUEUE* dq); //22(26)
int SifGetOtherData(struct sifcmd_RPC_RECEIVE_DATA *rd,
void *src, void *dst, int size, int mode); //23(26)
#endif//__SIFCMD_H__

View File

@ -1,57 +0,0 @@
#ifndef __SIFMAN_H__
#define __SIFMAN_H__
#include <tamtypes.h>
#define SIFMAN_VER 0x101
#define SIF_FROM_IOP 0x0
#define SIF_TO_IOP 0x1
#define SIF_FROM_EE 0x0
#define SIF_TO_EE 0x1
#define SIF_DMA_INT_I 0x2
#define SIF_DMA_INT_O 0x4
#define SIF_DMA_SPR 0x8
#define SIF_DMA_BSN 0x10
#define SIF_DMA_TAG 0x20
struct sifman_DMA { //t_sif_dma_transfer
void *data;
void *addr;
int size;
int attr;
};
void SifDeinit(); //2
void SifSIF2Init(); //4
void SifInit(); //5 (21,25,26)
void SifSetDChain(); //6
u32 SifSetDma(struct sifman_DMA* psd, int len); //7 (26)
int SifDmaStat(u32 id); //8 (26)
void SifSend(struct sifman_DMA sd); //9
void SifSendSync(); //10
int SifIsSending(); //11
void SifSetSIF0DMA(void *data, int size, int attr); //12
void SifSendSync0(); //13
int SifIsSending0(); //14
void SifSetSIF1DMA(void *data, int size, int attr); //15
void SifSendSync1(); //16
int SifIsSending1(); //17
void SifSetSIF2DMA(void *data, int size, int attr); //18
void SifSendSync2(); //19
int SifIsSending2(); //20
int SifGetEEIOPflags(); //21
int SifSetEEIOPflags(int val); //22(21)
int SifGetIOPEEflags(); //23
int SifSetIOPEEflags(int val); //24(28)
int SifGetEErcvaddr(); //25
int SifGetIOPrcvaddr(); //26
int SifSetIOPrcvaddr(int val); //27
void SifSet1450_2(); //28
int SifCheckInit(); //29(21,26)
void SifSet0CB(int (*_function)(int), int _param);//30
void SifReset0CB(); //31
#endif /* __SIFMAN_H__ */

View File

@ -1,21 +0,0 @@
#ifndef __STDIO_H__
#define __STDIO_H__
#define STDIO_VER 0x102
#define TAB 0x9 //\t
#define LF 0x10 //\n
#define CR 0x13 //\r
void printf(const char *format, ...); // 4(21,25,26)
int getchar(); // 5
//int putchar(int c); // 6
int puts(char *s); // 7
char *gets(char *s); // 8
int fdprintf(int fd, const char *format, ...); // 9
int fdgetc(int fd); //10
int fdputc(int c, int fd); //11
int fdputs(char *s, int fd); //12
char *fdgets(char *buf, int fd); //13
#endif//__STDIO_H__

View File

@ -1,46 +0,0 @@
#ifndef __SYSCLIB_H__
#define __SYSCLIB_H__
#define SYSCLIB_VER 0x101
#include <stddef.h>
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
extern const char _ctype_[];
#ifndef __cplusplus
#define isalpha(c) ((_ctype_+1)[(unsigned)(c)]&(_U|_L))
#define isupper(c) ((_ctype_+1)[(unsigned)(c)]&_U)
#define islower(c) ((_ctype_+1)[(unsigned)(c)]&_L)
#define isdigit(c) ((_ctype_+1)[(unsigned)(c)]&_N)
#define isxdigit(c) ((_ctype_+1)[(unsigned)(c)]&(_X|_N))
#define isspace(c) ((_ctype_+1)[(unsigned)(c)]&_S)
#define ispunct(c) ((_ctype_+1)[(unsigned)(c)]&_P)
#define isalnum(c) ((_ctype_+1)[(unsigned)(c)]&(_U|_L|_N))
#define isprint(c) ((_ctype_+1)[(unsigned)(c)]&(_P|_U|_L|_N|_B))
#define isgraph(c) ((_ctype_+1)[(unsigned)(c)]&(_P|_U|_L|_N))
#define iscntrl(c) ((_ctype_+1)[(unsigned)(c)]&_C)
#endif /* !__cplusplus */
#define isascii(c) ((unsigned)(c)<=0177)
#define toascii(c) ((c)&0177)
unsigned char look_ctype_table(int pos);
void* memset(void *s, int c, size_t n);
void bzero(void *s, size_t n);
int strcmp (const char *, const char *);
char* index (const char *s, int c);
int strlen (const char *);
char* strncpy(char *dest, const char *src, size_t n);
long int strtol(const char *nptr, char **endptr, int base);
//int prnt(void (*func)(void*, int), int *v, const char *format, ...); //18(17)
#endif//__SYSCLIB_H__

View File

@ -1,27 +0,0 @@
#ifndef __SYSMEM_H__
#define __SYSMEM_H__
#include <tamtypes.h>
#define SYSMEM_VER 0x101
//allocation strategies
#define ALLOC_FIRST 0
#define ALLOC_LAST 1
#define ALLOC_LATER 2
// see QueryBlockTopAddress, QueryBlockSize
#define USED 0x00000000
#define FREE 0x80000000
void *AllocSysMemory(int flags, int size, void *mem);//4 (11,26)
int FreeSysMemory(void *mem); //5 (26)
unsigned int QueryMemSize();
unsigned int QueryMaxFreeMemSize();
unsigned int QueryTotalFreeMemSize();
void *QueryBlockTopAddress(void *address);
int QueryBlockSize(void *address);
char *Kprintf(const char *format,...); //14(06,14,26)
void sysmem_call15_set_Kprintf(char* (*newKprintf)(unsigned int unk, const char*, ...), unsigned int newunk);
#endif //__SYSMEM_H__

View File

@ -1,19 +0,0 @@
#ifndef __THBASE_H__
#define __THBASE_H__
#define THBASE_VER 0x101
struct thbase_thread{
unsigned int attr;
unsigned int option;
int (*entry)();
unsigned int stackSize;
unsigned int initPriority;
};
int CreateThread(struct thbase_thread*); //4 (21,26) //returns thid
void StartThread(int thid, int); //6 (21,26)
int GetThreadId(); //20(26) //returns thid?
int GetSystemStatusFlag(); //41(13,21)
#endif//__THBASE_H__

View File

@ -1,17 +0,0 @@
#ifndef __THSEMAP_H__
#define __THSEMAP_H__
#define THSEMAP_VER 0x101
struct thsema_sema{
unsigned int attr;
unsigned int option;
int initCount;
int maxCount;
};
int CreateSema(struct thsema_sema* sema); // 4(15)
int SignalSema(int semaid); // 6(15)
int WaitSema(int semaid); // 8(15)
#endif//__THSEMAP_H__

View File

@ -1,48 +0,0 @@
#ifndef __TIMEMAN_H__
#define __TIMEMAN_H__
#define TIMEMAN_VER 0x101
//timids << 2; use AllocHardTimer or ReferHardTimer to get one
#define RTC0 0xBF801100
#define RTC1 0xBF801110
#define RTC2 0xBF801120
#define RTC3 0xBF801480
#define RTC4 0xBF801490
#define RTC5 0xBF8014A0
#define RTC_HOLDREGS 0xBF8014B0
#define RTC_HOLDMODE (*(volatile unsigned int*)0xBF8014C0)
//source
#define TC_SYSCLOCK 1
#define TC_PIXEL 2
#define TC_HLINE 4
#define TC_HOLD 8
//size
#define TIMER_SIZE_16 16
#define TIMER_SIZE_32 32
//prescale
#define TIMER_PRESCALE_1 1
#define TIMER_PRESCALE_8 8
#define TIMER_PRESCALE_16 16
#define TIMER_PRESCALE_256 256
int AllocHardTimer(int source, int size, int prescale); //4
int ReferHardTimer(int source, int size, int mode, int modemask);//5
int FreeHardTimer(int timid); //6
void SetTimerMode(int timid, int mode); //7
unsigned int GetTimerStatus(int timid); //8
void SetTimerCounter(int timid, unsigned int count); //9
unsigned int GetTimerCounter(int timid); //10
void SetTimerCompare(int timid, unsigned int compare); //11
unsigned int GetTimerCompare(int timid); //12
void SetHoldMode(int holdnum, int mode); //13
unsigned long GetHoldMode(int holdnum); //14
unsigned long GetHoldReg(int holdnum); //15
int GetHardTimerIntrCode(int timid); //16
#endif//__TIMEMAN_H__

View File

@ -1,115 +0,0 @@
#ifndef __ROMDIR_H__
#define __ROMDIR_H__
#include <tamtypes.h>
// an entry in a romdir table. a romdir table is an array of these.
// gets filled in by searchRomDir()
typedef struct romdir_entry {
char name[10]; //+00
short extSize; //+0A
int fileSize; //+0C
} __attribute__ ((packed)) ROMDIR_ENTRY;
// info about a file in a romdir
// gets filled in by searchFileInRom()
typedef struct {
ROMDIR_ENTRY* entry; // pointer to the file's ROMDIR_ENTRY
u32 fileData; // address of file contents
u32 extData; // address of file's ext info
} ROMFILE_INFO;
// info about the location of a romdir table
typedef struct {
u32 romPtr; //+00
ROMDIR_ENTRY* romdirPtr;//+04
u32 extinfoPtr; //+08
} ROMDIR_INFO;
typedef struct romfs {
char* filename; //+00
int fd; //+04
int size; //+08
ROMDIR_INFO romdirInfo; //+0C
} ROMFS;
// rounds off a value to the next multiple
#define ROUND_UP(num, multiple) (((num)+multiple-1) & (~(multiple-1)))
// searches between beginning and end addresses for a romdir structure.
// if found it returns info about it in romDirInfo.
//
// args: address to start searching from
// address to stop searching at
// gets filled in with info if found
// returns: a pointer to the filled in romDirInfo if successful
// NULL if error
extern ROMDIR_INFO* searchRomDir(const u32* searchStartAddr, const u32* searchEndAddr, ROMDIR_INFO* romDirInfo);
// find a file in the romdir table and return info about it
//
// args: info about romdir to search through
// filename to search for
// structure to get info about file into
// returns: a pointer to fileinfo if successful
// NULL otherwise
extern ROMFILE_INFO* searchFileInRom(const ROMDIR_INFO* romdirInfo, const char* filename, ROMFILE_INFO* fileinfo);
// gets a hex number from *addr and updates the pointer
//
// args: pointer to string buffer containing a hex number
// returns: the value of the hex number
extern u32 getHexNumber(char** addr);
/*
IOPBTCONF file format
=====================
each line is one of this:
1. loading address of IOP kernel
Format: @<HEXNUMBER>
Example: @800
Default: 0
Description: starting with <HEXNUMBER> (or 0 if not specified) the loader will
place modules in memory on 256 boundaries at +0x30 (the first 48 bytes are
reserved for info about the following module)
2. address of function to be called while loading of IOP kernel
Format: !addr <HEXNUMBER>
Description: the code indicated by <HEXNUMBER> will be run on kernel loading
3. name of (parent) included IOPBTCONF
Format: !include <NAME>
Description: allow to have another file with same format to be loaded
recursively; support for this is limited because of the BUGGY parsing;
Note: you can have such option only at the begining of IOPBTCONF and the
inclusion can be made without getting stucked in recursion like this:
ioprp1.img contains IOPBTCONF1 (!include IOPBTCON2) and IOPBTCONF11
ioprp2.img contains IOPBTCONF2 (!include IOPBTCONF1)
ioprp.img contains IOPBTCONF (!include IOPBTCONF2<EOL>!include IOPBTCONF11)
rom0 contains IOPBTCONF and IOPBTCON2
udnl cdrom0:ioprp1.img cdrom0:ioprp2.img cdrom0:ioprp.img
the starting of the chain can be named IOPBTCONF only
also you can include only from the previous romz
4. comment
Format: #<TEXT>
Example: #APPLOAD
Description: you can have comments on a line that starts with #
5. modules that have to be loaded after a reset
Format: <MODULENAME>
Example: SYSMEM
Description: each line of IOPBTCONF usualy have a module name; the order the
modules appear in the list is the order they are loaded as IOP kernel
--------------------------------
Notes:
- each line ends with <EOL>, that is 0x0A
- in the final loading list the first 2 positions must be SYSMEM and LOADCORE
*/
#endif /* __ROMDIR_H__ */

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/INTRMAN
IOP_INCS += -I../include
IOP_OBJS = int_handler.o intrman.o ../iopdebug.o ../libkernel/iop_loadcore.o ../libkernel/iop_excepman.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,373 +0,0 @@
.set noreorder
.set noat
.global EXCEP_Sys_handler
.ent EXCEP_Sys_handler
EXCEP_Sys_handler:
.word 0
.word 0
jal EXCEP_Sys_8
nop # branch delay
# restore status
lw $k0, EX_ST($0)
mtc0 $k0, $12
lw $k0, EX_PC($0)
add $k0, $k0, 4
jr $k0
cop0 0x10
nop
.end EXCEP_Sys_handler
.equiv STACK_FRAME_SIZE, 0x90
.equiv MODE0_ID, 0xAC0000FE
.equiv MODE1_ID, 0xFF00FFFE
.equiv MODE2_ID, 0xFFFFFFFE
.equiv EX_AT, 0x400
.equiv EX_PC, 0x404
.equiv EX_ST, 0x408
.equiv EX_CAUSE, 0x40C
.equiv INTR_STACK_SIZE, 0x800
.equiv I_REG, 0x1070
.equiv I_MASK, 0x1074
# ------------------------------------------------------------
# This is installed as priority 3 - the end of the chain.
# does nothing.
#
.global EXCEP_Int_priority_exception_handler
.ent EXCEP_Int_priority_exception_handler
EXCEP_Int_priority_exception_handler:
.word 0
.word 0
lw $at, EX_AT($0)
# restore status
lw $k0, EX_ST($0)
mtc0 $k0, $12
lw $k0, EX_PC($0)
jr $k0
cop0 0x10
nop
.end EXCEP_Int_priority_exception_handler
# ------------------------------------------------------------
.global EXCEP_Int_handler
.ent EXCEP_Int_handler
EXCEP_Int_handler:
.word 0
.word 0
# Initialise the mode 0 stack frame
sw $sp, 0x74-STACK_FRAME_SIZE($sp)
addiu $sp, $sp, -STACK_FRAME_SIZE
lw $at, EX_AT($0)
sw $at, 0x04($sp)
sw $v0, 0x08($sp)
sw $v1, 0x0C($sp)
sw $a0, 0x10($sp)
sw $a1, 0x14($sp)
sw $a2, 0x18($sp)
sw $a3, 0x1C($sp)
sw $ra, 0x7C($sp)
mfhi $v0
sw $v0, 0x80($sp)
mflo $v0
sw $v0, 0x84($sp)
lw $v0, EX_ST($0)
sw $v0, 0x88($sp)
lw $v0, EX_PC($0)
sw $v0, 0x8C($sp)
la $v0, MODE0_ID
jal QueryIntrContext
sw $v0, 0x00($sp) # branch delay slot
# Check whether this is a nested interrupt
# If it is not a nested interrupt then switch the stack to the interrupt context.
beq $v0, $0, $L_not_nested
or $v0, $sp, $sp # branch delay slot
# it is a nested interrupt
j $L1
sub $sp, $sp, 0x0C # branch delay slot
$L_not_nested:
# not a nested interrupt, so initialise to the top of the interrupt
# context stack.
la $sp, tempstack
addiu $sp, $sp, INTR_STACK_SIZE - 0x0C
$L1:
sw $v0, 0x4($sp) # link the location of the previous stack frame
sw $0, 0x8($sp) # interrupt number (bit mask)
lw $v0, EX_CAUSE($0)
andi $v0, $v0, 0x30
bne $v0, $0, $L_SoftwareInt
nop
# The interrupt must have been caused by a hardware event
lui $k0, 0xBF80
lw $a0, I_REG($k0)
lw $k0, I_MASK($k0) # k0 = I_MASK
and $a0, $a0, $k0
lw $k1, soft_hw_intr_mask
and $a0, $a0, $k1 # a0 = I_REG & I_MASK & soft_hw_intr_mask
beq $a0, $0, $L_ChainNextHandler # Interrupt is masked
nop
# The interrupt is not masked, so we should try and handle it
# Figure out what interrupt is being handled. Look at the bits from the LSB and
# find the first one that is set. The LSB is interrupt 0
la $a1, 0xFFFFFFFF # The interrupt being handled
$L_countInts:
addi $a1, $a1, 1
andi $a2, $a0, 0x01
beq $a2, $0, $L_countInts
srl $a0, 1
addiu $a0, $0, 0x1
sllv $a0, $a0, $a1 # a0 = the bitmask of the int being handled
sw $a0, 0x8($sp)
nor $a0, $a0, $0
and $k0, $a0, $k0
lui $k1, 0xBF80
sw $k0, I_MASK($k1)
sw $a0, I_REG($k1)
sll $a0, $a1, 3 # Int num * 8
lw $k0, intrtable
add $k0, $a0, $k0
lw $a2, 0($k0) # handler
bne $a2, $0, $L_HandleInterrupt
lw $a3, 4($k0) # arg
$L_ChainNextHandler:
# Pass control to the next exception handler
lw $sp, 0x4($sp) # pop the value of the previous stack frame (could be a context switch)
lw $at, 0x04($sp)
lw $v0, 0x08($sp)
lw $v1, 0x0C($sp)
lw $a0, 0x10($sp)
lw $a1, 0x14($sp)
lw $a2, 0x18($sp)
lw $a3, 0x1C($sp)
lw $ra, 0x7C($sp)
addiu $sp, $sp, STACK_FRAME_SIZE
lw $k0, EXCEP_Int_handler
jr $k0
nop
$L_SoftwareInt:
# $v0 = CAUSE & 0x30 is non-zero so the interrupt must have been caused by a software event
andi $v0, $v0, 0x10
bne $v0, $0, $L2
addiu $a0, $0, 0x0100 # sw Int 1
addiu $a0, $0, 0x0200 # sw Int 2
$L2:
mfc0 $a1, $13 # cause
nor $a2, $a0, $0
and $a1, $a1, $a2 # reset the relevent cause bit
mtc0 $a1, $13
srl $a0, $a0, 8
addiu $a0, $a0, 0x2D # interrupt vector is 0x2E or 0x2F
sll $a0, $a0, 3 # Int num * 8
lw $k0, intrtable
addu $k0, $a0, $k0
lw $a2, 0($k0) # handler
beq $a2, $0, $L_ChainNextHandler # No handler defined
lw $a3, 4($k0) # arg
# Both paths for SW and HW interrupts come together here.
#
# At this point:
# 0x8($sp) = int mask (0x01 << interrupt number)
# $a2 = handler
# $a3 = arg
$L_HandleInterrupt:
andi $a0, $a2, 0x03 # $a0 = mode
srl $a2, $a2, 2
beq $a0, $0, $L_Mode0
sll $a2, $a2, 2 # $a2 = masked handler
la $v1, MODE1_ID
srl $a0, $a0, 1
beq $a0, $0, $L_Mode1
lw $v0, 4($sp)
# Mode 2 or 3 (save t and s)
sw $s0, 0x40($v0)
sw $s1, 0x44($v0)
sw $s2, 0x48($v0)
sw $s3, 0x4C($v0)
sw $s4, 0x50($v0)
sw $s5, 0x54($v0)
sw $s6, 0x58($v0)
sw $s7, 0x5C($v0)
la $v1, MODE2_ID
$L_Mode1:
# Mode 1, save t
sw $t0, 0x20($v0)
sw $t1, 0x24($v0)
sw $t2, 0x28($v0)
sw $t3, 0x2C($v0)
sw $t4, 0x30($v0)
sw $t5, 0x34($v0)
sw $t6, 0x38($v0)
sw $t7, 0x3C($v0)
sw $t8, 0x60($v0)
sw $t9, 0x64($v0)
sw $gp, 0x70($v0)
sw $fp, 0x78($v0)
sw $v1, 0x00($v0) # mark the current state of the stack
$L_Mode0:
or $a0, $a3, $a3
jalr $a2 # call the interrupt handler
mtc0 $0, $12 # status
beq $v0, $0, $L_NotHandled
lui $k0, 0xBF80
lw $a0, I_MASK($k0)
lw $a1, 0x08($sp) # interrupt mask
or $a0, $a0, $a1
sw $a0, I_MASK($k0)
$L_NotHandled:
jal QueryIntrContext
nop
bne $v0, $0, $L_afterContextSwitch
lw $a0, 4($sp) # previous stack frame
# test if a context switch is pending. Returns true ($v0 != 0) if there is.
jal callContextSwitchRequiredHandler
nop
beq $v0, $0, $L_afterContextSwitch
lw $a0, 4($sp) # previous stack frame
lw $v0, 0($a0) # current stack context state
la $a1, MODE2_ID
beq $a1, $v0, $DoContextSwitch
nop
la $a1, MODE1_ID
beq $a1, $v0, $Mode1OnStack
nop
# stack state is currently mode 0
sw $t0, 0x20($a0)
sw $t1, 0x24($a0)
sw $t2, 0x28($a0)
sw $t3, 0x2C($a0)
sw $t4, 0x30($a0)
sw $t5, 0x34($a0)
sw $t6, 0x38($a0)
sw $t7, 0x3C($a0)
sw $t8, 0x60($a0)
sw $t9, 0x64($a0)
sw $gp, 0x70($a0)
sw $fp, 0x78($a0)
$Mode1OnStack:
sw $s0, 0x40($a0)
sw $s1, 0x44($a0)
sw $s2, 0x48($a0)
sw $s3, 0x4C($a0)
sw $s4, 0x50($a0)
sw $s5, 0x54($a0)
sw $s6, 0x58($a0)
sw $s7, 0x5C($a0)
la $v1, MODE2_ID
sw $v1, 0($a0)
$DoContextSwitch:
la $v0, context_switch_handler
lw $v0, 0($v0)
jalr $v0 # do the context switch, returns the new stack in $v0
nop
addu $a0, $v0, $0
$L_afterContextSwitch:
# At this point:
#
# $a0 = stack frame to switch to
or $sp, $a0, $a0
lw $a0, 0($sp)
la $a1, MODE0_ID
beq $a0, $a1, $L_RestoreMode0
nop
la $a1, MODE1_ID
beq $a0, $a1, $L_RestoreMode1
nop
# mode 2, restore t and s
lw $s0, 0x40($sp)
lw $s1, 0x44($sp)
lw $s2, 0x48($sp)
lw $s3, 0x4C($sp)
lw $s4, 0x50($sp)
lw $s5, 0x54($sp)
lw $s6, 0x58($sp)
lw $s7, 0x5C($sp)
$L_RestoreMode1:
# mode 1, restore t
lw $t0, 0x20($sp)
lw $t1, 0x24($sp)
lw $t2, 0x28($sp)
lw $t3, 0x2C($sp)
lw $t4, 0x30($sp)
lw $t5, 0x34($sp)
lw $t6, 0x38($sp)
lw $t7, 0x3C($sp)
lw $t8, 0x60($sp)
lw $t9, 0x64($sp)
lw $gp, 0x70($sp)
lw $fp, 0x78($sp)
$L_RestoreMode0:
lw $a0, 0x80($sp)
mthi $a0
lw $a0, 0x84($sp)
mtlo $a0
lw $a0, 0x88($sp)
srl $a0, $a0, 1
sll $a0, $a0, 1
mtc0 $a0, $12 # status (reset bit 0)
lw $at, 0x04($sp)
lw $v0, 0x08($sp)
lw $v1, 0x0C($sp)
lw $a0, 0x10($sp)
lw $a1, 0x14($sp)
lw $a2, 0x18($sp)
lw $a3, 0x1C($sp)
lw $ra, 0x7C($sp)
lw $k0, 0x8C($sp)
lw $sp, 0x74($sp)
jr $k0
cop0 0x10 # rfe
.end EXCEP_Int_handler

View File

@ -1,705 +0,0 @@
#define _GNU_SOURCE
#include "kloadcore.h"
#include "kexcepman.h"
#include "kintrman.h"
#include "err.h"
#define ICFG (*(volatile int*)0xbf801450)
#define IREG (*(volatile int*)0xbf801070)
#define IMASK (*(volatile int*)0xbf801074)
#define ICTRL (*(volatile int*)0xbf801078)
#define DMA_ICR (*(volatile int*)0xbf8010F4)
#define DMA_ICR2 (*(volatile int*)0xbf801574)
#define EXCEP_CAUSE (*(volatile int*)0x40C)
int debug=1;
#define _dprintf(fmt, args...) \
if (debug > 0) __printf("intrman: " fmt, ## args)
struct intrHandler {
u32 handler;
void *arg;
};
func context_switch_required_handler;
func context_switch_handler;
// Additional interrupt mask applied after IMASK
u32 soft_hw_intr_mask;
int unknown2[4]; //0x1280 up
#define INTR_STACK_SIZE 0x800
unsigned char tempstack[INTR_STACK_SIZE];
u32 *extable;
struct intrHandler *intrtable;
extern struct export export_stub;
int _start();
int IntrHandler();
void intrman_retonly();
/////////////////////////////syscalls//////////////////////////////////
__inline void syscall_0();
void syscall_1_CpuDisableIntr();
void syscall_2_CpuEnableIntr();
void syscall_3_intrman_call14();
void syscall_4_intrman_call17_19();
void syscall_5_intrman_call18_20();
void goto_EXCEP_Sys_handler();
void syscall_8_threadman();
func syscall[] = {
(func)syscall_0,
/* (func)syscall_1_CpuDisableIntr,
(func)syscall_2_CpuEnableIntr,
(func)syscall_3_intrman_call14,
(func)syscall_4_intrman_call17_19,
(func)syscall_5_intrman_call18_20,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)syscall_8_threadman,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler,
(func)goto_EXCEP_Sys_handler*/
};
///////////////////////////////////////////////////////////////////////
int intrmanDeinit() {
return 0;
}
///////////////////////////////////////////////////////////////////////
int intrman_call2()
{
IMASK = 0x00;
DMA_ICR = 0x00;
DMA_ICR2 = 0x00;
return 0;
}
///////////////////////////////////////////////////////////////////////
int intrman_call3(){
return (int)&unknown2;
}
///////////////////////////////////////////////////////////////////////
//
// interrupt values 0x2E - 0x3F are equivalent to 0x1E - 0x2F with a mode set
// interrupt values 0x20 - 0x2D have their mode forced to zero
//
// mode specifies what registers to save around the call
// 0 = don't save anything, handler will not change anything
// 1 = save t0 - t9, gp and fp
// 2 = save t0 - t9, gp, fp and s0 - s7
//
// arg is the value passed to the interrupt handler when it is called
//
int RegisterIntrHandler(int interrupt, int mode, intrh_func handler, void *arg)
{
u32 ictrl;
_dprintf("%s interrupt=%x, mode=%x\n", __FUNCTION__, interrupt, mode);
if (QueryIntrContext()){
// cannot be called from within an interrupt
_dprintf("%s ERROR_INTR_CONTEXT\n", __FUNCTION__);
return ERROR_INTR_CONTEXT;
}
CpuSuspendIntr(&ictrl);
if (interrupt < 0 || interrupt > 0x3F) {
CpuResumeIntr(ictrl);
_dprintf("%s ERROR_ILLEGAL_INTRCODE\n", __FUNCTION__);
return ERROR_ILLEGAL_INTRCODE;
}
int real_interrupt = interrupt;
int real_mode = mode;
if (interrupt >= 0x2E){
real_interrupt -= 0x10;
} else if (interrupt >= 0x20){
real_mode = 0;
}
if (intrtable[real_interrupt].handler){
CpuResumeIntr(ictrl);
_dprintf("%s ERROR_DOES_EXIST\n", __FUNCTION__);
return ERROR_DOES_EXIST;
}
intrtable[real_interrupt].handler = (mode & 0x03) | (u32)handler;
intrtable[real_interrupt].arg = arg;
CpuResumeIntr(ictrl);
return 0;
}
///////////////////////////////////////////////////////////////////////
int ReleaseIntrHandler(int interrupt)
{
u32 ictrl;
if (QueryIntrContext()){
// Cannot be called from within an interrupt
return ERROR_INTR_CONTEXT;
}
CpuSuspendIntr(&ictrl);
if (interrupt < 0 || interrupt >= 0x40) {
CpuResumeIntr(ictrl);
return ERROR_ILLEGAL_INTRCODE;
}
if (interrupt >= 0x2E){
interrupt -= 0x10;
}
if (intrtable[interrupt].handler){
intrtable[interrupt].handler = 0;
CpuResumeIntr(ictrl);
return 0;
}
CpuResumeIntr(ictrl);
return ERROR_DOES_EXIST;
}
///////////////////////////////////////////////////////////////////////
int CpuSuspendIntr(u32 *ictrl)
{
u32 rval = ICTRL;
if (ictrl) *ictrl = rval;
if (rval == 0) return ERROR_CPUDI;
return 0;
}
///////////////////////////////////////////////////////////////////////
int CpuResumeIntr(u32 ictrl)
{
ICTRL = ictrl;
return 0;
}
///////////////////////////////////////////////////////////////////////
int CpuDisableIntr()
{
if (ICTRL) return 0;
return ERROR_CPUDI;
}
///////////////////////////////////////////////////////////////////////
int CpuEnableIntr()
{
//_dprintf("%s\n", __FUNCTION__);
// intrman_syscall_08();
// _dprintf("syscall ok\n");
CpuEnableICTRL();
return 0;
}
///////////////////////////////////////////////////////////////////////
int CpuGetICTRL()
{
return ICTRL;
}
///////////////////////////////////////////////////////////////////////
int CpuEnableICTRL()
{
ICTRL = 1;
return 1;
}
///////////////////////////////////////////////////////////////////////
void intrman_syscall_04()
{
__asm__ (
"li $3, 4\n"
"syscall\n"
);
}
///////////////////////////////////////////////////////////////////////
void intrman_syscall_08()
{
__asm__ (
"li $3, 8\n"
"syscall\n"
);
}
///////////////////////////////////////////////////////////////////////
void intrman_syscall_10()
{
__asm__ (
"li $3, 16\n"
"syscall\n"
);
}
///////////////////////////////////////////////////////////////////////
void intrman_syscall_14()
{
__asm__ (
"li $3, 20\n"
"syscall\n"
);
}
///////////////////////////////////////////////////////////////////////
void intrman_syscall_0C()
{
__asm__ (
"li $3, 12\n"
"syscall\n"
);
}
///////////////////////////////////////////////////////////////////////
//
// Interrupt:
// 0 - 0x1F normal interrupt
// 0x20 - 0x26
// 0x27 - 0x2D
//
// Return 0 for success, -101 for invalid interrupt number
//
#define ERROR_BAD_NUMBER -101
#define INUM_DMA_0 0x20
#define INUM_DMA_BERR 0x27
#define INUM_DMA_7 0x28
#define IMODE_DMA_IRM 0x100
#define IMODE_DMA_IQE 0x200
#define INUM_DMA 3
int EnableIntr(int interrupt)
{
int retval = 0;
u32 low_irq = interrupt & 0xFF;
u32 high_irq = interrupt & 0xFFFFFF00;
u32 ictrl;
CpuSuspendIntr(&ictrl);
if( interrupt < 0 ) {
retval = ERROR_BAD_NUMBER;
}
else if (low_irq < INUM_DMA_0){
IMASK |= (1 << low_irq);
} else if (low_irq < INUM_DMA_BERR){
DMA_ICR = (DMA_ICR & ((~(1<<(low_irq-INUM_DMA_0)))&0x00FFFFFF))
| (1 << (INUM_DMA_BERR-INUM_DMA_0 + 16))
| (1<<(low_irq-INUM_DMA_0+0x10))
| ((high_irq & IMODE_DMA_IRM) ? (1<<(low_irq-INUM_DMA_0)) : 0);
DMA_ICR2 = (DMA_ICR2 & ((~(1<<(low_irq-INUM_DMA_0)))&0x00FFFFFF))
| ((high_irq & IMODE_DMA_IQE) ? (1<<(low_irq-0x10)) : 0);
IMASK |= 1<<INUM_DMA;
} else if ( (low_irq-INUM_DMA_7)<6){ // low_irq = 0x27 isn't handled?
u32 extra = 0;
if (high_irq & IMODE_DMA_IQE)
extra = (1<<(low_irq-INUM_DMA_7 + (INUM_DMA_BERR-INUM_DMA_0)));
DMA_ICR2=(DMA_ICR2&(~(1<<(low_irq-INUM_DMA_7 + (INUM_DMA_BERR-INUM_DMA_0))) & 0x00FFFFFF)) | (1<<(low_irq-INUM_DMA_7+0x10)) | extra;
DMA_ICR |= (DMA_ICR&0x00FFFFFF)| (1 << (INUM_DMA_BERR-INUM_DMA_0 + 16));
IMASK |= 1<<INUM_DMA;
} else {
retval = ERROR_BAD_NUMBER;
}
CpuResumeIntr(ictrl);
return retval;
}
///////////////////////////////////////////////////////////////////////
//not checked
int DisableIntr(int interrupt, int *oldstat){
u32 ictrl;
u32 old_IMASK;
u32 low_irq;
u32 stat;
u32 ret;
low_irq = interrupt & 0xFF;
CpuSuspendIntr(&ictrl);
ret = -101;
stat = -103;
if (low_irq<0) goto end;
ret = 0;
if (low_irq<0x20)
{
old_IMASK=IMASK;
IMASK&=~(1<<low_irq);
if (old_IMASK&(1<<low_irq))
{
stat = low_irq;
goto end;
}
ret = -103;
goto end;
}
if (low_irq<0x27)
{
if (DMA_ICR & 0xFFFFFF & (1<<(low_irq-0x10)))
{
if (((DMA_ICR & 0xFFFFFF)>>(low_irq-0x20)) & 0x01) stat = low_irq | 0x100;
if (DMA_ICR2 & (1<<(low_irq-0x20))) stat |= 0x200;
DMA_ICR2 &= ~(1<<(low_irq-0x20)) & 0xFFFFFF;
goto end;
}
ret = -103;
goto end;
}
if (low_irq<0x2E)
{
if (DMA_ICR2 & 0xFFFFFF & (1<<(low_irq-0x18)))
{
stat = low_irq;
if (((DMA_ICR2 & 0xFFFFFF)>>(low_irq-0x21))&0x01) stat |= 0x200;
DMA_ICR2 &= ~(1<<(low_irq-0x18)) & 0xFFFFFF;
goto end;
}
ret = -103;
goto end;
}
end:
if (oldstat) *(volatile int*)oldstat = stat;
CpuResumeIntr(ictrl);
return ret;
}
///////////////////////////////////////////////////////////////////////
// Enable
void intrman_call16(int interrupt)
{
u32 ictrl;
CpuSuspendIntr(&ictrl);
interrupt &= 0xFF;
if (interrupt < 0x20){
soft_hw_intr_mask |= (1 << interrupt);
} else if (interrupt < 0x28){
unknown2[1] |= 1 << (interrupt-0x08);
} else if (interrupt < 0x2E){
unknown2[2] |= 1 << (interrupt-0x10);
}
CpuResumeIntr(ictrl);
}
///////////////////////////////////////////////////////////////////////
// Disable
void intrman_call15(int interrupt)
{
u32 ictrl;
CpuSuspendIntr(&ictrl);
interrupt &= 0xFF;
if (interrupt < 0x20){
soft_hw_intr_mask &= ~(1 << interrupt);
} else if (interrupt < 0x28){
unknown2[1] &= ~(1 << (interrupt-0x08));
} else if (interrupt < 0x2E){
unknown2[2] &= ~(1 << (interrupt-0x10));
}
CpuResumeIntr(ictrl);
}
///////////////////////////////////////////////////////////////////////
void intrman_call27(int arg0)
{
unknown2[3]=arg0;
}
///////////////////////////////////////////////////////////////////////
//
int IntrHandler()
{
u32 masked_icr = DMA_ICR & unknown2[1];
_dprintf("%s\n", __FUNCTION__);
while (masked_icr & 0x7F008000){
int i;
if (masked_icr & 0x00008000){
// Int 0x25
func int_func = (func)(intrtable[0x25].handler & 0xFFFFFFFC);
DMA_ICR &= 0x00FF7FFF;
if (int_func){
int_func(intrtable[0x25].arg);
}
}
// Check each DMA interrupt
// The bits 24 - 30 are set for DMA channels 0 - 6 (ints 0x20 - 0x26 respectively)
// The bits 16 - 23 are the corresponding mask bits - the interrupt is only generated if the mask bit is set.
for (i=0; i < 7; ++i){
u32 ibit = 0x01000000 << i;
if (masked_icr & ibit){
func int_func = (func)(intrtable[0x20+i].handler & 0xFFFFFFFC);
DMA_ICR &= (ibit | 0x00FFFFFF);
if (int_func){
if (!int_func(intrtable[0x20+i].arg)){
// Disable / mask the interrupt if it was not handled
DMA_ICR &= (~(0x00010000 << i) & 0x00FFFFFF);
}
}
}
}
}
DMA_ICR &= 0x007FFFFF;
while (DMA_ICR & 0x00800000){
// do nothing
}
{
u32 temp_icr = DMA_ICR;
temp_icr &= 0x007FFFFF;
temp_icr |= 0x00800000;
DMA_ICR = temp_icr;
}
return 1;
}
///////////////////////////////////////////////////////////////////////
//
// Default context switch handler - does not switch context.
//
int default_ctx_switch_handler(u32 sp_in)
{
return sp_in;
}
///////////////////////////////////////////////////////////////////////
//
// Default routine to request a context switch. Does not request one.
//
int default_ctx_switch_required_handler()
{
return 0;
}
void SetCtxSwitchHandler(func handler){
context_switch_handler = handler;
}
void* ResetCtxSwitchHandler()
{
context_switch_handler = default_ctx_switch_handler;
return &context_switch_handler;
}
void SetCtxSwitchReqHandler(func handler)
{
context_switch_required_handler = handler;
}
int ResetCtxSwitchReqHandler()
{
context_switch_required_handler = default_ctx_switch_required_handler;
}
///////////////////////////////////////////////////////////////////////
// Return non-zero if sp is in an interrupt context
int QueryIntrStack(unsigned char* sp)
{
int retval = 0;
if ( (sp < tempstack + INTR_STACK_SIZE) && (sp > tempstack) ){
retval = 1;
}
return retval;
}
///////////////////////////////////////////////////////////////////////
// Return non-zero is we're currently in a interrupt context
int QueryIntrContext()
{
unsigned char* sp;
__asm__ ("move %0, $29\n" : "=r"(sp) :);
return QueryIntrStack(sp);
}
///////////////////////////////////////////////////////////////////////
//
int iCatchMultiIntr()
{
unsigned char* sp;
__asm__ ("move %0, $29\n" : "=r"(sp) :);
if (QueryIntrStack(sp)){
if (sp >= tempstack + 0x160){
u32 SR;
__asm__ ("mfc0 %0, $12\n" : "=r"(SR));
if (SR & 1 == 0){
u32 set_SR = SR | 1;
__asm__ volatile (
"mtc0 %0, $12\n"
"nop\n"
"nop\n"
"mtc0 %1, $12\n" : : "r"(set_SR), "r" (SR)
);
}
return SR;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////
// called by EXCEP_Sys_handler
void EXCEP_Sys_8() {
_dprintf("%s\n", __FUNCTION__);
}
///////////////////////////////////////////////////////////////////////
//not finished
void syscall_3_intrman_call14(){
}
///////////////////////////////////////////////////////////////////////
//not finished
void syscall_4_intrman_call17_19(){
}
///////////////////////////////////////////////////////////////////////
__inline void syscall_0(){
func funct;
funct=(func)((*(volatile int*)(0x404))+4);
__asm__ (
"jr %0\n"
"rfe\n"
: "=r" (funct)
);
}
///////////////////////////////////////////////////////////////////////
void retonly(){}
u32 callContextSwitchRequiredHandler()
{
if (NULL != context_switch_required_handler){
return context_switch_required_handler();
} else {
return 0;
}
}
//////////////////////////////entrypoint///////////////////////////////
struct export export_stub={
0x41C00000,
0,
VER(1, 2), // 1.2 => 0x102
0,
"intrman",
(func)_start, // entrypoint
(func)intrmanDeinit,
(func)intrman_call2,
(func)intrman_call3,
(func)RegisterIntrHandler,
(func)ReleaseIntrHandler,
(func)EnableIntr,
(func)DisableIntr,
(func)CpuDisableIntr,
(func)CpuEnableIntr,
(func)intrman_syscall_04, // 0x0A
(func)intrman_syscall_08,
(func)CpuGetICTRL,
(func)CpuEnableICTRL,
(func)intrman_syscall_0C, // 0x0E
(func)intrman_call15,
(func)intrman_call16, // 0x10
(func)CpuSuspendIntr,
(func)CpuResumeIntr,
(func)CpuSuspendIntr,
(func)CpuResumeIntr,
(func)intrman_syscall_10,
(func)intrman_syscall_14,
(func)QueryIntrContext, // 0x17
(func)QueryIntrStack,
(func)iCatchMultiIntr,
(func)retonly,
(func)intrman_call27,
(func)SetCtxSwitchHandler, // 0x1C (called by threadman)
(func)ResetCtxSwitchHandler,
(func)SetCtxSwitchReqHandler, // 0x1E (called by threadman)
(func)ResetCtxSwitchReqHandler,
0
};
extern struct exHandler EXCEP_Int_priority_exception_handler;
extern struct exHandler EXCEP_Int_handler;
extern struct exHandler EXCEP_Sys_handler;
//////////////////////////////entrypoint///////////////////////////////
int _start(){
int i;
intrtable = (struct intrHandler*)(GetExHandlersTable() + 0x40);
IMASK = 0x00;
DMA_ICR = 0x00;
DMA_ICR2 = 0x00;
for (i=0; i < 0x2F; i++) {
intrtable[i].handler = 0;
intrtable[i].arg = 0;
}
soft_hw_intr_mask = 0xFFFFFFFF;
unknown2[1] = -1;
unknown2[2] = -1;
unknown2[0] = (int)intrtable;
RegisterExceptionHandler(0, &EXCEP_Int_handler);
RegisterPriorityExceptionHandler(0, 3, &EXCEP_Int_priority_exception_handler);
RegisterExceptionHandler(8, &EXCEP_Sys_handler);
RegisterIntrHandler(3, 1, &IntrHandler, 0);
RegisterLibraryEntries(&export_stub);
return 0;
}
void ijb_ping1()
{
_dprintf("%s\n", __FUNCTION__);
unsigned char* x = tempstack;
}
void ijb_trace3(u32 a0, u32 a1, u32 a2, u32 a3)
{
__printf("trace3: 0x%x, 0x%x, 0x%x\n", a0, a1, a2);
while (1){}
}

View File

@ -1,20 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOPBOOT_BIN = ../../../build/IOPBOOT
IOP_INCS += -I../include
IOP_OBJS = iopboot.o ../iopdebug.o ../iopelf.o ../romdir.o
$(IOPBOOT_BIN): $(IOP_OBJS)
$(EE_CC) -Wl,--oformat,binary,--Map,iopboot.map -T linkfile $(IOP_OBJS) -nostartfiles -o $(IOPBOOT_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOPBOOT_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,252 +0,0 @@
//
// iopboot.c
//
// this is the c code for the iopboot file in the ps2 rom.
// this file is located at 0xBFC4A000 in the ps2 bios rom0.
// modload.irx also from the ps2 bios executes this direct from the rom
// (no loading to ram first)
//
// this is based on florin's disasm and converted to c code by xorloser and zerofrog
//
#include <tamtypes.h>
#include <stdio.h>
#include "iopload.h"
#include "iopdebug.h"
#include "iopelf.h"
#include "romdir.h"
#include "kloadcore.h"
static void kstrcpy(char* dst, const char* src);
static int kstrlen(const char* src);
//BOOT_PARAMS boot_params;
//u32* next_free_address[0x40]; // up to 64 modules
// this is the start point of execution at 0xBFC4A000
//
// it loads the IOPBTCONF module list from rom0 and compiles a
// list of modules and their addresses.
//
// this list is then passed to loadcore as it is executed in order
// to then load the rest of the modules
//
// args: total size of IOP ram in MegaBytes
// bootinfo flags
// string containing the reboot image filepath
// ? doesnt seem to be used
void _start(int ramMBSize, int bootInfo, char* udnlString, int unk)
{
ROMFS ri;
void *(*sysmem_entry)(u32 iopmemsize);
void (*loadcore_entry)(BOOT_PARAMS *init);
int i;
ROMDIR_INFO romdir_info;
ROMFILE_INFO romfile_info;
char conf_filename[10];
int ram_byte_size, num_lines;
u32 module_load_addr;
u32** modules_ptr;
char* file_data_ptr, *file_data_end;
void* psysmemstart;
BOOT_PARAMS* boot_params;
if( ramMBSize <= 2 )
ram_byte_size = 2;
else
ram_byte_size = ramMBSize;
ram_byte_size <<= 20;
// compile module list to send to loadcore
boot_params = (BOOT_PARAMS*)0x30000; // random address, has to be clear before loadcore call
boot_params->ramMBSize = ramMBSize;
boot_params->bootInfo = bootInfo;
boot_params->udnlString = NULL;
boot_params->moduleAddrs = (u32**)((u32)boot_params + sizeof(BOOT_PARAMS)); // right after
// if a undl string is specified, get a copy of it and store a pointer to it
if(udnlString)
{
boot_params->udnlString = (char*)boot_params->moduleAddrs;
kstrcpy(boot_params->udnlString, udnlString);
boot_params->moduleAddrs = (u32**)((u32)boot_params->udnlString + ROUND_UP(kstrlen(udnlString) + 8, 4));
}
// find the romdir table in the rom
if( searchRomDir((u32*)0xBFC00000, (u32*)0xBFC10000, &romdir_info) == NULL )
{
__printf("IOPBOOT: failed to find start of rom!\n");
// error - cant find romdir!
while(1) *(u8*)0x80000000 = 0;
}
// find the bootconf file in the romdir table
kstrcpy(conf_filename, "IOPBTCONF");
conf_filename[8] = '0' + bootInfo;
if( !searchFileInRom(&romdir_info, conf_filename, &romfile_info) )
{
kstrcpy(conf_filename, "IOPBTCONF");
if( !searchFileInRom(&romdir_info, conf_filename, &romfile_info) )
{
__printf("IOPBTCONF file not found!\n");
// error - cant find conf file!
while(1) *(u8*)0x80000000 = 1;
}
}
// count the number of lines in conf file
file_data_ptr = (char*)romfile_info.fileData;
file_data_end = (char*)romfile_info.fileData + romfile_info.entry->fileSize;
{
num_lines = 0;
while( file_data_ptr < file_data_end ) {
// loop until a "newline" charcter is found
while(file_data_ptr < file_data_end) {
if(*file_data_ptr++ < ' ')
break;
}
// loop until a "non-newline" charcter is found
while(file_data_ptr < file_data_end) {
if(*file_data_ptr++ >= ' ')
break;
}
num_lines++;
}
num_lines++;
}
// get the addresses of each module
{
module_load_addr = 0;
boot_params->numConfLines = num_lines-1;
modules_ptr = boot_params->moduleAddrs;
char* file_data_ptr = (char*)romfile_info.fileData;
while( file_data_ptr < file_data_end ) {
if(*file_data_ptr == '@') {
file_data_ptr++;
module_load_addr = getHexNumber(&file_data_ptr);
}
else if(*file_data_ptr == '!') {
if( file_data_ptr[1] == 'a' &&
file_data_ptr[2] == 'd' &&
file_data_ptr[3] == 'd' &&
file_data_ptr[4] == 'r' &&
file_data_ptr[5] == ' ' ) {
file_data_ptr += 6;
*modules_ptr++ = (u32*)(getHexNumber(&file_data_ptr) * 4 + 1);
*modules_ptr++ = 0;
}
}
else if(*file_data_ptr != '#') {
// 'file_data_ptr' should be pointing to a filename
// this finds the address of that file in the rom
ROMFILE_INFO module_fileinfo;
char strmodule[16];
for(i = 0; i < 16; ++i) {
if( file_data_ptr[i] < ' ' )
break;
strmodule[i] = file_data_ptr[i];
}
strmodule[i] = 0;
if( searchFileInRom(&romdir_info, strmodule, &module_fileinfo) == NULL ) {
__printf("IOPBOOT: failed to find %s module\n", strmodule);
return;
}
//__printf("mod: %s:%x\n", strmodule, module_fileinfo.fileData);
*modules_ptr++ = (u32*)module_fileinfo.fileData;
*modules_ptr = 0; // don't increment
}
// loop until a "newline" charcter is found
while(file_data_ptr < file_data_end) {
if(*file_data_ptr++ < ' ')
break;
}
// loop until a "non-newline" charcter is found
while(file_data_ptr < file_data_end) {
if(*file_data_ptr >= ' ')
break;
file_data_ptr++;
}
}
}
if( searchFileInRom(&romdir_info, "IOPBOOT", &romfile_info) == NULL ) {
__printf("loadElfFile: failed to find IOPBOOT module\n");
return;
}
// load sysmem module to memory and execute it
if( searchFileInRom(&romdir_info, "SYSMEM", &romfile_info) == NULL ) {
__printf("loadElfFile: failed to find SYSMEM module\n");
return;
}
sysmem_entry = (void *(*)(u32))loadElfFile(&romfile_info, module_load_addr);
if( sysmem_entry == 0 )
return;
psysmemstart = sysmem_entry(ram_byte_size);
//FlushIcache();
if( psysmemstart == 0 ) {
__printf("IOPBOOT: sysmem failed\n");
return;
}
__printf("SYSMEM success, start addr: %x, alloc start: %x\n", module_load_addr, psysmemstart);
if( searchFileInRom(&romdir_info, "LOADCORE", &romfile_info) == NULL ) {
__printf("loadElfFile: failed to find SYSMEM module\n");
return;
}
loadcore_entry = (void (*)())loadElfFile(&romfile_info, (u32)psysmemstart);
if( loadcore_entry == 0 )
return;
boot_params->firstModuleAddr = (u32)module_load_addr + 0x30; // skip elf?
if(0x1FC10000 < ram_byte_size) {
boot_params->pos = 0x1FC00000;
boot_params->size = 0x10100;
}
else {
boot_params->pos = 0;
boot_params->size = 0;
}
__printf("executing LOADCORE entry at %p\n", loadcore_entry);
loadcore_entry(boot_params);
__printf("iopboot error\n");
// error - loadcore shouldnt ever return
while(1) *(u8*)0x80000000 = 2;
}
void Kmemcpy(void *dest, const void *src, int n) {
const u8 *s = (u8*)src;
u8 *d = (u8*)dest;
while (n) {
*d++ = *s++; n--;
}
}
static void kstrcpy(char* dst, const char* src)
{
while(*src) *dst++ = *src++;
*dst = 0;
}
static int kstrlen(const char* src)
{
int len = 0;
while(*src++) len++;
return len;
}

View File

@ -1,17 +0,0 @@
// Boiler plate exception handlers used at boot time.
// EXCEPMAN replaces these with something more useful.
__asm__(".org 0x0000");
__asm__(".set noreorder");
void CpuException0() {
}
__asm__(".org 0x0080");
__asm__(".set noreorder");
void CpuException() {
}

View File

@ -1,16 +0,0 @@
_stack_size = 0x80000;
_heap_size = 1024*1024*10;
ENTRY(_start);
SECTIONS {
.text 0xbfc008f0 : {
*(.text)
*(.data)
*(.rdata)
*(.sdata)
*(.rodata)
*(.bss)
*(.sbss)
}
}

View File

@ -1,279 +0,0 @@
/* Debugging printf, for debugging the library itself.
We don't assume stdio is working.
We do assume _write_r is working.
*/
#include "iopload.h"
#include "iopdebug.h"
#ifdef __STDC__
#include "stdarg.h"
#else
#include "varargs.h"
#endif
static char *parse_number ();
static long get_number ();
static void print_number ();
static void write_char (char c);
static void write_string (char* s);
/* Non-zero for big-endian systems. */
static int big_endian_p;
/* For now hardcode 2 (stderr) as the console file descriptor.
May wish to let the caller pass in a file descriptor or some such but
this is only for debugging purposes anyway. */
#define CONSOLE_FD 2
/* Standalone printf routine.
The format string has been enhanced so that multiple values can be dumped
without having to have a %-field for each one (say if you want to dump
20 words at a certain address). A modifier of `N' says the next argument
is a count, and the one after that is a pointer.
Example: __dprintf (stderr, "%Nx\n", 20, p); /-* print 20 ints at `p' *-/
Supported formats are: c d u x s p.
All ints are retrieved a byte at a time so alignment issues are not
a problem.
This routine is used in situations where the only debugging capability
is console output and was written to aid debugging newlib itself. We don't
use printf ourselves as we may be debugging it. We do assume _write_r is
working.
*/
void
#ifdef __STDC__
__printf (char *fmt, ...)
#else
__printf (fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list args;
/* Which endian are we? */
{
short tmp = 1;
big_endian_p = *(char *) &tmp == 0;
}
#ifdef __STDC__
va_start (args, fmt);
#else
va_start (args);
#endif
while (*fmt)
{
char c, *p;
int count;
long l;
if (*fmt != '%' || *++fmt == '%')
{
write_char (*fmt++);
continue;
}
if (*fmt == 'N')
{
count = va_arg (args, int);
p = va_arg (args, char *);
++fmt;
c = *fmt++;
while (--count >= 0)
{
switch (c)
{
// case 'c' :
// write_string (unctrl (*p++));
// break;
case 'p' :
print_number (16, 1, get_number (p, sizeof (char *), 1));
p += sizeof (char *);
break;
case 'd' :
case 'u' :
case 'x' :
print_number (c == 'x' ? 16 : 10, c != 'd',
get_number (p, sizeof (int), c != 'd'));
p += sizeof (int);
break;
case 's' :
write_string (*(char **) p);
p += sizeof (char *);
break;
}
if (count > 0)
write_char (' ');
}
}
else
{
switch (c = *fmt++)
{
// case 'c' :
// c = va_arg (args, int);
// write_string (unctrl (c));
// break;
case 'p' :
l = (void *) va_arg (args, char *);
print_number (16, 1, l);
break;
case 'd' :
case 'u' :
case 'x' :
l = va_arg (args, int);
print_number (c == 'x' ? 16 : 10, c != 'd', l);
break;
case 's' :
p = va_arg (args, char *);
write_string (p);
break;
}
}
}
va_end (args);
}
static int isdigit(int c) {
if (c >= '0' && c <= '9') return 1;
return 0;
}
/* Parse a positive decimal integer at S.
FIXME: Was used in earlier version, but not currently used.
Keep for now. */
static char *
parse_number (s, p)
char *s;
long *p;
{
long x = 0;
while (isdigit (*s))
{
x = (x * 10) + (*s - '0');
++s;
}
*p = x;
return s;
}
/* Fetch the number at S of SIZE bytes. */
static long
get_number (s, size, unsigned_p)
char *s;
long size;
int unsigned_p;
{
long x;
unsigned char *p = (unsigned char *) s;
switch (size)
{
case 1 :
x = *p;
if (!unsigned_p)
x = (x ^ 0x80) - 0x80;
return x;
case 2 :
if (big_endian_p)
x = (p[0] << 8) | p[1];
else
x = (p[1] << 8) | p[0];
if (!unsigned_p)
x = (x ^ 0x8000) - 0x8000;
return x;
case 4 :
if (big_endian_p)
x = ((long)p[0] << 24) | ((long)p[1] << 16) | (p[2] << 8) | p[3];
else
x = ((long)p[3] << 24) | ((long)p[2] << 16) | (p[1] << 8) | p[0];
if (!unsigned_p)
x = (x ^ 0x80000000L) - 0x80000000L;
return x;
#if 0 /* FIXME: Is there a standard mechanism for knowing if
long longs exist? */
case 8 :
#endif
default :
return 0;
}
}
/* Print X in base BASE. */
static void
print_number (base, unsigned_p, n)
int base;
int unsigned_p;
long n;
{
static char chars[16] = "0123456789abcdef";
char *p, buf[32];
unsigned long x;
if (!unsigned_p && n < 0)
{
write_char ('-');
x = -n;
}
else
x = n;
p = buf + sizeof (buf);
*--p = '\0';
do
{
*--p = chars[x % base];
x /= base;
}
while (x != 0);
write_string (p);
}
/* Write C to the console.
We go through the file descriptor directly because we can't assume
stdio is working. */
static void
write_char (char c)
{
__putc(c);
}
/* Write S to the console.
We go through the file descriptor directly because we can't assume
stdio is working. */
static void
write_string (char *s)
{
__puts(s);
}
void __putc(u8 c) {
*((u8*)0x1f80380c) = c;
}
void __puts(u8 *s) {
while (*s != 0) {
__putc(*s++);
}
}

View File

@ -1,428 +0,0 @@
#include "romdir.h"
#include "iopelf.h"
typedef struct {
u32 st_name;
u32 st_value;
u32 st_size;
u8 st_info;
u8 st_other;
u16 st_shndx;
} Elf32_Sym;
char *sections_names;
ELF_HEADER *elfHeader;
ELF_PHR *elfProgH;
ELF_SHR *elfSectH;
u8 *elfdata;
int elfsize;
u32 elfbase;
static int debug=1;
#define _dprintf(fmt, args...) \
if (debug > 0) __printf("iopelf: " fmt, ## args)
static void __memcpy(void *dest, const void *src, int n) {
const u8 *s = (u8*)src;
u8 *d = (u8*)dest;
while (n) {
*d++ = *s++; n--;
}
}
int loadHeaders() {
elfHeader = (ELF_HEADER*)elfdata;
if ((elfHeader->e_shentsize != sizeof(ELF_SHR)) && (elfHeader->e_shnum > 0)) {
return -1;
}
#ifdef ELF_LOG
ELF_LOG( "type: " );
#endif
switch( elfHeader->e_type )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown %x", elfHeader->e_type );
#endif
break;
case 0x0:
#ifdef ELF_LOG
ELF_LOG( "no file type" );
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG( "relocatable" );
#endif
break;
case 0x2:
#ifdef ELF_LOG
ELF_LOG( "executable" );
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG( "\n" );
ELF_LOG( "machine: " );
#endif
switch ( elfHeader->e_machine )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown" );
#endif
break;
case 0x8:
#ifdef ELF_LOG
ELF_LOG( "mips_rs3000" );
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("version: %d\n",elfHeader->e_version);
ELF_LOG("entry: %08x\n",elfHeader->e_entry);
ELF_LOG("flags: %08x\n",elfHeader->e_flags);
ELF_LOG("eh size: %08x\n",elfHeader->e_ehsize);
ELF_LOG("ph off: %08x\n",elfHeader->e_phoff);
ELF_LOG("ph entsiz: %08x\n",elfHeader->e_phentsize);
ELF_LOG("ph num: %08x\n",elfHeader->e_phnum);
ELF_LOG("sh off: %08x\n",elfHeader->e_shoff);
ELF_LOG("sh entsiz: %08x\n",elfHeader->e_shentsize);
ELF_LOG("sh num: %08x\n",elfHeader->e_shnum);
ELF_LOG("sh strndx: %08x\n",elfHeader->e_shstrndx);
ELF_LOG("\n");
#endif
return 0;
}
int loadProgramHeaders() {
int i;
if (elfHeader->e_phnum == 0) {
return 0;
}
if (elfHeader->e_phentsize != sizeof(ELF_PHR)) {
return -1;
}
elfProgH = (ELF_PHR*)&elfdata[elfHeader->e_phoff];
for ( i = 0 ; i < elfHeader->e_phnum ; i++ )
{
#ifdef ELF_LOG
ELF_LOG( "Elf32 Program Header\n" );
ELF_LOG( "type: " );
#endif
switch ( elfProgH[ i ].p_type )
{
default:
#ifdef ELF_LOG
ELF_LOG( "unknown %x", (int)elfProgH[ i ].p_type );
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG("load");
#endif
/* if ( elfHeader->e_shnum == 0 ) {*/
if (elfProgH[ i ].p_offset < elfsize) {
int size;
if ((elfProgH[ i ].p_filesz + elfProgH[ i ].p_offset) > elfsize) {
size = elfsize - elfProgH[ i ].p_offset;
} else {
size = elfProgH[ i ].p_filesz;
}
_dprintf("loading program at %x, size=%x\n", elfProgH[ i ].p_paddr + elfbase, size);
__memcpy((void*)(elfProgH[ i ].p_paddr + elfbase),
&elfdata[elfProgH[ i ].p_offset],
size);
}
#ifdef ELF_LOG
ELF_LOG("\t*LOADED*");
#endif
// }
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("offset: %08x\n",(int)elfProgH[i].p_offset);
ELF_LOG("vaddr: %08x\n",(int)elfProgH[i].p_vaddr);
ELF_LOG("paddr: %08x\n",elfProgH[i].p_paddr);
ELF_LOG("file size: %08x\n",elfProgH[i].p_filesz);
ELF_LOG("mem size: %08x\n",elfProgH[i].p_memsz);
ELF_LOG("flags: %08x\n",elfProgH[i].p_flags);
ELF_LOG("palign: %08x\n",elfProgH[i].p_align);
ELF_LOG("\n");
#endif
}
return 0;
}
void _relocateElfSection(int i) {
ELF_REL *rel;
int size = elfSectH[i].sh_size / 4;
int r = 0;
u32 *ptr, *tmp;
ELF_SHR *rsec = &elfSectH[elfSectH[i].sh_info];
u8 *mem = (u8*)(elfSectH[i].sh_addr + elfbase);
u32 imm;
int j;
ptr = (u32*)(elfdata+elfSectH[i].sh_offset);
// _dprintf("relocating section %s\n", &sections_names[rsec->sh_name]);
// __printf("sh_addr %x\n", elfSectH[i].sh_addr);
while (size > 0) {
rel = (ELF_REL*)&ptr[r];
// __printf("rel size=%x: offset=%x, info=%x\n", size, rel->r_offset, rel->r_info);
tmp = (u32*)&mem[rel->r_offset];
switch ((u8)rel->r_info) {
case 2: // R_MIPS_32
*tmp+= elfbase; break;
case 4: // R_MIPS_26
*tmp = (*tmp & 0xfc000000) |
(((*tmp & 0x03ffffff) + (elfbase >> 2)) & 0x03ffffff);
break;
case 5: // R_MIPS_HI16
imm = (((*tmp & 0xffff) + (elfbase >> 16)) & 0xffff);
for (j=(r+2)/2; j<elfSectH[i].sh_size / 4; j++) {
if (j*2 == r) continue;
if ((u8)((ELF_REL*)&ptr[j*2])->r_info == 6)
break;
// if ((rel->r_info >> 8) == (((ELF_REL*)&ptr[j*2])->r_info >> 8))
// break;
}
/* if (j != elfSectH[i].sh_size / 4)*/ {
u32 *p;
rel = (ELF_REL*)&ptr[j*2];
// __printf("HI16: found match: %x\n", rel->r_offset);
p = (u32*)&mem[rel->r_offset];
// __printf("%x + %x = %x\n", *p, elfbase, (*p & 0xffff) + (elfbase & 0xffff));
if (((*p & 0xffff) + (elfbase & 0xffff)) & 0x8000) {
// __printf("found\n");
imm++;
}
}
*tmp = (*tmp & 0xffff0000) | imm;
break;
case 6: // R_MIPS_LO16
*tmp = (*tmp & 0xffff0000) |
(((*tmp & 0xffff) + (elfbase & 0xffff)) & 0xffff);
break;
default:
__printf("UNKNOWN R_MIPS REL!!\n");
break;
}
size-= 2; r+= 2;
}
}
int loadSectionHeaders() {
int i;
int i_st = -1;
int i_dt = -1;
if (elfHeader->e_shnum == 0) {
return -1;
}
elfSectH = (ELF_SHR*)&elfdata[elfHeader->e_shoff];
if ( elfHeader->e_shstrndx < elfHeader->e_shnum ) {
sections_names = (char *)&elfdata[elfSectH[ elfHeader->e_shstrndx ].sh_offset];
}
for ( i = 0 ; i < elfHeader->e_shnum ; i++ )
{
#ifdef ELF_LOG
ELF_LOG( "Elf32 Section Header [%x] %s", i, &sections_names[ elfSectH[ i ].sh_name ] );
#endif
/* if ( elfSectH[i].sh_flags & 0x2 ) {
if (elfSectH[i].sh_offset < elfsize) {
int size;
if ((elfSectH[i].sh_size + elfSectH[i].sh_offset) > elfsize) {
size = elfsize - elfSectH[i].sh_offset;
} else {
size = elfSectH[i].sh_size;
}
memcpy(&psM[ elfSectH[ i ].sh_addr &0x1ffffff ],
&elfdata[elfSectH[i].sh_offset],
size);
}
#ifdef ELF_LOG
ELF_LOG( "\t*LOADED*" );
#endif
}*/
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("type: ");
#endif
switch ( elfSectH[ i ].sh_type )
{
default:
#ifdef ELF_LOG
ELF_LOG("unknown %08x",elfSectH[i].sh_type);
#endif
break;
case 0x0:
#ifdef ELF_LOG
ELF_LOG("null");
#endif
break;
case 0x1:
#ifdef ELF_LOG
ELF_LOG("progbits");
#endif
break;
case 0x2:
#ifdef ELF_LOG
ELF_LOG("symtab");
#endif
break;
case 0x3:
#ifdef ELF_LOG
ELF_LOG("strtab");
#endif
break;
case 0x4:
#ifdef ELF_LOG
ELF_LOG("rela");
#endif
break;
case 0x8:
#ifdef ELF_LOG
ELF_LOG("no bits");
#endif
break;
case 0x9:
#ifdef ELF_LOG
ELF_LOG("rel");
#endif
break;
}
#ifdef ELF_LOG
ELF_LOG("\n");
ELF_LOG("flags: %08x\n", elfSectH[i].sh_flags);
ELF_LOG("addr: %08x\n", elfSectH[i].sh_addr);
ELF_LOG("offset: %08x\n", elfSectH[i].sh_offset);
ELF_LOG("size: %08x\n", elfSectH[i].sh_size);
ELF_LOG("link: %08x\n", elfSectH[i].sh_link);
ELF_LOG("info: %08x\n", elfSectH[i].sh_info);
ELF_LOG("addralign: %08x\n", elfSectH[i].sh_addralign);
ELF_LOG("entsize: %08x\n", elfSectH[i].sh_entsize);
#endif
// dump symbol table
if (elfSectH[i].sh_type == 0x02) {
i_st = i; i_dt = elfSectH[i].sh_link;
}
}
// now that we have all the stuff loaded, relocate it
for (i = 0 ; i < elfHeader->e_shnum ; i++) {
if (elfSectH[i].sh_type == 0x09) { // relocations
_relocateElfSection(i);
}
}
return 0;
}
void* loadElfFile(ROMFILE_INFO* ri, u32 offset)
{
imageInfo* ii;
ELF_PHR* ph;
ELF_IOPMOD* im;
__printf("loadElfFile: base=%x, size=%x\n", ri->fileData, ri->entry->fileSize);
elfdata = (u8*)(ri->fileData);
elfsize = ri->entry->fileSize;
elfbase = offset+0x30;
loadHeaders();
// fill the image info header
ph= (ELF_PHR*)((char*)elfHeader +elfHeader->e_phoff);
im= (ELF_IOPMOD*)((char*)elfHeader + ph[0].p_offset);
ii = (imageInfo*)offset;
if( *(u16*)(elfHeader->e_ident+4) != 0x101 )
return NULL;
if (elfHeader->e_machine != EM_MIPS)
return NULL;
if (elfHeader->e_phentsize != sizeof(ELF_PHR))
return NULL;
if (elfHeader->e_phnum != 2)
return NULL;
if (ph[0].p_type != PT_SCE_IOPMOD)
return NULL;
if (elfHeader->e_type != ET_SCE_IOPRELEXEC){
if (elfHeader->e_type != elfHeader->e_phnum )//ET_EXEC)
return NULL;
//result->type=3;
}
//else result->type=4;
ii->next =0;
ii->name =NULL;
ii->version =0;
ii->flags =0;
ii->modid =0;
if ((int)im->moduleinfo != -1) {
moduleInfo* minfo = (moduleInfo*)(im->moduleinfo+ph[1].p_vaddr); // probably wrong
ii->name = minfo->name;
ii->version = minfo->version;
}
else {
ii->name = NULL;
ii->version = 0;
}
ii->entry = im->entry;
ii->gp_value = im->gp_value;
ii->p1_vaddr = ph[1].p_vaddr;
ii->text_size = im->text_size;
ii->data_size = im->data_size;
ii->bss_size = im->bss_size;
loadProgramHeaders();
loadSectionHeaders();
_dprintf("loadElfFile: e_entry=%x, hdr=%x\n", elfHeader->e_entry, elfHeader);
return (void*)(elfbase+elfHeader->e_entry);
}

View File

@ -1,146 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Nick Van Veen
------------------------------------------------------------------------
iop_cdvdman.s CDVD Manager Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### CDVDMAN STUB ####### */
/* # Added by Sjeep, 24th June 2002 # */
.local cdvdman_stub
cdvdman_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "cdvdman\0"
.align 2
.globl CdInit # 004
CdInit:
j $31
li $0, 4
.globl CdStandby # 005
CdStandby:
j $31
li $0, 5
.globl CdRead # 006
CdRead:
j $31
li $0, 6
.globl CdSeek # 007
CdSeek:
j $31
li $0, 7
.globl CdGetError # 008
CdGetError:
j $31
li $0, 8
.globl CdGetToc # 009
CdGetToc:
j $31
li $0, 9
.globl CdSearchFile # 010
CdSearchFile:
j $31
li $0, 10
.globl CdSync # 011
CdSync:
j $31
li $0, 11
.globl CdGetDiskType # 012
CdGetDiskType:
j $31
li $0, 12
.globl CdDiskReady # 013
CdDiskReady:
j $31
li $0, 13
.globl CdTrayReq # 014
CdTrayReq:
j $31
li $0, 14
.globl CdStop # 015
CdStop:
j $31
li $0, 15
.globl CdPosToInt # 016
CdPosToInt:
j $31
li $0, 16
.globl CdIntToPos # 017
CdIntToPos:
j $31
li $0, 17
.globl CdCheckCmd # 021
CdCheckCmd:
j $31
li $0, 21
.globl CdReadILinkID # 022
CdReadILinkID:
j $31
li $0, 22
.globl CdReadClock # 024
CdReadClock:
j $31
li $0, 24
.globl CdStatus # 028
CdStatus:
j $31
li $0, 28
.globl CdCallback # 037
CdCallback:
j $31
li $0, 37
.globl CdPause # 038
CdPause:
j #31
li $0, 38
.globl CdBreak # 039
CdBreak:
j $31
li $0, 39
.globl CdGetReadPos # 044
CdGetReadPos:
j $31
li $0, 44
.globl CdReadChain # 066
CdReadChain:
j $31
li $0, 66
.globl CdMmode
CdMmode:
j $31
li $0, 75
.word 0
.word 0

View File

@ -1,52 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (oobles@hotmail.com)
------------------------------------------------------------------------
iop_dmacman.s DMAC library function imports.
taken from dmacman in bios.
*/
.text
.set noreorder
/* ############################### DMACMAN STUB ######## */
.local dmacman_stub
dmacman_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "dmacman\0"
.align 2
.globl dmacSetDMA # 028
dmacSetDMA:
j $31
li $0, 28
.globl dmacStartTransfer # 032
dmacStartTransfer:
j $31
li $0, 32
.globl dmacSetVal # 033
dmacSetVal:
j $31
li $0, 33
.globl dmacEnableDMAch # 034
dmacEnableDMAch:
j $31
li $0, 34
.globl dmacDisableDMAch # 035
dmacDisableDMAch:
j $31
li $0, 35
.word 0
.word 0

View File

@ -1,58 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_excepman.s Exception Manager Functions.
*/
.text
.set noreorder
/* ############################### EXCEPMAN STUB ####### */
/* # Added by linuzappz, 10th May 2004 # */
.local excepman_stub
excepman_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "excepman"
.align 2
.globl GetExHandlersTable # 003
GetExHandlersTable:
j $31
li $0, 3
.globl RegisterExceptionHandler # 004
RegisterExceptionHandler:
j $31
li $0, 4
.globl RegisterPriorityExceptionHandler # 005
RegisterPriorityExceptionHandler:
j $31
li $0, 5
.globl RegisterDefaultExceptionHandler # 006
RegisterDefaultExceptionHandler:
j $31
li $0, 6
.globl ReleaseExceptionHandler # 007
ReleaseExceptionHandler:
j $31
li $0, 7
.globl ReleaseDefaultExceptionHandler # 008
ReleaseDefaultExceptionHandler:
j $31
li $0, 8
.word 0
.word 0

View File

@ -1,51 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (oobles@hotmail.com)
------------------------------------------------------------------------
iop_heaplib.s Heap library function imports.
taken from heaplib in bios.
*/
.text
.set noreorder
/* ############################### SYSMEM STUB ######## */
.local sysmem_stub
sysmem_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "heaplib\0"
.align 2
.globl CreateHeap # 004
CreateHeap:
j $31
li $0, 4
.globl DestroyHeap # 005
DestroyHeap:
j $31
li $0, 5
.globl HeapMalloc # 006
HeapMalloc:
j $31
li $0, 6
.globl HeapFree # 007
HeapFree:
j $31
li $0, 7
.globl HeapSize # 008
HeapSize:
j $31
li $0, 8
.word 0
.word 0

View File

@ -1,73 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_intrman.s Interrupt Manager Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### INTRMAN STUB ####### */
/* # Added by Oobles, 5th March 2002 # */
.local intrman_stub
intrman_stub:
.word 0x41e00000
.word 0
.word 0x00000102
.ascii "intrman\0"
.align 2
.globl RegisterIntrHandler # 004
RegisterIntrHandler:
j $31
li $0, 4
.globl ReleaseIntrHandler # 005
ReleaseIntrHandler:
j $31
li $0, 5
.globl EnableIntr # 006
EnableIntr:
j $31
li $0, 6
.globl DisableIntr # 007
DisableIntr:
j $31
li $0, 7
.globl CpuDisableIntr # 008
CpuDisableIntr:
j $31
li $0, 8
.globl CpuEnableIntr # 009
CpuEnableIntr:
j $31
li $0, 9
.globl CpuSuspendIntr # 0x11
CpuSuspendIntr:
j $31
li $0, 0x11
.globl CpuResumeIntr # 0x12
CpuResumeIntr:
j $31
li $0, 0x12
.globl QueryIntrContext # 0x17
QueryIntrContext:
j $31
li $0, 0x17
.word 0
.word 0

View File

@ -1,116 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Gustavo Scott(gustavo@scotti.com)
------------------------------------------------------------------------
iop_iooman.s
IOP Basic libraries.
took from .irx files with symbol table / string table
*/
.text
.set noreorder
/* ############################### IOMAN STUB ######## */
.local ioman_stub
ioman_stub:
.word 0x41e00000
.word 0
.word 0x00000102
.ascii "ioman\0\0\0"
.align 2
.globl open # 004
open:
j $31
li $0, 4
.globl close # 005
close:
j $31
li $0, 5
.globl read # 006
read:
j $31
li $0, 6
.globl write # 007
write:
j $31
li $0, 7
.globl lseek # 008
lseek:
j $31
li $0, 8
.globl ioctl
ioctl:
j $31
li $0, 9
.globl remove
remove:
j $31
li $0, 10
.globl mkdir
mkdir:
j $31
li $0, 11
.globl rmdir
rmdir:
j $31
li $0, 12
.globl dopen
dopen:
j $31
li $0, 13
.globl dclose
dclose:
j $31
li $0, 14
.globl dread
dread:
j $31
li $0, 15
.globl getstat
getstat:
j $31
li $0, 16
.globl chstat
chstat:
j $31
li $0, 17
.globl format
format:
j $31
li $0, 18
.globl FILEIO_add # 020
.globl AddDrv
FILEIO_add:
AddDrv:
j $31
li $0, 20
.globl FILEIO_del # 021
.globl DelDrv
FILEIO_del:
DelDrv:
j $31
li $0, 21
.word 0
.word 0

View File

@ -1,160 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_libsd.s Sound Library
taken from .irx files with symbol table
Missing calls by Julian Tyler (lovely@crm114.net)
*/
.text
.set noreorder
/* ############################### LIBSD STUB ######### */
/* # Added by Oobles, 7th March 2002 # */
.local libsd_stub
libsd_stub:
.word 0x41e00000
.word 0
.word 0x00000104
.ascii "libsd\0\0"
.align 2
/* Added by Julian Tyler (lovely) */
.globl SdQuit # 0x02
SdQuit:
j $31
li $0, 0x02
.globl SdInit # 0x04
SdInit:
j $31
li $0, 0x04
.globl SdSetParam # 0x05
SdSetParam:
j $31
li $0, 0x05
.globl SdGetParam # 0x06
SdGetParam:
j $31
li $0, 0x06
.globl SdSetSwitch # 0x07
SdSetSwitch:
j $31
li $0, 0x07
/* Added by Julian Tyler (lovely) */
.globl SdGetSwitch # 0x08
SdGetSwitch:
j $31
li $0, 0x08
.globl SdSetAddr # 0x09
SdSetAddr:
j $31
li $0, 0x09
.globl SdGetAddr # 0x0a
SdGetAddr:
j $31
li $0, 0x0a
.globl SdSetCoreAttr # 0x0b
SdSetCoreAttr:
j $31
li $0, 0x0b
/* Added by Julian Tyler (lovely) 013-016 */
.globl SdGetCoreAttr # 012
SdGetCoreAttr:
j $31
li $0, 0x0c
.globl SdNote2Pitch # 013
SdNote2Pitch:
j $31
li $0, 0x0d
.globl SdPitch2Note # 014
SdPitch2Note:
j $31
li $0, 0x0e
.globl SdProcBatch # 015
SdProcBatch:
j $31
li $0, 0x0f
.globl SdProcBatchEx # 016
SdProcBatchEx:
j $31
li $0, 0x10
.globl SdVoiceTrans # 0x11
SdVoiceTrans:
j $31
li $0, 0x11
/* Added by Julian Tyler (lovely) 018-022 */
.globl SdBlockTrans # 018
SdBlockTrans:
j $31
li $0, 0x12
.globl SdVoiceTransStatus # 019
SdVoiceTransStatus:
j $31
li $0, 0x13
.globl SdBlockTransStatus # 020
SdBlockTransStatus:
j $31
li $0, 0x14
.globl SdSetTransCallback # 021
SdSetTransCallback:
j $31
li $0, 0x15
.globl SdSetIRQCallback # 022
SdSetIRQCallback:
j $31
li $0, 0x16
.globl SdSetEffectAttr # 0x17
SdSetEffectAttr:
j $31
li $0, 0x17
/* Added by Julian Tyler (lovely) 024-025 */
.globl SdGetEffectAttr # 024
SdGetEffectAttr:
j $31
li $0, 0x18
.globl SdClearEffectWorkArea # 025
SdClearEffectWorkArea:
j $31
li $0, 0x19
.globl SdSetTransIntrHandler # 0x1a
SdSetTransIntrHandler:
j $31
li $0, 0x1a
.globl SdSetSpu2IntrHandler # 0x1b
SdSetSpu2IntrHandler:
j $31
li $0, 0x1b
.word 0
.word 0

View File

@ -1,65 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_loadcore.s Core IOP Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### LOADCORE STUB ###### */
/* # Added by Oobles, 5th March 2002 # */
.local loadcore_stub
loadcore_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "loadcore"
.align 2
.globl GetLibraryEntryTable # 0x03
GetLibraryEntryTable:
j $31
li $0, 3
.globl FlushIcache # 0x05
FlushIcache:
j $31
li $0, 4
.globl FlushDcache # 0x05
FlushDcache:
j $31
li $0, 5
.global RegisterLibraryEntries # 0x06
RegisterLibraryEntries:
j $31
li $0, 6
.global ReleaseLibraryEntries
ReleaseLibraryEntries:
j $31
li $0, 7
.global QueryLibraryEntryTable
QueryLibraryEntryTable:
j $31
li $0, 11
.globl QueryBootMode # 0x0c
QueryBootMode:
j $31
li $0, 0x0c
.word 0
.word 0

View File

@ -1,61 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Nick Van Veen (nickvv@xtra.co.nz)
------------------------------------------------------------------------
iop_modload.s Module Manager Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### MODLOAD STUB ####### */
/* # Added by Sjeep, 28th March 2002 # */
.local modload_stub
modload_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "modload\0"
.align 2
.globl ReBootStart # 004
ReBootStart:
jr $31
li $0, 0x04
.globl LoadModuleAddress # 005
LoadModuleAddress:
jr $31
li $0, 0x05
.globl LoadModule # 006
LoadModule:
jr $31
li $0, 0x06
.globl LoadStartModule # 007
LoadStartModule:
jr $31
li $0, 0x07
.globl StartModule # 008
StartModule:
jr $31
li $0, 0x08
.globl LoadModuleBufferAddress # 009
LoadModuleBufferAddress:
jr $31
li $0, 0x09
.globl LoadModuleBuffer # 010
LoadModuleBuffer:
jr $31
li $0, 0x0A
.word 0
.word 0

View File

@ -1,144 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_sifcmd.s Serial Interface Command Functions.
taken from .irx files with symbol table
*/
.text
.set noreorder
/* ############################### SIFCMD STUB ######## */
/* # Added by Oobles, 5th March 2002 # */
.local sifcmd_stub
sifcmd_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "sifcmd\0\0"
.align 2
.globl SifInitCmd # 0x04
SifInitCmd:
j $31
li $0, 0x04
.globl SifExitCmd # 0x05
SifExitCmd:
j $31
li $0, 0x05
.globl SifGetSreg # 0x06
SifGetSreg:
j $31
li $0, 0x06
.globl SifSetSreg # 0x07
SifSetSreg:
j $31
li $0, 0x07
.globl SifSetCmdBuffer # 0x08
SifSetCmdBuffer:
j $31
li $0, 0x08
.globl SifAddCmdHandler # 0x0a
SifAddCmdHandler:
j $31
li $0, 0x0a
.globl SifRemoveCmdHandler # 0x0b
SifRemoveCmdHandler:
j $31
li $0, 0x0b
.globl SifSendCmd # 0x0c
SifSendCmd:
j $31
li $0, 0x0c
.globl iSifSendCmd # 0x0d
iSifSendCmd:
j $31
li $0, 0x0d
.globl SifInitRpc # 0x0E
SifInitRpc:
j $31
li $0, 0x0E
.globl SifBindRpc # 0x0F
SifBindRpc:
j $31
li $0, 0x0F
.globl SifCallRpc # 0x10
SifCallRpc:
j $31
li $0, 0x10
.globl SifRegisterRpc # 0x11
SifRegisterRpc:
j $31
li $0, 0x11
.globl SifCheckStatRpc # 0x12
SifCheckStatRpc:
j $31
li $0, 0x12
.globl SifSetRpcQueue # 0x13
SifSetRpcQueue:
j $31
li $0, 0x13
.globl SifGetNextRequest # 0x14
SifGetNextRequest:
j $31
li $0, 0x14
.globl SifExecRequest # 0x15
SifExecRequest:
j $31
li $0, 0x15
.globl SifRpcLoop # 0x16
SifRpcLoop:
j $31
li $0, 0x16
.globl SifRpcGetOtherData # 0x17
SifRpcGetOtherData:
j $31
li $0, 0x17
.globl SifRemoveRpc # 0x18
SifRemoveRpc:
j $31
li $0, 0x18
.globl SifRemoveRpcQueue # 0x19
SifRemoveRpcQueue:
j $31
li $0, 0x19
.globl SifSendCmdIntr # 0x20
SifSendCmdIntr:
j $31
li $0, 0x20
.globl iSifSendCmdIntr # 0x21
iSifSendCmdIntr:
j $31
li $0, 0x21
.word 0
.word 0

View File

@ -1,178 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2001, Gustavo Scotti (gustavo@scotti.com)
------------------------------------------------------------------------
iop_sifman.s Serial Interface Manager Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### SIFMAN STUB ######## */
/* # Added by Oobles, 7th March 2002 # */
.local sifman_stub
sifman_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "sifman\0\0"
.align 2
.globl SifDeinit # 0x03
SifDeinit:
j $31
li $0, 0x03
.globl SifSIF2Init # 0x04
SifSIF2Init:
j $31
li $0, 0x04
.globl SifInit # 0x05
SifInit:
j $31
li $0, 0x05
.globl SifSetDChain # 0x06
SifSetDChain:
j $31
li $0, 0x06
.globl SifSetDma # 0x07
SifSetDma:
j $31
li $0, 0x07
.globl SifDmaStat # 0x08
SifDmaStat:
j $31
li $0, 0x08
.globl SifSend # 0x09
SifSend:
j $31
li $0, 0x09
.globl SifSendSync # 0x0A
SifSendSync:
j $31
li $0, 0x0A
.globl SifIsSending # 0x0B
SifIsSending:
j $31
li $0, 0x0B
.globl SifSetSIF0DMA # 0x0C
SifSetSIF0DMA:
j $31
li $0, 0x0C
.globl SifSendSync0 # 0x0D
SifSendSync0:
j $31
li $0, 0x0D
.globl SifIsSending0 # 0x0E
SifIsSending0:
j $31
li $0, 0x0E
.globl SifSetSIF1DMA # 0x0F
SifSetSIF1DMA:
j $31
li $0, 0x0F
.globl SifSendSync1 # 0x10
SifSendSync1:
j $31
li $0, 0x10
.globl SifIsSending1 # 0x11
SifIsSending1:
j $31
li $0, 0x11
.globl SifSetSIF2DMA # 0x12
SifSetSIF2DMA:
j $31
li $0, 0x12
.globl SifSendSync2 # 0x13
SifSendSync2:
j $31
li $0, 0x13
.globl SifIsSending2 # 0x14
SifIsSending2:
j $31
li $0, 0x14
.globl SifGetEEIOPflags # 0x15
SifGetEEIOPflags:
j $31
li $0, 0x15
.globl SifSetEEIOPflags # 0x16
SifSetEEIOPflags:
j $31
li $0, 0x16
.globl SifGetIOPEEflags # 0x17
SifGetIOPEEflags:
j $31
li $0, 0x17
.globl SifSetIOPEEflags # 0x18
SifSetIOPEEflags:
j $31
li $0, 0x18
.globl SifGetEErcvaddr # 0x19
SifGetEErcvaddr:
j $31
li $0, 0x19
.globl SifGetIOPrcvaddr # 0x1A
SifGetIOPrcvaddr:
j $31
li $0, 0x1A
.globl SifSetIOPrcvaddr # 0x1B
SifSetIOPrcvaddr:
j $31
li $0, 0x1B
.globl SifSet1450_2 # 0x1C
SifSet1450_2:
j $31
li $0, 0x1C
.globl SifCheckInit # 0x1D
SifCheckInit:
j $31
li $0, 0x1D
.globl SifSet0CB # 0x1E
SifSet0CB:
j $31
li $0, 0x1E
.globl SifReset0CB # 0x1F
SifReset0CB:
j $31
li $0, 0x1F
.globl SifSetDmaIntr # 0x20
SifSetDmaIntr:
j $31
li $0, 0x20
.word 0
.word 0

View File

@ -1,32 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_stdio.s Stdio Import Library
taken from .irx files with symbol table
*/
.text
.set noreorder
/* ############################### STDIO STUB ######## */
.local stdio_stub
stdio_stub:
.word 0x41e00000
.word 0
.word 0x00000102
.ascii "stdio\0\0\0"
.align 2
.globl printf # 004
printf:
j $31
li $0, 4
.word 0
.word 0

View File

@ -1,219 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_sysclib.a C Library Functions.
taken from .irx files with symbol table.
Additions from Herben's IRX Tool imports.txt
*/
.text
.set noreorder
/* ############################### SYSCLIB STUB ####### */
/* # Added by Oobles, 5th March 2002 # */
.local sysclib_stub
sysclib_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "sysclib\0"
.align 2
.globl setjmp # 0x04
setjmp:
j $31
li $0, 0x04
.globl longjmp # 0x05
longjmp:
j $31
li $0, 0x05
.globl toupper # 0x06
toupper:
j $31
li $0, 0x06
.globl tolower # 0x07
tolower:
j $31
li $0, 0x07
.globl look_ctype_table # 0x08
look_ctype_table:
j $31
li $0, 0x08
.globl get_ctype_table # 0x09
get_ctype_table:
j $31
li $0, 0x09
.globl memchr # 0x0A
memchr:
j $31
li $0, 0x0A
.globl memcmp # 0x0B
memcmp:
j $31
li $0, 0x0B
.globl memcpy # 0x0C
memcpy:
j $31
li $0, 0x0C
.globl memmove # 0x0D
memmove:
j $31
li $0, 0x0D
.globl memset # 0x0E
memset:
j $31
li $0, 0x0E
.globl bcmp # 0x0F
bcmp:
j $31
li $0, 0x0F
.globl bcopy # 0x10
bcopy:
j $31
li $0, 0x10
.globl bzero # 0x11
bzero:
j $31
li $0, 0x11
.globl prnt # 0x12
prnt:
j $31
li $0, 0x12
.globl sprintf # 0x013
sprintf:
j $31
li $0, 0x13
.globl strcat # 0x14
strcat:
j $31
li $0, 0x14
.globl strchr # 0x15
strchr:
j $31
li $0, 0x15
.globl strcmp # 0x16
strcmp:
j $31
li $0, 0x16
.globl strcpy # 0x17
strcpy:
j $31
li $0, 0x17
.globl strcspn # 0x18
strcspn:
j $31
li $0, 0x18
.globl index # 0x19
index:
j $31
li $0, 0x19
.globl rindex # 0x1A
rindex:
j $31
li $0, 0x1A
.globl strlen # 0x1b
strlen:
j $31
li $0, 0x1b
.globl strncat # 0x1c
strncat:
j $31
li $0, 0x1C
.globl strncmp # 0x1d
strncmp:
j $31
li $0, 0x1d
.globl strncpy # 0x1E
strncpy:
j $31
li $0, 0x1E
.globl strpbrk # 0x1F
strpbrk:
j $31
li $0, 0x1F
.globl strrchr # 0x20
strrchr:
j $31
li $0, 0x20
.globl strspn # 0x21
strspn:
j $31
li $0, 0x21
.globl strstr # 0x22
strstr:
j $31
li $0, 0x22
.globl strtok # 0x23
strtok:
j $31
li $0, 0x23
.globl strtol # 0x24
strtol:
j $31
li $0, 0x24
.globl atob # 0x25
atob:
j $31
li $0, 0x25
.globl strtoul # 0x26
strtoul:
j $31
li $0, 0x26
.globl wmemcopy # 0x28
wmemcopy:
j $31
li $0, 0x28
.globl wmemset # 0x29
wmemset:
j $31
li $0, 0x29
.globl vsprintf # 0x2A
vsprintf:
j $31
li $0, 0x2A
.word 0
.word 0

View File

@ -1,71 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2001, Gustavo Scotti (gustavo@scotti.com)
------------------------------------------------------------------------
iop_sysmem.s Memory Function import list.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### SYSMEM STUB ######## */
.local sysmem_stub
sysmem_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "sysmem\0\0"
.align 2
.globl AllocSysMemory # 004
AllocSysMemory:
j $31
li $0, 0x04
.globl FreeSysMemory # 005
FreeSysMemory:
j $31
li $0, 0x05
.globl QueryMemSize # 006
QueryMemSize:
j $31
li $0, 0x06
.globl QueryMaxFreeMemSize # 007
QueryMaxFreeMemSize:
j $31
li $0, 0x07
.globl QueryTotalFreeMemSize # 008
QueryTotalFreeMemSize:
j $31
li $0, 0x08
.globl QueryBlockTopAddress # 009
QueryBlockTopAddress:
j $31
li $0, 0x09
.globl QueryBlockSize # 00A
QueryBlockSize:
j $31
li $0, 0x0A
.globl Kprintf # 0x0E
Kprintf:
j $31
li $0, 0x0E
.globl SetKprintf # 0x0F
SetKprintf:
j $31
li $0, 0x0F
.word 0
.word 0

View File

@ -1,167 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_thbase.s Base Kernel Functions.
taken from .irx files with symbol table
*/
.text
.set noreorder
/* ############################### THBASE STUB ######## */
/* # Added by Oobles, 5th March 2002 # */
.local thbase_stub
thbase_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "thbase\0\0"
.align 2
.globl CreateThread # 004
CreateThread:
j $31
li $0, 4
.globl DeleteThread # 005
DeleteThread:
j $31
li $0, 5
.globl StartThread # 006
StartThread:
j $31
li $0, 6
.globl StartThreadArgs # 007
StartThreadArgs:
j $31
li $0, 0x07
.globl ExitThread # 008
ExitThread:
j $31
li $0, 0x08
.globl ExitDeleteThread # 009
ExitDeleteThread:
j $31
li $0, 0x09
.globl TerminateThread # 010
TerminateThread:
j $31
li $0, 0x0A
.globl iTerminateThread # 011
iTerminateThread:
j $31
li $0, 0x0B
.globl DisableDispatchThread # 012
DisableDispatchThread:
j $31
li $0, 0x0C
.globl EnableDispatchThread # 013
EnableDispatchThread:
j $31
li $0, 0x0D
.globl ChangeThreadPriority # 014
ChangeThreadPriority:
j $31
li $0, 0x0E
.globl iChangeThreadPriority # 015
iChangeThreadPriority:
j $31
li $0, 0x0F
.globl ReleaseWaitThread # 018
ReleaseWaitThread:
j $31
li $0, 18
.globl iReleaseWaitThread # 019
iReleaseWaitThread:
j $31
li $0, 19
.globl GetThreadId # 0x14
GetThreadId:
j $31
li $0, 0x14
.globl SleepThread # 0x18
SleepThread:
j $31
li $0, 0x18
.globl WakeupThread # 0x19
WakeupThread:
j $31
li $0, 0x19
.globl iWakeupThread # 0x1A
iWakeupThread:
j $31
li $0, 0x1A
.globl DelayThread # 0x21
DelayThread:
j $31
li $0, 0x21
.globl GetSystemTime # 0x22
GetSystemTime:
j $31
li $0, 0x22
.globl SetAlarm # 0x23
SetAlarm:
j $31
li $0, 0x23
.globl iSetAlarm # 0x24
iSetAlarm:
j $31
li $0, 0x24
.globl CancelAlarm # 0x25
CancelAlarm:
j $31
li $0, 0x25
.globl iCancelAlarm # 0x26
iCancelAlarm:
j $31
li $0, 0x26
.globl USec2SysClock # 0x27
USec2SysClock:
j $31
li $0, 0x27
.globl SysClock2USec # 0x28
SysClock2USec:
j $31
li $0, 0x28
.globl GetSystemStatusFlag # 0x29
GetSystemStatusFlag:
j $31
li $0, 0x29
.word 0
.word 0

View File

@ -1,67 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Florin Sasu (florinsasu@yahoo.com)
------------------------------------------------------------------------
iop_thevent.s Event Function Imports.
*/
.text
.set noreorder
.local thevent_stub
thevent_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "thevent\0"
.align 2
.globl CreateEventFlag # 004
CreateEventFlag:
j $31
li $0, 0x04
.globl DeleteEventFlag
DeleteEventFlag:
j $31
li $0, 0x05
.globl SetEventFlag # 006
SetEventFlag:
j $31
li $0, 0x06
.globl iSetEventFlag # 007
iSetEventFlag:
j $31
li $0, 0x07
.globl ClearEventFlag # 008
ClearEventFlag:
j $31
li $0, 0x08
.globl iClearEventFlag # 009
iClearEventFlag:
j $31
li $0, 0x09
.globl WaitEventFlag # 00A
WaitEventFlag:
j $31
li $0, 0x0A
.word 0
.word 0
.globl ReferEventFlagStatus # 00D
ReferEventFlagStatus:
j $31
li $0, 0x0D
.globl iReferEventFlagStatus # 00E
iReferEventFlagStatus:
j $31
li $0, 0x0E

View File

@ -1,68 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan (Oobles@hotmail.com)
------------------------------------------------------------------------
iop_thsemap.s Semaphore Function Imports.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ############################### THSEMAP STUB ####### */
/* # Added by Oobles, 5th March 2002 # */
.local thsemap_stub
thsemap_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "thsemap\0"
.align 2
.globl CreateSema # 004
CreateSema:
j $31
li $0, 4
.globl DeleteSema # 005
DeleteSema:
j $31
li $0, 5
.globl SignalSema # 006
SignalSema:
j $31
li $0, 6
.globl iSignalSema # 007
iSignalSema:
j $31
li $0, 7
.globl WaitSema # 008
WaitSema:
j $31
li $0, 8
.globl PollSema # 009
PollSema:
j $31
li $0, 0x09
.globl ReferSemaStatus # 00B
ReferSemaStatus:
j $31
li $0, 0x0B
.globl iReferSemaStatus # 00C
iReferSemaStatus:
j $31
li $0, 0x0C
.word 0
.word 0

View File

@ -1,113 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Pedro J. Cabrera (rc5stint@yahoo.com)
------------------------------------------------------------------------
iop_usbd.s USB Driver Import functions.
Figured out from IRX files with symbol tables in Unreal Tournament
and JamPak demo discs.
*/
.text
.set noreorder
.local usbd_stub
usbd_stub: # Module Import Information
.word 0x41e00000 # Import Tag
.word 0x00000000 # Minor Version?
.word 0x00000101 # Major Version?
.ascii "usbd\0\0\0\0" # Library ID
.align 2
/* initialize USBD.IRX
* Note: UsbInit is automatically called first whenever USBD.IRX is loaded.
* There should never be a need to reinitialize the driver. In fact, it may
* not even work. But I'm providing the function hook anyhow. <shrug>
*/
.globl UsbInit
UsbInit:
j $31
li $0, 0x00
/*
* These two functions are used to register and unregister device drivers for
* listening for USB bus events. The events are device probe, connect, and disconnect.
*/
# register a USB device driver
.globl UsbRegisterDriver
UsbRegisterDriver:
j $31
li $0, 0x04
# unregister a USB device driver
.globl UsbUnregisterDriver
UsbUnregisterDriver:
j $31
li $0, 0x05
/*
* This function is used to get the static descriptors for the specific USB
* device. These descriptors identify the device uniquely and help determine
* what type of device we are dealing with, and what its capabilities and
* features are.
*/
.globl UsbGetDeviceStaticDescriptor
UsbGetDeviceStaticDescriptor:
j $31
li $0, 0x06
/*
* These two functions are used to assign relevant data to a specific device.
* The type of data is entirely up to the caller. For example, a particular
* USB device driver may store configuration data for each specific device
* under its control.
*/
# set the private data pointer for a device
.globl UsbSetDevicePrivateData
UsbSetDevicePrivateData:
j $31
li $0, 0x07
# get the private data pointer for a device
.globl UsbGetDevicePrivateData
UsbGetDevicePrivateData:
j $31
li $0, 0x08
/*
* This function returns an endpoint ID for the device ID and endpoint descriptor
* passed in. This endpoint ID is then used when transfering data to the device,
* and to close the endpoint.
*/
.globl UsbOpenEndpoint
UsbOpenEndpoint:
j $31
li $0, 0x09
# close an endpoint
.globl UsbCloseEndpoint
UsbCloseEndpoint:
j $31
li $0, 0x0A
/*
* This function is used for all types of USB data transfers. Which type of
* transfer is determined by the parameters that are passed in. The types are:
* control, isochronous, interrupt, and bulk transfers. More details can be
* found in usbd.h.
*/
.globl UsbTransfer
UsbTransfer:
j $31
li $0, 0x0B
.globl UsbOpenBulkEndpoint
UsbOpenBulkEndpoint:
j $31
li $0, 0x0C
.word 0
.word 0

View File

@ -1,53 +0,0 @@
/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, Nick Van Veen (nickvv@xtra.co.nz)
------------------------------------------------------------------------
iop_vblank.s Vblank Manager Functions.
taken from .irx files with symbol table.
*/
.text
.set noreorder
/* ################################ VBLANK STUB ####### */
/* # Added by Sjeep, 28th March 2002 # */
.local vblank_stub
vblank_stub:
.word 0x41e00000
.word 0
.word 0x00000101
.ascii "vblank\0\0"
.align 2
.globl WaitVblankStart
WaitVblankStart:
jr $31
li $0,4
.globl WaitVblankEnd
WaitVblankEnd:
jr $31
li $0,5
.globl WaitVblank
WaitVblank:
jr $31
li $0,6
.globl WaitNonVblank
WaitNonVblank:
jr $31
li $0,7
.globl RegisterVblankHandler
RegisterVblankHandler:
jr $31
li $0,8
.globl ReleaseVblankHandler
ReleaseVblankHandler:
jr $31
li $0,9

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/LOADCORE
IOP_INCS += -I../include
IOP_OBJS = loadcore.o ../iopdebug.o ../iopelf.o ../romdir.o ../libkernel/iop_sysmem.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

File diff suppressed because it is too large Load Diff

View File

@ -1,106 +0,0 @@
/***************************************************************
* romdir.c, based over Alex Lau (http://alexlau.8k.com) RomDir *
****************************************************************/
#include "romdir.h"
// searches between beginning and end addresses for a romdir structure.
// if found it returns info about it in romDirInfo.
//
// args: address to start searching from
// address to stop searching at
// gets filled in with info if found
// returns: a pointer to the filled in romDirInfo if successful
// NULL if error
ROMDIR_INFO* searchRomDir(const u32* searchStartAddr, const u32* searchEndAddr, ROMDIR_INFO* romDirInfo)
{
int offset = 0;
ROMDIR_ENTRY* dir_entry = (ROMDIR_ENTRY*)searchStartAddr;
while (dir_entry < (ROMDIR_ENTRY*)searchEndAddr)
{
if(dir_entry->name[0] == 'R' &&
dir_entry->name[1] == 'E' &&
dir_entry->name[2] == 'S' &&
dir_entry->name[3] == 'E' &&
dir_entry->name[4] == 'T' &&
dir_entry->name[5] == 0 &&
(ROUND_UP(dir_entry->fileSize,16) == offset) )
{
romDirInfo->romPtr = (u32)searchStartAddr; // start of rom
romDirInfo->romdirPtr = dir_entry; // start of romdir structure
romDirInfo->extinfoPtr = (u32)dir_entry + dir_entry[1].fileSize; // start of extinfo
return romDirInfo;
}
dir_entry++;
offset += sizeof(ROMDIR_ENTRY);
}
// not found
romDirInfo->romdirPtr = NULL;
return NULL;
}
// find a file in the romdir table and return info about it
//
// args: info about romdir to search through
// filename to search for
// structure to get info about file into
// returns: a pointer to fileinfo if successful
// NULL otherwise
ROMFILE_INFO* searchFileInRom(const ROMDIR_INFO* romdirInfo, const char* filename, ROMFILE_INFO* fileinfo)
{
register ROMDIR_ENTRY* dir_entry;
register ext_offset=0, file_offset=0;
int i;
for (dir_entry = romdirInfo->romdirPtr; dir_entry->name[0]; dir_entry++) {
for(i = 0; i < 10; ++i) {
if( filename[i] == 0 )
break;
if( dir_entry->name[i] != filename[i] ) {
i = -1;
break;
}
}
if (i > 0 ) {
fileinfo->entry = dir_entry;
fileinfo->fileData = file_offset + romdirInfo->romPtr; // address of file in rom
fileinfo->extData = (u32)NULL; // address of extinfo in rom
if (dir_entry->extSize)
fileinfo->extData = ext_offset + romdirInfo->extinfoPtr; // address of extinfo in rom
return fileinfo;
}
file_offset += ROUND_UP(dir_entry->fileSize,16);
ext_offset += dir_entry->extSize;
}
// error - file not found
return NULL;
}
// gets a hex number from *addr and updates the pointer
//
// args: pointer to string buffer containing a hex number
// returns: the value of the hex number
u32 getHexNumber(char** addr)
{
register char *p; //a1
register u32 h = 0; //a2;
for (p=*addr; *p >= '0'; p++)
{
int num;
if(*p <= '9') num = *p - '0';
else if(*p >= 'a') num = *p - 'a' + 10;
else num = *p - 'A' + 10;
h = h*16 + num;
}
*addr = p;
return h;
}

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/SIFCMD
IOP_INCS += -I../include
IOP_OBJS = sifcmd.o ../iopdebug.o ../libkernel/iop_loadcore.o ../libkernel/iop_intrman.o ../libkernel/iop_sifman.o ../libkernel/iop_thbase.o ../libkernel/iop_thevent.o ../libkernel/iop_stdio.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,798 +0,0 @@
//[module] SIFCMD
//[processor] IOP
//[type] ELF-IRX
//[name] IOP_SIF_rpc_interface
//[version] 0x101
//[memory map]
//[handlers]
//[entry point] sifcmd_start, sifcmd_stub
//[made by] [RO]man (roman_ps2dev@hotmail.com)
#include "kloadcore.h"
#include "kintrman.h"
#include "ksifman.h"
#include "kthbase.h"
#include "ksifcmd.h"
#include "ksifman.h"
#define _dprintf(fmt, args...) \
__printf("sifcmd: " fmt, ## args)
int sifInitRpc=0;
// CMD data
char sif1_rcvBuffer[8*16]; //8 qwords
char b[4*16]; //not used
struct tag_cmd_common {
char *sif1_rcvBuffer, //+00
*b, //+04
*saddr; //+08
SifCmdData *sysCmdBuffer; //+0C
int sysCmdBufferSize; //+10
SifCmdData *cmdBuffer; //+14
int cmdBufferSize, //+18
*Sreg, //+1C
systemStatusFlag; //+20
void (*func)(int); //+24
int param, //+28
_pad; //+2C
} cmd_common; //=30
SifCmdData sysCmds[32];
int Sreg[32];
// RPC data
int bufx[512], bufy[512];
struct tag_rpc_common{
int pid;
RPC_PACKET *paddr;
int size;
RPC_PACKET *paddr2;
int size2;
void *next;
int count;
int base;
void *queue;
int _pad0,
_pad1,
_pad2;
} rpc_common;
int _start();
///////////////////////////////////////////////////////////////////////
//////////////////////////// CMD //////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
void cmd80000001_SET_SREG(SifCmdSRData *packet, struct tag_cmd_common *common) {
common->Sreg[packet->rno]=packet->value;
}
///////////////////////////////////////////////////////////////////////
void cmd80000000_CHANGE_SADDR(SifCmdCSData *packet, struct tag_cmd_common *common) {
common->saddr=packet->newaddr;
}
///////////////////////////////////////////////////////////////////////[06]
int SifGetSreg(int index){
return Sreg[index];
}
///////////////////////////////////////////////////////////////////////[07]
int SifSetSreg(int index, unsigned int value){
return Sreg[index]=value;
}
///////////////////////////////////////////////////////////////////////
void *getCmdCommon(){
return &cmd_common;
}
///////////////////////////////////////////////////////////////////////
void cmd80000002_INIT_CMD(SifCmdCSData *packet, struct tag_cmd_common *common){
__printf("cmd80000002_INIT_CMD\n");
if (packet->hdr.opt==0){
iSetEventFlag(common->systemStatusFlag, 0x100);
SifSetEEIOPflags(0x20000);
common->saddr=packet->newaddr;
}else
iSetEventFlag(common->systemStatusFlag, 0x800);
}
///////////////////////////////////////////////////////////////////////[02]
int SifDeinitCmd(){
int x;
DisableIntr(INT_DMA10, &x);
ReleaseIntrHandler(INT_DMA10);
SifDeinit();
return 0;
}
///////////////////////////////////////////////////////////////////////[04]
void SifInitCmd(){
__printf("iopSifInitCmd\n");
SifSetIOPEEflags(0x20000);
WaitEventFlag(cmd_common.systemStatusFlag, 0x100, 0, 0);
}
///////////////////////////////////////////////////////////////////////[05]
void SifExitCmd(){
int x;
DisableIntr(INT_DMA10, &x);
ReleaseIntrHandler(INT_DMA10);
}
///////////////////////////////////////////////////////////////////////[08]
SifCmdData *SifSetCmdBuffer(SifCmdData *cmdBuffer, int size){
register SifCmdData *old;
old=cmd_common.cmdBuffer;
cmd_common.cmdBuffer=cmdBuffer;
cmd_common.cmdBufferSize=size;
return old;
}
///////////////////////////////////////////////////////////////////////[09]
SifCmdData *SifSetSysCmdBuffer(SifCmdData *sysCmdBuffer, int size){
register SifCmdData *old;
old=cmd_common.sysCmdBuffer;
cmd_common.sysCmdBuffer=sysCmdBuffer;
cmd_common.sysCmdBufferSize=size;
return old;
}
///////////////////////////////////////////////////////////////////////[0A]
void SifAddCmdHandler(int pos, cmdh_func f, void *data){
if (pos<0){
cmd_common.sysCmdBuffer[pos & 0x1FFFFFFF].func=f;
cmd_common.sysCmdBuffer[pos & 0x1FFFFFFF].data=data;
}else{
cmd_common.cmdBuffer [pos & 0x1FFFFFFF].func=f;
cmd_common.cmdBuffer [pos & 0x1FFFFFFF].data=data;
}
}
///////////////////////////////////////////////////////////////////////[0B]
void SifRemoveCmdHandler(unsigned int pos){
if (pos<0)
cmd_common.sysCmdBuffer[pos & 0x1FFFFFFF].func=0;
else
cmd_common.cmdBuffer [pos & 0x1FFFFFFF].func=0;
}
///////////////////////////////////////////////////////////////////////
unsigned int sendCmd(unsigned int pos, int mode, SifCmdHdr *cp, int ps, void *src, void *dst, int size){
u32 x;
struct sifman_DMA dma[2];
register int count, y;
if (ps<16 || ps>112) return 0;
count=0;
if (size>0){
count=1;
dma[0].addr=dst;
dma[0].size=size;
dma[0].attr=0;
dma[0].data=src;
cp->daddr=(u32)dst;
cp->dsize=size;
}else{
cp->daddr=0;
cp->dsize=0;
}
count++;
cp->psize=ps;
cp->fcode=pos;
dma[count-1].data=cp;
dma[count-1].attr=SIF_DMA_INT_O; //calls SIF0 handler
dma[count-1].size=ps; //on EE side after transfer;)
dma[count-1].addr=cmd_common.saddr;
if (mode & 1) //interrupt mode
return SifSetDma(dma, count);
else{
CpuSuspendIntr(&x);
y=SifSetDma(dma, count);
CpuResumeIntr(x);
return y;
}
}
///////////////////////////////////////////////////////////////////////[0C]
unsigned int SifSendCmd(unsigned int pos, void *cp, int ps, void *src, void *dst, int size){
return sendCmd(pos, 0, cp, ps, src, dst, size);
}
///////////////////////////////////////////////////////////////////////[0D]
unsigned int iSifSendCmd(unsigned int pos, void *cp, int ps, void *src, void *dst, int size){
return sendCmd(pos, 1, cp, ps, src, dst, size);
}
///////////////////////////////////////////////////////////////////////[1A]
void SifSet1CB(void *func, int param){
cmd_common.func =func;
cmd_common.param=param;
}
///////////////////////////////////////////////////////////////////////[1B]
void SifReset1CB(){
cmd_common.func =0;
cmd_common.param=0;
}
///////////////////////////////////////////////////////////////////////
int SIF1_handler(void *common){
int buf[112/4];
register int i, ps;
register SifCmdData *scd;
SifCmdHdr *packet;
struct tag_cmd_common *c = (struct tag_cmd_common *)common;
if (c->func)
c->func(c->param);
packet=(SifCmdHdr*)c->sif1_rcvBuffer;
if ((ps=packet->psize & 0xFF)==0){
SifSetDChain();
return 1;
}
packet->psize=0;
ps=(ps+3<0 ? ps+6 : ps+3)/4;
for (i=0; i<ps; i++)
buf[i]=((u32*)packet)[i];
SifSetDChain();
packet=(SifCmdHdr*)buf;
if (packet->fcode<0){
if (packet->fcode & 0x7FFFFFFF>=c->sysCmdBufferSize)
return 1;
scd=&c->sysCmdBuffer[packet->fcode & 0x7FFFFFFF];
}else{
if (packet->fcode>=c->cmdBufferSize)
return 1;
scd=&c->cmdBuffer[packet->fcode];
}
if (scd->func)
scd->func(packet, scd->data);
return 1;
}
///////////////////////////////////////////////////////////////////////
//////////////////////////// RPC //////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
RPC_PACKET *rpc_get_packet(struct tag_rpc_common *common){
u32 x;
register int pid, i;
RPC_PACKET *packet;
CpuSuspendIntr(&x);
for (i=0, packet=common->paddr; i<common->size; i++)
if (packet[i].rec_id & 2==0) goto found;
for (i=0, packet=common->paddr2; i<common->size2; i++)
if (packet[i].rec_id & 2==0) goto found;
CpuResumeIntr(x);
return 0;
found:
packet[i].rec_id |= 2;
pid=++common->pid;
if (pid == 1)
common->pid++;
packet[i].pid=pid;
packet[i].paddr=&packet[i];
CpuResumeIntr(x);
return &packet[i];
}
///////////////////////////////////////////////////////////////////////
void rpc_free_packet(RPC_PACKET *packet){
packet->pid = 0;
packet->rec_id &= 0xFFFFFFFD; //~2
}
///////////////////////////////////////////////////////////////////////
RPC_PACKET *rpc_get_fpacket(struct tag_rpc_common *common){
register int i;
i=common->base % common->count;
common->base=i+1;
return (RPC_PACKET*)(((u8*)common->next)+i*64);
}
///////////////////////////////////////////////////////////////////////
void cmd80000008_END(RPC_PACKET_END *packet, struct tag_rpc_common *common){
if (packet->command==0x8000000A){
if (packet->client->func)
packet->client->func(packet->client->param);
}else
if (packet->command==0x80000009){
packet->client->server=packet->server;
packet->client->buff =packet->buff;
packet->client->cbuff =packet->cbuff;
}
if (packet->client->hdr.tid>=0)
iWakeupThread(packet->client->hdr.tid);
rpc_free_packet(packet->client->hdr.pkt_addr);
packet->client->hdr.pkt_addr=0;
}
///////////////////////////////////////////////////////////////////////
void cmd8000000C_RDATA(RPC_PACKET_RDATA *packet, struct tag_rpc_common *common){
RPC_PACKET_END *epacket;
epacket = (RPC_PACKET_END *)rpc_get_fpacket(common);
epacket->packet.paddr = packet->packet.paddr;
epacket->command = 0x8000000C;
epacket->client = packet->client;
iSifSendCmd(0x80000008, epacket, 0x40, packet->src, packet->dst, packet->size);
}
///////////////////////////////////////////////////////////////////////[17]
int SifGetOtherData(struct sifcmd_RPC_RECEIVE_DATA *rd, void *src, void *dst, int size, int mode){
RPC_PACKET_RDATA *packet;
if ((packet=(RPC_PACKET_RDATA *)rpc_get_packet(&rpc_common))==0)
return -1;
rd->hdr.pkt_addr=packet;
rd->hdr.rpc_id =packet->packet.pid;
packet->packet.paddr=packet;
packet->client=(struct sifcmd_RPC_CLIENT_DATA*)rd;
packet->src=src;
packet->dst=dst;
packet->size=size;
if (mode & 1==0){
rd->hdr.tid=GetThreadId();
if (SifSendCmd(0x8000000C, packet, 0x40, 0, 0, 0)==0)
return -2;
SleepThread();
}else{ //async
rd->hdr.tid=-1;
if (SifSendCmd(0x8000000C, packet, 0x40, 0, 0, 0)==0)
return -2;
}
return 0;
}
///////////////////////////////////////////////////////////////////////
struct sifcmd_RPC_SERVER_DATA *search_svdata(u32 command, struct tag_rpc_common *common){
struct sifcmd_RPC_SERVER_DATA *q;
struct sifcmd_RPC_SERVER_DATA *s;
for (q=common->queue; q; q=q->next) {
for (s=q->link; s; s=s->link) {
if (s->command==command)
return s;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////
void cmd80000009_BIND(RPC_PACKET_BIND *packet, struct tag_rpc_common *common){
RPC_PACKET_END *epacket;
struct sifcmd_RPC_SERVER_DATA *s;
epacket = (RPC_PACKET_END *)rpc_get_fpacket(common);
epacket->packet.paddr=packet->packet.paddr;
epacket->command=0x80000009;
epacket->client=packet->client;
s = search_svdata(packet->fno, common);
if (s == NULL){
epacket->server=0;
epacket->buff =0;
epacket->cbuff =0;
}else{
epacket->server=s;
epacket->buff =s->buff;
epacket->cbuff =s->cbuff;
}
iSifSendCmd(0x80000008, epacket, 0x40, 0, 0, 0);
}
///////////////////////////////////////////////////////////////////////[0F]
int SifBindRpc(struct sifcmd_RPC_CLIENT_DATA *client, unsigned int number, unsigned int mode) {
RPC_PACKET_BIND *packet;
client->command=0;
client->server=0;
packet = (RPC_PACKET_BIND *)rpc_get_packet(&rpc_common);
if (packet==NULL) return -1;
client->hdr.pkt_addr = packet;
client->hdr.rpc_id = packet->packet.pid;
packet->packet.paddr = packet;
packet->client = client;
packet->fno = number;
if (mode & 1==0){
client->hdr.tid=GetThreadId();
if (SifSendCmd(0x80000009, packet, 0x40, 0, 0, 0)==0)
return -2;
SleepThread();
}else{ //async
client->hdr.tid=-1;
if (SifSendCmd(0x80000009, packet, 0x40, 0, 0, 0)==0)
return -2;
}
return 0;
}
///////////////////////////////////////////////////////////////////////
void cmd8000000A_CALL(RPC_PACKET_CALL *packet, struct tag_rpc_common *common){
struct sifcmd_RPC_DATA_QUEUE *qd;
qd = packet->server->base;
if (qd->start==0) qd->start=packet->server;
else qd->end->link=packet->server;
qd->end=packet->server;
packet->server->pkt_addr=packet->packet.packet.paddr;
packet->server->client=packet->packet.client;
packet->server->fno=packet->packet.fno;
packet->server->size=packet->size;
packet->server->receive=packet->receive;
packet->server->rsize=packet->rsize;
packet->server->rmode=packet->rmode;
if ((qd->key>=0) && (qd->active==0))
iWakeupThread(qd->key);
}
///////////////////////////////////////////////////////////////////////[10]
int SifCallRpc(struct sifcmd_RPC_CLIENT_DATA *client, unsigned int fno, unsigned int mode, void *send, int ssize, void *receive, int rsize, void (*end_func)(void*), void *end_para){
RPC_PACKET_CALL *packet;
if ((packet=(RPC_PACKET_CALL *)rpc_get_packet(&rpc_common))==0)
return -1;
client->hdr.pkt_addr=(void*)packet;
client->func = end_func;
client->param = end_para;
client->hdr.rpc_id= packet->packet.packet.pid;
packet->packet.packet.paddr = packet;
packet->packet.client = client;
packet->packet.fno = fno;
packet->size = ssize;
packet->receive= receive;
packet->rsize = rsize;
packet->server = client->server;
if (mode & 1){
packet->rmode=(end_func!=0);
client->hdr.tid=-1;
if (SifSendCmd(0x8000000A, packet, 0x40, send, client->buff, ssize))
return 0;
return -2;
}else{
packet->rmode=1;
client->hdr.tid=GetThreadId();
if (SifSendCmd(0x8000000A, packet, 0x40, send, client->buff, ssize)==0)
return -2;
SleepThread();
return 0;
}
}
///////////////////////////////////////////////////////////////////////[12]
int SifCheckStatRpc(struct sifcmd_RPC_HEADER *rd){
RPC_PACKET *packet = (RPC_PACKET*)rd->pkt_addr;
return (rd->pkt_addr &&
(rd->rpc_id==packet->pid) &&
(packet->rec_id & 2));
}
///////////////////////////////////////////////////////////////////////[13]
void SifSetRpcQueue(struct sifcmd_RPC_DATA_QUEUE *qd, int key){
u32 x;
register struct sifcmd_RPC_DATA_QUEUE *q, *i;
CpuSuspendIntr(&x);
qd->key=key;
qd->active=0;
qd->link=0;
qd->start=0;
qd->end=0;
qd->next=0;
q = (struct sifcmd_RPC_DATA_QUEUE *)&rpc_common.queue;
if (q) {
for (i=q->next; i; i=q->next) q=q->next;
}
rpc_common.queue = qd;
CpuResumeIntr(x);
}
///////////////////////////////////////////////////////////////////////[11]
void SifRegisterRpc(struct sifcmd_RPC_SERVER_DATA *sd, u32 command,
rpch_func func, void *buff,
rpch_func cfunc, void *cbuff,
struct sifcmd_RPC_DATA_QUEUE *qd) {
u32 x;
register struct sifcmd_RPC_DATA_QUEUE *q, *i;
CpuSuspendIntr(&x);
sd->command=command;
sd->func=func;
sd->buff=buff;
sd->next=0;
sd->link=0;
sd->cfunc=cfunc;
sd->cbuff=cbuff;
sd->base=qd;
if (qd->link==0)
qd->link=sd;
else{
for (q=qd->link, i=q->link; i; i=q->link)
q=q->link;
q->link=sd;
}
CpuResumeIntr(x);
}
///////////////////////////////////////////////////////////////////////[18]
struct sifcmd_RPC_SERVER_DATA *SifRemoveRpc(struct sifcmd_RPC_SERVER_DATA *sd, struct sifcmd_RPC_DATA_QUEUE *qd){
u32 x;
register struct sifcmd_RPC_SERVER_DATA *s;
CpuSuspendIntr(&x);
if ((s=qd->link)==sd)
qd->link=s->link;
else
for ( ; s; s=s->link)
if (s->link==sd){
s->link=s->link->link;
break;
}
CpuResumeIntr(x);
return s;
}
///////////////////////////////////////////////////////////////////////[19]
struct sifcmd_RPC_DATA_QUEUE *SifRemoveRpcQueue(struct sifcmd_RPC_DATA_QUEUE *qd){
u32 x;
register struct sifcmd_RPC_DATA_QUEUE *q;
CpuSuspendIntr(&x);
q=rpc_common.queue;
if (q==qd) {
rpc_common.queue=q->next;
} else {
for (; q; q=q->next) {
if (q->next==qd){
q->next=q->next->next;
break;
}
}
}
CpuResumeIntr(x);
return q;
}
///////////////////////////////////////////////////////////////////////[14]
struct sifcmd_RPC_SERVER_DATA *SifGetNextRequest(struct sifcmd_RPC_DATA_QUEUE *qd){
u32 x;
register struct sifcmd_RPC_SERVER_DATA *s;
CpuSuspendIntr(&x);
if ((s=qd->start)==0)
qd->active=0;
else{
qd->active=1;
qd->start=qd->start->next;
}
CpuResumeIntr(x);
return s;
}
///////////////////////////////////////////////////////////////////////[15]
void SifExecRequest(struct sifcmd_RPC_SERVER_DATA *sd){
u32 x;
register int size, id, count, i;
register void *buff;
RPC_PACKET_END *epacket;
struct sifman_DMA dma[2];
size=0;
if (buff=sd->func(sd->fno, sd->buff, sd->size))
size=sd->rsize;
CpuSuspendIntr(&x);
epacket=(RPC_PACKET_END *)rpc_get_fpacket(&rpc_common);
CpuResumeIntr(x);
epacket->command=0x8000000A;
epacket->client=sd->client;
count=0;
if (sd->rmode){
while (SifSendCmd(0x80000008, epacket, 0x40, buff, sd->receive, size)==0);
return;
}else{
epacket->packet.pid=0;
epacket->packet.rec_id=0;
if (size>0){
count=1;
dma[count-1].data=buff;
dma[count-1].size=size;
dma[count-1].attr=0;
dma[count-1].addr=sd->receive;
}
count++;
dma[count-1].data=epacket;
dma[count-1].size=0x40;
dma[count-1].attr=0;
dma[count-1].addr=sd->pkt_addr;
do{
CpuSuspendIntr(&x);
id=SifSetDma(dma, count);
CpuResumeIntr(x);
if (id) break;
i=0xFFFF; do --i; while (i!=-1);
} while (id==0);
}
}
///////////////////////////////////////////////////////////////////////[16]
void SifRpcLoop(struct sifcmd_RPC_DATA_QUEUE *qd){
register struct sifcmd_RPC_SERVER_DATA *s;
do{
if (s=SifGetNextRequest(qd))
SifExecRequest(s);
else
SleepThread();
} while (1);
}
///////////////////////////////////////////////////////////////////////[0E]
void SifInitRpc(int mode){
u32 x;
_dprintf("%s\n", __FUNCTION__);
SifInitCmd();
CpuSuspendIntr(&x);
if (sifInitRpc){
CpuResumeIntr(x);
}else{
sifInitRpc=1;
rpc_common.paddr=(RPC_PACKET*)bufx;
rpc_common.size=32;
rpc_common.paddr2=0;
rpc_common.size2=0;
rpc_common.next=(RPC_PACKET*)bufy;
rpc_common.count=32;
rpc_common.base=0;
rpc_common.pid=1;
SifAddCmdHandler(0x80000008, (cmdh_func)cmd80000008_END, &rpc_common);
SifAddCmdHandler(0x80000009, (cmdh_func)cmd80000009_BIND, &rpc_common);
SifAddCmdHandler(0x8000000A, (cmdh_func)cmd8000000A_CALL, &rpc_common);
SifAddCmdHandler(0x8000000C, (cmdh_func)cmd8000000C_RDATA, &rpc_common);
CpuResumeIntr(x);
((SifCmdSRData*)bufx)->rno =0;
((SifCmdSRData*)bufx)->value=1;
SifSendCmd(0x80000001, (void*)bufx, sizeof(SifCmdSRData), 0, 0, 0);
}
WaitEventFlag(GetSystemStatusFlag(), 0x800, 0, 0);
}
void _retonly() {}
struct export sifcmd_stub={
0x41C00000,
0,
VER(1, 1), // 1.1 => 0x101
0,
"sifcmd",
(func)_start, // entrypoint
(func)_retonly,
(func)SifDeinitCmd,
(func)_retonly,
(func)SifInitCmd,
(func)SifExitCmd,
(func)SifGetSreg,
(func)SifSetSreg,
(func)SifSetCmdBuffer,
(func)SifSetSysCmdBuffer,
(func)SifAddCmdHandler,
(func)SifRemoveCmdHandler,
(func)SifSendCmd,
(func)iSifSendCmd,
(func)SifInitRpc,
(func)SifBindRpc,
(func)SifCallRpc,
(func)SifRegisterRpc,
(func)SifCheckStatRpc,
(func)SifSetRpcQueue,
(func)SifGetNextRequest,
(func)SifExecRequest,
(func)SifRpcLoop,
(func)SifGetOtherData,
(func)SifRemoveRpc,
(func)SifRemoveRpcQueue,
(func)SifSet1CB,
(func)SifReset1CB,
(func)_retonly,
(func)_retonly,
(func)_retonly,
(func)_retonly,
0
};
//////////////////////////////entrypoint///////////////////////////////[00]
int _start(){
register int *v, i;
_dprintf("%s\n", __FUNCTION__);
if (v=QueryBootMode(3)){
_dprintf("bootmode: %x\n", v[1]);
if (v[1] & 1){ printf("%s No SIF service(sifcmd)\n", __FUNCTION__);return 1;}
if (v[1] & 2){ printf("%s No SIFCMD/RPC service\n", __FUNCTION__); return 1;}
}
if (SifCheckInit()==0)
SifInit();
if (RegisterLibraryEntries(&sifcmd_stub)) return 1;
cmd_common.sif1_rcvBuffer=sif1_rcvBuffer;
cmd_common.b=b;
cmd_common.sysCmdBuffer=sysCmds;
cmd_common.sysCmdBufferSize=32;
cmd_common.saddr=0;
cmd_common.cmdBuffer=0;
cmd_common.cmdBufferSize=0;
cmd_common.Sreg=Sreg;
cmd_common.func=0;
cmd_common.param=0;
for (i=0; i<32; i++) {
sysCmds[i].func=0;
sysCmds[i].data=0;
}
for (i=0; i<32; i++) {
Sreg[i]=0;
}
sysCmds[0].func=(cmdh_func)cmd80000000_CHANGE_SADDR;
sysCmds[0].data=&cmd_common;
sysCmds[1].func=(cmdh_func)cmd80000001_SET_SREG;
sysCmds[1].data=&cmd_common;
cmd_common.systemStatusFlag=GetSystemStatusFlag();
sysCmds[2].func=(cmdh_func)cmd80000002_INIT_CMD;
sysCmds[2].data=&cmd_common;
RegisterIntrHandler(INT_DMA10, 1, SIF1_handler, (void*)&cmd_common);
EnableIntr(INT_DMA10 | IMODE_DMA_IQE);
SifSetIOPrcvaddr((u32)sif1_rcvBuffer);
return 0;
}

View File

@ -1,19 +0,0 @@
# _____ ___ ____
# ____| | ____| PSX2 OpenSource Project
# | ___| |____ (C)2002, David Ryan ( Oobles@hotmail.com )
# ------------------------------------------------------------------------
IOP_BIN = ../../../build/SIFMAN
IOP_INCS += -I../include
IOP_OBJS = sifman.o ../iopdebug.o ../libkernel/iop_loadcore.o ../libkernel/iop_intrman.o
all: $(IOP_BIN)
clean:
rm -f -r $(IOP_OBJS) $(IOP_BIN)
include $(PS2SDK)/Defs.make
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.iopglobal

View File

@ -1,467 +0,0 @@
#include "kloadcore.h"
#include "kintrman.h"
#include "kdmacman.h"
#include "ksifman.h"
#define min(a, b) ((a)<(b)?(a):(b))
#define max(a, b) ((a)>(b)?(a):(b))
#define CONFIG_1450 (*(volatile int*)0xBF801450)
#define BD0 (*(volatile int*)0xBD000000) //mscom
#define BD1 (*(volatile int*)0xBD000010) //smcom
#define BD2 (*(volatile int*)0xBD000020) //msflag
#define BD3 (*(volatile int*)0xBD000030) //smflag
#define BD4 (*(volatile int*)0xBD000040)
#define BD5 (*(volatile int*)0xBD000050)
#define BD6 (*(volatile int*)0xBD000060)
#define BD7 (*(volatile int*)0xBD000070)
int debug=1;
#define _dprintf(fmt, args...) \
if (debug > 0) __printf("sifman: " fmt, ## args)
struct sifData{
int data,
words,
count,
addr;
};
int sifSIF2Init =0,
sifInit =0;
struct sm_internal{
short id, //+000 some id...?!?
res1; //+002 not used
int index; //+004 current position in dma buffer
struct sifData *crtbuf; //+008 address of current used buffer
struct sifData buf1[32]; //+00C first buffer
struct sifData buf2[32]; //+20C second buffer
int (*function)(int);//+40C a function ?!?
int param; //+410 a parameter for function
int res2; //+414 not used
} vars;
struct sifData one;
int res3, res4;
int _start(int argc, char* argv);
void RegisterSif0Handler();
///////////////////////////////////////////////////////////////////////
int getBD2_loopchanging(){
register int a, b;
a=BD2;
b=BD2;
while (a!=b) {
a=b;
b=BD2;
}
return a;
}
///////////////////////////////////////////////////////////////////////
int getBD3_loopchanging(){
register int a, b;
a=BD3;
b=BD3;
while (a!=b) {
a=b;
b=BD3;
}
return a;
}
///////////////////////////////////////////////////////////////////////[04]
void SifSIF2Init(){
if (sifSIF2Init!=0) return;
DMAch_SIF2_CHCR = 0; //reset ch. 2
DMAch_DPCR|= 0x800; //enable dma ch. 2
DMAch_DPCR;
sifSIF2Init =1;
}
///////////////////////////////////////////////////////////////////////[05]
void SifInit(){
u32 x, y;
u32 msflag;
_dprintf("%s: sifInit=%d\n", __FUNCTION__, sifInit);
if (sifInit!=0) return;
DMAch_DPCR2 |=0x8800; //enable dma ch. 9 and 10
DMAch_SIF9_CHCR = 0;
DMAch_SIFA_CHCR = 0;
SifSIF2Init();
if (CONFIG_1450 & 0x10)
CONFIG_1450 |= 0x10;
CONFIG_1450 |= 0x1;
RegisterSif0Handler();
CpuSuspendIntr(&x); //intrman
CpuEnableIntr(); //intrman
_dprintf("%s: waiting EE...\n", __FUNCTION__);
do { //EE kernel sif ready
CpuSuspendIntr(&y); //intrman
msflag = getBD2_loopchanging();
CpuResumeIntr(y); //intrman
} while(!(msflag & 0x10000));
_dprintf("%s: EE ready\n", __FUNCTION__);
CpuResumeIntr(x); //intrman
SifSetDChain();
SifSetIOPrcvaddr(0); //sif1 receive buffer
BD3 = 0x10000; //IOPEE_sifman_init
BD3;
sifInit =1;
_dprintf("%s ok\n", __FUNCTION__);
}
///////////////////////////////////////////////////////////////////////[02]
void SifDeinit(){
int x;
DisableIntr(INT_DMA9, &x);
ReleaseIntrHandler(INT_DMA9);
DMAch_SIF9_CHCR=0;
DMAch_SIFA_CHCR=0;
if (CONFIG_1450 & 0x10)
CONFIG_1450 |= 0x10;
}
///////////////////////////////////////////////////////////////////////[29]
int SifCheckInit(){
return sifInit;
}
///////////////////////////////////////////////////////////////////////[06]
void SifSetDChain(){
if ((BD4 & 0x40) == 0) BD4=0x40;
DMAch_SIFA_CHCR =0;
DMAch_SIFA_BCR_size =32;
DMAch_SIFA_CHCR =DMAf_08|DMAf_CO|DMAf_TR|DMAf_30;//EE->IOP (to memory)
}
///////////////////////////////////////////////////////////////////////[30]
void SifSet0CB(int (*_function)(int), int _param){
vars.function=_function;
vars.param=_param;
}
///////////////////////////////////////////////////////////////////////[31]
void SifReset0CB(){
vars.function=NULL;
vars.param=0;
}
///////////////////////////////////////////////////////////////////////
int Sif0Handler(void *common) {
struct sm_internal *vars = (struct sm_internal *)common;
int var_10;
if (vars->function)
vars->function(vars->param);
if ((DMAch_SIF9_CHCR & DMAf_TR == 0) && (vars->index>0)) {
DMAch_SIF9_CHCR =0;
DMAch_SIF9_TADR =(int)vars->crtbuf;
DMAch_SIF9_BCR =32;
if (BD4 & 0x20 == 0) BD4 = 0x20;
vars->id++;
if (vars->crtbuf == vars->buf1){
vars->index=0;
vars->crtbuf=vars->buf2;
}else
vars->crtbuf=vars->buf1;
DMAch_SIF9_CHCR = DMAf_DR|DMAf_08|DMAf_CO|DMAf_LI|DMAf_TR;//IOP->EE (from memory)
var_10=DMAch_SIF9_CHCR;
}
return 1;
}
///////////////////////////////////////////////////////////////////////
void RegisterSif0Handler(){
u32 x;
vars.index=0;
vars.crtbuf=vars.buf1;
vars.function=NULL;
vars.param=0;
CpuSuspendIntr(&x); //intrman
RegisterIntrHandler(INT_DMA9, 1, Sif0Handler, &vars); //intrman
EnableIntr(INT_DMA9); //intrman
CpuResumeIntr(x); //intrman
}
///////////////////////////////////////////////////////////////////////
void enqueue(struct sifman_DMA *psd){
vars.crtbuf[vars.index].data=(u32)psd->data & 0xFFFFFF; //16MB addressability
if (psd->attr & SIF_DMA_INT_I)
vars.crtbuf[vars.index].data |= 0x40000000;
vars.crtbuf[vars.index].words=(psd->size + 3)/4 & 0xFFFFFF;
vars.crtbuf[vars.index].count = ((psd->size + 3)/16 + (((psd->size + 3)/4) & 3))
| 0x10000000;
if (psd->attr & SIF_DMA_INT_O)
vars.crtbuf[vars.index].count |=0x80000000;
vars.crtbuf[vars.index].addr = (u32)psd->addr & 0x1FFFFFFF; //512MB addresability
vars.index++;
}
///////////////////////////////////////////////////////////////////////[07]
u32 SifSetDma(struct sifman_DMA *psd, int len){
int var_20;
register unsigned int ret;
int i;
if (32-vars.index < len) return 0; //no place
ret = vars.id;
ret = (ret << 16) | ((vars.index & 0xFF) << 8) | (len & 0xFF);
if (vars.index)
vars.crtbuf[vars.index-1].data &= 0x7FFFFFFF;
for (i=0; i<len; i++)
enqueue(&psd[i]);
vars.crtbuf[vars.index-1].data |= 0x80000000;
if ((DMAch_SIF9_CHCR & DMAf_TR) == 0) {
DMAch_SIF9_CHCR=0;
DMAch_SIF9_TADR=(int)vars.crtbuf;
if ((BD4 & 0x20) == 0) BD4=0x20;
DMAch_SIF9_BCR_size=32;
vars.index=0;
vars.id++;
if (vars.crtbuf==vars.buf1)vars.crtbuf=vars.buf2;
//stupid :D (why the if?)
DMAch_SIF9_CHCR=DMAf_DR|DMAf_08|DMAf_CO|DMAf_LI|DMAf_TR;//IOP->EE
var_20=DMAch_SIF9_CHCR; //?!?
}
return ret;
}
///////////////////////////////////////////////////////////////////////[08]
int SifDmaStat(u32 id){
if (DMAch_SIF9_CHCR & DMAf_TR){
if (id>>16 == vars.id) return 1; //waiting in queue
if (id>>16+1 == vars.id) return 0; //running
}
return -1; //terminated
}
///////////////////////////////////////////////////////////////////////[09]
void SifSend(struct sifman_DMA sd){
sd.size = sd.size /4 + ((sd.size & 3) > 0);
one.data = ((u32)sd.data & 0xFFFFFF) | 0x80000000;
one.words= sd.size & 0xFFFFFF;
if (sd.attr & SIF_DMA_INT_I) one.data |= 0x40000000;
one.count = (sd.size/4 + ((sd.size & 3)>0)) | 0x10000000;
if (sd.attr & SIF_DMA_INT_O) one.count|= 0x80000000;
one.addr = (u32)sd.addr & 0xFFFFFFF;
if (BD4 & 0x20 == 0) BD4=0x20;
DMAch_SIF9_CHCR=0;
DMAch_SIF9_TADR=(u32)&one;
DMAch_SIF9_BCR_size=32;
DMAch_SIF9_CHCR=DMAf_DR|DMAf_08|DMAf_CO|DMAf_LI|DMAf_TR; //IOP->EE
DMAch_SIF9_CHCR;
}
///////////////////////////////////////////////////////////////////////[10]
void SifSendSync(){
while (DMAch_SIF9_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[11]
int SifIsSending(){
return (DMAch_SIF9_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[12]
void SifSetSIF0DMA(void *data, int size, int attr){
size=size/4 + ((size & 3)>0);
if (BD4 & 0x20 == 0) BD4=0x20;
DMAch_SIF9_CHCR=0;
DMAch_SIF9_MADR=(u32)data & 0xFFFFFF;
DMAch_SIF9_BCR_size=32;
DMAch_SIF9_BCR_count=size/32 + ((size & 0x1F)>0);
DMAch_SIF9_CHCR=DMAf_DR|DMAf_CO|DMAf_TR;
DMAch_SIF9_CHCR;
}
///////////////////////////////////////////////////////////////////////[13]
void SifSendSync0(){
while (DMAch_SIF9_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[14]
int SifIsSending0(){
return (DMAch_SIF9_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[15]
void SifSetSIF1DMA(void *data, int size, int attr){
size=size/4 + ((size & 3)>0);
if (BD4 & 0x40 == 0) BD4=0x40;
DMAch_SIFA_CHCR=0;
DMAch_SIFA_MADR=(u32)data & 0xFFFFFF;
DMAch_SIFA_BCR_size=32;
DMAch_SIFA_BCR_count=size/32 + ((size & 0x1F)>0);
DMAch_SIFA_CHCR=DMAf_CO|DMAf_TR|
(attr & SIF_DMA_BSN?DMAf_30:0);
DMAch_SIFA_CHCR;
}
///////////////////////////////////////////////////////////////////////[16]
void SifSendSync1(){
while (DMAch_SIFA_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[17]
int SifIsSending1(){
return (DMAch_SIFA_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[18]
void SifSetSIF2DMA(void *data, int size, int attr){
size=size/4 + ((size & 3)>0);
if (BD4 & 0x80 == 0) BD4=0x80;
DMAch_SIF2_CHCR=0;
DMAch_SIF2_MADR=(u32)data & 0xFFFFFF;
DMAch_SIF2_BCR_size=min(size, 32);
DMAch_SIF2_BCR_count=size/32 + ((size & 0x1F)>0);
DMAch_SIF2_CHCR=DMAf_CO |DMAf_TR|
((attr & SIF_TO_EE ?DMAf_DR:
(attr & SIF_DMA_BSN?DMAf_30:0)));
DMAch_SIF2_CHCR;
}
///////////////////////////////////////////////////////////////////////[19]
void SifSendSync2(){
while (DMAch_SIF2_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[20]
int SifIsSending2(){
return (DMAch_SIF2_CHCR & DMAf_TR);
}
///////////////////////////////////////////////////////////////////////[21]
int SifGetEEIOPflags(){
return getBD2_loopchanging();
}
///////////////////////////////////////////////////////////////////////[22]
int SifSetEEIOPflags(int val){
BD2=val;
return getBD2_loopchanging();
}
///////////////////////////////////////////////////////////////////////[23]
int SifGetIOPEEflags(){
return getBD3_loopchanging();
}
///////////////////////////////////////////////////////////////////////[24]
int SifSetIOPEEflags(int val){
BD3=val;
return getBD3_loopchanging();
}
///////////////////////////////////////////////////////////////////////[25]
int SifGetEErcvaddr(){
return BD0;
}
///////////////////////////////////////////////////////////////////////[26]
int SifGetIOPrcvaddr(){
return BD1;
}
///////////////////////////////////////////////////////////////////////[27]
int SifSetIOPrcvaddr(int val){
BD1=val;
return BD1;
}
///////////////////////////////////////////////////////////////////////[28]
void SifSet1450_2(){
CONFIG_1450 |= 2;
CONFIG_1450 &= ~2;
CONFIG_1450;
}
///////////////////////////////////////////////////////////////////////[01,03,32,33,34,35]
void _retonly(){}
//////////////////////////////entrypoint///////////////////////////////
struct export sifman_stub={
0x41C00000,
0,
VER(1, 1), // 1.1 => 0x101
0,
"sifman",
(func)_start, // entrypoint
(func)_retonly,
(func)SifDeinit,
(func)_retonly,
(func)SifSIF2Init,
(func)SifInit,
(func)SifSetDChain,
(func)SifSetDma,
(func)SifDmaStat,
(func)SifSend,
(func)SifSendSync,
(func)SifIsSending,
(func)SifSetSIF0DMA,
(func)SifSendSync0,
(func)SifIsSending0,
(func)SifSetSIF1DMA,
(func)SifSendSync1,
(func)SifIsSending1,
(func)SifSetSIF2DMA,
(func)SifSendSync2,
(func)SifIsSending2,
(func)SifGetEEIOPflags,
(func)SifSetEEIOPflags,
(func)SifGetIOPEEflags,
(func)SifSetIOPEEflags,
(func)SifGetEErcvaddr,
(func)SifGetIOPrcvaddr,
(func)SifSetIOPrcvaddr,
(func)SifSet1450_2,
(func)SifCheckInit,
(func)SifSet0CB,
(func)SifReset0CB,
(func)_retonly,
(func)_retonly,
(func)_retonly,
(func)_retonly,
0
};
//////////////////////////////entrypoint///////////////////////////////[00]
int _start(int argc, char* argv){
return RegisterLibraryEntries(&sifman_stub) > 0;
}

Some files were not shown because too many files have changed in this diff Show More