Skip to content

Commit

Permalink
General docs + cleanup (#84)
Browse files Browse the repository at this point in the history
* osCreateThread small cleanup

* osViSetSpecialFeatures

Co-authored-by: Tharo <[email protected]>

* osAiSetNextBuffer

Co-authored-by: Tharo <[email protected]>

* macros.h move to PRinternal.h

* dbgproto.h and dbgdefs.h moved to PRinternal

* Align OSPifRAM struct

Co-authored-by: Tharo <[email protected]>

* LAN1 vimode comments

Co-authored-by: Tharo <[email protected]>

* Stack macros

* Hex for all ALIGNED macros

* leoDiskSTack ALIGNED(0x10)

* interrupt bug

Co-authored-by: Tharo <[email protected]>

* ASM comment

* Revert "LAN1 vimode comments"

This reverts commit bed467a.

* STACK_START

* FPCSR_RM_RN

---------

Co-authored-by: Tharo <[email protected]>
  • Loading branch information
hensldm and Thar0 authored Aug 20, 2024
1 parent bf1f007 commit bcca1c8
Show file tree
Hide file tree
Showing 74 changed files with 186 additions and 149 deletions.
4 changes: 3 additions & 1 deletion include/PRinternal/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include "PR/os_version.h"
#include "PR/rcp.h"

#include "PRinternal/macros.h"

#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4)

typedef struct
{
/* 0x0 */ u32 ramarray[15];
/* 0x3C */ u32 pifstatus;
} OSPifRam;
} OSPifRam ALIGNED(0x10);

typedef struct
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion include/dbgproto.h → include/PRinternal/dbgproto.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _DBGPROTO_H__
#define _DBGPROTO_H__

#include "dbgdefs.h"
#include "PRinternal/dbgdefs.h"

#define KK_REV 2

Expand Down
8 changes: 8 additions & 0 deletions include/macros.h → include/PRinternal/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
#define __attribute__(x)
#endif

#define ALIGN8(val) (((val) + 7) & ~7)

#define STACK(stack, size) \
u64 stack[ALIGN8(size) / sizeof(u64)]

#define STACK_START(stack) \
((u8*)(stack) + sizeof(stack))

#endif
2 changes: 1 addition & 1 deletion include/PRinternal/rmonint.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _RMONINT_H
#define _RMONINT_H

#include "dbgproto.h"
#include "PRinternal/dbgproto.h"
#include "PR/os_internal.h"

/* mips */
Expand Down
10 changes: 5 additions & 5 deletions src/debug/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#include "PR/ultralog.h"
#include "PR/sptask.h"
#include "PRinternal/osint.h"
#include "macros.h"
#include "PRinternal/macros.h"
#include "osint_debug.h"

#ifndef _FINALROM

OSTimer __osProfTimer;
OSMesg __osProfTimerMsg;

OSMesgQueue __osProfFlushMQ ALIGNED(8);
OSMesgQueue __osProfFlushMQ ALIGNED(0x8);
OSMesg __osProfFlushMesg;

OSMesgQueue __osProfAckMQ ALIGNED(8);
OSMesgQueue __osProfAckMQ ALIGNED(0x8);
OSMesg __osProfAckMesg;

u32 __osProfTimerPeriod;
Expand All @@ -26,7 +26,7 @@ u32 __osProfNumSections;
static u32 __osProfileActive = FALSE;
static u32 __osProfileIOActive = FALSE;

unsigned char __osProfileIOStack[2400] ALIGNED(16);
STACK(__osProfileIOStack, 0x960) ALIGNED(0x10);

static OSThread __osProfileIOThread;

