Matched most of the os folder (#6)

This commit is contained in:
Mr-Wiseguy
2021-12-25 14:39:40 -05:00
committed by GitHub
parent a5a2256f1e
commit 3099cf8258
49 changed files with 2355 additions and 31 deletions

View File

@@ -82,6 +82,12 @@ ifneq ($(NON_MATCHING),1)
@touch $@
endif
$(BUILD_DIR)/src/os/assert.marker: OPTFLAGS := -O0
$(BUILD_DIR)/src/os/ackramromread.marker: OPTFLAGS := -O0
$(BUILD_DIR)/src/os/ackramromwrite.marker: OPTFLAGS := -O0
$(BUILD_DIR)/src/os/exit.marker: OPTFLAGS := -O0
$(BUILD_DIR)/src/os/seterrorhandler.marker: OPTFLAGS := -O0
$(BUILD_DIR)/%.marker: %.c
cd $(<D) && $(WORKING_DIR)/$(CC) $(CFLAGS) $(OPTFLAGS) -I $(WORKING_DIR)/include $(<F) -o $(WORKING_DIR)/$(@:.marker=.o)
ifneq ($(NON_MATCHING),1)

981
include/PR/os.h Normal file

File diff suppressed because it is too large Load Diff

106
include/PR/os_internal.h Normal file
View File

@@ -0,0 +1,106 @@
/**************************************************************************
*
* $Revision: 1.18 $
* $Date: 1997/02/11 08:26:14 $
* $Source: /hosts/liberte/disk6/Master/cvsmdev2/PR/include/os_internal.h,v $
*
**************************************************************************/
#ifndef _OS_INTERNAL_H_
#define _OS_INTERNAL_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
#include "PR/os.h"
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
#include "os_internal_reg.h"
#include "os_internal_exception.h"
/* Routines to get/fetch coprocessor 0 registers */
extern u32 __osGetCause(void);
extern void __osSetCause(u32);
extern u32 __osGetCompare(void);
extern void __osSetCompare(u32);
extern u32 __osGetConfig(void);
extern void __osSetConfig(u32);
extern void __osSetCount(u32);
extern u32 __osGetSR(void);
extern void __osSetSR(u32);
extern u32 __osDisableInt(void);
extern void __osRestoreInt(u32);
/* Routines to get/set floating-point control and status register */
extern u32 __osSetFpcCsr(u32);
extern u32 __osGetFpcCsr(void);
/* Routine for global interrupt mask */
extern void __osSetGlobalIntMask(OSHWIntr);
extern void __osResetGlobalIntMask(OSHWIntr);
/* Routine for global interrupt mask */
extern s32 __osLeoInterrupt(void);
/* Routines for fetch TLB info */
extern u32 __osGetTLBASID(void);
extern u32 __osGetTLBPageMask(s32);
extern u32 __osGetTLBHi(s32);
extern u32 __osGetTLBLo0(s32);
extern u32 __osGetTLBLo1(s32);
/* Serial interface (Si) */
extern u32 __osSiGetStatus(void);
extern s32 __osSiRawWriteIo(u32, u32);
extern s32 __osSiRawReadIo(u32, u32 *);
extern s32 __osSiRawStartDma(s32, void *);
/* Signal processor interface (Sp) */
extern u32 __osSpGetStatus(void);
extern void __osSpSetStatus(u32);
extern s32 __osSpSetPc(u32);
extern s32 __osSpRawWriteIo(u32, u32);
extern s32 __osSpRawReadIo(u32, u32 *);
extern s32 __osSpRawStartDma(s32, u32, void *, u32);
/* Error handling */
extern void __osError(s16, s16, ...);
extern OSThread * __osGetCurrFaultedThread(void);
extern OSThread * __osGetNextFaultedThread(OSThread *);
/* Development board functions */
extern void __osGIOInit(s32);
extern void __osGIOInterrupt(s32);
extern void __osGIORawInterrupt(s32);
/* For debugger use */
extern OSThread * __osGetActiveQueue(void);
/* Debug port */
extern void __osSyncPutChars(int, int, const char *);
extern int __osSyncGetChars(char *);
extern void __osAsyncPutChars(int, int, const char *);
extern int __osAsyncGetChars(char *);
extern int __osAtomicInc(unsigned int *p);
extern int __osAtomicDec(unsigned int *p);
/* routine for rdb port */
extern u32 __osRdbSend(u8 *buf, u32 size, u32 type);
#endif /* _LANGUAGE_C */
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* !_OS_INTERNAL_H */

View File

@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------*
$RCSfile: os_internal_exception.h,v $
$Revision: 1.1 $
$Date: 1998/10/09 08:01:10 $
*---------------------------------------------------------------------*/
#ifndef _OS_INTERNAL_EXCEPTION_H_
#define _OS_INTERNAL_EXCEPTION_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
#include "PR/os.h"
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
/* Routine for HW interrupt "handler" */
extern void __osSetHWIntrRoutine(OSHWIntr interrupt,
s32 (*handler)(void), void *stackEnd);
extern void __osGetHWIntrRoutine(OSHWIntr interrupt,
s32 (**handler)(void), void **stackEnd);
/* Routine for global interrupt mask */
extern void __osSetGlobalIntMask(OSHWIntr);
extern void __osResetGlobalIntMask(OSHWIntr);
#endif /* _LANGUAGE_C */
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* !_OS_INTERNAL_EXCEPTION_H */

View File

@@ -0,0 +1,46 @@
/*---------------------------------------------------------------------*
$RCSfile: os_internal_reg.h,v $
$Revision: 1.2 $
$Date: 1999/03/10 12:19:14 $
*---------------------------------------------------------------------*/
#ifndef _OS_INTERNAL_REG_H_
#define _OS_INTERNAL_REG_H_
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
#include "PR/os.h"
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
/* Routines to get/fetch coprocessor 0 registers */
extern u32 __osGetCause(void);
extern void __osSetCause(u32);
extern u32 __osGetCompare(void);
extern void __osSetCompare(u32);
extern u32 __osGetConfig(void);
extern void __osSetConfig(u32);
extern void __osSetCount(u32);
extern u32 __osGetSR(void);
extern void __osSetSR(u32);
extern u32 __osDisableInt(void);
extern void __osRestoreInt(u32);
extern u32 __osGetWatchLo(void);
extern void __osSetWatchLo(u32);
/* Routines to get/set floating-point control and status register */
extern u32 __osSetFpcCsr(u32);
extern u32 __osGetFpcCsr(void);
#endif /* _LANGUAGE_C */
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* !_OS_INTERNAL_REG_H */

View File

@@ -66,6 +66,10 @@
#define RDRAM_0_DEVICE_ID 0
#define RDRAM_1_DEVICE_ID 1
#define RDRAM_RESET_MODE 0
#define RDRAM_ACTIVE_MODE 1
#define RDRAM_STANDBY_MODE 2
#define RDRAM_LENGTH (2 * 512 * 2048)
#define RDRAM_0_BASE_ADDRESS (RDRAM_0_DEVICE_ID * RDRAM_LENGTH)
#define RDRAM_1_BASE_ADDRESS (RDRAM_1_DEVICE_ID * RDRAM_LENGTH)
@@ -74,9 +78,46 @@
#define RDRAM_1_CONFIG 0x00400
#define RDRAM_GLOBAL_CONFIG 0x80000
#define RDRAM_RESET_MODE 0
#define RDRAM_ACTIVE_MODE 1
#define RDRAM_STANDBY_MODE 2
/**
* PIF Physical memory map (total size = 2 KB)
*
* Size Description Mode
* 1FC007FF +-------+-----------------+-----+
* | 64 B | JoyChannel RAM | R/W |
* 1FC007C0 +-------+-----------------+-----+
* |1984 B | Boot ROM | * | * = Reserved
* 1FC00000 +-------+-----------------+-----+
*/
#define PIF_ROM_START 0x1FC00000
#define PIF_ROM_END 0x1FC007BF
#define PIF_RAM_START 0x1FC007C0
#define PIF_RAM_END 0x1FC007FF
/**
* 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
*/
#define CHNL_ERR_NORESP 0x80 /* Bit 7 (Rx): No response error */
#define CHNL_ERR_OVERRUN 0x40 /* Bit 6 (Rx): Overrun error */
#define CHNL_ERR_FRAME 0x80 /* Bit 7 (Tx): Frame error */
#define CHNL_ERR_COLLISION 0x40 /* Bit 6 (Tx): Collision error */
#define CHNL_ERR_MASK 0xC0 /* Bit 6-7: channel errors */
/**
* External device info
*/
#define DEVICE_TYPE_CART 0 /* ROM cartridge */
#define DEVICE_TYPE_BULK 1 /* ROM bulk */
#define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */
#define DEVICE_TYPE_SRAM 3 /* SRAM */
/* 4-6 are reserved */
#define DEVICE_TYPE_INIT 7 /* initial value */
/* 8-14 are reserved */
/**
* Signal Processor (SP) Memory
@@ -87,7 +128,7 @@
#define SP_IMEM_END 0x04001FFF
/**
* Signal Processor (SP) Registers
* Signal Processor (SP) CP0 Registers
*/
#define SP_BASE_REG 0x04040000
@@ -119,9 +160,6 @@
//! SP PC (R/W): [11:0] program counter
#define SP_PC_REG 0x04080000
//! SP IMEM BIST REG (R/W): [6:0] BIST status bits
#define SP_IBIST_REG 0x04080004
/**
* SP_MEM_ADDR_REG: bit 12
*/
@@ -195,6 +233,11 @@
#define SP_SET_CPUSIGNAL SP_SET_SIG4
#define SP_STATUS_CPUSIGNAL SP_STATUS_SIG4
/*
* SP IMEM BIST REG (R/W): [6:0] BIST status bits; see below for detail
*/
#define SP_IBIST_REG 0x04080004
/*
* SP_IBIST_REG: write bits
*/
@@ -749,20 +792,23 @@
#define SI_STATUS_INTERRUPT (1 << 12) // Interrupt is set
/**
* PIF Physical memory map (total size = 2 KB)
*
* Size Description Mode
* 1FC007FF +-------+-----------------+-----+
* | 64 B | JoyChannel RAM | R/W |
* 1FC007C0 +-------+-----------------+-----+
* |1984 B | Boot ROM | * | * = Reserved
* 1FC00000 +-------+-----------------+-----+
* Development Board GIO Control Registers
*/
#define PIF_ROM_START 0x1FC00000
#define PIF_ROM_END 0x1FC007BF
#define PIF_RAM_START 0x1FC007C0
#define PIF_RAM_END 0x1FC007FF
#define GIO_BASE_REG 0x18000000
/* Game to Host Interrupt */
#define GIO_GIO_INTR_REG (GIO_BASE_REG+0x000)
/* Game to Host SYNC */
#define GIO_GIO_SYNC_REG (GIO_BASE_REG+0x400)
/* Host to Game Interrupt */
#define GIO_CART_INTR_REG (GIO_BASE_REG+0x800)
/**
* Common macros
*/
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
#define IO_READ(addr) (*(vu32*)PHYS_TO_K1(addr))
#define IO_WRITE(addr,data) (*(vu32*)PHYS_TO_K1(addr)=(u32)(data))

93
include/PR/rdb.h Normal file
View File

@@ -0,0 +1,93 @@
/**************************************************************************
*
* $Revision: 1.6 $
* $Date: 1997/02/11 08:29:31 $
* $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rdb.h,v $
*
**************************************************************************/
#ifndef _RDB_H
#define _RDB_H
/* U64 side address */
#define RDB_BASE_REG 0xc0000000
#define RDB_WRITE_INTR_REG (RDB_BASE_REG + 0x8)
#define RDB_READ_INTR_REG (RDB_BASE_REG + 0xc)
#define RDB_BASE_VIRTUAL_ADDR 0x80000000
/* packet type Have six bits, so can have up to 63 types */
#define RDB_TYPE_INVALID 0
#define RDB_TYPE_GtoH_PRINT 1
#define RDB_TYPE_GtoH_FAULT 2
#define RDB_TYPE_GtoH_LOG_CT 3
#define RDB_TYPE_GtoH_LOG 4
#define RDB_TYPE_GtoH_READY_FOR_DATA 5
#define RDB_TYPE_GtoH_DATA_CT 6
#define RDB_TYPE_GtoH_DATA 7
#define RDB_TYPE_GtoH_DEBUG 8
#define RDB_TYPE_GtoH_RAMROM 9
#define RDB_TYPE_GtoH_DEBUG_DONE 10
#define RDB_TYPE_GtoH_DEBUG_READY 11
#define RDB_TYPE_GtoH_KDEBUG 12
#define RDB_TYPE_GtoH_PROF_DATA 22
#define RDB_TYPE_HtoG_LOG_DONE 13
#define RDB_TYPE_HtoG_DEBUG 14
#define RDB_TYPE_HtoG_DEBUG_CT 15
#define RDB_TYPE_HtoG_DATA 16
#define RDB_TYPE_HtoG_DATA_DONE 17
#define RDB_TYPE_HtoG_REQ_RAMROM 18
#define RDB_TYPE_HtoG_FREE_RAMROM 19
#define RDB_TYPE_HtoG_KDEBUG 20
#define RDB_TYPE_HtoG_PROF_SIGNAL 21
#define RDB_PROF_ACK_SIG 1
#define RDB_PROF_FLUSH_SIG 2
#define PROF_BLOCK_SIZE 2048
#define RDB_LOG_MAX_BLOCK_SIZE 0x8000
#define RDB_DATA_MAX_BLOCK_SIZE 0x8000
/* GIO side address */
#define GIO_RDB_BASE_REG 0xbf480000
#define GIO_RDB_WRITE_INTR_REG (GIO_RDB_BASE_REG + 0x8)
#define GIO_RDB_READ_INTR_REG (GIO_RDB_BASE_REG + 0xc)
/* minor device number */
#define GIO_RDB_PRINT_MINOR 1
#define GIO_RDB_DEBUG_MINOR 2
/* interrupt bit */
#define GIO_RDB_WRITE_INTR_BIT 0x80000000
#define GIO_RDB_READ_INTR_BIT 0x40000000
/* debug command */
#define DEBUG_COMMAND_NULL 0
#define DEBUG_COMMAND_MEMORY 1
#define DEBUG_COMMAND_REGISTER 2
#define DEBUG_COMMAND_INVALID 255
/* debug state */
#define DEBUG_STATE_NULL 0
#define DEBUG_STATE_RECEIVE 1
#define DEBUG_STATE_INVALID 255
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
/* Structure for debug port */
typedef struct {
unsigned type : 6; /* 0: invalid, 1: print, 2: debug */
unsigned length : 2; /* 1, 2, or 3 */
char buf[3]; /* character buffer */
} rdbPacket;
extern unsigned int __osRdbWriteOK;
extern unsigned int __osRdbSendMessage;
#endif /* _LANGUAGE_C */
#endif /* !_RDB_H */

145
include/PR/ultraerror.h Normal file
View File

@@ -0,0 +1,145 @@
/**************************************************************************
*
* $Revision: 1.23 $
* $Date: 1997/02/11 08:38:08 $
* $Source: /hosts/liberte/disk6/Master/cvsmdev2/PR/include/ultraerror.h,v $
*
**************************************************************************/
#ifndef __ULTRAERROR_H__
#define __ULTRAERROR_H__
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
#include "PR/ultratypes.h"
#define OS_ERROR_FMT "/usr/lib/PR/error.fmt"
#define OS_ERROR_MAGIC 0x6b617479
/* OS error codes */
#define ERR_OSCREATETHREAD_SP 1
#define ERR_OSCREATETHREAD_PRI 2
#define ERR_OSSTARTTHREAD 3
#define ERR_OSSETTHREADPRI 4
#define ERR_OSCREATEMESGQUEUE 5
#define ERR_OSSENDMESG 6
#define ERR_OSJAMMESG 7
#define ERR_OSRECVMESG 8
#define ERR_OSSETEVENTMESG 9
#define ERR_OSMAPTLB_INDEX 10
#define ERR_OSMAPTLB_ASID 11
#define ERR_OSUNMAPTLB 12
#define ERR_OSSETTLBASID 13
#define ERR_OSAISETFREQUENCY 14
#define ERR_OSAISETNEXTBUFFER_ADDR 15
#define ERR_OSAISETNEXTBUFFER_SIZE 16
#define ERR_OSDPSETNEXTBUFFER_ADDR 17
#define ERR_OSDPSETNEXTBUFFER_SIZE 18
#define ERR_OSPIRAWREADIO 19
#define ERR_OSPIRAWWRITEIO 20
#define ERR_OSPIRAWSTARTDMA_DIR 21
#define ERR_OSPIRAWSTARTDMA_DEVADDR 22
#define ERR_OSPIRAWSTARTDMA_ADDR 23
#define ERR_OSPIRAWSTARTDMA_SIZE 24
#define ERR_OSPIRAWSTARTDMA_RANGE 25
#define ERR_OSPIREADIO 26
#define ERR_OSPIWRITEIO 27
#define ERR_OSPISTARTDMA_PIMGR 28
#define ERR_OSPISTARTDMA_PRI 29
#define ERR_OSPISTARTDMA_DIR 30
#define ERR_OSPISTARTDMA_DEVADDR 31
#define ERR_OSPISTARTDMA_ADDR 32
#define ERR_OSPISTARTDMA_SIZE 33
#define ERR_OSPISTARTDMA_RANGE 34
#define ERR_OSCREATEPIMANAGER 35
#define ERR_OSVIGETCURRENTMODE 36
#define ERR_OSVIGETCURRENTFRAMEBUFFER 37
#define ERR_OSVIGETNEXTFRAMEBUFFER 38
#define ERR_OSVISETXSCALE_VALUE 39
#define ERR_OSVISETXSCALE_VIMGR 40
#define ERR_OSVISETYSCALE_VALUE 41
#define ERR_OSVISETYSCALE_VIMGR 42
#define ERR_OSVISETSPECIAL_VALUE 43
#define ERR_OSVISETSPECIAL_VIMGR 44
#define ERR_OSVISETMODE 45
#define ERR_OSVISETEVENT 46
#define ERR_OSVISWAPBUFFER_ADDR 47
#define ERR_OSVISWAPBUFFER_VIMGR 48
#define ERR_OSCREATEVIMANAGER 49
#define ERR_OSCREATEREGION_ALIGN 50
#define ERR_OSCREATEREGION_SIZE 51
#define ERR_OSMALLOC 52
#define ERR_OSFREE_REGION 53
#define ERR_OSFREE_ADDR 54
#define ERR_OSGETREGIONBUFCOUNT 55
#define ERR_OSGETREGIONBUFSIZE 56
#define ERR_OSSPTASKLOAD_DRAM 57
#define ERR_OSSPTASKLOAD_OUT 58
#define ERR_OSSPTASKLOAD_OUTSIZE 59
#define ERR_OSSPTASKLOAD_YIELD 60
#define ERR_OSPROFILEINIT_STR 61
#define ERR_OSPROFILEINIT_CNT 62
#define ERR_OSPROFILEINIT_ALN 63
#define ERR_OSPROFILEINIT_ORD 64
#define ERR_OSPROFILEINIT_SIZ 65
#define ERR_OSPROFILESTART_TIME 66
#define ERR_OSPROFILESTART_FLAG 67
#define ERR_OSPROFILESTOP_FLAG 68
#define ERR_OSPROFILESTOP_TIMER 69
#define ERR_OSREADHOST_ADDR 70
#define ERR_OSREADHOST_SIZE 71
#define ERR_OSWRITEHOST_ADDR 72
#define ERR_OSWRITEHOST_SIZE 73
#define ERR_OSGETTIME 74
#define ERR_OSSETTIME 75
#define ERR_OSSETTIMER 76
#define ERR_OSSTOPTIMER 77
#define ERR_ALSEQP_NO_SOUND 100
#define ERR_ALSEQP_NO_VOICE 101
#define ERR_ALSEQP_MAP_VOICE 102
#define ERR_ALSEQP_OFF_VOICE 103
#define ERR_ALSEQP_POLY_VOICE 104
#define ERR_ALSNDP_NO_VOICE 105
#define ERR_ALSYN_NO_UPDATE 106
#define ERR_ALSNDPDEALLOCATE 107
#define ERR_ALSNDPDELETE 108
#define ERR_ALSNDPPLAY 109
#define ERR_ALSNDPSETSOUND 110
#define ERR_ALSNDPSETPRIORITY 111
#define ERR_ALSNDPSETPAR 112
#define ERR_ALBNKFNEW 113
#define ERR_ALSEQNOTMIDI 114
#define ERR_ALSEQNOTMIDI0 115
#define ERR_ALSEQNUMTRACKS 116
#define ERR_ALSEQTIME 117
#define ERR_ALSEQTRACKHDR 118
#define ERR_ALSEQSYSEX 119
#define ERR_ALSEQMETA 120
#define ERR_ALSEQPINVALIDPROG 121
#define ERR_ALSEQPUNKNOWNMIDI 122
#define ERR_ALSEQPUNMAP 123
#define ERR_ALEVENTNOFREE 124
#define ERR_ALHEAPNOFREE 125
#define ERR_ALHEAPCORRUPT 126
#define ERR_ALHEAPFIRSTBLOCK 127
#define ERR_ALCSEQZEROSTATUS 128
#define ERR_ALCSEQZEROVEL 129
#define ERR_ALCSPVNOTFREE 130
#define ERR_ALSEQOVERRUN 131
#define ERR_OSAISETNEXTBUFFER_ENDADDR 132
#define ERR_ALMODDELAYOVERFLOW 133
#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS)
typedef void (*OSErrorHandler)(s16, s16, ...);
OSErrorHandler osSetErrorHandler(OSErrorHandler);
#endif
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* __ULTRAERROR_H__ */

8
src/os/ackramromread.c Normal file
View File

@@ -0,0 +1,8 @@
#include "PR/os_internal.h"
// TODO: this comes from a header
#ident "$Revision: 1.4 $"
void osAckRamromRead() {
}

8
src/os/ackramromwrite.c Normal file
View File

@@ -0,0 +1,8 @@
#include "PR/os_internal.h"
// TODO: this comes from a header
#ident "$Revision: 1.4 $"
void osAckRamromWrite() {
}

5
src/os/assert.c Normal file
View File

@@ -0,0 +1,5 @@
#include "PR/os_internal.h"
void __assert(const char *exp, const char *filename, int line) {
osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp);
}

