From 902dc0b82976e020a7a08620b59263eff58b6134 Mon Sep 17 00:00:00 2001 From: Lywx Date: Wed, 14 Feb 2024 09:24:31 -0600 Subject: [PATCH] Match Libultra (#120) * Matched perspective, contquery, contreaddata, recvmesg and sendmesg * Fixed libultra compilation flags * Matched viblack * Matched virepeatline, visetmode, visetspecial and viswapbuf * Matched cartrominit, dpsetstat, sptask, sptaskyield, visetevent, createthread, gettime, setthreadpri, settime, settimer and starthread * Fixed bss bs * Matched even more libultra stuff * Matched even more * __osRdbSend * Decompiled most of the functions of libultra <3 * Matched last functions * Added a separation to libultra macros * Removed ARRLEN from controller.h * Fix libultra warnings --------- Co-authored-by: Alejandro Javier Asenjo Nitti --- Makefile | 101 ++- include/PR/assert.h | 12 + include/PR/controller.h | 4 +- include/PR/guint.h | 42 ++ include/PR/os.h | 986 +------------------------- include/PR/os_ai.h | 92 +++ include/PR/os_cache.h | 96 +++ include/PR/os_cont.h | 208 ++++++ include/PR/os_convert.h | 111 +++ include/PR/os_debug.h | 117 +++ include/PR/os_eeprom.h | 107 +++ include/PR/os_error.h | 86 +++ include/PR/os_exception.h | 86 +++ include/PR/os_flash.h | 77 ++ include/PR/os_gbpak.h | 107 +++ include/PR/os_gio.h | 86 +++ include/PR/os_host.h | 166 +++++ include/PR/os_internal.h | 1 + include/PR/os_libc.h | 100 +++ include/PR/os_message.h | 162 +++++ include/PR/os_motor.h | 84 +++ include/PR/os_pfs.h | 200 ++++++ include/PR/os_pi.h | 221 ++++++ include/PR/os_rdp.h | 92 +++ include/PR/os_reg.h | 90 +++ include/PR/os_rsp.h | 86 +++ include/PR/os_si.h | 86 +++ include/PR/os_system.h | 118 +++ include/PR/os_thread.h | 161 +++++ include/PR/os_time.h | 114 +++ include/PR/os_tlb.h | 107 +++ include/PR/os_vi.h | 298 ++++++++ include/PR/os_voice.h | 108 +++ include/PR/rcp.h | 154 ++-- include/PR/sptask.h | 2 +- include/PR/viint.h | 71 ++ include/PR/xstdio.h | 43 +- include/macros.h | 15 +- include/rmonint.h | 2 +- src/libultra/debug/kdebugserver.c | 93 ++- src/libultra/gu/cosf.c | 126 +++- src/libultra/gu/mtxutil.c | 77 +- src/libultra/gu/perspective.c | 60 +- src/libultra/gu/sinf.c | 143 +++- src/libultra/host/readhost.c | 37 +- src/libultra/io/aisetnextbuf.c | 9 +- src/libultra/io/cartrominit.c | 100 ++- src/libultra/io/conteepprobe.c | 20 +- src/libultra/io/conteepread.c | 87 ++- src/libultra/io/conteepwrite.c | 143 +++- src/libultra/io/contquery.c | 26 +- src/libultra/io/contramread.c | 171 ++++- src/libultra/io/contramwrite.c | 177 ++++- src/libultra/io/contreaddata.c | 75 +- src/libultra/io/controller.c | 10 +- src/libultra/io/crc.c | 115 ++- src/libultra/io/devmgr.c | 109 ++- src/libultra/io/dpsetstat.c | 10 +- src/libultra/io/epidma.c | 62 +- src/libultra/io/epirawdma.c | 54 +- src/libultra/io/epirawread.c | 30 +- src/libultra/io/epirawwrite.c | 23 +- src/libultra/io/leodiskinit.c | 39 +- src/libultra/io/leointerrupt.c | 196 ++++- src/libultra/io/motor.c | 8 +- src/libultra/io/pfsgetstatus.c | 29 +- src/libultra/io/pfsisplug.c | 106 ++- src/libultra/io/piacs.c | 26 +- src/libultra/io/pigetcmdq.c | 11 +- src/libultra/io/pimgr.c | 38 +- src/libultra/io/pirawdma.c | 54 +- src/libultra/io/pirawread.c | 30 +- src/libultra/io/si.c | 16 +- src/libultra/io/siacs.c | 26 +- src/libultra/io/sirawdma.c | 44 +- src/libultra/io/sirawread.c | 24 +- src/libultra/io/sirawwrite.c | 23 +- src/libultra/io/sp.c | 18 +- src/libultra/io/spgetstat.c | 10 +- src/libultra/io/sprawdma.c | 34 +- src/libultra/io/sprawread.c | 25 +- src/libultra/io/sprawwrite.c | 24 +- src/libultra/io/spsetpc.c | 16 +- src/libultra/io/spsetstat.c | 10 +- src/libultra/io/sptask.c | 83 ++- src/libultra/io/sptaskyield.c | 7 +- src/libultra/io/sptaskyielded.c | 19 +- src/libultra/io/vi.c | 40 +- src/libultra/io/viblack.c | 18 +- src/libultra/io/vigetcurrcontext.c | 10 +- src/libultra/io/vimgr.c | 127 +++- src/libultra/io/virepeatline.c | 18 +- src/libultra/io/visetevent.c | 28 +- src/libultra/io/visetmode.c | 28 +- src/libultra/io/visetspecial.c | 73 +- src/libultra/io/viswapbuf.c | 32 +- src/libultra/io/viswapcontext.c | 81 ++- src/libultra/libc/xldtob.c | 308 +++++++- src/libultra/libc/xlitob.c | 34 +- src/libultra/libc/xprintf.c | 252 ++++++- src/libultra/os/createthread.c | 55 +- src/libultra/os/getthreadpri.c | 11 +- src/libultra/os/gettime.c | 26 +- src/libultra/os/initialize.c | 225 +++++- src/libultra/os/initrdb.c | 32 +- src/libultra/os/jammesg.c | 38 +- src/libultra/os/rdbsend.c | 74 +- src/libultra/os/recvmesg.c | 41 +- src/libultra/os/resetglobalintmask.c | 10 +- src/libultra/os/sendmesg.c | 39 +- src/libultra/os/seteventmesg.c | 40 +- src/libultra/os/setglobalintmask.c | 10 +- src/libultra/os/setthreadpri.c | 37 +- src/libultra/os/settime.c | 17 +- src/libultra/os/settimer.c | 57 +- src/libultra/os/startthread.c | 40 +- src/libultra/os/thread.c | 29 +- src/libultra/os/timerintr.c | 145 +++- src/libultra/os/virtualtophysical.c | 14 +- src/libultra/os/yieldthread.c | 11 +- src/libultra/rmon/rmonbrk.c | 433 ++++++++++- src/libultra/rmon/rmoncmds.c | 55 +- src/libultra/rmon/rmonmain.c | 139 +++- src/libultra/rmon/rmonmem.c | 286 +++++++- src/libultra/rmon/rmonmisc.c | 64 +- src/libultra/rmon/rmonregs.c | 423 ++++++++++- src/libultra/rmon/rmonsio.c | 90 ++- src/libultra/rmon/rmontask.c | 345 ++++++++- src/libultra/vimodes/vimodempallan1.c | 37 + src/libultra/vimodes/vimodentsclan1.c | 37 + src/libultra/vimodes/vimodepallan1.c | 37 + src/main/fox_360.c | 1 + src/main/fox_hud.c | 1 + src/main/sys_fault.c | 2 +- src/main/sys_sprintf.c | 4 +- src/overlays/ovl_i4/fox_bo.c | 2 + src/overlays/ovl_menu/fox_map.c | 3 +- yamls/us/main.yaml | 86 +-- 138 files changed, 10087 insertions(+), 1430 deletions(-) create mode 100644 include/PR/assert.h create mode 100644 include/PR/guint.h create mode 100644 include/PR/os_ai.h create mode 100644 include/PR/os_cache.h create mode 100644 include/PR/os_cont.h create mode 100644 include/PR/os_convert.h create mode 100644 include/PR/os_debug.h create mode 100644 include/PR/os_eeprom.h create mode 100644 include/PR/os_error.h create mode 100644 include/PR/os_exception.h create mode 100644 include/PR/os_flash.h create mode 100644 include/PR/os_gbpak.h create mode 100644 include/PR/os_gio.h create mode 100644 include/PR/os_host.h create mode 100644 include/PR/os_libc.h create mode 100644 include/PR/os_message.h create mode 100644 include/PR/os_motor.h create mode 100644 include/PR/os_pfs.h create mode 100644 include/PR/os_pi.h create mode 100644 include/PR/os_rdp.h create mode 100644 include/PR/os_reg.h create mode 100644 include/PR/os_rsp.h create mode 100644 include/PR/os_si.h create mode 100644 include/PR/os_system.h create mode 100644 include/PR/os_thread.h create mode 100644 include/PR/os_time.h create mode 100644 include/PR/os_tlb.h create mode 100644 include/PR/os_vi.h create mode 100644 include/PR/os_voice.h create mode 100644 include/PR/viint.h create mode 100644 src/libultra/vimodes/vimodempallan1.c create mode 100644 src/libultra/vimodes/vimodentsclan1.c create mode 100644 src/libultra/vimodes/vimodepallan1.c diff --git a/Makefile b/Makefile index 9e60da560..cba3cd9ab 100644 --- a/Makefile +++ b/Makefile @@ -196,9 +196,9 @@ WARNINGS := -fullwarn -verbose -woff 624,649,838,712,516,513,596,564,594, ASFLAGS := -march=vr4300 -32 -G0 COMMON_DEFINES := -D_MIPS_SZLONG=32 GBI_DEFINES := -DF3DEX_GBI -RELEASE_DEFINES := -DNDEBUG -D_FINALROM +RELEASE_DEFINES := -DNDEBUG AS_DEFINES := -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_ULTRA64 -C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C -DBUILD_VERSION=VERSION_H +C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C -DBUILD_VERSION=VERSION_H ${RELEASE_DEFINES} ENDIAN := -EB OPTFLAGS := -O2 -g3 @@ -254,41 +254,130 @@ build/src/main/sys_audio_1EB50.o: OPTFLAGS := -O1 -g0 build/src/main/sys_sprintf.o: OPTFLAGS := -O2 -g0 build/src/main/sys_math64.o: OPTFLAGS := -O2 -g0 +build/src/libultra/debug/kdebugserver.o: OPTFLAGS := -O1 -g0 + build/src/libultra/gu/sqrtf.o: OPTFLAGS := -O3 -g0 build/src/libultra/gu/ortho.o: OPTFLAGS := -O3 -g0 build/src/libultra/gu/lookat.o: OPTFLAGS := -O3 -g0 - -build/src/libultra/io/pidma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/gu/perspective.o: OPTFLAGS := -O3 -g0 +build/src/libultra/gu/sinf.o: OPTFLAGS := -O3 -g0 +build/src/libultra/gu/cosf.o: OPTFLAGS := -O3 -g0 +build/src/libultra/gu/mtxutil.o: OPTFLAGS := -O3 -g0 + +build/src/libultra/host/readhost.o: OPTFLAGS := -O1 -g0 + +build/src/libultra/io/crc.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/contramwrite.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/cartrominit.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/contquery.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/contramread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/devmgr.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/epidma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/epirawdma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/epirawwrite.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/epirawread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/leodiskinit.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/leointerrupt.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pigetcmdq.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/conteepread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/conteepwrite.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/conteepprobe.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/contreaddata.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/dpsetstat.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/aisetnextbuf.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/pimgr.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pidma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pirawdma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pfsisplug.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/spsetpc.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/motor.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/ai.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/vi.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/aigetlen.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/aisetfreq.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pfsgetstatus.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/si.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/siacs.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sp.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sirawdma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sirawread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sirawwrite.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sprawwrite.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sprawread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sprawdma.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/spgetstat.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sptaskyielded.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sptaskyield.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/sptask.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/spsetstat.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/pirawread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/piacs.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/viblack.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/vimgr.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/vigetcurrcontext.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/virepeatline.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/visetmode.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/visetspecial.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/visetevent.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/viswapbuf.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/viswapcontext.o: OPTFLAGS := -O1 -g0 build/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0 build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0 build/src/libultra/libc/xlitob.o: OPTFLAGS := -O2 -g0 +build/src/libultra/libc/xldtob.o: OPTFLAGS := -O3 -g0 +build/src/libultra/libc/xprintf.o: OPTFLAGS := -O3 -g0 build/src/libultra/libc/ll.o: OPTFLAGS := -O1 -g0 build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32 build/src/libultra/os/createmesgqueue.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/createthread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/setglobalintmask.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/gettime.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/initialize.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/jammesg.o: OPTFLAGS := -O1 -g0 build/src/libultra/os/destroythread.o: OPTFLAGS := -O1 -g0 build/src/libultra/os/getactivequeue.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/recvmesg.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/rdbsend.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/resetglobalintmask.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/sendmesg.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/startthread.o: OPTFLAGS := -O1 -g0 build/src/libultra/os/stopthread.o: OPTFLAGS := -O1 -g0 - +build/src/libultra/os/setthreadpri.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/settimer.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/settime.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/seteventmesg.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/initrdb.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/thread.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/timerintr.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/timerintr.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/getthreadpri.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/virtualtophysical.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/yieldthread.o: OPTFLAGS := -O1 -g0 + +build/src/libultra/rmon/rmoncmds.o: OPTFLAGS := -O1 -g0 +build/src/libultra/rmon/rmonmain.o: OPTFLAGS := -O1 -g0 build/src/libultra/rmon/rmonmem.o: OPTFLAGS := -O1 -g0 +build/src/libultra/rmon/rmonbrk.o: OPTFLAGS := -O1 -g0 build/src/libultra/rmon/rmontask.o: OPTFLAGS := -O1 -g0 build/src/libultra/rmon/rmonregs.o: OPTFLAGS := -O1 -g0 -build/src/libultra/rmon/rmonmisc.o: OPTFLAGS := -O1 -g0 +build/src/libultra/rmon/rmonmisc.o: OPTFLAGS := -O1 -G0 +build/src/libultra/rmon/rmonsio.o: OPTFLAGS := -O1 -g0 # cc & asm-processor CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) -- build/src/libultra/gu/sqrtf.o: CC := $(IDO) +build/src/libultra/gu/sinf.o: CC := $(IDO) build/src/libultra/gu/lookat.o: CC := $(IDO) build/src/libultra/gu/ortho.o: CC := $(IDO) build/src/libultra/libc/ll.o: CC := $(IDO) +build/src/libultra/gu/perspective.o: CC := $(IDO) +build/src/libultra/gu/mtxutil.o: CC := $(IDO) +build/src/libultra/gu/cosf.o: CC := $(IDO) +build/src/libultra/libc/xprintf.o: CC := $(IDO) +build/src/libultra/libc/xldtob.o: CC := $(IDO) #build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) -- diff --git a/include/PR/assert.h b/include/PR/assert.h new file mode 100644 index 000000000..bfbf2555e --- /dev/null +++ b/include/PR/assert.h @@ -0,0 +1,12 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ + +#ifdef NDEBUG +#undef assert +#define assert(EX) ((void)0) +#else +extern void __assert(const char *, const char *, int); +#define assert(EX) ((EX)?((void)0):__assert("EX", __FILE__, __LINE__)) +#endif /* NDEBUG */ + +#endif /* !__ASSERT_H__ */ diff --git a/include/PR/controller.h b/include/PR/controller.h index da201fc28..c443a296c 100644 --- a/include/PR/controller.h +++ b/include/PR/controller.h @@ -1,12 +1,12 @@ #ifndef _CONTROLLER_H #define _CONTROLLER_H +#include "macros.h" +#include "PR/ultratypes.h" #include "PR/os_internal.h" #include "PR/os_version.h" #include "PR/rcp.h" -//should go somewhere else but -#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) #define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4) typedef struct diff --git a/include/PR/guint.h b/include/PR/guint.h new file mode 100644 index 000000000..692b08f26 --- /dev/null +++ b/include/PR/guint.h @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "PR/mbi.h" +#include "PR/gu.h" + +typedef union +{ + struct + { + unsigned int hi; + unsigned int lo; + } word; + + double d; +} du; + +typedef union +{ + unsigned int i; + float f; +} fu; + +#ifndef __GL_GL_H__ + +typedef float Matrix[4][4]; + +#endif + +#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5)) +#define ABS(d) ((d) > 0) ? (d) : -(d) + +extern float __libm_qnan_f; diff --git a/include/PR/os.h b/include/PR/os.h index 9af45371b..5de240174 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -19,414 +19,58 @@ * Copyright Laws of the United States. *====================================================================*/ -/************************************************************************** - * - * $Revision: 1.149 $ - * $Date: 1997/12/15 04:30:52 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/os.h,v $ - * - **************************************************************************/ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + $RCSfile: os.h,v $ + $Revision: 1.168 $ + $Date: 2000/06/15 06:24:52 $ + *---------------------------------------------------------------------*/ #ifndef _OS_H_ #define _OS_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif #include -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef s32 OSPri; -typedef s32 OSId; -typedef union { struct { f32 f_odd; f32 f_even; } f; f64 d; } __OSfp; - -typedef struct { - u64 at, v0, v1, a0, a1, a2, a3; - u64 t0, t1, t2, t3, t4, t5, t6, t7; - u64 s0, s1, s2, s3, s4, s5, s6, s7; - u64 t8, t9, gp, sp, s8, ra; - u64 lo, hi; - u32 sr, pc, cause, badvaddr, rcp; - u32 fpcsr; - __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; - __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; -} __OSThreadContext; - -typedef struct OSThread_s { - struct OSThread_s *next; /* run/mesg queue link */ - OSPri priority; /* run/mesg queue priority */ - struct OSThread_s **queue; /* queue thread is on */ - struct OSThread_s *tlnext; /* all threads queue link */ - u16 state; /* OS_STATE_* */ - u16 flags; /* flags for rmon */ - OSId id; /* id for debugging */ - int fp; /* thread has used fp unit */ - __OSThreadContext context; /* register/interrupt mask */ -} OSThread; - -typedef u32 OSEvent; -typedef u32 OSIntMask; -typedef u32 OSPageMask; -typedef u32 OSHWIntr; - -/* - * Structure for message - */ -typedef void * OSMesg; - -/* - * Structure for message queue - */ -typedef struct OSMesgQueue_s { - OSThread *mtqueue; /* Queue to store threads blocked - on empty mailboxes (receive) */ - OSThread *fullqueue; /* Queue to store threads blocked - on full mailboxes (send) */ - s32 validCount; /* Contains number of valid message */ - s32 first; /* Points to first valid message */ - s32 msgCount; /* Contains total # of messages */ - OSMesg *msg; /* Points to message buffer array */ -} OSMesgQueue; - -/* - * Structure for Enhanced PI interface - */ - -/* - * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained - * by exception handler. This is how the PIMGR and the ISR communicate. - */ - -typedef struct { - u32 errStatus; /* error status */ - void *dramAddr; /* RDRAM buffer address (DMA) */ - void *C2Addr; /* C2 buffer address */ - u32 sectorSize; /* size of transfering sector */ - u32 C1ErrNum; /* total # of C1 errors */ - u32 C1ErrSector[4]; /* error sectors */ -} __OSBlockInfo; - -typedef struct { - u32 cmdType; /* for disk only */ - u16 transferMode; /* Block, Track, or sector? */ - u16 blockNum; /* which block is transfering */ - s32 sectorNum; /* which sector is transfering */ - u32 devAddr; /* Device buffer address */ - u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ - u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ - __OSBlockInfo block[2]; /* bolck transfer info */ -} __OSTranxInfo; - - -typedef struct OSPiHandle_s { - struct OSPiHandle_s *next; /* point to next handle on the table */ - u8 type; /* DEVICE_TYPE_BULK for disk */ - u8 latency; /* domain latency */ - u8 pageSize; /* domain page size */ - u8 relDuration; /* domain release duration */ - u8 pulse; /* domain pulse width */ - u8 domain; /* which domain */ - u32 baseAddress; /* Domain address */ - u32 speed; /* for roms only */ - /* The following are "private" elements" */ - __OSTranxInfo transferInfo; /* for disk only */ -} OSPiHandle; - -typedef struct { - u8 type; - u32 address; -} OSPiInfo; - -/* - * Structure for I/O message block - */ -typedef struct { - u16 type; /* Message type */ - u8 pri; /* Message priority (High or Normal) */ - u8 status; /* Return status */ - OSMesgQueue *retQueue; /* Return message queue to notify I/O - * completion */ -} OSIoMesgHdr; - -typedef struct { - OSIoMesgHdr hdr; /* Message header */ - void * dramAddr; /* RDRAM buffer address (DMA) */ - u32 devAddr; /* Device buffer address (DMA) */ - u32 size; /* DMA transfer size in bytes */ - OSPiHandle *piHandle; /* PI device handle */ -} OSIoMesg; - -/* - * Structure for device manager block - */ -typedef struct { - s32 active; /* Status flag */ - OSThread *thread; /* Calling thread */ - OSMesgQueue *cmdQueue; /* Command queue */ - OSMesgQueue *evtQueue; /* Event queue */ - OSMesgQueue *acsQueue; /* Access queue */ - /* Raw DMA routine */ - s32 (*dma)(s32, u32, void *, u32); - s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); -} OSDevMgr; - - -/* - * Structure to store VI register values that remain the same between 2 fields - */ -typedef struct { - u32 ctrl; - u32 width; - u32 burst; - u32 vSync; - u32 hSync; - u32 leap; - u32 hStart; - u32 xScale; - u32 vCurrent; -} OSViCommonRegs; - - -/* - * Structure to store VI register values that change between fields - */ -typedef struct { - u32 origin; - u32 yScale; - u32 vStart; - u32 vBurst; - u32 vIntr; -} OSViFieldRegs; - - -/* - * Structure for VI mode - */ -typedef struct { - u8 type; /* Mode type */ - OSViCommonRegs comRegs; /* Common registers for both fields */ - OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ -} OSViMode; - -/* - * Structure for time value - */ -typedef u64 OSTime; - -/* - * Structure for interval timer - */ -typedef struct OSTimer_s { - struct OSTimer_s *next; /* point to next timer in list */ - struct OSTimer_s *prev; /* point to previous timer in list */ - OSTime interval; /* duration set by user */ - OSTime value; /* time remaining before */ - /* timer fires */ - OSMesgQueue *mq; /* Message Queue */ - OSMesg msg; /* Message to send */ -} OSTimer; - -/* - * Structure for controllers - */ - -typedef struct { - u16 type; /* Controller Type */ - u8 status; /* Controller status */ - u8 errno; -} OSContStatus; - -typedef struct { - u16 button; - s8 stick_x; /* -80 <= stick_x <= 80 */ - s8 stick_y; /* -80 <= stick_y <= 80 */ - u8 errno; -} OSContPad; - -typedef struct { - void *address; /* Ram pad Address: 11 bits */ - u8 databuffer[32]; /* address of the data buffer */ - u8 addressCrc; /* CRC code for address */ - u8 dataCrc; /* CRC code for data */ - u8 errno; -} OSContRamIo; - -/* - * Structure for file system - */ - - - -typedef struct { - int status; - OSMesgQueue *queue; - int channel; - u8 id[32]; - u8 label[32]; - int version; - int dir_size; - int inode_table; /* block location */ - int minode_table; /* mirrioring inode_table */ - int dir_table; /* block location */ - int inode_start_page; /* page # */ - u8 banks; - u8 activebank; -} OSPfs; - - -typedef struct { - u32 file_size; /* bytes */ - u32 game_code; - u16 company_code; - char ext_name[4]; - char game_name[16]; -} OSPfsState; - -/* - * Structure for Profiler - */ -typedef struct { - u16 *histo_base; /* histogram base */ - u32 histo_size; /* histogram size */ - u32 *text_start; /* start of text segment */ - u32 *text_end; /* end of text segment */ -} OSProf; - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - /************************************************************************** * * Global definitions * */ -/* Thread states */ - -#define OS_STATE_STOPPED 1 -#define OS_STATE_RUNNABLE 2 -#define OS_STATE_RUNNING 4 -#define OS_STATE_WAITING 8 - -/* Events */ -#ifdef _FINALROM -#define OS_NUM_EVENTS 15 -#else -#define OS_NUM_EVENTS 23 -#endif - -#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ -#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ -#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ -#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ -#define OS_EVENT_SP 4 /* SP task done interrupt */ -#define OS_EVENT_SI 5 /* SI (controller) interrupt */ -#define OS_EVENT_AI 6 /* AI interrupt */ -#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ -#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ -#define OS_EVENT_DP 9 /* DP full sync interrupt */ -#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ -#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ -#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ -#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ -#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ -#ifndef _FINALROM -#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ -#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ -#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ -#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ -#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ -#define OS_EVENT_RDB_DBG_DONE 20 -#define OS_EVENT_RDB_FLUSH_PROF 21 -#define OS_EVENT_RDB_ACK_PROF 22 -#endif - -/* Flags for debugging purpose */ - -#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ -#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ - -/* Interrupt masks */ - -#define OS_IM_NONE 0x00000001 -#define OS_IM_SW1 0x00000501 -#define OS_IM_SW2 0x00000601 -#define OS_IM_CART 0x00000c01 -#define OS_IM_PRENMI 0x00001401 -#define OS_IM_RDBWRITE 0x00002401 -#define OS_IM_RDBREAD 0x00004401 -#define OS_IM_COUNTER 0x00008401 -#define OS_IM_CPU 0x0000ff01 -#define OS_IM_SP 0x00010401 -#define OS_IM_SI 0x00020401 -#define OS_IM_AI 0x00040401 -#define OS_IM_VI 0x00080401 -#define OS_IM_PI 0x00100401 -#define OS_IM_DP 0x00200401 -#define OS_IM_ALL 0x003fff01 -#define RCP_IMASK 0x003f0000 -#define RCP_IMASKSHIFT 16 - -/* Recommended thread priorities for the system threads */ - -#define OS_PRIORITY_MAX 255 -#define OS_PRIORITY_VIMGR 254 -#define OS_PRIORITY_RMON 250 -#define OS_PRIORITY_RMONSPIN 200 -#define OS_PRIORITY_PIMGR 150 -#define OS_PRIORITY_SIMGR 140 -#define OS_PRIORITY_APPMAX 127 -#define OS_PRIORITY_IDLE 0 /* Must be 0 */ - - -/* Flags to turn blocking on/off when sending/receiving message */ - -#define OS_MESG_NOBLOCK 0 -#define OS_MESG_BLOCK 1 - -/* Flags to indicate direction of data transfer */ - -#define OS_READ 0 /* device -> RDRAM */ -#define OS_WRITE 1 /* device <- RDRAM */ -#define OS_OTHERS 2 /* for Leo disk only */ - -/* - * I/O message types - */ -#define OS_MESG_TYPE_BASE (10) -#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0) -#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1) -#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2) -#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3) -#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4) -#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5) -#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6) - -/* - * I/O message priority - */ -#define OS_MESG_PRI_NORMAL 0 -#define OS_MESG_PRI_HIGH 1 - -/* - * Page size argument for TLB routines - */ -#define OS_PM_4K 0x0000000 -#define OS_PM_16K 0x0006000 -#define OS_PM_64K 0x001e000 -#define OS_PM_256K 0x007e000 -#define OS_PM_1M 0x01fe000 -#define OS_PM_4M 0x07fe000 -#define OS_PM_16M 0x1ffe000 - /* * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), * SIM (SI Manager) @@ -439,90 +83,7 @@ typedef struct { #define OS_MIN_STACKSIZE 72 /* - * Values for osTvType - */ -#define OS_TV_PAL 0 -#define OS_TV_NTSC 1 -#define OS_TV_MPAL 2 - -/* - * Video Interface (VI) mode type - */ -#define OS_VI_NTSC_LPN1 0 /* NTSC */ -#define OS_VI_NTSC_LPF1 1 -#define OS_VI_NTSC_LAN1 2 -#define OS_VI_NTSC_LAF1 3 -#define OS_VI_NTSC_LPN2 4 -#define OS_VI_NTSC_LPF2 5 -#define OS_VI_NTSC_LAN2 6 -#define OS_VI_NTSC_LAF2 7 -#define OS_VI_NTSC_HPN1 8 -#define OS_VI_NTSC_HPF1 9 -#define OS_VI_NTSC_HAN1 10 -#define OS_VI_NTSC_HAF1 11 -#define OS_VI_NTSC_HPN2 12 -#define OS_VI_NTSC_HPF2 13 - -#define OS_VI_PAL_LPN1 14 /* PAL */ -#define OS_VI_PAL_LPF1 15 -#define OS_VI_PAL_LAN1 16 -#define OS_VI_PAL_LAF1 17 -#define OS_VI_PAL_LPN2 18 -#define OS_VI_PAL_LPF2 19 -#define OS_VI_PAL_LAN2 20 -#define OS_VI_PAL_LAF2 21 -#define OS_VI_PAL_HPN1 22 -#define OS_VI_PAL_HPF1 23 -#define OS_VI_PAL_HAN1 24 -#define OS_VI_PAL_HAF1 25 -#define OS_VI_PAL_HPN2 26 -#define OS_VI_PAL_HPF2 27 - -#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ -#define OS_VI_MPAL_LPF1 29 -#define OS_VI_MPAL_LAN1 30 -#define OS_VI_MPAL_LAF1 31 -#define OS_VI_MPAL_LPN2 32 -#define OS_VI_MPAL_LPF2 33 -#define OS_VI_MPAL_LAN2 34 -#define OS_VI_MPAL_LAF2 35 -#define OS_VI_MPAL_HPN1 36 -#define OS_VI_MPAL_HPF1 37 -#define OS_VI_MPAL_HAN1 38 -#define OS_VI_MPAL_HAF1 39 -#define OS_VI_MPAL_HPN2 40 -#define OS_VI_MPAL_HPF2 41 - -/* - * Video Interface (VI) special features - */ -#define OS_VI_GAMMA_ON 0x0001 -#define OS_VI_GAMMA_OFF 0x0002 -#define OS_VI_GAMMA_DITHER_ON 0x0004 -#define OS_VI_GAMMA_DITHER_OFF 0x0008 -#define OS_VI_DIVOT_ON 0x0010 -#define OS_VI_DIVOT_OFF 0x0020 -#define OS_VI_DITHER_FILTER_ON 0x0040 -#define OS_VI_DITHER_FILTER_OFF 0x0080 - -/* - * Video Interface (VI) mode attribute bit - */ -#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ -#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ -#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ -#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ -#define OS_VI_BIT_ANTIALIAS 0x0010 -#define OS_VI_BIT_POINTSAMPLE 0x0020 -#define OS_VI_BIT_16PIXEL 0x0040 -#define OS_VI_BIT_32PIXEL 0x0080 -#define OS_VI_BIT_LORES 0x0100 -#define OS_VI_BIT_HIRES 0x0200 -#define OS_VI_BIT_NTSC 0x0400 -#define OS_VI_BIT_PAL 0x0800 - -/* - * Leo Disk + * Leo Disk */ /* transfer mode */ @@ -531,156 +92,6 @@ typedef struct { #define LEO_TRACK_MODE 2 #define LEO_SECTOR_MODE 3 -/* - * Controllers number - */ - -#ifndef _HW_VERSION_1 -#define MAXCONTROLLERS 4 -#else -#define MAXCONTROLLERS 6 -#endif - -/* controller errors */ -#define CONT_NO_RESPONSE_ERROR 0x8 -#define CONT_OVERRUN_ERROR 0x4 -#ifdef _HW_VERSION_1 -#define CONT_FRAME_ERROR 0x2 -#define CONT_COLLISION_ERROR 0x1 -#endif - -/* Controller type */ - -#define CONT_ABSOLUTE 0x0001 -#define CONT_RELATIVE 0x0002 -#define CONT_JOYPORT 0x0004 -#define CONT_EEPROM 0x8000 -#define CONT_EEP16K 0x4000 -#define CONT_TYPE_MASK 0x1f07 -#define CONT_TYPE_NORMAL 0x0005 -#define CONT_TYPE_MOUSE 0x0002 - -/* Controller status */ - -#define CONT_CARD_ON 0x01 -#define CONT_CARD_PULL 0x02 -#define CONT_ADDR_CRC_ER 0x04 -#define CONT_EEPROM_BUSY 0x80 - -/* EEPROM TYPE */ - -#define EEPROM_TYPE_4K 0x01 -#define EEPROM_TYPE_16K 0x02 - -/* Buttons */ - -#define CONT_A 0x8000 -#define CONT_B 0x4000 -#define CONT_G 0x2000 -#define CONT_START 0x1000 -#define CONT_UP 0x0800 -#define CONT_DOWN 0x0400 -#define CONT_LEFT 0x0200 -#define CONT_RIGHT 0x0100 -#define CONT_L 0x0020 -#define CONT_R 0x0010 -#define CONT_E 0x0008 -#define CONT_D 0x0004 -#define CONT_C 0x0002 -#define CONT_F 0x0001 - -/* Nintendo's official button names */ - -#define A_BUTTON CONT_A -#define B_BUTTON CONT_B -#define L_TRIG CONT_L -#define R_TRIG CONT_R -#define Z_TRIG CONT_G -#define START_BUTTON CONT_START -#define U_JPAD CONT_UP -#define L_JPAD CONT_LEFT -#define R_JPAD CONT_RIGHT -#define D_JPAD CONT_DOWN -#define U_CBUTTONS CONT_E -#define L_CBUTTONS CONT_C -#define R_CBUTTONS CONT_F -#define D_CBUTTONS CONT_D - -/* File System size */ -#define OS_PFS_VERSION 0x0200 -#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) -#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) - -#define PFS_FILE_NAME_LEN 16 -#define PFS_FILE_EXT_LEN 4 -#define BLOCKSIZE 32 /* bytes */ -#define PFS_ONE_PAGE 8 /* blocks */ -#define PFS_MAX_BANKS 62 - -/* File System flag */ - -#define PFS_READ 0 -#define PFS_WRITE 1 -#define PFS_CREATE 2 - -/* File System status */ -#define PFS_INITIALIZED 0x1 -#define PFS_CORRUPTED 0x2 /* File system was corrupted */ - -/* File System error number */ - -#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ -#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a */ - /* different one */ -#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker */ -#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR -#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ -#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ -#define PFS_DATA_FULL 7 /* no free pages on ram pack */ -#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ -#define PFS_ERR_EXIST 9 /* file exists */ -#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ -#define PFS_ERR_DEVICE 11 /* wrong device type*/ -#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ -#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ - -/* Definition for bank */ -#define PFS_ID_BANK_256K 0 -#define PFS_ID_BANK_1M 4 -#define PFS_BANKS_256K 1 - -#define PFS_WRITTEN 2 -#define DEF_DIR_PAGES 2 - -#define PFS_ID_0AREA 1 -#define PFS_ID_1AREA 3 -#define PFS_ID_2AREA 4 -#define PFS_ID_3AREA 6 -#define PFS_LABEL_AREA 7 -#define PFS_ID_PAGE PFS_ONE_PAGE * 0 - -#define PFS_BANK_LAPPED_BY 8 /* => u8 */ -#define PFS_SECTOR_PER_BANK 32 -#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) -#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) - -/* definition for EEPROM */ - -#define EEPROM_MAXBLOCKS 64 -#define EEP16K_MAXBLOCKS 256 -#define EEPROM_BLOCK_SIZE 8 - -/* - * PI/EPI - */ -#define PI_DOMAIN1 0 -#define PI_DOMAIN2 1 - -/* - * Profiler constants - */ -#define PROF_MIN_INTERVAL 50 /* microseconds */ - /* * Boot addresses */ @@ -689,331 +100,6 @@ typedef struct { #define BOOT_ADDRESS_EMU 0x20010000 #define BOOT_ADDRESS_INDY 0x88100000 -/* - * Size of buffer the retains contents after NMI - */ -#define OS_APP_NMI_BUFSIZE 64 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/* PARTNER-N64 */ -#ifdef PTN64 -#define osReadHost osReadHost_pt -#define osWriteHost osWriteHost_pt -#endif - -/* Get count of valid messages in queue */ -#define MQ_GET_COUNT(mq) ((mq)->validCount) - -/* Figure out if message queue is empty or full */ -#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) -#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) - -/* - * CPU counter increments at 3/4 of bus clock rate: - * - * Bus Clock Proc Clock Counter (1/2 Proc Clock) - * --------- ---------- ------------------------ - * 62.5 Mhz 93.75 Mhz 46.875 Mhz - */ -extern u64 osClockRate; - -#define OS_CLOCK_RATE 62500000LL -#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) -#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) -#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) -#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) -#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) - -/************************************************************************** - * - * Extern variables - * - */ -extern OSViMode osViModeTable[]; /* Global VI mode table */ - -extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ -extern OSViMode osViModeNtscLpf1; -extern OSViMode osViModeNtscLan1; -extern OSViMode osViModeNtscLaf1; -extern OSViMode osViModeNtscLpn2; -extern OSViMode osViModeNtscLpf2; -extern OSViMode osViModeNtscLan2; -extern OSViMode osViModeNtscLaf2; -extern OSViMode osViModeNtscHpn1; -extern OSViMode osViModeNtscHpf1; -extern OSViMode osViModeNtscHan1; -extern OSViMode osViModeNtscHaf1; -extern OSViMode osViModeNtscHpn2; -extern OSViMode osViModeNtscHpf2; - -extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ -extern OSViMode osViModePalLpf1; -extern OSViMode osViModePalLan1; -extern OSViMode osViModePalLaf1; -extern OSViMode osViModePalLpn2; -extern OSViMode osViModePalLpf2; -extern OSViMode osViModePalLan2; -extern OSViMode osViModePalLaf2; -extern OSViMode osViModePalHpn1; -extern OSViMode osViModePalHpf1; -extern OSViMode osViModePalHan1; -extern OSViMode osViModePalHaf1; -extern OSViMode osViModePalHpn2; -extern OSViMode osViModePalHpf2; - -extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ -extern OSViMode osViModeMpalLpf1; -extern OSViMode osViModeMpalLan1; -extern OSViMode osViModeMpalLaf1; -extern OSViMode osViModeMpalLpn2; -extern OSViMode osViModeMpalLpf2; -extern OSViMode osViModeMpalLan2; -extern OSViMode osViModeMpalLaf2; -extern OSViMode osViModeMpalHpn1; -extern OSViMode osViModeMpalHpf1; -extern OSViMode osViModeMpalHan1; -extern OSViMode osViModeMpalHaf1; -extern OSViMode osViModeMpalHpn2; -extern OSViMode osViModeMpalHpf2; - -extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ -extern void *osRomBase; /* Rom base address of the game image */ -extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ -extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ -extern s32 osCicId; -extern s32 osVersion; -extern u32 osMemSize; /* Memory Size */ -extern s32 osAppNMIBuffer[]; - -extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ -extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ -extern OSPiHandle *__osDiskHandle; /* For exceptasm to get disk info*/ - - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Thread operations */ - -extern void osCreateThread(OSThread *, OSId, void (*)(void *), - void *, void *, OSPri); -extern void osDestroyThread(OSThread *); -extern void osYieldThread(void); -extern void osStartThread(OSThread *); -extern void osStopThread(OSThread *); -extern OSId osGetThreadId(OSThread *); -extern void osSetThreadPri(OSThread *, OSPri); -extern OSPri osGetThreadPri(OSThread *); - -/* Message operations */ - -extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); -extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); - -/* Event operations */ - -extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); - -/* Interrupt operations */ - -extern OSIntMask osGetIntMask(void); -extern OSIntMask osSetIntMask(OSIntMask); - -/* RDB port operations */ - -extern void osInitRdb(u8 *sendBuf, u32 sendSize); - -/* Cache operations and macros */ - -extern void osInvalDCache(void *, s32); -extern void osInvalICache(void *, s32); -extern void osWritebackDCache(void *, s32); -extern void osWritebackDCacheAll(void); - -#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) -#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) - -/* TLB management routines */ - -extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); -extern void osMapTLBRdb(void); -extern void osUnmapTLB(s32); -extern void osUnmapTLBAll(void); -extern void osSetTLBASID(s32); - -/* Address translation routines and macros */ - -extern u32 osVirtualToPhysical(void *); -extern void * osPhysicalToVirtual(u32); - -#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) -#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) - -#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) -#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) - -/* I/O operations */ - -/* Audio interface (Ai) */ -extern u32 osAiGetStatus(void); -extern u32 osAiGetLength(void); -extern s32 osAiSetFrequency(u32); -extern s32 osAiSetNextBuffer(void *, u32); - -/* Display processor interface (Dp) */ -extern u32 osDpGetStatus(void); -extern void osDpSetStatus(u32); -extern void osDpGetCounters(u32 *); -extern s32 osDpSetNextBuffer(void *, u64); - -/* Peripheral interface (Pi) */ -extern u32 osPiGetStatus(void); -extern s32 osPiGetDeviceType(void); -extern s32 osPiRawWriteIo(u32, u32); -extern s32 osPiRawReadIo(u32, u32 *); -extern s32 osPiRawStartDma(s32, u32, void *, u32); -extern s32 osPiWriteIo(u32, u32); -extern s32 osPiReadIo(u32, u32 *); -extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, - OSMesgQueue *); -extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); - -/* Video interface (Vi) */ -extern u32 osViGetStatus(void); -extern u32 osViGetCurrentMode(void); -extern u32 osViGetCurrentLine(void); -extern u32 osViGetCurrentField(void); -extern void *osViGetCurrentFramebuffer(void); -extern void *osViGetNextFramebuffer(void); -extern void osViSetXScale(f32); -extern void osViSetYScale(f32); -extern void osViSetSpecialFeatures(u32); -extern void osViSetMode(OSViMode *); -extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); -extern void osViSwapBuffer(void *); -extern void osViBlack(u8); -extern void osViFade(u8, u16); -extern void osViRepeatLine(u8); -extern void osCreateViManager(OSPri); - -/* Timer interface */ - -extern OSTime osGetTime(void); -extern void osSetTime(OSTime); -extern int osSetTimer(OSTimer *, OSTime, OSTime, - OSMesgQueue *, OSMesg); -extern int osStopTimer(OSTimer *); - -/* Controller interface */ - -extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); -extern s32 osContReset(OSMesgQueue *, OSContStatus *); -extern s32 osContStartQuery(OSMesgQueue *); -extern s32 osContStartReadData(OSMesgQueue *); -#ifndef _HW_VERSION_1 -extern s32 osContSetCh(u8); -#endif -extern void osContGetQuery(OSContStatus *); -extern void osContGetReadData(OSContPad *); - -/* file system interface */ - -extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsRepairId(OSPfs *); -extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); -extern s32 osPfsChecker(OSPfs *); -extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); -extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); -extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); -extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); -extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); -extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); -extern s32 osPfsSetLabel(OSPfs *, u8 *); -extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); -extern s32 osPfsFreeBlocks(OSPfs *, s32 *); -extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); - -/* EEPROM interface */ - -extern s32 osEepromProbe(OSMesgQueue *); -extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); -extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); -extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); -extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); - -/* MOTOR interface */ - -extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); -extern s32 osMotorStop(OSPfs *); -extern s32 osMotorStart(OSPfs *); - -/* Enhanced PI interface */ - -extern OSPiHandle *osCartRomInit(void); -extern OSPiHandle *osLeoDiskInit(void); -extern OSPiHandle *osDriveRomInit(void); - -extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); -extern s32 osEPiRawWriteIo(OSPiHandle *, u32 , u32); -extern s32 osEPiRawReadIo(OSPiHandle *, u32 , u32 *); -extern s32 osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 ); -extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); -extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); -extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); -extern s32 osEPiLinkHandle(OSPiHandle *); - -/* Profiler Interface */ - -extern void osProfileInit(OSProf *, u32 profcnt); -extern void osProfileStart(u32); -extern void osProfileFlush(void); -extern void osProfileStop(void); - -/* Game <> Host data transfer functions */ - -extern s32 osTestHost(void); -extern void osReadHost(void *, u32); -extern void osWriteHost(void *, u32); -extern void osAckRamromRead(void); -extern void osAckRamromWrite(void); - - -/* byte string operations */ - -extern void bcopy(const void *, void *, int); -extern int bcmp(const void *, const void *, int); -extern void bzero(void *, int); - -/* Miscellaneous operations */ - -extern void osInitialize(void); -extern u32 osGetCount(void); -extern void osExit(void); -extern u32 osGetMemSize(void); - -/* Printf */ - -extern int sprintf(char *s, const char *fmt, ...); -extern void osSyncPrintf(const char *fmt, ...); -extern void osAsyncPrintf(const char *fmt, ...); -extern int osSyncGetChars(char *buf); -extern int osAsyncGetChars(char *buf); - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ #ifdef _LANGUAGE_C_PLUS_PLUS } diff --git a/include/PR/os_ai.h b/include/PR/os_ai.h new file mode 100644 index 000000000..93160921f --- /dev/null +++ b/include/PR/os_ai.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_ai.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_ai.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_AI_H_ +#define _OS_AI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Audio interface (Ai) */ +extern u32 osAiGetStatus(void); +extern u32 osAiGetLength(void); +extern s32 osAiSetFrequency(u32); +extern s32 osAiSetNextBuffer(void *, u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_AI_H_ */ diff --git a/include/PR/os_cache.h b/include/PR/os_cache.h new file mode 100644 index 000000000..7b8a24bff --- /dev/null +++ b/include/PR/os_cache.h @@ -0,0 +1,96 @@ + +/*==================================================================== + * os_cache.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cache.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CACHE_H_ +#define _OS_CACHE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) +#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Cache operations and macros */ + +extern void osInvalDCache(void *, s32); +extern void osInvalICache(void *, s32); +extern void osWritebackDCache(void *, s32); +extern void osWritebackDCacheAll(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CACHE_H_ */ diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h new file mode 100644 index 000000000..7d1aeec3e --- /dev/null +++ b/include/PR/os_cont.h @@ -0,0 +1,208 @@ + +/*==================================================================== + * os_cont.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cont.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:05 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONT_H_ +#define _OS_CONT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for controllers + */ + +typedef struct { + u16 type; /* Controller Type */ + u8 status; /* Controller status */ + u8 errno; +}OSContStatus; + +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; + +typedef struct { + void *address; /* Ram pad Address: 11 bits */ + u8 databuffer[32]; /* address of the data buffer */ + u8 addressCrc; /* CRC code for address */ + u8 dataCrc; /* CRC code for data */ + u8 errno; +} OSContRamIo; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Controllers number + */ + +#ifndef _HW_VERSION_1 +#define MAXCONTROLLERS 4 +#else +#define MAXCONTROLLERS 6 +#endif + +/* controller errors */ +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 +#define CONT_RANGE_ERROR -1 +#ifdef _HW_VERSION_1 +#define CONT_FRAME_ERROR 0x2 +#define CONT_COLLISION_ERROR 0x1 +#endif + +/* Controller type */ + +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1f07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 + +/* Controller status */ + +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 + +/* Buttons */ + +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ + +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + +/* Controller error number */ + +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Controller interface */ + +extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); +extern s32 osContReset(OSMesgQueue *, OSContStatus *); +extern s32 osContStartQuery(OSMesgQueue *); +extern s32 osContStartReadData(OSMesgQueue *); +#ifndef _HW_VERSION_1 +extern s32 osContSetCh(u8); +#endif +extern void osContGetQuery(OSContStatus *); +extern void osContGetReadData(OSContPad *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONT_H_ */ diff --git a/include/PR/os_convert.h b/include/PR/os_convert.h new file mode 100644 index 000000000..3797d1b53 --- /dev/null +++ b/include/PR/os_convert.h @@ -0,0 +1,111 @@ + +/*==================================================================== + * os_convert.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_convert.h,v $ + $Revision: 1.2 $ + $Date: 1999/04/21 02:53:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONVERT_H_ +#define _OS_CONVERT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +#define OS_CLOCK_RATE 62500000LL +#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) +#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) +#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) +#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) + +/* OS_K?_TO_PHYSICAL macro bug fix for CodeWarrior */ +#ifndef __MWERKS__ +#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) +#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) +#else +#define OS_K0_TO_PHYSICAL(x) ((char *)(x)-0x80000000) +#define OS_K1_TO_PHYSICAL(x) ((char *)(x)-0xa0000000) +#endif + +#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) +#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Address translation routines and macros */ + +extern u32 osVirtualToPhysical(void *); +extern void * osPhysicalToVirtual(u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONVERT_H_ */ diff --git a/include/PR/os_debug.h b/include/PR/os_debug.h new file mode 100644 index 000000000..e8bc8b660 --- /dev/null +++ b/include/PR/os_debug.h @@ -0,0 +1,117 @@ + +/*==================================================================== + * os_debug.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_debug.h,v $ + $Revision: 1.4 $ + $Date: 1999/06/30 03:04:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_DEBUG_H_ +#define _OS_DEBUG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Profiler + */ +typedef struct { + u16 *histo_base; /* histogram base */ + u32 histo_size; /* histogram size */ + u32 *text_start; /* start of text segment */ + u32 *text_end; /* end of text segment */ +} OSProf; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Profiler constants + */ +#define PROF_MIN_INTERVAL 50 /* microseconds */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Profiler Interface */ + +extern void osProfileInit(OSProf *, u32 profcnt); +extern void osProfileStart(u32); +extern void osProfileFlush(void); +extern void osProfileStop(void); + +/* Thread Profiler Interface */ +extern void osThreadProfileClear(OSId); +extern void osThreadProfileInit(void); +extern void osThreadProfileStart(void); +extern void osThreadProfileStop(void); +extern u32 osThreadProfileReadCount(OSId); +extern u32 osThreadProfileReadCountTh(OSThread*); +extern OSTime osThreadProfileReadTime(OSId); +extern OSTime osThreadProfileReadTimeTh(OSThread*); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_DEBUG_H_ */ diff --git a/include/PR/os_eeprom.h b/include/PR/os_eeprom.h new file mode 100644 index 000000000..361803af1 --- /dev/null +++ b/include/PR/os_eeprom.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_eeprom.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_eeprom.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EEPROM_H_ +#define _OS_EEPROM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "PR/os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* EEPROM TYPE */ + +#define EEPROM_TYPE_4K 0x01 +#define EEPROM_TYPE_16K 0x02 + +/* definition for EEPROM */ + +#define EEPROM_MAXBLOCKS 64 +#define EEP16K_MAXBLOCKS 256 +#define EEPROM_BLOCK_SIZE 8 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* EEPROM interface */ + +extern s32 osEepromProbe(OSMesgQueue *); +extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); +extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); +extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); +extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EEPROM_H_ */ diff --git a/include/PR/os_error.h b/include/PR/os_error.h new file mode 100644 index 000000000..31203e0fc --- /dev/null +++ b/include/PR/os_error.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_error.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_error.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_ERROR_H_ +#define _OS_ERROR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_ERROR_H_ */ diff --git a/include/PR/os_exception.h b/include/PR/os_exception.h new file mode 100644 index 000000000..70c994338 --- /dev/null +++ b/include/PR/os_exception.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_exception.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EXCEPTION_H_ +#define _OS_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "PR/ultratypes.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +typedef u32 OSIntMask; +typedef u32 OSHWIntr; + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/* Flags for debugging purpose */ + +#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ +#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ + +/* Interrupt masks */ + +#define OS_IM_NONE 0x00000001 +#define OS_IM_RCP 0x00000401 +#define OS_IM_SW1 0x00000501 +#define OS_IM_SW2 0x00000601 +#define OS_IM_CART 0x00000c01 +#define OS_IM_PRENMI 0x00001401 +#define OS_IM_RDBWRITE 0x00002401 +#define OS_IM_RDBREAD 0x00004401 +#define OS_IM_COUNTER 0x00008401 +#define OS_IM_CPU 0x0000ff01 +#define OS_IM_SP 0x00010401 +#define OS_IM_SI 0x00020401 +#define OS_IM_AI 0x00040401 +#define OS_IM_VI 0x00080401 +#define OS_IM_PI 0x00100401 +#define OS_IM_DP 0x00200401 +#define OS_IM_ALL 0x003fff01 +#define RCP_IMASK 0x003f0000 +#define RCP_IMASKSHIFT 16 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Interrupt operations */ + +extern OSIntMask osGetIntMask(void); +extern OSIntMask osSetIntMask(OSIntMask); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EXCEPTION_H_ */ diff --git a/include/PR/os_flash.h b/include/PR/os_flash.h new file mode 100644 index 000000000..734f92164 --- /dev/null +++ b/include/PR/os_flash.h @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_flash.h,v $ + $Revision: 1.1 $ + $Date: 2000/06/15 06:24:55 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_FLASH_H_ +#define _OS_FLASH_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "PR/ultratypes.h" +#include "PR/os_pi.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * defines for FLASH + */ +#define FLASH_START_ADDR 0x08000000 + +#define FLASH_SIZE 0x20000 + +#define FLASH_LATENCY 0x5 +#define FLASH_PULSE 0x0c +#define FLASH_PAGE_SIZE 0xf +#define FLASH_REL_DURATION 0x2 +#define DEVICE_TYPE_FLASH 8 + +#define FLASH_VERSION_MX_PROTO_A 0x00c20000 +#define FLASH_VERSION_MX_A 0x00c20001 +#define FLASH_VERSION_MX_C 0x00c2001e +#define FLASH_VERSION_MX_B_AND_D 0x00c2001d +#define FLASH_VERSION_MEI 0x003200f1 + +/* OLD_FLASH is MX_PROTO_A, MX_A and MX_C */ +#define OLD_FLASH 0 +/* NEW_FLASH is MX_B_AND_D and MATSUSHITA flash */ +#define NEW_FLASH 1 + +#define FLASH_STATUS_ERASE_BUSY 2 +#define FLASH_STATUS_ERASE_OK 0 +#define FLASH_STATUS_ERASE_ERROR -1 + +#define FLASH_STATUS_WRITE_BUSY 1 +#define FLASH_STATUS_WRITE_OK 0 +#define FLASH_STATUS_WRITE_ERROR -1 + +extern OSPiHandle *osFlashReInit(u8 latency, u8 pulse, + u8 page_size, u8 rel_duration, u32 start); +extern OSPiHandle *osFlashInit(void); +extern void osFlashReadStatus(u8 *flash_status); +extern void osFlashReadId(u32 *flash_type, u32 *flash_maker); +extern void osFlashClearStatus(void); +extern s32 osFlashAllErase(void); +extern s32 osFlashSectorErase(u32 page_num); +extern s32 osFlashWriteBuffer(OSIoMesg *mb, s32 priority, + void *dramAddr, OSMesgQueue *mq); +extern s32 osFlashWriteArray(u32 page_num); +extern s32 osFlashReadArray(OSIoMesg *mb, s32 priority, u32 page_num, + void *dramAddr, u32 n_pages, OSMesgQueue *mq); +extern void osFlashChange(u32 flash_num); +extern void osFlashAllEraseThrough(void); +extern void osFlashSectorEraseThrough(u32 page_num); +extern s32 osFlashCheckEraseEnd(void); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_FLASH_H_ */ diff --git a/include/PR/os_gbpak.h b/include/PR/os_gbpak.h new file mode 100644 index 000000000..e2a696aac --- /dev/null +++ b/include/PR/os_gbpak.h @@ -0,0 +1,107 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_gbpak.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GBPAK_H_ +#define _OS_GBPAK_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" +#include "os_pfs.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { + u16 fixed1; + u16 start_address; + u8 nintendo_chr[0x30]; + u8 game_title[16]; + u16 company_code; + u8 body_code; + u8 cart_type; + u8 rom_size; + u8 ram_size; + u8 country_code; + u8 fixed2; + u8 version; + u8 isum; + u16 sum; +} OSGbpakId; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for 64GB-PAK */ + +#define OS_GBPAK_POWER 0x01 +#define OS_GBPAK_RSTB_DETECTION 0x04 +#define OS_GBPAK_RSTB_STATUS 0x08 +#define OS_GBPAK_GBCART_PULL 0x40 +#define OS_GBPAK_GBCART_ON 0x80 + +#define OS_GBPAK_POWER_OFF 0x00 /* power of 64GB-PAK */ +#define OS_GBPAK_POWER_ON 0x01 + +#define OS_GBPAK_ROM_ID_SIZE 0x50 /* ID size of GB cartridge */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* 64GB-PAK */ +extern s32 osGbpakInit(OSMesgQueue *, OSPfs *, int); +extern s32 osGbpakPower(OSPfs *, s32); +extern s32 osGbpakGetStatus(OSPfs *, u8 *); +extern s32 osGbpakReadWrite(OSPfs *, u16, u16, u8 *, u16); +extern s32 osGbpakReadId(OSPfs *, OSGbpakId *, u8 *); +extern s32 osGbpakCheckConnector(OSPfs *, u8 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GBPAK_H_ */ diff --git a/include/PR/os_gio.h b/include/PR/os_gio.h new file mode 100644 index 000000000..093b7cb95 --- /dev/null +++ b/include/PR/os_gio.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_gio.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_gio.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GIO_H_ +#define _OS_GIO_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GIO_H_ */ diff --git a/include/PR/os_host.h b/include/PR/os_host.h new file mode 100644 index 000000000..1e5c29d01 --- /dev/null +++ b/include/PR/os_host.h @@ -0,0 +1,166 @@ + +/*==================================================================== + * os_host.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_host.h,v $ + $Revision: 1.3 $ + $Date: 1999/06/24 09:23:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_HOST_H_ +#define _OS_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +extern void __osInitialize_common(void); + +#if defined(_FINALROM) + +#define osInitialize() __osInitialize_common() + +#else + +/* PARTNER-N64 */ +#if defined(PTN64) +extern void __osInitialize_kmc(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_kmc(); \ +} + +/* MONEGI SMART PACK A */ +#elif defined(MWN64) +extern void __osInitialize_msp(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_msp(); \ +} + +/* IS-Viewer(for Debugger) */ +#elif defined(ISV64) +extern void __osInitialize_isv(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_isv(); \ +} + +/* Emulation board for INDY */ +#elif defined(EMU64) +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_emu(); \ +} + +#else +/* Default (auto detect) */ +extern void __osInitialize_autodetect(void); +extern void __osInitialize_msp(void); +extern void __osInitialize_kmc(void); +extern void __osInitialize_isv(void); +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_autodetect(); \ +} +#endif + +#endif /* _FINAL_ROM */ + +#if BUILD_VERSION < VERSION_K +#undef osInitialize +#endif + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Game <> Host data transfer functions */ + +extern s32 osTestHost(void); +extern void osReadHost(void *, u32); +extern void osWriteHost(void *, u32); +extern void osAckRamromRead(void); +extern void osAckRamromWrite(void); + +/* RDB port operations */ + +extern void osInitRdb(u8 *sendBuf, u32 sendSize); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_HOST_H_ */ diff --git a/include/PR/os_internal.h b/include/PR/os_internal.h index 544eb32fa..c8cbf43b8 100644 --- a/include/PR/os_internal.h +++ b/include/PR/os_internal.h @@ -26,6 +26,7 @@ extern "C" { #endif #include +#include "PR/os_version.h" #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h new file mode 100644 index 000000000..0a84badda --- /dev/null +++ b/include/PR/os_libc.h @@ -0,0 +1,100 @@ + +/*==================================================================== + * os_libc.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_libc.h,v $ + $Revision: 1.3 $ + $Date: 1999/07/13 01:43:47 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_LIBC_H_ +#define _OS_LIBC_H_ + +#include "os_pfs.h" + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* byte string operations */ + + +extern void bcopy(const void *, void *, int); +extern int bcmp(const void *, const void *, int); +extern void bzero(void *, int); + +/* Printf */ + +extern int sprintf(char *s, const char *fmt, ...); +extern void osSyncPrintf(const char *fmt, ...); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_LIBC_H_ */ diff --git a/include/PR/os_message.h b/include/PR/os_message.h new file mode 100644 index 000000000..3efbafadb --- /dev/null +++ b/include/PR/os_message.h @@ -0,0 +1,162 @@ + +/*==================================================================== + * os_message.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_message.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MESSAGE_H_ +#define _OS_MESSAGE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "PR/ultratypes.h" +#include "PR/os_thread.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSEvent; + +/* + * Structure for message + */ +typedef void *OSMesg; + +/* + * Structure for message queue + */ +typedef struct OSMesgQueue_s { + OSThread *mtqueue; /* Queue to store threads blocked on empty mailboxes (receive) */ + OSThread *fullqueue; /* Queue to store threads blocked on full mailboxes (send) */ + s32 validCount; /* Contains number of valid message */ + s32 first; /* Points to first valid message */ + s32 msgCount; /* Contains total # of messages */ + OSMesg *msg; /* Points to message buffer array */ +} OSMesgQueue; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Events */ +#ifdef _FINALROM +#define OS_NUM_EVENTS 15 +#else +#define OS_NUM_EVENTS 23 +#endif + +#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ +#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ +#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ +#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ +#define OS_EVENT_SP 4 /* SP task done interrupt */ +#define OS_EVENT_SI 5 /* SI (controller) interrupt */ +#define OS_EVENT_AI 6 /* AI interrupt */ +#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ +#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ +#define OS_EVENT_DP 9 /* DP full sync interrupt */ +#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ +#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ +#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ +#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ +#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ +#ifndef _FINALROM +#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ +#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ +#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ +#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ +#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ +#define OS_EVENT_RDB_DBG_DONE 20 +#define OS_EVENT_RDB_FLUSH_PROF 21 +#define OS_EVENT_RDB_ACK_PROF 22 +#endif + +/* Flags to turn blocking on/off when sending/receiving message */ + +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* Get count of valid messages in queue */ +#define MQ_GET_COUNT(mq) ((mq)->validCount) + +/* Figure out if message queue is empty or full */ +#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Message operations */ + +extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); +extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); + +/* Event operations */ + +extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MESSAGE_H_ */ diff --git a/include/PR/os_motor.h b/include/PR/os_motor.h new file mode 100644 index 000000000..d2723e0c9 --- /dev/null +++ b/include/PR/os_motor.h @@ -0,0 +1,84 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_motor.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MOTOR_H_ +#define _OS_MOTOR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "PR/os_message.h" +#include "PR/os_pfs.h" +#include "PR/os_version.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Rumble PAK interface */ + +extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); +#if BUILD_VERSION >= VERSION_J +#define MOTOR_START 1 +#define MOTOR_STOP 0 +#define osMotorStart(x) __osMotorAccess((x), MOTOR_START) +#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP) +extern s32 __osMotorAccess(OSPfs *, s32); +#else +extern s32 osMotorStop(OSPfs *); +extern s32 osMotorStart(OSPfs *); +#endif + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MOTOR_H_ */ diff --git a/include/PR/os_pfs.h b/include/PR/os_pfs.h new file mode 100644 index 000000000..bb4403d49 --- /dev/null +++ b/include/PR/os_pfs.h @@ -0,0 +1,200 @@ + +/*==================================================================== + * os_pfs.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pfs.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PFS_H_ +#define _OS_PFS_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "PR/os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for file system + */ +typedef struct { + int status; + OSMesgQueue *queue; + int channel; + u8 id[32]; + u8 label[32]; + int version; + int dir_size; + int inode_table; /* block location */ + int minode_table; /* mirrioring inode_table */ + int dir_table; /* block location */ + int inode_start_page; /* page # */ + u8 banks; + u8 activebank; +} OSPfs; + +typedef struct { + u32 file_size; /* bytes */ + u32 game_code; + u16 company_code; + char ext_name[4]; + char game_name[16]; +} OSPfsState; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +/* File System size */ +#define OS_PFS_VERSION 0x0200 +#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) +#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) + +#define PFS_INODE_SIZE_PER_PAGE 128 +#define PFS_FILE_NAME_LEN 16 +#define PFS_FILE_EXT_LEN 4 +#define BLOCKSIZE 32 /* bytes */ +#define PFS_ONE_PAGE 8 /* blocks */ +#define PFS_MAX_BANKS 62 + +/* File System flag */ + +#define PFS_READ 0 +#define PFS_WRITE 1 +#define PFS_CREATE 2 + +/* File System status */ +#define PFS_INITIALIZED 0x1 +#define PFS_CORRUPTED 0x2 +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 + +/* Definition for page usage */ +#define PFS_EOF 1 +#define PFS_PAGE_NOT_EXIST 2 +#define PFS_PAGE_NOT_USED 3 + +/* File System error number */ + +#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ +#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ +#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ +#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR +#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ +#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ +#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ +#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ +#define PFS_ERR_EXIST 9 /* file exists*/ +#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ +#define PFS_ERR_DEVICE 11 /* wrong device type*/ +#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ +#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ + +/* Definition for bank */ +#define PFS_ID_BANK_256K 0 +#define PFS_ID_BANK_1M 4 +#define PFS_BANKS_256K 1 + +#define PFS_WRITTEN 2 +#define DEF_DIR_PAGES 2 + +#define PFS_ID_0AREA 1 +#define PFS_ID_1AREA 3 +#define PFS_ID_2AREA 4 +#define PFS_ID_3AREA 6 +#define PFS_LABEL_AREA 7 +#define PFS_ID_PAGE PFS_ONE_PAGE * 0 + +#define PFS_BANK_LAPPED_BY 8 /* => u8 */ +#define PFS_SECTOR_PER_BANK 32 +#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) +#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* file system interface */ + +extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsRepairId(OSPfs *); +extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); +extern s32 osPfsChecker(OSPfs *); +extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); +extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); +extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); +extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); +extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); +extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); +extern s32 osPfsSetLabel(OSPfs *, u8 *); +extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); +extern s32 osPfsFreeBlocks(OSPfs *, s32 *); +extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PFS_H_ */ diff --git a/include/PR/os_pi.h b/include/PR/os_pi.h new file mode 100644 index 000000000..8043169f5 --- /dev/null +++ b/include/PR/os_pi.h @@ -0,0 +1,221 @@ + +/*==================================================================== + * os_pi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PI_H_ +#define _OS_PI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "PR/ultratypes.h" +#include "PR/os_thread.h" +#include "PR/os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Enhanced PI interface + */ + +/* + * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained + * by exception handler. This is how the PIMGR and the ISR communicate. + */ + +typedef struct { + u32 errStatus; /* error status */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + void *C2Addr; /* C2 buffer address */ + u32 sectorSize; /* size of transfering sector */ + u32 C1ErrNum; /* total # of C1 errors */ + u32 C1ErrSector[4]; /* error sectors */ +} __OSBlockInfo; + +typedef struct { + u32 cmdType; /* for disk only */ + u16 transferMode; /* Block, Track, or sector? */ + u16 blockNum; /* which block is transfering */ + s32 sectorNum; /* which sector is transfering */ + u32 devAddr; /* Device buffer address */ + u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ + u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ + __OSBlockInfo block[2]; /* bolck transfer info */ +} __OSTranxInfo; + + +typedef struct OSPiHandle_s { + struct OSPiHandle_s *next; /* point to next handle on the table */ + u8 type; /* DEVICE_TYPE_BULK for disk */ + u8 latency; /* domain latency */ + u8 pageSize; /* domain page size */ + u8 relDuration; /* domain release duration */ + u8 pulse; /* domain pulse width */ + u8 domain; /* which domain */ + u32 baseAddress; /* Domain address */ + u32 speed; /* for roms only */ + /* The following are "private" elements" */ + __OSTranxInfo transferInfo; /* for disk only */ +} OSPiHandle; + +typedef struct { + u8 type; + u32 address; +} OSPiInfo; + +/* + * Structure for I/O message block + */ +typedef struct { + u16 type; /* Message type */ + u8 pri; /* Message priority (High or Normal) */ + u8 status; /* Return status */ + OSMesgQueue *retQueue; /* Return message queue to notify I/O completion */ +} OSIoMesgHdr; + +typedef struct { + OSIoMesgHdr hdr; /* Message header */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + u32 devAddr; /* Device buffer address (DMA) */ + u32 size; /* DMA transfer size in bytes */ + OSPiHandle *piHandle; /* PI device handle */ +} OSIoMesg; + +/* + * Structure for device manager block + */ +typedef struct { + s32 active; /* Status flag */ + OSThread *thread; /* Calling thread */ + OSMesgQueue *cmdQueue; /* Command queue */ + OSMesgQueue *evtQueue; /* Event queue */ + OSMesgQueue *acsQueue; /* Access queue */ + /* Raw DMA routine */ + s32 (*dma)(s32, u32, void *, u32); + s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); +} OSDevMgr; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Flags to indicate direction of data transfer */ + +#define OS_READ 0 /* device -> RDRAM */ +#define OS_WRITE 1 /* device <- RDRAM */ +#define OS_OTHERS 2 /* for Leo disk only */ + +/* + * I/O message types + */ +#define OS_MESG_TYPE_BASE (10) +#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE + 0) +#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE + 1) +#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE + 2) +#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE + 3) +#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE + 4) +#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE + 5) +#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE + 6) + +/* + * I/O message priority + */ +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 + +/* + * PI/EPI + */ +#define PI_DOMAIN1 0 +#define PI_DOMAIN2 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +extern u32 osPiGetStatus(void); +extern s32 osPiGetDeviceType(void); +extern s32 osPiWriteIo(u32, u32); +extern s32 osPiReadIo(u32, u32 *); +extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, OSMesgQueue *); +extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); + +/* Enhanced PI interface */ + +extern OSPiHandle *osCartRomInit(void); +extern OSPiHandle *osLeoDiskInit(void); +extern OSPiHandle *osDriveRomInit(void); + +extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); +extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); +extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); +extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); +extern s32 osEPiLinkHandle(OSPiHandle *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PI_H_ */ diff --git a/include/PR/os_rdp.h b/include/PR/os_rdp.h new file mode 100644 index 000000000..198c756a3 --- /dev/null +++ b/include/PR/os_rdp.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_rdp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rdp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RDP_H_ +#define _OS_RDP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Display processor interface (Dp) */ +extern u32 osDpGetStatus(void); +extern void osDpSetStatus(u32); +extern void osDpGetCounters(u32 *); +extern s32 osDpSetNextBuffer(void *, u64); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RDP_H_ */ diff --git a/include/PR/os_reg.h b/include/PR/os_reg.h new file mode 100644 index 000000000..2049a60a6 --- /dev/null +++ b/include/PR/os_reg.h @@ -0,0 +1,90 @@ + +/*==================================================================== + * os_reg.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_reg.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_REG_H_ +#define _OS_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Miscellaneous operations */ + +extern u32 osGetCount(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_REG_H_ */ diff --git a/include/PR/os_rsp.h b/include/PR/os_rsp.h new file mode 100644 index 000000000..5c983117c --- /dev/null +++ b/include/PR/os_rsp.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_rsp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rsp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RSP_H_ +#define _OS_RSP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RSP_H_ */ diff --git a/include/PR/os_si.h b/include/PR/os_si.h new file mode 100644 index 000000000..e1d1d09b6 --- /dev/null +++ b/include/PR/os_si.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_si.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_si.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SI_H_ +#define _OS_SI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SI_H_ */ diff --git a/include/PR/os_system.h b/include/PR/os_system.h new file mode 100644 index 000000000..96f4f7154 --- /dev/null +++ b/include/PR/os_system.h @@ -0,0 +1,118 @@ + +/*==================================================================== + * os_system.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_system.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SYSTEM_H_ +#define _OS_SYSTEM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Values for osTvType + */ +#define OS_TV_PAL 0 +#define OS_TV_NTSC 1 +#define OS_TV_MPAL 2 + +/* + * Size of buffer the retains contents after NMI + */ +#define OS_APP_NMI_BUFSIZE 64 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ +extern void *osRomBase; /* Rom base address of the game image */ +extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ +extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ +extern s32 osCicId; +extern s32 osVersion; +extern u32 osMemSize; /* Memory Size */ +extern s32 osAppNMIBuffer[]; + +extern u64 osClockRate; + +extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +extern void osInitialize(void); +extern void osExit(void); +extern u32 osGetMemSize(void); + +/* pre-NMI */ +extern s32 osAfterPreNMI(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SYSTEM_H_ */ diff --git a/include/PR/os_thread.h b/include/PR/os_thread.h new file mode 100644 index 000000000..2bfed68e9 --- /dev/null +++ b/include/PR/os_thread.h @@ -0,0 +1,161 @@ + +/*==================================================================== + * os_thread.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_thread.h,v $ + $Revision: 1.3 $ + $Date: 1999/06/15 12:39:40 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_THREAD_H_ +#define _OS_THREAD_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef s32 OSPri; +typedef s32 OSId; + +typedef union { + struct { + f32 f_odd; + f32 f_even; + } f; + f64 d; +} __OSfp; + +typedef struct { + u64 at, v0, v1, a0, a1, a2, a3; + u64 t0, t1, t2, t3, t4, t5, t6, t7; + u64 s0, s1, s2, s3, s4, s5, s6, s7; + u64 t8, t9; + u64 gp, sp, s8, ra; + u64 lo, hi; + u32 sr, pc, cause, badvaddr, rcp; + u32 fpcsr; + __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; + __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; +} __OSThreadContext; + +typedef struct { + u32 flag; + u32 count; + u64 time; +} __OSThreadprofile_s; + +typedef struct OSThread_s { + struct OSThread_s *next; /* run/mesg queue link */ + OSPri priority; /* run/mesg queue priority */ + struct OSThread_s **queue; /* queue thread is on */ + struct OSThread_s *tlnext; /* all threads queue link */ + u16 state; /* OS_STATE_* */ + u16 flags; /* flags for rmon */ + OSId id; /* id for debugging */ + int fp; /* thread has used fp unit */ + __OSThreadprofile_s *thprof; /* workarea for thread profiler */ + __OSThreadContext context; /* register/interrupt mask */ +} OSThread; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Thread states */ + +#define OS_STATE_STOPPED (1 << 0) +#define OS_STATE_RUNNABLE (1 << 1) +#define OS_STATE_RUNNING (1 << 2) +#define OS_STATE_WAITING (1 << 3) + +/* Recommended thread priorities for the system threads */ + +#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_SIMGR 140 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_IDLE 0 /* Must be 0 */ + +/* For thread profiler */ +#define THPROF_IDMAX 64 +#define THPROF_STACKSIZE 256 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Thread operations */ + +extern void osCreateThread(OSThread *, OSId, void (*)(void *), void *, void *, OSPri); +extern void osDestroyThread(OSThread *); +extern void osYieldThread(void); +extern void osStartThread(OSThread *); +extern void osStopThread(OSThread *); +extern OSId osGetThreadId(OSThread *); +extern void osSetThreadPri(OSThread *, OSPri); +extern OSPri osGetThreadPri(OSThread *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_THREAD_H_ */ diff --git a/include/PR/os_time.h b/include/PR/os_time.h new file mode 100644 index 000000000..d6422db54 --- /dev/null +++ b/include/PR/os_time.h @@ -0,0 +1,114 @@ + +/*==================================================================== + * os_time.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_time.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:19 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TIME_H_ +#define _OS_TIME_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "PR/os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for time value + */ +typedef u64 OSTime; + +/* + * Structure for interval timer + */ +typedef struct OSTimer_s { + struct OSTimer_s *next; /* point to next timer in list */ + struct OSTimer_s *prev; /* point to previous timer in list */ + OSTime interval; /* duration set by user */ + OSTime value; /* time remaining before */ + /* timer fires */ + OSMesgQueue *mq; /* Message Queue */ + OSMesg msg; /* Message to send */ +} OSTimer; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Timer interface */ + +extern OSTime osGetTime(void); +extern void osSetTime(OSTime); +extern int osSetTimer(OSTimer *, OSTime, OSTime, + OSMesgQueue *, OSMesg); +extern int osStopTimer(OSTimer *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TIME_H_ */ diff --git a/include/PR/os_tlb.h b/include/PR/os_tlb.h new file mode 100644 index 000000000..a4ea6fa0c --- /dev/null +++ b/include/PR/os_tlb.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_tlb.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TLB_H_ +#define _OS_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSPageMask; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Page size argument for TLB routines + */ +#define OS_PM_4K 0x0000000 +#define OS_PM_16K 0x0006000 +#define OS_PM_64K 0x001e000 +#define OS_PM_256K 0x007e000 +#define OS_PM_1M 0x01fe000 +#define OS_PM_4M 0x07fe000 +#define OS_PM_16M 0x1ffe000 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* TLB management routines */ + +extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); +extern void osMapTLBRdb(void); +extern void osUnmapTLB(s32); +extern void osUnmapTLBAll(void); +extern void osSetTLBASID(s32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TLB_H_ */ diff --git a/include/PR/os_vi.h b/include/PR/os_vi.h new file mode 100644 index 000000000..7fd3aad91 --- /dev/null +++ b/include/PR/os_vi.h @@ -0,0 +1,298 @@ + +/*==================================================================== + * os_vi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_vi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VI_H_ +#define _OS_VI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "PR/os_thread.h" +#include "PR/os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure to store VI register values that remain the same between 2 fields + */ +typedef struct { + u32 ctrl; + u32 width; + u32 burst; + u32 vSync; + u32 hSync; + u32 leap; + u32 hStart; + u32 xScale; + u32 vCurrent; +} OSViCommonRegs; + + +/* + * Structure to store VI register values that change between fields + */ +typedef struct { + u32 origin; + u32 yScale; + u32 vStart; + u32 vBurst; + u32 vIntr; +} OSViFieldRegs; + + +/* + * Structure for VI mode + */ +typedef struct { + u8 type; /* Mode type */ + OSViCommonRegs comRegs; /* Common registers for both fields */ + OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ +} OSViMode; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Video Interface (VI) mode type + */ +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 + +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 + +#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ +#define OS_VI_MPAL_LPF1 29 +#define OS_VI_MPAL_LAN1 30 +#define OS_VI_MPAL_LAF1 31 +#define OS_VI_MPAL_LPN2 32 +#define OS_VI_MPAL_LPF2 33 +#define OS_VI_MPAL_LAN2 34 +#define OS_VI_MPAL_LAF2 35 +#define OS_VI_MPAL_HPN1 36 +#define OS_VI_MPAL_HPF1 37 +#define OS_VI_MPAL_HAN1 38 +#define OS_VI_MPAL_HAF1 39 +#define OS_VI_MPAL_HPN2 40 +#define OS_VI_MPAL_HPF2 41 + +#define OS_VI_FPAL_LPN1 42 /* FPAL - Full screen PAL */ +#define OS_VI_FPAL_LPF1 43 +#define OS_VI_FPAL_LAN1 44 +#define OS_VI_FPAL_LAF1 45 +#define OS_VI_FPAL_LPN2 46 +#define OS_VI_FPAL_LPF2 47 +#define OS_VI_FPAL_LAN2 48 +#define OS_VI_FPAL_LAF2 49 +#define OS_VI_FPAL_HPN1 50 +#define OS_VI_FPAL_HPF1 51 +#define OS_VI_FPAL_HAN1 52 +#define OS_VI_FPAL_HAF1 53 +#define OS_VI_FPAL_HPN2 54 +#define OS_VI_FPAL_HPF2 55 + +/* + * Video Interface (VI) special features + */ +#define OS_VI_GAMMA_ON 0x0001 +#define OS_VI_GAMMA_OFF 0x0002 +#define OS_VI_GAMMA_DITHER_ON 0x0004 +#define OS_VI_GAMMA_DITHER_OFF 0x0008 +#define OS_VI_DIVOT_ON 0x0010 +#define OS_VI_DIVOT_OFF 0x0020 +#define OS_VI_DITHER_FILTER_ON 0x0040 +#define OS_VI_DITHER_FILTER_OFF 0x0080 + +/* + * Video Interface (VI) mode attribute bit + */ +#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ +#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ +#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ +#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ +#define OS_VI_BIT_ANTIALIAS 0x0010 +#define OS_VI_BIT_POINTSAMPLE 0x0020 +#define OS_VI_BIT_16PIXEL 0x0040 +#define OS_VI_BIT_32PIXEL 0x0080 +#define OS_VI_BIT_LORES 0x0100 +#define OS_VI_BIT_HIRES 0x0200 +#define OS_VI_BIT_NTSC 0x0400 +#define OS_VI_BIT_PAL 0x0800 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSViMode osViModeTable[]; /* Global VI mode table */ + +extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ +extern OSViMode osViModeNtscLpf1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeNtscLaf1; +extern OSViMode osViModeNtscLpn2; +extern OSViMode osViModeNtscLpf2; +extern OSViMode osViModeNtscLan2; +extern OSViMode osViModeNtscLaf2; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModeNtscHan1; +extern OSViMode osViModeNtscHaf1; +extern OSViMode osViModeNtscHpn2; +extern OSViMode osViModeNtscHpf2; + +extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ +extern OSViMode osViModePalLpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModePalLaf1; +extern OSViMode osViModePalLpn2; +extern OSViMode osViModePalLpf2; +extern OSViMode osViModePalLan2; +extern OSViMode osViModePalLaf2; +extern OSViMode osViModePalHpn1; +extern OSViMode osViModePalHpf1; +extern OSViMode osViModePalHan1; +extern OSViMode osViModePalHaf1; +extern OSViMode osViModePalHpn2; +extern OSViMode osViModePalHpf2; + +extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ +extern OSViMode osViModeMpalLpf1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeMpalLaf1; +extern OSViMode osViModeMpalLpn2; +extern OSViMode osViModeMpalLpf2; +extern OSViMode osViModeMpalLan2; +extern OSViMode osViModeMpalLaf2; +extern OSViMode osViModeMpalHpn1; +extern OSViMode osViModeMpalHpf1; +extern OSViMode osViModeMpalHan1; +extern OSViMode osViModeMpalHaf1; +extern OSViMode osViModeMpalHpn2; +extern OSViMode osViModeMpalHpf2; + +extern OSViMode osViModeFpalLpn1; /* Individual VI FPAL modes */ +extern OSViMode osViModeFpalLpf1; +extern OSViMode osViModeFpalLan1; +extern OSViMode osViModeFpalLaf1; +extern OSViMode osViModeFpalLpn2; +extern OSViMode osViModeFpalLpf2; +extern OSViMode osViModeFpalLan2; +extern OSViMode osViModeFpalLaf2; +extern OSViMode osViModeFpalHpn1; +extern OSViMode osViModeFpalHpf1; +extern OSViMode osViModeFpalHan1; +extern OSViMode osViModeFpalHaf1; +extern OSViMode osViModeFpalHpn2; +extern OSViMode osViModeFpalHpf2; + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Video interface (Vi) */ +extern u32 osViGetStatus(void); +extern u32 osViGetCurrentMode(void); +extern u32 osViGetCurrentLine(void); +extern u32 osViGetCurrentField(void); +extern void *osViGetCurrentFramebuffer(void); +extern void *osViGetNextFramebuffer(void); +extern void osViSetXScale(f32); +extern void osViSetYScale(f32); +extern void osViExtendVStart(u32); +extern void osViSetSpecialFeatures(u32); +extern void osViSetMode(OSViMode *); +extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); +extern void osViSwapBuffer(void *); +extern void osViBlack(u8); +extern void osViFade(u8, u16); +extern void osViRepeatLine(u8); +extern void osCreateViManager(OSPri); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VI_H_ */ diff --git a/include/PR/os_voice.h b/include/PR/os_voice.h new file mode 100644 index 000000000..6273a2cfb --- /dev/null +++ b/include/PR/os_voice.h @@ -0,0 +1,108 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_voice.h,v $ + $Revision: 1.2 $ + $Date: 1999/07/13 08:36:42 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VOICE_H_ +#define _OS_VOICE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { /* Voice Recognition System */ + OSMesgQueue *__mq; /* SI Message Queue */ + int __channel; /* Controller Port # */ + s32 __mode; + u8 cmd_status; /* Command Status */ +} OSVoiceHandle; + +typedef struct { /* Voice Recognition System */ + u16 warning; + u16 answer_num; /* 0...5 */ + u16 voice_level; + u16 voice_sn; + u16 voice_time; + u16 answer[5]; + u16 distance[5]; +} OSVoiceData; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for Voice Recognition System */ + +#define VOICE_WARN_TOO_SMALL 0x0400 +#define VOICE_WARN_TOO_LARGE 0x0800 +#define VOICE_WARN_NOT_FIT 0x4000 +#define VOICE_WARN_TOO_NOISY 0x8000 + +#define VOICE_STATUS_READY 0 +#define VOICE_STATUS_START 1 +#define VOICE_STATUS_CANCEL 3 +#define VOICE_STATUS_BUSY 5 +#define VOICE_STATUS_END 7 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Voice Recognition System */ +extern s32 osVoiceInit(OSMesgQueue *, OSVoiceHandle *, int); +extern s32 osVoiceCheckWord(u8 *data); +extern s32 osVoiceClearDictionary(OSVoiceHandle *, u8); +extern s32 osVoiceControlGain(OSVoiceHandle *, s32, s32); +extern s32 osVoiceSetWord(OSVoiceHandle *, u8 *); +extern s32 osVoiceStartReadData(OSVoiceHandle *); +extern s32 osVoiceStopReadData(OSVoiceHandle *); +extern s32 osVoiceGetReadData(OSVoiceHandle *, OSVoiceData *); +extern s32 osVoiceMaskDictionary(OSVoiceHandle *, u8 *, int); +extern void osVoiceCountSyllables(u8 *, u32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VOICE_H_ */ diff --git a/include/PR/rcp.h b/include/PR/rcp.h index 3795ff72a..4ee409216 100644 --- a/include/PR/rcp.h +++ b/include/PR/rcp.h @@ -60,9 +60,9 @@ The Indy development board use cartridge domain 1: 0x1000_0000 .. 0x10ff_ffff RAMROM -0x1800_0000 .. 0x1800_0003 GIO interrupt (6 bits valid in 4 bytes) -0x1800_0400 .. 0x1800_0403 GIO sync (6 bits valid in 4 bytes) -0x1800_0800 .. 0x1800_0803 CART interrupt (6 bits valid in 4 bytes) +0x1800_0000 .. 0x1800_0003 GIO interrupt (6 bits valid in 4 bytes) +0x1800_0400 .. 0x1800_0403 GIO sync (6 bits valid in 4 bytes) +0x1800_0800 .. 0x1800_0803 CART interrupt (6 bits valid in 4 bytes) @@ -141,7 +141,7 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * Controller channel + * Controller channel * Each game controller channel has 4 error bits that are defined in bit 6-7 of * the Rx and Tx data size area bytes. Programmers need to clear these bits * when setting the Tx/Rx size area values for a channel @@ -178,7 +178,7 @@ The Indy development board use cartridge domain 1: /* SP memory address (R/W): [11:0] DMEM/IMEM address; [12] 0=DMEM,1=IMEM */ #define SP_MEM_ADDR_REG (SP_BASE_REG+0x00) /* Master */ - + /* SP DRAM DMA address (R/W): [23:0] RDRAM address */ #define SP_DRAM_ADDR_REG (SP_BASE_REG+0x04) /* Slave */ @@ -258,7 +258,7 @@ The Indy development board use cartridge domain 1: #define SP_STATUS_SIG6 0x2000 /* Bit 13: signal 6 set */ #define SP_STATUS_SIG7 0x4000 /* Bit 14: signal 7 set */ -/* +/* * Use of SIG bits */ #define SP_CLR_YIELD SP_CLR_SIG0 @@ -290,15 +290,15 @@ The Indy development board use cartridge domain 1: /* * Patterns to interpret status reg (SP_BIST_REG - read) */ -/* First 2 bits are same as in write mode: - * Bit 0: BIST check; Bit 1: BIST go +/* First 2 bits are same as in write mode: + * Bit 0: BIST check; Bit 1: BIST go */ #define SP_IBIST_DONE 0x04 /* Bit 2: BIST done */ #define SP_IBIST_FAILED 0x78 /* Bit [6:3]: BIST fail */ /************************************************************************* - * DP Command Registers + * DP Command Registers */ #define DPC_BASE_REG 0x04100000 @@ -309,13 +309,13 @@ The Indy development board use cartridge domain 1: #define DPC_END_REG (DPC_BASE_REG+0x04) /* DP CMD DMA end (R): [23:0] DMEM/RDRAM current address */ -#define DPC_CURRENT_REG (DPC_BASE_REG+0x08) +#define DPC_CURRENT_REG (DPC_BASE_REG+0x08) /* DP CMD status (R/W): [9:0] valid bits - see below for definitions */ #define DPC_STATUS_REG (DPC_BASE_REG+0x0C) /* DP clock counter (R): [23:0] clock counter */ -#define DPC_CLOCK_REG (DPC_BASE_REG+0x10) +#define DPC_CLOCK_REG (DPC_BASE_REG+0x10) /* DP buffer busy counter (R): [23:0] clock counter */ #define DPC_BUFBUSY_REG (DPC_BASE_REG+0x14) @@ -358,7 +358,7 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * DP Span Registers + * DP Span Registers */ #define DPS_BASE_REG 0x04200000 @@ -384,19 +384,19 @@ The Indy development board use cartridge domain 1: /* * Patterns to interpret status reg (DPS_TMEM_BIST_REG - read) */ -/* First 2 bits are same as in write mode: - * Bit 0: BIST check; Bit 1: BIST go +/* First 2 bits are same as in write mode: + * Bit 0: BIST check; Bit 1: BIST go */ #define DPS_TBIST_DONE 0x004 /* Bit 2: BIST done */ #define DPS_TBIST_FAILED 0x7F8 /* Bit [10:3]: BIST fail */ /************************************************************************* - * MIPS Interface (MI) Registers + * MIPS Interface (MI) Registers */ #define MI_BASE_REG 0x04300000 -/* +/* * MI init mode (W): [6:0] init length, [7] clear init mode, [8] set init mode * [9/10] clear/set ebus test mode, [11] clear DP interrupt * (R): [6:0] init length, [7] init mode, [8] ebus test mode @@ -429,9 +429,9 @@ The Indy development board use cartridge domain 1: /* MI interrupt (R): [5:0] valid bits - see below for bit patterns */ #define MI_INTR_REG (MI_BASE_REG+0x08) -/* - * MI interrupt mask (W): [11:0] valid bits - see below for bit patterns - * (R): [5:0] valid bits - see below for bit patterns +/* + * MI interrupt mask (W): [11:0] valid bits - see below for bit patterns + * (R): [5:0] valid bits - see below for bit patterns */ #define MI_INTR_MASK_REG (MI_BASE_REG+0x0C) @@ -447,7 +447,7 @@ The Indy development board use cartridge domain 1: /* * The following are values to clear/set various interrupt bit mask - * They can be ORed together to manipulate multiple bits + * They can be ORed together to manipulate multiple bits * (MI_INTR_MASK_REG - write) */ #define MI_INTR_MASK_CLR_SP 0x0001 /* Bit 0: clear SP mask */ @@ -464,7 +464,7 @@ The Indy development board use cartridge domain 1: #define MI_INTR_MASK_SET_DP 0x0800 /* Bit 11: set DP mask */ /* - * The following are values to check for interrupt mask setting + * The following are values to check for interrupt mask setting * (MI_INTR_MASK_REG - read) */ #define MI_INTR_MASK_SP 0x01 /* Bit 0: SP intr mask */ @@ -476,12 +476,12 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * Video Interface (VI) Registers + * Video Interface (VI) Registers */ #define VI_BASE_REG 0x04400000 -/* VI status/control (R/W): [15-0] valid bits: - * [1:0] = type[1:0] (pixel size) +/* VI status/control (R/W): [15-0] valid bits: + * [1:0] = type[1:0] (pixel size) * 0: blank (no data, no sync) * 1: reserved * 2: 5/5/5/3 ("16" bit) @@ -492,7 +492,7 @@ The Indy development board use cartridge domain 1: * [5] = reserved - always off * [6] = serrate (always on if interlaced, off if not) * [7] = reserved - diagnostics only - * [9:8] = anti-alias (aa) mode[1:0] + * [9:8] = anti-alias (aa) mode[1:0] * 0: aa & resamp (always fetch extra lines) * 1: aa & resamp (fetch extra lines if needed) * 2: resamp only (treat as all fully covered) @@ -509,89 +509,96 @@ The Indy development board use cartridge domain 1: #define VI_DRAM_ADDR_REG VI_ORIGIN_REG /* VI width (R/W): [11:0] frame buffer line width in pixels */ -#define VI_WIDTH_REG (VI_BASE_REG+0x08) +#define VI_WIDTH_REG (VI_BASE_REG+0x08) #define VI_H_WIDTH_REG VI_WIDTH_REG /* VI vertical intr (R/W): [9:0] interrupt when current half-line = V_INTR */ -#define VI_INTR_REG (VI_BASE_REG+0x0C) +#define VI_INTR_REG (VI_BASE_REG+0x0C) #define VI_V_INTR_REG VI_INTR_REG -/* +/* * VI current vertical line (R/W): [9:0] current half line, sampled once per * line (the lsb of V_CURRENT is constant within a field, and in * interlaced modes gives the field number - which is constant for non- * interlaced modes) * - Any write to this register will clear interrupt line */ -#define VI_CURRENT_REG (VI_BASE_REG+0x10) +#define VI_CURRENT_REG (VI_BASE_REG+0x10) #define VI_V_CURRENT_LINE_REG VI_CURRENT_REG -/* - * VI video timing (R/W): [ 7: 0] horizontal sync width in pixels, +/* + * VI video timing (R/W): [ 7: 0] horizontal sync width in pixels, * [15: 8] color burst width in pixels, - * [19:16] vertical sync width in half lines, + * [19:16] vertical sync width in half lines, * [29:20] start of color burst in pixels from h-sync */ -#define VI_BURST_REG (VI_BASE_REG+0x14) +#define VI_BURST_REG (VI_BASE_REG+0x14) #define VI_TIMING_REG VI_BURST_REG /* VI vertical sync (R/W): [9:0] number of half-lines per field */ -#define VI_V_SYNC_REG (VI_BASE_REG+0x18) +#define VI_V_SYNC_REG (VI_BASE_REG+0x18) -/* VI horizontal sync (R/W): [11: 0] total duration of a line in 1/4 pixel - * [20:16] a 5-bit leap pattern used for PAL only +/* VI horizontal sync (R/W): [11: 0] total duration of a line in 1/4 pixel + * [20:16] a 5-bit leap pattern used for PAL only * (h_sync_period) */ -#define VI_H_SYNC_REG (VI_BASE_REG+0x1C) +#define VI_H_SYNC_REG (VI_BASE_REG+0x1C) -/* +/* * VI horizontal sync leap (R/W): [11: 0] identical to h_sync_period * [27:16] identical to h_sync_period */ -#define VI_LEAP_REG (VI_BASE_REG+0x20) +#define VI_LEAP_REG (VI_BASE_REG+0x20) #define VI_H_SYNC_LEAP_REG VI_LEAP_REG -/* +/* * VI horizontal video (R/W): [ 9: 0] end of active video in screen pixels * : [25:16] start of active video in screen pixels */ #define VI_H_START_REG (VI_BASE_REG+0x24) #define VI_H_VIDEO_REG VI_H_START_REG -/* +/* * VI vertical video (R/W): [ 9: 0] end of active video in screen half-lines * : [25:16] start of active video in screen half-lines */ #define VI_V_START_REG (VI_BASE_REG+0x28) #define VI_V_VIDEO_REG VI_V_START_REG -/* +/* * VI vertical burst (R/W): [ 9: 0] end of color burst enable in half-lines * : [25:16] start of color burst enable in half-lines */ -#define VI_V_BURST_REG (VI_BASE_REG+0x2C) +#define VI_V_BURST_REG (VI_BASE_REG+0x2C) /* VI x-scale (R/W): [11: 0] 1/horizontal scale up factor (2.10 format) * [27:16] horizontal subpixel offset (2.10 format) */ -#define VI_X_SCALE_REG (VI_BASE_REG+0x30) +#define VI_X_SCALE_REG (VI_BASE_REG+0x30) /* VI y-scale (R/W): [11: 0] 1/vertical scale up factor (2.10 format) * [27:16] vertical subpixel offset (2.10 format) */ -#define VI_Y_SCALE_REG (VI_BASE_REG+0x34) +#define VI_Y_SCALE_REG (VI_BASE_REG+0x34) /* * Patterns to interpret VI_CONTROL_REG */ -#define VI_CTRL_TYPE_16 0x00002 /* Bit [1:0] pixel size: 16 bit */ -#define VI_CTRL_TYPE_32 0x00003 /* Bit [1:0] pixel size: 32 bit */ -#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* Bit 2: default = on */ -#define VI_CTRL_GAMMA_ON 0x00008 /* Bit 3: default = on */ -#define VI_CTRL_DIVOT_ON 0x00010 /* Bit 4: default = on */ -#define VI_CTRL_SERRATE_ON 0x00040 /* Bit 6: on if interlaced */ -#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* Bit 16: dither-filter mode */ +#define VI_CTRL_TYPE_16 0x00002 /* [1:0] pixel size: 16 bit */ +#define VI_CTRL_TYPE_32 0x00003 /* [1:0] pixel size: 32 bit */ +#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* 2: default = on */ +#define VI_CTRL_GAMMA_ON 0x00008 /* 3: default = on */ +#define VI_CTRL_DIVOT_ON 0x00010 /* 4: default = on */ +#define VI_CTRL_SERRATE_ON 0x00040 /* 6: on if interlaced */ +#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_PIXEL_ADV_MASK 0x01000 /* [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_1 0x01000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_2 0x02000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_3 0x03000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* 16: dither-filter mode */ /* * Possible video clocks (NTSC or PAL) @@ -602,7 +609,7 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * Audio Interface (AI) Registers + * Audio Interface (AI) Registers * * The address and length registers are double buffered; that is, they * can be written twice before becoming full. @@ -620,21 +627,21 @@ The Indy development board use cartridge domain 1: /* AI control (W): [0] DMA enable - if LSB == 1, DMA is enabled */ #define AI_CONTROL_REG (AI_BASE_REG+0x08) /* R2: DMA Control */ -/* - * AI status (R): [31]/[0] ai_full (addr & len buffer full), [30] ai_busy +/* + * AI status (R): [31]/[0] ai_full (addr & len buffer full), [30] ai_busy * Note that a 1->0 transition in ai_full will set interrupt - * (W): clear audio interrupt + * (W): clear audio interrupt */ #define AI_STATUS_REG (AI_BASE_REG+0x0C) /* R3: Status */ -/* - * AI DAC sample period register (W): [13:0] dac rate +/* + * AI DAC sample period register (W): [13:0] dac rate * - vid_clock/(dperiod + 1) is the DAC sample rate * - (dperiod + 1) >= 66 * (aclockhp + 1) must be true */ #define AI_DACRATE_REG (AI_BASE_REG+0x10) /* R4: DAC rate 14-lsb*/ -/* +/* * AI bit rate (W): [3:0] bit rate (abus clock half period register - aclockhp) * - vid_clock/(2 * (aclockhp + 1)) is the DAC clock rate * - The abus clock stops if aclockhp is zero @@ -675,7 +682,7 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * Peripheral Interface (PI) Registers + * Peripheral Interface (PI) Registers */ #define PI_BASE_REG 0x04600000 @@ -691,7 +698,7 @@ The Indy development board use cartridge domain 1: /* PI write length (R/W): [23:0] write data length */ #define PI_WR_LEN_REG (PI_BASE_REG+0x0C) -/* +/* * PI status (R): [0] DMA busy, [1] IO busy, [2], error * (W): [0] reset controller (and abort current op), [1] clear intr */ @@ -742,12 +749,12 @@ The Indy development board use cartridge domain 1: /* PI status register has 2 bits active when written to: * Bit 0: When set, reset PIC * Bit 1: When set, clear interrupt flag - * The values of the two bits can be ORed together to both reset PIC and + * The values of the two bits can be ORed together to both reset PIC and * clear interrupt at the same time. * - * Note: - * - The PIC does generate an interrupt at the end of each DMA. CPU - * needs to clear the interrupt flag explicitly (from an interrupt + * Note: + * - The PIC does generate an interrupt at the end of each DMA. CPU + * needs to clear the interrupt flag explicitly (from an interrupt * handler) by writing into the STATUS register with bit 1 set. * * - When a DMA completes, the interrupt flag is set. CPU can issue @@ -779,12 +786,12 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * RDRAM Interface (RI) Registers + * RDRAM Interface (RI) Registers */ #define RI_BASE_REG 0x04700000 /* RI mode (R/W): [1:0] operating mode, [2] stop T active, [3] stop R active */ -#define RI_MODE_REG (RI_BASE_REG+0x00) +#define RI_MODE_REG (RI_BASE_REG+0x00) /* RI config (R/W): [5:0] current control input, [6] current control enable */ #define RI_CONFIG_REG (RI_BASE_REG+0x04) @@ -796,8 +803,8 @@ The Indy development board use cartridge domain 1: #define RI_SELECT_REG (RI_BASE_REG+0x0C) /* RI refresh (R/W): [7:0] clean refresh delay, [15:8] dirty refresh delay, - * [16] refresh bank, [17] refresh enable - * [18] refresh optimize + * [16] refresh bank, [17] refresh enable + * [18] refresh optimize */ #define RI_REFRESH_REG (RI_BASE_REG+0x10) #define RI_COUNT_REG RI_REFRESH_REG @@ -813,7 +820,7 @@ The Indy development board use cartridge domain 1: /************************************************************************* - * Serial Interface (SI) Registers + * Serial Interface (SI) Registers */ #define SI_BASE_REG 0x04800000 @@ -828,7 +835,7 @@ The Indy development board use cartridge domain 1: /* SI address write 64B (W): [] any write causes a 64B DMA read */ #define SI_PIF_ADDR_WR64B_REG (SI_BASE_REG+0x10) /* R4: 64B DRAM->PIF */ -/* +/* * SI status (W): [] any write clears interrupt * (R): [0] DMA busy, [1] IO read busy, [2] reserved * [3] DMA error, [12] interrupt @@ -847,7 +854,7 @@ The Indy development board use cartridge domain 1: #define SI_STATUS_INTERRUPT 0x1000 /************************************************************************* - * Development Board GIO Control Registers + * Development Board GIO Control Registers */ #define GIO_BASE_REG 0x18000000 @@ -879,4 +886,3 @@ The Indy development board use cartridge domain 1: #endif #endif /* _RCP_H_ */ - diff --git a/include/PR/sptask.h b/include/PR/sptask.h index 8d6ea4123..1c1274d90 100644 --- a/include/PR/sptask.h +++ b/include/PR/sptask.h @@ -186,7 +186,7 @@ typedef u32 OSYieldResult; /* * break this up into two steps for debugging. */ -extern void osSpTaskLoad(OSTask *tp); +extern void osSpTaskLoad(OSTask *intp); extern void osSpTaskStartGo(OSTask *tp); extern void osSpTaskYield(void); diff --git a/include/PR/viint.h b/include/PR/viint.h new file mode 100644 index 000000000..ffe092771 --- /dev/null +++ b/include/PR/viint.h @@ -0,0 +1,71 @@ +#ifndef _VIINT_H +#define _VIINT_H +#include "PR/os_internal.h" + +#define OS_TV_TYPE_PAL 0 +#define OS_TV_TYPE_NTSC 1 +#define OS_TV_TYPE_MPAL 2 + +#define VI_STATE_MODE_UPDATED 0x01 +#define VI_STATE_XSCALE_UPDATED 0x02 +#define VI_STATE_YSCALE_UPDATED 0x04 +#define VI_STATE_CTRL_UPDATED 0x08 // related to control regs changing +#define VI_STATE_BUFFER_UPDATED 0x10 // swap buffer +#define VI_STATE_BLACK 0x20 // probably related to a black screen +#define VI_STATE_REPEATLINE 0x40 // repeat line? +#define VI_STATE_FADE 0x80 // fade + +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ + +#define VI_SCALE_MASK 0xfff //see rcp scale_x/scale_y +#define VI_2_10_FPART_MASK 0x3ff +#define VI_SUBPIXEL_SH 0x10 + +#define BURST(hsync_width, color_width, vsync_width, color_start) \ + (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20)) +#define WIDTH(v) (v) +#define VSYNC(v) (v) +#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF)) +#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF)) +#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF)) + +#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1)) + +#define F210(val) FTOFIX(val, 2, 10) +#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16)) + +#define VCURRENT(v) v //seemingly unused +#define ORIGIN(v) v +#define VINTR(v) v +#define HSTART START + +typedef struct +{ + /* 0x0 */ f32 factor; + /* 0x4 */ u16 offset; + /* 0x8 */ u32 scale; +} __OSViScale; + +typedef struct +{ + /* 0x0 */ u16 state; + /* 0x2 */ u16 retraceCount; + /* 0x4 */ void *framep; + /* 0x8 */ OSViMode *modep; + /* 0xC */ u32 control; + /* 0x10 */ OSMesgQueue *msgq; + /* 0x14 */ OSMesg msg; + /* 0x18 */ __OSViScale x; + /* 0x24 */ __OSViScale y; +} __OSViContext; // 0x30 bytes + +void __osViSwapContext(void); +extern __OSViContext *__osViCurr; +extern __OSViContext *__osViNext; +extern u32 __additional_scanline; +__OSViContext *__osViGetCurrentContext(void); +void __osViInit(void); +extern OSDevMgr __osViDevMgr; +#endif diff --git a/include/PR/xstdio.h b/include/PR/xstdio.h index 9850d88f8..2eb1592c3 100644 --- a/include/PR/xstdio.h +++ b/include/PR/xstdio.h @@ -1,38 +1,37 @@ -#ifndef PR_XSTDIO_H -#define PR_XSTDIO_H - -#include "ultratypes.h" +#ifndef _XSTDIO_H +#define _XSTDIO_H +#include "PR/ultratypes.h" +#include "libc/stdlib.h" #include "libc/stdarg.h" typedef struct { /* 0x0 */ union { - /* 0x0 */ s64 ll; - /* 0x0 */ f64 ld; + /* 0x0 */ long long ll; + /* 0x0 */ double ld; } v; - /* 0x8 */ char* s; - /* 0xC */ s32 n0; - /* 0x10 */ s32 nz0; - /* 0x14 */ s32 n1; - /* 0x18 */ s32 nz1; - /* 0x1C */ s32 n2; - /* 0x20 */ s32 nz2; - /* 0x24 */ s32 prec; - /* 0x28 */ s32 width; + /* 0x8 */ unsigned char* s; + /* 0xC */ int n0; + /* 0x10 */ int nz0; + /* 0x14 */ int n1; + /* 0x18 */ int nz1; + /* 0x1C */ int n2; + /* 0x20 */ int nz2; + /* 0x24 */ int prec; + /* 0x28 */ int width; /* 0x2C */ size_t nchar; - /* 0x30 */ u32 flags; - /* 0x34 */ u8 qual; + /* 0x30 */ unsigned int flags; + /* 0x34 */ char qual; } _Pft; -typedef void* (*PrintCallback)(void*, const char*, size_t); - #define FLAGS_SPACE 1 #define FLAGS_PLUS 2 #define FLAGS_MINUS 4 #define FLAGS_HASH 8 #define FLAGS_ZERO 16 +typedef char *outfun(char*,const char*,size_t); -s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap); -void _Litob(_Pft* args, u8 type); -void _Ldtob(_Pft* args, u8 type); +int _Printf(outfun prout, char *arg, const char *fmt, va_list args); +void _Litob(_Pft *args, char type); +void _Ldtob(_Pft* px, char code); #endif diff --git a/include/macros.h b/include/macros.h index 3756c919a..0474f68ec 100644 --- a/include/macros.h +++ b/include/macros.h @@ -14,7 +14,7 @@ #define RAND_INT_SEEDED(max) ((s32)(Rand_ZeroOneSeeded()*(max))) #define RAND_FLOAT_CENTERED_SEEDED(width) ((Rand_ZeroOneSeeded()-0.5f)*(width)) -#define SEGMENTED_TO_VIRTUAL(segment) ((void*)OS_PHYSICAL_TO_K0(gSegments[((uintptr_t)(segment)<<4)>>0x1C]+(((uintptr_t)(segment))&0xFFFFFF))) +#define SEGMENTED_TO_VIRTUAL(segment) ((void*)OS_PHYSICAL_TO_K0(gSegments[((uintptr_t)(segment)<<4)>>0x1C]+(((uintptr_t)(segment))&0xFFFFFF))) #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) @@ -31,10 +31,23 @@ #define CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(osClockRate/15625LL)) #define CYCLES_TO_MSEC(c) ((s32)CYCLES_TO_USEC(c)/1000) +/* + * Macros for libultra + */ + #if defined(__sgi) #define PRINTF #else #define PRINTF(...) #endif +#define ALIGNED(x) __attribute__((aligned(x))) +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) +#define STUBBED_PRINTF(x) ((void)(x)) +#define UNUSED __attribute__((unused)) + +#ifndef __GNUC__ +#define __attribute__(x) +#endif + #endif // MACROS_H diff --git a/include/rmonint.h b/include/rmonint.h index 59ad7364f..a9d93a326 100644 --- a/include/rmonint.h +++ b/include/rmonint.h @@ -139,7 +139,7 @@ int __rmonExecute(KKHeader* request); /* commands */ -typedef int (*FUNPTR)(); +typedef int (*FUNPTR)(KKHeader*); int __rmonLoadProgram(KKHeader* req); int __rmonListProcesses(KKHeader* req); diff --git a/src/libultra/debug/kdebugserver.c b/src/libultra/debug/kdebugserver.c index 84364b4cd..9c4814227 100644 --- a/src/libultra/debug/kdebugserver.c +++ b/src/libultra/debug/kdebugserver.c @@ -1,11 +1,92 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/rdb.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/debug/kdebugserver/string_to_u32.s") +// not included in final rom, but __osThreadSave is here for some reason +OSThread __osThreadSave; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/debug/kdebugserver/send_packet.s") +extern OSThread* __osRunningThread; +extern u32 __osRdb_IP6_Empty; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/debug/kdebugserver/clear_IP6.s") +static u8 buffer[12]; +static u32 numChars = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/debug/kdebugserver/send.s") +static u32 string_to_u32(u8* s) { + u32 k; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/debug/kdebugserver/kdebugserver.s") + k = ((s[0] & 0xFF) << 0x18); + k |= ((s[1] & 0xFF) << 0x10); + k |= ((s[2] & 0xFF) << 0x8); + k |= (s[3] & 0xFF); + + return k; +} + +static void send_packet(u8* s, u32 n) { + rdbPacket packet; + u32 i; + + packet.type = 0xC; + packet.length = n; + + for (i = 0; i < n; i++) { + packet.buf[i] = s[i]; + } + *(vu32*) RDB_BASE_REG = *(u32*) &packet; +} + +static void clear_IP6(void) { + while (!(__osGetCause() & CAUSE_IP6)) { + ; + } + *(vu32*) RDB_READ_INTR_REG = 0; + + while (__osGetCause() & CAUSE_IP6) { + ; + } +} + +static void send(u8* s, u32 n) { + u32 ct; + u32 i = 0; + u32 getLastIP6; + + if (!__osRdb_IP6_Empty) { + clear_IP6(); + getLastIP6 = FALSE; + } else { + getLastIP6 = TRUE; + } + while (n != 0) { + ct = (n < 3) ? n : 3; + send_packet(s + i, ct); + n -= ct; + i += ct; + if (n != 0) { + clear_IP6(); + } + } + if (getLastIP6) { + clear_IP6(); + } +} + +void kdebugserver(rdbPacket packet) { + u32 i; + u32 length; + u8* addr; + + for (i = 0; i < 3; i++) { + buffer[numChars++] = packet.buf[i]; + } + + if (buffer[0] == 2) { + send((char*) &__osRunningThread->context, sizeof(__OSThreadContext)); + numChars = 0; + } else if (numChars >= 9 && buffer[0] == 1) { + addr = string_to_u32(&buffer[1]); + length = string_to_u32(&buffer[5]); + send(addr, length); + numChars = 0; + } +} diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c index 8dc3fb067..e67d54851 100644 --- a/src/libultra/gu/cosf.c +++ b/src/libultra/gu/cosf.c @@ -1,5 +1,125 @@ -#include "common.h" +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/cosf/__cosf.s") +#include "PR/ultratypes.h" +#include "PR/guint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/cosf/D_800C9390.s") +/* ==================================================================== + * ==================================================================== + * + * Module: fcos.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:10:53 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/cosf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fcos function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fcos = __cosf +#pragma weak cosf = __cosf +#define fcos __cosf + +/* coefficients for polynomial approximation of cos on +/- pi/2 */ + +static const du P[] = { + { 0x3ff00000, 0x00000000 }, { 0xbfc55554, 0xbc83656d }, { 0x3f8110ed, 0x3804c2a0 }, + { 0xbf29f6ff, 0xeea56814 }, { 0x3ec5dbdf, 0x0e314bfe }, +}; + +static const du rpi = { 0x3fd45f30, 0x6dc9c883 }; + +static const du pihi = { 0x400921fb, 0x50000000 }; + +static const du pilo = { 0x3e6110b4, 0x611a6263 }; + +static const fu zero = { 0x00000000 }; + +/* ==================================================================== + * + * FunctionName fcos + * + * Description computes cosine of arg + * + * ==================================================================== + */ + +float fcos(float x) { + float absx; + double dx, xsq, poly; + double dn; + int n; + double result; + int ix, xpt; + + ix = *(int*) &x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + if (xpt < 0x136) { + /* |x| < 2^28 */ + + /* use the standard algorithm from Cody and Waite, doing + the computations in double precision + */ + + absx = ABS(x); + + dx = absx; + + dn = dx * rpi.d + 0.5; + n = ROUND(dn); + dn = n; + + dn -= 0.5; + + dx = dx - dn * pihi.d; + dx = dx - dn * pilo.d; /* dx = x - (n - 0.5)*pi */ + + xsq = dx * dx; + + poly = ((P[4].d * xsq + P[3].d) * xsq + P[2].d) * xsq + P[1].d; + + result = dx + (dx * xsq) * poly; + + /* negate result if n is odd */ + + if ((n & 1) == 0) { + return ((float) result); + } + + return (-(float) result); + } + + if (x != x) { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return (__libm_qnan_f); + } + + /* just give up and return 0.0 */ + + return (zero.f); +} diff --git a/src/libultra/gu/mtxutil.c b/src/libultra/gu/mtxutil.c index a1d5fc9d4..66dc44c3d 100644 --- a/src/libultra/gu/mtxutil.c +++ b/src/libultra/gu/mtxutil.c @@ -1,9 +1,76 @@ -#include "common.h" +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/mtxutil/guMtxF2L.s") +#include "PR/ultratypes.h" +#include "PR/guint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/mtxutil/guMtxIdentF.s") +void guMtxF2L(float mf[4][4], Mtx* m) { + int i, j; + int e1, e2; + int *ai, *af; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/mtxutil/guMtxIdent.s") + ai = (int*) &m->m[0][0]; + af = (int*) &m->m[2][0]; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/mtxutil/guMtxL2F.s") + for (i = 0; i < 4; i++) { + for (j = 0; j < 2; j++) { + e1 = FTOFIX32(mf[i][j * 2]); + e2 = FTOFIX32(mf[i][j * 2 + 1]); + *(ai++) = (e1 & 0xffff0000) | ((e2 >> 16) & 0xffff); + *(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff); + } + } +} + +// This function seems to use the SM64 version of the guMtxF2L function +void guMtxL2F(float mf[4][4], Mtx* m) { + int r, c; + u32 tmp1; + u32 tmp2; + u32* m1; + u32* m2; + s32 stmp1, stmp2; + m1 = (u32*) &m->m[0][0]; + m2 = (u32*) &m->m[2][0]; + for (r = 0; r < 4; r++) { + for (c = 0; c < 2; c++) { + tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff); + tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff); + stmp1 = *(s32*) &tmp1; + stmp2 = *(s32*) &tmp2; + mf[r][c * 2 + 0] = stmp1 / 65536.0f; + mf[r][c * 2 + 1] = stmp2 / 65536.0f; + } + } +} + +void guMtxIdentF(float mf[4][4]) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (i == j) { + mf[i][j] = 1.0; + } else { + mf[i][j] = 0.0; + } + } + } +} + +void guMtxIdent(Mtx* m) { + float mf[4][4]; + + guMtxIdentF(mf); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/perspective.c b/src/libultra/gu/perspective.c index 174663561..9b54e888b 100644 --- a/src/libultra/gu/perspective.c +++ b/src/libultra/gu/perspective.c @@ -1,5 +1,59 @@ -#include "common.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/perspective/guPerspectiveF.s") +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/perspective/guPerspective.s") +#include "PR/ultratypes.h" +#include "PR/guint.h" + +extern f32 __cosf(f32); +extern f32 __sinf(f32); + +void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { + float cot; + int i, j; + + guMtxIdentF(mf); + + fovy *= 3.1415926 / 180.0; + cot = __cosf(fovy / 2) / __sinf(fovy / 2); + + mf[0][0] = cot / aspect; + mf[1][1] = cot; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = (2 * near * far) / (near - far); + mf[3][3] = 0; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + mf[i][j] *= scale; + } + } + + if (perspNorm != (u16*) NULL) { + if (near + far <= 2.0) { + *perspNorm = (u16) 0xFFFF; + } else { + *perspNorm = (u16) ((2.0 * 65536.0) / (near + far)); + if (*perspNorm <= 0) { + *perspNorm = (u16) 0x0001; + } + } + } +} + +void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { + Matrix mf; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c index f0f3026f9..b10dece66 100644 --- a/src/libultra/gu/sinf.c +++ b/src/libultra/gu/sinf.c @@ -1,5 +1,142 @@ -#include "common.h" +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/sinf/__sinf.s") +#include "PR/ultratypes.h" +#include "PR/guint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/sinf/D_800C9340.s") +/* ==================================================================== + * ==================================================================== + * + * Module: fsin.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:14:51 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sinf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fsin function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fsin = __sinf +#pragma weak sinf = __sinf +#define fsin __sinf + +/* coefficients for polynomial approximation of sin on +/- pi/2 */ + +static const du P[] = { + { 0x3ff00000, 0x00000000 }, { 0xbfc55554, 0xbc83656d }, { 0x3f8110ed, 0x3804c2a0 }, + { 0xbf29f6ff, 0xeea56814 }, { 0x3ec5dbdf, 0x0e314bfe }, +}; + +static const du rpi = { 0x3fd45f30, 0x6dc9c883 }; + +static const du pihi = { 0x400921fb, 0x50000000 }; + +static const du pilo = { 0x3e6110b4, 0x611a6263 }; + +static const fu zero = { 0x00000000 }; + +/* ==================================================================== + * + * FunctionName fsin + * + * Description computes sine of arg + * + * ==================================================================== + */ + +float fsin(float x) { + double dx, xsq, poly; + double dn; + int n; + double result; + int ix, xpt; + + ix = *(int*) &x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + if (xpt < 0xff) { + /* |x| < 1.5 */ + + dx = x; + + if (xpt >= 0xe6) { + /* |x| >= 2^(-12) */ + + /* compute sin(x) with a standard polynomial approximation */ + + xsq = dx * dx; + + poly = ((P[4].d * xsq + P[3].d) * xsq + P[2].d) * xsq + P[1].d; + + result = dx + (dx * xsq) * poly; + + return ((float) result); + } + + return (x); + } + + if (xpt < 0x136) { + /* |x| < 2^28 */ + + dx = x; + + /* reduce argument to +/- pi/2 */ + + dn = dx * rpi.d; + + n = ROUND(dn); + dn = n; + + dx = dx - dn * pihi.d; + dx = dx - dn * pilo.d; /* dx = x - n*pi */ + + /* compute sin(dx) as before, negating result if n is odd + */ + + xsq = dx * dx; + + poly = ((P[4].d * xsq + P[3].d) * xsq + P[2].d) * xsq + P[1].d; + + result = dx + (dx * xsq) * poly; + + if ((n & 1) == 0) { + return ((float) result); + } + + return (-(float) result); + } + + if (x != x) { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return (__libm_qnan_f); + } + + /* just give up and return 0.0 */ + + return (zero.f); +} diff --git a/src/libultra/host/readhost.c b/src/libultra/host/readhost.c index 587c60cdf..ed6402d45 100644 --- a/src/libultra/host/readhost.c +++ b/src/libultra/host/readhost.c @@ -1,3 +1,36 @@ -#include "common.h" +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/host/readhost/osReadHost.s") +#include "PR/os_internal.h" +#include "PR/rdb.h" + +#include "macros.h" + +static int readHostInitialized = FALSE; +static OSMesgQueue readHostMesgQueue ALIGNED(8); +static OSMesg readHostMesgBuf[1]; + +u32 __osRdb_Read_Data_Buf; +u32 __osRdb_Read_Data_Ct; + +void osReadHost(void* dramAddr, u32 nbytes) { + char tstr[4]; + u32 sent = 0; + + if (!readHostInitialized) { + osCreateMesgQueue(&readHostMesgQueue, readHostMesgBuf, ARRLEN(readHostMesgBuf)); + osSetEventMesg(OS_EVENT_RDB_READ_DONE, &readHostMesgQueue, NULL); + readHostInitialized = TRUE; + } + + __osRdb_Read_Data_Buf = dramAddr; + __osRdb_Read_Data_Ct = nbytes; + + while (sent == 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_READY_FOR_DATA); + } + + osRecvMesg(&readHostMesgQueue, NULL, OS_MESG_BLOCK); + return; +} + +#endif diff --git a/src/libultra/io/aisetnextbuf.c b/src/libultra/io/aisetnextbuf.c index 94af7437d..cbcb45f87 100644 --- a/src/libultra/io/aisetnextbuf.c +++ b/src/libultra/io/aisetnextbuf.c @@ -1,6 +1,8 @@ -#include "global.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "osint.h" -#ifdef IMPORT_DATA_PENDING s32 osAiSetNextBuffer(void* bufPtr, u32 size) { static u8 hdwrBugFlag = FALSE; char* bptr; @@ -45,6 +47,3 @@ s32 osAiSetNextBuffer(void* bufPtr, u32 size) { IO_WRITE(AI_LEN_REG, size); return 0; } -#else -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/aisetnextbuf/osAiSetNextBuffer.s") -#endif diff --git a/src/libultra/io/cartrominit.c b/src/libultra/io/cartrominit.c index 885b44c94..97de5f8c1 100644 --- a/src/libultra/io/cartrominit.c +++ b/src/libultra/io/cartrominit.c @@ -1,3 +1,99 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_version.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "piint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/cartrominit/osCartRomInit.s") +#if BUILD_VERSION >= VERSION_J +OSPiHandle __CartRomHandle ALIGNED(8); +OSPiHandle* osCartRomInit(void) { + u32 value = 0; + u32 saveMask; + static int first = 1; + register u32 stat; + u32 latency; + u32 pulse; + u32 pageSize; + u32 relDuration; + + __osPiGetAccess(); + + if (!first) { + __osPiRelAccess(); + return &__CartRomHandle; + } + + first = 0; + __CartRomHandle.type = DEVICE_TYPE_CART; + __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + __CartRomHandle.domain = PI_DOMAIN1; + __CartRomHandle.speed = 0; + + bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + WAIT_ON_IOBUSY(stat); + + latency = IO_READ(PI_BSD_DOM1_LAT_REG); + pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + + IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xFF); + IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); + IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); + IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xFF); + + value = IO_READ(__CartRomHandle.baseAddress); + __CartRomHandle.latency = value & 0xFF; + __CartRomHandle.pageSize = (value >> 0x10) & 0xF; + __CartRomHandle.relDuration = (value >> 0x14) & 0xF; + __CartRomHandle.pulse = (value >> 8) & 0xFF; + + IO_WRITE(PI_BSD_DOM1_LAT_REG, latency); + IO_WRITE(PI_BSD_DOM1_PGS_REG, pageSize); + IO_WRITE(PI_BSD_DOM1_RLS_REG, relDuration); + IO_WRITE(PI_BSD_DOM1_PWD_REG, pulse); + + saveMask = __osDisableInt(); + __CartRomHandle.next = __osPiTable; + __osPiTable = &__CartRomHandle; + __osRestoreInt(saveMask); + __osPiRelAccess(); + + return &__CartRomHandle; +} +#else + +OSPiHandle CartRomHandle ALIGNED(8); +OSPiHandle* osCartRomInit(void) { + u32 domain = 0; + u32 saveMask; + + if (CartRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR2)) { + return &CartRomHandle; + } + + CartRomHandle.type = DEVICE_TYPE_CART; + CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + osPiRawReadIo(NULL, &domain); + CartRomHandle.latency = domain & 0xff; + CartRomHandle.pulse = (domain >> 8) & 0xff; + CartRomHandle.pageSize = (domain >> 0x10) & 0xf; + CartRomHandle.relDuration = (domain >> 0x14) & 0xf; + CartRomHandle.domain = PI_DOMAIN1; + +#if BUILD_VERSION > VERSION_I + CartRomHandle.speed = 0; +#endif + + bzero(&CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + CartRomHandle.next = __osPiTable; + __osPiTable = &CartRomHandle; + __osRestoreInt(saveMask); + + return &CartRomHandle; +} +#endif diff --git a/src/libultra/io/conteepprobe.c b/src/libultra/io/conteepprobe.c index a73466f77..24b0c7fea 100644 --- a/src/libultra/io/conteepprobe.c +++ b/src/libultra/io/conteepprobe.c @@ -1,3 +1,19 @@ -#include "common.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepprobe/osEepromProbe.s") +s32 osEepromProbe(OSMesgQueue* mq) { + s32 status = 0; + OSContStatus sdata; + + __osSiGetAccess(); + + status = __osEepStatus(mq, &sdata); + if (status == 0 && (sdata.type & 0x8000) != 0) { + status = 1; + } else { + status = 0; + } + + __osSiRelAccess(); + return status; +} diff --git a/src/libultra/io/conteepread.c b/src/libultra/io/conteepread.c index 745bfea38..113cbba2f 100644 --- a/src/libultra/io/conteepread.c +++ b/src/libultra/io/conteepread.c @@ -1,5 +1,86 @@ -#include "common.h" +#include "macros.h" +#include "PR/rcp.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepread/osEepromRead.s") +OSPifRam __osEepPifRam ALIGNED(16); +#if BUILD_VERSION >= VERSION_L +s32 __osEepromRead16K; +#endif +void __osPackEepReadData(u8 address); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepread/__osPackEepReadData.s") +s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; + int i = 0; + u8* ptr = (u8*) &__osEepPifRam; + OSContStatus sdata; + __OSContEepromFormat eepromformat; + + if (address > 0x40) { + return -1; + } + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + if (ret != 0 || sdata.type != 0x8000) { + return 8; + } + while (sdata.status & 0x80) { + __osEepStatus(mq, &sdata); + } + __osPackEepReadData(address); + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + for (i = 0; i < 0x10; i++) { + __osEepPifRam.ramarray[i] = 0xFF; + } + __osEepPifRam.pifstatus = 0; + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + __osContLastCmd = 4; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + for (i = 0; i < 4; i++) { + ptr++; + } + eepromformat = *(__OSContEepromFormat*) ptr; + ret = CHNL_ERR(eepromformat); + + if (ret == 0) { + for (i = 0; i < 8; i++) { + *buffer++ = eepromformat.data[i]; + } + } + __osSiRelAccess(); + return ret; +} + +void __osPackEepReadData(u8 address) { + u8* ptr = (u8*) &__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + int i; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { + __osEepPifRam.ramarray[i] = CONT_CMD_NOP; + } +#endif + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_READ_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX; + eepromformat.cmd = CONT_CMD_READ_EEPROM; + eepromformat.address = address; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + eepromformat.data[i] = 0; + } +#endif + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat*) (ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} diff --git a/src/libultra/io/conteepwrite.c b/src/libultra/io/conteepwrite.c index 37bc1782c..4698a0216 100644 --- a/src/libultra/io/conteepwrite.c +++ b/src/libultra/io/conteepwrite.c @@ -1,7 +1,142 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepwrite/osEepromWrite.s") +void __osPackEepWriteData(u8 address, u8* buffer); +s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; + int i; + u8* ptr = (u8*) &__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + OSContStatus sdata; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepwrite/__osPackEepWriteData.s") + if (address > 0x40) { + return -1; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/conteepwrite/__osEepStatus.s") + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + + if (ret != 0 || sdata.type != 0x8000) { + return 8; + } + + while (sdata.status & 0x80) { + __osEepStatus(mq, &sdata); + } + + __osPackEepWriteData(address, buffer); + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + for (i = 0; i < 0x10; i++) { + __osEepPifRam.ramarray[i] = 255; + } + + __osEepPifRam.pifstatus = 0; + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + __osContLastCmd = 5; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + for (i = 0; i < 4; i++) { + ptr++; + } + + eepromformat = *(__OSContEepromFormat*) ptr; + ret = CHNL_ERR(eepromformat); + __osSiRelAccess(); + return ret; +} + +void __osPackEepWriteData(u8 address, u8* buffer) { + u8* ptr = (u8*) &__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + int i; + +#if BUILD_VERSION < VERSION_J + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { + __osEepPifRam.ramarray[i] = CONT_CMD_NOP; + } +#endif + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX; + eepromformat.cmd = CONT_CMD_WRITE_EEPROM; + eepromformat.address = address; + + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + eepromformat.data[i] = *buffer++; + } + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat*) (ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} + +s32 __osEepStatus(OSMesgQueue* mq, OSContStatus* data) { + s32 ret = 0; + int i; + u8* ptr = (u8*) __osEepPifRam.ramarray; + __OSContRequesFormat requestformat; + + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { + __osEepPifRam.ramarray[i] = 0; + } + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*) __osEepPifRam.ramarray; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = CONT_CMD_REQUEST_STATUS; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + *(__OSContRequesFormat*) ptr = requestformat; + ptr += sizeof(__OSContRequesFormat); + *ptr = CONT_CMD_END; + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); +#if BUILD_VERSION >= VERSION_J + __osContLastCmd = CONT_CMD_END; +#else + __osContLastCmd = CONT_CMD_WRITE_EEPROM; // seems to be 5 in 2.0H +#endif + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + if (ret != 0) { + return ret; + } + + ptr = (u8*) &__osEepPifRam; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + requestformat = *(__OSContRequesFormat*) ptr; + data->errno = CHNL_ERR(requestformat); + data->type = (requestformat.typel << 8) | requestformat.typeh; + data->status = requestformat.status; + + if (data->errno != 0) { + return data->errno; + } + + return 0; +} diff --git a/src/libultra/io/contquery.c b/src/libultra/io/contquery.c index 17c7569de..32c08e4f6 100644 --- a/src/libultra/io/contquery.c +++ b/src/libultra/io/contquery.c @@ -1,5 +1,25 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contquery/osContStartQuery.s") +s32 osContStartQuery(OSMesgQueue* mq) { + s32 ret = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contquery/osContGetQuery.s") + __osSiGetAccess(); + + if (__osContLastCmd != CONT_CMD_REQUEST_STATUS) { + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + __osContLastCmd = CONT_CMD_REQUEST_STATUS; + __osSiRelAccess(); + return ret; +} + +void osContGetQuery(OSContStatus* data) { + u8 pattern; + __osContGetInitData(&pattern, data); +} diff --git a/src/libultra/io/contramread.c b/src/libultra/io/contramread.c index 267a6372e..401872984 100644 --- a/src/libultra/io/contramread.c +++ b/src/libultra/io/contramread.c @@ -1,5 +1,170 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contramread/__osContRamRead.s") +#define READFORMAT(ptr) ((__OSContRamReadFormat*) (ptr)) -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contramread/__osPackRamReadData.s") +#if BUILD_VERSION >= VERSION_J +s32 __osPfsLastChannel = -1; + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + + __osSiGetAccess(); + + do { + ptr = (u8*) &__osPfsPifRam; + + if (__osContLastCmd != CONT_CMD_READ_PAK || (u32) __osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_READ_PAK; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_READ_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_READ_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_READ_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = (u8) ((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (__osContDataCrc(READFORMAT(ptr)->data) != READFORMAT(ptr)->datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } else { + bcopy(READFORMAT(ptr)->data, buffer, BLOCKSIZE); + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + __osSiRelAccess(); + return ret; +} +#else + +static void __osPackRamReadData(int channel, u16 address); + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + int i; + u8* ptr = (u8*) &__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + int retry = 2; + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_READ_PAK; + __osPackRamReadData(channel, address); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*) &__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + u8 c = __osContDataCrc((u8*) &ramreadformat.data); + if (c != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } else { + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + *buffer++ = ramreadformat.data[i]; + } + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamReadData(int channel, u16 address) { + u8* ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8*) __osPfsPifRam.ramarray; + +#if BUILD_VERSION < VERSION_I + for (i = 0; i < 16; i++) { + __osPfsPifRam.ramarray[i] = 0; + } +#endif + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_READ_PAK_TX; + ramreadformat.rxsize = CONT_CMD_READ_PAK_RX; + ramreadformat.cmd = CONT_CMD_READ_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = CONT_CMD_NOP; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *(__OSContRamReadFormat*) ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif diff --git a/src/libultra/io/contramwrite.c b/src/libultra/io/contramwrite.c index 5993aa645..3f8323cbe 100644 --- a/src/libultra/io/contramwrite.c +++ b/src/libultra/io/contramwrite.c @@ -1,5 +1,176 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contramwrite/__osContRamWrite.s") +extern s32 __osPfsLastChannel; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contramwrite/__osPackRamWriteData.s") +#define READFORMAT(ptr) ((__OSContRamReadFormat*) (ptr)) + +#if BUILD_VERSION >= VERSION_J +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + u8 crc; + + if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + + do { + ptr = (u8*) __osPfsPifRam.ramarray; + + if (__osContLastCmd != CONT_CMD_WRITE_PAK || (u32) __osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_WRITE_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_WRITE_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_WRITE_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = ((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + bcopy(buffer, READFORMAT(ptr)->data, BLOCKSIZE); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + crc = __osContDataCrc(buffer); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (crc != READFORMAT(ptr)->datacrc) { + if ((ret = __osPfsGetStatus(mq, channel))) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + + __osSiRelAccess(); + + return ret; +} +#else + +static void __osPackRamWriteData(int channel, u16 address, u8* buffer); + +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr = (u8*) &__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + s32 retry = 2; + u8 crc; + + if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osPackRamWriteData(channel, address, buffer); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*) &__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + if (__osContDataCrc(buffer) != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamWriteData(int channel, u16 address, u8* buffer) { + u8* ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8*) __osPfsPifRam.ramarray; + +#if BUILD_VERSION < VERSION_I + for (i = 0; i < 16; i++) { + __osPfsPifRam.ramarray[i] = 0; + } +#endif + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = *buffer++; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *(__OSContRamReadFormat*) ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif diff --git a/src/libultra/io/contreaddata.c b/src/libultra/io/contreaddata.c index 304d6be91..f4c1cf67d 100644 --- a/src/libultra/io/contreaddata.c +++ b/src/libultra/io/contreaddata.c @@ -1,7 +1,74 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contreaddata/osContStartReadData.s") +static void __osPackReadData(void); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contreaddata/osContGetReadData.s") +s32 osContStartReadData(OSMesgQueue* mq) { + s32 ret = 0; + s32 i; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/contreaddata/__osPackReadData.s") + __osSiGetAccess(); + + if (__osContLastCmd != CONT_CMD_READ_BUTTON) { + __osPackReadData(); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + + for (i = 0; i <= ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0xFF; + } + __osContPifRam.pifstatus = 0; + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + __osContLastCmd = CONT_CMD_READ_BUTTON; + __osSiRelAccess(); + + return ret; +} + +void osContGetReadData(OSContPad* data) { + u8* ptr = (u8*) __osContPifRam.ramarray; + __OSContReadFormat readformat; + int i; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { + readformat = *(__OSContReadFormat*) ptr; + data->errno = CHNL_ERR(readformat); + + if (data->errno != 0) { + continue; + } + + data->button = readformat.button; + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; + } +} + +static void __osPackReadData(void) { + u8* ptr = (u8*) __osContPifRam.ramarray; + __OSContReadFormat readformat; + int i; + + for (i = 0; i <= ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + readformat.dummy = CONT_CMD_NOP; + readformat.txsize = CONT_CMD_READ_BUTTON_TX; + readformat.rxsize = CONT_CMD_READ_BUTTON_RX; + readformat.cmd = CONT_CMD_READ_BUTTON; + readformat.button = 0xFFFF; + readformat.stick_x = -1; + readformat.stick_y = -1; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContReadFormat*) ptr = readformat; + ptr += sizeof(__OSContReadFormat); + } + + *ptr = CONT_CMD_END; +} diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 33018cfee..5d1e3de3c 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -2,7 +2,15 @@ #include "PR/controller.h" #include "siint.h" -extern s32 __osContinitialized; +OSPifRam __osContPifRam ALIGNED(16); +u8 __osContLastCmd; +u8 __osMaxControllers; + +OSTimer __osEepromTimer; +OSMesgQueue __osEepromTimerQ ALIGNED(8); +OSMesg __osEepromTimerMsg; + +s32 __osContinitialized = 0; #define USEC_TO_CYCLES_OLD(n, clock) ((n) * (u64) (clock) / 1000000) diff --git a/src/libultra/io/crc.c b/src/libultra/io/crc.c index 92c7c1df4..3c22287fc 100644 --- a/src/libultra/io/crc.c +++ b/src/libultra/io/crc.c @@ -1,5 +1,114 @@ -#include "common.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/crc/__osContAddressCrc.s") +#if BUILD_VERSION >= VERSION_J -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/crc/__osContDataCrc.s") +u8 __osContAddressCrc(u16 addr) { + u32 temp = 0; + u32 i = 0x400; + + do { + temp <<= 1; + + if ((u32) addr & i) { + if (temp & 0x20) { + temp ^= 0x14; + } else { + ++temp; + } + } else if (temp & 0x20) { + temp ^= 0x15; + } + + i >>= 1; + } while (i != 0); + + i = 5; + + do { + temp <<= 1; + if (temp & 0x20) { + temp ^= 0x15; + } + } while (--i != 0); + + return temp & 0x1F; +} + +u8 __osContDataCrc(u8* data) { + u32 temp = 0; + u32 i; + u32 j; + + for (i = 0x20; i; --i) { + for (j = 0x80; j; j >>= 1) { + temp <<= 1; + + if ((*data & j) != 0) { + if ((temp & 0x100) != 0) { + temp ^= 0x84; + } else { + ++temp; + } + } else if (temp & 0x100) { + temp ^= 0x85; + } + } + + data++; + } + do { + temp <<= 1; + + if (temp & 0x100) { + temp ^= 0x85; + } + } while (++i < 8U); + + return temp; +} + +#else + +u8 __osContAddressCrc(u16 addr) { + u8 temp = 0; + u8 temp2; + int i; + + for (i = 0; i < 16; i++) { + temp2 = (temp & 0x10) ? 0x15 : 0; + + temp <<= 1; + temp |= (u8) ((addr & 0x400) ? 1 : 0); + addr <<= 1; + temp ^= temp2; + } + + return temp & 0x1f; +} + +u8 __osContDataCrc(u8* data) { + u8 temp = 0; + u8 temp2; + int i; + int j; + + for (i = 0; i <= 32; i++) { + for (j = 7; j > -1; j--) { + temp2 = (temp & 0x80) ? 0x85 : 0; + + temp <<= 1; + + if (i == 32) { + temp &= -1; + } else { + temp |= ((*data & (1 << j)) ? 1 : 0); + } + + temp ^= temp2; + } + data++; + } + return temp; +} + +#endif diff --git a/src/libultra/io/devmgr.c b/src/libultra/io/devmgr.c index 6988e47ac..e9ac09200 100644 --- a/src/libultra/io/devmgr.c +++ b/src/libultra/io/devmgr.c @@ -1,3 +1,108 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "piint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/devmgr/__osDevMgrMain.s") +void __osDevMgrMain(void* args) { + OSIoMesg* mb; + OSMesg em; + OSMesg dummy; + s32 ret; + OSDevMgr* dm; + s32 messageSend = 0; + + dm = (OSDevMgr*) args; + mb = NULL; + ret = 0; + + while (TRUE) { + osRecvMesg(dm->cmdQueue, (OSMesg) &mb, OS_MESG_BLOCK); + + if (mb->piHandle != NULL && mb->piHandle->type == DEVICE_TYPE_64DD && + (mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0 || + mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_1)) { + __OSBlockInfo* blockInfo; + __OSTranxInfo* info; + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + info->sectorNum = -1; + + if (info->transferMode != LEO_SECTOR_MODE) { + blockInfo->dramAddr = (void*) ((u32) blockInfo->dramAddr - blockInfo->sectorSize); + } + + if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) { + messageSend = 1; + } else { + messageSend = 0; + } + + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + __osResetGlobalIntMask(OS_IM_PI); + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000)); + + readblock1: + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + + if (blockInfo->errStatus == LEO_ERROR_29) { + u32 stat; + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow); + __osEPiRawReadIo(mb->piHandle, LEO_STATUS, &stat); + + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + } + + blockInfo->errStatus = LEO_ERROR_4; + IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); + __osSetGlobalIntMask(OS_IM_PI | SR_IBIT4); + } + + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + + if (messageSend == 1 && mb->piHandle->transferInfo.block[0].errStatus == LEO_ERROR_GOOD) { + messageSend = 0; + goto readblock1; + } + + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + if (mb->piHandle->transferInfo.blockNum == 1) { + osYieldThread(); + } + } else { + switch (mb->hdr.type) { + case OS_MESG_TYPE_DMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_DMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_EDMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_EDMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_LOOPBACK: + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + ret = -1; + break; + default: + ret = -1; + break; + } + + if (ret == 0) { + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + } + } + } +} diff --git a/src/libultra/io/dpsetstat.c b/src/libultra/io/dpsetstat.c index 4d53053af..5b538670a 100644 --- a/src/libultra/io/dpsetstat.c +++ b/src/libultra/io/dpsetstat.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/dpsetstat/osDpSetStatus.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osDpSetStatus(u32 data) { + IO_WRITE(DPC_STATUS_REG, data); +} diff --git a/src/libultra/io/epidma.c b/src/libultra/io/epidma.c index 1058167e1..efc24343c 100644 --- a/src/libultra/io/epidma.c +++ b/src/libultra/io/epidma.c @@ -1,3 +1,61 @@ -#include "common.h" +#include "piint.h" +#include "PR/ultraerror.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/epidma/osEPiStartDma.s") +s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { + register s32 ret; + + if (!__osPiDevMgr.active) { +#ifdef _DEBUG + __osError(ERR_OSPISTARTDMA_PIMGR, 0); +#endif + return -1; + } + +#ifdef _DEBUG + if ((mb->hdr.pri != OS_MESG_PRI_NORMAL) && (mb->hdr.pri != OS_MESG_PRI_HIGH)) { + __osError(ERR_OSPISTARTDMA_PRI, 1, mb->hdr.pri); + return -1; + } + + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPISTARTDMA_DIR, 1, direction); + return -1; + } + + if (mb->devAddr & 0x1) { + __osError(ERR_OSPISTARTDMA_DEVADDR, 1, mb->devAddr); + return -1; + } + + if ((u32) mb->dramAddr & 0x7) { + __osError(ERR_OSPISTARTDMA_ADDR, 1, mb->dramAddr); + return -1; + } + + if (mb->size & 0x1) { + __osError(ERR_OSPISTARTDMA_SIZE, 1, mb->size); + return -1; + } + + if ((mb->size == 0) || (mb->size > (16 * 1024 * 1024))) { + __osError(ERR_OSPISTARTDMA_RANGE, 1, mb->size); + return -1; + } +#endif + + mb->piHandle = pihandle; + + if (direction == OS_READ) { + mb->hdr.type = OS_MESG_TYPE_EDMAREAD; + } else { + mb->hdr.type = OS_MESG_TYPE_EDMAWRITE; + } + + if (mb->hdr.pri == OS_MESG_PRI_HIGH) { + ret = osJamMesg(osPiGetCmdQueue(), (OSMesg) mb, OS_MESG_NOBLOCK); + } else { + ret = osSendMesg(osPiGetCmdQueue(), (OSMesg) mb, OS_MESG_NOBLOCK); + } + + return ret; +} diff --git a/src/libultra/io/epirawdma.c b/src/libultra/io/epirawdma.c index 85eb9e776..c72673a16 100644 --- a/src/libultra/io/epirawdma.c +++ b/src/libultra/io/epirawdma.c @@ -1,3 +1,53 @@ -#include "common.h" +#include "piint.h" +#include "PR/ultraerror.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/epirawdma/osEPiRawStartDma.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawStartDma(OSPiHandle* pihandle, s32 direction, u32 devAddr, void* dramAddr, u32 size) { + u32 stat; + u32 domain; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32) dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + EPI_SYNC(pihandle, stat, domain); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | devAddr)); + + switch (direction) { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/src/libultra/io/epirawread.c b/src/libultra/io/epirawread.c index 610fdeb30..c7995a7cf 100644 --- a/src/libultra/io/epirawread.c +++ b/src/libultra/io/epirawread.c @@ -1,3 +1,29 @@ -#include "common.h" +#include "piint.h" +#include "PR/ultraerror.h" +#include "PR/assert.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/epirawread/osEPiRawReadIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 28 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { + register u32 stat; + register u32 domain; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWREADIO, 1, devAddr); + return -1; + } +#endif + assert(data != NULL); + + WAIT_ON_IOBUSY(stat); + *data = IO_READ(pihandle->baseAddress | devAddr); + + return 0; +} diff --git a/src/libultra/io/epirawwrite.c b/src/libultra/io/epirawwrite.c index e99d01ffd..29db079d0 100644 --- a/src/libultra/io/epirawwrite.c +++ b/src/libultra/io/epirawwrite.c @@ -1,3 +1,22 @@ -#include "common.h" +#include "piint.h" +#include "PR/ultraerror.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/epirawwrite/osEPiRawWriteIo.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { + register u32 stat; + register u32 domain; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + IO_WRITE(pihandle->baseAddress | devAddr, data); + + return 0; +} diff --git a/src/libultra/io/leodiskinit.c b/src/libultra/io/leodiskinit.c index 3c512b756..e5825868d 100644 --- a/src/libultra/io/leodiskinit.c +++ b/src/libultra/io/leodiskinit.c @@ -1,3 +1,38 @@ -#include "common.h" +// This file was removed in 2.0J +#include "PR/os_internal.h" +#include "PR/os_libc.h" +#include "PR/rcp.h" +#include "macros.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/leodiskinit/osLeoDiskInit.s") +OSPiHandle LeoDiskHandle ALIGNED(8); +OSPiHandle* __osDiskHandle; + +OSPiHandle* osLeoDiskInit() { + u32 saveMask; + + LeoDiskHandle.type = DEVICE_TYPE_64DD; + LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1); + LeoDiskHandle.latency = 3; + LeoDiskHandle.pulse = 6; + LeoDiskHandle.pageSize = 6; + LeoDiskHandle.relDuration = 2; + LeoDiskHandle.domain = PI_DOMAIN2; + + IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency); + IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse); + IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize); + IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration); +#if BUILD_VERSION >= VERSION_I + LeoDiskHandle.speed = 0; +#endif + + bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + LeoDiskHandle.next = __osPiTable; + __osPiTable = &LeoDiskHandle; + __osDiskHandle = &LeoDiskHandle; + __osRestoreInt(saveMask); + + return &LeoDiskHandle; +} diff --git a/src/libultra/io/leointerrupt.c b/src/libultra/io/leointerrupt.c index e4dc1269e..58ee2a6f0 100644 --- a/src/libultra/io/leointerrupt.c +++ b/src/libultra/io/leointerrupt.c @@ -1,7 +1,195 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "osint.h" +#include "piint.h" +#include "macros.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/leointerrupt/__osLeoInterrupt.s") +extern OSPiHandle* __osDiskHandle; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/leointerrupt/__osLeoAbnormalResume.s") +u8 leoDiskStack[OS_PIM_STACKSIZE] ALIGNED(16); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/leointerrupt/__osLeoResume.s") +static void __osLeoAbnormalResume(void); +static void __osLeoResume(void); + +s32 __osLeoInterrupt() { + u32 stat = 0; + volatile u32 pi_stat; + u32 bm_stat; + __OSTranxInfo* info = &__osDiskHandle->transferInfo; + __OSBlockInfo* blockInfo = &info->block[info->blockNum]; + + pi_stat = IO_READ(PI_STATUS_REG); + if (pi_stat & PI_STATUS_DMA_BUSY) { + __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; // cart interrupt + blockInfo->errStatus = LEO_ERROR_29; + __osLeoResume(); + return 1; + } + + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 0; + } + + if (info->cmdType == LEO_CMD_TYPE_2) { + return 1; + } + + if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + blockInfo->errStatus = LEO_ERROR_22; + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + return 1; + } + + if (info->cmdType == LEO_CMD_TYPE_1) { + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + if (info->sectorNum + 1 != info->transferMode * 85) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoResume(); + return 1; + } else { + blockInfo->dramAddr = (void*) ((u32) blockInfo->dramAddr + blockInfo->sectorSize); + info->sectorNum++; + osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + return 1; + } + } else if (info->cmdType == LEO_CMD_TYPE_0) { + if (info->transferMode == LEO_SECTOR_MODE) { + if (info->sectorNum > (s32) blockInfo->C1ErrNum + 17) { + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoAbnormalResume(); + return 1; + } + + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + blockInfo->dramAddr = (void*) ((u32) blockInfo->dramAddr + blockInfo->sectorSize); + } + + bm_stat = IO_READ(LEO_BM_STATUS); + if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { + if (blockInfo->C1ErrNum > 3) { + if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + int errNum = blockInfo->C1ErrNum; + blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; + } + + blockInfo->C1ErrNum++; + } + + if (stat & LEO_STATUS_C2_TRANSFER) { + if (info->sectorNum + 1 != 88) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + } + + if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { + info->blockNum = 1; + info->sectorNum = -1; + info->block[1].dramAddr = (void*) ((u32) info->block[1].dramAddr - info->block[1].sectorSize); + + blockInfo->errStatus = LEO_ERROR_22; + } else { + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + info->cmdType = LEO_CMD_TYPE_2; + blockInfo->errStatus = LEO_ERROR_GOOD; + } + + osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); + return 1; + } + + if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { + __OSBlockInfo* bptr = &info->block[0]; + if (bptr->C1ErrNum == 0) { + if (((u32*) bptr->C2Addr)[0] | ((u32*) bptr->C2Addr)[1] | ((u32*) bptr->C2Addr)[2] | + ((u32*) bptr->C2Addr)[3]) { + bptr->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + } + + bptr->errStatus = 0; + __osLeoResume(); + } + info->sectorNum++; + if (stat & LEO_STATUS_DATA_REQUEST) { + if (info->sectorNum > 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 1; + } else if (info->sectorNum <= 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + return 1; + } else { + blockInfo->errStatus = LEO_ERROR_4; + __osLeoAbnormalResume(); + return 1; + } +} + +static void __osLeoAbnormalResume(void) { + __OSTranxInfo* info = &__osDiskHandle->transferInfo; + u32 pi_stat; + + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; +} + +static void __osLeoResume(void) { + __OSEventState* es = &__osEventStateTab[OS_EVENT_PI]; + OSMesgQueue* mq = es->messageQueue; + s32 last; + + if (mq == NULL || MQ_IS_FULL(mq)) { + return; + } + + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = es->message; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue)); + } +} diff --git a/src/libultra/io/motor.c b/src/libultra/io/motor.c index dd583ac12..1cfe125fd 100644 --- a/src/libultra/io/motor.c +++ b/src/libultra/io/motor.c @@ -1,10 +1,10 @@ #include "global.h" #include "siint.h" -extern OSPifRam _MotorStopData[MAXCONTROLLERS]; -extern OSPifRam _MotorStartData[MAXCONTROLLERS]; -extern u8 _motorstopbuf[0x20]; -extern u8 _motorstartbuf[0x20]; +OSPifRam _MotorStopData[MAXCONTROLLERS] ALIGNED(8); +OSPifRam _MotorStartData[MAXCONTROLLERS] ALIGNED(8); +u8 _motorstopbuf[32] ALIGNED(8); +u8 _motorstartbuf[32] ALIGNED(8); s32 osMotorStop(OSPfs* pfs) { s32 i; diff --git a/src/libultra/io/pfsgetstatus.c b/src/libultra/io/pfsgetstatus.c index 49c254584..8c8ab37d8 100644 --- a/src/libultra/io/pfsgetstatus.c +++ b/src/libultra/io/pfsgetstatus.c @@ -1,3 +1,28 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pfsgetstatus/__osPfsGetStatus.s") +s32 __osPfsGetStatus(OSMesgQueue* queue, int channel) { + s32 ret = 0; + OSMesg dummy; + u8 pattern; + OSContStatus status[4]; + + __osPfsRequestData(0); + ret = __osSiRawStartDma(1, &__osPfsPifRam); + osRecvMesg(queue, &dummy, 1); + ret = __osSiRawStartDma(0, &__osPfsPifRam); + osRecvMesg(queue, &dummy, 1); + __osPfsGetInitData(&pattern, status); + + if (status[channel].status & CONT_CARD_ON && status[channel].status & CONT_CARD_PULL) { + return 2; + } + if (status[channel].errno || !(status[channel].status & CONT_CARD_ON)) { + return 1; + } + if (status[channel].status & CONT_ADDR_CRC_ER) { + return 4; + } + return ret; +} diff --git a/src/libultra/io/pfsisplug.c b/src/libultra/io/pfsisplug.c index 4aa4382e5..d4b962d31 100644 --- a/src/libultra/io/pfsisplug.c +++ b/src/libultra/io/pfsisplug.c @@ -1,7 +1,105 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/controller.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pfsisplug/osPfsIsPlug.s") +OSPifRam __osPfsPifRam ALIGNED(16); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pfsisplug/__osPfsRequestData.s") +s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { + s32 ret = 0; + OSMesg msg; + u8 bitpattern; + OSContStatus contData[MAXCONTROLLERS]; + s32 channel; + u8 bits = 0; + s32 crcErrorCount = 3; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pfsisplug/__osPfsGetInitData.s") + __osSiGetAccess(); + + do { + __osPfsRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + __osPfsGetInitData(&bitpattern, &contData[0]); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].status & CONT_ADDR_CRC_ER) == 0) { + crcErrorCount--; + break; + } + } + + if (channel == __osMaxControllers) { + crcErrorCount = 0; + } + } while (crcErrorCount > 0); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].errno == 0) && ((contData[channel].status & CONT_CARD_ON) != 0)) { + bits |= (1 << channel); + } + } + __osSiRelAccess(); + *pattern = bits; + return ret; +} + +void __osPfsRequestData(u8 cmd) { + u8* ptr; + __OSContRequesFormat requestformat; + int i; + + __osContLastCmd = cmd; + +#if BUILD_VERSION < VERSION_I + for (i = 0; i < 16; i++) { + __osPfsPifRam.ramarray[i] = 0; + } + __osPfsPifRam.pifstatus = CONT_CMD_EXE; +#endif + + ptr = (u8*) &__osPfsPifRam; + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = cmd; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + + for (i = 0; i < __osMaxControllers; i++) { + *((__OSContRequesFormat*) ptr) = requestformat; + ptr += sizeof(__OSContRequesFormat); + } + + *ptr = CONT_CMD_END; +} + +void __osPfsGetInitData(u8* pattern, OSContStatus* data) { + u8* ptr; + __OSContRequesFormat requestformat; + int i; + u8 bits = 0; + + ptr = (u8*) &__osPfsPifRam; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestformat), data++) { + requestformat = *((__OSContRequesFormat*) ptr); + data->errno = CHNL_ERR(requestformat); + + if (data->errno != 0) { + continue; + } + + data->type = ((requestformat.typel << 8) | requestformat.typeh); + data->status = requestformat.status; + bits |= (1 << i); + } + *pattern = bits; +} diff --git a/src/libultra/io/piacs.c b/src/libultra/io/piacs.c index d84ad887e..4cd1bb5bf 100644 --- a/src/libultra/io/piacs.c +++ b/src/libultra/io/piacs.c @@ -1,7 +1,25 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/piacs/__osPiCreateAccessQueue.s") +#define PI_Q_BUF_LEN 1 +u32 __osPiAccessQueueEnabled = 0; +OSMesg piAccessBuf[PI_Q_BUF_LEN]; +OSMesgQueue __osPiAccessQueue ALIGNED(8); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/piacs/__osPiGetAccess.s") +void __osPiCreateAccessQueue(void) { + __osPiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/piacs/__osPiRelAccess.s") +void __osPiGetAccess(void) { + OSMesg dummyMesg; + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osPiRelAccess(void) { + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/src/libultra/io/pigetcmdq.c b/src/libultra/io/pigetcmdq.c index 6992ece93..4724301d0 100644 --- a/src/libultra/io/pigetcmdq.c +++ b/src/libultra/io/pigetcmdq.c @@ -1,3 +1,10 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "piint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pigetcmdq/osPiGetCmdQueue.s") +OSMesgQueue* osPiGetCmdQueue(void) { + if (!__osPiDevMgr.active) { + return NULL; + } else { + return __osPiDevMgr.cmdQueue; + } +} diff --git a/src/libultra/io/pimgr.c b/src/libultra/io/pimgr.c index b6933237b..83221f880 100644 --- a/src/libultra/io/pimgr.c +++ b/src/libultra/io/pimgr.c @@ -2,16 +2,33 @@ #include "piint.h" #include "PR/rdb.h" -void ramromMain(void* arg); -extern OSMesg piEventBuf[]; -extern OSMesgQueue piEventQueue; -extern OSThread piThread; -extern char piThreadStack[]; -extern OSThread ramromThread; -extern char ramromThreadStack[]; - -#ifdef IMPORT_DATA_PENDING +OSThread piThread ALIGNED(8); +char piThreadStack[OS_PIM_STACKSIZE] ALIGNED(16); + +#ifndef _FINALROM +static OSThread ramromThread ALIGNED(8); +static char ramromThreadStack[1024] ALIGNED(16); +static OSMesgQueue getRamromQ ALIGNED(8); +static OSMesg getRamromBuf[1]; +static OSMesgQueue freeRamromQ ALIGNED(8); +static OSMesg freeRamromBuf[1]; +static void ramromMain(void*); +#endif + +OSMesgQueue piEventQueue ALIGNED(8); +OSMesg piEventBuf[1]; + OSDevMgr __osPiDevMgr = { 0 }; +OSPiHandle* __osPiTable = NULL; +#if BUILD_VERSION >= VERSION_J +OSPiHandle __Dom1SpeedParam ALIGNED(8); +OSPiHandle __Dom2SpeedParam ALIGNED(8); +OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &__Dom1SpeedParam, &__Dom2SpeedParam }; +#else +extern OSPiHandle CartRomHandle; +extern OSPiHandle LeoDiskHandle; +OSPiHandle* __osCurrentHandle[2] ALIGNED(8) = { &CartRomHandle, &LeoDiskHandle }; +#endif void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { u32 savedMask; @@ -56,9 +73,6 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC osSetThreadPri(NULL, oldPri); } } -#else -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pimgr/osCreatePiManager.s") -#endif extern OSMesg freeRamromBuf[]; extern OSMesgQueue freeRamromQ; diff --git a/src/libultra/io/pirawdma.c b/src/libultra/io/pirawdma.c index 9b3d8c5c4..16887dab3 100644 --- a/src/libultra/io/pirawdma.c +++ b/src/libultra/io/pirawdma.c @@ -1,3 +1,53 @@ -#include "common.h" +#include "piint.h" +#include "PR/ultraerror.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pirawdma/osPiRawStartDma.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + register u32 stat; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32) dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((u32) osRomBase | devAddr)); + + switch (direction) { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/src/libultra/io/pirawread.c b/src/libultra/io/pirawread.c index 2d3c07b9d..98f3b9d51 100644 --- a/src/libultra/io/pirawread.c +++ b/src/libultra/io/pirawread.c @@ -1,3 +1,29 @@ -#include "global.h" +#include "PR/assert.h" +#include "PR/ultraerror.h" +#include "piint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/pirawread/osPiRawReadIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 46 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawReadIo(u32 devAddr, u32* data) { + register u32 stat; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWREADIO, 1, devAddr); + return -1; + } +#endif + + assert(data != NULL); + + WAIT_ON_IOBUSY(stat); + *data = IO_READ((u32) osRomBase | devAddr); + + return 0; +} diff --git a/src/libultra/io/si.c b/src/libultra/io/si.c index 4de8eb317..0188927e3 100644 --- a/src/libultra/io/si.c +++ b/src/libultra/io/si.c @@ -1,3 +1,15 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/si/__osSiDeviceBusy.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSiDeviceBusy() { + register u32 stat = IO_READ(SI_STATUS_REG); + + if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/src/libultra/io/siacs.c b/src/libultra/io/siacs.c index bf8233d0f..e2ce38eac 100644 --- a/src/libultra/io/siacs.c +++ b/src/libultra/io/siacs.c @@ -1,7 +1,25 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/siacs/__osSiCreateAccessQueue.s") +#define SI_Q_BUF_LEN 1 +OSMesg siAccessBuf[SI_Q_BUF_LEN] ALIGNED(8); +OSMesgQueue __osSiAccessQueue ALIGNED(8); +u32 __osSiAccessQueueEnabled = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/siacs/__osSiGetAccess.s") +void __osSiCreateAccessQueue(void) { + __osSiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/siacs/__osSiRelAccess.s") +void __osSiGetAccess(void) { + OSMesg dummyMesg; + if (!__osSiAccessQueueEnabled) { + __osSiCreateAccessQueue(); + } + osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osSiRelAccess(void) { + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/src/libultra/io/sirawdma.c b/src/libultra/io/sirawdma.c index 40ad403aa..68517b8d9 100644 --- a/src/libultra/io/sirawdma.c +++ b/src/libultra/io/sirawdma.c @@ -1,3 +1,43 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/assert.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sirawdma/__osSiRawStartDma.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 49 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawStartDma(s32 direction, void* dramAddr) { + assert(((u32) dramAddr & 0x3) == 0); + +#if BUILD_VERSION >= VERSION_J + if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return -1; + } +#else + if (__osSiDeviceBusy()) { + return -1; + } +#endif + + if (direction == OS_WRITE) { + osWritebackDCache(dramAddr, 64); + } + + IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SI_PIF_ADDR_RD64B_REG, PIF_RAM_START); + } else { + IO_WRITE(SI_PIF_ADDR_WR64B_REG, PIF_RAM_START); + } + + if (direction == OS_READ) { + osInvalDCache(dramAddr, 64); + } + + return 0; +} diff --git a/src/libultra/io/sirawread.c b/src/libultra/io/sirawread.c index a4d378555..b8d769f1c 100644 --- a/src/libultra/io/sirawread.c +++ b/src/libultra/io/sirawread.c @@ -1,3 +1,23 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/assert.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sirawread/__osSiRawReadIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawReadIo(u32 devAddr, u32* data) { + assert((devAddr & 0x3) == 0); + assert(data != NULL); + + if (__osSiDeviceBusy()) { + return -1; + } + + *data = IO_READ(devAddr); + return 0; +} diff --git a/src/libultra/io/sirawwrite.c b/src/libultra/io/sirawwrite.c index c00aaa0ec..40573b58a 100644 --- a/src/libultra/io/sirawwrite.c +++ b/src/libultra/io/sirawwrite.c @@ -1,3 +1,22 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/assert.h" +#include "siint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sirawwrite/__osSiRawWriteIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 46 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawWriteIo(u32 devAddr, u32 data) { + assert((devAddr & 0x3) == 0); + + if (__osSiDeviceBusy()) { + return -1; + } + + IO_WRITE(devAddr, data); + return 0; +} diff --git a/src/libultra/io/sp.c b/src/libultra/io/sp.c index fb6102a0d..46a638490 100644 --- a/src/libultra/io/sp.c +++ b/src/libultra/io/sp.c @@ -1,3 +1,17 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sp/__osSpDeviceBusy.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSpDeviceBusy() { + register u32 stat = IO_READ(SP_STATUS_REG); + + if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/src/libultra/io/spgetstat.c b/src/libultra/io/spgetstat.c index 12d3d4a16..0cdfda699 100644 --- a/src/libultra/io/spgetstat.c +++ b/src/libultra/io/spgetstat.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/spgetstat/__osSpGetStatus.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 __osSpGetStatus() { + return IO_READ(SP_STATUS_REG); +} diff --git a/src/libultra/io/sprawdma.c b/src/libultra/io/sprawdma.c index ab30cddcd..86a826f21 100644 --- a/src/libultra/io/sprawdma.c +++ b/src/libultra/io/sprawdma.c @@ -1,3 +1,33 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/assert.h" +#include "PR/rcp.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sprawdma/__osSpRawStartDma.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 52 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + assert(((u32) devAddr & 0x7) == 0); + assert(((u32) dramAddr & 0x7) == 0); + assert(((u32) size & 0x7) == 0); + + if (__osSpDeviceBusy()) { + return -1; + } + + IO_WRITE(SP_MEM_ADDR_REG, devAddr); + IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SP_WR_LEN_REG, size - 1); + } else { + IO_WRITE(SP_RD_LEN_REG, size - 1); + } + + return 0; +} diff --git a/src/libultra/io/sprawread.c b/src/libultra/io/sprawread.c index f63c3cb2f..710ec885a 100644 --- a/src/libultra/io/sprawread.c +++ b/src/libultra/io/sprawread.c @@ -1,3 +1,24 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/assert.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sprawread/__osSpRawReadIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawReadIo(u32 devAddr, u32* data) { + assert((devAddr & 0x3) == 0); + assert(data != NULL); + + if (__osSpDeviceBusy()) { + return -1; + } + + *data = IO_READ(devAddr); + return 0; +} diff --git a/src/libultra/io/sprawwrite.c b/src/libultra/io/sprawwrite.c index 358497a13..1b121dfcb 100644 --- a/src/libultra/io/sprawwrite.c +++ b/src/libultra/io/sprawwrite.c @@ -1,3 +1,23 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/assert.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sprawwrite/__osSpRawWriteIo.s") +// Adjust line numbers to match assert +#if BUILD_VERSION < VERSION_J +#line 45 +#endif + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawWriteIo(u32 devAddr, u32 data) { + assert((devAddr & 0x3) == 0); + + if (__osSpDeviceBusy()) { + return -1; + } + + IO_WRITE(devAddr, data); + return 0; +} diff --git a/src/libultra/io/spsetpc.c b/src/libultra/io/spsetpc.c index 5a1ab22a6..dce0b5d24 100644 --- a/src/libultra/io/spsetpc.c +++ b/src/libultra/io/spsetpc.c @@ -1,3 +1,15 @@ -#include "common.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/spsetpc/__osSpSetPc.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpSetPc(u32 pc) { + register u32 status = IO_READ(SP_STATUS_REG); + + if (!(status & SP_STATUS_HALT)) { + return -1; + } + IO_WRITE(SP_PC_REG, pc); + + return 0; +} diff --git a/src/libultra/io/spsetstat.c b/src/libultra/io/spsetstat.c index a50f8d738..2ab47e080 100644 --- a/src/libultra/io/spsetstat.c +++ b/src/libultra/io/spsetstat.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/spsetstat/__osSpSetStatus.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osSpSetStatus(u32 data) { + IO_WRITE(SP_STATUS_REG, data); +} diff --git a/src/libultra/io/sptask.c b/src/libultra/io/sptask.c index 8170f9fa3..405bbd9c8 100644 --- a/src/libultra/io/sptask.c +++ b/src/libultra/io/sptask.c @@ -1,7 +1,82 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/sptask.h" +#include "PR/rcp.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sptask/_VirtualToPhysicalTask.s") +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.4 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sptask/osSpTaskLoad.s") +#define _osVirtualToPhysical(ptr) \ + if (ptr != NULL) { \ + ptr = (void*) osVirtualToPhysical(ptr); \ + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sptask/osSpTaskStartGo.s") +static OSTask tmp_task; + +static OSTask* _VirtualToPhysicalTask(OSTask* intp) { + OSTask* tp; + tp = &tmp_task; + bcopy(intp, tp, sizeof(OSTask)); + + _osVirtualToPhysical(tp->t.ucode); + _osVirtualToPhysical(tp->t.ucode_data); + _osVirtualToPhysical(tp->t.dram_stack); + _osVirtualToPhysical(tp->t.output_buff); + _osVirtualToPhysical(tp->t.output_buff_size); + _osVirtualToPhysical(tp->t.data_ptr); + _osVirtualToPhysical(tp->t.yield_data_ptr); + return tp; +} + +void osSpTaskLoad(OSTask* intp) { + OSTask* tp; + +#ifdef _DEBUG + if ((intp->t.dram_stack != 0x0) && ((u32) intp->t.dram_stack & 0xf)) { + __osError(ERR_OSSPTASKLOAD_DRAM, 1, intp->t.dram_stack); + return; + } + if ((intp->t.output_buff != 0x0) && ((u32) intp->t.output_buff & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUT, 1, intp->t.output_buff); + return; + } + if ((intp->t.output_buff_size != 0x0) && ((u32) intp->t.output_buff_size & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUTSIZE, 1, intp->t.output_buff_size); + return; + } + if ((intp->t.yield_data_ptr != 0x0) && ((u32) intp->t.yield_data_ptr & 0xf)) { + __osError(ERR_OSSPTASKLOAD_YIELD, 1, intp->t.yield_data_ptr); + return; + } +#endif + + tp = _VirtualToPhysicalTask(intp); + + if (tp->t.flags & OS_TASK_YIELDED) { + tp->t.ucode_data = tp->t.yield_data_ptr; + tp->t.ucode_data_size = tp->t.yield_data_size; + intp->t.flags &= ~OS_TASK_YIELDED; + if (tp->t.flags & OS_TASK_LOADABLE) { + tp->t.ucode = (u64*) IO_READ((u32) intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4); + } + } + + osWritebackDCache(tp, sizeof(OSTask)); + __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); + + while (__osSpSetPc(SP_IMEM_START) == -1) {} + + while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} + + while (__osSpDeviceBusy()) {} + + while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) {} +} + +void osSpTaskStartGo(OSTask* tp) { + while (__osSpDeviceBusy()) {} + + __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); +} diff --git a/src/libultra/io/sptaskyield.c b/src/libultra/io/sptaskyield.c index f7b2f4c7a..78bacaee3 100644 --- a/src/libultra/io/sptaskyield.c +++ b/src/libultra/io/sptaskyield.c @@ -1,3 +1,6 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sptaskyield/osSpTaskYield.s") +void osSpTaskYield(void) { + __osSpSetStatus(SP_SET_YIELD); +} diff --git a/src/libultra/io/sptaskyielded.c b/src/libultra/io/sptaskyielded.c index 2deb9eb3f..3ecab5569 100644 --- a/src/libultra/io/sptaskyielded.c +++ b/src/libultra/io/sptaskyielded.c @@ -1,3 +1,18 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "PR/rcp.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/sptaskyielded/osSpTaskYielded.s") +OSYieldResult osSpTaskYielded(OSTask* tp) { + u32 status; + OSYieldResult result; + + status = __osSpGetStatus(); + result = (status & SP_STATUS_YIELDED) ? OS_TASK_YIELDED : 0; + + if (status & SP_STATUS_YIELD) { + tp->t.flags |= result; + tp->t.flags &= ~(OS_TASK_DP_WAIT); + } + + return result; +} diff --git a/src/libultra/io/vi.c b/src/libultra/io/vi.c index 34d4e1e51..969fae6c6 100644 --- a/src/libultra/io/vi.c +++ b/src/libultra/io/vi.c @@ -1,3 +1,39 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/vi/__osViInit.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +static __OSViContext vi[2] ALIGNED(8) = { 0 }; +__OSViContext* __osViCurr = &vi[0]; +__OSViContext* __osViNext = &vi[1]; + +void __osViInit(void) { + bzero(vi, sizeof(vi)); + __osViCurr = &vi[0]; + __osViNext = &vi[1]; + __osViNext->retraceCount = 1; + __osViCurr->retraceCount = 1; + __osViNext->framep = (void*) K0BASE; + __osViCurr->framep = (void*) K0BASE; + + if (osTvType == OS_TV_TYPE_PAL) { + __osViNext->modep = &osViModePalLan1; + } else if (osTvType == OS_TV_TYPE_MPAL) { + __osViNext->modep = &osViModeMpalLan1; + } else { + __osViNext->modep = &osViModeNtscLan1; + } + + __osViNext->state = VI_STATE_BLACK; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + + while (IO_READ(VI_CURRENT_REG) > 10) { // wait for vsync? + } + + IO_WRITE(VI_CONTROL_REG, 0); // pixel size blank (no data, no sync) + __osViSwapContext(); +} diff --git a/src/libultra/io/viblack.c b/src/libultra/io/viblack.c index 545e4d778..3a822bb1f 100644 --- a/src/libultra/io/viblack.c +++ b/src/libultra/io/viblack.c @@ -1,3 +1,17 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/viblack/osViBlack.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViBlack(u8 active) { + register u32 saveMask = __osDisableInt(); + + if (active) { + __osViNext->state |= VI_STATE_BLACK; + } else { + __osViNext->state &= ~VI_STATE_BLACK; + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/vigetcurrcontext.c b/src/libultra/io/vigetcurrcontext.c index e44696920..f96da33b8 100644 --- a/src/libultra/io/vigetcurrcontext.c +++ b/src/libultra/io/vigetcurrcontext.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/vigetcurrcontext/__osViGetCurrentContext.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +__OSViContext* __osViGetCurrentContext(void) { + return __osViCurr; +} diff --git a/src/libultra/io/vimgr.c b/src/libultra/io/vimgr.c index e64d024da..c2b5d03e3 100644 --- a/src/libultra/io/vimgr.c +++ b/src/libultra/io/vimgr.c @@ -1,5 +1,126 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PR/viint.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/vimgr/osCreateViManager.s") +OSDevMgr __osViDevMgr = { 0 }; +#if BUILD_VERSION >= VERSION_J +u32 __additional_scanline = 0; +#endif +static OSThread viThread; +static unsigned char viThreadStack[OS_VIM_STACKSIZE] ALIGNED(16); +static OSMesgQueue viEventQueue ALIGNED(8); +static OSMesg viEventBuf[5] ALIGNED(8); +static OSIoMesg viRetraceMsg ALIGNED(8); +static OSIoMesg viCounterMsg ALIGNED(8); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/vimgr/viMgrMain.s") +static void viMgrMain(void* arg); +void osCreateViManager(OSPri pri) { + u32 savedMask; + OSPri oldPri; + OSPri myPri; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATEVIMANAGER, 1, pri); + return; + } +#endif + + if (__osViDevMgr.active) { + return; + } + __osTimerServicesInit(); +#if BUILD_VERSION >= VERSION_J + __additional_scanline = 0; +#endif + osCreateMesgQueue(&viEventQueue, viEventBuf, ARRLEN(viEventBuf)); + viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE; + viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viRetraceMsg.hdr.retQueue = NULL; + viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER; + viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viCounterMsg.hdr.retQueue = NULL; + osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg); + osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg); + oldPri = -1; + myPri = osGetThreadPri(NULL); + + if (myPri < pri) { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + + savedMask = __osDisableInt(); + __osViDevMgr.active = TRUE; + __osViDevMgr.thread = &viThread; + __osViDevMgr.cmdQueue = &viEventQueue; + __osViDevMgr.evtQueue = &viEventQueue; + __osViDevMgr.acsQueue = NULL; + __osViDevMgr.dma = NULL; + __osViDevMgr.edma = NULL; + osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); + __osViInit(); + osStartThread(&viThread); + __osRestoreInt(savedMask); + + if (oldPri != -1) { + osSetThreadPri(NULL, oldPri); + } +} + +static void viMgrMain(void* arg) { + __OSViContext* vc; + OSDevMgr* dm; + OSIoMesg* mb; + static u16 retrace; + s32 first; + u32 count; + + mb = NULL; + first = 0; + vc = __osViGetCurrentContext(); + retrace = vc->retraceCount; + if (retrace == 0) { + retrace = 1; + } + dm = (OSDevMgr*) arg; + + while (TRUE) { + osRecvMesg(dm->evtQueue, (OSMesg) &mb, OS_MESG_BLOCK); + switch (mb->hdr.type) { + case OS_MESG_TYPE_VRETRACE: + __osViSwapContext(); + retrace--; + + if (retrace == 0) { + vc = __osViGetCurrentContext(); + if (vc->msgq != NULL) { + osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK); + } + retrace = vc->retraceCount; + } + + __osViIntrCount++; + + if (first) { + count = osGetCount(); + __osCurrentTime = count; + first = 0; + } + + count = __osBaseCounter; + __osBaseCounter = osGetCount(); + count = __osBaseCounter - count; + __osCurrentTime = __osCurrentTime + count; + break; + case OS_MESG_TYPE_COUNTER: + __osTimerInterrupt(); + break; + default: + break; + } + } +} diff --git a/src/libultra/io/virepeatline.c b/src/libultra/io/virepeatline.c index 09a3a4788..55ffe71db 100644 --- a/src/libultra/io/virepeatline.c +++ b/src/libultra/io/virepeatline.c @@ -1,3 +1,17 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/virepeatline/osViRepeatLine.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViRepeatLine(u8 active) { + register u32 saveMask = __osDisableInt(); + + if (active) { + __osViNext->state |= VI_STATE_REPEATLINE; + } else { + __osViNext->state &= ~VI_STATE_REPEATLINE; + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetevent.c b/src/libultra/io/visetevent.c index 51ed1eef9..4546f702e 100644 --- a/src/libultra/io/visetevent.c +++ b/src/libultra/io/visetevent.c @@ -1,3 +1,27 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/assert.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/visetevent/osViSetEvent.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETEVENT, 0); + return; + } + + assert(mq != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->msgq = mq; + __osViNext->msg = m; + __osViNext->retraceCount = retraceCount; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetmode.c b/src/libultra/io/visetmode.c index 5b1a5d080..a5c5f9eaf 100644 --- a/src/libultra/io/visetmode.c +++ b/src/libultra/io/visetmode.c @@ -1,3 +1,27 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/assert.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/visetmode/osViSetMode.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetMode(OSViMode* modep) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETMODE, 0); + return; + } + + assert(modep != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->modep = modep; + __osViNext->state = VI_STATE_MODE_UPDATED; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetspecial.c b/src/libultra/io/visetspecial.c index 88ac826ac..f963a01ba 100644 --- a/src/libultra/io/visetspecial.c +++ b/src/libultra/io/visetspecial.c @@ -1,3 +1,72 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/visetspecial/osViSetSpecialFeatures.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +// This value was incorrectly calculated until being fixed in 2.0J +#if BUILD_VERSION >= VERSION_J +#define OS_VI_SPECIAL_MAX \ + (OS_VI_GAMMA_ON | OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_ON | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | \ + OS_VI_DIVOT_OFF | OS_VI_DITHER_FILTER_ON | OS_VI_DITHER_FILTER_OFF) +#else +#define OS_VI_SPECIAL_MAX OS_VI_DITHER_FILTER_OFF +#endif + +void osViSetSpecialFeatures(u32 func) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETSPECIAL_VIMGR, 0); + return; + } + + if ((func < OS_VI_GAMMA_ON) || (func > OS_VI_SPECIAL_MAX)) { + __osError(ERR_OSVISETSPECIAL_VALUE, 1, func); + return; + } +#endif + + saveMask = __osDisableInt(); + + if ((func & OS_VI_GAMMA_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_DIVOT_ON) != 0) { + __osViNext->control |= VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DIVOT_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DITHER_FILTER_ON) != 0) { + __osViNext->control |= VI_CTRL_DITHER_FILTER_ON; + __osViNext->control &= ~VI_CTRL_ANTIALIAS_MASK; + } + + if ((func & OS_VI_DITHER_FILTER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DITHER_FILTER_ON; + __osViNext->control |= __osViNext->modep->comRegs.ctrl & VI_CTRL_ANTIALIAS_MASK; + } + + __osViNext->state |= VI_STATE_CTRL_UPDATED; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/viswapbuf.c b/src/libultra/io/viswapbuf.c index 66d8648ea..3275d0b85 100644 --- a/src/libultra/io/viswapbuf.c +++ b/src/libultra/io/viswapbuf.c @@ -1,3 +1,31 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/assert.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/viswapbuf/osViSwapBuffer.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSwapBuffer(void* frameBufPtr) { + u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISWAPBUFFER_VIMGR, 0); + return; + } + + assert(frameBufPtr != NULL); + + if ((u32) frameBufPtr & 0x3f) { + __osError(ERR_OSVISWAPBUFFER_ADDR, 1, frameBufPtr); + return; + } +#endif + + saveMask = __osDisableInt(); + + __osViNext->framep = frameBufPtr; + __osViNext->state |= VI_STATE_BUFFER_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/viswapcontext.c b/src/libultra/io/viswapcontext.c index 84194fa6c..f1327631c 100644 --- a/src/libultra/io/viswapcontext.c +++ b/src/libultra/io/viswapcontext.c @@ -1,3 +1,80 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/viswapcontext/__osViSwapContext.s") +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osViSwapContext() { + register OSViMode* vm; + register __OSViContext* vc; + u32 origin; + u32 hStart; +#if BUILD_VERSION >= VERSION_J + u32 vStart; +#endif + u32 nomValue; + u32 field; + + field = 0; + vc = __osViNext; + vm = vc->modep; + + field = IO_READ(VI_CURRENT_REG) & 1; // field num + + origin = osVirtualToPhysical(vc->framep) + (vm->fldRegs[field].origin); + if (vc->state & VI_STATE_XSCALE_UPDATED) { + vc->x.scale |= (vm->comRegs.xScale & ~VI_SCALE_MASK); + } else { + vc->x.scale = vm->comRegs.xScale; + } + + if (vc->state & VI_STATE_YSCALE_UPDATED) { + nomValue = vm->fldRegs[field].yScale & VI_SCALE_MASK; + vc->y.scale = vc->y.factor * nomValue; + vc->y.scale |= vm->fldRegs[field].yScale & ~VI_SCALE_MASK; + } else { + vc->y.scale = vm->fldRegs[field].yScale; + } + +#if BUILD_VERSION >= VERSION_J + vStart = (vm->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; +#endif + hStart = vm->comRegs.hStart; + + if (vc->state & VI_STATE_BLACK) { + hStart = 0; + } + + if (vc->state & VI_STATE_REPEATLINE) { + vc->y.scale = 0; + origin = osVirtualToPhysical(vc->framep); + } + + if (vc->state & VI_STATE_FADE) { + vc->y.scale = (vc->y.offset << VI_SUBPIXEL_SH) & (VI_2_10_FPART_MASK << VI_SUBPIXEL_SH); + origin = osVirtualToPhysical(vc->framep); + } + + IO_WRITE(VI_ORIGIN_REG, origin); + IO_WRITE(VI_WIDTH_REG, vm->comRegs.width); + IO_WRITE(VI_BURST_REG, vm->comRegs.burst); + IO_WRITE(VI_V_SYNC_REG, vm->comRegs.vSync); + IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync); + IO_WRITE(VI_LEAP_REG, vm->comRegs.leap); + IO_WRITE(VI_H_START_REG, hStart); +#if BUILD_VERSION >= VERSION_J + IO_WRITE(VI_V_START_REG, vStart); +#else + IO_WRITE(VI_V_START_REG, vm->fldRegs[field].vStart); +#endif + IO_WRITE(VI_V_BURST_REG, vm->fldRegs[field].vBurst); + IO_WRITE(VI_INTR_REG, vm->fldRegs[field].vIntr); + IO_WRITE(VI_X_SCALE_REG, vc->x.scale); + IO_WRITE(VI_Y_SCALE_REG, vc->y.scale); + IO_WRITE(VI_CONTROL_REG, vc->control); + + __osViNext = __osViCurr; + __osViCurr = vc; + *__osViNext = *__osViCurr; +} diff --git a/src/libultra/libc/xldtob.c b/src/libultra/libc/xldtob.c index 932764557..0327cc66d 100644 --- a/src/libultra/libc/xldtob.c +++ b/src/libultra/libc/xldtob.c @@ -1,9 +1,307 @@ -#include "common.h" +#include "libc/stdlib.h" +#include "libc/string.h" +#include "PR/xstdio.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xldtob/_Genld.s") +// TODO: these come from headers +#ident "$Revision: 1.23 $" +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xldtob/D_800C9580.s") +#define BUFF_LEN 0x20 -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xldtob/_Ldtob.s") +static s16 _Ldunscale(s16* pex, _Pft* px); +static void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xldtob/D_800C95D0.s") +static const double pows[] = { 10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L }; + +// float properties +#define _D0 0 +#define _DBIAS 0x3ff +#define _DLONG 1 +#define _DOFF 4 +#define _FBIAS 0x7e +#define _FOFF 7 +#define _FRND 1 +#define _LBIAS 0x3ffe +#define _LOFF 15 +// integer properties +#define _C2 1 +#define _CSIGN 1 +#define _ILONG 0 +#define _MBMAX 8 +#define NAN 2 +#define INF 1 +#define FINITE -1 +#define _DFRAC ((1 << _DOFF) - 1) +#define _DMASK (0x7fff & ~_DFRAC) +#define _DMAX ((1 << (15 - _DOFF)) - 1) +#define _DNAN (0x8000 | _DMAX << _DOFF | 1 << (_DOFF - 1)) +#define _DSIGN 0x8000 +#define _D1 1 // big-endian order +#define _D2 2 +#define _D3 3 + +#define ALIGN(s, align) (((u32) (s) + ((align) -1)) & ~((align) -1)) + +void _Ldtob(_Pft* px, char code) { + char buff[BUFF_LEN]; + char* p; + f64 ldval; + s16 err; + s16 nsig; + s16 xexp; + + // char unused[0x4]; + p = buff; + ldval = px->v.ld; + + if (px->prec < 0) { + px->prec = 6; + } else if (px->prec == 0 && (code == 'g' || code == 'G')) { + px->prec = 1; + } + + err = _Ldunscale(&xexp, px); + if (err > 0) { + memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3); + return; + } else if (err == 0) { + nsig = 0; + xexp = 0; + } else { + { + int i; + int n; + + if (ldval < 0) { + ldval = -ldval; + } + + // what + if ((xexp = xexp * 30103 / 100000 - 4) < 0) { + n = ALIGN(-xexp, 4), xexp = -n; + + for (i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + ldval *= pows[i]; + } + } + } else if (xexp > 0) { + f64 factor = 1; + + xexp &= ~3; + + for (n = xexp, i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + factor *= pows[i]; + } + } + + ldval /= factor; + } + } + { + int gen = px->prec + ((code == 'f') ? 10 + xexp : 6); + + if (gen > 0x13) { + gen = 0x13; + } + + for (*p++ = '0'; gen > 0 && 0 < ldval; p += 8) { + int j; + long lo = ldval; + + if ((gen -= 8) > 0) { + ldval = (ldval - lo) * 1e8; + } + + for (p += 8, j = 8; lo > 0 && --j >= 0;) { + ldiv_t qr; + qr = ldiv(lo, 10); + *--p = qr.rem + '0', lo = qr.quot; + } + + while (--j >= 0) { + *--p = '0'; + } + } + + gen = p - &buff[1]; + + for (p = &buff[1], xexp += 7; *p == '0'; p++) { + --gen, --xexp; + } + + nsig = px->prec + ((code == 'f') ? xexp + 1 : ((code == 'e' || code == 'E') ? 1 : 0)); + + if (gen < nsig) { + nsig = gen; + } + + if (nsig > 0) { + const char drop = nsig < gen && '5' <= p[nsig] ? '9' : '0'; + int n; + + for (n = nsig; p[--n] == drop;) { + --nsig; + } + + if (drop == '9') { + ++p[n]; + } + + if (n < 0) { + --p, ++nsig, ++xexp; + } + } + } + } + + _Genld(px, code, p, nsig, xexp); +} + +s16 _Ldunscale(s16* pex, _Pft* px) { + u16* ps = (u16*) px; + s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; + + if (xchar == _DMAX) { + *pex = 0; + + return (ps[_D0] & _DFRAC) || ps[_D1] || ps[_D2] || ps[_D3] ? 2 : 1; + } else if (xchar > 0) { + ps[_D0] = (ps[_D0] & ~_DMASK) | 0x3FF0; + *pex = xchar - 0x3FE; + return -1; + } else if (xchar < 0) { + return 2; + } else { + *pex = 0; + return 0; + } +} + +void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) { + const unsigned char point = '.'; + + if (nsig <= 0) { + nsig = 1, p = "0"; + } + + if (code == 'f' || (code == 'g' || code == 'G') && xexp >= -4 && xexp < px->prec) { + xexp++; + if (code != 'f') { + if (((px->flags & 8) == 0) && nsig < px->prec) { + px->prec = nsig; + } + + if ((px->prec -= xexp) < 0) { + px->prec = 0; + } + } + + if (xexp <= 0) { + px->s[px->n1++] = '0'; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < -xexp) { + xexp = -px->prec; + } + + px->nz1 = -xexp; + px->prec += xexp; + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, px->n2 = nsig); + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1] = point; + px->n2++; + } + + px->nz2 = px->prec; + } else { + memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], &p[xexp], nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { + if (code == 'g' || code == 'G') { + if (nsig < px->prec) { + px->prec = nsig; + } + + if (--px->prec < 0) { + px->prec = 0; + } + + code = (code == 'g') ? 'e' : 'E'; + } + + px->s[px->n1++] = *p++; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec > 0) { + if (px->prec < --nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + + p = &px->s[px->n1]; + *p++ = code; + + if (xexp >= 0) { + *p++ = '+'; + } else { + *p++ = '-'; + xexp = -xexp; + } + + if (xexp >= 100) { + if (xexp >= 1000) { + *p++ = (xexp / 1000) + '0', xexp %= 1000; + } + *p++ = (xexp / 100) + '0', xexp %= 100; + } + *p++ = (xexp / 10) + '0', xexp %= 10; + + *p++ = xexp + '0'; + px->n2 = (size_t) p - ((size_t) px->s + px->n1); + } + + if ((px->flags & 0x14) == 0x10) { + s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) { + px->nz0 = px->width - n; + } + } +} diff --git a/src/libultra/libc/xlitob.c b/src/libultra/libc/xlitob.c index 00eae28d4..4c82854b7 100644 --- a/src/libultra/libc/xlitob.c +++ b/src/libultra/libc/xlitob.c @@ -2,40 +2,12 @@ #include "libc/string.h" #include "libc/stdlib.h" -// typedef struct { -// /* 0x0 */ union { -// /* 0x0 */ s64 ll; -// /* 0x0 */ f64 ld; -// } v; -// /* 0x8 */ char* s; -// /* 0xC */ s32 n0; -// /* 0x10 */ s32 nz0; -// /* 0x14 */ s32 n1; -// /* 0x18 */ s32 nz1; -// /* 0x1C */ s32 n2; -// /* 0x20 */ s32 nz2; -// /* 0x24 */ s32 prec; -// /* 0x28 */ s32 width; -// /* 0x2C */ size_t nchar; -// /* 0x30 */ u32 flags; -// /* 0x34 */ u8 qual; -// } _Pft; - #define BUFF_LEN 0x18 -// #define FLAGS_SPACE 1 -// #define FLAGS_PLUS 2 -// #define FLAGS_MINUS 4 -// #define FLAGS_HASH 8 -// #define FLAGS_ZERO 16 - -// Pending Data for import: -// u8 ldigs[] = "0123456789abcdef"; -// u8 udigs[] = "0123456789ABCDEF"; -extern u8 ldigs[]; -extern u8 udigs[]; +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; -void _Litob(_Pft* args, u8 type) { +void _Litob(_Pft* args, char type) { u8 buff[BUFF_LEN]; const u8* numMap; s32 base; diff --git a/src/libultra/libc/xprintf.c b/src/libultra/libc/xprintf.c index 9e461508f..f338f6621 100644 --- a/src/libultra/libc/xprintf.c +++ b/src/libultra/libc/xprintf.c @@ -1,5 +1,251 @@ -#include "common.h" +#include "macros.h" +#include "libc/string.h" +#include "libc/stdarg.h" +#include "PR/xstdio.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xprintf/_Putfld.s") +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.23 $" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/xprintf/_Printf.s") +#define isdigit(x) ((x >= '0' && x <= '9')) +#define LDSIGN(x) (((unsigned short*) &(x))[0] & 0x8000) + +#define ATOI(dst, src) \ + for (dst = 0; isdigit(*src); ++src) { \ + if (dst < 999) \ + dst = dst * 10 + *src - '0'; \ + } + +#define MAX_PAD ((sizeof(spaces) - 1)) +#define PAD(s, n) \ + if (0 < (n)) { \ + int i, j = (n); \ + for (; 0 < j; j -= i) { \ + i = MAX_PAD < (unsigned int) j ? (int) MAX_PAD : j; \ + PUT(s, i); \ + } \ + } +#define PUT(s, n) \ + if (0 < (n)) { \ + if ((arg = (*prout)(arg, s, n)) != NULL) \ + x.nchar += (n); \ + else \ + return x.nchar; \ + } +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(_Pft* x, va_list* args, char type, char* buff); + +int _Printf(outfun prout, char* arg, const char* fmt, va_list args) { + _Pft x; + + x.nchar = 0; + + while (TRUE) { + const char* s; + char c; + const char* t; + static const char fchar[] = { ' ', '+', '-', '#', '0', '\0' }; + static const int fbit[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 }; + char ac[32]; + s = fmt; + + for (c = *s; c != 0 && c != '%';) { + c = *++s; + } + + PUT(fmt, s - fmt); + + if (c == 0) { + return x.nchar; + } + + fmt = ++s; + + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; s++) { + x.flags |= fbit[t - fchar]; + } + + if (*s == '*') { + x.width = va_arg(args, int); + + if (x.width < 0) { + x.width = -x.width; + x.flags |= FLAGS_MINUS; + } + s++; + } else + ATOI(x.width, s); + + if (*s != '.') { + x.prec = -1; + } else if (*++s == '*') { + x.prec = va_arg(args, int); + ++s; + } else { + for (x.prec = 0; isdigit(*s); s++) { + if (x.prec < 999) { + x.prec = x.prec * 10 + *s - '0'; + } + } + } + + x.qual = strchr("hlL", *s) ? *s++ : '\0'; + + if (x.qual == 'l' && *s == 'l') { + x.qual = 'L'; + ++s; + } + + _Putfld(&x, &args, *s, ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; + + { + + if (!(x.flags & FLAGS_MINUS)) { + int i, j; + if (0 < (x.width)) { + i, j = x.width; + for (; 0 < j; j -= i) { + i = MAX_PAD < (unsigned int) j ? (int) MAX_PAD : j; + PUT(spaces, i); + } + } + } + + PUT(ac, x.n0); + PAD(zeroes, x.nz0) + + PUT(x.s, x.n1); + PAD(zeroes, x.nz1); + + PUT(x.s + x.n1, x.n2); + PAD(zeroes, x.nz2); + + if (x.flags & FLAGS_MINUS) { + PAD(spaces, x.width); + } + } + fmt = s + 1; + } + return 0; +} + +static void _Putfld(_Pft* x, va_list* args, char type, char* buff) { + x->n0 = x->nz0 = x->n1 = x->nz1 = x->n2 = x->nz2 = 0; + + switch (type) { + case 'c': + buff[x->n0++] = va_arg(*args, int); + break; + case 'd': + case 'i': + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); + } else { + x->v.ll = va_arg(*args, int); + } + + if (x->qual == 'h') { + x->v.ll = (s16) x->v.ll; + } + + if (x->v.ll < 0) { + buff[x->n0++] = '-'; + } else if (x->flags & FLAGS_PLUS) { + buff[x->n0++] = '+'; + } else if (x->flags & FLAGS_SPACE) { + buff[x->n0++] = ' '; + } + + x->s = (char*) &buff[x->n0]; + + _Litob(x, type); + break; + case 'x': + case 'X': + case 'u': + case 'o': + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); + } else { + x->v.ll = va_arg(*args, int); + } + + if (x->qual == 'h') { + x->v.ll = (u16) x->v.ll; + } else if (x->qual == 0) { + x->v.ll = (unsigned int) x->v.ll; + } + + if (x->flags & FLAGS_HASH) { + buff[x->n0++] = '0'; + + if (type == 'x' || type == 'X') { + buff[x->n0++] = type; + } + } + + x->s = (char*) &buff[x->n0]; + _Litob(x, type); + break; + case 'e': + case 'f': + case 'g': + case 'E': + case 'G': + //... okay? + x->v.ld = x->qual == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); + + if (LDSIGN(x->v.ld)) { + buff[x->n0++] = '-'; + } else if (x->flags & FLAGS_PLUS) { + buff[x->n0++] = '+'; + } else if (x->flags & FLAGS_SPACE) { + buff[x->n0++] = ' '; + } + + x->s = (char*) &buff[x->n0]; + _Ldtob(x, type); + break; + + case 'n': + if (x->qual == 'h') { + *(va_arg(*args, u16*)) = x->nchar; + } else if (x->qual == 'l') { + *va_arg(*args, unsigned int*) = x->nchar; + } else if (x->qual == 'L') { + *va_arg(*args, u64*) = x->nchar; + } else { + *va_arg(*args, unsigned int*) = x->nchar; + } + + break; + case 'p': + x->v.ll = (long) va_arg(*args, void*); + x->s = (char*) &buff[x->n0]; + _Litob(x, 'x'); + break; + case 's': + x->s = va_arg(*args, char*); + x->n1 = strlen(x->s); + + if (x->prec >= 0 && x->prec < x->n1) { + x->n1 = x->prec; + } + + break; + case '%': + buff[x->n0++] = '%'; + break; + default: + buff[x->n0++] = type; + break; + } +} diff --git a/src/libultra/os/createthread.c b/src/libultra/os/createthread.c index 545cf5ef5..f349e6b1f 100644 --- a/src/libultra/os/createthread.c +++ b/src/libultra/os/createthread.c @@ -1,3 +1,54 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/createthread/osCreateThread.s") +extern __OSThreadprofile_s thprof[]; + +void osCreateThread(OSThread* t, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri p) { + register u32 saveMask; + OSIntMask mask; + +#ifdef _DEBUG + if ((u32) sp & 0x7) { + __osError(ERR_OSCREATETHREAD_SP, 1, sp); + return; + } + + if ((p < OS_PRIORITY_IDLE) || (p > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATETHREAD_PRI, 1, p); + return; + } +#endif + + t->id = id; + t->priority = p; + t->next = NULL; + t->queue = NULL; + t->context.pc = (u32) entry; + t->context.a0 = (s64) (s32) arg; // Double cast gets rid of compiler warning + t->context.sp = (s64) (s32) sp - 16; + t->context.ra = __osCleanupThread; + mask = OS_IM_ALL; + t->context.sr = (mask & (SR_IMASK | SR_IE)) | SR_EXL; + t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; + t->context.fpcsr = (u32) (FPCSR_FS | FPCSR_EV); + t->fp = 0; + t->state = OS_STATE_STOPPED; + t->flags = 0; + +#if BUILD_VERSION >= VERSION_K +#ifndef _FINALROM + if (id < THPROF_IDMAX) { + t->thprof = &thprof[id]; + } else { + t->thprof = &thprof[THPROF_IDMAX - 1]; + } +#endif +#endif + + saveMask = __osDisableInt(); + t->tlnext = __osActiveQueue; + __osActiveQueue = t; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/getthreadpri.c b/src/libultra/os/getthreadpri.c index edf58fc50..149f3f718 100644 --- a/src/libultra/os/getthreadpri.c +++ b/src/libultra/os/getthreadpri.c @@ -1,3 +1,10 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/getthreadpri/osGetThreadPri.s") +OSPri osGetThreadPri(OSThread* thread) { + if (thread == NULL) { + thread = __osRunningThread; + } + + return thread->priority; +} diff --git a/src/libultra/os/gettime.c b/src/libultra/os/gettime.c index 443461d42..920df07f9 100644 --- a/src/libultra/os/gettime.c +++ b/src/libultra/os/gettime.c @@ -1,3 +1,25 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/viint.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/gettime/osGetTime.s") +OSTime osGetTime() { + u32 tmptime; + u32 elapseCount; + OSTime currentCount; + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSGETTIME, 0); + return 0; + } +#endif + + saveMask = __osDisableInt(); + tmptime = osGetCount(); + elapseCount = tmptime - __osBaseCounter; + currentCount = __osCurrentTime; + __osRestoreInt(saveMask); + return currentCount + elapseCount; +} diff --git a/src/libultra/os/initialize.c b/src/libultra/os/initialize.c index d43a98054..9f45d50ee 100644 --- a/src/libultra/os/initialize.c +++ b/src/libultra/os/initialize.c @@ -1,3 +1,224 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/os_version.h" +#include "piint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/initialize/osInitialize.s") +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; +extern __osExceptionVector __osExceptionPreamble[]; + +extern OSPiHandle __Dom1SpeedParam; +extern OSPiHandle __Dom2SpeedParam; + +OSTime osClockRate = OS_CLOCK_RATE; +s32 osViClock = VI_NTSC_CLOCK; +u32 __osShutdown = 0; +u32 __OSGlobalIntMask = OS_IM_ALL; +#ifdef _FINALROM +u32 __osFinalrom; +#else +u32 __kmc_pt_mode; +#if BUILD_VERSION >= VERSION_K +void* __printfunc = NULL; +#endif +#endif + +#if BUILD_VERSION >= VERSION_K + +#define INITIALIZE_FUNC __osInitialize_common +#define SPEED_PARAM_FUNC __createSpeedParam +#else + +#define INITIALIZE_FUNC osInitialize +#define SPEED_PARAM_FUNC createSpeedParam +#if BUILD_VERSION >= VERSION_J +static void ptstart(void); +static void SPEED_PARAM_FUNC(void); +#endif +extern __osExceptionVector __ptExceptionPreamble[]; + +#endif + +#if BUILD_VERSION >= VERSION_K +void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif + +void INITIALIZE_FUNC() { + u32 pifdata; +#if BUILD_VERSION < VERSION_K + u32 clock = 0; +#endif + +#ifdef _FINALROM + __osFinalrom = TRUE; +#endif + + __osSetSR(__osGetSR() | SR_CU1); // enable fpu + __osSetFpcCsr(FPCSR_FS | FPCSR_EV); // flush denorm to zero, enable invalid operation +#if BUILD_VERSION >= VERSION_K + __osSetWatchLo(0x4900000); +#endif + + while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) { // last byte of joychannel ram + ; + } + while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) { + ; // todo: magic contant + } + *(__osExceptionVector*) UT_VEC = *__osExceptionPreamble; + *(__osExceptionVector*) XUT_VEC = *__osExceptionPreamble; + *(__osExceptionVector*) ECC_VEC = *__osExceptionPreamble; + *(__osExceptionVector*) E_VEC = *__osExceptionPreamble; + osWritebackDCache((void*) UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); + osInvalICache((void*) UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); +#if BUILD_VERSION >= VERSION_J + SPEED_PARAM_FUNC(); + osUnmapTLBAll(); + osMapTLBRdb(); +#else + osMapTLBRdb(); + osPiRawReadIo(4, &clock); // Read clock rate from the ROM header + clock &= ~0xf; + if (clock != 0) { + osClockRate = clock; + } +#endif + osClockRate = osClockRate * 3 / 4; + + if (osResetType == 0) { // cold reset + bzero(osAppNMIBuffer, OS_APP_NMI_BUFSIZE); + } + + if (osTvType == OS_TV_PAL) { + osViClock = VI_PAL_CLOCK; + } else if (osTvType == OS_TV_MPAL) { + osViClock = VI_MPAL_CLOCK; + } else { + osViClock = VI_NTSC_CLOCK; + } + +#if BUILD_VERSION >= VERSION_J + // Wait until there are no RCP interrupts + if (__osGetCause() & CAUSE_IP5) { + while (TRUE) { + ; + } + } + + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); + IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1); + IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1); +#endif + +#if BUILD_VERSION < VERSION_K && !defined(_FINALROM) + if (!__kmc_pt_mode) { + int (*fnc)(s32, s32); +#if BUILD_VERSION < VERSION_J + unsigned int c; + unsigned int c1; +#endif + unsigned int* src; + unsigned int* dst; + unsigned int monadr; + volatile unsigned int* mon; + volatile unsigned int* stat; + + stat = (unsigned*) 0xbff08004; + mon = (unsigned*) 0xBFF00000; + if (*mon != 0x4B4D4300) { + return; + } + + src = (unsigned*) __ptExceptionPreamble; + dst = (unsigned*) E_VEC; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + src += 2; + dst += 2; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; +#if BUILD_VERSION >= VERSION_H + *dst++ = *src++; +#endif + + osWritebackDCache(E_VEC, 0x24); + osInvalICache(E_VEC, 0x24); + + __kmc_pt_mode = TRUE; + + if ((*stat & 0x10) == 0) { + monadr = *(mon + 1); + if (monadr != 0xBFF00000) { + unsigned int* src; + unsigned int* dst = monadr | 0x20000000; + unsigned int ct = 0x2000 / 4; + + src = 0xBFF00000; + + while (ct != 0) { + *dst++ = *src++; + ct--; + } + } + fnc = monadr + 8; + fnc(0x4B4D4300, 0); + } + } +#endif +} + +#if !defined(_FINALROM) && BUILD_VERSION < VERSION_J +void ptstart() { +} +#elif !defined(_FINALROM) && BUILD_VERSION < VERSION_K +static void ptstart() { +} +#endif + +#if BUILD_VERSION >= VERSION_K +void __osInitialize_autodetect() { +#ifndef _FINALROM + if (__checkHardware_msp()) { + __osInitialize_msp(); + } else if (__checkHardware_kmc()) { + __osInitialize_kmc(); + } else if (__checkHardware_isv()) { + __osInitialize_isv(); + } else { + __osInitialize_emu(); + } +#endif +} +#elif BUILD_VERSION == VERSION_J +static void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif diff --git a/src/libultra/os/initrdb.c b/src/libultra/os/initrdb.c index 204c3abd9..3d2d88719 100644 --- a/src/libultra/os/initrdb.c +++ b/src/libultra/os/initrdb.c @@ -1,3 +1,31 @@ -#include "common.h" +#ifndef _FINALROM +#include "PR/rdb.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/initrdb/osInitRdb.s") +rdbPacket* __osRdb_IP6_Data; +u32 __osRdb_IP6_Size; +u32 __osRdb_IP6_Ct; +u32 __osRdb_IP6_CurWrite; +u32 __osRdb_IP6_CurSend; + +void osInitRdb(u8* sendBuf, u32 sendSize) { + u32 mask; + + sendSize /= 4; + + if (((u32) sendBuf & 3) != 0) { + sendBuf = ((u32) sendBuf & 3) + 4; + sendSize--; + } + mask = __osDisableInt(); + + __osRdb_IP6_Data = (rdbPacket*) sendBuf; + __osRdb_IP6_Size = sendSize; + __osRdb_IP6_Ct = 0; + __osRdb_IP6_CurWrite = 0; + __osRdb_IP6_CurSend = 0; + + __osRestoreInt(mask); +} + +#endif diff --git a/src/libultra/os/jammesg.c b/src/libultra/os/jammesg.c index 644ea8ded..cef68dab1 100644 --- a/src/libultra/os/jammesg.c +++ b/src/libultra/os/jammesg.c @@ -1,3 +1,37 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/jammesg/osJamMesg.s") +s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { + register u32 saveMask; + +#ifdef _DEBUG + if ((flag != OS_MESG_NOBLOCK) && (flag != OS_MESG_BLOCK)) { + __osError(ERR_OSJAMMESG, 1, flag); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (mq->validCount >= mq->msgCount) { + if (flag == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } else { + __osRestoreInt(saveMask); + return -1; + } + } + + mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount; + mq->msg[mq->first] = msg; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + osStartThread(__osPopThread(&mq->mtqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/src/libultra/os/rdbsend.c b/src/libultra/os/rdbsend.c index c8e5085cb..1c181e953 100644 --- a/src/libultra/os/rdbsend.c +++ b/src/libultra/os/rdbsend.c @@ -1,3 +1,73 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/rdb.h" +#include "PR/R4300.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/rdbsend/__osRdbSend.s") +extern rdbPacket* __osRdb_IP6_Data; +extern u32 __osRdb_IP6_Size; +extern u32 __osRdb_IP6_Ct; +extern u32 __osRdb_IP6_CurWrite; + +u32 __osRdb_IP6_Empty = 1; + +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +u32 __osRdbSend(u8* buf, u32 size, u32 type) { + rdbPacket* pPtr; + rdbPacket pkt; + u32 len; + u32 c; + u32 inCt = 0; + u32 needFirst = 0; + u32 mask; + u32 sent = 0; + + mask = __osDisableInt(); + + if (__osRdb_IP6_Empty != 0) { + __osRdb_IP6_Empty = 0; + pkt.type = type; + + len = MIN(size, sizeof(pkt.buf)); + + pkt.length = len; + + c = 0; + while (c < len) { + pkt.buf[c++] = buf[inCt++]; + } + + size -= len; + sent = len; + needFirst = 1; + } + + while (size != 0 && __osRdb_IP6_Ct < __osRdb_IP6_Size) { + len = MIN(size, sizeof(pPtr->buf)); + + pPtr = &__osRdb_IP6_Data[__osRdb_IP6_CurWrite]; + + pPtr->type = type; + pPtr->length = len; + + c = 0; + while (c < len) { + pPtr->buf[c++] = buf[inCt++]; + } + + __osRdb_IP6_CurWrite++; + if (__osRdb_IP6_CurWrite >= __osRdb_IP6_Size) { + __osRdb_IP6_CurWrite = 0; + } + + __osRdb_IP6_Ct++; + size -= len; + sent += len; + } + + if (needFirst) { + *(u32*) RDB_BASE_REG = *(u32*) &pkt; + } + __osRestoreInt(mask); + + return sent; +} diff --git a/src/libultra/os/recvmesg.c b/src/libultra/os/recvmesg.c index 24ebc777f..043ed2156 100644 --- a/src/libultra/os/recvmesg.c +++ b/src/libultra/os/recvmesg.c @@ -1,3 +1,40 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/recvmesg/osRecvMesg.s") +s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) { + register u32 saveMask; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSRECVMESG, 1, flags); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (MQ_IS_EMPTY(mq)) { + if (flags == OS_MESG_NOBLOCK) { + __osRestoreInt(saveMask); + return -1; + } else { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->mtqueue); + } + } + + if (msg != NULL) { + *msg = mq->msg[mq->first]; + } + + mq->first = (mq->first + 1) % mq->msgCount; + mq->validCount--; + + if (mq->fullqueue->next != NULL) { + osStartThread(__osPopThread(&mq->fullqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/src/libultra/os/resetglobalintmask.c b/src/libultra/os/resetglobalintmask.c index 07ca8cdb5..780da7cb7 100644 --- a/src/libultra/os/resetglobalintmask.c +++ b/src/libultra/os/resetglobalintmask.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/resetglobalintmask/__osResetGlobalIntMask.s") +void __osResetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __OSGlobalIntMask &= ~(mask & ~OS_IM_RCP); + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/sendmesg.c b/src/libultra/os/sendmesg.c index 3be93f3a8..19cf3de77 100644 --- a/src/libultra/os/sendmesg.c +++ b/src/libultra/os/sendmesg.c @@ -1,3 +1,38 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/sendmesg/osSendMesg.s") +s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) { + register u32 saveMask; + register s32 last; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSSENDMESG, 1, flags); + return -1; + } +#endif + + saveMask = __osDisableInt(); + + while (MQ_IS_FULL(mq)) { + if (flags == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } else { + __osRestoreInt(saveMask); + return -1; + } + } + + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = msg; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + osStartThread(__osPopThread(&mq->mtqueue)); + } + + __osRestoreInt(saveMask); + return 0; +} diff --git a/src/libultra/os/seteventmesg.c b/src/libultra/os/seteventmesg.c index 77492b83a..f59308c0d 100644 --- a/src/libultra/os/seteventmesg.c +++ b/src/libultra/os/seteventmesg.c @@ -1,3 +1,39 @@ -#include "common.h" +#include "macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/seteventmesg/osSetEventMesg.s") +__OSEventState __osEventStateTab[OS_NUM_EVENTS] ALIGNED(8); +#if BUILD_VERSION >= VERSION_J +u32 __osPreNMI = FALSE; +#endif + +void osSetEventMesg(OSEvent event, OSMesgQueue* mq, OSMesg msg) { + register u32 saveMask; + __OSEventState* es; + +#ifdef _DEBUG + if (event >= OS_NUM_EVENTS) { + __osError(ERR_OSSETEVENTMESG, 1, event); + return; + } +#endif + + saveMask = __osDisableInt(); + + es = &__osEventStateTab[event]; + + es->messageQueue = mq; + es->message = msg; + +#if BUILD_VERSION >= VERSION_J + if (event == OS_EVENT_PRENMI) { + if (__osShutdown && !__osPreNMI) { + osSendMesg(mq, msg, OS_MESG_NOBLOCK); + } + __osPreNMI = TRUE; + } +#endif + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/setglobalintmask.c b/src/libultra/os/setglobalintmask.c index a12c3eedb..a71898077 100644 --- a/src/libultra/os/setglobalintmask.c +++ b/src/libultra/os/setglobalintmask.c @@ -1,3 +1,9 @@ -#include "common.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/setglobalintmask/__osSetGlobalIntMask.s") +void __osSetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __OSGlobalIntMask |= mask; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/setthreadpri.c b/src/libultra/os/setthreadpri.c index 409c93658..d836323ce 100644 --- a/src/libultra/os/setthreadpri.c +++ b/src/libultra/os/setthreadpri.c @@ -1,3 +1,36 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/setthreadpri/osSetThreadPri.s") +void osSetThreadPri(OSThread* t, OSPri pri) { + register u32 saveMask; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSSETTHREADPRI, 1, pri); + return; + } +#endif + + saveMask = __osDisableInt(); + + if (t == NULL) { + t = __osRunningThread; + } + + if (t->priority != pri) { + t->priority = pri; + + if (t != __osRunningThread && t->state != OS_STATE_STOPPED) { + __osDequeueThread(t->queue, t); + __osEnqueueThread(t->queue, t); + } + + if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/settime.c b/src/libultra/os/settime.c index 87af930fc..29aac718f 100644 --- a/src/libultra/os/settime.c +++ b/src/libultra/os/settime.c @@ -1,3 +1,16 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/settime/osSetTime.s") +void osSetTime(OSTime time) { + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIME, 0); + return; + } +#endif + + __osCurrentTime = time; +} diff --git a/src/libultra/os/settimer.c b/src/libultra/os/settimer.c index be282868c..962433759 100644 --- a/src/libultra/os/settimer.c +++ b/src/libultra/os/settimer.c @@ -1,3 +1,56 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" +#include "PR/viint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/settimer/osSetTimer.s") +int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime time; +#if BUILD_VERSION >= VERSION_K + OSTimer* next; + u32 count; + u32 value; + u32 saveMask; +#endif + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIMER, 0); + return 0; + } +#endif + + t->next = NULL; + t->prev = NULL; + t->interval = interval; + t->value = (countdown != 0) ? countdown : interval; + t->mq = mq; + t->msg = msg; + +#if BUILD_VERSION >= VERSION_K + saveMask = __osDisableInt(); + if (__osTimerList->next == __osTimerList) { + + } else { + next = __osTimerList->next; + count = osGetCount(); + value = count - __osTimerCounter; + + if (value < next->value) { + next->value -= value; + } else { + next->value = 1; + } + } + + time = __osInsertTimer(t); + __osSetTimerIntr(__osTimerList->next->value); + __osRestoreInt(saveMask); +#else + time = __osInsertTimer(t); + if (__osTimerList->next == t) { + __osSetTimerIntr(time); + } +#endif + + return 0; +} diff --git a/src/libultra/os/startthread.c b/src/libultra/os/startthread.c index e015b71fe..2ce15465c 100644 --- a/src/libultra/os/startthread.c +++ b/src/libultra/os/startthread.c @@ -1,3 +1,39 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/startthread/osStartThread.s") +void osStartThread(OSThread* t) { + register u32 saveMask = __osDisableInt(); + + switch (t->state) { + case OS_STATE_WAITING: + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + break; + case OS_STATE_STOPPED: + if (t->queue == NULL || t->queue == &__osRunQueue) { + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + } else { + t->state = OS_STATE_WAITING; + __osEnqueueThread(t->queue, t); + __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); + } + break; +#ifdef _DEBUG + default: + __osError(ERR_OSSTARTTHREAD, 0); + __osRestoreInt(saveMask); + return; +#endif + } + + if (__osRunningThread == NULL) { + __osDispatchThread(); + } else if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/thread.c b/src/libultra/os/thread.c index 846ee03ae..0cdb1b604 100644 --- a/src/libultra/os/thread.c +++ b/src/libultra/os/thread.c @@ -1,3 +1,28 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/thread/__osDequeueThread.s") +struct __osThreadTail __osThreadTail = { NULL, -1 }; +OSThread* __osRunQueue = (OSThread*) &__osThreadTail; +OSThread* __osActiveQueue = (OSThread*) &__osThreadTail; +OSThread* __osRunningThread = { 0 }; +OSThread* __osFaultedThread = { 0 }; + +void __osDequeueThread(register OSThread** queue, register OSThread* t) { + register OSThread* pred; + register OSThread* succ; + + pred = (OSThread*) queue; + succ = pred->next; + + while (succ != NULL) { + if (succ == t) { + pred->next = t->next; +#ifdef _DEBUG + t->next = NULL; +#endif + return; + } + pred = succ; + succ = pred->next; + } +} diff --git a/src/libultra/os/timerintr.c b/src/libultra/os/timerintr.c index 8dcb17cfd..3135885c2 100644 --- a/src/libultra/os/timerintr.c +++ b/src/libultra/os/timerintr.c @@ -1,9 +1,144 @@ -#include "common.h" +#include "macros.h" +#include "osint.h" +#include "PR/os_internal.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/timerintr/__osTimerServicesInit.s") +// this needs to be in bss, because __osTimerServicesInit wont match otherwise. +// The rest cannot be declared here, as they will be put above this symbol, which +// doesnt match. +OSTime __osCurrentTime; +u32 __osBaseCounter; +u32 __osViIntrCount; +u32 __osTimerCounter; +OSTimer __osBaseTimer; +OSTimer* __osTimerList = &__osBaseTimer; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/timerintr/__osTimerInterrupt.s") +#ifndef _FINALROM +OSMesgQueue __osProfTimerQ ALIGNED(8); +OSProf* __osProfileList; +OSProf* __osProfileListEnd; +u32 __osProfileOverflowBin; +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/timerintr/__osSetTimerIntr.s") +void __osTimerServicesInit(void) { + __osCurrentTime = 0; + __osBaseCounter = 0; + __osViIntrCount = 0; + __osTimerList->next = __osTimerList->prev = __osTimerList; + __osTimerList->interval = __osTimerList->value = 0; + __osTimerList->mq = NULL; + __osTimerList->msg = 0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/timerintr/__osInsertTimer.s") +void __osTimerInterrupt(void) { + OSTimer* t; + u32 count; + u32 elapsed_cycles; + +#ifndef _FINALROM + u32 pc; + s32 offset; + OSProf* prof = __osProfileList; +#endif + + if (__osTimerList->next == __osTimerList) { + return; + } + for (;;) { + t = __osTimerList->next; + + if (t == __osTimerList) { + __osSetCompare(0); + __osTimerCounter = 0; + break; + } + + count = osGetCount(); + elapsed_cycles = count - __osTimerCounter; + __osTimerCounter = count; + + if (elapsed_cycles < t->value) { + t->value -= elapsed_cycles; + __osSetTimerIntr(t->value); + break; + } + + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + + if (t->mq != NULL) { +#ifdef _FINALROM + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } +#else + if (t->mq != &__osProfTimerQ) { + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } else { + pc = __osRunQueue->context.pc; + for (prof = __osProfileList; prof < __osProfileListEnd; prof++) { + offset = pc - (u32) prof->text_start; + + if (offset >= 0) { + if ((s32) prof->text_end - (s32) pc > 0) { + (*(u16*) (u32) ((offset >> 2) + prof->histo_base))++; + goto __ProfDone; + } + } + } + + __osProfileOverflowBin++; + } + } +#endif + + __ProfDone: + + if (t->interval != 0) { + t->value = t->interval; + __osInsertTimer(t); + } + } +} + +void __osSetTimerIntr(OSTime tim) { + OSTime NewTime; + u32 savedMask; + +#if BUILD_VERSION >= VERSION_K + if (tim < 468) { + tim = 468; + } +#endif + + savedMask = __osDisableInt(); + __osTimerCounter = osGetCount(); + NewTime = __osTimerCounter + tim; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); +} + +OSTime __osInsertTimer(OSTimer* t) { + OSTimer* timep; + OSTime tim; + u32 savedMask = __osDisableInt(); + + timep = __osTimerList->next; + tim = t->value; + for (; timep != __osTimerList && tim > timep->value; timep = timep->next) { + tim -= timep->value; + } + + t->value = tim; + + if (timep != __osTimerList) { + timep->value -= tim; + } + + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return tim; +} diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c index bac6bd651..553fe6858 100644 --- a/src/libultra/os/virtualtophysical.c +++ b/src/libultra/os/virtualtophysical.c @@ -1,3 +1,13 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/virtualtophysical/osVirtualToPhysical.s") +u32 osVirtualToPhysical(void* addr) { + if (IS_KSEG0(addr)) { + return K0_TO_PHYS(addr); + } else if (IS_KSEG1(addr)) { + return K1_TO_PHYS(addr); + } else { + return __osProbeTLB(addr); + } +} diff --git a/src/libultra/os/yieldthread.c b/src/libultra/os/yieldthread.c index eebebd847..9a4dafb8d 100644 --- a/src/libultra/os/yieldthread.c +++ b/src/libultra/os/yieldthread.c @@ -1,3 +1,10 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "osint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/yieldthread/osYieldThread.s") +void osYieldThread(void) { + register u32 saveMask = __osDisableInt(); + + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + __osRestoreInt(saveMask); +} diff --git a/src/libultra/rmon/rmonbrk.c b/src/libultra/rmon/rmonbrk.c index 167d263e5..effe64d3c 100644 --- a/src/libultra/rmon/rmonbrk.c +++ b/src/libultra/rmon/rmonbrk.c @@ -1,31 +1,432 @@ -#include "common.h" +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/SetTempBreakpoint.s") +#include "PR/os_internal.h" +#include "dbgproto.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "rmonint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/ClearTempBreakpoint.s") +#include "macros.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonSetBreak.s") +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonListBreak.s") +#define TMP_BP 0 +#define NUM_BREAKPOINTS 16 -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonClearBreak.s") +typedef struct { + TVushort type; + TVushort response; + TVid threadID; + void* pc; +} TVExceptionReplyMsg; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonGetBranchTarget.s") +typedef struct { + u32* breakAddress; + u32 oldInstruction; +} BREAKINFO; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonbrk_IsJump.s") +/* first breakpoint is reserved for implementing single-stepping */ +static BREAKINFO breakpoints[NUM_BREAKPOINTS] ALIGNED(8); +/* breakpoint for alternate branch target */ +static BREAKINFO altBreak; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonSetSingleStep.s") +static BREAKINFO RCPbreakpoints[NUM_BREAKPOINTS] ALIGNED(8); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonGetExceptionStatus.s") +u8 __rmonRcpAtBreak; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/rmonSendBreakMessage.s") +static void rmonFindFaultedThreads(void); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonHitBreak.s") +void SetTempBreakpoint(u32* addr1, u32* addr2) { + STUBBED_PRINTF(("Set temp BP at %08x", addr1)); + if (addr2 != NULL) { + STUBBED_PRINTF((" and %08x", addr2)); + } + STUBBED_PRINTF(("\n")); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonHitSpBreak.s") + /* Save the word at the target address to be restored later */ + breakpoints[TMP_BP].oldInstruction = *addr1; + /* Install a break instruction at the target address */ + *addr1 = MIPS_BREAK(16); + osWritebackDCache(addr1, sizeof(*addr1)); + osInvalICache(addr1, sizeof(*addr1)); + breakpoints[TMP_BP].breakAddress = addr1; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/__rmonHitCpuFault.s") + /* Also do so for an alt address if required */ + if (addr2 != NULL) { + altBreak.oldInstruction = *addr2; + *addr2 = MIPS_BREAK(16); + osWritebackDCache(addr2, sizeof(*addr2)); + osInvalICache(addr2, sizeof(*addr2)); + altBreak.breakAddress = addr2; + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/rmonFindFaultedThreads.s") +void ClearTempBreakpoint(void) { + u32 inst; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonbrk/D_800C9880.s") + if (breakpoints[TMP_BP].breakAddress != NULL) { + inst = *breakpoints[TMP_BP].breakAddress; + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + STUBBED_PRINTF(("ClearTempBreak @ %08x\n", breakpoints[TMP_BP].breakAddress)); + + /* After confirming that there is a break instruction with code at the target + address, restore the original contents of the word at the target address */ + *breakpoints[TMP_BP].breakAddress = breakpoints[TMP_BP].oldInstruction; + osWritebackDCache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); + osInvalICache(breakpoints[TMP_BP].breakAddress, sizeof(*breakpoints[TMP_BP].breakAddress)); + } + breakpoints[TMP_BP].breakAddress = NULL; + } + + /* Same as above for the alt breakpoint */ + if (altBreak.breakAddress != NULL) { + inst = *altBreak.breakAddress; + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + STUBBED_PRINTF(("ClearTempBreak @ %08x\n", altBreak.breakAddress)); + + *altBreak.breakAddress = altBreak.oldInstruction; + osWritebackDCache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); + osInvalICache(altBreak.breakAddress, sizeof(*altBreak.breakAddress)); + } + altBreak.breakAddress = NULL; + } +} + +int __rmonSetBreak(KKHeader* req) { + register KKSetBkptRequest* request = (KKSetBkptRequest*) req; + register BREAKINFO* breakBase; + register BREAKINFO* whichBreak; + register BREAKINFO* lastBreak; + KKBkptEvent reply; + + STUBBED_PRINTF(("SetBreak at %08x, method %d\n", request->addr, req->method)); + + /* Select breakpoint list */ + if (req->method == RMON_RSP) { + breakBase = RCPbreakpoints; + whichBreak = &RCPbreakpoints[1]; + lastBreak = &RCPbreakpoints[NUM_BREAKPOINTS]; + } else { + breakBase = breakpoints; + whichBreak = &breakpoints[1]; + lastBreak = &breakpoints[NUM_BREAKPOINTS]; + } + + /* Find breakpoint slot */ + for (; whichBreak < lastBreak; whichBreak++) { + if (whichBreak->breakAddress != NULL) { + if (whichBreak->breakAddress == (u32*) request->addr) { + /* Breakpoint already set here */ + break; + } + continue; + } else { + /* Empty slot */ + break; + } + } + + /* No breakpoints available */ + if (whichBreak == lastBreak) { + return TV_ERROR_NO_MORE_IDS; + } + + /* Set breakpoint if not already set */ + if (whichBreak->breakAddress == NULL) { + if (req->method == RMON_RSP) { + whichBreak->oldInstruction = __rmonReadWordAt((u32*) request->addr); + __rmonWriteWordTo((u32*) request->addr, MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS)); + } else { + whichBreak->oldInstruction = *(u32*) request->addr; + *(u32*) request->addr = MIPS_BREAK((whichBreak - breakBase) + NUM_BREAKPOINTS); + osWritebackDCache((void*) request->addr, sizeof(whichBreak->oldInstruction)); + osInvalICache((void*) request->addr, sizeof(whichBreak->oldInstruction)); + } + whichBreak->breakAddress = (u32*) request->addr; + STUBBED_PRINTF(("* (%08x) = %08x (was %08x)\n", whichBreak->breakAddress, *whichBreak->breakAddress, + whichBreak->oldInstruction)); + } + + /* Send reply */ + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + reply.bp = whichBreak - breakBase; + reply.instruction = whichBreak->oldInstruction; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonListBreak(KKHeader* request UNUSED) { + STUBBED_PRINTF(("ListBreak\n")); + + return TV_ERROR_ILLEGAL_CALL; +} + +int __rmonClearBreak(KKHeader* req) { + register KKClrBkptRequest* request = (KKClrBkptRequest*) req; + register BREAKINFO* whichBreak; + KKBkptEvent reply; + u32 inst; + + STUBBED_PRINTF(("ClearBreak\n")); + + /* Check valid breakpoint index */ + if (request->bp >= NUM_BREAKPOINTS) { + return TV_ERROR_INVALID_ID; + } + + /* Clear the breakpoint, restore whatever was there before */ + if (req->method == RMON_RSP) { + whichBreak = &RCPbreakpoints[request->bp]; + + if (whichBreak->breakAddress == NULL) { + return TV_ERROR_INVALID_ID; + } + + inst = __rmonReadWordAt(whichBreak->breakAddress); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + __rmonWriteWordTo(whichBreak->breakAddress, whichBreak->oldInstruction); + } + } else { + whichBreak = &breakpoints[request->bp]; + + if (whichBreak->breakAddress == NULL) { + return TV_ERROR_INVALID_ID; + } + + inst = *whichBreak->breakAddress; + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + *whichBreak->breakAddress = whichBreak->oldInstruction; + osWritebackDCache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); + osInvalICache(whichBreak->breakAddress, sizeof(*whichBreak->breakAddress)); + } + } + whichBreak->breakAddress = NULL; + + /* Send reply */ + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + reply.bp = request->bp; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +u32 __rmonGetBranchTarget(int method, int thread, char* addr) { + int inst; + + if (method == RMON_RSP) { + inst = __rmonReadWordAt((u32*) addr); + } else { + inst = *(u32*) addr; + } + + switch ((inst >> 26) & 0x3F) { + case 0: /* SPECIAL */ + if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { + /* JR */ + return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); + } + if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { + /* JALR */ + return __rmonGetRegisterContents(method, thread, (inst >> 21) & 0x1F); + } + break; + case 1: /* REGIMM */ + switch ((inst >> 16) & 0x1F) { + case 0: /* BLTZ */ + case 1: /* BGEZ */ + case 2: /* BLTZL */ + case 3: /* BGEZL */ + case 16: /* BLTZAL */ + case 17: /* BGEZAL */ + case 18: /* BLTZALL */ + case 19: /* BGEZALL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + } + break; + case 2: /* J */ + case 3: /* JAL */ + return (((u32) inst << 6) >> 4) + (((s32) ((u32) addr + 4) >> 0x1C) << 0x1C); + case 4: /* BEQ */ + case 5: /* BNE */ + case 20: /* BEQL */ + case 21: /* BNEL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + case 6: /* BLEZ */ + case 7: /* BGTZ */ + case 22: /* BLEZL */ + case 23: /* BGTZL */ + if (((inst >> 16) & 0x1F) == 0) { + return (((inst << 0x10) >> 0xE) + addr + 4); + } + break; + case 16: /* COP0 */ + case 17: /* COP1 */ + case 18: /* COP2 */ + case 19: /* COP3 */ + if (((inst >> 21) & 0x1F) == 8) { + switch ((inst >> 16) & 0x1F) { + case 0: /* BCzF */ + case 1: /* BCzT */ + case 2: /* BCzFL */ + case 3: /* BCzTL */ + return (((inst << 0x10) >> 0xE) + addr + 4); + } + } + break; + } + return -1; +} + +int IsJump(u32 inst) { + switch ((inst >> 26) & 0x3F) { + case 0: /* SPECIAL */ + if (((inst >> 5) & 0x7FFF) == 0 && (inst & 0x3F) == 8) { + /* JR */ + return TRUE; + } + if (((inst >> 16) & 0x1F) == 0 && (inst & 0x7FF) == 9) { + /* JALR */ + return TRUE; + } + break; + case 2: /* J */ + case 3: /* JAL */ + return TRUE; + } + return FALSE; +} + +int __rmonSetSingleStep(int thread, u32* instptr) { + u32 branchTarget = __rmonGetBranchTarget(RMON_CPU, thread, (void*) instptr); + + STUBBED_PRINTF(("SingleStep\n")); + + if ((branchTarget & 3) != 0) { + /* no branch target, set breakpoint at next pc */ + SetTempBreakpoint(instptr + 1, NULL); + } else if (branchTarget == (u32) instptr) { + /* branch target is this instruction, can't single step here */ + return FALSE; + } else if (IsJump(*instptr) || branchTarget == (u32) (instptr + 2)) { + /* unconditional branch, set at branch target */ + SetTempBreakpoint((u32*) branchTarget, NULL); + } else { + /* set two breakpoints for handling conditional branches */ + SetTempBreakpoint((u32*) branchTarget, instptr + 2); + } + return TRUE; +} + +void __rmonGetExceptionStatus(KKStatusEvent* reply) { + reply->status.flags = OS_STATE_STOPPED; + reply->status.why = 2; + reply->status.what = 0; + reply->status.rv = 0; + reply->status.info.major = 2; + reply->status.info.minor = 4; + reply->header.code = KK_CODE_THREAD_STATUS; + reply->header.error = TV_ERROR_NO_ERROR; + reply->header.length = sizeof(*reply); +} + +#define FAULT_BREAKNUM (NUM_BREAKPOINTS - 1) + +void rmonSendBreakMessage(s32 whichThread, int breakNumber) { + KKStatusEvent reply; + + STUBBED_PRINTF(("Break %d in thread %d\n", breakNumber, whichThread)); + + /* Build thread exception status */ + __rmonGetThreadStatus(RMON_CPU, (whichThread != 0) ? whichThread : RMON_TID_NOTHREAD, &reply); + __rmonGetExceptionStatus(&reply); + + if (breakNumber == FAULT_BREAKNUM) { + /* Hit fault */ + reply.status.info.major = 1; + reply.status.info.minor = 2; + } + if (breakNumber < NUM_BREAKPOINTS) { + breakNumber = 0; + } else { + breakNumber -= NUM_BREAKPOINTS; + } + if (breakNumber != 0) { + /* Break not set by debugger, or set during single-step */ + reply.status.instr = MIPS_BREAK_OPCODE; + } + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); +} + +void __rmonHitBreak(void) { + STUBBED_PRINTF(("HitBreak\n")); + + /* Stop all user threads and report faulted threads */ + ClearTempBreakpoint(); + __rmonStopUserThreads(0); + rmonFindFaultedThreads(); +} + +void __rmonHitSpBreak(void) { + KKStatusEvent exceptionReply; + + STUBBED_PRINTF(("Hit SP Break\n")); + + /* Rewind RSP PC by one instruction to return to the location of the break instruction */ + __rmonWriteWordTo((u32*) SP_PC_REG, __rmonReadWordAt((u32*) SP_PC_REG) - 4); + + /* Report RSP break event */ + __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); + __rmonGetExceptionStatus(&exceptionReply); + __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); + __rmonRcpAtBreak = TRUE; +} + +void __rmonHitCpuFault(void) { + STUBBED_PRINTF(("HitCpuFault\n")); + + /* Stop all user threads and report faulted threads */ + __rmonMaskIdleThreadInts(); + __rmonStopUserThreads(0); + rmonFindFaultedThreads(); +} + +void rmonFindFaultedThreads(void) { + register OSThread* tptr = __osGetActiveQueue(); + + while (tptr->priority != -1) { + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + if (tptr->flags & OS_FLAG_CPU_BREAK) { + int inst = *(u32*) tptr->context.pc; + + STUBBED_PRINTF(("Brk in thread %d @ %08x, inst %08x\r\n", tptr->id, tptr->context.pc, inst)); + + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + rmonSendBreakMessage(tptr->id, inst >> 6); + } else { + rmonSendBreakMessage(tptr->id, 0); + } + } + if (tptr->flags & OS_FLAG_FAULT) { + __rmonSendFault(tptr); + rmonSendBreakMessage(tptr->id, FAULT_BREAKNUM); + } + } + tptr = tptr->tlnext; + } +} + +#endif diff --git a/src/libultra/rmon/rmoncmds.c b/src/libultra/rmon/rmoncmds.c index a2aa65878..4448b788e 100644 --- a/src/libultra/rmon/rmoncmds.c +++ b/src/libultra/rmon/rmoncmds.c @@ -1,5 +1,54 @@ -#include "common.h" +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmoncmds/__rmoncmd_NotImplemented.s") +#include "dbgproto.h" +#include "rmonint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmoncmds/__rmonExecute.s") +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +static int NotImplemented(KKHeader* dummy UNUSED) { + return TV_ERROR_ILLEGAL_CALL; +} + +static FUNPTR dispatchTable[] = { + __rmonLoadProgram, __rmonListProcesses, __rmonGetExeName, __rmonListThreads, __rmonThreadStatus, + NotImplemented, __rmonStopThread, __rmonRunThread, NotImplemented, NotImplemented, + __rmonSetFault, NotImplemented, __rmonGetRegionCount, __rmonGetRegions, __rmonGetGRegisters, + __rmonSetGRegisters, __rmonGetFRegisters, __rmonSetFRegisters, __rmonReadMem, __rmonWriteMem, + __rmonSetBreak, __rmonClearBreak, __rmonListBreak, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + __rmonSetComm, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, NotImplemented, + NotImplemented, NotImplemented, NotImplemented, NotImplemented, __rmonGetSRegs, + __rmonSetSRegs, __rmonGetVRegs, __rmonSetVRegs, NotImplemented, +}; + +int __rmonExecute(KKHeader* request) { + int retval; + KKHeader reply; + + if (request->code >= ARRLEN(dispatchTable) - 1) { + return TV_ERROR_ILLEGAL_CALL; + } + + retval = dispatchTable[(int) request->code](request); + if (retval < TV_ERROR_NO_ERROR) { + reply.code = request->code; + reply.error = retval; + __rmonSendReply(&reply, sizeof(reply), KK_TYPE_REPLY); + } + return retval; +} + +#endif diff --git a/src/libultra/rmon/rmonmain.c b/src/libultra/rmon/rmonmain.c index 40c46571a..e5ebc4b0a 100644 --- a/src/libultra/rmon/rmonmain.c +++ b/src/libultra/rmon/rmonmain.c @@ -1,9 +1,138 @@ -#include "common.h" +#include "PR/os_version.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmain/__rmonSendHeader.s") +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmain/__rmonSendReply.s") +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmain/__rmonSendData.s") +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "rmonint.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "PR/rdb.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmain/rmonMain.s") +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +int __rmonActive = FALSE; + +static vu32 somethingToDo; +static u32 inbuffer[280] ALIGNED(0x10); +static u8 cmdinptr; +static u8 cmdoutptr; +static int state; +static char* inPointer; + +void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type) { + int sent; + char* cPtr = (char*) block; + + block->rev = KK_REV; + block->type = type; + + sent = 0; + while (sent < blockSize) { + sent += __osRdbSend(cPtr + sent, blockSize - sent, RDB_TYPE_GtoH_DEBUG); + } +} + +void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType) { + char* cPtr; + int sent = 0; + + block->length = blockSize; + cPtr = (char*) &blockSize; + + /* send size */ + while (sent < (signed) sizeof(blockSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(blockSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + /* send data */ + __rmonSendHeader(block, blockSize, replyType); + __rmonIOflush(); +} + +void __rmonSendData(char* const block, unsigned int blockSize) { + int* blockPointer = (int*) block; + unsigned int wordCount = (u32) (blockSize + 3) / 4; + u32 data; + union { + char bufBytes[4]; + u32 bufWord; + } buffer; + + if (((u32) block & 3) == 0) { + while (wordCount--) { + if ((u32) blockPointer >= SP_DMEM_START && (u32) blockPointer < 0x05000000) { + __osSpRawReadIo((u32) blockPointer++, &data); + __rmonIOputw(data); + } else { + __rmonIOputw(*(blockPointer++)); + } + } + } else { + while (wordCount--) { + __rmonMemcpy((u8*) buffer.bufBytes, (u8*) blockPointer, sizeof(buffer)); + __rmonIOputw(buffer.bufWord); + blockPointer++; + } + } + __rmonIOflush(); +} + +void rmonMain(void) { + register int newChars UNUSED; + + STUBBED_PRINTF(("rmon: Thread %d created\n")); + STUBBED_PRINTF(("rmon: Thread %d destroyed\n")); + + somethingToDo = 0; + cmdoutptr = 0; + cmdinptr = 0; + + __rmonInit(); + __rmonActive = TRUE; + + state = 0, newChars = 0, inPointer = (void*) &inbuffer; + for (;;) { + OSMesg work; + + osRecvMesg(&__rmonMQ, &work, OS_MESG_BLOCK); + + somethingToDo |= (u32) work; + + if (somethingToDo & RMON_MESG_CPU_BREAK) { + somethingToDo &= ~RMON_MESG_CPU_BREAK; + __rmonHitBreak(); + } + if (somethingToDo & RMON_MESG_SP_BREAK) { + somethingToDo &= ~RMON_MESG_SP_BREAK; + __rmonHitSpBreak(); + } + if (somethingToDo & RMON_MESG_FAULT) { + somethingToDo &= ~RMON_MESG_FAULT; + __rmonHitCpuFault(); + } + if (somethingToDo & 0x10) { + somethingToDo; + somethingToDo &= (u8) ~0x10; + } + if (somethingToDo & 0x20) { + somethingToDo; + somethingToDo &= (u8) ~0x20; + } + } +} + +#endif diff --git a/src/libultra/rmon/rmonmem.c b/src/libultra/rmon/rmonmem.c index 720b0f170..a807dc3b2 100644 --- a/src/libultra/rmon/rmonmem.c +++ b/src/libultra/rmon/rmonmem.c @@ -1,31 +1,285 @@ -#include "common.h" +#include "PR/os_version.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonWriteWordTo.s") +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonReadWordAt.s") +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonMemcpy.s") +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "rmonint.h" +#include "PR/rdb.h" -void __rmonCopyWords(s32* arg0, s32* arg1, s32 arg2) { - while (arg2--) { - *arg0++ = *arg1++; +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +u8 __rmonUtilityBuffer[256] ALIGNED(8); + +void __rmonWriteWordTo(u32* addr, u32 val) { + while (__osSpRawWriteIo((u32) addr, val) != 0) { + ; } } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonmem_strcopy.s") +u32 __rmonReadWordAt(u32* addr) { + u32 data; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonReadMem.s") + if ((u32) addr >= SP_DMEM_START && (u32) addr < 0x05000000) { + __osSpRawReadIo((u32) addr, &data); + return data; + } + return 0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonWriteMem.s") +void __rmonMemcpy(u8* dest, u8* srce, u32 count) { + while (count--) { + *dest++ = *srce++; + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonListProcesses.s") +void __rmonCopyWords(u32* dest, u32* srce, u32 count) { + while (count--) { + *dest++ = *srce++; + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonLoadProgram.s") +static void strcpy(char* dest, char* srce) { + while ((*dest++ = *srce++)) { + ; + } +} + +int __rmonReadMem(KKHeader* req) { + char* cPtr; + int sent; + int dataSize; + KKReadRequest* request = (KKReadRequest*) req; + KKBufferEvent* reply = (KKBufferEvent*) __rmonUtilityBuffer; + u8* blockStart; + + STUBBED_PRINTF(("ReadMem @ %08x for %d\n", request->addr, request->nbytes)); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/D_800C9660.s") + reply->header.code = request->header.code; + reply->object = request->object; + reply->header.error = TV_ERROR_NO_ERROR; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonGetExeName.s") + if (request->addr == (u32) -1) { + return TV_ERROR_INVALID_ADDRESS; + } + if (request->nbytes > RMON_MAX_XFER_SIZE) { + return TV_ERROR_INVALID_CAPABILITY; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonGetRegionCount.s") + if (req->method == RMON_RSP) { + if (!((request->addr < SP_IMEM_START || (request->addr + request->nbytes) > SP_IMEM_END) ? FALSE : TRUE) && + !((request->addr < SP_DMEM_START || (request->addr + request->nbytes) > SP_DMEM_END) ? FALSE : TRUE)) { + return TV_ERROR_INVALID_ADDRESS; + } + } else if (osVirtualToPhysical((void*) request->addr) == (u32) -1) { + return TV_ERROR_INVALID_ADDRESS; + } + + blockStart = (u8*) request->addr; + reply->header.length = request->nbytes + sizeof(reply->header) + sizeof(reply->object); + dataSize = request->nbytes + sizeof(reply->header) + sizeof(reply->object); + + cPtr = (char*) &dataSize; + sent = 0; + while (sent < (signed) sizeof(dataSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + __rmonSendHeader(&reply->header, sizeof(reply->header) + sizeof(reply->object), KK_TYPE_REPLY); + __rmonSendData(blockStart, request->nbytes); + return TV_ERROR_NO_ERROR; +} + +int __rmonWriteMem(KKHeader* req) { + register KKWriteRequest* request = (KKWriteRequest*) req; + KKObjectEvent reply; + + STUBBED_PRINTF(("WriteMem\n")); + + /* Bad virtual address, abort */ + if (req->method == RMON_CPU && osVirtualToPhysical((u32*) request->writeHeader.addr) == (u32) -1) { + return TV_ERROR_INVALID_ADDRESS; + } + + /* Transfer size too large, abort */ + if (request->writeHeader.nbytes > RMON_MAX_XFER_SIZE) { + return TV_ERROR_INVALID_CAPABILITY; + } + + if (((request->writeHeader.addr < SP_DMEM_START || + (request->writeHeader.addr + request->writeHeader.nbytes) > 0x04FFFFFF) + ? FALSE + : TRUE)) { + int align; + u32 word; + + if ((align = request->writeHeader.addr & 3) != 0) { + STUBBED_PRINTF(("Long unaligned write...\n")); + + if (request->writeHeader.nbytes != 1) { + return TV_ERROR_INVALID_ADDRESS; + } + + /* Unaligned write; read the word, substitute in the written byte, write it back */ + word = __rmonReadWordAt((u32*) (request->writeHeader.addr & ~3)); + if (align == 1) { + word = (word & ~0xFF0000) | (request->buffer[0] << 0x10); + } else if (align == 2) { + word = (word & ~0xFF00) | (request->buffer[0] << 8); + } else { + word = (word & ~0xFF) | (request->buffer[0] << 0); + } + __rmonWriteWordTo((u32*) (request->writeHeader.addr & ~3), word); + } else { + int wordCount = request->writeHeader.nbytes / sizeof(u32); + u32* wordPointer = (u32*) request->buffer; + + if (request->writeHeader.nbytes % sizeof(u32) != 0) { + STUBBED_PRINTF(("RCP write not an integral number of words\n")); + return TV_ERROR_INVALID_ADDRESS; + } + + while (wordCount--) { + __rmonWriteWordTo((u32*) request->writeHeader.addr, *(wordPointer++)); + request->writeHeader.addr += sizeof(*wordPointer); + } + } + } else { + __rmonMemcpy((u8*) request->writeHeader.addr, (u8*) request->buffer, request->writeHeader.nbytes); + } + + reply.header.code = request->writeHeader.header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->writeHeader.object; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonListProcesses(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKObjsEvent reply; + + STUBBED_PRINTF(("ListProcesses\n")); + + reply.object = 0; + reply.objs.number = 1; + reply.objs.objects[0] = (req->method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonLoadProgram(KKHeader* request UNUSED) { + STUBBED_PRINTF(("LoadProgram\n")); + + return TV_ERROR_ILLEGAL_CALL; +} + +int __rmonGetExeName(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKBufferEvent* reply = (KKBufferEvent*) __rmonUtilityBuffer; + + STUBBED_PRINTF(("GetExeName\n")); + + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + reply->object = request->object; + + if (req->method == RMON_RSP) { + strcpy(reply->buffer, "imem"); + } else { + strcpy(reply->buffer, "rmon"); + } + __rmonSendReply(&reply->header, sizeof(reply->header) + sizeof(reply->object) + 8, KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonGetRegionCount(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKNumberEvent reply; + + STUBBED_PRINTF(("GetRegionCount\n")); + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->object; + + reply.number = (req->method == RMON_RSP) ? 2 : 5; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} + +int __rmonGetRegions(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKRegionEvent* reply = (KKRegionEvent*) __rmonUtilityBuffer; + int numRegions; + + STUBBED_PRINTF(("GetRegions\n")); + + numRegions = (req->method == RMON_RSP) ? 2 : 6; + + reply->header.length = numRegions * sizeof(reply->regions[0]) + sizeof(*reply); + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + reply->object = request->object; + reply->number = numRegions; + + reply->regions[1].vaddr = SP_IMEM_START; + reply->regions[1].size = SP_IMEM_END + 1 - SP_IMEM_START; + reply->regions[1].flags = 1 | 2 | 4; + reply->regions[1].paddr = SP_IMEM_START; + + reply->regions[0].vaddr = SP_DMEM_START; + reply->regions[0].size = SP_DMEM_END + 1 - SP_DMEM_START; + reply->regions[0].flags = 1 | 2; + reply->regions[0].paddr = SP_DMEM_START; + + if (numRegions > 2) { + reply->regions[2].vaddr = 0x88200000; + reply->regions[2].size = 0x6130; + reply->regions[2].flags = 1 | 4; + reply->regions[2].paddr = 0; + + reply->regions[3].vaddr = 4; + reply->regions[3].size = 0x200000; + reply->regions[3].flags = 1 | 2; + reply->regions[3].paddr = 0; + + reply->regions[4].vaddr = 0x4002000; + reply->regions[4].size = 0x800000; + reply->regions[4].flags = 1 | 2; + reply->regions[4].paddr = 0; + + reply->regions[5].vaddr = 0x88206130; + reply->regions[5].size = 0x9000; + reply->regions[5].flags = 1 | 2; + reply->regions[5].paddr = 0; + } + + __rmonSendReply(&reply->header, reply->header.length, KK_TYPE_REPLY); + + return TV_ERROR_NO_ERROR; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmem/__rmonGetRegions.s") +#endif diff --git a/src/libultra/rmon/rmonmisc.c b/src/libultra/rmon/rmonmisc.c index f9e874961..4f7efbc0b 100644 --- a/src/libultra/rmon/rmonmisc.c +++ b/src/libultra/rmon/rmonmisc.c @@ -1,15 +1,69 @@ -#include "global.h" +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/sptask.h" #include "rmonint.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmisc/__rmonSetFault.s") +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif + +int __rmonSetFault(KKHeader* req) { + KKFaultRequest* request = (KKFaultRequest*) req; + KKObjectEvent reply; + + STUBBED_PRINTF(("SetFault\n")); + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +OSMesgQueue __rmonMQ ALIGNED(8); +static OSThread rmonIOThread ALIGNED(8); +static OSMesg rmonMsgs[8] ALIGNED(8); +static u64 rmonIOStack[2048] ALIGNED(16); +static OSMesg rmonPiMsgs[8] ALIGNED(8); +static OSMesgQueue rmonPiMQ ALIGNED(8); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmisc/__rmonInit.s") +void __rmonInit(void) { + osCreateMesgQueue(&__rmonMQ, rmonMsgs, ARRLEN(rmonMsgs)); + osSetEventMesg(OS_EVENT_CPU_BREAK, &__rmonMQ, (OSMesg) RMON_MESG_CPU_BREAK); + osSetEventMesg(OS_EVENT_SP_BREAK, &__rmonMQ, (OSMesg) RMON_MESG_SP_BREAK); + osSetEventMesg(OS_EVENT_FAULT, &__rmonMQ, (OSMesg) RMON_MESG_FAULT); + osSetEventMesg(OS_EVENT_THREADSTATUS, &__rmonMQ, NULL); + osCreateThread(&rmonIOThread, 0, (void (*)(void*)) __rmonIOhandler, NULL, rmonIOStack + ARRLEN(rmonIOStack), + OS_PRIORITY_MAX); + osCreatePiManager(OS_PRIORITY_PIMGR, &rmonPiMQ, rmonPiMsgs, ARRLEN(rmonPiMsgs)); + osStartThread(&rmonIOThread); +} + +void __rmonPanic(void) { + STUBBED_PRINTF(("PANIC!!\n")); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmisc/__rmonPanic.s") + for (;;) { + ; + } +} int __rmonSetComm(KKHeader* req) { KKObjectEvent reply; + STUBBED_PRINTF(("SetComm\n")); + reply.header.code = req->code; reply.object = 0; reply.header.error = TV_ERROR_NO_ERROR; @@ -19,4 +73,4 @@ int __rmonSetComm(KKHeader* req) { return TV_ERROR_NO_ERROR; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonmisc/D_800C97D0.s") +#endif diff --git a/src/libultra/rmon/rmonregs.c b/src/libultra/rmon/rmonregs.c index 7ded6bfc9..2ca6b46ac 100644 --- a/src/libultra/rmon/rmonregs.c +++ b/src/libultra/rmon/rmonregs.c @@ -1,48 +1,417 @@ -#include "global.h" +#ifndef _FINALROM + +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" #include "rmonint.h" +#include "PR/rdb.h" +#include "PR/os_version.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonregs_LoadStoreSU.s") +#include "macros.h" -void __rmonregs_LoadStoreSU(int opcode, int regno); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/LoadStoreVU.s") +// TODO: these come from headers +#if BUILD_VERSION >= VERSION_K +#ident "$Revision: 1.4 $" +// This revision was bumped down at K for some reason +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#elif BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#ident "$Revision: 3.71 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -void SetUpForRCPop(int isVector); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/SetUpForRCPop.s") +static u32 RCPpc; +static u32 oldIMEMvalue; +static u32 DMEMbuffer[4] ALIGNED(8); -void CleanupFromRCPop(int isVector); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/CleanupFromRCPop.s") +typedef union { + u32 everything; + struct { + int opcode : 6; + int base : 5; + int rt : 5; + int offset : 16; + } scalarop; + struct { + int opcode : 6; + int base : 5; + int rt : 5; + int size : 5; + int element : 4; + int offset : 7; + } vectorop; +} INSTRUCTION; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonGetGRegisters.s") +void LoadStoreSU(int opcode, int regno) { + INSTRUCTION inst; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonSetGRegisters.s") + /* Prepare a scalar load or store instruction at DMEM address 0 */ + inst.everything = 0; + inst.scalarop.opcode = opcode; + inst.scalarop.rt = regno; + __rmonWriteWordTo((u32*) SP_IMEM_START, inst.everything); + __rmonWriteWordTo((u32*) SP_PC_REG, 0); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonGetFRegisters.s") +void LoadStoreVU(int opcode, int regno) { + INSTRUCTION inst; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonSetFRegisters.s") + /* Prepare a vector 128-bit load or store instruction at DMEM address 0 */ + inst.everything = 0; + inst.vectorop.opcode = opcode; + inst.vectorop.rt = regno; + inst.vectorop.size = 4; /* LQV / SQV */ + __rmonWriteWordTo((u32*) SP_IMEM_START, inst.everything); + __rmonWriteWordTo((u32*) SP_PC_REG, 0); +} -s32 rmonGetRcpRegister(s32 arg0) { - s32 ret; +void SetUpForRCPop(int isVector) { + /* Save RSP data that would be overwritten when reading or writing registers */ + RCPpc = __rmonReadWordAt((u32*) SP_PC_REG); + oldIMEMvalue = __rmonReadWordAt((u32*) SP_IMEM_START); + DMEMbuffer[0] = __rmonReadWordAt((u32*) SP_DMEM_START); + if (isVector) { + DMEMbuffer[1] = __rmonReadWordAt((u32*) (SP_DMEM_START + 0x4)); + DMEMbuffer[2] = __rmonReadWordAt((u32*) (SP_DMEM_START + 0x8)); + DMEMbuffer[3] = __rmonReadWordAt((u32*) (SP_DMEM_START + 0xC)); + } +} - if (__rmonRCPrunning() != 0) { - return 0; +void CleanupFromRCPop(int isVector) { + /* Restore RSP data that was saved to read or write registers */ + __rmonWriteWordTo((u32*) SP_DMEM_START, DMEMbuffer[0]); + if (isVector) { + __rmonWriteWordTo((u32*) (SP_DMEM_START + 0x4), DMEMbuffer[1]); + __rmonWriteWordTo((u32*) (SP_DMEM_START + 0x8), DMEMbuffer[2]); + /* BUG: the last word is not restored properly */ + __rmonWriteWordTo((u32*) (SP_DMEM_START + 0xC), DMEMbuffer[2]); + } + __rmonWriteWordTo((u32*) SP_IMEM_START, oldIMEMvalue); + __rmonWriteWordTo((u32*) SP_PC_REG, RCPpc); +} + +int __rmonGetGRegisters(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*) req; + KKGregEvent reply; + + STUBBED_PRINTF(("GetGRegisters\n")); + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + if (request->header.method == RMON_CPU) { + OSThread* tptr = __rmonGetTCB(request->object); + u64* tcbregptr; + register s32 i; + + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { + reply.registers.gregs[i] = *tcbregptr; + } + for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { + reply.registers.gregs[i] = *tcbregptr; + } + + reply.registers.gregs[GREG_IDX_CAUSE] = tptr->context.cause; + reply.registers.gregs[GREG_IDX_PC] = tptr->context.pc; + reply.registers.gregs[GREG_IDX_SR] = tptr->context.sr; + reply.registers.gregs[GREG_IDX_ZERO] = 0; } else { - SetUpForRCPop(0); - __rmonregs_LoadStoreSU(0x2B, arg0); + return TV_ERROR_INVALID_ID; + } + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetGRegisters(KKHeader* req) { + register KKGRegsetRequest* request = (KKGRegsetRequest*) req; + KKObjectEvent reply; + + STUBBED_PRINTF(("SetGRegisters\n")); + + if (request->header.method == RMON_CPU) { + OSThread* tptr = __rmonGetTCB(request->tid); + u64* tcbregptr; + register int i; + + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + for (i = GREG_IDX_AT, tcbregptr = &tptr->context.at; i < GREG_IDX_K0; i++, tcbregptr++) { + *tcbregptr = (s32) request->registers.gregs[i]; + } + + for (i = GREG_IDX_GP, tcbregptr = &tptr->context.gp; i < GREG_IDX_CAUSE; i++, tcbregptr++) { + *tcbregptr = (s32) request->registers.gregs[i]; + } + + tptr->context.cause = request->registers.gregs[GREG_IDX_CAUSE]; + tptr->context.pc = request->registers.gregs[GREG_IDX_PC]; + tptr->context.sr = request->registers.gregs[GREG_IDX_SR]; + } else { + return TV_ERROR_INVALID_ID; + } + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetFRegisters(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*) req; + KKFPregEvent reply; + OSThread* tptr; + volatile float f UNUSED; + + STUBBED_PRINTF(("GetFRegisters\n")); + + if (req->method != RMON_CPU) { + return TV_ERROR_INVALID_ID; + } + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tptr = __rmonGetTCB(request->object); + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + __rmonCopyWords((u32*) reply.registers.fpregs.regs, (u32*) &tptr->context.fp0, ARRLEN(reply.registers.fpregs.regs)); + + reply.registers.fpcsr = tptr->context.fpcsr; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.tid = request->object; + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetFRegisters(KKHeader* req) { + register KKFPRegsetRequest* request = (KKFPRegsetRequest*) req; + KKObjectEvent reply; + OSThread* tptr; + volatile float f UNUSED; + + STUBBED_PRINTF(("SetFRegisters\n")); + + if (req->method != RMON_CPU) { + return TV_ERROR_INVALID_ID; + } + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tptr = __rmonGetTCB(request->tid); + if (tptr == NULL) { + return TV_ERROR_INVALID_ID; + } + + __rmonCopyWords((u32*) &tptr->context.fp0, (u32*) request->registers.fpregs.regs, + ARRLEN(request->registers.fpregs.regs)); + tptr->context.fpcsr = request->registers.fpcsr; + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +u32 rmonGetRcpRegister(int regNumber) { + u32 contents; + + if (__rmonRCPrunning()) { + return 0; + } + + SetUpForRCPop(FALSE); + LoadStoreSU(MIPS_SW_OPCODE, regNumber); + __rmonStepRCP(); + contents = __rmonReadWordAt((u32*) SP_DMEM_START); + CleanupFromRCPop(FALSE); + + return contents; +} + +int __rmonGetSRegs(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*) req; + KKCpSregEvent reply; + register int i; + + STUBBED_PRINTF(("GetSRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + + SetUpForRCPop(FALSE); + for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { + LoadStoreSU(MIPS_SW_OPCODE, i); + __rmonStepRCP(); + reply.registers.sregs[i] = __rmonReadWordAt((u32*) SP_DMEM_START); + } + CleanupFromRCPop(FALSE); + + reply.registers.sregs[SREG_IDX_DRAM_ADDR] = __rmonReadWordAt((u32*) SP_DRAM_ADDR_REG); + reply.registers.sregs[SREG_IDX_MEM_ADDR] = __rmonReadWordAt((u32*) SP_MEM_ADDR_REG); + reply.registers.sregs[SREG_IDX_RD_LEN] = __rmonReadWordAt((u32*) SP_RD_LEN_REG); + reply.registers.sregs[SREG_IDX_PC] = __rmonReadWordAt((u32*) SP_PC_REG) + SP_IMEM_START; + reply.registers.sregs[SREG_IDX_WR_LEN] = __rmonReadWordAt((u32*) SP_WR_LEN_REG); + reply.registers.sregs[SREG_IDX_STATUS] = __rmonReadWordAt((u32*) SP_STATUS_REG); + reply.registers.sregs[SREG_IDX_DMA_FULL] = __rmonReadWordAt((u32*) SP_DMA_FULL_REG); + reply.registers.sregs[SREG_IDX_DMA_BUSY] = __rmonReadWordAt((u32*) SP_DMA_BUSY_REG); + + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonSetSRegs(KKHeader* req) { + register KKCpScalarRegsetRequest* request = (KKCpScalarRegsetRequest*) req; + KKObjectEvent reply; + register int i; + + STUBBED_PRINTF(("SetSRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + SetUpForRCPop(FALSE); + for (i = SREG_IDX_ZERO; i <= SREG_IDX_RA; i++) { + __rmonWriteWordTo((u32*) SP_DMEM_START, request->registers.sregs[i]); + LoadStoreSU(MIPS_LW_OPCODE, i); __rmonStepRCP(); - ret = __rmonReadWordAt((u32*) SP_DMEM_START); - CleanupFromRCPop(0); - return ret; } + CleanupFromRCPop(FALSE); + + __rmonWriteWordTo((u32*) SP_DRAM_ADDR_REG, request->registers.sregs[SREG_IDX_DRAM_ADDR]); + __rmonWriteWordTo((u32*) SP_MEM_ADDR_REG, request->registers.sregs[SREG_IDX_MEM_ADDR]); + __rmonWriteWordTo((u32*) SP_PC_REG, request->registers.sregs[SREG_IDX_PC] & 0xFFF); + __rmonWriteWordTo((u32*) SP_WR_LEN_REG, request->registers.sregs[SREG_IDX_WR_LEN]); + __rmonWriteWordTo((u32*) SP_STATUS_REG, request->registers.sregs[SREG_IDX_STATUS]); + + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetVRegs(KKHeader* req) { + char* cPtr; + int sent; + int dataSize; + register KKObjectRequest* request = (KKObjectRequest*) req; + KKCpVregEvent reply; + register int i; + + STUBBED_PRINTF(("GetVRegisters\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.tid = request->object; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.header.length = sizeof(reply); + + dataSize = sizeof(reply); + cPtr = (char*) &dataSize; + sent = 0; + while (sent < (signed) sizeof(dataSize)) { + sent += __osRdbSend(cPtr + sent, sizeof(dataSize) - sent, RDB_TYPE_GtoH_DEBUG); + } + + __rmonSendHeader(&reply.header, VREG_SIZE, KK_TYPE_REPLY); + + SetUpForRCPop(TRUE); + for (i = 0; i < VREG_NUM; i++) { + LoadStoreVU(MIPS_SWC2_OPCODE, i); + __rmonStepRCP(); + __rmonSendData((void*) SP_DMEM_START, VREG_SIZE); + } + CleanupFromRCPop(TRUE); + + return TV_ERROR_NO_ERROR; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonGetSRegs.s") +int __rmonSetVRegs(KKHeader* req) { + register KKCpVectorRegsetRequest* request = (KKCpVectorRegsetRequest*) req; + KKObjectEvent reply; + register int i; + + STUBBED_PRINTF(("SetVRegs\n")); + + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonSetSRegs.s") + SetUpForRCPop(TRUE); + for (i = 0; i < VREG_NUM; i++) { + __rmonCopyWords((u32*) SP_DMEM_START, (u32*) &request->registers.vregs[i], VREG_SIZE / sizeof(u32)); + LoadStoreVU(MIPS_LWC2_OPCODE, i); + __rmonStepRCP(); + } + CleanupFromRCPop(TRUE); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonGetVRegs.s") + reply.object = request->tid; + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonSetVRegs.s") +u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber) { + if (method == RMON_CPU) { + /* CPU register */ + u32* regPointer; + OSThread* tptr; -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/__rmonGetRegisterContents.s") + if (regNumber >= GREG_IDX_AT && regNumber < GREG_IDX_K0) { + regNumber -= GREG_IDX_AT - GREG_IDX_ZERO; + } else if (regNumber >= GREG_IDX_GP && regNumber < GREG_IDX_LO) { + regNumber -= GREG_IDX_GP - GREG_IDX_T9; + } else { + return 0; + } + tptr = __rmonGetTCB(threadNumber); + if (tptr == NULL) { + return 0; + } + regPointer = (u32*) &tptr->context; + regPointer += regNumber; + return *regPointer; + } else { + /* RSP register */ + return rmonGetRcpRegister(regNumber); + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonregs/D_800C9800.s") +#endif diff --git a/src/libultra/rmon/rmonsio.c b/src/libultra/rmon/rmonsio.c index 465a30010..70b2ec847 100644 --- a/src/libultra/rmon/rmonsio.c +++ b/src/libultra/rmon/rmonsio.c @@ -1,9 +1,89 @@ -#include "common.h" +#include "PR/os_version.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonsio/__rmonSendFault.s") +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonsio/__rmonIOflush.s") +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonsio/__rmonIOputw.s") +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/ultralog.h" +#include "PR/sptask.h" +#include "dbgproto.h" +#include "rmonint.h" +#include "PR/ramrom.h" +#include "PR/rdb.h" +#include "PR/rmon.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmonsio/__rmonIOhandler.s") +#include "macros.h" + +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#endif + +static OSMesgQueue IOmq ALIGNED(8); +static OSMesg IOmsgs; + +void* __osRdb_DbgRead_Buf; +u8 rmonRdbReadBuf[RMON_DBG_BUF_SIZE] ALIGNED(0x10); + +void __rmonSendFault(OSThread* thread) { + volatile float f UNUSED; + u8* tPtr; + u32 sent = 0; + + /* touch fpu to ensure registers are saved to the context structure */ + f = 0.0f; + + tPtr = (u8*) thread; + while (sent < sizeof(OSThread)) { + sent += __osRdbSend(tPtr + sent, sizeof(OSThread) - sent, RDB_TYPE_GtoH_FAULT); + } +} + +void __rmonIOflush(void) { + int sent = 0; + char tstr[4]; + + while (sent <= 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_DONE); + } +} + +void __rmonIOputw(u32 word) { + int sent = 0; + char* cPtr = (char*) &word; + + while (sent < 4) { + sent += __osRdbSend(cPtr + sent, sizeof(word) - sent, RDB_TYPE_GtoH_DEBUG); + } +} + +void __rmonIOhandler(void) { + int sent; + char tstr[4]; + + osCreateMesgQueue(&IOmq, &IOmsgs, 1); + osSetEventMesg(OS_EVENT_RDB_DBG_DONE, &IOmq, NULL); + __osRdb_DbgRead_Buf = rmonRdbReadBuf; + + while (TRUE) { + osRecvMesg(&IOmq, NULL, OS_MESG_BLOCK); + + __rmonExecute((KKHeader*) &rmonRdbReadBuf); + __osRdb_DbgRead_Buf = rmonRdbReadBuf; + + sent = 0; + while (sent <= 0) { + sent += __osRdbSend(tstr, 1, RDB_TYPE_GtoH_DEBUG_READY); + } + } +} + +#endif diff --git a/src/libultra/rmon/rmontask.c b/src/libultra/rmon/rmontask.c index ece49c694..3d951cb38 100644 --- a/src/libultra/rmon/rmontask.c +++ b/src/libultra/rmon/rmontask.c @@ -1,17 +1,344 @@ -#include "common.h" +#ifndef _FINALROM -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonMaskIdleThreadInts.s") +#include "dbgproto.h" +#include "PR/os_internal.h" +#include "rmonint.h" +#include "PR/rcp.h" +#include "PR/sptask.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonGetTCB.s") +#include "macros.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonStopUserThreads.s") +// TODO: this comes from a header +#if BUILD_VERSION >= VERSION_J +#ident "$Revision: 1.4 $" +#else +#ident "$Revision: 3.70 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.2 $" +#ident "$Revision: 1.4 $" +#ident "$Revision: 1.3 $" +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonListThreads.s") +void __rmonMaskIdleThreadInts(void) { + register OSThread* tptr = __osGetActiveQueue(); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonGetThreadStatus.s") + while (tptr->priority != -1) { + if (tptr->priority == OS_PRIORITY_IDLE) { + tptr->context.sr &= ~OS_IM_CPU; + tptr->context.sr |= (OS_IM_RDBREAD | OS_IM_RDBWRITE | OS_IM_CART); + break; + } + tptr = tptr->tlnext; + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonThreadStatus.s") +OSThread* __rmonGetTCB(int threadNumber) { + register OSThread* tptr = __osGetActiveQueue(); -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonStopThread.s") + if (threadNumber < 1) { + return NULL; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/rmon/rmontask/__rmonRunThread.s") + while (tptr->priority != -1) { + if (tptr->id == threadNumber) { + return tptr; + } + tptr = tptr->tlnext; + } + + return NULL; +} + +int __rmonStopUserThreads(int whichThread) { + register int whichOne = 0; + register OSThread* tptr = __osGetActiveQueue(); + + STUBBED_PRINTF(("StopThreads %d\n", whichThread)); + + if (whichThread != 0) { + /* Stop specified thread */ + + while (tptr->priority != -1) { + if (tptr->id == whichThread) { + break; + } + tptr = tptr->tlnext; + } + + if (tptr->priority == -1) { + return 0; + } + + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + osStopThread(tptr); + if (tptr->state != OS_STATE_STOPPED) { + STUBBED_PRINTF(("Couldn't stop thread %d\n", tptr->id)); + } + whichOne = whichThread; + } + } else { + /* Stop all threads */ + + while (tptr->priority != -1) { + if (tptr->priority > OS_PRIORITY_IDLE && tptr->priority <= OS_PRIORITY_APPMAX) { + osStopThread(tptr); + if (tptr->state != OS_STATE_STOPPED) { + STUBBED_PRINTF(("Couldn\'t stop thread %d\n", tptr->id)); + } + whichOne = -1; + } + tptr = tptr->tlnext; + } + } + return whichOne; +} + +int __rmonListThreads(KKHeader* req) { + register KKObjectRequest* request = (KKObjectRequest*) req; + KKObjsEvent* reply = (KKObjsEvent*) __rmonUtilityBuffer; + + STUBBED_PRINTF(("ListThreads\n")); + + reply->object = (request->object == -1) ? RMON_PID_CPU : request->object; + + if (req->method == RMON_RSP) { + reply->objs.number = 1; + reply->objs.objects[0] = RMON_TID_RSP; + } else { + register OSThread* tptr = __osGetActiveQueue(); + + reply->objs.number = 0; + + while (tptr->priority != -1) { + if (tptr->id != 0) { + reply->objs.objects[reply->objs.number] = tptr->id; + reply->objs.number++; + } + tptr = tptr->tlnext; + } + } + reply->header.code = request->header.code; + reply->header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply->header, sizeof(*reply) + sizeof(reply->objs.objects[0]) * (reply->objs.number - 1), + KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply) { + u32 inst; + + STUBBED_PRINTF(("ThreadStatus %d method %d\n", id, method)); + + reply->status.tid = id; + reply->status.pid = (method == RMON_RSP) ? RMON_PID_RSP : RMON_PID_CPU; + reply->status.why = 1; + reply->status.what = 0; + reply->status.info.major = 0; + reply->status.info.minor = 0; + reply->status.rv = 0; + + if (method == RMON_RSP) { + reply->status.start = SP_IMEM_START; + reply->status.priority = RMON_PRI_RSP; + + if (__rmonRCPrunning()) { + reply->status.flags = OS_STATE_RUNNING; + /* Cannot read RSP PC or current instruction while the RSP is running */ + reply->status.info.addr = 0; + reply->status.instr = 0; + } else { + reply->status.flags = OS_STATE_STOPPED; + reply->status.info.addr = __rmonReadWordAt((u32*) SP_PC_REG) + SP_IMEM_START; + inst = __rmonReadWordAt((u32*) reply->status.info.addr); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + inst = MIPS_BREAK_OPCODE; + } + if (__rmonRcpAtBreak) { + /* Report RSP break */ + reply->status.why = 2; + reply->status.info.major = 2; + reply->status.info.minor = 4; + } + reply->status.instr = inst; + } + } else { + OSThread* tptr = __osGetActiveQueue(); + + while (tptr->priority != -1) { + if (tptr->id == id) { + break; + } + tptr = tptr->tlnext; + } + if (tptr->priority == -1) { + return TV_ERROR_INVALID_ID; + } + + reply->status.priority = tptr->priority; + reply->status.flags = (tptr->state != 0) ? tptr->state : OS_STATE_STOPPED; + reply->status.info.addr = tptr->context.pc; + + inst = *(u32*) (tptr->context.pc); + if ((inst & MIPS_BREAK_MASK) == MIPS_BREAK_OPCODE) { + inst = MIPS_BREAK_OPCODE; + } + + reply->status.instr = inst; + reply->status.start = (int) tptr; + + if (tptr->flags & OS_FLAG_CPU_BREAK) { + /* Report break */ + reply->status.why = 2; + reply->status.info.major = 2; + reply->status.info.minor = 4; + } else if (tptr->flags & OS_FLAG_FAULT) { + /* Report fault */ + reply->status.why = 2; + reply->status.info.major = 1; + reply->status.info.minor = 2; + } + } + + return TV_ERROR_NO_ERROR; +} + +int __rmonThreadStatus(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKStatusEvent reply; + + if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { + return TV_ERROR_INVALID_ID; + } + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + return TV_ERROR_NO_ERROR; +} + +int __rmonStopThread(KKHeader* req) { + KKObjectRequest* request = (KKObjectRequest*) req; + KKStatusEvent reply; + u32* pc; + + STUBBED_PRINTF(("StopThread %d\n", request->object)); + + switch (req->method) { + case RMON_CPU: + __rmonStopUserThreads(request->object); + break; + case RMON_RSP: + if (__rmonRCPrunning()) { + /* Stop the rsp */ + __rmonIdleRCP(); + pc = (u32*) __rmonReadWordAt((u32*) SP_PC_REG); + if (pc == NULL) { + break; + } + pc--; + /* Check if the RSP is stopped in a branch delay slot, if it is step out of it. The RSP would otherwise + lose information about whether the branch should or should not be taken when reading registers. */ + if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, (void*) ((u32) pc + SP_IMEM_START)) % 4 == 0) { + __rmonStepRCP(); + } + } + break; + default: + return TV_ERROR_OPERATIONS_PROTECTED; + } + + if (__rmonGetThreadStatus(req->method, request->object, &reply) != TV_ERROR_NO_ERROR) { + return TV_ERROR_INVALID_ID; + } + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + if (reply.status.flags == OS_STATE_STOPPED) { + reply.header.code = KK_CODE_THREAD_STATUS; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_EXCEPTION); + } + return TV_ERROR_NO_ERROR; +} + +int __rmonRunThread(KKHeader* req) { + KKRunThreadRequest* request = (KKRunThreadRequest*) req; + KKObjectEvent reply; + KKStatusEvent exceptionReply; + register OSThread* tptr; + register int runNeeded = FALSE; + + STUBBED_PRINTF(("RunThread %d\n", request->tid)); + + switch (req->method) { + case RMON_CPU: + tptr = __osGetActiveQueue(); + while (tptr->priority != -1) { + if (tptr->id == request->tid) { + break; + } + tptr = tptr->tlnext; + } + + if (tptr->priority == -1) { + return TV_ERROR_INVALID_ID; + } + if (tptr->state != OS_STATE_STOPPED) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + tptr->flags &= ~(OS_FLAG_CPU_BREAK | OS_FLAG_FAULT); + if (request->actions.flags & KK_RUN_SETPC) { + tptr->context.pc = request->actions.vaddr; + } + if ((request->actions.flags & KK_RUN_SSTEP) && + !__rmonSetSingleStep(request->tid, (u32*) tptr->context.pc)) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + runNeeded = TRUE; + break; + case RMON_RSP: + if (__rmonRCPrunning()) { + return TV_ERROR_OPERATIONS_PROTECTED; + } + if (request->actions.flags & KK_RUN_SETPC) { + __rmonWriteWordTo((u32*) SP_PC_REG, request->actions.vaddr - SP_IMEM_START); + } + if (request->actions.flags & KK_RUN_SSTEP) { + /* If the RSP is stopped at a branch step twice so as to not stop in a branch delay slot. */ + if (__rmonGetBranchTarget(RMON_RSP, RMON_TID_RSP, + (void*) (__rmonReadWordAt((u32*) SP_PC_REG) + SP_IMEM_START)) % + 4 == + 0) { + __rmonStepRCP(); + } + __rmonStepRCP(); + __rmonRcpAtBreak = TRUE; + } else { + __rmonRcpAtBreak = FALSE; + __rmonRunRCP(); + } + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + if (request->actions.flags & KK_RUN_SSTEP) { + __rmonGetThreadStatus(RMON_RSP, RMON_TID_RSP, &exceptionReply); + __rmonGetExceptionStatus(&exceptionReply); + __rmonSendReply(&exceptionReply.header, sizeof(exceptionReply), KK_TYPE_EXCEPTION); + } + return TV_ERROR_NO_ERROR; + default: + return TV_ERROR_OPERATIONS_PROTECTED; + } + + reply.header.code = request->header.code; + reply.header.error = TV_ERROR_NO_ERROR; + reply.object = request->tid; + __rmonSendReply(&reply.header, sizeof(reply), KK_TYPE_REPLY); + + if (runNeeded) { + osStartThread(tptr); + } + return 1; +} + +#endif diff --git a/src/libultra/vimodes/vimodempallan1.c b/src/libultra/vimodes/vimodempallan1.c new file mode 100644 index 000000000..f645186fb --- /dev/null +++ b/src/libultra/vimodes/vimodempallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/viint.h" + +OSViMode osViModeMpalLan1 = { + OS_VI_MPAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 30, 5, 70), // burst + VSYNC(525), // vSync + HSYNC(3089, 4), // hSync + LEAP(3097, 3098), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/src/libultra/vimodes/vimodentsclan1.c b/src/libultra/vimodes/vimodentsclan1.c new file mode 100644 index 000000000..8139cdf86 --- /dev/null +++ b/src/libultra/vimodes/vimodentsclan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/viint.h" + +OSViMode osViModeNtscLan1 = { + OS_VI_NTSC_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(57, 34, 5, 62), // burst + VSYNC(525), // vSync + HSYNC(3093, 0), // hSync + LEAP(3093, 3093), // leap + HSTART(108, 748), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(37, 511), // vStart + BURST(4, 2, 14, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/src/libultra/vimodes/vimodepallan1.c b/src/libultra/vimodes/vimodepallan1.c new file mode 100644 index 000000000..b2882c92d --- /dev/null +++ b/src/libultra/vimodes/vimodepallan1.c @@ -0,0 +1,37 @@ +#include "PR/os.h" +#include "PR/rcp.h" +#include "PR/viint.h" + +OSViMode osViModePalLan1 = { + OS_VI_PAL_LAN1, // type + { + // comRegs + VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON | VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | + VI_CTRL_PIXEL_ADV_3, // ctrl + WIDTH(320), // width + BURST(58, 30, 4, 69), // burst + VSYNC(625), // vSync + HSYNC(3177, 23), // hSync + LEAP(3183, 3181), // leap + HSTART(128, 768), // hStart + SCALE(2, 0), // xScale + VCURRENT(0), // vCurrent + }, + { // fldRegs + { + // [0] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + }, + { + // [1] + ORIGIN(640), // origin + SCALE(1, 0), // yScale + HSTART(95, 569), // vStart + BURST(107, 2, 9, 0), // vBurst + VINTR(2), // vIntr + } }, +}; diff --git a/src/main/fox_360.c b/src/main/fox_360.c index a691636ed..26a61309f 100644 --- a/src/main/fox_360.c +++ b/src/main/fox_360.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "global.h" typedef struct { diff --git a/src/main/fox_hud.c b/src/main/fox_hud.c index 8c899252e..aadb60b20 100644 --- a/src/main/fox_hud.c +++ b/src/main/fox_hud.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "sf64math.h" // BSS section range: diff --git a/src/main/sys_fault.c b/src/main/sys_fault.c index f65b3941d..6ac6d778e 100644 --- a/src/main/sys_fault.c +++ b/src/main/sys_fault.c @@ -104,7 +104,7 @@ void func_8000762C(s32 arg0, s32 arg1, const char* fmt, ...) { sp40[i] = 0; } - if (_Printf(func_80007604, sp40, fmt, args) <= 0) { + if (_Printf((outfun*) func_80007604, sp40, fmt, args) <= 0) { return; } for (var_s0 = sp40; *var_s0 != 0; var_s0++) { diff --git a/src/main/sys_sprintf.c b/src/main/sys_sprintf.c index 783164768..33df713d5 100644 --- a/src/main/sys_sprintf.c +++ b/src/main/sys_sprintf.c @@ -7,7 +7,7 @@ void* proutSprintf(void* dst, const char* fmt, size_t size) { } s32 vsprintf(char* dst, const char* fmt, va_list args) { - s32 ret = _Printf(proutSprintf, dst, fmt, args); + s32 ret = _Printf((outfun*) proutSprintf, dst, fmt, args); if (ret > -1) { dst[ret] = 0; @@ -20,7 +20,7 @@ int sprintf(char* s, const char* fmt, ...) { va_list args; va_start(args, fmt); - ret = _Printf(proutSprintf, s, fmt, args); + ret = _Printf((outfun*) proutSprintf, s, fmt, args); if (ret >= 0) { s[ret] = 0; diff --git a/src/overlays/ovl_i4/fox_bo.c b/src/overlays/ovl_i4/fox_bo.c index ce8f33d1c..5c88880d9 100644 --- a/src/overlays/ovl_i4/fox_bo.c +++ b/src/overlays/ovl_i4/fox_bo.c @@ -1,3 +1,5 @@ +#include "prevent_bss_reordering.h" +#include "prevent_bss_reordering2.h" #include "global.h" typedef struct UnkStruct_D_i4_801A03E0 { diff --git a/src/overlays/ovl_menu/fox_map.c b/src/overlays/ovl_menu/fox_map.c index 0fc995a78..599646470 100644 --- a/src/overlays/ovl_menu/fox_map.c +++ b/src/overlays/ovl_menu/fox_map.c @@ -5,7 +5,8 @@ */ #include "mods.h" -// #include "prevent_bss_reordering.h" +#include "prevent_bss_reordering.h" +#include "prevent_bss_reordering2.h" #include "global.h" #include "fox_map.h" #include "fox_option.h" diff --git a/yamls/us/main.yaml b/yamls/us/main.yaml index 797fc0d11..0b814685c 100644 --- a/yamls/us/main.yaml +++ b/yamls/us/main.yaml @@ -213,24 +213,27 @@ - [0xC8880, .data, sys_sprintf] # DATA - Libultra - - [0xC88C0, data, ../libultra/io/controller] - - [0xC88D0, data, ../libultra/io/vimgr] - - [0xC89E0, data, ../libultra/io/pimgr] - - [0xC8A10, data, ../libultra/os/initialize] - - [0xC8A30, data, ../libultra/libc/xprintf] - - [0xC8A80, data, ../libultra/io/aisetnextbuf] - - [0xC8A90, data, ../libultra/io/siacs] - - [0xC8AA0, data, ../libultra/os/thread] + - [0xC88C0, .data, ../libultra/io/controller] + - [0xC88D0, .data, ../libultra/vimodes/vimodentsclan1] + - [0xC8920, .data, ../libultra/vimodes/vimodepallan1] + - [0xC8970, .data, ../libultra/vimodes/vimodempallan1] + - [0xC89DC, .data, ../libultra/io/vimgr] + - [0xC89E0, .data, ../libultra/io/pimgr] + - [0xC8A10, .data, ../libultra/os/initialize] + - [0xC8A30, .data, ../libultra/libc/xprintf] + - [0xC8A80, .data, ../libultra/io/aisetnextbuf] + - [0xC8A90, .data, ../libultra/io/siacs] + - [0xC8AA0, .data, ../libultra/os/thread] - [0xC8AC0, data, ../libultra/os/exceptasm] - - [0xC8AE0, data, ../libultra/io/vi] - - [0xC8B50, data, ../libultra/os/timerintr] - - [0xC8B60, data, ../libultra/io/piacs] - - [0xC8B70, data, ../libultra/os/rdbsend] - - [0xC8B80, data, ../libultra/libc/xlitob] - - [0xC8BB0, data, ../libultra/debug/kdebugserver] - - [0xC8BC0, data, ../libultra/host/readhost] - - [0xC8BD0, data, ../libultra/rmon/rmoncmds] - - [0xC8CB0, data, ../libultra/rmon/rmonmain] + - [0xC8AE0, .data, ../libultra/io/vi] + - [0xC8B50, .data, ../libultra/os/timerintr] + - [0xC8B60, .data, ../libultra/io/piacs] + - [0xC8B70, .data, ../libultra/os/rdbsend] + - [0xC8B80, .data, ../libultra/libc/xlitob] + - [0xC8BB0, .data, ../libultra/debug/kdebugserver] + - [0xC8BC0, .data, ../libultra/host/readhost] + - [0xC8BD0, .data, ../libultra/rmon/rmoncmds] + - [0xC8CB0, .data, ../libultra/rmon/rmonmain] # RODATA - Nintendo Libraries - [0xC8CC0, .rodata, sys_math] @@ -257,6 +260,7 @@ - [0xCA180, .rodata, ../libultra/libc/xldtob] - [0xCA1E0, rodata, ../libultra/os/setintmask] - [0xCA260, .rodata, ../libultra/rmon/rmonmem] + - [0xCA330, .rodata, ../libultra/rmon/rmontask] - [0xCA3D0, .rodata, ../libultra/rmon/rmonmisc] - [0xCA400, .rodata, ../libultra/rmon/rmonregs] - [0xCA480, .rodata, ../libultra/rmon/rmonbrk] @@ -331,30 +335,30 @@ - { type: bss, vram: 0x80145D40, name: sys_audio } # Libultra bss - - { type: bss, vram: 0x80156620, name: ../libultra/io/controller } - - { type: bss, vram: 0x801566B0, name: ../libultra/io/motor } - - { type: bss, vram: 0x801568F0, name: ../libultra/os/seteventmesg } - - { type: bss, vram: 0x801569B0, name: ../libultra/io/sptask } - - { type: bss, vram: 0x801569F0, name: ../libultra/io/vimgr } - - { type: bss, vram: 0x80157C10, name: ../libultra/io/pimgr } - - { type: bss, vram: 0x801593D0, name: ../libultra/os/initialize } - - { type: bss, vram: 0x801593E0, name: ../libultra/io/conteepread } - - { type: bss, vram: 0x80159420, name: ../libultra/io/cartrominit } - - { type: bss, vram: 0x801594A0, name: ../libultra/io/siacs } - - { type: bss, vram: 0x801594C0, name: ../libultra/io/pfsisplug } - - { type: bss, vram: 0x80159500, name: ../libultra/os/timerintr } - - { type: bss, vram: 0x80159560, name: ../libultra/io/leodiskinit } - - { type: bss, vram: 0x801595E0, name: ../libultra/io/piacs } - - { type: bss, vram: 0x80159600, name: ../libultra/debug/kdebugserver } - - { type: bss, vram: 0x801597C0, name: ../libultra/host/readhost } - - { type: bss, vram: 0x801597F0, name: ../libultra/rmon/rmonsio } - - { type: bss, vram: 0x8015A010, name: ../libultra/os/initrdb } - - { type: bss, vram: 0x8015A030, name: ../libultra/io/leointerrupt } - - { type: bss, vram: 0x8015B030, name: ../libultra/rmon/rmonmem } - - { type: bss, vram: 0x8015B130, name: ../libultra/rmon/rmonmisc } - - { type: bss, vram: 0x8015F350, name: ../libultra/rmon/rmonregs } - - { type: bss, vram: 0x8015F370, name: ../libultra/rmon/rmonbrk } - - { type: bss, vram: 0x8015F480, name: ../libultra/rmon/rmonmain } + - { type: .bss, vram: 0x80156620, name: ../libultra/io/controller } + - { type: .bss, vram: 0x801566B0, name: ../libultra/io/motor } + - { type: .bss, vram: 0x801568F0, name: ../libultra/os/seteventmesg } + - { type: .bss, vram: 0x801569B0, name: ../libultra/io/sptask } + - { type: .bss, vram: 0x801569F0, name: ../libultra/io/vimgr } + - { type: .bss, vram: 0x80157C10, name: ../libultra/io/pimgr } + - { type: .bss, vram: 0x801593D0, name: ../libultra/os/initialize } + - { type: .bss, vram: 0x801593E0, name: ../libultra/io/conteepread } + - { type: .bss, vram: 0x80159420, name: ../libultra/io/cartrominit } + - { type: .bss, vram: 0x801594A0, name: ../libultra/io/siacs } + - { type: .bss, vram: 0x801594C0, name: ../libultra/io/pfsisplug } + - { type: .bss, vram: 0x80159500, name: ../libultra/os/timerintr } + - { type: .bss, vram: 0x80159560, name: ../libultra/io/leodiskinit } + - { type: .bss, vram: 0x801595E0, name: ../libultra/io/piacs } + - { type: .bss, vram: 0x80159600, name: ../libultra/debug/kdebugserver } + - { type: .bss, vram: 0x801597C0, name: ../libultra/host/readhost } + - { type: .bss, vram: 0x801597F0, name: ../libultra/rmon/rmonsio } + - { type: .bss, vram: 0x8015A010, name: ../libultra/os/initrdb } + - { type: .bss, vram: 0x8015A030, name: ../libultra/io/leointerrupt } + - { type: .bss, vram: 0x8015B030, name: ../libultra/rmon/rmonmem } + - { type: .bss, vram: 0x8015B130, name: ../libultra/rmon/rmonmisc } + - { type: .bss, vram: 0x8015F350, name: ../libultra/rmon/rmonregs } + - { type: .bss, vram: 0x8015F370, name: ../libultra/rmon/rmonbrk } + - { type: .bss, vram: 0x8015F480, name: ../libultra/rmon/rmonmain } # Game engine bss - { type: .bss, vram: 0x8015F900, name: fox_360 }