Expand Down Expand Up @@ -130,7 +130,7 @@ void osProfileInit(OSProf* profp, u32 profcnt) {
osSetEventMesg(OS_EVENT_RDB_FLUSH_PROF, &__osProfFlushMQ, 0);
osCreateMesgQueue(&__osProfAckMQ, &__osProfAckMesg, 1);
osSetEventMesg(OS_EVENT_RDB_ACK_PROF, &__osProfAckMQ, 0);
osCreateThread(&__osProfileIOThread, 0, __osProfileIO, NULL, &__osProfileIOStack[2400], 0x81);
osCreateThread(&__osProfileIOThread, 0, __osProfileIO, NULL, STACK_START(__osProfileIOStack), 0x81);
osStartThread(&__osProfileIOThread);
__osProfileIOActive = TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/debug/threadprofile.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "osint_debug.h"

#include "macros.h"
#include "PRinternal/macros.h"

s32 __osThprofFlag = 0;
void (*__osThprofFunc)(OSThread*) = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/error/commonerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include "PR/sptask.h"
#include "PR/ultraerror.h"
#include "PR/ultralog.h"
#include "macros.h"
#include "PRinternal/macros.h"
#include "stdarg.h"

#ifndef _FINALROM

void __osSyncVPrintf(const char* fmt, va_list args);

static u32 errorLogData[19] ALIGNED(8);
static u32 errorLogData[19] ALIGNED(0x8);
static OSLog errorLog = {
OS_ERROR_MAGIC, // magic
sizeof(errorLogData), // len
Expand Down
6 changes: 3 additions & 3 deletions src/error/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include "PR/os_internal.h"
#include "PR/ultralog.h"
#include "PR/ultraerror.h"
#include "macros.h"
#include "PRinternal/macros.h"

void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr);
static void __osDefaultHandler(s16 code, s16 numArgs, ...);

static u32 errorLogData[19] ALIGNED(8);
static OSLog errorLog ALIGNED(8) = {
static u32 errorLogData[19] ALIGNED(0x8);
static OSLog errorLog ALIGNED(0x8) = {
OS_ERROR_MAGIC, // magic
sizeof(errorLogData), // len
errorLogData, // base
Expand Down
10 changes: 5 additions & 5 deletions src/flash/flashinit.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "ultra64.h"
#include "PR/os_internal_flash.h"
#include "macros.h"
#include "PRinternal/macros.h"

u32 __osFlashID[4] ALIGNED(8);
OSIoMesg __osFlashMsg ALIGNED(8);
OSMesgQueue __osFlashMessageQ ALIGNED(8);
OSPiHandle __osFlashHandler ALIGNED(8);
u32 __osFlashID[4] ALIGNED(0x8);
OSIoMesg __osFlashMsg ALIGNED(0x8);
OSMesgQueue __osFlashMessageQ ALIGNED(0x8);
OSPiHandle __osFlashHandler ALIGNED(0x8);
OSMesg __osFlashMsgBuf[1];
s32 __osFlashVersion;

Expand Down
4 changes: 2 additions & 2 deletions src/gt/dumpturbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <ultra64.h>
#include <gt.h>
#include "macros.h"
#include "PRinternal/macros.h"

#if BUILD_VERSION < VERSION_J
#ident "$Revision: 1.4 $"
Expand All @@ -29,7 +29,7 @@


#define TX_MAX 100
static u32 textures[TX_MAX] ALIGNED(8);
static u32 textures[TX_MAX] ALIGNED(0x8);
static u32 numtextures;

#define UNSEG_ADDR(sa) ((u32 *) (((globp)? \
Expand Down
4 changes: 2 additions & 2 deletions src/gu/loadtextureblockmipmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "guint.h"
#include <stdio.h>
#include "ultra64.h"
#include "macros.h"
#include "PRinternal/macros.h"

// TODO: this comes from a header
#ident "$Revision: 1.49 $"
Expand Down Expand Up @@ -44,7 +44,7 @@ struct Tile
};

/* tram mipmaps */
static struct Tile mipmap[MM_MAX_LEVEL+1] ALIGNED(8);
static struct Tile mipmap[MM_MAX_LEVEL+1] ALIGNED(0x8);
static struct texelSizeParams sizeParams[4] =
{ 16, 3, 1, 0,
8, 2, 2, 1,
Expand Down
4 changes: 2 additions & 2 deletions src/host/host_ptn64.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "PR/rcp.h"
#include "memory.h"

#include "macros.h"
#include "PRinternal/macros.h"

#if BUILD_VERSION >= VERSION_J || !defined(_FINALROM)

Expand All @@ -12,7 +12,7 @@ static volatile unsigned int* ptstat = (unsigned*)0xbff08004;
static volatile unsigned int* ptport = (unsigned*)0xbff08000;
static volatile unsigned int* n64piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG);

static OSMesgQueue waitPtQueue ALIGNED(8);
static OSMesgQueue waitPtQueue ALIGNED(0x8);
static OSMesg waitPtQueueBuf;
static u32 isWaitPtQueueCreated = FALSE;

Expand Down
4 changes: 2 additions & 2 deletions src/host/readhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "PR/os_internal.h"
#include "PR/rdb.h"

#include "macros.h"
#include "PRinternal/macros.h"

static int readHostInitialized = FALSE;
static OSMesgQueue readHostMesgQueue ALIGNED(8);
static OSMesgQueue readHostMesgQueue ALIGNED(0x8);
static OSMesg readHostMesgBuf[1];

u32 __osRdb_Read_Data_Buf;
Expand Down
4 changes: 2 additions & 2 deletions src/host/writehost.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "PR/rdb.h"
#include "PR/ultraerror.h"

#include "macros.h"
#include "PRinternal/macros.h"

static int writeHostInitialized = FALSE;
static OSMesgQueue writeHostMesgQueue ALIGNED(8);
static OSMesgQueue writeHostMesgQueue ALIGNED(0x8);
static OSMesg writeHostMesgBuf[1];

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
Expand Down
12 changes: 12 additions & 0 deletions src/io/aisetnextbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
// TODO: this comes from a header
#ident "$Revision: 1.17 $"

/**
* Submits an audio buffer to be consumed by the Audio DAC. The audio interface can queue a second DMA while another
* is in progress and automatically begin the next one as soon as the current DMA completes. If there is already a
* second DMA queued (DMA is full), -1 is returned to indicate the buffer could not be submitted.
*
* @param bufPtr Next audio buffer. Must be an 8-byte aligned KSEG0 (0x80XXXXXX) address.
* @param size Length of next audio buffer in bytes, maximum size 0x40000 bytes / 256 KiB. Should be a multiple of 8.
* @return 0 if the DMA was enqueued successfully, -1 if the DMA could not yet be queued.
*/
s32 osAiSetNextBuffer(void* bufPtr, u32 size) {
static u8 hdwrBugFlag = FALSE;
char* bptr;
Expand Down Expand Up @@ -41,6 +50,9 @@ s32 osAiSetNextBuffer(void* bufPtr, u32 size) {
}

#if BUILD_VERSION < VERSION_J
//! @bug The __osAiDeviceBusy call should be above the hardware bug workaround to ensure that it was only
//! performed when a transfer was guaranteed to start. If this condition passes and this function returns without
//! submitting a buffer for DMA, the code above will lose track of when to apply the workaround.
if (__osAiDeviceBusy()) {
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/io/cartrominit.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_version.h"
#include "PR/os_internal.h"
#include "PR/R4300.h"
#include "PR/rcp.h"
#include "PRinternal/piint.h"

#if BUILD_VERSION >= VERSION_J
OSPiHandle __CartRomHandle ALIGNED(8);
OSPiHandle __CartRomHandle ALIGNED(0x8);
OSPiHandle* osCartRomInit(void) {
u32 value = 0;
u32 saveMask;
Expand Down Expand Up @@ -65,7 +65,7 @@ OSPiHandle* osCartRomInit(void) {
}
#else

OSPiHandle CartRomHandle ALIGNED(8);
OSPiHandle CartRomHandle ALIGNED(0x8);
OSPiHandle* osCartRomInit(void) {
u32 domain = 0;
u32 saveMask;
Expand Down
4 changes: 2 additions & 2 deletions src/io/conteepread.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/rcp.h"
#include "PRinternal/controller.h"
#include "PRinternal/siint.h"

OSPifRam __osEepPifRam ALIGNED(16);
OSPifRam __osEepPifRam;
#if BUILD_VERSION >= VERSION_L
s32 __osEepromRead16K;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/io/conteepwrite.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PRinternal/controller.h"
Expand Down
4 changes: 2 additions & 2 deletions src/io/contpfs.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PR/os_version.h"
#include "PRinternal/controller.h"
#include "PR/rmon.h"

#if BUILD_VERSION >= VERSION_J
__OSInode __osPfsInodeCache ALIGNED(8);
__OSInode __osPfsInodeCache ALIGNED(0x8);
s32 __osPfsInodeCacheChannel = -1;
u8 __osPfsInodeCacheBank = 250;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/io/contramread.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PRinternal/controller.h"
Expand Down
2 changes: 1 addition & 1 deletion src/io/contramwrite.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PRinternal/controller.h"
Expand Down
2 changes: 1 addition & 1 deletion src/io/contreaddata.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"
#include "PRinternal/siint.h"
Expand Down
6 changes: 3 additions & 3 deletions src/io/controller.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"
#include "PRinternal/siint.h"

OSPifRam __osContPifRam ALIGNED(16);
OSPifRam __osContPifRam;
u8 __osContLastCmd;
u8 __osMaxControllers;

OSTimer __osEepromTimer;
OSMesgQueue __osEepromTimerQ ALIGNED(8);
OSMesgQueue __osEepromTimerQ ALIGNED(0x8);
OSMesg __osEepromTimerMsg;

s32 __osContinitialized = FALSE;
Expand Down
4 changes: 2 additions & 2 deletions src/io/driverominit.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "macros.h"
#include "PRinternal/macros.h"

OSPiHandle DriveRomHandle ALIGNED(8);
OSPiHandle DriveRomHandle ALIGNED(0x8);

OSPiHandle *osDriveRomInit(void) {
u32 saveMask;
Expand Down
2 changes: 1 addition & 1 deletion src/io/gbpakcheckconnector.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"

Expand Down
4 changes: 2 additions & 2 deletions src/io/gbpakinit.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"
#include "PRinternal/controller_gbpak.h"

OSTimer __osGbpakTimer;
OSMesgQueue __osGbpakTimerQ ALIGNED(8);
OSMesgQueue __osGbpakTimerQ ALIGNED(0x8);
OSMesg __osGbpakTimerMsg;

s32 osGbpakInit(OSMesgQueue* mq, OSPfs* pfs, int channel) {
Expand Down
2 changes: 1 addition & 1 deletion src/io/gbpakreadid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "macros.h"
#include "PRinternal/macros.h"
#include "PR/os_internal.h"
#include "PRinternal/controller.h"
#include "os_version.h"
Expand Down
4 changes: 2 additions & 2 deletions src/io/leodiskinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "PR/os_internal.h"
#include "PR/os_libc.h"
#include "PR/rcp.h"
#include "macros.h"
#include "PRinternal/macros.h"

OSPiHandle LeoDiskHandle ALIGNED(8);
OSPiHandle LeoDiskHandle ALIGNED(0x8);
OSPiHandle *__osDiskHandle;

OSPiHandle *osLeoDiskInit(void) {
Expand Down
Loading

0 comments on commit bcca1c8

Please sign in to comment.