3a_asm: more .fill power and better 'make test' target
authorBernhard Urban <lewurm@gmail.com>
Mon, 1 Nov 2010 13:48:45 +0000 (14:48 +0100)
committerBernhard Urban <lewurm@gmail.com>
Mon, 1 Nov 2010 13:51:39 +0000 (14:51 +0100)
2_isa/callingconv.tex
3a_asm/DTFormat.hs
3a_asm/Main.hs
3a_asm/Makefile
3a_asm/tst/fill.s [new file with mode: 0644]

index e5388d500ee2347a55d7c2e3c1bb57d6f78cc29d..951ef0beec7fc9a4288017aa7eb4e7057c36cbcc 100644 (file)
@@ -61,9 +61,9 @@ assembler, a list is given in table~\ref{tab:asmdirs}.
                address in data or instruction memory, depending on the current
                section \\ \hline
 
-               \texttt{.fill \textit{repeat}, \textit{size}, \textit{value}} & place a
-               value of a specific size \texttt{\textit{repeat}}-times, while
-               \texttt{\textit{repeat}} and \texttt{\texttt{size}} are optional.
+               \texttt{.fill \textit{repeat}, \textit{value}} & place a
+               32 bit value \texttt{\textit{repeat}}-times, while
+               \texttt{\textit{repeat}} is optional.
 
                When one parameter is given, the value is placed at the current address.
                Note that a given value will be rounded up to a full byte, e.g.
index be9aafe462d7ebbeb8f35161fe3a31cc1c6b0a18..3a43eb8b854487ca6b4c18dbd13af4c44b0f5566 100644 (file)
@@ -14,6 +14,7 @@ data DT_State = NoState | InData | InText deriving (Show,Eq)
 
 type Address = Word32
 type Value = Word32
+type Repeat = Word32
 type ValueToParse = String
 type Code = String
 type Label = String
@@ -29,6 +30,7 @@ data DTF =
        DTF_SectionToDet Address Value Code Label Comment |
        DTF_Org Address |
        DTF_Define Label Value Comment |
+       DTF_Fill Repeat Value Label Code Comment |
        DTF_State DT_State
 
 instance Show (DTF) where
@@ -42,7 +44,8 @@ showsDTF (DTF_Label l c _) = (++) (printf "3;%s;%s\n" l c)
 showsDTF (DTF_InstrToParse a v c l s) = (++) (printf "itp;%08x;%s;%s;%s;%s\n" a v c l s)
 showsDTF (DTF_SectionToDet a v c l s) = (++) (datins "std" a v c l s)
 showsDTF (DTF_Org a) = (++) (printf "org;%08x\n" a)
-showsDTF (DTF_Define l a c) = (++) (printf "def;%s;%08X;%s\n" l a c)
+showsDTF (DTF_Define l a c) = (++) (printf "def;%s;%08x;%s\n" l a c)
+showsDTF (DTF_Fill r v code l c) = (++) (printf "fill;%08x;%08x;%s;%s;%s\n" r v code l c)
 showsDTF (DTF_State s) = (++) (printf "sta;%s\n" (show s))
 
 datins :: String -> Address -> Value -> Code -> Label -> Comment -> String
index 2e99807e06f0cf10a41347045dcf3d427becbeb3..f3a6fc11d0681aac60ad2bb9bb8d05a8d82df96a 100644 (file)
@@ -58,6 +58,13 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
        actlist (DTF_Org _) = next
        actlist (DTF_State _) = next
        actlist (DTF_Define _ _ _) = next
+       actlist (DTF_Fill rep val code l c) = if state == InData then
+               (DTF_Data datacnt val code l c):[(DTF_Data dc val "" "" "") | i<-[2..repi], let dc = [(datacnt+0x4),(datacnt+0x8)..]!!(i-2)] ++ next
+               else
+               (DTF_Instr instrcnt val code l c):[(DTF_Instr ic val "" "" "") | i<-[2..repi], let ic = [(instrcnt+0x4),(instrcnt+0x8)..]!!(i-2)] ++ next
+               where
+               repi :: Int
+               repi = fromInteger (toInteger rep)
        actlist y = y:next
 
        (newdict,next) = convertDTF xs (nstate newdtf) (ndatacnt newdtf) (ninstrcnt newdtf) (ndict newdtf)
