Skip to content

Commit 4f537d4

Browse files
authored
[jak3] Set up ckernel (#3308)
This sets up the C Kernel for Jak 3, and makes it possible to build and load code built with `goalc --jak3`. There's not too much interesting here, other than they switched to a system where symbol IDs (unique numbers less than 2^14) are generated at compile time, and those get included in the object file itself. This is kind of annoying, since it means all tools that produce a GOAL object file need to work together to assign unique symbol IDs. And since the symbol IDs can't conflict, and are only a number between 0 and 2^14, you can't just hash and hope for no collisions. We work around this by ignoring the IDs and re-assigning our own. I think this is very similar to what the C Kernel did on early builds of Jak 3 which supported loading old format level files, which didn't have the IDs included. As far as I can tell, this shouldn't cause any problems. It defeats all of their fancy tricks to save memory by not storing the symbol string, but we don't care.
1 parent ed6639e commit 4f537d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7364
-653
lines changed

common/formatter/formatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool can_node_be_inlined(const FormatterTreeNode& curr_node, int cursor_pos) {
191191
}
192192

193193
std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
194-
std::vector<std::string> output = {},
194+
std::vector<std::string> /*output*/ = {},
195195
int cursor_pos = 0) {
196196
using namespace formatter_rules;
197197
if (!curr_node.token && curr_node.refs.empty()) {

common/formatter/rules/rule_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace config {
99
FormFormattingConfig new_flow_rule(int start_index) {
1010
FormFormattingConfig cfg;
1111
cfg.hang_forms = false;
12-
cfg.inline_until_index = [start_index](const std::vector<std::string>& curr_lines) {
12+
cfg.inline_until_index = [start_index](const std::vector<std::string>& /*curr_lines*/) {
1313
return start_index;
1414
};
1515
return cfg;

common/goal_constants.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,9 @@ constexpr int LEVEL_MAX = 6;
6262
constexpr int LEVEL_TOTAL = LEVEL_MAX + 1;
6363
} // namespace jak2
6464

65-
// TODO copypaste from jak 2 for now
6665
namespace jak3 {
6766
// for now, we don't have the ability to extend the size of the symbol table
6867
constexpr s32 GOAL_MAX_SYMBOLS = 0x4000;
69-
constexpr s32 SYM_TABLE_MEM_SIZE = 0x30000;
70-
// from the "off-by-one" symbol pointer
71-
constexpr int SYM_TO_STRING_OFFSET = 0xff37;
72-
constexpr int SYM_TO_HASH_OFFSET = 0x1fe6f;
73-
7468
// amount of levels in level heap
7569
constexpr int LEVEL_MAX = 10;
7670
// total amount of levels, including ones outside level heap (default-level)
@@ -84,7 +78,7 @@ constexpr s32 max_symbols(GameVersion version) {
8478
case GameVersion::Jak2:
8579
return jak2::GOAL_MAX_SYMBOLS;
8680
case GameVersion::Jak3:
87-
return jak2::GOAL_MAX_SYMBOLS;
81+
return jak3::GOAL_MAX_SYMBOLS;
8882
}
8983
}
9084

common/link_types.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ struct LinkHeaderV4 {
5454
uint32_t code_size; // length of object data before link data starts
5555
};
5656

57+
struct LinkHeaderV5Core {
58+
uint32_t length_to_get_to_code; // 4 length.. of link data?
59+
uint16_t version; // 8
60+
uint16_t unknown; // 10
61+
uint32_t length_to_get_to_link; // 12
62+
uint32_t link_length; // 16
63+
uint8_t n_segments; // 20
64+
char name[59]; // 21 (really??)
65+
};
66+
67+
struct LinkHeaderV5 {
68+
uint32_t type_tag; // 0 always 0?
69+
LinkHeaderV5Core core;
70+
};
71+
5772
// when a u32/s32 symbol link contains this value, (s7 + <val>) should be a 4-byte aligned address,
5873
// not including the 1 byte symbol offset. (no effect in jak 1).
5974
constexpr u32 LINK_SYM_NO_OFFSET_FLAG = 0xbadbeef;

common/symbols.h

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,180 @@ constexpr int FIX_FIXED_SYM_END_OFFSET = 0xec;
150150

151151
} // namespace jak2_symbols
152152

153+
namespace jak3_symbols {
154+
155+
constexpr int FIX_SYM_EMPTY_CAR = -0x8;
156+
constexpr int S7_OFF_FIX_SYM_EMPTY_PAIR = -0x6 - 1;
157+
constexpr int FIX_SYM_EMPTY_CDR = -0x4;
158+
constexpr int FIX_SYM_FALSE = 0x0; // GOAL boolean #f (note that this is equal to the $s7 register)
159+
constexpr int FIX_SYM_TRUE = 0x4; // GOAL boolean #t
160+
constexpr int FIX_SYM_FUNCTION_TYPE = 0x8;
161+
constexpr int FIX_SYM_BASIC = 0xc;
162+
constexpr int FIX_SYM_STRING_TYPE = 0x10;
163+
constexpr int FIX_SYM_SYMBOL_TYPE = 0x14;
164+
constexpr int FIX_SYM_TYPE_TYPE = 0x18;
165+
constexpr int FIX_SYM_OBJECT_TYPE = 0x1c;
166+
constexpr int FIX_SYM_LINK_BLOCK = 0x20;
167+
constexpr int FIX_SYM_INTEGER = 0x24;
168+
constexpr int FIX_SYM_SINTEGER = 0x28;
169+
constexpr int FIX_SYM_UINTEGER = 0x2c;
170+
constexpr int FIX_SYM_BINTEGER = 0x30;
171+
constexpr int FIX_SYM_INT8 = 0x34;
172+
constexpr int FIX_SYM_INT16 = 0x38;
173+
constexpr int FIX_SYM_INT32 = 0x3c;
174+
constexpr int FIX_SYM_INT64 = 0x40;
175+
constexpr int FIX_SYM_INT128 = 0x44;
176+
constexpr int FIX_SYM_UINT8 = 0x48;
177+
constexpr int FIX_SYM_UINT16 = 0x4c;
178+
constexpr int FIX_SYM_UINT32 = 0x50;
179+
constexpr int FIX_SYM_UINT64 = 0x54;
180+
constexpr int FIX_SYM_UINT128 = 0x58;
181+
constexpr int FIX_SYM_FLOAT = 0x5c;
182+
constexpr int FIX_SYM_PROCESS_TREE = 0x60;
183+
constexpr int FIX_SYM_PROCESS_TYPE = 0x64;
184+
constexpr int FIX_SYM_THREAD = 0x68;
185+
constexpr int FIX_SYM_STRUCTURE = 0x6c;
186+
constexpr int FIX_SYM_PAIR_TYPE = 0x70;
187+
constexpr int FIX_SYM_POINTER = 0x74;
188+
constexpr int FIX_SYM_NUMBER = 0x78;
189+
constexpr int FIX_SYM_ARRAY = 0x7c;
190+
constexpr int FIX_SYM_VU_FUNCTION = 0x80;
191+
constexpr int FIX_SYM_CONNECTABLE = 0x84;
192+
constexpr int FIX_SYM_STACK_FRAME = 0x88;
193+
constexpr int FIX_SYM_FILE_STREAM = 0x8c;
194+
constexpr int FIX_SYM_HEAP = 0x90;
195+
constexpr int FIX_SYM_NOTHING_FUNC = 0x94;
196+
constexpr int FIX_SYM_DELETE_BASIC = 0x98;
197+
constexpr int FIX_SYM_STATIC = 0x9c;
198+
constexpr int FIX_SYM_GLOBAL_HEAP = 0xa0;
199+
constexpr int FIX_SYM_DEBUG = 0xa4;
200+
constexpr int FIX_SYM_LOADING_LEVEL = 0xa8;
201+
constexpr int FIX_SYM_LOADING_PACKAGE = 0xac;
202+
constexpr int FIX_SYM_PROCESS_LEVEL_HEAP = 0xb0;
203+
constexpr int FIX_SYM_STACK = 0xb4;
204+
constexpr int FIX_SYM_SCRATCH = 0xb8;
205+
constexpr int FIX_SYM_SCRATCH_TOP = 0xbc;
206+
constexpr int FIX_SYM_ZERO_FUNC = 0xc0;
207+
constexpr int FIX_SYM_ASIZE_OF_BASIC_FUNC = 0xc4;
208+
constexpr int FIX_SYM_COPY_BASIC_FUNC = 0xc8; // bugged name
209+
constexpr int FIX_SYM_LEVEL = 0xcc;
210+
constexpr int FIX_SYM_ART_GROUP = 0xd0;
211+
constexpr int FIX_SYM_TEXTURE_PAGE_DIR = 0xd4;
212+
constexpr int FIX_SYM_TEXTURE_PAGE = 0xd8;
213+
constexpr int FIX_SYM_SOUND = 0xdc;
214+
constexpr int FIX_SYM_DGO = 0xe0;
215+
constexpr int FIX_SYM_TOP_LEVEL = 0xe4;
216+
constexpr int FIX_SYM_QUOTE = 0xe8;
217+
constexpr int FIX_SYM_LISTENER_LINK_BLOCK = 0xec;
218+
constexpr int FIX_SYM_LISTENER_FUNCTION = 0xf0;
219+
constexpr int FIX_SYM_STACK_TOP = 0xf4;
220+
constexpr int FIX_SYM_STACK_BASE = 0xf8;
221+
constexpr int FIX_SYM_STACK_SIZE = 0xfc;
222+
constexpr int FIX_SYM_KERNEL_FUNCTION = 0x100;
223+
constexpr int FIX_SYM_KERNEL_PACKAGES = 0x104;
224+
constexpr int FIX_SYM_KERNEL_BOOT_MESSAGE = 0x108;
225+
constexpr int FIX_SYM_KERNEL_BOOT_MODE = 0x10c;
226+
constexpr int FIX_SYM_KERNEL_BOOT_LEVEL = 0x110;
227+
constexpr int FIX_SYM_KERNEL_BOOT_ART_GROUP = 0x114;
228+
constexpr int FIX_SYM_KERNEL_DEBUG = 0x118;
229+
constexpr int FIX_SYM_KERNEL_VERSION = 0x11c;
230+
constexpr int FIX_SYM_KERNEL_DISPATCHER = 0x120;
231+
constexpr int FIX_SYM_SYNC_DISPATCHER = 0x124;
232+
constexpr int FIX_SYM_PRINT_COLLUMN = 0x128;
233+
constexpr int FIX_SYM_DEBUG_SEGMENT = 300;
234+
constexpr int FIX_SYM_ENABLE_METHOD_SET = 0x130;
235+
constexpr int FIX_SYM_SQL_RESULT = 0x134;
236+
constexpr int FIX_SYM_COLLAPSE_QUOTE = 0x138;
237+
constexpr int FIX_SYM_LEVEL_TYPE_LIST = 0x13C;
238+
constexpr int FIX_SYM_DECI_COUNT = 0x140;
239+
constexpr int FIX_SYM_USER = 0x144;
240+
constexpr int FIX_SYM_VIDEO_MODE = 0x148;
241+
constexpr int FIX_SYM_BOOT_VIDEO_MODE = 0x14C;
242+
constexpr int FIX_SYM_BOOT = 0x150;
243+
constexpr int FIX_SYM_DEMO = 0x154;
244+
constexpr int FIX_SYM_DEMO_SHARED = 0x158;
245+
constexpr int FIX_SYM_PREVIEW = 0x15C;
246+
constexpr int FIX_SYM_KIOSK = 0x160;
247+
constexpr int FIX_SYM_PLAY_BOOT = 0x164;
248+
constexpr int FIX_SYM_SIN = 0x168;
249+
constexpr int FIX_SYM_COS = 0x16C;
250+
constexpr int FIX_SYM_PUT_DISPLAY_ENV = 0x170;
251+
constexpr int FIX_SYM_SYNCV = 0x174;
252+
constexpr int FIX_SYM_SYNC_PATH = 0x178;
253+
constexpr int FIX_SYM_RESET_PATH = 0x17C;
254+
constexpr int FIX_SYM_RESET_GRAPH = 0x180;
255+
constexpr int FIX_SYM_DMA_SYNC = 0x184;
256+
constexpr int FIX_SYM_GS_PUT_IMR = 0x188;
257+
constexpr int FIX_SYM_GS_GET_IMR = 0x18C;
258+
constexpr int FIX_SYM_GS_STORE_IMAGE = 400;
259+
constexpr int FIX_SYM_FLUSH_CACHE = 0x194;
260+
constexpr int FIX_SYM_CPAD_OPEN = 0x198;
261+
constexpr int FIX_SYM_CPAD_GET_DATA = 0x19C;
262+
constexpr int FIX_SYM_MOUSE_GET_DATA = 0x1A0;
263+
constexpr int FIX_SYM_KEYBD_GET_DATA = 0x1A4;
264+
constexpr int FIX_SYM_INSTALL_HANDLER = 0x1A8;
265+
constexpr int FIX_SYM_INSTALL_DEBUG_HANDLER = 0x1AC;
266+
constexpr int FIX_SYM_FILE_STREAM_OPEN = 0x1B0;
267+
constexpr int FIX_SYM_FILE_STREAM_CLOSE = 0x1B4;
268+
constexpr int FIX_SYM_FILE_STREAM_LENGTH = 0x1B8;
269+
constexpr int FIX_SYM_FILE_STREAM_SEEK = 0x1BC;
270+
constexpr int FIX_SYM_FILE_STREAM_READ = 0x1C0;
271+
constexpr int FIX_SYM_FILE_STREAM_WRITE = 0x1C4;
272+
constexpr int FIX_SYM_SCF_GET_LANGUAGE = 0x1C8;
273+
constexpr int FIX_SYM_SCF_GET_TIME = 0x1CC;
274+
constexpr int FIX_SYM_SCF_GET_ASPECT = 0x1D0;
275+
constexpr int FIX_SYM_SCF_GET_VOLUME = 0x1D4;
276+
constexpr int FIX_SYM_SCF_GET_TERRITORY = 0x1D8;
277+
constexpr int FIX_SYM_SCF_GET_TIMEOUT = 0x1DC;
278+
constexpr int FIX_SYM_SCF_GET_INACTIVE_TIMEOUT = 0x1E0;
279+
constexpr int FIX_SYM_DMA_TO_IOP = 0x1E4;
280+
constexpr int FIX_SYM_KERNEL_SHUTDOWN = 0x1E8;
281+
constexpr int FIX_SYM_AYBABTU = 0x1EC;
282+
constexpr int FIX_SYM_STRING_TO_SYMBOL = 0x1F0;
283+
constexpr int FIX_SYM_SYMBOL_TO_STRING = 500;
284+
constexpr int FIX_SYM_PRINT = 0x1F8;
285+
constexpr int FIX_SYM_INSPECT = 0x1FC;
286+
constexpr int FIX_SYM_LOAD = 0x200;
287+
constexpr int FIX_SYM_LOADB = 0x204;
288+
constexpr int FIX_SYM_LOADO = 0x208;
289+
constexpr int FIX_SYM_UNLOAD = 0x20C;
290+
constexpr int FIX_SYM_FORMAT = 0x210;
291+
constexpr int FIX_SYM_MALLOC = 0x214;
292+
constexpr int FIX_SYM_KMALLOC = 0x218;
293+
constexpr int FIX_SYM_KMEMOPEN = 0x21C;
294+
constexpr int FIX_SYM_KMEMCLOSE = 0x220;
295+
constexpr int FIX_SYM_NEW_DYNAMIC_STRUCTURE = 0x224;
296+
constexpr int FIX_SYM_METHOD_SET = 0x228;
297+
constexpr int FIX_SYM_LINK = 0x22C;
298+
constexpr int FIX_SYM_LINK_BUSY = 0x230;
299+
constexpr int FIX_SYM_LINK_RESET = 0x234;
300+
constexpr int FIX_SYM_LINK_BEGIN = 0x238;
301+
constexpr int FIX_SYM_LINK_RESUME = 0x23C;
302+
constexpr int FIX_SYM_DGO_LOAD = 0x240;
303+
constexpr int FIX_SYM_SQL_QUERY = 0x244;
304+
constexpr int FIX_SYM_MC_RUN = 0x248;
305+
constexpr int FIX_SYM_MC_FORMAT = 0x24C;
306+
constexpr int FIX_SYM_MC_UNFORMAT = 0x250;
307+
constexpr int FIX_SYM_MC_CREATE_FILE = 0x254;
308+
constexpr int FIX_SYM_MC_SAVE = 600;
309+
constexpr int FIX_SYM_MC_LOAD = 0x25C;
310+
constexpr int FIX_SYM_MC_CHECK_RESULT = 0x260;
311+
constexpr int FIX_SYM_MC_GET_SLOT_INFO = 0x264;
312+
constexpr int FIX_SYM_MC_MAKEFILE = 0x268;
313+
constexpr int FIX_SYM_KSET_LANGUAGE = 0x26C;
314+
constexpr int FIX_SYM_RPC_CALL = 0x270;
315+
constexpr int FIX_SYM_RPC_BUSY = 0x274;
316+
constexpr int FIX_SYM_TEST_LOAD_DGO_C = 0x278;
317+
constexpr int FIX_SYM_SYMLINK2 = 0x27c;
318+
constexpr int FIX_SYM_SYMLINK3 = 0x280;
319+
constexpr int FIX_SYM_ULTIMATE_MEMCPY = 0x284;
320+
constexpr int FIX_SYM_PLAY = 0x288;
321+
constexpr int FIX_SYM_SYMBOL_STRING = 0x28c;
322+
constexpr int FIX_SYM_KERNEL_SYMBOL_WARNINGS = 0x290;
323+
constexpr int FIX_SYM_NETWORK_BOOTSTRAP = 0x294;
324+
325+
} // namespace jak3_symbols
326+
153327
constexpr int false_symbol_offset() {
154328
return jak1_symbols::FIX_SYM_FALSE;
155329
}

common/versions/versions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ constexpr u32 TX_PAGE_VERSION = 8;
3434
namespace jak3 {
3535
constexpr u32 ART_FILE_VERSION = 8;
3636
constexpr u32 LEVEL_FILE_VERSION = 36;
37+
constexpr u32 DGO_FILE_VERSION = 1;
3738
constexpr u32 TX_PAGE_VERSION = 8;
3839
} // namespace jak3
3940

decompiler/ObjectFile/LinkedObjectFileCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static void link_v5(LinkedObjectFile& f,
472472
for (int i = 0; i < n_segs; i++) {
473473
segment_data_offsets[i] = header->length_to_get_to_code + seg_info_array[i].data;
474474
segment_link_offsets[i] = header->length_to_get_to_link + seg_info_array[i].relocs;
475-
ASSERT(seg_info_array[i].magic == 1);
475+
ASSERT(seg_info_array[i].magic == 1); // if set, always use symlink2.
476476
}
477477

478478
// check that the data region is filled

decompiler/ObjectFile/ObjectFileDB_IR2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void ObjectFileDB::ir2_analyze_all_types(const fs::path& output_file,
367367
for (const auto& [obj_name, type_names] : all_type_names) {
368368
for (const auto& type_name : type_names) {
369369
if (str_util::starts_with(sym_name, type_name) &&
370-
type_name.length() > longest_match_length) {
370+
(int)type_name.length() > longest_match_length) {
371371
longest_match_length = type_name.length();
372372
longest_match = type_name;
373373
longest_match_object_name = obj_name;

0 commit comments

Comments
 (0)