15
src/os/atomic.c Normal file
View File

@@ -0,0 +1,15 @@
#include "PR/os_internal.h"
int __osAtomicDec(unsigned int *p) {
register u32 saveMask = __osDisableInt();
int mask;
if (*p) {
(*p)--;
mask = 1;
} else {
mask = 0;
}
__osRestoreInt(saveMask);
return mask;
}

11
src/os/createmesgqueue.c Normal file
View File

@@ -0,0 +1,11 @@
#include "PR/os_internal.h"
#include "osint.h"
void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 msgCount) {
mq->mtqueue = &__osThreadTail.next;
mq->fullqueue = &__osThreadTail.next;
mq->validCount = 0;
mq->first = 0;
mq->msgCount = msgCount;
mq->msg = msg;
}

27
src/os/createthread.c Normal file
View File

@@ -0,0 +1,27 @@
#include "PR/os_internal.h"
#include "PR/R4300.h"
#include "osint.h"
void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri p) {
register u32 saveMask;
OSIntMask mask;
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 = (u64)__osCleanupThread;
mask = OS_IM_ALL;
t->context.sr = SR_IMASK | SR_EXL | SR_IE;
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;
saveMask = __osDisableInt();
t->tlnext = __osActiveQueue;
__osActiveQueue = t;
__osRestoreInt(saveMask);
}

