Shifting segments

This commit is contained in:
a
2025-06-19 21:09:48 -04:00
parent 8cf2c982e8
commit 31840adf4b
5 changed files with 36 additions and 62 deletions

View File

@@ -40,14 +40,14 @@ DECLARE_SEGMENT(engine)
DECLARE_SEGMENT(behavior)
DECLARE_SEGMENT(scripts)
DECLARE_SEGMENT(goddard)
DECLARE_SEGMENT(framebuffers)
extern u8 _goddardSegmentStart[];
#ifdef USE_EXT_RAM
extern u8 _engineSegmentStart[];
extern u8 _framebuffersSegmentNoloadStart[];
extern u8 _engineSegmentNoloadEnd[];
extern u8 _engineSegmentEnd[];
extern u8 _framebuffersSegmentNoloadEnd[];
#endif
DECLARE_LEVEL_SEGMENT(menu)
DECLARE_LEVEL_SEGMENT(intro)

View File

@@ -1,7 +1,9 @@
#ifndef SEGMENTS_H
#define SEGMENTS_H
#include "config.h"
#ifndef _LD
#include "segment_symbols.h"
#endif
/*
* Memory addresses for segments. Ideally, this header file would not be
@@ -13,50 +15,17 @@
* linker script syntax.
*/
#define SEG_START 0x8005C000
#define USE_EXT_RAM // Undefine this to set a strict 4MB limit.
#define SEG_FRAMEBUFFERS_SIZE (2 * SCREEN_WIDTH * SCREEN_HEIGHT * 3)
#define SEG_GODDARD_POOL_OFFSET 0x52000 // Offset from right side of pool
#define SEG_GODDARD (SEG_POOL_END - SEG_GODDARD_POOL_OFFSET)
#ifndef USE_EXT_RAM /* Default: Runs out of memory quickly when importing custom assets. */
#define SEG_RAM_END 0x80400000
#define SEG_POOL_START SEG_START
#define SEG_POOL_SIZE 0x165000
#define SEG_POOL_END (SEG_POOL_START + SEG_POOL_SIZE)
#define SEG_BUFFERS SEG_POOL_END
#ifdef VERSION_EU
#define SEG_ENGINE 0x8036FF00
#ifndef USE_EXT_RAM
#define RAM_END 0x80400000
#else
#define SEG_ENGINE 0x80378800
#define RAM_END 0x80800000
#endif
#define SEG_FRAMEBUFFERS (SEG_RAM_END - SEG_FRAMEBUFFERS_SIZE)
#else /* Use Expansion Pak space for pool. */
/*
* Workaround for running out of pool space due to
* importing large custom content.
*/
#ifdef VERSION_CN
#define SEG_RAM_END 0x807C0000 // iQue has stuff like EEPROM mapped at 807C0000 onwards. TODO: Code this using osMemSize
#else
#define SEG_RAM_END 0x80800000
#endif
#define SEG_BUFFERS SEG_START
#define SEG_ENGINE ((u32) &_engineSegmentStart)
#define SEG_FRAMEBUFFERS ((u32) &_framebuffersSegmentNoloadStart)
#define SEG_POOL_START ((u32) &_framebuffersSegmentNoloadEnd)
#define SEG_POOL_END SEG_RAM_END
#define SEG_POOL_END_4MB 0x80400000 // For the error message screen enhancement.
#endif
#define SEG_POOL_START _framebuffersSegmentNoloadEnd // 0x0165000 in size
#define SEG_GODDARD SEG_POOL_START + 0x113000
#define POOL_SIZE RAM_END - SEG_POOL_START
#endif // SEGMENTS_H

35
sm64.ld
View File

