From 3851cecd9b49b7bf5d8612fa164377da6b786fb5 Mon Sep 17 00:00:00 2001 From: jaby Date: Wed, 25 Jan 2023 20:46:26 +0100 Subject: [PATCH] Prepare for supporting LBAs in persitent code --- include/PSX/AutoLBA/auto_lba.hpp | 16 ++++++++++++++++ include/PSX/AutoLBA/auto_lba_declaration.hpp | 9 +++++++++ include/PSX/Overlay/overlay.hpp | 8 ++------ include/PSX/Overlay/overlay_declaration.hpp | 7 +++---- include/PSX/Overlay/overlay_lba.hpp | 8 -------- lib/psexe.ld | 19 ++++++++++++++----- 6 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 include/PSX/AutoLBA/auto_lba.hpp create mode 100644 include/PSX/AutoLBA/auto_lba_declaration.hpp delete mode 100644 include/PSX/Overlay/overlay_lba.hpp diff --git a/include/PSX/AutoLBA/auto_lba.hpp b/include/PSX/AutoLBA/auto_lba.hpp new file mode 100644 index 00000000..d211535d --- /dev/null +++ b/include/PSX/AutoLBA/auto_lba.hpp @@ -0,0 +1,16 @@ +#ifndef __JABYENGINE_AUTO_LBA_HPP__ +#define __JABYENGINE_AUTO_LBA_HPP__ +#include "../../stdint.h" + +namespace JabyEngine { + #define __jabyengine_start_lba_request + #define __jabyengine_request_lba_for(name, file) name + #define __jabyengine_end_lba_request EndOfRequest + + struct __attribute__((packed)) AutoLBAEntry { + uint16_t lba; + uint16_t size_words; + }; +} + +#endif //!__JABYENGINE_AUTO_LBA_HPP__ \ No newline at end of file diff --git a/include/PSX/AutoLBA/auto_lba_declaration.hpp b/include/PSX/AutoLBA/auto_lba_declaration.hpp new file mode 100644 index 00000000..2d84927c --- /dev/null +++ b/include/PSX/AutoLBA/auto_lba_declaration.hpp @@ -0,0 +1,9 @@ +#ifndef __JABYENGINE_AUTO_LBA_DECLARATION_HPP__ +#define __JABYENGINE_AUTO_LBA_DECLARATION_HPP__ + +extern const JabyEngine::AutoLBAEntry overlay_lba[]; + +#define __declare_lba_header(enum_struct) \ +[[gnu::used]] \ +const JabyEngine::AutoLBAEntry __section(".header.lbas") overlay_lba[static_cast(enum_struct::EndOfRequest)] = {0} +#endif //!__JABYENGINE_AUTO_LBA_DECLARATION_HPP__ \ No newline at end of file diff --git a/include/PSX/Overlay/overlay.hpp b/include/PSX/Overlay/overlay.hpp index 1903782a..cd7b8ae8 100644 --- a/include/PSX/Overlay/overlay.hpp +++ b/include/PSX/Overlay/overlay.hpp @@ -1,6 +1,6 @@ #ifndef __JABYENGINE_OVERLAY__HPP__ #define __JABYENGINE_OVERLAY__HPP__ -#include "../../stdint.h" +#include "../AutoLBA/auto_lba.hpp" namespace JabyEngine { struct __attribute__((packed)) OverlayHeader { @@ -8,10 +8,6 @@ namespace JabyEngine { uint16_t lba_size; //< The size of the OverlayLBA section }; - // Maybe encode attributes like "isLZ4" into size parameter - struct __attribute__((packed)) OverlayLBA { - uint16_t lba; - uint16_t size_words; - }; + typedef AutoLBAEntry OverlayLBA; } #endif //!__JABYENGINE_OVERLAY__HPP__ \ No newline at end of file diff --git a/include/PSX/Overlay/overlay_declaration.hpp b/include/PSX/Overlay/overlay_declaration.hpp index 0b896dd5..279c1dfc 100644 --- a/include/PSX/Overlay/overlay_declaration.hpp +++ b/include/PSX/Overlay/overlay_declaration.hpp @@ -3,12 +3,11 @@ // No include here because this header should be included in a namespace and we don't want multiple namespace definitions of OverlayHeader and OverlayLBA +#include "../AutoLBA/auto_lba_declaration.hpp" extern const JabyEngine::OverlayHeader overlay_header; -extern const JabyEngine::OverlayLBA overlay_lba[]; #define __declare_overlay_header(function, enum_struct) \ +__declare_lba_header(enum_struct); \ [[gnu::used]] \ -const JabyEngine::OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast(enum_struct::EndOfRequest)}; \ -[[gnu::used]] \ -const JabyEngine::OverlayLBA __section(".header.lbas") overlay_lba[static_cast(enum_struct::EndOfRequest)] = {0} +const JabyEngine::OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast(enum_struct::EndOfRequest)}; #endif //!__JABYENGINE_OVERLAY_DECLARATION__HPP__ \ No newline at end of file diff --git a/include/PSX/Overlay/overlay_lba.hpp b/include/PSX/Overlay/overlay_lba.hpp deleted file mode 100644 index d86dd25d..00000000 --- a/include/PSX/Overlay/overlay_lba.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __JABYENGINE_OVERLAY_LBA__HPP__ -#define __JABYENGINE_OVERLAY_LBA__HPP__ - -#define __jabyengine_start_lba_request -#define __jabyengine_request_lba_for(name, file) name -#define __jabyengine_end_lba_request EndOfRequest - -#endif //!__JABYENGINE_OVERLAY_LBA__HPP__ \ No newline at end of file diff --git a/lib/psexe.ld b/lib/psexe.ld index fb1869e5..2c1638e6 100644 --- a/lib/psexe.ld +++ b/lib/psexe.ld @@ -44,9 +44,10 @@ __sp = __ram_top - 0x100; __dcache = ORIGIN(dcache); __dcache_top = ORIGIN(dcache) + LENGTH(dcache); -__bss_len = (__bss_end - __bss_start); -__ftext_len = (__ftext_end - __ftext_start); -__fdata_len = (__planschi_end - __fdata_start); +__bss_len = (__bss_end - __bss_start); +__ftext_len = (__ftext_end - __ftext_start); +__fdata_len = (__planschi_end - __fdata_start); +__persistent_lbas_len = (__persistent_lbas_end - __persistent_lbas_start); __stack_start = ORIGIN(ram) + LENGTH(ram); @@ -120,7 +121,7 @@ SECTIONS { LONG(TLOAD_ADDR); /* 0x001C - 0x001F : size, in bytes, of the "text" section. */ - LONG(__ftext_len + __fdata_len); + LONG(__persistent_lbas_len + __ftext_len + __fdata_len); /* 0x0020 - 0x002F : Skip "data_addr", "data_size", "bss_addr" and "bss_size". @@ -140,8 +141,16 @@ SECTIONS { . = . + 1992; } > loader + __persistent_lbas_start = ABSOLUTE(.); + .persistent_lbas TLOAD_ADDR : { + __persistent_lbas = .; + KEEP(*(.header.lbas)) + } > ram + . = ALIGN(4); + __persistent_lbas_end = ABSOLUTE(.); + __ftext_start = ABSOLUTE(.); - .text TLOAD_ADDR : { + .text : { *(.start) *(.init) KEEP (*(SORT_NONE(.fini)))