2 Copyright 2006-2008, Romz
4 Licenced under Academic Free License version 3.0
5 Review OpenUsbLd README & LICENSE files for further details.
10 /* prototype for LOADCORE's function */
11 void *QueryLibraryEntryTable(iop_library_t
*lib
);
13 //---------------------------------------------------------------------------
14 /* Returns a pointer to a library entry table */
15 void *GetExportTable(char *libname
, int version
)
23 mips_memset(&lib
, 0, sizeof(iop_library_t
));
24 lib
.version
= version
;
26 for (i
= 0, psrc
= libname
; (i
< 8) && (*psrc
); i
++, psrc
++) lib
.name
[i
] = *psrc
;
28 return QueryLibraryEntryTable(&lib
);
33 //------------------------------
35 //---------------------------------------------------------------------------
36 /* Returns number of entries in the export table */
37 u32
GetExportTableSize(void *table
)
45 if (exp
!= NULL
) while (*exp
++ != NULL
) size
++;
49 //------------------------------
51 //---------------------------------------------------------------------------
52 /* Returns an entry from the export table */
53 void *GetExportEntry(void *table
, u32 entry
)
55 if (entry
< GetExportTableSize(table
))
66 //------------------------------
68 //---------------------------------------------------------------------------
69 /* Replaces an entry in the export table */
70 void *HookExportEntry(void *table
, u32 entry
, void *func
)
72 if (entry
< GetExportTableSize(table
))
75 register void **exp
, *temp
;
80 CpuSuspendIntr(&oldstate
);
84 CpuResumeIntr(oldstate
);
91 //------------------------------
93 //---------------------------------------------------------------------------
94 /* Allocates system memory on IOP */
95 void *_SysAlloc(u64 size
)
100 CpuSuspendIntr(&oldstate
);
101 p
= AllocSysMemory(ALLOC_FIRST
, size
, NULL
);
102 CpuResumeIntr(oldstate
);
106 //------------------------------
108 //---------------------------------------------------------------------------
109 /* Frees system memory on IOP */
110 int _SysFree(void *area
)
115 CpuSuspendIntr(&oldstate
);
116 r
= FreeSysMemory(area
);
117 CpuResumeIntr(oldstate
);
121 //------------------------------
123 //---------------------------------------------------------------------------
124 /* Makes an integer value */
125 int GetInt(void *ptr
)
131 return p
[0] | (p
[1] << 8) | (p
[2] << 16) | (p
[3] << 24);
133 //------------------------------
135 //---------------------------------------------------------------------------
136 /* Calculates a "checksum" */
137 u32
CalculateEDC(u8
*buf
, u32 size
)
144 while (i
++ < size
) x
^= *p
++;
148 //------------------------------
150 //---------------------------------------------------------------------------
151 /* Calculates ECC for a 0x80 bytes of data */
152 void CalculateECC(u8
*buf
, void *chk
)
155 register int i
, c1
, c2
, b
, c3
;
161 /* calculating ECC for a 0x80-bytes buffer */
164 b
= xortable
[*ptr
++];
171 } while (++ i
< 0x80);
179 //------------------------------
181 //---------------------------------------------------------------------------
183 /* Return ata sector corresponding to page number in vmc file */
184 u32
Mcpage_to_Apasector(int mc_num
, u32 mc_page
)
187 register u32 sector_to_read
, lbound
, ubound
;
193 for(i
= 0; i
< 10; i
++)
196 ubound
+=vmcSpec
[mc_num
].blocks
[i
].count
;
198 if((mc_page
>= (lbound
<< 4)) && (mc_page
< (ubound
<< 4)))
199 sector_to_read
= vmcSpec
[mc_num
].parts
[vmcSpec
[mc_num
].blocks
[i
].subpart
].start
+ (vmcSpec
[mc_num
].blocks
[i
].number
<< 4) + (mc_page
- (lbound
<< 4));
202 return sector_to_read
;
204 //------------------------------
206 //---------------------------------------------------------------------------
208 //---------------------------------------------------------------------------
209 // End of file: mcsiosys.c
210 //---------------------------------------------------------------------------