From 69152efdad181c70fd794ecba5f5f48f23bc67bd Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 12 Nov 2023 11:13:20 -0500 Subject: [PATCH] msp430: reduce excess memory usage; trim linker script --- libalee/dictionary.hpp | 5 ++-- msp430/alee-msp430.cpp | 15 ++++++++---- msp430/msp430fr2476.ld | 54 ------------------------------------------ 3 files changed, 13 insertions(+), 61 deletions(-) diff --git a/libalee/dictionary.hpp b/libalee/dictionary.hpp index 2b7afdf..96db2ea 100644 --- a/libalee/dictionary.hpp +++ b/libalee/dictionary.hpp @@ -37,9 +37,8 @@ * - 0+ bytes of entry's data... */ -class Dictionary +struct Dictionary { -public: /** * The beginning of the dictionary is used for "internal" variables. */ @@ -129,7 +128,7 @@ public: return std::equal(b1, e1, b2, eqchars); } - virtual ~Dictionary() = default; + virtual ~Dictionary() {}; private: // Case-insensitive comparison. diff --git a/msp430/alee-msp430.cpp b/msp430/alee-msp430.cpp index 48a806e..c270612 100644 --- a/msp430/alee-msp430.cpp +++ b/msp430/alee-msp430.cpp @@ -42,13 +42,18 @@ static void initUART(); static void Software_Trim(); #define MCLK_FREQ_MHZ (8) // MCLK = 8MHz -#define ALEE_RODICTSIZE (7000) +#define ALEE_RODICTSIZE (9200) __attribute__((section(".lodict"))) #include "core.fth.h" static bool exitLpm; static Addr isr_list[24] = {}; -static SplitMemDictRW dict (alee_dat, 0x10000); + +using DictType = SplitMemDictRW; + +alignas(DictType) +static unsigned char dictbuf[sizeof(DictType)]; +static auto dict = reinterpret_cast(dictbuf); int main() { @@ -59,7 +64,9 @@ int main() SYSCFG0 = FRWPPW; (void)alee_dat_len; - State state (dict, readchar); + dict->lodict = alee_dat; + dict->hidict = 0x10000; + State state (*dict, readchar); Parser::customParse = findword; serputs("alee forth\n\r"); @@ -371,7 +378,7 @@ bool alee_isr_handle(unsigned index) const Addr isr = isr_list[index]; if (isr != 0) { - State isrstate (dict, readchar); + State isrstate (*dict, readchar); exitLpm = false; isrstate.execute(isr); return exitLpm; diff --git a/msp430/msp430fr2476.ld b/msp430/msp430fr2476.ld index 9a2b089..08b0299 100644 --- a/msp430/msp430fr2476.ld +++ b/msp430/msp430fr2476.ld @@ -166,10 +166,8 @@ SECTIONS .rodata : { . = ALIGN(2); - *(.plt) *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*) *(.rodata1) - KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) } > FRAM /* Note: This is a separate .rodata section for sections which are @@ -193,8 +191,6 @@ SECTIONS KEEP (*(SORT(.fini_array.*))) PROVIDE (__fini_array_end = .); . = ALIGN(2); - *(.eh_frame_hdr) - KEEP (*(.eh_frame)) /* gcc uses crtbegin.o to find the start of the constructors, so we make sure it is first. Because this is a wildcard, it @@ -218,17 +214,6 @@ SECTIONS KEEP (*(.dtors)) } > FRAM - /* This section contains data that is initialised during load - but not on application reset. */ - .persistent : - { - . = ALIGN(2); - PROVIDE (__persistent_start = .); - *(.persistent) - . = ALIGN(2); - PROVIDE (__persistent_end = .); - } > FRAM - .tinyram : {} > TINYRAM .data : @@ -236,15 +221,10 @@ SECTIONS . = ALIGN(2); PROVIDE (__datastart = .); - KEEP (*(.jcr)) - *(.data.rel.ro.local) *(.data.rel.ro*) - *(.dynamic) - *(.data .data.* .gnu.linkonce.d.*) KEEP (*(.gnu.linkonce.d.*personality*)) SORT(CONSTRUCTORS) *(.data1) - *(.got.plt) *(.got) /* We want the small data sections together, so single-instruction offsets can access them all, and initialized data all before uninitialized, so @@ -268,7 +248,6 @@ SECTIONS { . = ALIGN(2); PROVIDE (__bssstart = .); - *(.dynbss) *(.sbss .sbss.*) *(.bss .bss.* .gnu.linkonce.b.*) . = ALIGN(2); @@ -288,29 +267,6 @@ SECTIONS PROVIDE (__noinit_end = .); } > RAM - /* We create this section so that "end" will always be in the - RAM region (matching .stack below), even if the .bss - section is empty. */ - .heap (NOLOAD) : - { - . = ALIGN(2); - __heap_start__ = .; - _end = __heap_start__; - PROVIDE (end = .); - KEEP (*(.heap)) - _end = .; - PROVIDE (end = .); - /* This word is here so that the section is not empty, and thus - not discarded by the linker. The actual value does not matter - and is ignored. */ - LONG(0); - __heap_end__ = .; - __HeapLimit = __heap_end__; - } > RAM - /* WARNING: Do not place anything in RAM here. - The heap section must be the last section in RAM and the stack - section must be placed at the very end of the RAM region. */ - .stack (ORIGIN (RAM) + LENGTH(RAM)) : { PROVIDE (__stack = .); @@ -330,19 +286,9 @@ SECTIONS . = ALIGN(2); KEEP (*(SORT(.crt_*))) - . = ALIGN(2); - KEEP (*(.lowtext)) - . = ALIGN(2); *(.text .stub .text.* .gnu.linkonce.t.* .text:*) - KEEP (*(.text.*personality*)) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.interp .hash .dynsym .dynstr .gnu.version*) - PROVIDE (__etext = .); - PROVIDE (_etext = .); - PROVIDE (etext = .); . = ALIGN(2); KEEP (*(.init)) KEEP (*(.fini))