From d62631d60081b4fca503d3c1ff25385cb11b9896 Mon Sep 17 00:00:00 2001 From: Mittenshugg Date: Sat, 1 Aug 2020 03:50:31 -0500 Subject: [PATCH] c: osPfcFreeBlocks --- Makefile | 1 + data/dkr.data.s | 2 +- include/PR/os_message.h | 17 +++ include/PR/pfs.h | 137 ++++++++++++++++++ include/controller.h | 133 +++++++++++++++++ include/ultra64.h | 1 + .../unknown_0CFFE0/osPfsFreeBlocks.s | 98 ------------- .../unknown_0D2E40/osSpTaskYield.s | 10 -- .../{D_800D35A0.s => __osCleanupThread.s} | 2 +- .../unknown_0D3020/osDestroyThread.s | 12 +- lib/src/osCreateThread.c | 14 +- lib/src/osPfsFreeBlocks.c | 34 +++++ lib/src/unknown_0CFFE0.c | 7 - lib/src/unknown_0D2590.c | 5 + lib/src/unknown_0D2E40.c | 6 +- lib/src/unknown_0D3160.c | 2 +- undefined_syms.txt | 4 +- 17 files changed, 349 insertions(+), 136 deletions(-) create mode 100644 include/PR/pfs.h create mode 100644 include/controller.h delete mode 100644 lib/asm/non_matchings/unknown_0CFFE0/osPfsFreeBlocks.s delete mode 100644 lib/asm/non_matchings/unknown_0D2E40/osSpTaskYield.s rename lib/asm/non_matchings/unknown_0D3020/{D_800D35A0.s => __osCleanupThread.s} (87%) create mode 100644 lib/src/osPfsFreeBlocks.c delete mode 100644 lib/src/unknown_0CFFE0.c diff --git a/Makefile b/Makefile index a71e0ccb..6515848a 100755 --- a/Makefile +++ b/Makefile @@ -176,6 +176,7 @@ $(BUILD_DIR)/lib/src/unknown_0C91A0.o : OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/unknown_0D29F0.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osCreateThread.o : OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osGetThreadPri.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osPfsFreeBlocks.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osPiStartDma.o : OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osRecvMesg.o : OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osSendMesg.o : OPT_FLAGS := -O1 diff --git a/data/dkr.data.s b/data/dkr.data.s index dde1465b..142f9591 100644 --- a/data/dkr.data.s +++ b/data/dkr.data.s @@ -9259,7 +9259,7 @@ glabel __osThreadTail glabel D_800E4888 .word 0x800E4880 -glabel D_800E488C +glabel __osActiveQueue .word 0x800E4880 glabel __osRunningThread diff --git a/include/PR/os_message.h b/include/PR/os_message.h index 191e1b1d..0c26e2a6 100644 --- a/include/PR/os_message.h +++ b/include/PR/os_message.h @@ -112,6 +112,23 @@ typedef struct OSMesgQueue_s { #define OS_MESG_NOBLOCK 0 #define OS_MESG_BLOCK 1 +/* + * 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 #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) diff --git a/include/PR/pfs.h b/include/PR/pfs.h new file mode 100644 index 00000000..183be08e --- /dev/null +++ b/include/PR/pfs.h @@ -0,0 +1,137 @@ +#ifndef _ULTRA64_PFS_H_ +#define _ULTRA64_PFS_H_ + +#include + +/* 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 +#define PFS_ONE_PAGE 8 +#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) + +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 inodeStartPage; /* 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; + +typedef union { + struct { + u8 bank; + u8 page; + } inode_t; + u16 ipage; +} __OSInodeUnit; + +typedef struct { + __OSInodeUnit inodePage[128]; +} __OSInode; + +typedef struct { + u32 game_code; + u16 company_code; + __OSInodeUnit start_page; + u8 status; + s8 reserved; + u16 data_sum; + u8 ext_name[PFS_FILE_EXT_LEN]; + u8 game_name[PFS_FILE_NAME_LEN]; +} __OSDir; + +typedef struct { + u32 repaired; + u32 random; + u64 serialMid; + u64 serialLow; + u16 deviceid; + u8 banks; + u8 version; + u16 checksum; + u16 invertedChecksum; +} __OSPackId; + +typedef struct { + __OSInode inode; + u8 bank; + u8 map[PFS_INODE_DIST_MAP]; +} __OSInodeCache; + +#endif \ No newline at end of file diff --git a/include/controller.h b/include/controller.h new file mode 100644 index 00000000..0abc36cb --- /dev/null +++ b/include/controller.h @@ -0,0 +1,133 @@ +#ifndef _CONTROLLER_H +#define _CONTROLLER_H +#include "libultra_internal.h" +//#include + +//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 +{ + /* 0x0 */ u32 ramarray[15]; + /* 0x3C */ u32 pifstatus; +} OSPifRam; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u16 button; + /* 0x6 */ s8 stick_x; + /* 0x7 */ s8 stick_y; +} __OSContReadFormat; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 typeh; + /* 0x5 */ u8 typel; + /* 0x6 */ u8 status; + /* 0x7 */ u8 dummy1; +} __OSContRequesFormat; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 typeh; + /* 0x4 */ u8 typel; + /* 0x5 */ u8 status; +} __OSContRequesFormatShort; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u16 address; + /* 0x6 */ u8 data[32]; + /* 0x26 */ u8 datacrc; +} __OSContRamReadFormat; + + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 address; + /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE]; +} __OSContEepromFormat; + +//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage +#define CONT_CMD_REQUEST_STATUS 0 +#define CONT_CMD_READ_BUTTON 1 +#define CONT_CMD_READ_MEMPACK 2 +#define CONT_CMD_WRITE_MEMPACK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_RESET 0xff + +#define CONT_CMD_REQUEST_STATUS_TX 1 +#define CONT_CMD_READ_BUTTON_TX 1 +#define CONT_CMD_READ_MEMPACK_TX 3 +#define CONT_CMD_WRITE_MEMPACK_TX 35 +#define CONT_CMD_READ_EEPROM_TX 2 +#define CONT_CMD_WRITE_EEPROM_TX 10 +#define CONT_CMD_RESET_TX 1 + +#define CONT_CMD_REQUEST_STATUS_RX 3 +#define CONT_CMD_READ_BUTTON_RX 4 +#define CONT_CMD_READ_MEMPACK_RX 33 +#define CONT_CMD_WRITE_MEMPACK_RX 1 +#define CONT_CMD_READ_EEPROM_RX 8 +#define CONT_CMD_WRITE_EEPROM_RX 1 +#define CONT_CMD_RESET_RX 3 + +#define CONT_CMD_NOP 0xff +#define CONT_CMD_END 0xfe //indicates end of a command +#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command + +#define DIR_STATUS_EMPTY 0 +#define DIR_STATUS_UNKNOWN 1 +#define DIR_STATUS_OCCUPIED 2 + + + +//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0 +#define ERRCK(fn) \ + ret = fn; \ + if (ret != 0) \ + return ret; + +#define SET_ACTIVEBANK_TO_ZERO \ + if (pfs->activebank != 0) \ + { \ + pfs->activebank = 0; \ + ERRCK(__osPfsSelectBank(pfs)) \ + } + +#define PFS_CHECK_ID \ + if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ + return PFS_ERR_NEW_PACK; +#endif + +#define PFS_CHECK_STATUS \ + if ((pfs->status & PFS_INITIALIZED) == 0) \ + return PFS_ERR_INVALID; + +#define PFS_GET_STATUS \ + __osSiGetAccess(); \ + ret = __osPfsGetStatus(queue, channel); \ + __osSiRelAccess(); \ + if (ret != 0) \ + return ret; + \ No newline at end of file diff --git a/include/ultra64.h b/include/ultra64.h index b53e434a..f9dfe94f 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,5 +30,6 @@ #include #include #include +#include #endif diff --git a/lib/asm/non_matchings/unknown_0CFFE0/osPfsFreeBlocks.s b/lib/asm/non_matchings/unknown_0CFFE0/osPfsFreeBlocks.s deleted file mode 100644 index 614e1f81..00000000 --- a/lib/asm/non_matchings/unknown_0CFFE0/osPfsFreeBlocks.s +++ /dev/null @@ -1,98 +0,0 @@ -glabel osPfsFreeBlocks -/* 0CFFE0 800CF3E0 27BDFED0 */ addiu $sp, $sp, -0x130 -/* 0CFFE4 800CF3E4 AFA40130 */ sw $a0, 0x130($sp) -/* 0CFFE8 800CF3E8 8FAE0130 */ lw $t6, 0x130($sp) -/* 0CFFEC 800CF3EC AFBF0014 */ sw $ra, 0x14($sp) -/* 0CFFF0 800CF3F0 AFA50134 */ sw $a1, 0x134($sp) -/* 0CFFF4 800CF3F4 AFA00128 */ sw $zero, 0x128($sp) -/* 0CFFF8 800CF3F8 AFA00024 */ sw $zero, 0x24($sp) -/* 0CFFFC 800CF3FC 8DCF0000 */ lw $t7, ($t6) -/* 0D0000 800CF400 31F80001 */ andi $t8, $t7, 1 -/* 0D0004 800CF404 17000003 */ bnez $t8, .L800CF414 -/* 0D0008 800CF408 00000000 */ nop -/* 0D000C 800CF40C 10000043 */ b .L800CF51C -/* 0D0010 800CF410 24020005 */ li $v0, 5 -.L800CF414: -/* 0D0014 800CF414 0C0356F0 */ jal __osCheckId -/* 0D0018 800CF418 8FA40130 */ lw $a0, 0x130($sp) -/* 0D001C 800CF41C 24010002 */ li $at, 2 -/* 0D0020 800CF420 14410003 */ bne $v0, $at, .L800CF430 -/* 0D0024 800CF424 00000000 */ nop -/* 0D0028 800CF428 1000003C */ b .L800CF51C -/* 0D002C 800CF42C 24020002 */ li $v0, 2 -.L800CF430: -/* 0D0030 800CF430 8FB90130 */ lw $t9, 0x130($sp) -/* 0D0034 800CF434 A3A00023 */ sb $zero, 0x23($sp) -/* 0D0038 800CF438 93280064 */ lbu $t0, 0x64($t9) -/* 0D003C 800CF43C 19000031 */ blez $t0, .L800CF504 -/* 0D0040 800CF440 00000000 */ nop -.L800CF444: -/* 0D0044 800CF444 8FA40130 */ lw $a0, 0x130($sp) -/* 0D0048 800CF448 27A50028 */ addiu $a1, $sp, 0x28 -/* 0D004C 800CF44C 00003025 */ move $a2, $zero -/* 0D0050 800CF450 0C03572F */ jal __osPfsRWInode -/* 0D0054 800CF454 93A70023 */ lbu $a3, 0x23($sp) -/* 0D0058 800CF458 AFA20024 */ sw $v0, 0x24($sp) -/* 0D005C 800CF45C 8FA90024 */ lw $t1, 0x24($sp) -/* 0D0060 800CF460 11200003 */ beqz $t1, .L800CF470 -/* 0D0064 800CF464 00000000 */ nop -/* 0D0068 800CF468 1000002C */ b .L800CF51C -/* 0D006C 800CF46C 01201025 */ move $v0, $t1 -.L800CF470: -/* 0D0070 800CF470 93AA0023 */ lbu $t2, 0x23($sp) -/* 0D0074 800CF474 19400004 */ blez $t2, .L800CF488 -/* 0D0078 800CF478 00000000 */ nop -/* 0D007C 800CF47C 240B0001 */ li $t3, 1 -/* 0D0080 800CF480 10000004 */ b .L800CF494 -/* 0D0084 800CF484 AFAB001C */ sw $t3, 0x1c($sp) -.L800CF488: -/* 0D0088 800CF488 8FAC0130 */ lw $t4, 0x130($sp) -/* 0D008C 800CF48C 8D8D0060 */ lw $t5, 0x60($t4) -/* 0D0090 800CF490 AFAD001C */ sw $t5, 0x1c($sp) -.L800CF494: -/* 0D0094 800CF494 8FAE001C */ lw $t6, 0x1c($sp) -/* 0D0098 800CF498 29C10080 */ slti $at, $t6, 0x80 -/* 0D009C 800CF49C 10200010 */ beqz $at, .L800CF4E0 -/* 0D00A0 800CF4A0 AFAE012C */ sw $t6, 0x12c($sp) -.L800CF4A4: -/* 0D00A4 800CF4A4 8FAF012C */ lw $t7, 0x12c($sp) -/* 0D00A8 800CF4A8 24010003 */ li $at, 3 -/* 0D00AC 800CF4AC 000FC040 */ sll $t8, $t7, 1 -/* 0D00B0 800CF4B0 03B8C821 */ addu $t9, $sp, $t8 -/* 0D00B4 800CF4B4 97390028 */ lhu $t9, 0x28($t9) -/* 0D00B8 800CF4B8 17210004 */ bne $t9, $at, .L800CF4CC -/* 0D00BC 800CF4BC 00000000 */ nop -/* 0D00C0 800CF4C0 8FA80128 */ lw $t0, 0x128($sp) -/* 0D00C4 800CF4C4 25090001 */ addiu $t1, $t0, 1 -/* 0D00C8 800CF4C8 AFA90128 */ sw $t1, 0x128($sp) -.L800CF4CC: -/* 0D00CC 800CF4CC 8FAA012C */ lw $t2, 0x12c($sp) -/* 0D00D0 800CF4D0 254B0001 */ addiu $t3, $t2, 1 -/* 0D00D4 800CF4D4 29610080 */ slti $at, $t3, 0x80 -/* 0D00D8 800CF4D8 1420FFF2 */ bnez $at, .L800CF4A4 -/* 0D00DC 800CF4DC AFAB012C */ sw $t3, 0x12c($sp) -.L800CF4E0: -/* 0D00E0 800CF4E0 93AC0023 */ lbu $t4, 0x23($sp) -/* 0D00E4 800CF4E4 8FAF0130 */ lw $t7, 0x130($sp) -/* 0D00E8 800CF4E8 258D0001 */ addiu $t5, $t4, 1 -/* 0D00EC 800CF4EC A3AD0023 */ sb $t5, 0x23($sp) -/* 0D00F0 800CF4F0 91F80064 */ lbu $t8, 0x64($t7) -/* 0D00F4 800CF4F4 31AE00FF */ andi $t6, $t5, 0xff -/* 0D00F8 800CF4F8 01D8082A */ slt $at, $t6, $t8 -/* 0D00FC 800CF4FC 1420FFD1 */ bnez $at, .L800CF444 -/* 0D0100 800CF500 00000000 */ nop -.L800CF504: -/* 0D0104 800CF504 8FB90128 */ lw $t9, 0x128($sp) -/* 0D0108 800CF508 8FAA0134 */ lw $t2, 0x134($sp) -/* 0D010C 800CF50C 00001025 */ move $v0, $zero -/* 0D0110 800CF510 001940C0 */ sll $t0, $t9, 3 -/* 0D0114 800CF514 00084940 */ sll $t1, $t0, 5 -/* 0D0118 800CF518 AD490000 */ sw $t1, ($t2) -.L800CF51C: -/* 0D011C 800CF51C 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D0120 800CF520 27BD0130 */ addiu $sp, $sp, 0x130 -/* 0D0124 800CF524 03E00008 */ jr $ra -/* 0D0128 800CF528 00000000 */ nop - -/* 0D012C 800CF52C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D2E40/osSpTaskYield.s b/lib/asm/non_matchings/unknown_0D2E40/osSpTaskYield.s deleted file mode 100644 index 7bb18e7a..00000000 --- a/lib/asm/non_matchings/unknown_0D2E40/osSpTaskYield.s +++ /dev/null @@ -1,10 +0,0 @@ -glabel osSpTaskYield -/* 0D2E40 800D2240 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0D2E44 800D2244 AFBF0014 */ sw $ra, 0x14($sp) -/* 0D2E48 800D2248 0C033490 */ jal __osSpSetStatus -/* 0D2E4C 800D224C 24040400 */ li $a0, 1024 -/* 0D2E50 800D2250 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D2E54 800D2254 27BD0018 */ addiu $sp, $sp, 0x18 -/* 0D2E58 800D2258 03E00008 */ jr $ra -/* 0D2E5C 800D225C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s b/lib/asm/non_matchings/unknown_0D3020/__osCleanupThread.s similarity index 87% rename from lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s rename to lib/asm/non_matchings/unknown_0D3020/__osCleanupThread.s index d8efce4c..686faede 100644 --- a/lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osCleanupThread.s @@ -1,4 +1,4 @@ -glabel D_800D35A0 +glabel __osCleanupThread /* 0D41A0 800D35A0 0C035980 */ jal osDestroyThread /* 0D41A4 800D35A4 00002025 */ move $a0, $zero /* 0D41A8 800D35A8 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s b/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s index 6a4ebe8e..da5d72c4 100644 --- a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s +++ b/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s @@ -24,18 +24,18 @@ glabel osDestroyThread /* 0D7254 800D6654 0C034B1C */ jal __osDequeueThread /* 0D7258 800D6658 03002825 */ move $a1, $t8 .L800D665C: -/* 0D725C 800D665C 3C08800E */ lui $t0, %hi(D_800E488C) # $t0, 0x800e -/* 0D7260 800D6660 8D08488C */ lw $t0, %lo(D_800E488C)($t0) +/* 0D725C 800D665C 3C08800E */ lui $t0, %hi(__osActiveQueue) # $t0, 0x800e +/* 0D7260 800D6660 8D08488C */ lw $t0, %lo(__osActiveQueue)($t0) /* 0D7264 800D6664 8FA90038 */ lw $t1, 0x38($sp) /* 0D7268 800D6668 15090005 */ bne $t0, $t1, .L800D6680 /* 0D726C 800D666C 00000000 */ nop /* 0D7270 800D6670 8D0A000C */ lw $t2, 0xc($t0) -/* 0D7274 800D6674 3C01800E */ lui $at, %hi(D_800E488C) # $at, 0x800e +/* 0D7274 800D6674 3C01800E */ lui $at, %hi(__osActiveQueue) # $at, 0x800e /* 0D7278 800D6678 10000010 */ b .L800D66BC -/* 0D727C 800D667C AC2A488C */ sw $t2, %lo(D_800E488C)($at) +/* 0D727C 800D667C AC2A488C */ sw $t2, %lo(__osActiveQueue)($at) .L800D6680: -/* 0D7280 800D6680 3C11800E */ lui $s1, %hi(D_800E488C) # $s1, 0x800e -/* 0D7284 800D6684 8E31488C */ lw $s1, %lo(D_800E488C)($s1) +/* 0D7280 800D6680 3C11800E */ lui $s1, %hi(__osActiveQueue) # $s1, 0x800e +/* 0D7284 800D6684 8E31488C */ lw $s1, %lo(__osActiveQueue)($s1) /* 0D7288 800D6688 8E32000C */ lw $s2, 0xc($s1) /* 0D728C 800D668C 1240000B */ beqz $s2, .L800D66BC /* 0D7290 800D6690 00000000 */ nop diff --git a/lib/src/osCreateThread.c b/lib/src/osCreateThread.c index fa41adc0..48463f0a 100644 --- a/lib/src/osCreateThread.c +++ b/lib/src/osCreateThread.c @@ -1,15 +1,11 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8850 */ -#include "types.h" -#include "macros.h" #include "libultra_internal.h" #include "PR/R4300.h" -//GLOBAL_ASM("lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s") - -extern OSThread *D_800E488C; //__osActiveQueue; -void D_800D35A0(void); //__osCleanupThread +extern OSThread *__osActiveQueue; //__osActiveQueue; +void __osCleanupThread(void); //__osCleanupThread void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri p) { @@ -22,7 +18,7 @@ void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void t->context.pc = (u32)entry; t->context.a0 = (u64)arg; t->context.sp = (u64)sp - 16; - t->context.ra = (u64)D_800D35A0; + 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; @@ -31,7 +27,7 @@ void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void t->state = OS_STATE_STOPPED; t->flags = 0; saveMask = __osDisableInt(); - t->tlnext = D_800E488C; - D_800E488C = t; + t->tlnext = __osActiveQueue; + __osActiveQueue = t; __osRestoreInt(saveMask); } \ No newline at end of file diff --git a/lib/src/osPfsFreeBlocks.c b/lib/src/osPfsFreeBlocks.c new file mode 100644 index 00000000..f3934383 --- /dev/null +++ b/lib/src/osPfsFreeBlocks.c @@ -0,0 +1,34 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CF3E0 */ + +#include "libultra_internal.h" +#include "controller.h" + +s32 osPfsFreeBlocks(OSPfs *pfs, s32 *bytes_not_used) +{ + int j; + int pages; + __OSInode inode; + s32 ret; + u8 bank; + int offset; + pages = 0; + ret = 0; + PFS_CHECK_STATUS; + PFS_CHECK_ID; + for (bank = 0; bank < pfs->banks; bank++) + { + ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); + if (bank > 0) + offset = 1; + else + offset = pfs->inodeStartPage; + for (j = offset; j < ARRLEN(inode.inodePage); j++) + { + if (inode.inodePage[j].ipage == 3) + pages++; + } + } + *bytes_not_used = pages * 8 * 32; + return 0; +} \ No newline at end of file diff --git a/lib/src/unknown_0CFFE0.c b/lib/src/unknown_0CFFE0.c deleted file mode 100644 index 0c96e522..00000000 --- a/lib/src/unknown_0CFFE0.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CF3E0 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0CFFE0/osPfsFreeBlocks.s") diff --git a/lib/src/unknown_0D2590.c b/lib/src/unknown_0D2590.c index 44ebfbea..c928470c 100644 --- a/lib/src/unknown_0D2590.c +++ b/lib/src/unknown_0D2590.c @@ -3,6 +3,11 @@ #include "types.h" #include "macros.h" +#include "libultra_internal.h" +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 D_8012D22C; //__osViIntrCount +//extern u16 D_8012D190; //static u16 retrace GLOBAL_ASM("lib/asm/non_matchings/unknown_0D2590/osCreateViManager.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D2590/viMgrMain.s") diff --git a/lib/src/unknown_0D2E40.c b/lib/src/unknown_0D2E40.c index f3012e7b..704199a2 100644 --- a/lib/src/unknown_0D2E40.c +++ b/lib/src/unknown_0D2E40.c @@ -3,6 +3,10 @@ #include "types.h" #include "macros.h" +#include "libultra_internal.h" + +void osSpTaskYield(void) { + __osSpSetStatus(SPSTATUS_SET_SIGNAL0); +} -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D2E40/osSpTaskYield.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D2E40/osViSetSpecialFeatures.s") diff --git a/lib/src/unknown_0D3160.c b/lib/src/unknown_0D3160.c index 8a8d2217..b0666507 100644 --- a/lib/src/unknown_0D3160.c +++ b/lib/src/unknown_0D3160.c @@ -19,7 +19,7 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueThread.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPopThread.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osCleanupThread.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osProbeTLB.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D3670.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osJamMesg.s") diff --git a/undefined_syms.txt b/undefined_syms.txt index b5ccb334..a0387b27 100755 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -65,7 +65,7 @@ D_800D2680 = 0x800D2680; D_800D2760 = 0x800D2760; __osExceptionPreamble = 0x800D2CB0; __osException = 0x800D2CC0; -D_800D35A0 = 0x800D35A0; +__osCleanupThread = 0x800D35A0; D_800D7600 = 0x800D7600; D_800D84C0 = 0x800D84C0; D_800D8590 = 0x800D8590; @@ -787,7 +787,7 @@ D_800E4874 = 0x800E4874; D_800E4878 = 0x800E4878; __osThreadTail = 0x800E4880; D_800E4888 = 0x800E4888; -D_800E488C = 0x800E488C; +__osActiveQueue = 0x800E488C; __osRunningThread = 0x800E4890; D_800E4894 = 0x800E4894; D_800E48C0 = 0x800E48C0;