pspsdk-1.0+beta2
pspmoduleinfo.h
Go to the documentation of this file.
1 /*
2  * PSP Software Development Kit - http://www.pspdev.org
3  * -----------------------------------------------------------------------
4  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
5  *
6  * pspmoduleinfo.h - Definitions for the .rodata.sceModuleInfo ELF section.
7  *
8  * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
9  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
10  * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
11  *
12  * $Id: pspmoduleinfo.h 2434 2008-10-15 17:37:25Z iwn $
13  */
14 #ifndef PSPMODULEINFO_H
15 #define PSPMODULEINFO_H
16 
17 /* Note: Some of the structures and definitions in this file were extrapolated from
18  symbolic debugging information found in the Japanese version of Puzzle Bobble. */
19 
20 /* Module info structure. Used to declare a module (library or executable). This structure
21  is required in all PSP executables. */
22 typedef struct _scemoduleinfo {
23  unsigned short modattribute;
24  unsigned char modversion[2];
25  char modname[27];
26  char terminal;
27  void * gp_value;
28  void * ent_top;
29  void * ent_end;
30  void * stub_top;
31  void * stub_end;
33 
35 
36 extern char _gp[];
37 
39 {
45 };
46 
47 #ifdef __cplusplus
48 
49 /* Declare a module. This must be specified in the source of a library or executable. */
50 #define PSP_MODULE_INFO(name, attributes, major_version, minor_version) \
51  __asm__ ( \
52  " .set push\n" \
53  " .section .lib.ent.top, \"a\", @progbits\n" \
54  " .align 2\n" \
55  " .word 0\n" \
56  "__lib_ent_top:\n" \
57  " .section .lib.ent.btm, \"a\", @progbits\n" \
58  " .align 2\n" \
59  "__lib_ent_bottom:\n" \
60  " .word 0\n" \
61  " .section .lib.stub.top, \"a\", @progbits\n" \
62  " .align 2\n" \
63  " .word 0\n" \
64  "__lib_stub_top:\n" \
65  " .section .lib.stub.btm, \"a\", @progbits\n" \
66  " .align 2\n" \
67  "__lib_stub_bottom:\n" \
68  " .word 0\n" \
69  " .set pop\n" \
70  " .text\n" \
71  ); \
72  extern char __lib_ent_top[], __lib_ent_bottom[]; \
73  extern char __lib_stub_top[], __lib_stub_bottom[]; \
74  extern SceModuleInfo module_info \
75  __attribute__((section(".rodata.sceModuleInfo"), \
76  aligned(16), unused)) = { \
77  attributes, { minor_version, major_version }, #name, 0, _gp, \
78  __lib_ent_top, __lib_ent_bottom, \
79  __lib_stub_top, __lib_stub_bottom \
80  }
81 #else
82 /* Declare a module. This must be specified in the source of a library or executable. */
83 #define PSP_MODULE_INFO(name, attributes, major_version, minor_version) \
84  __asm__ ( \
85  " .set push\n" \
86  " .section .lib.ent.top, \"a\", @progbits\n" \
87  " .align 2\n" \
88  " .word 0\n" \
89  "__lib_ent_top:\n" \
90  " .section .lib.ent.btm, \"a\", @progbits\n" \
91  " .align 2\n" \
92  "__lib_ent_bottom:\n" \
93  " .word 0\n" \
94  " .section .lib.stub.top, \"a\", @progbits\n" \
95  " .align 2\n" \
96  " .word 0\n" \
97  "__lib_stub_top:\n" \
98  " .section .lib.stub.btm, \"a\", @progbits\n" \
99  " .align 2\n" \
100  "__lib_stub_bottom:\n" \
101  " .word 0\n" \
102  " .set pop\n" \
103  " .text\n" \
104  ); \
105  extern char __lib_ent_top[], __lib_ent_bottom[]; \
106  extern char __lib_stub_top[], __lib_stub_bottom[]; \
107  SceModuleInfo module_info \
108  __attribute__((section(".rodata.sceModuleInfo"), \
109  aligned(16), unused)) = { \
110  attributes, { minor_version, major_version }, name, 0, _gp, \
111  __lib_ent_top, __lib_ent_bottom, \
112  __lib_stub_top, __lib_stub_bottom \
113  }
114 #endif
115 
116 /* Define the main thread's initial priority. */
117 #define PSP_MAIN_THREAD_PRIORITY(priority) \
118  unsigned int sce_newlib_priority = (priority)
119 /* Define the main thread's stack size (in KB). */
120 #define PSP_MAIN_THREAD_STACK_SIZE_KB(size_kb) \
121  unsigned int sce_newlib_stack_kb_size = (size_kb)
122 /* Define the main thread's attributes. */
123 #define PSP_MAIN_THREAD_ATTR(attr) \
124  unsigned int sce_newlib_attribute = (attr)
125 #define PSP_MAIN_THREAD_ATTRIBUTE PSP_MAIN_THREAD_ATTR
126 
127 /* Define all main thread parameters. */
128 #define PSP_MAIN_THREAD_PARAMS(priority, size_kb, attribute) \
129  PSP_MAIN_THREAD_PRIORITY(priority); \
130  PSP_MAIN_THREAD_STACK_SIZE_KB(size_kb); \
131  PSP_MAIN_THREAD_ATTR(attribute)
132 
133 /* If declared, the runtime code won't create a main thread for the program. */
134 #define PSP_NO_CREATE_MAIN_THREAD() \
135  int sce_newlib_nocreate_thread_in_start = 1
136 
137 /* Declare the size of the heap (in KB) that the program wants to allocate from. */
138 #define PSP_HEAP_SIZE_KB(size_kb) \
139  int sce_newlib_heap_kb_size = (size_kb)
140 
141 /* Declare to allocate maximum heap area */
142 #define PSP_HEAP_SIZE_MAX() \
143  PSP_HEAP_SIZE_KB(-1)
144 
145 /* Declare the name of the main thread */
146 #define PSP_MAIN_THREAD_NAME(s) const char* sce_newlib_main_thread_name = (s)
147 
148 #endif /* PSPMODULEINFO_H */