]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
msp430: more dict space; prepare for hal impl
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Nov 2023 14:21:21 +0000 (09:21 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 11 Nov 2023 14:21:21 +0000 (09:21 -0500)
Makefile
alee-standalone.cpp
alee.cpp
forth/core.fth
forth/msp430.fth
msp430/alee-msp430.cpp
msp430/msp430fr2476.ld

index 442b73ca88a45a952bc026b0c7b3215981d890d5..b1237b6d8ac56e7e16167149c0eb9174c8cb702d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,9 +15,11 @@ 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: 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 +30,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 +49,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
index 5681dbfea94d7455514e6d30ade92f31baa81307..2ab9b71f68e11d5a7a14a8de68f82ef6614435b6 100644 (file)
 #include "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;
index 55cae573635c048aa6f4b9a17711a4682e0b985b..a1540172a0556ecaa55fbbdf2de95b3dd643e62d 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
 #include <iostream>
 #include <vector>
 
+#ifdef ALEE_MSP430
+#include <cstring>
+#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 +42,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 +164,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 && strncmp(lzword, lzbuf, lzptr - lzbuf - 2) == 0) {
+                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
+
index 64007c0f8a98f1554e31d1a90fc6ead6516cde6b..4ab67211af93e0c4e377e690b5523dc83eb06d62 100644 (file)
 
 : (        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
index ef8bf6032a10afe701483b080e5b22b63fb7c22a..f415b2a4d5ed74441ca51ad699986691b809eab6 100644 (file)
 : 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 ,
+create _sel0 p1sel0 , p2sel0 , p3sel0 , p4sel0 , p5sel0 , p6sel0 ,
+create _sel1 p1sel1 , p2sel1 , p3sel1 , p4sel1 , p5sel1 , p6sel1 ,
+
+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 ;
+
+: 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 ;
+
+: LED1R bit1 5 ;
+: LED1G bit0 5 ;
+: LED1B bit2 5 ;
+
+: LED2R bit6 4 ;
+: LED2G bit5 4 ;
+: LED2B bit7 4 ;
index 06960b5e824b05b47563c99b412d6fa3257943f4..48a806eed57a371fb3fd7d2a762d2dee3eaf4905 100644 (file)
@@ -27,10 +27,6 @@ static const
 
 #include "splitmemdictrw.hpp"
 
-alignas(sizeof(Cell))
-__attribute__((section(".lodict")))
-#include "core.fth.h"
-
 static char strbuf[80];
 
 static void readchar(State& state);
@@ -46,12 +42,13 @@ static void initUART();
 static void Software_Trim();
 #define MCLK_FREQ_MHZ (8)    // MCLK = 8MHz
 
-//__attribute__((section(".hidict")))
-//static uint8_t hidict[32767];
+#define ALEE_RODICTSIZE (7000)
+__attribute__((section(".lodict")))
+#include "core.fth.h"
 
 static bool exitLpm;
 static Addr isr_list[24] = {};
-static SplitMemDictRW<sizeof(alee_dat), 32767> dict (alee_dat, 0x10000);
+static SplitMemDictRW<ALEE_RODICTSIZE, 32767> dict (alee_dat, 0x10000);
 
 int main()
 {
index fce197c7772200a246e88f3f3fa05772ae829d06..9a2b089fc280bf1842e4aef938530b0b83ada918 100644 (file)
@@ -46,9 +46,8 @@ MEMORY {
   BSL1             : ORIGIN = 0xFFC00, LENGTH = 0x0400 /* END=0xFFFFF, size 1024 */\r
   RAM              : ORIGIN = 0x2000, LENGTH = 0x2000 /* END=0x3FFF, size 8192 */\r
   INFOMEM          : ORIGIN = 0x1800, LENGTH = 0x0200 /* END=0x19FF, size 512 */\r
-  FRAM (rx)        : ORIGIN = 0x8000, LENGTH = 0x6600 /* END=0xAFFF, size 9216 */\r
-  LOFRAM (rxw)     : ORIGIN = 0xE600, LENGTH = 0x1980 /* END=0xFF7F, size 23424 */\r
-  HIFRAM (rxw)     : ORIGIN = 0x00010000, LENGTH = 0x00007FFF\r
+  FRAM (rwx)       : ORIGIN = 0x8000, LENGTH = 0x7F80 /* END=0xFF7F, size 32640 */\r
+  HIFRAM (rxw)     : ORIGIN = 0x10000, LENGTH = 0x00007FFF\r
   JTAGSIGNATURE    : ORIGIN = 0xFF80, LENGTH = 0x0004\r
   BSLSIGNATURE     : ORIGIN = 0xFF84, LENGTH = 0x0004\r
   BSLCONFIGURATIONSIGNATURE : ORIGIN = 0xFF88, LENGTH = 0x0002\r
@@ -164,12 +163,6 @@ SECTIONS
     KEEP (*(.resetvec))\r
   } > RESETVEC\r
 \r
-  .lower.rodata :\r
-  {\r
-    . = ALIGN(2);\r
-    *(.lower.rodata.* .lower.rodata)\r
-  } > FRAM\r
-\r
   .rodata :\r
   {\r
     . = ALIGN(2);\r
@@ -238,16 +231,10 @@ SECTIONS
 \r
   .tinyram : {} > TINYRAM\r
 \r
-  .lower.data :\r
-  {\r
-    . = ALIGN(2);\r
-    PROVIDE (__datastart = .);\r
-    *(.lower.data.* .lower.data)\r
-  } > RAM AT> FRAM\r
-\r
   .data :\r
   {\r
     . = ALIGN(2);\r
+    PROVIDE (__datastart = .);\r
 \r
     KEEP (*(.jcr))\r
     *(.data.rel.ro.local) *(.data.rel.ro*)\r
@@ -274,19 +261,13 @@ SECTIONS
 \r
   /* Note that crt0 assumes this is a multiple of two; all the\r
      start/stop symbols are also assumed word-aligned.  */\r
-  PROVIDE(__romdatastart = LOADADDR(.lower.data));\r
-  PROVIDE (__romdatacopysize = SIZEOF(.lower.data) + SIZEOF(.data));\r
-\r
-  .lower.bss :\r
-  {\r
-    . = ALIGN(2);\r
-    PROVIDE (__bssstart = .);\r
-    *(.lower.bss.* .lower.bss)\r
-  } > RAM\r
+  PROVIDE(__romdatastart = LOADADDR(.data));\r
+  PROVIDE (__romdatacopysize = SIZEOF(.data));\r
 \r
   .bss :\r
   {\r
     . = ALIGN(2);\r
+    PROVIDE (__bssstart = .);\r
     *(.dynbss)\r
     *(.sbss .sbss.*)\r
     *(.bss .bss.* .gnu.linkonce.b.*)\r
@@ -294,7 +275,7 @@ SECTIONS
     *(COMMON)\r
     PROVIDE (__bssend = .);\r
   } > RAM\r
-  PROVIDE (__bsssize = SIZEOF(.lower.bss) + SIZEOF(.bss));\r
+  PROVIDE (__bsssize = SIZEOF(.bss));\r
 \r
   /* This section contains data that is not initialised during load\r
      or application reset.  */\r
@@ -336,18 +317,6 @@ SECTIONS
     *(.stack)\r
   }\r
 \r
-  .lower.text :\r
-  {\r
-    . = ALIGN(2);\r
-    *(.lower.text.* .lower.text)\r
-  } > FRAM\r
-\r
-  .lodict :\r
-  {\r
-      . = ALIGN(2);\r
-      *(.lodict)\r
-  } > LOFRAM\r
-\r
   .hidict :\r
   {\r
       . = ALIGN(2);\r
@@ -380,6 +349,12 @@ SECTIONS
     KEEP (*(.tm_clone_table))\r
   } > FRAM\r
 \r
+  .lodict :\r
+  {\r
+      . = ALIGN(2);\r
+      *(.lodict)\r
+  } > FRAM\r
+\r
   .info (NOLOAD) : {} > INFOMEM              /* MSP430 INFO FLASH MEMORY SEGMENTS */\r
 \r
   /* The rest are all not normally part of the runtime image.  */\r
@@ -430,7 +405,7 @@ SECTIONS
   /* DWARF Extension.  */\r
   .debug_macro    0 : { *(.debug_macro) }\r
 \r
-  /DISCARD/ : { *(.note.GNU-stack) }\r
+  /DISCARD/ : { *(.note.GNU-stack .debug_loclists) }\r
 }\r
 \r
 \r