@@ -2,7 +2,10 @@ OUTPUT_ARCH (mips)
/* include/segments.h defines SEG_POOL_START, SEG_POOL_END, SEG_BUFFERS,
* SEG_GODDARD, SEG_ENGINE, SEG_FRAMEBUFFERS */
#define _LD
#include "segments.h"
#include "config.h"
#include "ld.h"
@@ -22,8 +25,10 @@ SECTIONS
BEGIN_NOLOAD(zbuffer) {
BUILD_DIR/src/buffers/zbuffer.o(.bss*);
}
END_NOLOAD(zbuffer)
. = _zbufferSegmentNoloadEnd;
. = SEG_BUFFERS;
BEGIN_NOLOAD(buffers)
{
BUILD_DIR/src/buffers/buffers.o(.bss*);
@@ -40,16 +45,8 @@ SECTIONS
BUILD_DIR/src/buffers/gfx_output_buffer.o(.bss*);
}
END_NOLOAD(buffers)
/* lib/src/__osDevMgrMain.c and lib/src/osCreateViManager.c contain infinite
* loops compiled without -g, which cause the return statements and the .o
* files themselves to be aligned to 32-byte boundaries. But the linker
* Nintendo used did not respect .o file alignment, and aligned the files
* only to 16 bytes, in some cases misaligning them. We force the same to
* happen using the SUBALIGN directive. This is harmless; the alignment is
* just an optimization. */
BEGIN_SEG(main, )
SUBALIGN(16)
. = _buffersSegmentNoloadEnd;
BEGIN_SEG(main, .)
{
BUILD_DIR/asm/entry.o(.text);
BUILD_DIR/asm/decompress.o(.text);
@@ -103,12 +100,14 @@ SECTIONS
#endif
CREATE_LO_HI_PAIR(_mainSegmentNoloadSize, SIZEOF (.main.noload))
. = _mainSegmentNoloadEnd;
BEGIN_SEG(engine, ADDR_OR_ALIGN(SEG_ENGINE))
BEGIN_SEG(engine, .)
{
BUILD_DIR/src/engine*.o(.text);
BUILD_DIR/src/engine*.o(.data*);
BUILD_DIR/src/engine*.o(.rodata*);
. = ALIGN(0x100);
}
END_SEG(engine)
BEGIN_NOLOAD(engine)
@@ -117,13 +116,19 @@ SECTIONS
}
END_NOLOAD(engine)
. = ADDR_OR_ALIGN(SEG_FRAMEBUFFERS);
. = _engineSegmentNoloadEnd;
BEGIN_NOLOAD(framebuffers)
{
BUILD_DIR/src/buffers/framebuffers.o(.bss*);
. = ALIGN(0x100);
}
END_NOLOAD(framebuffers)
__mainPoolStart = .;
__mainPoolSize = RAM_END - .;
ASSERT((. <= (SEG_POOL_START + POOL_SIZE)), "Error: extended past pool end.")
BEGIN_SEG(entry, 0x10000000)
{
BUILD_DIR/levels/entry.o(.data);
@@ -338,8 +343,8 @@ SECTIONS
*(*);
}
ASSERT((_goddardSegmentNoloadEnd <= SEG_POOL_END), "Error: menu segment extended past pool end")
ASSERT((_goddardSegmentNoloadEnd <= SEG_POOL_START + POOL_SIZE), "Error: menu segment extended past pool end")
ASSERT((_mainSegmentNoloadEnd <= _engineSegmentStart), "Error: main segment extended into engine.")
ASSERT((_engineSegmentNoloadEnd <= _framebuffersSegmentNoloadStart), "Error: engine segment extended into framebuffers.")
ASSERT((_framebuffersSegmentNoloadEnd <= SEG_RAM_END), "Error: framebuffers segment extended past RDRAM end")
ASSERT((_framebuffersSegmentNoloadEnd <= RAM_END), "Error: framebuffers segment extended past RDRAM end")
}

View File

@@ -130,7 +130,7 @@ void setup_mesg_queues(void) {
void alloc_pool(void) {
void *start = (void *) SEG_POOL_START;
void *end = (void *) SEG_POOL_END;
void *end = (void *) (SEG_POOL_START + POOL_SIZE);
main_pool_init(start, end);
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);

View File

@@ -367,8 +367,8 @@ void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd) {
}
void load_engine_code_segment(void) {
void *startAddr = (void *) SEG_ENGINE;
u32 totalSize = SEG_FRAMEBUFFERS - SEG_ENGINE;
void *startAddr = (void *) _engineSegmentStart;
u32 totalSize = _engineSegmentEnd - _engineSegmentStart;
UNUSED u32 alignedSize = ALIGN16(_engineSegmentRomEnd - _engineSegmentRomStart);
bzero(startAddr, totalSize);