Revert "Allocate initialized sections for EWRAM and IWRAM (#3877)" (#3891)

This reverts commit f24deb9301.
This commit is contained in:
Martin Griffin 2024-01-02 13:54:42 +00:00 committed by GitHub
parent f24deb9301
commit d1ab525552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 175 deletions

View file

@ -473,7 +473,7 @@ endif
$(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS)
cd $(OBJ_DIR) && sed "s#tools/#../../tools/#g" ../../$(LD_SCRIPT) > ld_script.ld
LDFLAGS = -Map ../../$(MAP) --no-warn-rwx-segments
LDFLAGS = -Map ../../$(MAP)
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS) libagbsyscall
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ <objects> <lib>"
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat

View file

@ -3,6 +3,4 @@
extern u32 IntrMain[];
extern void ReInitializeEWRAM();
#endif //GUARD_CRT0_H

View file

@ -6,10 +6,8 @@
#define TRUE 1
#define FALSE 0
#define IWRAM_DATA __attribute__((section(".bss")))
#define EWRAM_DATA __attribute__((section(".sbss")))
#define IWRAM_INIT __attribute__((section(".iwram")))
#define EWRAM_INIT __attribute__((section(".ewram")))
#define IWRAM_DATA __attribute__((section("iwram_data")))
#define EWRAM_DATA __attribute__((section("ewram_data")))
#define UNUSED __attribute__((unused))
#if MODERN

View file

