sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
irx.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (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
16
17#ifndef __IRX_H__
18#define __IRX_H__
19
20#include <types.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define IRX_VER(major, minor) ((((major) & 0xff) << 8) + ((minor) & 0xff))
27
28struct irx_id {
29 const char *n;
30 u16 v;
31};
32
33#define IRX_ID(name, major, minor) \
34struct irx_id _irx_id = { \
35 name, IRX_VER(major, minor) \
36};
37
38/*
39 * Module imports
40 */
41#define IMPORT_MAGIC 0x41e00000
42
44{
45 u32 magic;
46 struct irx_import_table *next;
47 u16 version;
48 u16 mode;
49 char name[8];
50 void *stubs[];
51} __attribute ((packed));
52
54{
55 u32 jump;
56 u16 fno;
57 u16 ori_zero;
58} __attribute ((packed));
59
60/*
61 * Ugly, yet functional.
62 */
63#define STR(val) #val
64#define XSTR(val) STR(val)
65
66/* The name field is 8 bytes: longer names are cut, shorter ones padded with zeros. */
67#define IRX_ASM_NAME(modname) \
68 ".set\t.Lirx_name_len, 0\n\t" \
69 ".irpc\tc, " #modname "\n\t" \
70 ".if .Lirx_name_len < 8\n\t" \
71 ".ascii\t\"\\c\"\n\t" \
72 ".endif\n\t" \
73 ".set\t.Lirx_name_len, .Lirx_name_len + 1\n\t" \
74 ".endr\n\t" \
75 ".if .Lirx_name_len < 8\n\t" \
76 ".fill\t8 - .Lirx_name_len, 1, 0\n\t" \
77 ".endif\n"
78
79#ifdef __clang__
80/* The GNU assembler reads the section name below as ".text" plus a comment. Clang takes it literally and
81 puts the table header in a section of its own, away from the stubs that follow it, so write it as assembly. */
82#define DECLARE_IMPORT_TABLE(modname, major, minor) \
83 __asm__ (".section\t.text\n\t" \
84 ".balign\t4\n\t" \
85 ".word\t" XSTR(IMPORT_MAGIC) ", 0\n\t" \
86 ".short\t" XSTR(IRX_VER(major, minor)) ", 0\n\t" \
87 IRX_ASM_NAME(modname));
88#else
89#define DECLARE_IMPORT_TABLE(modname, major, minor) \
90static struct irx_import_table _imp_##modname \
91 __attribute__((section(".text\n\t#"), unused))= { \
92 magic: IMPORT_MAGIC, version: IRX_VER(major, minor), \
93 name: #modname, };
94#endif
95
96// .word 0x03e00008 == jr $ra (return immediately), this value will be patched later
97#define DECLARE_IMPORT(ord, name) \
98 __asm__ (".section\t.text\n\t" \
99 ".globl\t"#name"\n\t"#name":\n\t" \
100 ".word 0x03e00008\n\t" \
101 ".word " STR(0x24000000|ord));
102
103#define END_IMPORT_TABLE \
104 __asm__ (".section\t.text\n\t.word\t0, 0");
105
106/*
107 * Module exports
108 *
109 * I'm not sure why GCC won't generate the fptrs initializers, so I fell back
110 * to the above approach to generate the fptrs themselves. Cleaner solutions
111 * requested.
112 */
113#define EXPORT_MAGIC 0x41c00000
114
115void __attribute__((unused)) _retonly();
116
118 u32 magic;
119 struct irx_export_table *next;
120 u16 version;
121 u16 mode;
122 u8 name[8];
123 void *fptrs[];
124};
125
126#ifdef __clang__
127#define DECLARE_EXPORT_TABLE(modname, major, minor) \
128extern struct irx_export_table _exp_##modname; \
129 __asm__ (".section\t.text\n\t" \
130 ".balign\t4\n\t" \
131 ".globl\t_exp_" #modname "\n\t" \
132 ".type\t_exp_" #modname ", @object\n" \
133 "_exp_" #modname ":\n\t" \
134 ".word\t" XSTR(EXPORT_MAGIC) ", 0\n\t" \
135 ".short\t" XSTR(IRX_VER(major, minor)) ", 0\n\t" \
136 IRX_ASM_NAME(modname));
137#else
138#define DECLARE_EXPORT_TABLE(modname, major, minor) \
139struct irx_export_table _exp_##modname \
140 __attribute__((section(".text\n\t#"), unused)) = { \
141 magic: EXPORT_MAGIC, version: IRX_VER(major, minor), \
142 name: #modname, };
143#endif
144
145#define DECLARE_EXPORT(fptr) \
146 __asm__ (".section\t.text\n\t.word\t" STR(fptr));
147
148#define END_EXPORT_TABLE __asm__ (".section\t.text\n\t.word\t0");
149
150#ifdef __cplusplus
151}
152#endif
153
154#endif /* __IRX_H__ */
Definition irx.h:28