Small Cleanup (#55)

* Improve initialize_isv

* Small flash improvement

* error

* OS_USEC_TO_CYCLES is osSetTimer

* parens in flash

* typo
This commit is contained in:
Derek Hensley
2023-09-24 16:58:55 -07:00
committed by GitHub
parent d7dc7177d6
commit eddcfcd44e
6 changed files with 40 additions and 33 deletions

View File

@@ -8,8 +8,16 @@
#ifndef _FINALROM
void __osSyncVPrintf(const char* fmt, va_list args);
static u32 errorLogData[19] ALIGNED(8);
static OSLog errorLog = { OS_ERROR_MAGIC, 76, errorLogData, 0, 0 };
static OSLog errorLog = {
OS_ERROR_MAGIC, // magic
sizeof(errorLogData), // len
errorLogData, // base
0, //startCount
0, //writeOffset
};
static void __commonErrorHandler(s16 code, s16 numArgs, ...);
OSErrorHandler __osCommonHandler = __commonErrorHandler;

View File

@@ -6,11 +6,11 @@
#include "macros.h"
void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr);
void __osDefaultHandler(s16 code, s16 numArgs, ...);
static void __osDefaultHandler(s16 code, s16 numArgs, ...);
static u32 errorLogData[19] ALIGNED(8);
static OSLog errorLog ALIGNED(8) = {
0x6b617479, // magic
OS_ERROR_MAGIC, // magic
sizeof(errorLogData), // len
errorLogData, // base
0, //startCount

View File

@@ -5,9 +5,10 @@ u32 __osFlashGetAddr(u32 page_num) {
u32 devAddr;
if (__osFlashVersion == OLD_FLASH) {
devAddr = page_num * 64;
// Account for hardware bug in old flash where the address bits are shifted 1-off where they should be
devAddr = page_num * (FLASH_BLOCK_SIZE >> 1);
} else {
devAddr = page_num * 128;
devAddr = page_num * FLASH_BLOCK_SIZE;
}
return devAddr;

View File

@@ -9,7 +9,7 @@ s32 osEepromLongWrite(OSMesgQueue* mq, u8 address, u8* buffer, int length) {
length -= EEPROM_BLOCK_SIZE;
address++;
buffer += EEPROM_BLOCK_SIZE;
osSetTimer(&__osEepromTimer, 562500, 0, &__osEepromTimerQ, &__osEepromTimerMsg);
osSetTimer(&__osEepromTimer, OS_USEC_TO_CYCLES(12000), 0, &__osEepromTimerQ, &__osEepromTimerMsg);
osRecvMesg(&__osEepromTimerQ, NULL, OS_MESG_BLOCK);
}

View File

@@ -76,7 +76,7 @@ s32 osGbpakInit(OSMesgQueue* mq, OSPfs* pfs, int channel) {
ERRCK(__osPfsGetStatus(mq, channel));
osCreateMesgQueue(&__osGbpakTimerQ, &__osGbpakTimerMsg, 1);
osSetTimer(&__osGbpakTimer, 9000000, 0, &__osGbpakTimerQ, &__osGbpakTimerMsg);
osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(192000), 0, &__osGbpakTimerQ, &__osGbpakTimerMsg);
osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK);
pfs->queue = mq;
pfs->status = PFS_GBPAK_INITIALIZED;

View File

@@ -17,21 +17,20 @@ extern __osExceptionVector __isExpJP;
void MonitorInitBreak(void);
typedef struct {
/* 0x00 */ u32 magic; // IS64
/* 0x04 */ u32 get;
/* 0x08 */ u8 unk_08[0x14 - 0x08];
/* 0x14 */ u32 put;
/* 0x18 */ u8 unk_18[0x20 - 0x18];
/* 0x20 */ u8 data[0x10000 - 0x20];
} ISVDbg;
#define ISV_BASE gISVDbgPrnAdrs
#define ISV_MAGIC_ADDR (ISV_BASE + 0x00)
#define ISV_GET_ADDR (ISV_BASE + 0x04)
#define ISV_PUT_ADDR (ISV_BASE + 0x14)
#define ISV_BUFFER (ISV_BASE + 0x20)
#define ISV_BUFFER_LEN (0x10000 - 0x20)
#define IS64_MAGIC 'IS64'
__osExceptionVector ramOldVector ALIGNED(8);
u32 gISVFlag;
u16 gISVChk;
ISVDbg* gISVDbgPrnAdrs;
u32 gISVDbgPrnAdrs;
u32 leoComuBuffAdd;
static OSPiHandle* is_Handle;
@@ -39,9 +38,9 @@ static OSPiHandle* is_Handle;
void isPrintfInit(void) {
is_Handle = osCartRomInit();
osEPiWriteIo(is_Handle, &gISVDbgPrnAdrs->put, 0);
osEPiWriteIo(is_Handle, &gISVDbgPrnAdrs->get, 0);
osEPiWriteIo(is_Handle, &gISVDbgPrnAdrs->magic, IS64_MAGIC);
osEPiWriteIo(is_Handle, ISV_PUT_ADDR, 0);
osEPiWriteIo(is_Handle, ISV_GET_ADDR, 0);
osEPiWriteIo(is_Handle, ISV_MAGIC_ADDR, IS64_MAGIC);
}
static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) {
@@ -49,25 +48,24 @@ static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) {
s32 p;
s32 start;
s32 end;
u32* magic = &gISVDbgPrnAdrs->magic;
if (gISVDbgPrnAdrs == NULL) {
if (gISVDbgPrnAdrs == 0) {
return 0;
}
osEPiReadIo(is_Handle, (u32)magic, &data);
osEPiReadIo(is_Handle, ISV_MAGIC_ADDR, &data);
if (data != IS64_MAGIC) {
return 1;
}
osEPiReadIo(is_Handle, (u32)&gISVDbgPrnAdrs->get, &data);
osEPiReadIo(is_Handle, ISV_GET_ADDR, &data);
p = data;
osEPiReadIo(is_Handle, (u32)&gISVDbgPrnAdrs->put, &data);
osEPiReadIo(is_Handle, ISV_PUT_ADDR, &data);
start = data;
end = start + count;
if (end >= 0xffe0) {
end -= 0xffe0;
if (end >= ISV_BUFFER_LEN) {
end -= ISV_BUFFER_LEN;
if (p < end || start < p) {
return 1;
}
@@ -79,7 +77,7 @@ static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) {
while (count) {
if (*str != '\0') {
s32 shift = start & 3;
u32 addr = (u32)&gISVDbgPrnAdrs->data[start & 0xFFFFFFC];
u32 addr = ISV_BUFFER + (start & 0xFFFFFFC);
shift = (3 - shift) * 8;
@@ -87,14 +85,14 @@ static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) {
osEPiWriteIo(is_Handle, addr, (data & ~(0xff << shift)) | (*str << shift));
start++;
if (start >= 0xffe0) {
start -= 0xffe0;
if (start >= ISV_BUFFER_LEN) {
start -= ISV_BUFFER_LEN;
}
}
count--;
str++;
}
osEPiWriteIo(is_Handle, (u32)&gISVDbgPrnAdrs->put, start);
osEPiWriteIo(is_Handle, ISV_PUT_ADDR, start);
return 1;
}
@@ -105,7 +103,7 @@ int __checkHardware_isv(void) {
u32 save[4];
OSPiHandle* hnd = osCartRomInit();
gISVDbgPrnAdrs = NULL;
gISVDbgPrnAdrs = 0;
leoComuBuffAdd = 0;
gISVFlag = IS64_MAGIC;
gISVChk = 0;
@@ -127,7 +125,7 @@ int __checkHardware_isv(void) {
data = 0;
osEPiWriteIo(hnd, 0xB0000100, data);
gISVChk |= 1;
osEPiReadIo(hnd, 0xB0000104, (void*)&gISVDbgPrnAdrs);
osEPiReadIo(hnd, 0xB0000104, &gISVDbgPrnAdrs);
osEPiReadIo(hnd, 0xB0000108, &leoComuBuffAdd);
break;
}
@@ -151,7 +149,7 @@ void __osInitialize_isv(void) {
s32 pad2;
if (gISVFlag == IS64_MAGIC || __checkHardware_isv()) {
if (gISVDbgPrnAdrs != NULL) {
if (gISVDbgPrnAdrs != 0) {
__printfunc = is_proutSyncPrintf;
isPrintfInit();
}