diff options
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | alee-standalone.cpp | 5 | ||||
-rw-r--r-- | alee.cpp | 57 | ||||
-rw-r--r-- | alee.hpp | 6 | ||||
-rw-r--r-- | forth/core-ext.fth | 2 | ||||
-rw-r--r-- | forth/core.fth | 65 | ||||
-rw-r--r-- | forth/msp430.fth | 101 | ||||
-rw-r--r-- | libalee/alee.hpp | 7 | ||||
-rw-r--r-- | libalee/config.hpp | 5 | ||||
-rw-r--r-- | libalee/corewords.cpp | 6 | ||||
-rw-r--r-- | libalee/corewords.hpp | 11 | ||||
-rw-r--r-- | libalee/ctype.hpp | 12 | ||||
-rw-r--r-- | libalee/dictionary.cpp | 16 | ||||
-rw-r--r-- | libalee/dictionary.hpp | 12 | ||||
-rw-r--r-- | libalee/parser.cpp | 16 | ||||
-rw-r--r-- | libalee/parser.hpp | 2 | ||||
-rw-r--r-- | libalee/state.cpp | 12 | ||||
-rw-r--r-- | libalee/state.hpp | 11 | ||||
-rw-r--r-- | libalee/types.cpp | 10 | ||||
-rw-r--r-- | libalee/types.hpp | 1 | ||||
-rw-r--r-- | memdict.hpp | 2 | ||||
-rw-r--r-- | msp430/Makefile | 12 | ||||
-rw-r--r-- | msp430/alee-msp430.cpp | 149 | ||||
-rwxr-xr-x | msp430/build.sh | 9 | ||||
-rw-r--r-- | msp430/examples/spi.txt | 15 | ||||
-rw-r--r-- | msp430/examples/uart.txt | 13 | ||||
-rw-r--r-- | msp430/msp430fr2476.h | 52 | ||||
-rw-r--r-- | msp430/msp430fr2476.ld | 118 | ||||
-rw-r--r-- | splitmemdict.hpp | 2 | ||||
-rw-r--r-- | splitmemdictrw.hpp | 6 |
30 files changed, 480 insertions, 268 deletions
@@ -15,9 +15,12 @@ msp430: AR := msp430-elf-gcc-ar msp430: CXXFLAGS += -I. -I/usr/msp430-elf/usr/include msp430: CXXFLAGS += -Os -mmcu=msp430fr2476 -ffunction-sections -fdata-sections msp430: CXXFLAGS += -flto -fno-asynchronous-unwind-tables -fno-threadsafe-statics -fno-stack-protector -msp430: LDFLAGS += -L msp430 -T msp430fr2476.ld -Wl,-gc-sections +msp430: CXXFLAGS += -DALEE_MSP430_HOST +msp430: LDFLAGS += -L msp430 -T msp430fr2476.ld -Wl,-gc-sections -Wl,--no-warn-rwx-segments msp430: msp430/alee-msp430 +msp430-prep: CXXFLAGS += -DALEE_MSP430 -Imsp430 +msp430-prep: msp430/msp430fr2476_all.h msp430-prep: STANDALONE += forth/core-ext.fth forth/tools.fth forth/msp430.fth msp430-prep: core.fth.h msp430-prep: clean-lib @@ -28,11 +31,12 @@ small: alee fast: CXXFLAGS += -O3 -march=native -mtune=native -flto fast: alee +standalone: core.fth.h standalone: alee-standalone alee: $(LIBFILE) msp430/alee-msp430: $(LIBFILE) -alee-standalone: core.fth.h $(LIBFILE) +alee-standalone: $(LIBFILE) cppcheck: cppcheck --enable=warning,style,information --disable=missingInclude \ @@ -46,11 +50,14 @@ $(LIBFILE): $(OBJFILES) core.fth.h: alee.dat xxd -i $< > $@ - sed -i "s/unsigned /static &/" $@ + sed -i "s/\[\]/\[ALEE_RODICTSIZE\]/" $@ alee.dat: alee $(STANDALONE) echo "3 sys" | ./alee $(STANDALONE) +msp430/msp430fr2476_all.h: + $(MAKE) -C msp430 + clean: clean-lib rm -f alee alee-standalone msp430/alee-msp430 rm -f alee.dat core.fth.h diff --git a/alee-standalone.cpp b/alee-standalone.cpp index 5681dbf..9f5eae5 100644 --- a/alee-standalone.cpp +++ b/alee-standalone.cpp @@ -16,15 +16,16 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "alee.hpp" +#include "libalee/alee.hpp" #include "splitmemdict.hpp" +#include <array> #include <charconv> #include <fstream> #include <iostream> #include <vector> -alignas(sizeof(Cell)) +#define ALEE_RODICTSIZE #include "core.fth.h" static bool okay = false; @@ -16,7 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "alee.hpp" +#include "libalee/alee.hpp" #include "memdict.hpp" #include <charconv> @@ -24,6 +24,13 @@ #include <iostream> #include <vector> +#ifdef ALEE_MSP430 +#include "lzss.h" +static const +#include "msp430fr2476_all.h" +static Error findword(State&, Word); +#endif // ALEE_MSP430 + static bool okay = false; static void readchar(State&); @@ -34,6 +41,9 @@ int main(int argc, char *argv[]) { MemDict dict; State state (dict, readchar); +#ifdef ALEE_MSP430 + Parser::customParse = findword; +#endif // ALEE_MSP430 dict.initialize(); @@ -153,3 +163,48 @@ void parseFile(State& state, std::istream& file) } } +#ifdef ALEE_MSP430 +#define LZSS_MAGIC_SEPARATOR (0xFB) + +static char lzword[32]; +static int lzwlen; +static char lzbuf[32]; +static char *lzptr; + +Error findword(State& state, Word word) +{ + char *ptr = lzword; + for (auto it = word.begin(&state.dict); it != word.end(&state.dict); ++it) { + *ptr = *it; + if (islower(*ptr)) + *ptr -= 32; + ++ptr; + } + lzwlen = (int)(ptr - lzword); + + lzptr = lzbuf; + lzssinit(msp430fr2476_all_lzss, msp430fr2476_all_lzss_len); + + auto ret = decode([](int c) { + if (c != LZSS_MAGIC_SEPARATOR) { + *lzptr++ = (char)c; + } else { + if (lzwlen == lzptr - lzbuf - 2 && std::equal(lzbuf, lzptr - 2, lzword)) { + lzwlen = (*(lzptr - 2) << 8) | *(lzptr - 1); + return 1; + } else { + lzptr = lzbuf; + } + } + return 0; + }); + + if (ret == EOF) { + return Error::noword; + } else { + Parser::processLiteral(state, (Cell)lzwlen); + return Error::none; + } +} +#endif // ALEE_MSP430 + diff --git a/alee.hpp b/alee.hpp deleted file mode 100644 index e4ed7de..0000000 --- a/alee.hpp +++ /dev/null @@ -1,6 +0,0 @@ -/// @file alee.hpp -/// @brief Single header to include all of Alee Forth - -#include "libalee/parser.hpp" -#include "libalee/state.hpp" - diff --git a/forth/core-ext.fth b/forth/core-ext.fth index 8bc83be..f9178e8 100644 --- a/forth/core-ext.fth +++ b/forth/core-ext.fth @@ -67,7 +67,7 @@ drop - spaces u. ; ( WORD uses HERE and must be at least 33 characters. ) -: pad here 50 chars + align ; +: pad here [ 50 chars ] literal + align ; : parse here dup >r swap begin key? if key else dup then 2dup <> while diff --git a/forth/core.fth b/forth/core.fth index 8ec5b71..d198583 100644 --- a/forth/core.fth +++ b/forth/core.fth @@ -6,6 +6,8 @@ : cell+ 2 + ; : cells 2 * ; +: char+ 1 + ; +: chars ; : . 0 sys ; : emit 2 sys ; @@ -13,39 +15,41 @@ : 1+ 1 + ; : 1- 1 - ; +: over 1 pick ; +: rot >r swap r> swap ; +: -rot rot rot ; + : ' _' drop ; : ! 1 _! ; : @ 1 _@ ; : +! dup >r swap r> @ + swap ! ; -: base 0 ; -: here 1 cells @ ; -: allot 1 cells +! ; - -: c! 0 _! ; -: c@ 0 _@ ; -: c, here c! 1 allot ; -: char+ 1+ ; -: chars ; - : _latest 2 cells ; : imm _latest @ dup @ 1 5 << | swap ! ; : immediate imm ; -: state 3 cells ; -: _compxt 4 cells ; -: _source 5 cells ; -: _sourceu 6 cells ; -: >in 7 cells ; -: _begin 8 cells 80 chars + ; -: , here ! 1 cells allot ; +: [ 0 3 cells ! ; imm +: ] 1 3 cells ! ; -: [ 0 state ! ; imm -: ] 1 state ! ; +: , 1 cells dup >r @ ! r> dup +! ; : literal [ ' _lit dup , , ] , , ; imm : ['] ' [ ' literal , ] ; imm +: base 0 ; +: here [ 1 cells ] literal @ ; +: allot [ 1 cells ] literal +! ; +: state [ 3 cells ] literal ; +: _compxt [ 4 cells ] literal ; +: _source [ 5 cells ] literal ; +: _sourceu [ 6 cells ] literal ; +: >in [ 7 cells ] literal ; +: _begin [ 8 cells 80 chars + ] literal ; + +: c! 0 _! ; +: c@ 0 _@ ; +: c, here c! 1 allot ; + : if ['] _jmp0 , here 0 , ; imm : then here swap ! ; imm : else ['] _jmp , here 0 , swap here swap ! ; imm @@ -54,10 +58,6 @@ 1 = swap ['] _lit , , if ['] execute , else ['] , , then ; imm -: over 1 pick ; -: rot >r swap r> swap ; -: -rot rot rot ; - : 2drop drop drop ; : 2dup over over ; : 2over 3 pick 3 pick ; @@ -99,7 +99,8 @@ : j postpone 2r> ['] r> , postpone r@ ['] swap , ['] >r , ['] -rot , postpone 2>r ; imm -: aligned dup 1 cells 1- swap over & if 1 cells swap - + else drop then ; +: aligned dup [ 1 cells 1- ] literal swap over & if [ 1 cells ] literal + swap - + else drop then ; : align here dup aligned swap - allot ; : and & ; @@ -110,7 +111,7 @@ : invert -1 ^ ; : mod % ; : 2* 2 * ; -: _msb 1 1 cells 8 * 1- << ; +: _msb [ 1 1 cells 8 * 1- << ] literal ; : 2/ dup 1 >> swap 0< if _msb or then ; : /mod 2dup % -rot / ; @@ -145,12 +146,14 @@ 2dup <> while rot repeat 2drop here - here c! here ; : count dup char+ swap c@ ; -: char bl word char+ c@ ; +: char 0 here char+ c! bl word char+ c@ ; : [char] char postpone literal ; imm : ( begin [char] ) key <> while repeat ; imm -: type begin dup 0 > while swap dup c@ emit char+ swap 1- repeat 2drop ; +: _type >r begin dup 0 > while + swap dup c@ r@ execute char+ swap 1- repeat 2drop r> drop ; +: type [ ' emit ] literal _type ; : s" state @ if ['] _jmp , here 0 , then [char] " word count state @ 0= if exit then @@ -161,17 +164,17 @@ : :noname here dup _compxt ! 0 , here swap ] ; -: create : here 4 cells + postpone literal postpone ; 0 , ; +: create : here [ 4 cells ] literal + postpone literal postpone ; 0 , ; : >body cell+ @ ; -: _does> >r _latest @ dup @ 31 & + cell+ aligned 2 cells + +: _does> >r _latest @ dup @ 31 & + cell+ aligned [ 2 cells ] literal + ['] _jmp over ! cell+ r> cell+ swap ! ; : does> state @ if ['] _lit , here 2 cells + , ['] _does> , ['] exit , else here dup _does> dup _compxt ! 0 , ] then ; imm -: variable create 1 cells allot ; +: variable create [ 1 cells ] literal allot ; : constant create , does> @ ; : quit begin _rdepth 1 > while r> drop repeat postpone [ ; @@ -197,7 +200,7 @@ : accept over >r begin dup 0 > while key dup 32 < if 2drop 0 else dup emit rot 2dup c! char+ swap drop swap 1- then - repeat drop r> - 1 chars / ; + repeat drop r> - [ 1 chars ] literal / ; : evaluate _source @ >r _sourceu @ >r >in @ >r 0 >in ! _sourceu ! _source ! _ev diff --git a/forth/msp430.fth b/forth/msp430.fth index 1b3ab40..9c5fd30 100644 --- a/forth/msp430.fth +++ b/forth/msp430.fth @@ -1,18 +1,97 @@ -: vector! 10 sys ; -: reg! 11 sys ; -: reg@ 12 sys ; -: 2reg! 13 sys ; -: 2reg@ 14 sys ; -: sr+ 15 sys ; -: sr- 16 sys ; +: vector! 10 sys ; +: byte! 11 sys ; +: byte@ 12 sys ; +: reg! 13 sys ; +: reg@ 14 sys ; +: sr+ 15 sys ; +: sr- 16 sys ; +: lpm-exit 17 sys ; : reg [ ' reg@ ' reg! ] literal literal ; -: 2reg [ ' 2reg@ ' 2reg! ] literal literal ; +: byte [ ' byte@ ' byte! ] literal literal ; -: set ( b r reg/wreg -- ) +: set ( b r reg/byte -- ) >r over r> execute >r rot r> | -rot execute ; -: clear ( b r reg/wreg -- ) +: clear ( b r reg/byte -- ) >r over r> execute >r rot invert r> & -rot execute ; -: toggle ( b r reg/wreg -- ) +: toggle ( b r reg/byte -- ) >r over r> execute >r rot r> ^ -rot execute ; +create _outs p1out , p2out , p3out , p4out , p5out , p6out , +create _ins p1in , p2in , p3in , p4in , p5in , p6in , +create _dirs p1dir , p2dir , p3dir , p4dir , p5dir , p6dir , + +1 constant output +0 constant input + +: pin-mode ( output? pin port -- ) + rot >r cells _dirs + @ byte r> if set else clear then ; + +: pin-set ( high? pin port -- ) + rot >r cells _outs + @ byte r> if set else clear then ; + +: pin-get ( pin port -- high? ) + cells _ins + @ byte@ swap and 0 > ; + +: analog-init + adcon adcsht_2 or adcctl0 reg set + adcshp adcctl1 reg set + adcres adcctl2 reg clear + adcres_2 adcctl2 reg set + adcie0 adcie reg set ; + +: rtc-init + rtcps__10 rtcctl reg! ; + +: ms ( u -- ) + rtcmod reg! + rtcss_3 rtcsr or rtcctl reg set + begin rtciv reg@ 0<> until + rtc-init ; + +: D0 bit5 1 ; +: D1 bit6 1 ; +: D2 bit1 2 ; +: D3 bit4 1 ; +: D4 bit7 2 ; +: D5 bit0 3 ; +: D6 bit1 3 ; +: D7 bit7 3 ; +: D8 bit6 3 ; +: D9 bit5 3 ; +: D10 bit4 4 ; +: D11 bit2 2 ; +: D12 bit6 2 ; +: D13 bit5 2 ; + +: A0 bit0 0 ; +: A1 bit1 0 ; +: A2 bit5 0 ; +: A3 bit6 0 ; +: A4 bit2 0 ; +: A5 bit3 0 ; +: AREF bit4 0 ; + +: pin-analog + drop + dup p1sel0 reg set + p1sel1 reg set ; + +: analog-get + drop 0 begin + swap 2/ dup 0<> while + swap 1+ repeat + drop adcmctl0 reg! + adcenc adcsc or adcctl0 reg set + adcmem0 reg@ ; + +: LED1R bit1 5 ; +: LED1G bit0 5 ; +: LED1B bit2 5 ; + +: LED2R bit6 4 ; +: LED2G bit5 4 ; +: LED2B bit7 4 ; + +: SW2 bit3 1 ; +: SW3 bit4 2 ; diff --git a/libalee/alee.hpp b/libalee/alee.hpp new file mode 100644 index 0000000..7b46845 --- /dev/null +++ b/libalee/alee.hpp @@ -0,0 +1,7 @@ +#include "config.hpp" +#include "corewords.hpp" +#include "ctype.hpp" +#include "dictionary.hpp" +#include "parser.hpp" +#include "state.hpp" +#include "types.hpp" diff --git a/libalee/config.hpp b/libalee/config.hpp new file mode 100644 index 0000000..20d0950 --- /dev/null +++ b/libalee/config.hpp @@ -0,0 +1,5 @@ +#ifndef ALEE_MSP430_HOST +#define LIBALEE_SECTION +#else +#define LIBALEE_SECTION __attribute__((section(".libalee"))) +#endif diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp index 661590f..7c79aea 100644 --- a/libalee/corewords.cpp +++ b/libalee/corewords.cpp @@ -16,8 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "corewords.hpp" -#include "parser.hpp" +#include "alee.hpp" #include <utility> @@ -25,6 +24,7 @@ static void find(State&, Word); static DoubleCell popd(State&); static void pushd(State&, DoubleCell); +LIBALEE_SECTION void CoreWords::run(Cell ins, State& state) { Cell cell; @@ -230,11 +230,13 @@ execute: ip += sizeof(Cell); } +LIBALEE_SECTION Cell CoreWords::findi(State& state, Word word) { return findi(word.begin(&state.dict), word.size()); } +LIBALEE_SECTION void find(State& state, Word word) { Cell tok = 0; diff --git a/libalee/corewords.hpp b/libalee/corewords.hpp index 630f3cf..30d0a42 100644 --- a/libalee/corewords.hpp +++ b/libalee/corewords.hpp @@ -21,11 +21,13 @@ #ifndef ALEEFORTH_COREWORDS_HPP #define ALEEFORTH_COREWORDS_HPP +#include "config.hpp" +#include "dictionary.hpp" #include "types.hpp" -#include "state.hpp" #include <algorithm> -#include <cstring> + +class State; /** * To be implemented by the user, this function is called when the `sys` word @@ -57,7 +59,7 @@ public: * @return The token/index of the word or -1 if not found. */ consteval static Cell token(const char *word) { - return findi(word, std::strlen(word)); + return findi(word, strlen(word)); } /** @@ -95,12 +97,13 @@ private: * @return The token/index of the word or -1 if not found. */ template<typename Iter> + LIBALEE_SECTION constexpr static Cell findi(Iter it, std::size_t size) { const char *ptr = CoreWords::wordsarr; for (Cell wordsi = 0; wordsi < WordCount; ++wordsi) { - std::size_t wordsize = std::strlen(ptr); + std::size_t wordsize = strlen(ptr); if (wordsize == size && Dictionary::equal(ptr, ptr + wordsize, it)) return wordsi; diff --git a/libalee/ctype.hpp b/libalee/ctype.hpp index 5252eda..f7ce3fb 100644 --- a/libalee/ctype.hpp +++ b/libalee/ctype.hpp @@ -23,6 +23,13 @@ #include <cstdint> +/** Determines the length of a null-terminated string. */ +constexpr inline unsigned strlen(const char * const s) { + unsigned i = 0; + while (s[i]) i++; + return i; +} + /** Tests if given character represents whitespace. */ constexpr inline bool isspace(uint8_t c) { return c == ' ' || c == '\t' || c == '\r' || c == '\n'; @@ -38,6 +45,11 @@ constexpr inline bool isupper(uint8_t c) { return c >= 'A' && c <= 'Z'; } +/** Tests if given character is a lowercase letter. */ +constexpr inline bool islower(uint8_t c) { + return c >= 'a' && c <= 'z'; +} + /** Tests if given character is a letter. */ constexpr inline bool isalpha(uint8_t c) { return isupper(c) || (c >= 'a' && c <= 'z'); diff --git a/libalee/dictionary.cpp b/libalee/dictionary.cpp index f2ad231..b1cbc5f 100644 --- a/libalee/dictionary.cpp +++ b/libalee/dictionary.cpp @@ -16,10 +16,9 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "dictionary.hpp" - -#include <cstring> +#include "alee.hpp" +LIBALEE_SECTION void Dictionary::initialize() { write(Base, 10); @@ -29,6 +28,7 @@ void Dictionary::initialize() write(Source, Input + sizeof(Cell)); } +LIBALEE_SECTION Addr Dictionary::allot(Cell amount) noexcept { Addr old = here(); @@ -43,22 +43,26 @@ Addr Dictionary::allot(Cell amount) noexcept return old; } +LIBALEE_SECTION void Dictionary::add(Cell value) noexcept { write(allot(sizeof(Cell)), value); } +LIBALEE_SECTION Addr Dictionary::aligned(Addr addr) { return (addr + (sizeof(Cell) - 1)) & ~(sizeof(Cell) - 1); } +LIBALEE_SECTION Addr Dictionary::alignhere() noexcept { here(aligned(here())); return here(); } +LIBALEE_SECTION void Dictionary::addDefinition(Word word) noexcept { Cell wsize = word.size(); @@ -77,6 +81,7 @@ void Dictionary::addDefinition(Word word) noexcept alignhere(); } +LIBALEE_SECTION Addr Dictionary::find(Word word) noexcept { Addr lt = latest(); @@ -108,6 +113,7 @@ Addr Dictionary::find(Word word) noexcept return 0; } +LIBALEE_SECTION Addr Dictionary::getexec(Addr addr) noexcept { const Addr l = read(addr); @@ -121,6 +127,7 @@ Addr Dictionary::getexec(Addr addr) noexcept return aligned(addr); } +LIBALEE_SECTION bool Dictionary::hasInput() const noexcept { const Addr src = read(Dictionary::Source); @@ -142,6 +149,7 @@ bool Dictionary::hasInput() const noexcept return false; } +LIBALEE_SECTION Word Dictionary::input() noexcept { const Addr src = read(Dictionary::Source); @@ -171,11 +179,13 @@ Word Dictionary::input() noexcept return Word(wstart, wend); } +LIBALEE_SECTION bool Dictionary::equal(Word word, const char *str, unsigned len) const noexcept { return word.size() == len && equal(word.begin(this), word.end(this), str); } +LIBALEE_SECTION bool Dictionary::equal(Word word, Word other) const noexcept { return word.size() == other.size() && equal(word.begin(this), word.end(this), other.begin(this)); diff --git a/libalee/dictionary.hpp b/libalee/dictionary.hpp index f6f6bbe..ad1ee02 100644 --- a/libalee/dictionary.hpp +++ b/libalee/dictionary.hpp @@ -21,8 +21,9 @@ #ifndef ALEEFORTH_DICTIONARY_HPP #define ALEEFORTH_DICTIONARY_HPP -#include "ctype.hpp" +#include "config.hpp" #include "types.hpp" +#include "ctype.hpp" #include <algorithm> #include <cstddef> @@ -99,21 +100,25 @@ public: /** * Gets the address stored in `here`. */ + LIBALEE_SECTION Addr here() const noexcept { return read(Here); } /** * Sets the address stored in `here`. */ + LIBALEE_SECTION void here(Addr l) noexcept { write(Here, l); } /** * Gets the value of `latest`. */ + LIBALEE_SECTION Addr latest() const noexcept { return read(Latest); } /** * Sets the value of `latest`. */ + LIBALEE_SECTION void latest(Addr l) noexcept { write(Latest, l); } /** @@ -199,17 +204,19 @@ public: * Arguments and return value identical to std::equal. */ template<typename Iter1, typename Iter2> + LIBALEE_SECTION constexpr static bool equal(Iter1 b1, Iter1 e1, Iter2 b2) { return std::equal(b1, e1, b2, eqchars); } - virtual ~Dictionary() = default; + virtual ~Dictionary() {}; private: /** * Case-insensitive character comparison used for dictionary lookup. * @return True if the characters are equivalent. */ + LIBALEE_SECTION constexpr static bool eqchars(char c1, char c2) { if (isalpha(static_cast<uint8_t>(c1))) c1 |= 32; @@ -218,7 +225,6 @@ private: return c1 == c2; } - }; #endif // ALEEFORTH_DICTIONARY_HPP diff --git a/libalee/parser.cpp b/libalee/parser.cpp index 3699d5f..11aba38 100644 --- a/libalee/parser.cpp +++ b/libalee/parser.cpp @@ -16,21 +16,17 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "corewords.hpp" -#include "ctype.hpp" -#include "parser.hpp" - -#include <algorithm> -#include <cstring> +#include "alee.hpp" Error (*Parser::customParse)(State&, Word) = nullptr; +LIBALEE_SECTION Error Parser::parse(State& state, const char *str) { auto addr = Dictionary::Input; // Set source and input length - const auto len = static_cast<Cell>(std::strlen(str)); + const auto len = static_cast<Cell>(strlen(str)); state.dict.write(addr, 0); state.dict.write(Dictionary::SourceLen, len); @@ -46,6 +42,7 @@ Error Parser::parse(State& state, const char *str) return parseSource(state); } +LIBALEE_SECTION Error Parser::parseSource(State& state) { auto err = Error::none; @@ -56,6 +53,7 @@ Error Parser::parseSource(State& state) return err; } +LIBALEE_SECTION Error Parser::parseWord(State& state, Word word) { bool imm; @@ -89,6 +87,7 @@ Error Parser::parseWord(State& state, Word word) return Error::none; } +LIBALEE_SECTION Error Parser::parseNumber(State& state, Word word) { const auto base = state.dict.read(Dictionary::Base); @@ -100,7 +99,7 @@ Error Parser::parseNumber(State& state, Word word) ++it; const auto end = word.end(&state.dict); - for (char c; it != end; ++it) { + for (uint8_t c; it != end; ++it) { c = *it; if (isdigit(c)) { @@ -121,6 +120,7 @@ Error Parser::parseNumber(State& state, Word word) return Error::none; } +LIBALEE_SECTION void Parser::processLiteral(State& state, Cell value) { if (state.compiling()) { diff --git a/libalee/parser.hpp b/libalee/parser.hpp index 06ba8fc..7eca656 100644 --- a/libalee/parser.hpp +++ b/libalee/parser.hpp @@ -21,7 +21,9 @@ #ifndef ALEEFORTH_PARSER_HPP #define ALEEFORTH_PARSER_HPP +#include "config.hpp" #include "types.hpp" +#include "state.hpp" #include <string_view> diff --git a/libalee/state.cpp b/libalee/state.cpp index 6e12999..ed1562f 100644 --- a/libalee/state.cpp +++ b/libalee/state.cpp @@ -16,32 +16,35 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "corewords.hpp" -#include "state.hpp" +#include "alee.hpp" -#include <cstring> #include <iterator> +LIBALEE_SECTION bool State::compiling() const { return dict.read(Dictionary::Compiling); } +LIBALEE_SECTION void State::compiling(bool yes) { dict.write(Dictionary::Compiling, yes); } +LIBALEE_SECTION State::Context State::save() { return context; } +LIBALEE_SECTION void State::load(const State::Context& ctx) { context = ctx; } +LIBALEE_SECTION Error State::execute(Addr addr) { auto stat = static_cast<Error>(setjmp(context.jmpbuf)); @@ -64,6 +67,7 @@ Error State::execute(Addr addr) return stat; } +LIBALEE_SECTION void State::reset() { while (size()) @@ -75,11 +79,13 @@ void State::reset() context.ip = 0; } +LIBALEE_SECTION std::size_t State::size() const noexcept { return dsp - dstack; } +LIBALEE_SECTION std::size_t State::rsize() const noexcept { return rsp - rstack; diff --git a/libalee/state.hpp b/libalee/state.hpp index 60ff95f..a5e49b5 100644 --- a/libalee/state.hpp +++ b/libalee/state.hpp @@ -21,6 +21,7 @@ #ifndef ALEEFORTH_STATE_HPP #define ALEEFORTH_STATE_HPP +#include "config.hpp" #include "dictionary.hpp" #include "types.hpp" @@ -82,11 +83,13 @@ public: void reset(); /** Returns a reference to the instruction pointer. */ + LIBALEE_SECTION Addr& ip() noexcept { return context.ip; } /** Calls the user input function with this state as the argument. */ + LIBALEE_SECTION void input() noexcept { inputfunc(*this); } @@ -114,6 +117,7 @@ public: /** * Pushes the given value to the data stack. */ + LIBALEE_SECTION inline void push(Cell value) { verify(dsp < dstack + DataStackSize, Error::push); *dsp++ = value; @@ -122,6 +126,7 @@ public: /** * Pops a value from the data stack and returns that value. */ + LIBALEE_SECTION inline Cell pop() { verify(dsp > dstack, Error::pop); return *--dsp; @@ -130,6 +135,7 @@ public: /** * Pushes the given value to the return stack. */ + LIBALEE_SECTION inline void pushr(Cell value) { verify(rsp < rstack + ReturnStackSize, Error::pushr); *rsp++ = value; @@ -138,6 +144,7 @@ public: /** * Pops a value from the return stack and returns that value. */ + LIBALEE_SECTION inline Cell popr() { verify(rsp > rstack, Error::popr); return *--rsp; @@ -146,6 +153,7 @@ public: /** * Returns the value stored at the current data stack position. */ + LIBALEE_SECTION inline Cell& top() { verify(dsp > dstack, Error::top); return *(dsp - 1); @@ -156,6 +164,7 @@ public: * @param i Index from current position to fetch from * @return The value stored at the given index */ + LIBALEE_SECTION inline Cell& pick(std::size_t i) { verify(dsp - i > dstack, Error::pick); return *(dsp - i - 1); @@ -164,6 +173,7 @@ public: /** * Advances the instruction pointer and returns that cell's contents. */ + LIBALEE_SECTION inline Cell beyondip() { context.ip += sizeof(Cell); return dict.read(context.ip); @@ -175,6 +185,7 @@ public: * @param condition Condition to be tested * @param error Error code to report via longjmp() on false condition */ + LIBALEE_SECTION inline void verify(bool condition, Error error) { if (!condition) std::longjmp(context.jmpbuf, static_cast<int>(error)); diff --git a/libalee/types.cpp b/libalee/types.cpp index bfff2ae..7ac67c7 100644 --- a/libalee/types.cpp +++ b/libalee/types.cpp @@ -16,30 +16,34 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "dictionary.hpp" -#include "types.hpp" +#include "alee.hpp" +LIBALEE_SECTION Addr Word::size() const noexcept { return wend - start; } +LIBALEE_SECTION Word::iterator Word::begin(const Dictionary *dict) { return iterator(start, dict); } +LIBALEE_SECTION Word::iterator Word::end(const Dictionary *dict) { return iterator(wend, dict); } +LIBALEE_SECTION Word::iterator& Word::iterator::operator++() { addr++; return *this; } +LIBALEE_SECTION Word::iterator Word::iterator::operator++(int) { const auto copy = *this; @@ -47,11 +51,13 @@ Word::iterator Word::iterator::operator++(int) return copy; } +LIBALEE_SECTION Word::iterator::value_type Word::iterator::operator*() { return dict->readbyte(addr); } +LIBALEE_SECTION bool Word::iterator::operator!=(const iterator& other) { return dict != other.dict || addr != other.addr; diff --git a/libalee/types.hpp b/libalee/types.hpp index a122c84..7b5bb62 100644 --- a/libalee/types.hpp +++ b/libalee/types.hpp @@ -79,6 +79,7 @@ public: * @param l Count of bytes until end of word * @return Resulting Word object */ + LIBALEE_SECTION static constexpr Word fromLength(Addr s, Addr l) { return Word(s, s + l); } diff --git a/memdict.hpp b/memdict.hpp index b1dbe55..9861921 100644 --- a/memdict.hpp +++ b/memdict.hpp @@ -21,7 +21,7 @@ #ifndef ALEEFORTH_MEMDICT_HPP #define ALEEFORTH_MEMDICT_HPP -#include "alee.hpp" +#include "libalee/alee.hpp" #ifndef MEMDICTSIZE /** Default dictionary size in bytes. */ diff --git a/msp430/Makefile b/msp430/Makefile deleted file mode 100644 index 8b91764..0000000 --- a/msp430/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -dict: lzss - cat msp430fr2476_symbols.ld | grep "^PROVIDE.*" | sed -e "s/^PROVIDE(//" -e "s/[ ][ ]*//" -e "s/=.0x/\\\\x/" -e "s/..);/\\\\x&/" -e "s/);//" > msp430fr2476_symbols.dat - grep -E "^#define \w+\s+\([0-9].*$$" msp430fr2476.h | sed -e "s/).*$$/)/" -e "s/^#define //" -e "s/[ ][ ]*//" -e "s/(0x/\\\\x/" -e "s/..)/\\\\x&/" -e "s/)//" -e "s/(/\\\\x/" -e "s/\\\\x\\\\/\\\\x00\\\\/" > msp430fr2476.dat - cat msp430fr2476_symbols.dat msp430fr2476.dat | tr '\n' '\373' | tr -d '\r' > msp430fr2476_all.dat - @echo "printf ... > msp430fr2476_all.bin" - @printf "$(shell cat msp430fr2476_all.dat)" > msp430fr2476_all.bin - ./lzss e msp430fr2476_all.bin msp430fr2476_all.lzss - ls -l msp430fr2476_all.lzss - xxd -i msp430fr2476_all.lzss > msp430fr2476_all.h - -lzss: lzss.c - diff --git a/msp430/alee-msp430.cpp b/msp430/alee-msp430.cpp index b983900..51f63f8 100644 --- a/msp430/alee-msp430.cpp +++ b/msp430/alee-msp430.cpp @@ -16,50 +16,63 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "alee.hpp" -#include "libalee/ctype.hpp" +#include "libalee/alee.hpp" #include "lzss.h" static const #include "msp430fr2476_all.h" -#include <cstring> #include <msp430.h> #include "splitmemdictrw.hpp" -alignas(sizeof(Cell)) -__attribute__((section(".lodict"))) -#include "core.fth.h" - static char strbuf[80]; static void readchar(State& state); static void serput(int c); static void serputs(const char *s); -static void printint(DoubleCell n, char *buf); +static void printint(DoubleCell n, char *buf, int base); + static Error findword(State&, Word); static void initGPIO(); static void initClock(); static void initUART(); static void Software_Trim(); -#define MCLK_FREQ_MHZ (8) // MCLK = 8MHz +#define MCLK_FREQ_MHZ (16) + +static void alee_main(); -//__attribute__((section(".hidict"))) -//static uint8_t hidict[16384]; +#define ALEE_RODICTSIZE (9088) +__attribute__((section(".lodict"))) +#include "core.fth.h" -static bool inISR = false; +static bool exitLpm; static Addr isr_list[24] = {}; -static SplitMemDictRW<sizeof(alee_dat), 16384> dict (alee_dat, 0x10000); + +using DictType = SplitMemDictRW<ALEE_RODICTSIZE, 32767>; +extern char __dict[sizeof(DictType)]; +static auto& dict = *(new (__dict) DictType (alee_dat, 0x10000)); int main() { WDTCTL = WDTPW | WDTHOLD; + + extern char __libaleebegin; + extern char __libaleeend; + extern char __libaleedst; + std::copy(&__libaleebegin, &__libaleeend, &__libaleedst); + initGPIO(); initClock(); initUART(); SYSCFG0 = FRWPPW; + alee_main(); +} + +LIBALEE_SECTION +void alee_main() +{ (void)alee_dat_len; State state (dict, readchar); Parser::customParse = findword; @@ -105,6 +118,7 @@ int main() } } +LIBALEE_SECTION void readchar(State& state) { auto idx = state.dict.read(Dictionary::Input); @@ -117,20 +131,25 @@ void readchar(State& state) state.dict.writebyte(addr, c ? c : ' '); } +LIBALEE_SECTION void serput(int c) { while (!(UCA0IFG & UCTXIFG)); UCA0TXBUF = static_cast<char>(c); } +LIBALEE_SECTION void serputs(const char *s) { while (*s) serput(*s++); } -void printint(DoubleCell n, char *buf) +LIBALEE_SECTION +void printint(DoubleCell n, char *buf, int base) { + static const char digit[] = "0123456789ABCDEF"; + char *ptr = buf; bool neg = n < 0; @@ -138,8 +157,8 @@ void printint(DoubleCell n, char *buf) n = -n; do { - *ptr++ = static_cast<char>((n % 10) + '0'); - } while ((n /= 10)); + *ptr++ = digit[n % base]; + } while ((n /= base)); if (neg) serput('-'); @@ -150,11 +169,12 @@ void printint(DoubleCell n, char *buf) serput(' '); } +LIBALEE_SECTION void user_sys(State& state) { switch (state.pop()) { case 0: // . - printint(state.pop(), strbuf); + printint(state.pop(), strbuf, state.dict.read(Dictionary::Base)); break; case 1: // unused state.push(static_cast<Addr>(state.dict.capacity() - state.dict.here())); @@ -181,16 +201,18 @@ void user_sys(State& state) state.push(*reinterpret_cast<uint16_t *>(state.pop())); break; case 15: - if (!inISR) - _bis_SR_register(state.pop()); - else - _bis_SR_register_on_exit(state.pop()); + _bis_SR_register(state.pop()); break; case 16: - if (!inISR) - _bic_SR_register(state.pop()); - else - _bic_SR_register_on_exit(state.pop()); + _bic_SR_register(state.pop()); + break; + case 17: + exitLpm |= true; + break; + case 50: + Parser::customParse = nullptr; + extern char _etext; + state.push((Addr)&_etext); break; default: break; @@ -199,14 +221,14 @@ void user_sys(State& state) #define LZSS_MAGIC_SEPARATOR (0xFB) -static char lzword[32]; +static uint8_t lzword[32]; static int lzwlen; -static char lzbuf[32]; -static char *lzptr; +static uint8_t lzbuf[32]; +static uint8_t *lzptr; Error findword(State& state, Word word) { - char *ptr = lzword; + uint8_t *ptr = lzword; for (auto it = word.begin(&state.dict); it != word.end(&state.dict); ++it) { *ptr = *it; if (islower(*ptr)) @@ -220,9 +242,9 @@ Error findword(State& state, Word word) auto ret = decode([](int c) { if (c != LZSS_MAGIC_SEPARATOR) { - *lzptr++ = (char)c; + *lzptr++ = (uint8_t)c; } else { - if (lzwlen == lzptr - lzbuf - 2 && strncmp(lzword, lzbuf, lzptr - lzbuf - 2) == 0) { + if (lzwlen == lzptr - lzbuf - 2 && std::equal(lzbuf, lzptr - 2, lzword)) { lzwlen = (*(lzptr - 2) << 8) | *(lzptr - 1); return 1; } else { @@ -267,35 +289,47 @@ void initGPIO() void initClock() { - __bis_SR_register(SCG0); // disable FLL - CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source - CSCTL1 = DCOFTRIMEN_1 | DCOFTRIM0 | DCOFTRIM1 | DCORSEL_3;// DCOFTRIM=3, DCO Range = 8MHz - CSCTL2 = FLLD_0 + 243; // DCODIV = 8MHz + static_assert(MCLK_FREQ_MHZ == 16); + + // Configure one FRAM waitstate as required by the device datasheet for MCLK + // operation beyond 8MHz _before_ configuring the clock system. + FRCTL0 = FRCTLPW | NWAITS_1; + + P2SEL0 |= BIT0 | BIT1; // P2.0~P2.1: crystal pins + do + { + CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag + SFRIFG1 &= ~OFIFG; + } while (SFRIFG1 & OFIFG); // Test oscillator fault flag + + __bis_SR_register(SCG0); // disable FLL + CSCTL3 |= SELREF__XT1CLK; // Set XT1 as FLL reference source + CSCTL1 = DCOFTRIMEN_1 | DCOFTRIM0 | DCOFTRIM1 | DCORSEL_5;// DCOFTRIM=5, DCO Range = 16MHz + CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz __delay_cycles(3); - __bic_SR_register(SCG0); // enable FLL - Software_Trim(); // Software Trim to get the best DCOFTRIM value + __bic_SR_register(SCG0); // enable FLL + Software_Trim(); // Software Trim to get the best DCOFTRIM value + + CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // set XT1 (~32768Hz) as ACLK source, ACLK = 32768Hz + // default DCOCLKDIV as MCLK and SMCLK source - CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz - // default DCODIV as MCLK and SMCLK source } void initUART() { // Configure UART pins - P5SEL0 |= BIT1 | BIT2; // set 2-UART pin as second function - SYSCFG3|=USCIA0RMP; //Set the remapping source - // Configure UART + P5SEL0 |= BIT1 | BIT2; + SYSCFG3 |= USCIA0RMP; // Set the remapping source + UCA0CTLW0 |= UCSWRST; - UCA0CTLW0 |= UCSSEL__SMCLK; + UCA0CTLW0 |= UCSSEL__SMCLK; // 16 MHz // Baud Rate calculation - // 8000000/(16*9600) = 52.083 - // Fractional portion = 0.083 - // User's Guide Table 17-4: UCBRSx = 0x49 - // UCBRFx = int ( (52.083-52)*16) = 1 - UCA0BR0 = 52; // 8000000/16/9600 - UCA0BR1 = 0x00; - UCA0MCTLW = 0x4900 | UCOS16 | UCBRF_1; + // N = 16MHz / 115200 = 138.888 + // OS16 = 1, UCBRx = INT(N/16) = 8(.6806) + // UCBRFx = INT( ((N/16) - UCBRx) * 16) = 10(.8896) + UCA0BRW = 8; + UCA0MCTLW = 0xD600 | 0x00A0 | UCOS16; UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI } @@ -369,21 +403,25 @@ void Software_Trim() while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked } -void alee_isr_handle(unsigned index) +bool alee_isr_handle(unsigned index) { const Addr isr = isr_list[index]; if (isr != 0) { State isrstate (dict, readchar); - inISR = true; + exitLpm = false; isrstate.execute(isr); - inISR = false; + return exitLpm; } + + return false; } #define DEFINE_ISR(VVV, III) \ __attribute__((interrupt(VVV))) \ - void VVV##_ISR() { alee_isr_handle(III); } + void VVV##_ISR() { \ + if (alee_isr_handle(III)) \ + _low_power_mode_off_on_exit(); } DEFINE_ISR(ECOMP0_VECTOR, 0) DEFINE_ISR(PORT6_VECTOR, 1) @@ -410,3 +448,6 @@ DEFINE_ISR(TIMER1_A0_VECTOR, 21) DEFINE_ISR(TIMER0_A1_VECTOR, 22) DEFINE_ISR(TIMER0_A0_VECTOR, 23) +// Override newlib's free to save hundreds of bytes +extern "C" void free(void *) {} + diff --git a/msp430/build.sh b/msp430/build.sh new file mode 100755 index 0000000..3d296d3 --- /dev/null +++ b/msp430/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash -x + +cat msp430fr2476_symbols.ld | grep "^PROVIDE.*" | sed -e "s/^PROVIDE(//" -e "s/[ ][ ]*//" -e "s/=.0x/\\\\x/" -e "s/..);/\\\\x&/" -e "s/);//" > msp430fr2476_symbols.dat +grep -E "^#define \w+\s+\([0-9].*$" msp430fr2476.h | sed -e "s/).*$/)/" -e "s/^#define //" -e "s/[ ][ ]*//" -e "s/(0x/\\\\x/" -e "s/..)/\\\\x&/" -e "s/)//" -e "s/(/\\\\x/" -e "s/\\\\x\\\\/\\\\x00\\\\/" > msp430fr2476.dat +cat msp430fr2476_symbols.dat msp430fr2476.dat | tr '\n' '\373' | tr -d '\r' > msp430fr2476_all.dat +echo -e "$(cat msp430fr2476_all.dat)" > msp430fr2476_all.bin +./lzss e msp430fr2476_all.bin msp430fr2476_all.lzss +ls -l msp430fr2476_all.lzss +xxd -i msp430fr2476_all.lzss > msp430fr2476_all.h diff --git a/msp430/examples/spi.txt b/msp430/examples/spi.txt new file mode 100644 index 0000000..64a7189 --- /dev/null +++ b/msp430/examples/spi.txt @@ -0,0 +1,15 @@ +unsigned char RXData = 0; +unsigned char TXData; + +: spi-init + bit2 bit5 or bit6 or p3sel0 byte set + ucb1ctlw0 + ucswrst over reg set + ucmst ucsync or ucckpl or ucmsb or over reg set + ucssel__aclk over reg set + 2 ucb1brw reg! + ucswrst swap reg clear ; + +: spi-emit + begin ucb1ifg reg@ uctxifg and until + ucb1txbuf reg! ; diff --git a/msp430/examples/uart.txt b/msp430/examples/uart.txt new file mode 100644 index 0000000..e090e75 --- /dev/null +++ b/msp430/examples/uart.txt @@ -0,0 +1,13 @@ +\ UART example, 19200 baud, pins D0/1 + +: uart-init ( -- ) + bit5 bit6 or p2sel0 byte set + ucswrst uca1ctlw0 reg set + ucssel__smclk uca1ctlw0 reg set + 52 uca1brw reg! + 18688 ucos16 or ucbrf0 or uca1mctlw reg! + ucswrst uca1ctlw0 reg clear ; + +: uart-emit ( n -- ) + begin uca1ifg reg@ uctxifg and until + uca1txbuf byte! ; diff --git a/msp430/msp430fr2476.h b/msp430/msp430fr2476.h index 33c8ee8..fa02406 100644 --- a/msp430/msp430fr2476.h +++ b/msp430/msp430fr2476.h @@ -4232,32 +4232,32 @@ sfr_b(UCB1IV_H); * Interrupt Vectors (offset from 0xFF80 + 0x10 for Password)
************************************************************/
-#define ECOMP0_VECTOR (20) /* 0xFFCA */
-#define PORT6_VECTOR (21) /* 0xFFCC */
-#define PORT5_VECTOR (22) /* 0xFFCE */
-#define PORT4_VECTOR (23) /* 0xFFD0 */
-#define PORT3_VECTOR (24) /* 0xFFD2 */
-#define PORT2_VECTOR (25) /* 0xFFD4 */
-#define PORT1_VECTOR (26) /* 0xFFD6 */
-#define ADC_VECTOR (27) /* 0xFFD8 */
-#define EUSCI_B1_VECTOR (28) /* 0xFFDA */
-#define EUSCI_B0_VECTOR (29) /* 0xFFDC */
-#define EUSCI_A1_VECTOR (30) /* 0xFFDE */
-#define EUSCI_A0_VECTOR (31) /* 0xFFE0 */
-#define WDT_VECTOR (32) /* 0xFFE2 */
-#define RTC_VECTOR (33) /* 0xFFE4 */
-#define TIMER0_B1_VECTOR (34) /* 0xFFE6 */
-#define TIMER0_B0_VECTOR (35) /* 0xFFE8 */
-#define TIMER3_A1_VECTOR (36) /* 0xFFEA */
-#define TIMER3_A0_VECTOR (37) /* 0xFFEC */
-#define TIMER2_A1_VECTOR (38) /* 0xFFEE */
-#define TIMER2_A0_VECTOR (39) /* 0xFFF0 */
-#define TIMER1_A1_VECTOR (40) /* 0xFFF2 */
-#define TIMER1_A0_VECTOR (41) /* 0xFFF4 */
-#define TIMER0_A1_VECTOR (42) /* 0xFFF6 */
-#define TIMER0_A0_VECTOR (43) /* 0xFFF8 */
-#define UNMI_VECTOR (44) /* 0xFFFA */
-#define SYSNMI_VECTOR (45) /* 0xFFFC */
+#define ECOMP0_VECTOR (0x14) /* 0xFFCA */
+#define PORT6_VECTOR (0x15) /* 0xFFCC */
+#define PORT5_VECTOR (0x16) /* 0xFFCE */
+#define PORT4_VECTOR (0x17) /* 0xFFD0 */
+#define PORT3_VECTOR (0x18) /* 0xFFD2 */
+#define PORT2_VECTOR (0x19) /* 0xFFD4 */
+#define PORT1_VECTOR (0x1A) /* 0xFFD6 */
+#define ADC_VECTOR (0x1B) /* 0xFFD8 */
+#define EUSCI_B1_VECTOR (0x1C) /* 0xFFDA */
+#define EUSCI_B0_VECTOR (0x1D) /* 0xFFDC */
+#define EUSCI_A1_VECTOR (0x1E) /* 0xFFDE */
+#define EUSCI_A0_VECTOR (0x1F) /* 0xFFE0 */
+#define WDT_VECTOR (0x20) /* 0xFFE2 */
+#define RTC_VECTOR (0x21) /* 0xFFE4 */
+#define TIMER0_B1_VECTOR (0x22) /* 0xFFE6 */
+#define TIMER0_B0_VECTOR (0x23) /* 0xFFE8 */
+#define TIMER3_A1_VECTOR (0x24) /* 0xFFEA */
+#define TIMER3_A0_VECTOR (0x25) /* 0xFFEC */
+#define TIMER2_A1_VECTOR (0x26) /* 0xFFEE */
+#define TIMER2_A0_VECTOR (0x27) /* 0xFFF0 */
+#define TIMER1_A1_VECTOR (0x28) /* 0xFFF2 */
+#define TIMER1_A0_VECTOR (0x29) /* 0xFFF4 */
+#define TIMER0_A1_VECTOR (0x2A) /* 0xFFF6 */
+#define TIMER0_A0_VECTOR (0x2B) /* 0xFFF8 */
+#define UNMI_VECTOR (0x2C) /* 0xFFFA */
+#define SYSNMI_VECTOR (0x2D) /* 0xFFFC */
#define RESET_VECTOR ("reset") /* 0xFFFE Reset (Highest Priority) */
diff --git a/msp430/msp430fr2476.ld b/msp430/msp430fr2476.ld index fce197c..a65f652 100644 --- a/msp430/msp430fr2476.ld +++ b/msp430/msp430fr2476.ld @@ -44,11 +44,10 @@ MEMORY { BOOTCODE : ORIGIN = 0x1C00, LENGTH = 0x0400 /* END=0x1FFF, size 1024 */
ROMLIB : ORIGIN = 0xC0000, LENGTH = 0x4000 /* END=0xC3FFF, size 16384 */
BSL1 : ORIGIN = 0xFFC00, LENGTH = 0x0400 /* END=0xFFFFF, size 1024 */
- RAM : ORIGIN = 0x2000, LENGTH = 0x2000 /* END=0x3FFF, size 8192 */
+ RAM (rwx) : ORIGIN = 0x2000, LENGTH = 0x2000 /* END=0x3FFF, size 8192 */
INFOMEM : ORIGIN = 0x1800, LENGTH = 0x0200 /* END=0x19FF, size 512 */
- FRAM (rx) : ORIGIN = 0x8000, LENGTH = 0x6600 /* END=0xAFFF, size 9216 */
- LOFRAM (rxw) : ORIGIN = 0xE600, LENGTH = 0x1980 /* END=0xFF7F, size 23424 */
- HIFRAM (rxw) : ORIGIN = 0x00010000, LENGTH = 0x00007FFF
+ FRAM (rwx) : ORIGIN = 0x8000, LENGTH = 0x7F80 /* END=0xFF7F, size 32640 */
+ HIFRAM (rxw) : ORIGIN = 0x10000, LENGTH = 0x00007FFF
JTAGSIGNATURE : ORIGIN = 0xFF80, LENGTH = 0x0004
BSLSIGNATURE : ORIGIN = 0xFF84, LENGTH = 0x0004
BSLCONFIGURATIONSIGNATURE : ORIGIN = 0xFF88, LENGTH = 0x0002
@@ -164,19 +163,11 @@ SECTIONS KEEP (*(.resetvec))
} > RESETVEC
- .lower.rodata :
- {
- . = ALIGN(2);
- *(.lower.rodata.* .lower.rodata)
- } > FRAM
-
.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
@@ -200,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
@@ -225,39 +214,27 @@ 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
+ .tinyram : {
+ PROVIDE (__dict = .);
+ } > TINYRAM
- .lower.data :
- {
+ .libalee : {
. = ALIGN(2);
- PROVIDE (__datastart = .);
- *(.lower.data.* .lower.data)
+ PROVIDE (__libaleedst = .);
+ *(.libalee)
} > RAM AT> FRAM
+ PROVIDE(__libaleebegin = LOADADDR(.libalee));
+ PROVIDE (__libaleeend = LOADADDR(.libalee) + SIZEOF(.libalee));
.data :
{
. = ALIGN(2);
-
- KEEP (*(.jcr))
- *(.data.rel.ro.local) *(.data.rel.ro*)
- *(.dynamic)
+ PROVIDE (__datastart = .);
*(.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
@@ -274,27 +251,20 @@ SECTIONS /* Note that crt0 assumes this is a multiple of two; all the
start/stop symbols are also assumed word-aligned. */
- PROVIDE(__romdatastart = LOADADDR(.lower.data));
- PROVIDE (__romdatacopysize = SIZEOF(.lower.data) + SIZEOF(.data));
-
- .lower.bss :
- {
- . = ALIGN(2);
- PROVIDE (__bssstart = .);
- *(.lower.bss.* .lower.bss)
- } > RAM
+ PROVIDE(__romdatastart = LOADADDR(.data));
+ PROVIDE (__romdatacopysize = SIZEOF(.data));
.bss :
{
. = ALIGN(2);
- *(.dynbss)
+ PROVIDE (__bssstart = .);
*(.sbss .sbss.*)
*(.bss .bss.* .gnu.linkonce.b.*)
. = ALIGN(2);
*(COMMON)
PROVIDE (__bssend = .);
} > RAM
- PROVIDE (__bsssize = SIZEOF(.lower.bss) + SIZEOF(.bss));
+ PROVIDE (__bsssize = SIZEOF(.bss));
/* This section contains data that is not initialised during load
or application reset. */
@@ -307,47 +277,12 @@ 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 = .);
*(.stack)
}
- .lower.text :
- {
- . = ALIGN(2);
- *(.lower.text.* .lower.text)
- } > FRAM
-
- .lodict :
- {
- . = ALIGN(2);
- *(.lodict)
- } > LOFRAM
-
.hidict :
{
. = ALIGN(2);
@@ -362,22 +297,21 @@ SECTIONS 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))
KEEP (*(.tm_clone_table))
+
+ . = ALIGN(2);
+ PROVIDE (_etext = .);
+ } > FRAM
+
+ .lodict :
+ {
+ . = ALIGN(1024);
+ *(.lodict)
} > FRAM
.info (NOLOAD) : {} > INFOMEM /* MSP430 INFO FLASH MEMORY SEGMENTS */
@@ -430,7 +364,7 @@ SECTIONS /* DWARF Extension. */
.debug_macro 0 : { *(.debug_macro) }
- /DISCARD/ : { *(.note.GNU-stack) }
+ /DISCARD/ : { *(.note.GNU-stack .debug_loclists) }
}
diff --git a/splitmemdict.hpp b/splitmemdict.hpp index 730d103..1093fbc 100644 --- a/splitmemdict.hpp +++ b/splitmemdict.hpp @@ -19,7 +19,7 @@ #ifndef ALEEFORTH_SPLITMEMDICT_HPP #define ALEEFORTH_SPLITMEMDICT_HPP -#include "alee.hpp" +#include "libalee/alee.hpp" #include <algorithm> diff --git a/splitmemdictrw.hpp b/splitmemdictrw.hpp index 7fcb5cd..21fd142 100644 --- a/splitmemdictrw.hpp +++ b/splitmemdictrw.hpp @@ -19,7 +19,7 @@ #ifndef ALEEFORTH_SPLITMEMDICTRW_HPP #define ALEEFORTH_SPLITMEMDICTRW_HPP -#include "alee.hpp" +#include "libalee/alee.hpp" #include <algorithm> @@ -40,7 +40,6 @@ public: return *this; } - virtual Cell read(Addr addr) const noexcept final { if (addr < LON) return *reinterpret_cast<const Cell *>(lodict + addr); @@ -72,6 +71,9 @@ public: virtual unsigned long int capacity() const noexcept final { return LON + HIN; } + +private: + virtual ~SplitMemDictRW() override {}; }; #endif // ALEEFORTH_SPLITMEMDICTRW_HPP |