Share bss section with planschi section

This commit is contained in:
Jaby Blubb 2023-08-27 02:43:59 +02:00
parent 6ff067587d
commit 5c40ef119e
8 changed files with 87 additions and 84 deletions

View File

@ -7,7 +7,7 @@
#include "../cd_file_types.hpp" #include "../cd_file_types.hpp"
#include "file_processor.hpp" #include "file_processor.hpp"
extern "C" uint32_t __heap_base; extern "C" uint32_t __heap_start;
namespace JabyEngine { namespace JabyEngine {
class CDFileProcessor { class CDFileProcessor {
@ -20,7 +20,7 @@ namespace JabyEngine {
size_t sector_count = 0; size_t sector_count = 0;
static constexpr BufferConfiguration new_default() { static constexpr BufferConfiguration new_default() {
return {&__heap_base, BufferConfiguration::MediumSectorCount}; return {&__heap_start, BufferConfiguration::MediumSectorCount};
} }
}; };

View File

@ -58,7 +58,7 @@ CCFLAGS += -DJABYENGINE_$(TV_FORMAT)
#Linker flags #Linker flags
LDFLAGS_release += -Os LDFLAGS_release += -Os
LDFLAGS_all += -Wl,-Map=$(TARGET).map -nostdlib -T$(AUTO_OVERLAY_DIR)/Overlays.ld -T$(JABY_ENGINE_DIR)/lib/psexe.ld -static -Wl,--gc-sections -Wl,--build-id=none -Wl,--no-check-sections LDFLAGS_all += -Wl,-Map=$(TARGET).map -nostdlib -T$(JABY_ENGINE_DIR)/lib/psexe.ld -static -Wl,--gc-sections -Wl,--build-id=none -Wl,--no-check-sections
LDFLAGS_all += $(ARCHFLAGS) -Wl,--oformat=$(FORMAT) LDFLAGS_all += $(ARCHFLAGS) -Wl,--oformat=$(FORMAT)
LDFLAGS_all += $(LDFLAGS_$(BUILD_PROFILE)) LDFLAGS_all += $(LDFLAGS_$(BUILD_PROFILE))

View File

@ -11,7 +11,7 @@ OVERLAY_TARGET = $(foreach ovl, $(OVERLAYSECTION), $(OUTPUT_DIR)/Overlay$(ovl))
#Linking rule #Linking rule
$(TARGET).elf: $(OBJS) $(JABY_ENGINE_LIB_DIR)/lib$(JABY_ENGINE_LIB_NAME).a $(AUTO_OVERLAY_DIR)/Overlays.ld $(TARGET).elf: $(OBJS) $(JABY_ENGINE_LIB_DIR)/lib$(JABY_ENGINE_LIB_NAME).a $(AUTO_OVERLAY_DIR)/Overlays.ld
$(LD) -o $(TARGET).elf $(LDFLAGS_all) $(LDFLAGS) $(OBJS) -L$(JABY_ENGINE_LIB_DIR) -l$(JABY_ENGINE_LIB_NAME) $(LIBS) $(LD) -o $(TARGET).elf $(LDFLAGS_all) $(LDFLAGS) $(OBJS) -L$(JABY_ENGINE_LIB_DIR) -L$(AUTO_OVERLAY_DIR) -l$(JABY_ENGINE_LIB_NAME) $(LIBS)
#Strips the psexe #Strips the psexe
$(TARGET).psexe: $(TARGET).elf $(TARGET).psexe: $(TARGET).elf

View File

@ -25,7 +25,6 @@ SOFTWARE.
*/ */
OUTPUT_FORMAT("binary") OUTPUT_FORMAT("binary")
EXTERN(_ZN10JabyEngine5startEv) EXTERN(_ZN10JabyEngine5startEv)
ENTRY(_ZN10JabyEngine5startEv) ENTRY(_ZN10JabyEngine5startEv)
@ -34,7 +33,6 @@ TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000;
MEMORY { MEMORY {
loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048
ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000
ram2 (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000
dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 dcache : ORIGIN = 0x1f800000, LENGTH = 0x400
} }
@ -62,30 +60,31 @@ SECTIONS {
} }
/*Overlay sections created by mkoverlay*/ /*Overlay sections created by mkoverlay*/
INCLUDE Overlays.ld
SECTIONS { SECTIONS {
.planschi __bss_end : SUBALIGN(4) .planschi __engine_bss_end : SUBALIGN(4)
{ {
__planschi_start = .; __planschi_start = .;
__boot_loader_start = .; __boot_loader_start = .;
*libJabyEngine.a:*_boot.o(.text.startup._GLOBAL__*) *libJabyEngine_*.a:*_boot.o(.text.startup._GLOBAL__*)
*_boot.o(.text.startup._GLOBAL__*) *_boot.o(.text.startup._GLOBAL__*)
*libJabyEngine.a:*_boot.o(.ctors) *libJabyEngine_*.a:*_boot.o(.ctors)
*_boot.o(.ctors) *_boot.o(.ctors)
*libJabyEngine.a:*_boot.o(.text.*) *libJabyEngine_*.a:*_boot.o(.text.*)
*_boot.o(.text.*) *_boot.o(.text.*)
*libJabyEngine.a:*_boot.o(.rodata*) *libJabyEngine_*.a:*_boot.o(.rodata*)
*_boot.o(.rodata*) *_boot.o(.rodata*)
*libJabyEngine.a:*_boot.o(.sdata*) *libJabyEngine_*.a:*_boot.o(.sdata*)
*_boot.o(.sdata*) *_boot.o(.sdata*)
*libJabyEngine.a:*_boot.o(.data*) *libJabyEngine_*.a:*_boot.o(.data*)
*_boot.o(.data*) *_boot.o(.data*)
*libJabyEngine.a:*_boot.o(.sbss*) *libJabyEngine_*.a:*_boot.o(.sbss*)
*_boot.o(.sbss*) *_boot.o(.sbss*)
*libJabyEngine.a:*_boot.o(.bss*) *libJabyEngine_*.a:*_boot.o(.bss*)
*_boot.o(.bss*) *_boot.o(.bss*)
*libJabyEngine.a:*_boot.o(*) *libJabyEngine_*.a:*_boot.o(*)
*_boot.o(*) *_boot.o(*)
. = ALIGN(4); . = ALIGN(4);
@ -141,16 +140,17 @@ SECTIONS {
. = . + 1992; . = . + 1992;
} > loader } > loader
__persistent_lbas_start = ABSOLUTE(.);
.persistent_lbas TLOAD_ADDR : { .persistent_lbas TLOAD_ADDR : {
__persistent_lbas_start = .;
__persistent_lbas = .; __persistent_lbas = .;
KEEP(*(.header.lbas)) KEEP(*(.header.lbas))
} > ram
. = ALIGN(4); . = ALIGN(4);
__persistent_lbas_end = ABSOLUTE(.); __persistent_lbas_end = .;
} > ram
__ftext_start = ABSOLUTE(.); __ftext_start = ABSOLUTE(.);
.text : { .text : {
__text_start = .;
*(.start) *(.start)
*(.init) *(.init)
KEEP (*(SORT_NONE(.fini))) KEEP (*(SORT_NONE(.fini)))
@ -164,14 +164,12 @@ SECTIONS {
KEEP(*(.init)) KEEP(*(.init))
. = ALIGN(16); . = ALIGN(16);
KEEP(*(.fini)) KEEP(*(.fini))
} > ram
. = ALIGN(16); . = ALIGN(16);
__text_end = .; __text_end = .;
} > ram
__ftext_end = ABSOLUTE(.); __ftext_end = ABSOLUTE(.);
__fdata_start = ABSOLUTE(.); __fdata_start = ABSOLUTE(.);
.rodata : { .rodata : {
*(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*)
. = ALIGN(16); . = ALIGN(16);
@ -210,8 +208,8 @@ SECTIONS {
*(.rodata1) *(.rodata1)
} > ram } > ram
__data_start = .;
.data : { .data : {
__data_start = .;
*(.a0table) *(.a0table)
*(.data .data.* .gnu.linkonce.d.*) *(.data .data.* .gnu.linkonce.d.*)
*(.data1) *(.data1)
@ -219,24 +217,34 @@ SECTIONS {
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*) *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
*(.got.plt) *(.got.plt)
*(.got) *(.got)
__data_end = .;
} > ram } > ram
__data_end = .; .engine_bss : {
__engine_bss_start = .;
*libJabyEngine_*.a:*(.dynsbss)
*libJabyEngine_*.a:*(.sbss .sbss.* .gnu.linkonce.sb.*)
*libJabyEngine_*.a:*(.scommon)
*libJabyEngine_*.a:*(.dynbss)
*libJabyEngine_*.a:*(.bss .bss.* .gnu.linkonce.b.*)
*libJabyEngine_*.a:*(COMMON)
. = ALIGN(4);
__engine_bss_end = .;
} > ram
__fdata_end = .; __fdata_end = .;
.bss __persistent_overlay_end (NOLOAD) : {
__bss_start = .; __bss_start = .;
.bss : {
*(.dynsbss) *(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*) *(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon) *(.scommon)
*(.dynbss) *(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*) *(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON) *(COMMON)
} > ram
. = ALIGN(4); . = ALIGN(4);
__bss_end = .; __bss_end = .;
__heap_start = __heap_base; } > ram
/*. = ADDR(.text) - 0x800;*/ __heap_start = __bss_end;
__end = .; __end = .;
} }

View File

@ -1,3 +1,4 @@
include ../../lib/RebuildTarget.mk
JABY_ENGINE_DIR = ../../ JABY_ENGINE_DIR = ../../
ARTIFACT = libJabyEngine_$(TV_FORMAT) ARTIFACT = libJabyEngine_$(TV_FORMAT)

View File

@ -3,6 +3,13 @@
#include <PSX/System/IOPorts/dma_io.hpp> #include <PSX/System/IOPorts/dma_io.hpp>
#include <stdio.h> #include <stdio.h>
extern "C" uint32_t __heap_start;
extern "C" uint32_t __bss_start;
extern "C" uint32_t __bss_end;
extern "C" uint32_t __bss_len;
extern "C" uint32_t __planschi_start;
extern "C" uint32_t __planschi_end;
namespace JabyEngine { namespace JabyEngine {
namespace boot { namespace boot {
namespace Start { namespace Start {
@ -29,6 +36,9 @@ namespace JabyEngine {
void start() { void start() {
printf("Starting Planschbecken\n"); printf("Starting Planschbecken\n");
printf("Heap starts @0x%p\n", &__heap_start);
printf("BSS from 0x%p to 0x%p (%u)\n", &__bss_start, &__bss_end, __bss_len);
printf("PLANSCHI from 0x%p to 0x%p\n", &__planschi_start, &__planschi_end);
boot::Start::setup(); boot::Start::setup();
printf("Running main...\n"); printf("Running main...\n");

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mkoverlay" name = "mkoverlay"
version = "1.1.1" version = "1.5.0"
edition = "2021" edition = "2021"
[profile.release] [profile.release]

View File

@ -1,9 +1,7 @@
use super::super::types::{OverlayDesc, OverlaySection}; use super::super::types::{OverlayDesc, OverlaySection};
use tool_helper::{Error, format_if_error, Output}; use tool_helper::{Error, Output};
use std::io::Write; use std::io::Write;
const OVERLAY_DEFAULT_START:&'static str = "__planschi_start"; // < will probably be "__boot_loader_start" later
macro_rules! section_end_name_template { macro_rules! section_end_name_template {
() => { () => {
"__{}_end" "__{}_end"
@ -11,25 +9,8 @@ macro_rules! section_end_name_template {
} }
pub fn write(output: &mut Output, overlay_desc: &OverlayDesc) -> Result<(), Error> { pub fn write(output: &mut Output, overlay_desc: &OverlayDesc) -> Result<(), Error> {
fn create_heap_base(overlay_desc: &OverlayDesc) -> String { let has_overlays = !overlay_desc.is_empty();
let (first_entry, additional_slots_iter) = (&overlay_desc[0].name, overlay_desc.iter().skip(1)); let mut slot_start_adr = format!(section_end_name_template!(), "engine_bss");
let mut heap_start = format!(concat!("MAX({}, ", section_end_name_template!(), ")"), OVERLAY_DEFAULT_START, first_entry);
for slot in additional_slots_iter {
heap_start = format!(concat!("MAX(", section_end_name_template!(), ", {})"), slot.name, heap_start);
}
heap_start
}
if overlay_desc.is_empty() {
write_heap_base(output, OVERLAY_DEFAULT_START)?;
}
else {
write_heap_base(output, &create_heap_base(&overlay_desc))?;
}
let mut slot_start_adr = format!(section_end_name_template!(), "bss");
writeln!(output, "")?; writeln!(output, "")?;
writeln!(output, "SECTIONS {{")?; writeln!(output, "SECTIONS {{")?;
@ -38,22 +19,25 @@ pub fn write(output: &mut Output, overlay_desc: &OverlayDesc) -> Result<(), Erro
writeln!(output, "\t/*{}*/", slot.name)?; writeln!(output, "\t/*{}*/", slot.name)?;
writeln!(output, "\tOVERLAY {} : NOCROSSREFS SUBALIGN(4) {{", slot_start_adr)?; writeln!(output, "\tOVERLAY {} : NOCROSSREFS SUBALIGN(4) {{", slot_start_adr)?;
write_section(output, &slot.sections, false)?; write_section(output, &slot.sections, false)?;
writeln!(output, "\t}}")?; writeln!(output, "\t}} > ram")?;
writeln!(output, "\t. = ALIGN(4);")?; writeln!(output, "\t. = ALIGN(4);")?;
writeln!(output, concat!("\t", section_end_name_template!(), " = .;"), slot.name)?; writeln!(output, concat!("\t", section_end_name_template!(), " = .;"), slot.name)?;
writeln!(output, "")?; writeln!(output, "")?;
slot_start_adr = format!(section_end_name_template!(), slot.name); slot_start_adr = format!(section_end_name_template!(), slot.name);
} }
if has_overlays {
writeln!(output, "\t__persistent_overlay_end = .;")?;
}
else {
writeln!(output, "\t__persistent_overlay_end =__engine_bss_end;")?;
}
writeln!(output, "}}")?; writeln!(output, "}}")?;
return Ok(()); return Ok(());
} }
fn write_heap_base(output: &mut Output, heap_base: &str) -> Result<(), Error> {
format_if_error!(writeln!(output, "__heap_base = {};", heap_base), "Writing default LD Script failed with: {error_text}")?;
Ok(())
}
fn write_section(output: &mut Output, sections: &Vec<OverlaySection>, add_end_name: bool) -> Result<(), Error> { fn write_section(output: &mut Output, sections: &Vec<OverlaySection>, add_end_name: bool) -> Result<(), Error> {
for section in sections { for section in sections {
writeln!(output, "\t\t.{} {{", section.name)?; writeln!(output, "\t\t.{} {{", section.name)?;