pspmoduleinfo.h

Go to the documentation of this file.
00001 /*
00002  * PSP Software Development Kit - http://www.pspdev.org
00003  * -----------------------------------------------------------------------
00004  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
00005  *
00006  * pspmoduleinfo.h - Definitions for the .rodata.sceModuleInfo ELF section.
00007  *
00008  * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
00009  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
00010  * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
00011  *
00012  * $Id: pspmoduleinfo.h 2434 2008-10-15 17:37:25Z iwn $
00013  */
00014 #ifndef PSPMODULEINFO_H
00015 #define PSPMODULEINFO_H
00016 
00017 /* Note: Some of the structures and definitions in this file were extrapolated from
00018    symbolic debugging information found in the Japanese version of Puzzle Bobble. */
00019 
00020 /* Module info structure.  Used to declare a module (library or executable).  This structure
00021    is required in all PSP executables. */
00022 typedef struct _scemoduleinfo {
00023         unsigned short          modattribute;
00024         unsigned char           modversion[2];
00025         char                    modname[27];
00026         char                    terminal;
00027         void *                  gp_value;
00028         void *                  ent_top;
00029         void *                  ent_end;
00030         void *                  stub_top;
00031         void *                  stub_end;
00032 } _sceModuleInfo;
00033 
00034 typedef const _sceModuleInfo SceModuleInfo;
00035 
00036 extern char _gp[];
00037 
00038 enum PspModuleInfoAttr
00039 {
00040         PSP_MODULE_USER                 = 0,
00041         PSP_MODULE_NO_STOP              = 0x0001,
00042         PSP_MODULE_SINGLE_LOAD  = 0x0002,
00043         PSP_MODULE_SINGLE_START = 0x0004,
00044         PSP_MODULE_KERNEL               = 0x1000,
00045 };
00046 
00047 #ifdef __cplusplus
00048 
00049 /* Declare a module.  This must be specified in the source of a library or executable. */
00050 #define PSP_MODULE_INFO(name, attributes, major_version, minor_version) \
00051         __asm__ (                                                       \
00052         "    .set push\n"                                               \
00053         "    .section .lib.ent.top, \"a\", @progbits\n"                 \
00054         "    .align 2\n"                                                \
00055         "    .word 0\n"                                                 \
00056         "__lib_ent_top:\n"                                              \
00057         "    .section .lib.ent.btm, \"a\", @progbits\n"                 \
00058         "    .align 2\n"                                                \
00059         "__lib_ent_bottom:\n"                                           \
00060         "    .word 0\n"                                                 \
00061         "    .section .lib.stub.top, \"a\", @progbits\n"                \
00062         "    .align 2\n"                                                \
00063         "    .word 0\n"                                                 \
00064         "__lib_stub_top:\n"                                             \
00065         "    .section .lib.stub.btm, \"a\", @progbits\n"                \
00066         "    .align 2\n"                                                \
00067         "__lib_stub_bottom:\n"                                          \
00068         "    .word 0\n"                                                 \
00069         "    .set pop\n"                                                \
00070         "    .text\n"                                                                                                   \
00071         );                                                              \
00072         extern char __lib_ent_top[], __lib_ent_bottom[];                \
00073         extern char __lib_stub_top[], __lib_stub_bottom[];              \
00074         extern SceModuleInfo module_info                                \
00075                 __attribute__((section(".rodata.sceModuleInfo"),        \
00076                                aligned(16), unused)) = {                \
00077           attributes, { minor_version, major_version }, #name, 0, _gp,  \
00078           __lib_ent_top, __lib_ent_bottom,                              \
00079           __lib_stub_top, __lib_stub_bottom                             \
00080         }
00081 #else
00082 /* Declare a module.  This must be specified in the source of a library or executable. */
00083 #define PSP_MODULE_INFO(name, attributes, major_version, minor_version) \
00084         __asm__ (                                                       \
00085         "    .set push\n"                                               \
00086         "    .section .lib.ent.top, \"a\", @progbits\n"                 \
00087         "    .align 2\n"                                                \
00088         "    .word 0\n"                                                 \
00089         "__lib_ent_top:\n"                                              \
00090         "    .section .lib.ent.btm, \"a\", @progbits\n"                 \
00091         "    .align 2\n"                                                \
00092         "__lib_ent_bottom:\n"                                           \
00093         "    .word 0\n"                                                 \
00094         "    .section .lib.stub.top, \"a\", @progbits\n"                \
00095         "    .align 2\n"                                                \
00096         "    .word 0\n"                                                 \
00097         "__lib_stub_top:\n"                                             \
00098         "    .section .lib.stub.btm, \"a\", @progbits\n"                \
00099         "    .align 2\n"                                                \
00100         "__lib_stub_bottom:\n"                                          \
00101         "    .word 0\n"                                                 \
00102         "    .set pop\n"                                                \
00103         "    .text\n"                                                                                                   \
00104         );                                                              \
00105         extern char __lib_ent_top[], __lib_ent_bottom[];                \
00106         extern char __lib_stub_top[], __lib_stub_bottom[];              \
00107         SceModuleInfo module_info                                       \
00108                 __attribute__((section(".rodata.sceModuleInfo"),        \
00109                                aligned(16), unused)) = {                \
00110           attributes, { minor_version, major_version }, name, 0, _gp,  \
00111           __lib_ent_top, __lib_ent_bottom,                              \
00112           __lib_stub_top, __lib_stub_bottom                             \
00113         }
00114 #endif
00115 
00116 /* Define the main thread's initial priority. */
00117 #define PSP_MAIN_THREAD_PRIORITY(priority) \
00118         unsigned int sce_newlib_priority = (priority)
00119 /* Define the main thread's stack size (in KB). */
00120 #define PSP_MAIN_THREAD_STACK_SIZE_KB(size_kb) \
00121         unsigned int sce_newlib_stack_kb_size = (size_kb)
00122 /* Define the main thread's attributes. */
00123 #define PSP_MAIN_THREAD_ATTR(attr) \
00124         unsigned int sce_newlib_attribute = (attr)
00125 #define PSP_MAIN_THREAD_ATTRIBUTE PSP_MAIN_THREAD_ATTR
00126 
00127 /* Define all main thread parameters. */
00128 #define PSP_MAIN_THREAD_PARAMS(priority, size_kb, attribute) \
00129         PSP_MAIN_THREAD_PRIORITY(priority); \
00130         PSP_MAIN_THREAD_STACK_SIZE_KB(size_kb); \
00131         PSP_MAIN_THREAD_ATTR(attribute)
00132 
00133 /* If declared, the runtime code won't create a main thread for the program. */
00134 #define PSP_NO_CREATE_MAIN_THREAD() \
00135         int sce_newlib_nocreate_thread_in_start = 1
00136 
00137 /* Declare the size of the heap (in KB) that the program wants to allocate from. */
00138 #define PSP_HEAP_SIZE_KB(size_kb) \
00139         int sce_newlib_heap_kb_size = (size_kb)
00140 
00141 /* Declare to allocate maximum heap area */
00142 #define PSP_HEAP_SIZE_MAX() \
00143         PSP_HEAP_SIZE_KB(-1)
00144 
00145 /* Declare the name of the main thread */
00146 #define PSP_MAIN_THREAD_NAME(s) const char* sce_newlib_main_thread_name = (s)
00147 
00148 #endif /* PSPMODULEINFO_H */