default.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #ifndef __DEFAULT_H
  2. #define __DEFAULT_H
  3. #define asm __asm__ /* for ANSI mode compiling */
  4. #define _main __main
  5. #define __ATTR_STD__ __attribute__((__stkparm__))
  6. #define __ATTR_STD_NORETURN__ __attribute__((__stkparm__,__noreturn__))
  7. #define CALLBACK __ATTR_STD__
  8. #define __ATTR_TIOS__ __ATTR_STD__
  9. #define __ATTR_TIOS_NORETURN__ __ATTR_STD_NORETURN__
  10. #define __ATTR_TIOS_CALLBACK__ CALLBACK
  11. #define __ATTR_GCC__
  12. #define __ATTR_LIB_C__ __attribute__((__regparm__(4)))
  13. #define __ATTR_LIB_ASM__ __ATTR_STD__
  14. #define __ATTR_LIB_ASM_NORETURN__ __ATTR_STD_NORETURN__
  15. #define __ATTR_LIB_CALLBACK_C__ CALLBACK
  16. #define __ATTR_LIB_CALLBACK_ASM__ CALLBACK
  17. #ifndef FARGO
  18. #ifdef USE_TI92P
  19. #define USE_TI92PLUS
  20. #endif
  21. #ifdef USE_TI89
  22. asm (".xdef _ti89");
  23. asm (".xdef _ti89ti");
  24. #if !defined (USE_TI92PLUS) && !defined (USE_V200)
  25. #define _TI89_ONLY
  26. #define _ONE_CALC_ONLY
  27. #endif
  28. #endif
  29. #ifdef USE_TI92PLUS
  30. asm (".xdef _ti92plus");
  31. #if !defined (USE_TI89) && !defined (USE_V200)
  32. #define _TI92PLUS_ONLY
  33. #define _ONE_CALC_ONLY
  34. #endif
  35. #endif
  36. #ifdef USE_V200
  37. asm (".xdef _v200");
  38. #if !defined (USE_TI89) && !defined (USE_TI92PLUS)
  39. #define _V200_ONLY
  40. #define _ONE_CALC_ONLY
  41. #endif
  42. #endif
  43. #if !defined (USE_TI89) && !defined (USE_TI92PLUS) && !defined (USE_V200)
  44. /* The program uses its own symbols to control the linker.
  45. So support all calcs. */
  46. #define USE_TI89
  47. #define USE_TI92PLUS
  48. #define USE_V200
  49. #endif
  50. #if defined (USE_TI89) && defined (USE_TI92PLUS) && defined (USE_V200)
  51. #define _SUPPORT_ALL_CALCS
  52. #endif
  53. #ifdef _NO_INCLUDE_PATCH
  54. #define _INCLUDE_PATCH(patchname)
  55. #else
  56. #define _INCLUDE_PATCH(patchname) asm(".xdef __ref_all_"#patchname)
  57. #endif
  58. /* Quick hacks for better archive support. */
  59. #ifdef _GENERIC_ARCHIVE
  60. #ifndef NO_CALC_DETECT
  61. #define NO_CALC_DETECT
  62. #endif
  63. #undef OPTIMIZE_ROM_CALLS
  64. #undef USE_FLINE_ROM_CALLS
  65. #undef USE_FLINE_JUMPS
  66. #undef USE_4_BYTE_FLINE_JUMPS
  67. #undef USE_INTERNAL_FLINE_EMULATOR
  68. #undef KERNEL_FORMAT_RELOCS
  69. #undef KERNEL_FORMAT_ROM_CALLS
  70. #undef KERNEL_FORMAT_BSS
  71. #undef COMPRESSED_FORMAT_RELOCS
  72. #undef COMPRESSED_FORMAT_ROM_CALLS
  73. #undef COMPRESSED_FORMAT_BSS
  74. #undef MLINK_FORMAT_RELOCS
  75. #undef MLINK_FORMAT_ROM_CALLS
  76. #undef MLINK_FORMAT_BSS
  77. #ifndef MIN_AMS
  78. #define MIN_AMS 100
  79. #endif
  80. #else
  81. _INCLUDE_PATCH(__startup_code);
  82. #ifndef MIN_AMS
  83. #define MIN_AMS 101
  84. #endif
  85. #endif
  86. #ifdef EXECUTE_IN_GHOST_SPACE
  87. #if defined(USE_KERNEL) || defined(DOORS)
  88. #error EXECUTE_IN_GHOST_SPACE does not work in kernel mode yet
  89. #endif
  90. _INCLUDE_PATCH(__execute_in_ghost_space);
  91. #endif
  92. #ifndef NO_CALC_DETECT
  93. #if !defined (_SUPPORT_ALL_CALCS)
  94. #define _NEED_CALC_DETECT
  95. _INCLUDE_PATCH(__detect_calc);
  96. #ifdef _ONE_CALC_ONLY
  97. _INCLUDE_PATCH(__test_for_specific_calc);
  98. #ifdef USE_TI89
  99. _INCLUDE_PATCH(__test_for_89);
  100. #endif
  101. #ifdef USE_TI92PLUS
  102. _INCLUDE_PATCH(__test_for_92p);
  103. #endif
  104. #ifdef USE_V200
  105. _INCLUDE_PATCH(__test_for_v200);
  106. #endif
  107. #else
  108. _INCLUDE_PATCH(__test_against_specific_calc);
  109. #ifndef USE_TI89
  110. _INCLUDE_PATCH(__test_for_89);
  111. #endif
  112. #ifndef USE_TI92PLUS
  113. _INCLUDE_PATCH(__test_for_92p);
  114. #endif
  115. #ifndef USE_V200
  116. _INCLUDE_PATCH(__test_for_v200);
  117. #endif
  118. #endif
  119. #elif defined (OPTIMIZE_CALC_CONSTS)
  120. #define _NEED_CALC_DETECT
  121. _INCLUDE_PATCH(__detect_calc);
  122. _INCLUDE_PATCH(__test_for_specific_calc);
  123. _INCLUDE_PATCH(__test_for_any_calc);
  124. #endif
  125. #endif
  126. #if (!defined (NO_AMS_CHECK)) && ((MIN_AMS>101 && (defined (USE_TI89))) || (MIN_AMS>100 && (defined (USE_TI92PLUS))) || (MIN_AMS>206 && (defined (USE_V200))))
  127. #define _NEED_AMS_CHECK
  128. _INCLUDE_PATCH(__MIN_AMS_required);
  129. #if (MIN_AMS>=310)
  130. _INCLUDE_PATCH(__MIN_AMS_3_10);
  131. #if (MIN_AMS>310)
  132. #warning Cannot check for AMS versions greater than 3.10
  133. #endif
  134. #elif (MIN_AMS>=301)
  135. _INCLUDE_PATCH(__MIN_AMS_3_01);
  136. #elif (MIN_AMS>=300)
  137. _INCLUDE_PATCH(__MIN_AMS_3_00);
  138. #elif (MIN_AMS>=209)
  139. _INCLUDE_PATCH(__MIN_AMS_2_09);
  140. #if (MIN_AMS>209)
  141. #warning Cannot check for AMS versions between 2.09 and 3.00
  142. #endif
  143. #elif (MIN_AMS>=208)
  144. _INCLUDE_PATCH(__MIN_AMS_2_08);
  145. #elif (MIN_AMS>=207)
  146. _INCLUDE_PATCH(__MIN_AMS_2_07);
  147. #elif (MIN_AMS>=205)
  148. _INCLUDE_PATCH(__MIN_AMS_2_05);
  149. #if (MIN_AMS>205)
  150. #warning Cannot check for AMS version 2.06
  151. #endif
  152. #elif (MIN_AMS>=204)
  153. _INCLUDE_PATCH(__MIN_AMS_2_04);
  154. #elif (MIN_AMS>=203)
  155. _INCLUDE_PATCH(__MIN_AMS_2_03);
  156. #elif (MIN_AMS>=202)
  157. _INCLUDE_PATCH(__MIN_AMS_2_02);
  158. #elif (MIN_AMS>=201)
  159. _INCLUDE_PATCH(__MIN_AMS_2_01);
  160. #elif (MIN_AMS>=200)
  161. _INCLUDE_PATCH(__MIN_AMS_2_00);
  162. #elif (MIN_AMS>=105)
  163. _INCLUDE_PATCH(__MIN_AMS_1_05);
  164. #if (MIN_AMS>105)
  165. #warning Cannot check for AMS versions between 1.05 and 2.00
  166. #endif
  167. #elif (MIN_AMS>=101)
  168. _INCLUDE_PATCH(__MIN_AMS_1_01);
  169. #if (MIN_AMS>101)
  170. #warning Cannot check for AMS versions between 1.01 and 1.05
  171. #endif
  172. #endif
  173. #endif
  174. /* The following auto-generated definitions are preliminary and possibly overridden later by other files. */
  175. #define __rom_call_addr_concat _rom_call_addr_concat
  176. /* Begin Auto-Generated Part */
  177. #define MIN_AMS_MAJOR (MIN_AMS/100)
  178. #define MIN_AMS_MINOR (MIN_AMS%100)
  179. #define __jmp_tbl (*(void***)0xC8)
  180. #define _rom_call_addr_concat(intindex,romindex) (__jmp_tbl[intindex])
  181. #define _rom_call_addr_hack_concat(intindex,romindex,addr,minams,minindex) (MIN_AMS >= (minams) || TIOS_entries > (minindex) ? _rom_call_addr_concat (intindex, romindex) : ({ asm (".xdef __ref_all___reject_unofficial_os"); (void *) (addr); }))
  182. #define _rom_call_addr_hack(index,addr,minams) (_rom_call_addr_hack_concat(0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
  183. #define _rom_call_addr(index) (_rom_call_addr_concat(0x##index,_ROM_CALL_##index))
  184. #define _rom_call_attr(type,args,attr,index) (*({typedef __ATTR_TIOS__ attr type(*__temp__type__)args;(__temp__type__)(__rom_call_addr_concat(0x##index,_ROM_CALL_##index));}))
  185. #define _rom_call_concat(type,args,intindex,romindex) (*((type(*__ATTR_TIOS__)args)(__rom_call_addr_concat(intindex,romindex))))
  186. #define _rom_call_hack_attr_concat(type,args,attr,intindex,romindex,addr,minams,minindex) (*({ typedef __ATTR_TIOS__ attr type (*__temp__type__hack__) args; (__temp__type__hack__) (MIN_AMS >= (minams) || TIOS_entries > (minindex) ? (const void *) (&(_rom_call_concat (void, (void), (intindex), (romindex)))) : ({ asm (".xdef __ref_all___reject_unofficial_os"); (const void *) (addr); })); }))
  187. #define _rom_call_hack_attr(type,args,attr,index,addr,minams) (_rom_call_hack_attr_concat(type,args,attr,0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
  188. #define _rom_call_hack(type,args,index,addr,minams) (_rom_call_hack_attr_concat(type,args,,0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
  189. #define _rom_call(type,args,index) (_rom_call_concat(type,args,0x##index,_ROM_CALL_##index))
  190. #define import_binary(filename,symname) asm(".globl "#symname"\n"#symname":\n\t.incbin \""filename"\"")
  191. /* End Auto-Generated Part */
  192. #define TIOS_entries (*(unsigned long*)(__jmp_tbl-1))
  193. #ifdef UNOFFICIAL_OS_SUPPORT
  194. #undef _rom_call_hack_attr_concat
  195. #define _rom_call_hack_attr_concat(type,args,attr,intindex,romindex,addr,minams) (*({typedef __ATTR_TIOS__ attr type(*__temp__type__hack__)args;(__temp__type__hack__)(MIN_AMS>=(minams)||TIOS_entries>(intindex)?(const void*)(&(_rom_call_concat(void,(void),(intindex),(romindex)))):(const void*)__invalid_rom_call_hack);}))
  196. #undef _rom_call_addr_hack_concat
  197. #define _rom_call_addr_hack_concat(intindex,romindex,addr,minams,minindex) (MIN_AMS>=(minams)||TIOS_entries>(minindex)?_rom_call_addr_concat(intindex,romindex):__invalid_rom_call_hack)
  198. extern void *__invalid_rom_call_hack;
  199. #endif
  200. #ifdef REJECT_UNOFFICIAL_OS
  201. _INCLUDE_PATCH(__reject_unofficial_os);
  202. #endif
  203. #ifdef USE_INTERNAL_FLINE_EMULATOR
  204. _INCLUDE_PATCH(__fline_internal_emulator);
  205. #else
  206. #if defined (USE_4_BYTE_FLINE_JUMPS)
  207. #error You need to define USE_INTERNAL_FLINE_EMULATOR for 4-byte F-Line jumps
  208. #elif defined (USE_FLINE_ROM_CALLS) || defined (USE_FLINE_JUMPS)
  209. #if (MIN_AMS < 204) && !defined (USE_FLINE_EMULATOR)
  210. #error You need to define USE_[INTERNAL_]FLINE_EMULATOR or an appropriate value for MIN_AMS
  211. #endif
  212. #endif
  213. #endif
  214. #ifdef USE_FLINE_ROM_CALLS
  215. _INCLUDE_PATCH(__fline_rom_calls);
  216. asm(".set _F_LINE,0xF800");
  217. #endif
  218. #ifdef USE_4_BYTE_FLINE_JUMPS
  219. _INCLUDE_PATCH(__fline_jumps_4byte);
  220. asm(".xdef __ld_use_4byte_fline_jumps");
  221. #else
  222. #ifdef USE_FLINE_JUMPS
  223. _INCLUDE_PATCH(__fline_jumps);
  224. asm(".xdef __ld_use_fline_jumps");
  225. #endif
  226. #endif
  227. asm(".set _A_LINE,0xA000");
  228. #define __need_in_use_bit _INCLUDE_PATCH(__set_file_in_use_bit);
  229. #ifdef SET_FILE_IN_USE_BIT
  230. __need_in_use_bit;
  231. #endif
  232. #ifndef _GENERIC_ARCHIVE
  233. #ifdef COMPRESSED_FORMAT_DATA_VAR
  234. _INCLUDE_PATCH(__compressed_format_data_var);
  235. #else
  236. #ifdef MLINK_FORMAT_DATA_VAR
  237. _INCLUDE_PATCH(__mlink_format_data_var);
  238. #else
  239. _INCLUDE_PATCH(__kernel_format_data_var);
  240. #endif
  241. #endif
  242. #endif
  243. #if defined (DOORS) || defined (USE_KERNEL)
  244. #if MIN_AMS >= 200
  245. #define AMS_1xx 0
  246. #else
  247. #define AMS_1xx ((_ram_call(14,unsigned short)&0x0F00)==0x100)
  248. #endif
  249. #if MIN_AMS >= 300
  250. #define AMS_2xx 0
  251. #else
  252. #define AMS_2xx ((_ram_call(14,unsigned short)&0x0F00)==0x200)
  253. #endif
  254. #define AMS_3xx ((_ram_call(14,unsigned short)&0x0F00)==0x300)
  255. #else
  256. #if MIN_AMS >= 200
  257. #define AMS_1xx 0
  258. #else
  259. #define AMS_1xx (TIOS_entries<1000)
  260. #endif
  261. #if MIN_AMS >= 300
  262. #define AMS_2xx 0
  263. #define AMS_3xx 1
  264. #else
  265. #define AMS_2xx (!AMS_1xx && TIOS_entries<0x608)
  266. #define AMS_3xx (TIOS_entries>=0x608)
  267. #endif
  268. #endif
  269. #endif
  270. #ifdef OMIT_BSS_INIT
  271. asm(".xdef __ld_omit_bss_init");
  272. #endif
  273. #ifndef __PINT
  274. #define __PINT
  275. #ifdef __INT_SHORT__
  276. typedef union
  277. {
  278. short *__sp;
  279. int *__ip;
  280. #ifndef STRICT_POINTERS
  281. unsigned short *__usp;
  282. unsigned int *__uip;
  283. #endif
  284. } __pshort __attribute__((__transparent_union__));
  285. typedef union
  286. {
  287. unsigned short *__sp;
  288. unsigned int *__ip;
  289. #ifndef STRICT_POINTERS
  290. short *__ssp;
  291. int *__sip;
  292. #endif
  293. } __pushort __attribute__((__transparent_union__));
  294. typedef long *__plong;
  295. typedef unsigned long *__pulong;
  296. typedef union
  297. {
  298. const short *__sp;
  299. const int *__ip;
  300. #ifndef STRICT_POINTERS
  301. const unsigned short *__usp;
  302. const unsigned int *__uip;
  303. #endif
  304. } __cpshort __attribute__((__transparent_union__));
  305. typedef union
  306. {
  307. const unsigned short *__sp;
  308. const unsigned int *__ip;
  309. #ifndef STRICT_POINTERS
  310. const short *__ssp;
  311. const int *__sip;
  312. #endif
  313. } __cpushort __attribute__((__transparent_union__));
  314. typedef const long *__cplong;
  315. typedef const unsigned long *__cpulong;
  316. #else
  317. typedef short *__pshort;
  318. typedef unsigned short *__pushort;
  319. typedef union
  320. {
  321. long *__lp;
  322. int *__ip;
  323. #ifndef STRICT_POINTERS
  324. unsigned long *__ulp;
  325. unsigned int *__uip;
  326. #endif
  327. } __plong __attribute__((__transparent_union__));
  328. typedef union
  329. {
  330. unsigned long *__lp;
  331. unsigned int *__ip;
  332. #ifndef STRICT_POINTERS
  333. long *__slp;
  334. int *__sip;
  335. #endif
  336. } __pulong __attribute__((__transparent_union__));
  337. typedef const short *__cpshort;
  338. typedef const unsigned short *__cpushort;
  339. typedef union
  340. {
  341. const long *__lp;
  342. const int *__ip;
  343. #ifndef STRICT_POINTERS
  344. const unsigned long *__ulp;
  345. const unsigned int *__uip;
  346. #endif
  347. } __cplong __attribute__((__transparent_union__));
  348. typedef union
  349. {
  350. const unsigned long *__lp;
  351. const unsigned int *__ip;
  352. #ifndef STRICT_POINTERS
  353. const long *__slp;
  354. const int *__sip;
  355. #endif
  356. } __cpulong __attribute__((__transparent_union__));
  357. #endif
  358. #endif
  359. extern float __BC(short,...)__ATTR_LIB_ASM__;
  360. #define _tios_float_1(f,x,t) ({typedef float(*__temp__type__)(short,t)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x);})
  361. #define _tios_float_2(f,x,y,t1,t2) ({typedef float(*__temp__type__)(short,t1,t2)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x,y);})
  362. #if !defined (NOSTUB) && !defined (DOORS) && !defined (FARGO)
  363. #ifdef USE_KERNEL
  364. #include <doors.h>
  365. #else
  366. #include <nostub.h>
  367. #endif
  368. #endif
  369. #endif