37
src/os/destroythread.c Normal file
View File

@@ -0,0 +1,37 @@
#include "PR/os_internal.h"
#include "osint.h"
void osDestroyThread(OSThread *t) {
register u32 saveMask;
register OSThread *pred;
register OSThread *succ;
saveMask = __osDisableInt();
if (t == NULL) {
t = __osRunningThread;
} else if (t->state != OS_STATE_STOPPED) {
__osDequeueThread(t->queue, t);
}
if (__osActiveQueue == t) {
__osActiveQueue = __osActiveQueue->tlnext;
} else {
pred = __osActiveQueue;
while (pred->priority != -1) {
succ = pred->tlnext;
if (succ == t) {
pred->tlnext = t->tlnext;
break;
}
pred = succ;
succ = pred->tlnext;
}
}
if (t == __osRunningThread) {
__osDispatchThread();
}
__osRestoreInt(saveMask);
}

8
src/os/exit.c Normal file
View File

@@ -0,0 +1,8 @@
#include "PR/os_internal.h"
void osExit() {
__osGIOInterrupt(16);
for (;;);
}

6
src/os/getactivequeue.c Normal file
View File

@@ -0,0 +1,6 @@
#include "PR/os_internal.h"
#include "osint.h"
OSThread *__osGetActiveQueue(void) {
return __osActiveQueue;
}