@ -13,35 +13,19 @@ MEMORY
SECTIONS {
.ewram ORIGIN(EWRAM) : AT (__ewram_lma)
ALIGN(4)
{
__ewram_start = .;
*(.ewram*)
__ewram_end = .;
} > EWRAM
.ewram.sbss (NOLOAD) :
ewram 0x2000000 (NOLOAD) :
ALIGN(4)
{
INCLUDE "sym_ewram.ld"
src/*.o(.sbss);
gflib/*.o(.sbss);
src/*.o(ewram_data);
gflib/*.o(ewram_data);
*libc.a:impure.o(.data);
*libc.a:locale.o(.data);
*libc.a:mallocr.o(.data);
} > EWRAM
.iwram ORIGIN(IWRAM) : AT (__iwram_lma)
ALIGN(4)
{
__iwram_start = .;
*(.iwram*);
__iwram_end = .;
} > IWRAM
.iwram.bss (NOLOAD) :
iwram 0x3000000 (NOLOAD) :
ALIGN(4)
{
/* .bss starts at 0x3000000 */
@ -1340,20 +1324,6 @@ SECTIONS {
data/*.o(.rodata);
} > ROM = 0
.data.iwram :
ALIGN(4)
{
__iwram_lma = .;
. = . + (__iwram_end - __iwram_start);
} > ROM = 0
.data.ewram :
ALIGN(4)
{
__ewram_lma = .;
. = . + (__ewram_end - __ewram_start);
} > ROM = 0
__rom_end = .;
/* DWARF debug sections.

View file

@ -12,32 +12,15 @@ MEMORY
}
SECTIONS {
.ewram ORIGIN(EWRAM) : AT (__ewram_lma)
ewram 0x2000000 (NOLOAD) :
ALIGN(4)
{
__ewram_start = .;
*(.ewram*)
__ewram_end = .;
src/*.o(ewram_data);
gflib/*.o(ewram_data);
} > EWRAM
.ewram.sbss (NOLOAD) :
ALIGN(4)
{
src/*.o(.sbss);
gflib/*.o(.sbss);
} > EWRAM
.iwram ORIGIN(IWRAM) : AT (__iwram_lma)
ALIGN(4)
{
__iwram_start = .;
*(.iwram*);
__iwram_end = .;
} > IWRAM
.iwram.bss (NOLOAD) :
iwram 0x3000000 (NOLOAD) :
ALIGN(4)
{
src/*.o(.bss);
@ -55,8 +38,9 @@ SECTIONS {
} > IWRAM
/* BEGIN ROM DATA */
. = 0x8000000;
.text ORIGIN(ROM) :
.text :
ALIGN(4)
{
src/rom_header.o(.text*);
@ -141,20 +125,6 @@ SECTIONS {
src/graphics.o(.rodata);
} > ROM =0
.data.iwram :
ALIGN(4)
{
__iwram_lma = .;
. = . + (__iwram_end - __iwram_start);
} > ROM = 0
.data.ewram :
ALIGN(4)
{
__ewram_lma = .;
. = . + (__ewram_end - __ewram_start);
} > ROM = 0
__rom_end = .;
/* DWARF debug sections.

View file

@ -12,32 +12,15 @@ MEMORY
}
SECTIONS {
.ewram ORIGIN(EWRAM) : AT (__ewram_lma)
ewram 0x2000000 (NOLOAD) :
ALIGN(4)
{
__ewram_start = .;
*(.ewram*)
__ewram_end = .;
src/*.o(ewram_data);
gflib/*.o(ewram_data);
test/*.o(ewram_data);
} > EWRAM
.ewram.sbss (NOLOAD) :
ALIGN(4)
{
src/*.o(.sbss);
gflib/*.o(.sbss);
test/*.o(.sbss);
} > EWRAM
.iwram ORIGIN(IWRAM) : AT (__iwram_lma)
ALIGN(4)
{
__iwram_start = .;
*(.iwram*);
__iwram_end = .;
} > IWRAM
.iwram.sbss (NOLOAD) :
iwram 0x3000000 (NOLOAD) :
ALIGN(4)
{
src/*.o(.bss);
@ -114,20 +97,6 @@ SECTIONS {
src/libisagbprn.o(.rodata);
} > ROM =0
.data.iwram :
ALIGN(4)
{
__iwram_lma = .;
. = . + (__iwram_end - __iwram_start);
} > ROM = 0
.data.ewram :
ALIGN(4)
{
__ewram_lma = .;
. = . + (__ewram_end - __ewram_start);
} > ROM = 0
tests :
ALIGN(4)
{

View file

@ -6,28 +6,22 @@
.align 2, 0
Init::
@ Set up location for IRQ stack
mov r0, #PSR_IRQ_MODE
msr cpsr_cf, r0
ldr sp, sp_irq
@ Set up location for system stack
mov r0, #PSR_SYS_MODE
msr cpsr_cf, r0
ldr sp, sp_sys
@ Prepare for interrupt handling
ldr r1, =INTR_VECTOR
adr r0, IntrMain
str r0, [r1]
@ Dispatch memory reset request to hardware
.if MODERN
mov r0, #255 @ RESET_ALL
svc #1 << 16
@ Fill RAM areas with appropriate data
bl InitializeWorkingMemory
@ Jump to AgbMain
.endif @ MODERN
ldr r1, =AgbMain + 1
mov lr, pc
bx r1
@ Re-init if AgbMain exits
b Init
.align 2, 0
@ -130,54 +124,3 @@ IntrMain_RetAddr:
.pool
.align 2, 0 @ Don't pad with nop.
@ Fills initialized IWRAM and EWRAM sections in RAM from LMA areas in ROM
InitializeWorkingMemory:
push {r0-r3,lr}
ldr r0, =__iwram_lma
ldr r1, =__iwram_start
ldr r2, =__iwram_end
cmp r1, r2
beq skip_iwram_copy
bl CopyMemory_DMA
skip_iwram_copy:
ldr r0, =__ewram_lma
ldr r1, =__ewram_start
ldr r2, =__ewram_end
cmp r1, r2
beq skip_ewram_copy
bl CopyMemory_DMA
skip_ewram_copy:
pop {r0-r3,lr}
bx lr
@ Uses a DMA transfer to load from r0 into r1 until r2
CopyMemory_DMA:
subs r2, r2, r1
lsr r2, r2, #2
mov r4, #0x80000000
orr r4, r4, #(1 << 26)
orr r2, r2, r4
ldr r3, =REG_DMA3
stmia r3, {r0, r1, r2}
bx lr
.thumb
@ Called from C code to reinitialize working memory after a link connection failure
ReInitializeEWRAM::
ldr r0, =__ewram_lma
ldr r1, =__ewram_start
ldr r2, =__ewram_end
cmp r1, r2
beq EndReinitializeEWRAM
subs r2, r1
movs r3, #1
lsls r3, r3, #26
orrs r2, r2, r3
swi 0x0B
EndReinitializeEWRAM:
bx lr
.pool
.align 2, 0 @ Don't pad with nop.

View file

@ -93,6 +93,11 @@ void EnableVCountIntrAtLine150(void);
void AgbMain()
{
// Modern compilers are liberal with the stack on entry to this function,
// so RegisterRamReset may crash if it resets IWRAM.
#if !MODERN
RegisterRamReset(RESET_ALL);
#endif //MODERN
*(vu16 *)BG_PLTT = RGB_WHITE; // Set the backdrop to white on startup
InitGpuRegManager();
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;

View file

@ -1,6 +1,5 @@
#include "global.h"
#include "main.h"
#include "crt0.h"
#include "gpu_regs.h"
#include "m4a.h"
#include "load_save.h"
@ -16,7 +15,6 @@ void ReloadSave(void)
u16 imeBackup = REG_IME;
REG_IME = 0;
RegisterRamReset(RESET_EWRAM);
ReInitializeEWRAM();
ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_FORCED_BLANK);
REG_IME = imeBackup;
gMain.inBattle = FALSE;