; -------------------------------------------------------------------------------- ; @Props: NoMetaTags, NoIndex ; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Id: readetmprogram.cmm 6932 2014-04-23 11:15:09Z kjmal $ LOCAL &ret &line &file &adir ENTRY %line &adir &file="&adir" dialog.setfile IFILE "&file" &file=dialog.string(IFILE) if "&file"=="" ( print %ERROR "No file choosen!" ENDDO &adir ) if !os.file(&file) ( print %ERROR "File "+"&file"+" does not exist!" ENDDO &adir ) gosub SetDir &file OPEN #1 "&file" /READ gosub ReadDefs ENTRY &ret &line if &ret==0. ( gosub ReadStates &line ENTRY &ret ) CLOSE #1 if &ret!=0.&&&ret>-2. print %ERROR "Could not init dialog correctly!" ENDDO &adir ReadDefs: LOCAL &ret &line &l1 &l2 &l &pos &x &code &end &first &txt &ret=0. &end=0. &l=0. repeat ( READ #1 %LINE &line &l=&l+1. ) while &ret==0.&&"&line"==""&&&l<10. if "&line"=="" ( print %ERROR "No lines found in file!" &ret=-2. ) while &ret==0.&&&end==0.&&"&line"!="" ( &x=0. &pos=string.mid("&line",&x,1.) while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) if &x>7. &code=string.mid("&line",0.,7.) else &code=string.mid("&line",0.,&x) &first=string.mid("&line",0.,1.) if "&code"==";#AB"||"&code"==";#BB"||"&code"==";#CB" ( LOCAL &bre &bre=string.mid("&code",2.,1.) if etm.addrcomp()==0. ( &txt="Could not load address definition "+"&bre"+"-Range . No address comparators available!" print %ERROR "&txt" &ret=-2. ) else if etm.addrcomp()==1.&&("&code"==";#BB"||"&code"==";#CB") ( &txt="Could not load address definition "+"&bre"+"-Range . Only 1 address comparator available!" print %ERROR "&txt" &ret=-2. ) else if etm.addrcomp()==2.&&"&code"==";#CB" ( &txt="Could not load address definition "+"&bre"+"-Range . Only 2 address comparators available!" print %ERROR "&txt" &ret=-2. ) else ( gosub SetAddr &bre &line ENTRY &ret ) ) else if "&code"==";#D0"||"&code"==";#D1" ( LOCAL &bre &bre=string.mid("&code",3.,1.) if etm.datacomp()==0. ( &txt="Could not load data definition DATA"+"&bre"+". No data comparators available!" print %ERROR "&txt" &ret=-2. ) else if etm.datacomp()==1.&&"&code"==";#D1" ( &txt="Could not load address definition DATA"+"&bre"+". Only 1 data comparator available!" print %ERROR "&txt" &ret=-2. ) else ( gosub SetData &bre &line ENTRY &ret ) ) else if "&code"==";#C0"||"&code"==";#C1" ( LOCAL &bre &bre=string.mid("&code",3.,1.) if etm.counters()==0. ( &txt="Could not load counter definition COUNT"+"&bre"+". No counters available!" print %ERROR "&txt" &ret=-2. ) else if etm.counters()==1.&&"&code"==";#C1" ( &txt="Could not load counter definition COUNT"+"&bre"+". Only 1 counter available!" print %ERROR "&txt" &ret=-2. ) else ( gosub SetCount &bre &line ENTRY &ret ) ) else if "&code"=="; writt" ( if radix()!=0. gosub ShowWarn "This program was written in with old software. Now changing radix to classic." radix classic ) else if "&code"==";0x0 wr" ( if radix()!=0. gosub ShowWarn "This program was written in RADIX Classic. Now changing radix to classic." radix classic ) else if "&code"==";0x0A w" ( if radix()!=10. gosub ShowWarn "This program was written in RADIX Decimal. Now changing radix to decimal." radix decimal ) else if "&code"==";0x10 w" ( if radix()!=16. gosub ShowWarn "This program was written in RADIX Hex. Now changing radix to hex." radix hex ) else if "&code"==";LEVEL0"||"&code"==";LEVEL1"||"&code"==";LEVEL2"||"&first"==";" &end=1. if &end==0. ( READ #1 %LINE &line &l=0. while "&line"==""&&&l<10. ( READ #1 %LINE &line &l=&l+1. ) ) ) RETURN &ret "&line" SetAddr: LOCAL &type &line &ret &x &pos &y &xd &addr &count &tok &set &t1 ENTRY &type &line &x=5. &count=1. &ret=0. &set=0. &pos=string.mid("&line",&x,1.) while "&pos"!=""&&&ret==0. ( &y=&x while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) &xd=&x-&y &addr=string.mid("&line",&y,&xd) on error gosub return EVAL &addr &ret=eval.type() if &ret!=&DAddress&&&ret!=&DARange &ret=-1. else &ret=0. if &ret==0.&&"&addr"!=""&&&count<4. ( &t1=string.cut("&count",-1.) &tok="R"+"&type"+"&t1" dialog.set &tok "&addr" &set=&set+1. ) if "&pos"=="," ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) &count=&count+1. ) if &set==0.&&&ret==0. &ret=-1. RETURN &ret SetData: LOCAL &type &line &ret &x &pos &y &xd &addr &tok &dv &dt ENTRY &type &line &x=5. &ret=0. &dv="" &pos=string.mid("&line",&x,1.) while "&pos"!="" ( &y=&x while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) &xd=&x-&y &addr=string.mid("&line",&y,&xd) if &y==5. ( &dt="&addr" &x=&x+1. &pos=string.mid("&line",&x,1.) ) else &dv="&addr" ) if &ret==0. ( gosub CheckData &dv &dt ENTRY &ret if "&ret"!="" ( &tok="RD"+"&type"+"1" dialog.set &tok "&dv" &tok="RD"+"&type"+"2" dialog.set &tok "&dt" &ret=0. ) else &ret=-1. ) else ( print %ERROR "Data definition wrong; has no value!" &ret=-2. ) RETURN &ret SetCount: LOCAL &type &line &ret &x &pos &y &xd &addr &count &tok &set &cv &etype ENTRY &type &line &x=5. &count=1. &ret=0. &set=0. &cv="" &pos=string.mid("&line",&x,1.) while "&pos"!=""&&&ret==0. ( &y=&x while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) &xd=&x-&y &addr=string.mid("&line",&y,&xd) if &ret==0. ( if &set==0. &cv="&addr" else ( print %ERROR "Count definition is not consistent!" &ret=-2. ) &set=&set+1. ) if "&pos"=="," ( &x=&x+1. &pos=string.mid("&line",&x,1.) ) &count=&count+1. ) if (&set==1.)&&&ret==0. ( LOCAL &cvo &cvo="&cv" if "&cv"!="" ( on error gosub return EVAL &cv &etype=eval.type() if &etype!=&DInteger&&&etype!=&DIntNum&&&etype!=&DFloat&&&etype!=&DBinary&&&etype!=&DHex&&&etype!=&DNumeric ( &etype="&cv"+" no valid count value!" print %ERROR "&etype" &ret=-2. &cv ) if &cv>0xffff ( &etype="Count value "+"&cv"+" bigger than max count value 0xffff!" print %ERROR "&etype" &ret=-2. ) ) else &ret=-1. if &ret==0. ( &tok="EC"+"&type" dialog.set &tok "&cv" &ret=0. ) ) if &set==0.&&&ret==0. &ret=-1. RETURN &ret ReadStates: LOCAL &ret &line &pos &x &code &end &fi &level &count &set ENTRY &line &ret=0. &set=0. &end=0. &level=-1. &count=1. &x=0. &pos=string.mid(&line,&x,1.) while &ret==0.&&"&pos"!="" ( while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid(&line,&x,1.) ) &code=string.mid(&line,0.,7.) &fi=string.mid(&line,0.,1.) if "&code"==";LEVEL0"||"&code"==";LEVEL1"||"&code"==";LEVEL2" ( &level=string.mid(&line,6.,1.)+"." gosub InitLevel &level &count=1. ) else if "&fi"==";"&&&level>=0.&&&level<3. ( gosub IdentifyActLine &line &level &count ENTRY &ret &count=&count+1. &set=&set+1. ) else if &level<0. ( print %ERROR "Could not read level label for action!" &ret=-2. ) else if &level>2. ( print %ERROR "Levels exceeded (>3)!" &ret=-2. ) READ #1 %LINE &line &line="""&line""" &x=0. &pos=string.mid(&line,&x,1.) ) if &set==0. ( print %ERROR "Could not read analyzer programm!(no ;)" &ret=-2. ) RETURN &ret InitLevel: LOCAL &level &ret &txt ENTRY &level if &level==0. ( if etm.addrcomp()==0. ( dialog.disable S0AR1 dialog.disable S0AR2 dialog.disable S0AR3 dialog.disable S0AR4 ) else ( dialog.enable S0AR1 dialog.enable S0AR2 dialog.enable S0AR3 dialog.enable S0AR4 ) if etm.datacomp()==0. ( dialog.disable S0D1 dialog.disable S0D2 dialog.disable S0D3 dialog.disable S0D4 ) else ( dialog.enable S0D1 dialog.enable S0D2 dialog.enable S0D3 dialog.enable S0D4 ) if etm.counters()==0. ( dialog.disable S0C1 dialog.disable S0C2 dialog.disable S0C3 dialog.disable S0C4 ) else ( dialog.enable S0C1 dialog.enable S0C2 dialog.enable S0C3 dialog.enable S0C4 ) dialog.enable S0A1 dialog.enable S0WR1 dialog.enable S0A2 dialog.enable S0WR2 dialog.enable S0A3 dialog.enable S0WR3 dialog.enable S0A4 dialog.enable S0WR4 ) else if &level==1. ( if etm.addrcomp()==0. ( dialog.disable S1AR1 dialog.disable S1AR2 dialog.disable S1AR3 ) else ( dialog.enable S1AR1 dialog.enable S1AR2 dialog.enable S1AR3 ) if etm.datacomp()==0. ( dialog.disable S1D1 dialog.disable S1D2 dialog.disable S1D3 ) else ( dialog.enable S1D1 dialog.enable S1D2 dialog.enable S1D3 ) if etm.counters()==0. ( dialog.disable S1C1 dialog.disable S1C2 dialog.disable S1C3 ) else ( dialog.enable S1C1 dialog.enable S1C2 dialog.enable S1C3 ) dialog.enable S1A1 dialog.enable S1WR1 dialog.enable S1A2 dialog.enable S1WR2 dialog.enable S1A3 dialog.enable S1WR3 ) else if &level==2. ( if etm.addrcomp()==0. ( dialog.disable S2AR1 dialog.disable S2AR2 dialog.disable S2AR3 ) else ( dialog.enable S2AR1 dialog.enable S2AR2 dialog.enable S2AR3 ) if etm.datacomp()==0. ( dialog.disable S2D1 dialog.disable S2D2 dialog.disable S2D3 ) else ( dialog.enable S2D1 dialog.enable S2D2 dialog.enable S2D3 ) if etm.counters()==0. ( dialog.disable S2C1 dialog.disable S2C2 dialog.disable S2C3 ) else ( dialog.enable S2C1 dialog.enable S2C2 dialog.enable S2C3 ) dialog.enable S2A1 dialog.enable S2WR1 dialog.enable S2A2 dialog.enable S2WR2 dialog.enable S2A3 dialog.enable S2WR3 ) else ( &txt="Level "+"&level"+" not valid!" print %ERROR "&txt" &ret=-2. ) RETURN IdentifyActLine: LOCAL &line &level &nr &sact &sa &pos &x &y &t1 &t2 &count &ret &cfound ENTRY &line &level &nr &ret=0. &x=0. &cfound=-1. &t1=string.cut("&level",-1.) &t2=string.cut("&nr",-1.) &pos=string.mid(&line,&x,1.) while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid(&line,&x,1.) ) &sa=string.mid(&line,0.,&x) if "&sa"==";#SE" &sact="Trace" else if "&sa"==";#SG" ( LOCAL &tok &sact="Trace (Global)" ; due to restrictions disable counter &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"E"+"&t2" dialog.disable &tok ) else if "&sa"==";#ST" ( LOCAL &tok &sact="TraceON (Global)" ; due to restrictions disable counter &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"E"+"&t2" dialog.disable &tok ) else if "&sa"==";#SF" ( LOCAL &tok &sact="TraceOFF (Global)" ; due to restrictions disable counter &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"E"+"&t2" dialog.disable &tok ) else if "&sa"==";#DE" ( LOCAL &tok &sact="View Data" ; due to restrictions disable counter &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok ) else if "&sa"==";#TT" &sact="Trigger TRACE" else if "&sa"==";#GS0" &sact="Goto Level0" else if "&sa"==";#GS1" ( &sact="Goto Level1" if &level==0.&&&stateon==-1. &stateon=&nr ) else if "&sa"==";#GS2" ( &sact="Goto Level2" if &level==0.&&&stateon==-1. &stateon=&nr ) else if "&sa"==";#IC0" &sact="Decr COUNT0" else if "&sa"==";#IC1" &sact="Decr COUNT1" else if "&sa"==";#RC0" &sact="Reload COUNT0" else if "&sa"==";#RC1" &sact="Reload COUNT1" else if "&sa"==";#EX0" &sact="Set EXT0" else if "&sa"==";#EX1" &sact="Set EXT1" else &sact="" if "&sact"!="" ( LOCAL &ye &sb &sb1 &sb2 &sb3 &sb4 &sb5 &tok="S"+"&t1"+"A"+"&t2" dialog.set &tok "&sact" &count=0. &sb1="" &sb2="" &sb3="" &sb4="" &sb5="" while "&pos"!="" ( &x=&x+1. &pos=string.mid(&line,&x,1.) &y=&x while "&pos"!=","&&"&pos"!="" ( &x=&x+1. &pos=string.mid(&line,&x,1.) ) &ye=&x-&y if &count==0. &sb1=string.mid(&line,&y,&ye) else if &count==1. &sb2=string.mid(&line,&y,&ye) else if &count==2. &sb3=string.mid(&line,&y,&ye) else if &count==3. &sb4=string.mid(&line,&y,&ye) else if &count==4. &sb5=string.mid(&line,&y,&ye) &count=&count+1. ) &count=0. &ye=0. &sb="x" while "&sb"!=""&&&ret==0. ( LOCAL &tok &bstr if &count==0. ( if "&sb1"!="" &sb="&sb1" else if "&sb2"!="" ( &sb="&sb2" &count=&count+1. ) else if "&sb3"!="" ( &sb="&sb3" &count=&count+2. ) else if "&sb4"!="" ( &sb="&sb4" &count=&count+3. ) else if "&sb5"!="" ( &sb="&sb5" &count=&count+4. ) else &sb="" ) else if &count==1. ( if "&sb2"!="" &sb="&sb2" else if "&sb3"!="" ( &sb="&sb3" &count=&count+1. ) else if "&sb4"!="" ( &sb="&sb4" &count=&count+2. ) else if "&sb5"!="" ( &sb="&sb5" &count=&count+3. ) else &sb="" ) else if &count==2. ( if "&sb3"!="" &sb="&sb3" else if "&sb4"!="" ( &sb="&sb4" &count=&count+1. ) else if "&sb5"!="" ( &sb="&sb5" &count=&count+2. ) else &sb="" ) else if &count==3. ( if "&sb4"!="" &sb="&sb4" else if "&sb5"!="" ( &sb="&sb5" &count=&count+1. ) else &sb="" ) else if &count==4.&&"&sb5"!="" &sb="&sb5" else &sb="" if "&sb"=="(READ||WRITE)"||"&sb"=="WRITE"||"&sb"=="READ"||"&sb"=="FETCH"||"&sb"=="EXECUTE"||"&sb"=="EXECUTEPASS"||"&sb"=="EXECUTEFAIL" ( &tok="S"+"&t1"+"WR"+"&t2" if "&sb"=="(READ||WRITE)" dialog.set &tok "ACCESS" else dialog.set &tok "&sb" &ye=&ye+1. ) else if "&sb"=="DATA0"||"&sb"=="DATA1" ( &tok="S"+"&t1"+"D"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. ) else if "&sb"=="!DATA0"||"&sb"=="!DATA1" ( LOCAL &dnr &dnr=string.mid("&sb",5.,1.) &sb="NOT DATA"+"&dnr" &tok="S"+"&t1"+"D"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. ) else if "&sb"=="COUNT0"||"&sb"=="COUNT1" ( if &level>0.&&&cfound==1. ( &sact="Condition "+"&sb"+" not allowed with address range in Level "+"&level"+" Line "+"&line"+"!" print %ERROR "&sact" &ret=-2. ) else ( &tok="S"+"&t1"+"C"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. &cfound=2. if &level>0. ( &tok="S"+"&t1"+"AR"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"WR"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"D"+"&t2" dialog.disable &tok ) ) ) else if "&sb"=="!COUNT0"||"&sb"=="!COUNT1" ( if &level>0.&&&cfound==1. ( &sact="Condition "+"&sb"+" not allowed with address range in Level "+"&level"+" Line "+"&line"+"!" print %ERROR "&sact" &ret=-2. ) else ( LOCAL &dnr &dnr=string.mid("&sb",6.,1.) &sb="NOT COUNT"+"&dnr" &tok="S"+"&t1"+"C"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. &cfound=2. if &level>0. ( &tok="S"+"&t1"+"AR"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"WR"+"&t2" dialog.disable &tok &tok="S"+"&t1"+"D"+"&t2" dialog.disable &tok ) ) ) else if "&sb"=="AB"||"&sb"=="BB"||"&sb"=="CB" ( &bstr=string.mid("&sb",0.,1.) &bstr="&bstr"+"-Range" &tok="S"+"&t1"+"AR"+"&t2" dialog.set &tok "&bstr" if &level>0. ( &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok ) &cfound=1. &ye=&ye+1. ) else if "&sb"=="!AB"||"&sb"=="!BB"||"&sb"=="!CB" ( &bstr=string.mid("&sb",1.,1.) &bstr="NOT "+"&bstr"+"-Range" &tok="S"+"&t1"+"AR"+"&t2" dialog.set &tok "&bstr" if &level>0. ( &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok ) &cfound=1. &ye=&ye+1. ) else if "&sb"=="AB&&BB"||"&sb"=="AB&&CB"||"&sb"=="BB&&CB" ( LOCAL &b1 &b2 &b1=string.mid("&sb",0.,1.) &b2=string.mid("&sb",5.,1.) &bstr="&b1"+"&b2"+"-Range" &tok="S"+"&t1"+"AR"+"&t2" dialog.set &tok "&bstr" if &level>0. ( &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok ) &cfound=1. &ye=&ye+1. ) else if "&sb"=="EXT0"||"&sb"=="EXT1" ( &tok="S"+"&t1"+"E"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. ) else if "&sb"=="!EXT0"||"&sb"=="!EXT1" ( LOCAL &dnr &dnr=string.mid("&sb",4.,1.) &sb="NOT EXT"+"&dnr" &tok="S"+"&t1"+"E"+"&t2" dialog.set &tok "&sb" &ye=&ye+1. ) else if "&sb"!="" ( &sact="Condition "+"&sb"+" unknown!" print %ERROR "&sact" &ret=-2. ) &count=&count+1. ) ) else ( &sact="Action "+"&sa"+" unknown!" print %ERROR "&sact" &ret=-2. ) if &level>0.&&&cfound==1. ( &tok="S"+"&t1"+"C"+"&t2" dialog.disable &tok ) RETURN &ret SetDir: LOCAL &i &j &p &file ENTRY %line &file &i=0. &j=string.len("&file")-1. &p=string.mid("&file",&j,1.) while "&p"!="/"&&"&p"!="\"&&&j>0. ( &j=&j-1. &p=string.mid("&file",&j,1.) &i=&i+1. ) if &j>0. ( &adir=string.cut("&file",-&i) &adir="&adir"+"*.cmm" ) else &adir="*.cmm" RETURN CheckData: LOCAL &dval &dtype &dmax &x ENTRY &dval &dtype on error gosub return EVAL &dval &x=eval.type() if &x==&DAddress||&x==&DARange||&x==&DEmpty||&x==&DTime||&x==&DTRange ( &x="&dval"+" no valid data value!" print %ERROR "&x" &dval="" ) else if &x!=&DBitmask&&&x!=&DAscii&&&x!=&DString ( if &dval<0. ( if &dval<0xefffffff ( &x="&dval"+" smaller than minimum 0xefffffff!" print %ERROR "&x" &dval="" ) ) if &dval>0x7fffffff ( &x="&dval"+" bigger than maximum 0x7fffffff!" print %ERROR "&x" &dval="" ) ) RETURN &dval ShowWarn: LOCAL &stext &text ENTRY &stext &text=&stext print "" dialog ( header "WARNING" pos 1. 1. 50. text:EDIT "" "" pos 1. 3. 5. DEFBUTTON "OK" "goto oclose" CLOSE "goto oclose" ) dialog.set text "&text" stop oclose: dialog.end RETURN