View File

@@ -0,0 +1,6 @@
#include "PR/os_internal.h"
#include "osint.h"
OSThread *__osGetCurrFaultedThread() {
return __osFaultedThread;
}

35
src/os/getmemsize.c Normal file
View File

@@ -0,0 +1,35 @@
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PR/R4300.h"
#define STEP 0x100000
#define SIZE_4MB 0x400000
#define SIZE_8MB 0x800000
u32 osGetMemSize(void) {
vu32* ptr;
u32 size = SIZE_4MB;
u32 data0;
u32 data1;
while (size < SIZE_8MB) {
ptr = (vu32*)(K1BASE + size);
data0 = *ptr;
data1 = ptr[STEP / 4 - 1];
*ptr ^= ~0;
ptr[STEP / 4 - 1] ^= ~0;
if ((*ptr != (data0 ^ ~0)) || (ptr[STEP / 4 - 1] != (data1 ^ ~0))) {
return size;
}
*ptr = data0;
ptr[STEP / 4 - 1] = data1;
size += STEP;
}
return size;
}

View File

@@ -0,0 +1,28 @@
#include "PR/os_internal.h"
#include "osint.h"
OSThread *__osGetNextFaultedThread(OSThread *lastFault) {
register int saveMask = __osDisableInt();
register OSThread *fault;
if (lastFault == NULL) {
fault = __osActiveQueue;
} else {
fault = lastFault;
}
while (fault->priority != -1) {
if ((fault->flags & OS_FLAG_FAULT) != 0 && fault != lastFault) {
break;
}
fault = fault->tlnext;
}
if (fault->priority == -1) {
fault = NULL;
}
__osRestoreInt(saveMask);
return fault;
}

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