From f4be1364cd91e4bd0bdc2bafdf2e5115018d30c0 Mon Sep 17 00:00:00 2001 From: Dennis Heinze Date: Wed, 9 Oct 2024 20:30:58 +0200 Subject: [PATCH] Add "meta" section to ucodes By putting output into the .meta section, ucodes can now store arbitrary metadata about themselves in a blob that is separate to text and data. If a ucode does not define a .meta section, the meta blob will be a single zero byte by default. --- include/rsp.h | 6 ++++++ n64.mk | 13 +++++++++++-- rsp.ld | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/rsp.h b/include/rsp.h index 137b8a8b68..8177d2f400 100644 --- a/include/rsp.h +++ b/include/rsp.h @@ -281,6 +281,8 @@ typedef struct { void *code_end; ///< Pointer past the end of the code segment uint8_t *data; ///< Pointer to the data segment void *data_end; ///< Pointer past the end of the data segment + uint8_t *meta; ///< Pointer to the meta segment + void *meta_end; ///< Pointer past the end of the meta segment const char *name; ///< Name of the ucode uint32_t start_pc; ///< Initial RSP PC @@ -344,13 +346,17 @@ typedef struct { #define DEFINE_RSP_UCODE(ucode_name, ...) \ extern uint8_t ucode_name ## _text_start[]; \ extern uint8_t ucode_name ## _data_start[]; \ + extern uint8_t ucode_name ## _meta_start[]; \ extern uint8_t ucode_name ## _text_end[0]; \ extern uint8_t ucode_name ## _data_end[0]; \ + extern uint8_t ucode_name ## _meta_end[0]; \ rsp_ucode_t ucode_name = (rsp_ucode_t){ \ .code = ucode_name ## _text_start, \ .code_end = ucode_name ## _text_end, \ .data = ucode_name ## _data_start, \ .data_end = ucode_name ## _data_end, \ + .meta = ucode_name ## _meta_start, \ + .meta_end = ucode_name ## _meta_end, \ .name = #ucode_name, .start_pc = 0, \ .crash_handler = 0, .assert_handler = 0, \ __VA_ARGS__ \ diff --git a/n64.mk b/n64.mk index b122ea2ffe..8dc89f887b 100644 --- a/n64.mk +++ b/n64.mk @@ -137,12 +137,15 @@ $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.S SYMPREFIX="$(subst .,_,$(subst /,_,$(basename $@)))"; \ TEXTSECTION="$(basename $@).text"; \ DATASECTION="$(basename $@).data"; \ + METASECTION="$(basename $@).meta"; \ BINARY="$(basename $@).elf"; \ echo " [RSP] $<"; \ $(N64_CC) $(RSPASFLAGS) -L$(N64_LIBDIR) -nostartfiles -Wl,-Trsp.ld -Wl,--gc-sections -Wl,-Map=$(BUILD_DIR)/$(notdir $(basename $@)).map -o $@ $<; \ mv "$@" $$BINARY; \ $(N64_OBJCOPY) -O binary -j .text $$BINARY $$TEXTSECTION.bin; \ $(N64_OBJCOPY) -O binary -j .data $$BINARY $$DATASECTION.bin; \ + $(N64_OBJCOPY) -O binary -j .meta $$BINARY $$METASECTION.bin --set-section-flags .meta=alloc,load; \ + [ -s $$METASECTION.bin ] || printf '\0' > $$METASECTION.bin; \ $(N64_OBJCOPY) -I binary -O elf32-bigmips -B mips4300 \ --redefine-sym _binary_$${SYMPREFIX}_text_bin_start=$${FILENAME}_text_start \ --redefine-sym _binary_$${SYMPREFIX}_text_bin_end=$${FILENAME}_text_end \ @@ -155,9 +158,15 @@ $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.S --redefine-sym _binary_$${SYMPREFIX}_data_bin_size=$${FILENAME}_data_size \ --set-section-alignment .data=16 \ --rename-section .text=.data $$DATASECTION.bin $$DATASECTION.o; \ + $(N64_OBJCOPY) -I binary -O elf32-bigmips -B mips4300 \ + --redefine-sym _binary_$${SYMPREFIX}_meta_bin_start=$${FILENAME}_meta_start \ + --redefine-sym _binary_$${SYMPREFIX}_meta_bin_end=$${FILENAME}_meta_end \ + --redefine-sym _binary_$${SYMPREFIX}_meta_bin_size=$${FILENAME}_meta_size \ + --set-section-alignment .data=16 \ + --rename-section .text=.data $$METASECTION.bin $$METASECTION.o; \ $(N64_SIZE) -G $$BINARY; \ - $(N64_LD) -relocatable $$TEXTSECTION.o $$DATASECTION.o -o $@; \ - rm $$TEXTSECTION.bin $$DATASECTION.bin $$TEXTSECTION.o $$DATASECTION.o; \ + $(N64_LD) -relocatable $$TEXTSECTION.o $$DATASECTION.o $$METASECTION.o -o $@; \ + rm $$TEXTSECTION.bin $$DATASECTION.bin $$METASECTION.bin $$TEXTSECTION.o $$DATASECTION.o $$METASECTION.o; \ else \ echo " [AS] $<"; \ $(CC) -c $(ASFLAGS) -o $@ $<; \ diff --git a/rsp.ld b/rsp.ld index 67921ac7ca..1153aa0ece 100644 --- a/rsp.ld +++ b/rsp.ld @@ -63,5 +63,10 @@ SECTIONS } } > ram_data AT > rom_dmem + .meta : { + KEEP(*(.meta)) + *(.meta.*) + } + /DISCARD/ : { *(.MIPS.abiflags) } }