@@ -65,12 +72,18 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
        ndatacnt (DTF_Org adr)
                | state == InData = adr
                | otherwise = datacnt
+       ndatacnt (DTF_Fill rep _ _ _ _)
+               | state == InData = datacnt + (4*rep)
+               | otherwise = datacnt
        ndatacnt (DTF_Data _ _ _ _ _) = inc datacnt
        ndatacnt _ = datacnt
 
        ninstrcnt (DTF_Org adr)
                | state == InText = adr
                | otherwise = instrcnt
+       ninstrcnt (DTF_Fill rep _ _ _ _)
+               | state == InText = instrcnt + (4*rep)
+               | otherwise = instrcnt
        ninstrcnt (DTF_Instr _ _ _ _ _) = inc instrcnt
        ninstrcnt (DTF_InstrToParse _ _ _ _ _) = inc instrcnt
        ninstrcnt _ = instrcnt
@@ -84,6 +97,9 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
        ndict (DTF_Data a _ _ l _) = dict `add_elem` (l,a)
        ndict (DTF_Instr a _ _ l _) = dict `add_elem` (l,a)
        ndict (DTF_Define l v _) = dict `add_elem` (l,v)
+       ndict (DTF_Fill _ _ _ l _)
+               | state == InText = dict `add_elem` (l,instrcnt)
+               | state == InData = dict `add_elem` (l,datacnt)
        ndict _ = dict
 
        newdtf = case (parse (parseDTFLine dict) "" (str++"\n")) of
@@ -104,7 +120,7 @@ convertDTF ((lno,str):xs) state datacnt instrcnt dict = (newdict, (actlist newdt
                                NoState -> error "missing .data or .text"
                                InData -> (DTF_Label l c datacnt)
                                InText -> (DTF_Label l c instrcnt)
-               Right z -> z -- DTF_Comment, DTF_State, DTF_Define
+               Right z -> z -- DTF_Comment, DTF_State, DTF_Define, DTF_Fill
 
 
 
@@ -149,12 +165,14 @@ lf_data d = do
        l <- try (parseLabel) <|> string ""
        skipMany space
        fill <- string ".fill "
+       repeat <- try (do {size <- many1 $ noneOf "\n;,"; char ','; return $ size}) <|> return "1"
        -- TODO: atm 32bit imm only
        code <- many1 $ noneOf "\n;"
        -- TODO: this is quite ugly here :/
        let (Right val) = parse (parseConst d) "" code
+       let (Right r) = parse (parseConst d) "" repeat
        comment <- try(parseComment) <|> parseMySpaces
-       return $ DTF_SectionToDet 0 val (fill ++ code) l comment
+       return $ DTF_Fill r val (fill ++ (if repeat == "1" then "" else repeat) ++ code) l comment
 
 lf_comment _ = do
        comment <- parseComment
index c38230d22d8586cb7f3e842c89537955d6700afe..4b3da7ef10095bd5532c2bacf9bce841c05663bf 100644 (file)
@@ -5,7 +5,13 @@ all:
 
 .PHONY: clean test
 clean:
-       rm -Rf **/**.o **/**.hi dtas
+       -rm -Rf **/**.o **/**.hi dtas
 
-test: all
-       cat ../2_isa/src/sum.s && echo '==== here comes the DT ASM output ====' && cat ../2_isa/src/sum.s | ./dtas
+TESTFILES := $(shell ls tst/*.s) $(shell ls ../2_isa/src/*.s)
+test: all $(TESTFILES:.s=.out)
+
+%.out: %.s
+       @echo "=== testing file $<"
+       @cat $<
+       @echo "=== here comes the DT ASM output ==="
+       @./dtas < $<
diff --git a/3a_asm/tst/fill.s b/3a_asm/tst/fill.s
new file mode 100644 (file)
index 0000000..44e3b79
--- /dev/null
@@ -0,0 +1,13 @@
+.data
+.fill 5, 0x14732
+yeah: .fill 0x1111
+
+.text
+addi r0,r0,0;
+ldil r3, 0x444
+.org 0x1000
+.fill 0x10-8, 0x987655
+
+.data
+.org 0x500
+.fill 10, 0x1337