Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check in makerom files #1758

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ TEXTURE_FILES_OUT := $(foreach f,$(TEXTURE_FILES_PNG_EXTRACTED:.png=.inc.c),$(f:
ASSET_C_FILES_EXTRACTED := $(filter-out %.inc.c,$(foreach dir,$(ASSET_BIN_DIRS_EXTRACTED),$(wildcard $(dir)/*.c)))
ASSET_C_FILES_COMMITTED := $(filter-out %.inc.c,$(foreach dir,$(ASSET_BIN_DIRS_COMMITTED),$(wildcard $(dir)/*.c)))
C_FILES := $(foreach dir,$(SRC_DIRS) $(ASSET_BIN_DIRS_C_FILES),$(wildcard $(dir)/*.c))
S_FILES := $(shell grep -F "\$$(BUILD_DIR)/asm" spec | sed 's/.*$$(BUILD_DIR)\/// ; s/\.o\".*/.s/') \
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) \
$(shell grep -F "\$$(BUILD_DIR)/asm" spec | sed 's/.*$$(BUILD_DIR)\/// ; s/\.o\".*/.s/') \
$(shell grep -F "\$$(BUILD_DIR)/data" spec | sed 's/.*$$(BUILD_DIR)\/// ; s/\.o\".*/.s/')
SCHEDULE_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.schl))
BASEROM_FILES := $(shell grep -F "\$$(BUILD_DIR)/baserom" spec | sed 's/.*$$(BUILD_DIR)\/// ; s/\.o\".*//')
Expand Down
85 changes: 85 additions & 0 deletions include/PR/asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef PR_ASM_H
#define PR_ASM_H

#ifdef __sgi
#define _MIPS_ISA_MIPS1 1
#define _MIPS_ISA_MIPS2 2
#define _MIPS_ISA_MIPS3 3
#define _MIPS_ISA_MIPS4 4
#endif

#ifndef _LANGUAGE_C

#define LEAF(x) \
.balign 4 ;\
.globl x ;\
.type x, @function ;\
x: ;\
.ent x, 0 ;\
.frame $sp, 0, $ra

#define XLEAF(x) \
.balign 4 ;\
.globl x ;\
.type x, @function ;\
x: ;\
.aent x, 0

#define NESTED(x, fsize, ra) \
.globl x ;\
x: ;\
.ent x, 0 ;\
.frame $sp, fsize, ra

#define XNESTED(x) \
.globl x ;\
x: ;\
.aent x, 0

#define END(x) \
.size x, . - x ;\
.end x

#define IMPORT(x, size) \
.extern x, size

#define EXPORT(x) \
.globl x ;\
x:

#define DATA(x) \
.balign 4 ;\
.globl x ;\
.type x, @object ;\
x:

#define ENDDATA(x) \
.size x, . - x

#endif

/**
* Stack Alignment
*/
#if (_MIPS_SIM == _ABIO32)
#define NARGSAVE 4 // space for 4 args must be allocated
#define ALSZ (8-1)
#define ALMASK ~(8-1)
#elif (_MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64)
#define NARGSAVE 0 // no caller responsibilities
#define ALSZ (16-1)
#define ALMASK ~(16-1)
#endif

#define FRAMESZ(size) (((size) + ALSZ) & ALMASK)

/**
* Register Size
*/
#if (_MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA == _MIPS_ISA_MIPS2)
#define SZREG 4
#elif (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4)
#define SZREG 8
#endif

#endif
6 changes: 6 additions & 0 deletions include/boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef BOOT_H
#define BOOT_H

#define BOOT_STACK_SIZE 0x400

#endif
6 changes: 3 additions & 3 deletions spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ endseg
beginseg
name "makerom"
address 0x8007F000
include "$(BUILD_DIR)/asm/makerom/rom_header.o"
include "$(BUILD_DIR)/asm/makerom/ipl3.o"
include "$(BUILD_DIR)/asm/makerom/entry.o"
include "$(BUILD_DIR)/src/makerom/rom_header.o"
include "$(BUILD_DIR)/src/makerom/ipl3.o"
include "$(BUILD_DIR)/src/makerom/entry.o"
endseg

beginseg
Expand Down
3 changes: 2 additions & 1 deletion src/boot/boot_main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "boot.h"
#include "carthandle.h"
#include "CIC6105.h"
#include "idle.h"
Expand All @@ -9,7 +10,7 @@ StackEntry sBootStackInfo;
OSThread sIdleThread;
STACK(sIdleStack, 0x400);
StackEntry sIdleStackInfo;
STACK(sBootStack, 0x400);
STACK(sBootStack, BOOT_STACK_SIZE);

void bootproc(void) {
StackCheck_Init(&sBootStackInfo, sBootStack, STACK_TOP(sBootStack), 0, -1, "boot");
Expand Down
34 changes: 34 additions & 0 deletions src/makerom/entry.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "PR/asm.h"
#include "boot.h"

.set noreorder

.section .text

.balign 16

LEAF(entrypoint)
// Clear boot segment .bss
la $t0, _bootSegmentBssStart
#ifndef AVOID_UB
// UB: li only loads the lower 16 bits of _bootSegmentBssSize when it may be larger than this,
// so not all of bss may be cleared if it is too large
li $t1, _bootSegmentBssSize
#else
la $t1, _bootSegmentBssSize
#endif
.clear_bss:
addi $t1, $t1, -8
sw $zero, 0($t0)
sw $zero, 4($t0)
bnez $t1, .clear_bss
addi $t0, $t0, 8
// Set up stack and enter program code
lui $t2, %hi(bootproc)
lui $sp, %hi(sBootStack + BOOT_STACK_SIZE)
addiu $t2, %lo(bootproc)
jr $t2
addiu $sp, %lo(sBootStack + BOOT_STACK_SIZE)
END(entrypoint)

.fill 0x60 - (. - entrypoint)
2 changes: 2 additions & 0 deletions src/makerom/ipl3.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.text
.incbin "extracted/n64-us/baserom/makerom", 0x40, 0xFC0
15 changes: 15 additions & 0 deletions src/makerom/rom_header.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "rom_header.h"

/* 0x00 */ ENDIAN_IDENTIFIER
/* 0x01 */ PI_DOMAIN_1_CFG(64, 18, 7, 3)
/* 0x04 */ SYSTEM_CLOCK_RATE_SETTING(0xF)
/* 0x08 */ ENTRYPOINT(entrypoint)
/* 0x0C */ LIBULTRA_VERSION(2, 0, K)
/* 0x10 */ CHECKSUM()
/* 0x18 */ PADDING(8)
/* 0x20 */ ROM_NAME("ZELDA MAJORA'S MASK")
/* 0x34 */ PADDING(7)
/* 0x3B */ MEDIUM(CARTRIDGE)
/* 0x3C */ GAME_ID("ZS")
/* 0x3E */ REGION(US)
/* 0x3F */ GAME_REVISION(0)
12 changes: 7 additions & 5 deletions tools/disasm/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ def discard_decomped_files(files_spec, include_files):
.split("$(BUILD_DIR)/", 1)[1]
.replace(".o", ".c")[:-1]
)
with open(root_path / last_line, "r") as f2:
if "GLOBAL_ASM" in f2.read():
include = True
if os.path.exists(root_path / last_line):
with open(root_path / last_line, "r") as f2:
if "GLOBAL_ASM" in f2.read():
include = True
else:
assert os.path.exists(root_path / last_line.replace(".c", ".s"))

include |= force_include
if include:
Expand All @@ -131,8 +134,7 @@ def discard_decomped_files(files_spec, include_files):
continue
if included:
f[4] = new_files

new_spec.append(f)
new_spec.append(f)

return new_spec

Expand Down