Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
12 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. # _____ ___ ____ ___ ____
  3. # ____| | ____| | | |____|
  4. # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
  5. #-----------------------------------------------------------------------
  6. # (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
  7. # Licenced under Academic Free License version 2.0
  8. # Review ps2sdk README & LICENSE files for further details.
  9. */
  10. /**
  11. * @file
  12. * IOP executable file loader.
  13. */
  14. #ifndef __LOADFILE_H__
  15. #define __LOADFILE_H__
  16. #include <tamtypes.h>
  17. #define LF_PATH_MAX 252
  18. #define LF_ARG_MAX 252
  19. enum _lf_val_types {
  20. LF_VAL_BYTE = 0,
  21. LF_VAL_SHORT,
  22. LF_VAL_LONG
  23. };
  24. enum _lf_functions {
  25. LF_F_MOD_LOAD = 0,
  26. LF_F_ELF_LOAD,
  27. LF_F_SET_ADDR,
  28. LF_F_GET_ADDR,
  29. LF_F_MG_MOD_LOAD,
  30. LF_F_MG_ELF_LOAD,
  31. LF_F_MOD_BUF_LOAD,
  32. LF_F_MOD_STOP,
  33. LF_F_MOD_UNLOAD,
  34. LF_F_SEARCH_MOD_BY_NAME,
  35. LF_F_SEARCH_MOD_BY_ADDRESS,
  36. };
  37. typedef struct
  38. {
  39. u32 epc;
  40. u32 gp;
  41. u32 sp;
  42. u32 dummy;
  43. } t_ExecData;
  44. /* Extended error codes */
  45. /** Could not bind with RPC server */
  46. #define SCE_EBINDMISS 0x10000
  47. /** Could not call the RPC function */
  48. #define SCE_ECALLMISS 0x10001
  49. /** ELF/Module load failed */
  50. #define SCE_ELOADMISS 0x10003
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /** Initialize the LOADFILE library.
  55. * @ingroup loadfile
  56. *
  57. * @returns 0 on success, E_SIF_RPC_BIND if unable to connect to the server.
  58. *
  59. * Initializes the LOADFILE API and binds to the remote LOADFILE RPC server.
  60. */
  61. int SifLoadFileInit(void);
  62. /** Reset the LOADFILE library.
  63. * @ingroup loadfile
  64. *
  65. * Deinitializes the LOADFILE library in preparation of an IOP reset.
  66. */
  67. void SifLoadFileExit(void);
  68. /** Load and execute an IRX module.
  69. * @ingroup loadfile
  70. *
  71. * @param path Path to an IRX module
  72. * @param arg_len Length, in bytes, of the argument list
  73. * @param args List of arguments to pass to the IRX on startup
  74. *
  75. * @returns The ID of the loaded module on success, or an error if the module
  76. * couldn't be loaded.
  77. *
  78. * Loads an IRX module from the specified path, and executes it. The args
  79. * parameter specifies a list of arguments that are passed to the loaded module
  80. * as the argv[] array. Each argument string in args must be seperated by NUL ('\\0').
  81. * Pass the length of the entire args list, including the NUL seperators in the args_len
  82. * parameter.
  83. *
  84. * @note By default, modules cannot be loaded directly from the memory card. If you need to
  85. * load modules from the memory card, you should use ::SifExecModuleFile or link with the
  86. * sbv-lite library (http://www.0xd6.org).
  87. *
  88. * @see SifExecModuleFile
  89. */
  90. int SifLoadModule(const char *path, int arg_len, const char *args);
  91. /** Load and execute and IRX module, and retrieve the module's load status.
  92. * @ingroup loadfile
  93. *
  94. * @param path Path to an IRX module
  95. * @param arg_len Length, in bytes, of the argument list
  96. * @param args List of arguments to pass to the IRX on startup
  97. * @param mod_res Pointer to a variable that will store the return value from the IRX's _start() function
  98. *
  99. * @returns The ID of the loaded module on success, or an error if the module
  100. * couldn't be loaded.
  101. *
  102. * Loads an IRX module from the specified path, and executes it. See ::SifLoadModule for
  103. * details on the arg_len and args parameters. If mod_res is non-NULL, the result code from
  104. * the module's _start() function is stored here.
  105. *
  106. * @see SifLoadModule
  107. */
  108. int SifLoadStartModule(const char *path, int arg_len, const char *args, int *mod_res);
  109. /** Load and execute an IRX module encrypted with MagicGate.
  110. * @ingroup loadfile
  111. *
  112. * @param path Path to an IRX module
  113. * @param arg_len Length, in bytes, of the argument list
  114. * @param args List of arguments to pass to the IRX on startup
  115. *
  116. * @returns The ID of the loaded module on success, or an error if the module
  117. * couldn't be loaded.
  118. *
  119. * There is no real use for this function; it is only included in ps2lib for completeness.
  120. *
  121. * @see SifLoadModule
  122. */
  123. int SifLoadModuleEncrypted(const char *path, int arg_len, const char *args);
  124. /** Load and execute an IRX module from a buffer in IOP RAM.
  125. * @ingroup loadfile
  126. *
  127. * @param ptr Pointer to a buffer in IOP RAM where the IRX module will be loaded from
  128. * @param arg_len Length, in bytes, of the argument list
  129. * @param args List of arguments to pass to the IRX on startup
  130. *
  131. * @returns The ID of the loaded module on success, or an error if the module couldn't
  132. * be loaded.
  133. *
  134. * Loads an IRX module from a buffer located in IOP RAM. See ::SifLoadModule for details on
  135. * the arg_len and args parameters.
  136. *
  137. * @note If you need to load an IRX module onto the IOP directly from a buffer in EE RAM, then
  138. * use ::SifExecModuleBuffer.
  139. *
  140. * @see SifLoadModule, SifExecModuleBuffer
  141. */
  142. int SifLoadModuleBuffer(void *ptr, int arg_len, const char *args);
  143. /** Load and execute an IRX module from a buffer in IOP RAM, and retrieve the module's load status.
  144. * @ingroup loadfile
  145. *
  146. * @param ptr Pointer to a buffer in IOP RAM where the IRX module will be loaded from
  147. * @param arg_len Length, in bytes, of the argument list
  148. * @param args List of arguments to pass to the IRX on startup
  149. * @param mod_res Pointer to a variable that will store the return value from the IRX's _start() function
  150. *
  151. * @returns The ID of the loaded module on success, or an error if the module
  152. * couldn't be loaded.
  153. *
  154. * Loads an IRX module from a buffer located in IOP RAM. See ::SifLoadModule for details on
  155. * the arg_len and args parameters. If mod_res is non-NULL, the result code from the module's
  156. * _start() function is stored here.
  157. *
  158. * @note If you need to load an IRX module onto the IOP directly from a buffer in EE RAM, then
  159. * use ::SifExecModuleBuffer.
  160. *
  161. * @see SifLoadModule, SifExecModuleBuffer
  162. */
  163. int SifLoadStartModuleBuffer(void *ptr, int arg_len, const char *args, int *mod_res);
  164. int SifStopModule(int id, int arg_len, const char *args, int *mod_res);
  165. int SifUnloadModule(int id);
  166. int SifSearchModuleByName(const char *name);
  167. int SifSearchModuleByAddress(const void *ptr);
  168. /** Load the specified section of an ELF executable into EE RAM.
  169. * @ingroup loadfile
  170. *
  171. * @param path Path to an ELF executable
  172. * @param secname The name of a single section to load from the ELF, or "all" to load all sections
  173. * @param data Pointer to a variable that will store information about the loaded executable
  174. *
  175. * @returns 0 on success, or an error code if an error occurred.
  176. *
  177. * Loads the section secname from the ELF file specified by path into EE RAM.
  178. *
  179. * data points to a t_ExecData structure where information about the loaded
  180. * section will be returned.
  181. *
  182. * @warning Don't ever use this function, it does not work as intended.
  183. */
  184. int SifLoadElfPart(const char *path, const char *secname, t_ExecData *data);
  185. /** Load an ELF executable into EE RAM.
  186. * @ingroup loadfile
  187. *
  188. * @param path Path to an ELF executable
  189. * @param data Pointer to a variable that will store information about the loaded executable
  190. *
  191. * @returns 0 on success, or an error code if an error occurred.
  192. *
  193. * Loads the ELF executable specified by path into EE RAM. data points to a
  194. * t_ExecData structure where information about the loaded executable will be returned.
  195. *
  196. * @warning It's possible to overwrite your program if the ELF that you're trying to
  197. * load overlaps your program's memory space. Always ensure that the target ELF will
  198. * load before or after your program's code and data addresses.
  199. */
  200. int SifLoadElf(const char *path, t_ExecData *data);
  201. /** Load a MagicGate-encrypted ELF executable into EE RAM.
  202. * @ingroup loadfile
  203. *
  204. * @param path Path to an ELF executable
  205. * @param data Pointer to a variable that will store information about the loaded executable
  206. *
  207. * @returns 0 on success, or an error code if an error occurred.
  208. *
  209. * There is no real use for this function; it is only included in ps2lib for completeness.
  210. *
  211. * @see SifLoadElf
  212. */
  213. int SifLoadElfEncrypted(const char *path, t_ExecData *data);
  214. /** Write a value to an address within the IOP's memory space.
  215. * @ingroup loadfile
  216. *
  217. * @param iop_addr Address to modify in the IOP's address space
  218. * @param val Data to write at iop_addr
  219. * @param type A type describing the size of the val argument
  220. *
  221. * @returns Previous value at iop_addr on success (?), or an error code if an
  222. * error occurred.
  223. *
  224. * Writes the data passed in val to the IOP address specified by iop_addr. Use
  225. * the following types specify the size of data write:
  226. * - ::LF_VAL_BYTE to write an 8-bit value
  227. * - ::LF_VAL_SHORT to write a 16-bit value
  228. * - ::LF_VAL_LONG to write a 32-bit value
  229. *
  230. * @note Because iop_addr can be any address within the IOP's address space, it's
  231. * possible to modify IOP hardware registers. However, in most cases the EE can
  232. * modify the IOP's hardware registers directly so there is little use for this function.
  233. *
  234. * @see SifIopGetVal
  235. */
  236. int SifIopSetVal(u32 iop_addr, int val, int type);
  237. /** Read a value from an address within the IOP's memory space.
  238. * @ingroup loadfile
  239. *
  240. * @param iop_addr Address within the IOP's address space to read from
  241. * @param val Pointer to a variable that stores the value read
  242. * @param type A type describing the size of the data to read
  243. *
  244. * @returns 0 on success, or an error code if an error occurred.
  245. *
  246. * Reads data of the size specified by type from the IOP address specified by
  247. * iop_addr. Use the following types to specify the size of the data to read:
  248. * - ::LF_VAL_BYTE to write an 8-bit value
  249. * - ::LF_VAL_SHORT to write a 16-bit value
  250. * - ::LF_VAL_LONG to write a 32-bit value
  251. *
  252. * @note Because iop_addr can be any address within the IOP's address space, it's
  253. * possible to read from IOP hardware registers. However, in most cases the EE can
  254. * read the IOP's hardware registers directly so there is little use for this function.
  255. * @see SifIopSetVal
  256. */
  257. int SifIopGetVal(u32 iop_addr, void *val, int type);
  258. /** Transfer an IRX module from EE RAM to IOP RAM and execute it.
  259. * @ingroup loadfile
  260. *
  261. * @param ptr Pointer to a buffer in EE RAM where the IRX module will be loaded from
  262. * @param size Size of the buffer in EE RAM that contains the IRX module
  263. * @param arg_len Length, in bytes, of the argument list
  264. * @param args List of arguments to pass to the IRX on startup
  265. * @param mod_res Pointer to a variable that will store the return value from the IRX's _start() function
  266. *
  267. * @returns The ID of the loaded module on success, or an error if the module couldn't
  268. * be loaded.
  269. *
  270. * Transfers an IRX module stored in a buffer in EE RAM to the IOP, and calls ::SifLoadModuleBuffer to
  271. * load and execute the module. See ::SifLoadModule for details on the arg_len and args parameters.
  272. * If mod_res is non-NULL, the result code from the module's _start() function is stored here.
  273. *
  274. * @see SifLoadModule, SifLoadModuleBuffer
  275. */
  276. int SifExecModuleBuffer(void *ptr, u32 size, u32 arg_len, const char *args, int *mod_res);
  277. /** Read an IRX module from a file into IOP RAM and execute it.
  278. * @ingroup loadfile
  279. *
  280. * @param path Path to an IRX module
  281. * @param arg_len Length, in bytes, of the argument list
  282. * @param args List of arguments to pass to the IRX on startup
  283. * @param mod_res Pointer to a variable that will store the return value from the IRX's _start() function
  284. *
  285. * @returns The ID of the loaded module on success, or an error if the module
  286. * couldn't be loaded.
  287. *
  288. * Loads an IRX module from the specified path into a buffer on the IOP, then calls ::SifLoadModuleBuffer
  289. * to load and execute the module. See ::SifLoadModule for details on the arg_len and args parameters.
  290. * This function is useful if you need to load an IRX module from a prohibited device, such as the memory card.
  291. *
  292. * @see SifLoadModule, SifLoadModuleBuffer
  293. */
  294. int SifExecModuleFile(const char *path, u32 arg_len, const char *args, int *mod_res);
  295. /** Low-level function for loading and executing an IRX module.
  296. * @ingroup loadfile
  297. *
  298. * @param path Path to an IRX module
  299. * @param arg_len Length, in bytes, of the argument list
  300. * @param args List of arguments to pass to the IRX on startup
  301. * @param *modres Pointer to a variable that will store the return value from the IRX's _start() function
  302. * @param fno Function number of function to execute.
  303. * @param dontwait Whether to wait for the module's _start function to finish executing.
  304. *
  305. * @returns The ID of the loaded module on success, or an error if the module
  306. * couldn't be loaded.
  307. *
  308. * Unless required, use the higher-level functions instead.
  309. *
  310. * @see SifLoadModule, SifLoadModuleBuffer, SifLoadModuleEncrypted
  311. */
  312. int _SifLoadModule(const char *path, int arg_len, const char *args,
  313. int *modres, int fno, int dontwait);
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317. #endif /* __LOADFILE_H__ */