home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dumptool.zip / TRUTILS.ZIP / maptsf.cmd < prev    next >
OS/2 REXX Batch file  |  1998-07-27  |  17KB  |  534 lines

  1. /* rexx */
  2. /* MAPTSF Map to TSF conversion utility */
  3. /* R.J.Moore 6 May 1997                 */
  4. /* version 1.7                          */
  5. say ";MAPTSF: Map to TSF conversion utility version 1.7"
  6. say ";Author: Richard Moore - 27th July 98"
  7. say ';Copyright (C) 1997, IBM UK Ltd.'
  8.  
  9. trace 'o'
  10. signal on halt name haltexit
  11. parse arg parms
  12.  
  13. ?.=''
  14. ?tmpl16.=''
  15. ?tmpl16ret.=''
  16. ?tmpl32.=''
  17. ?tmpl32ret.=''
  18. ?tmpl16.0=0
  19. ?tmpl16ret.0=0
  20. ?tmpl32.0=0
  21. ?tmpl32ret.0=0
  22.  
  23. rc=parse_parms(parms)
  24.  
  25. if rc=0 then rc=readmap()
  26.  
  27. if rc=0 then rc=gentsf()
  28.  
  29. haltexit:
  30. exit rc
  31.  
  32.  
  33. parse_parms: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32.,
  34.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  35. parse arg parms
  36.  
  37. parse var parms mapfile parms
  38.  
  39. if mapfile='' then do
  40.    call emsg  'Map file required'
  41.    call syntax_help
  42.    return 4
  43. end /* do */
  44. else ?.0mapfile=mapfile
  45.  
  46. ?.0retep=0=1
  47. ?.0logreturn=0=1
  48. ?.0logstack=0
  49. ?.0case=0=1
  50. ?.0types=0=1
  51. rc=0
  52. tin= 'abcdefghijklmnopqrstuvwzyz,'
  53. tout='ABCDEFGHIJKLMNOPQRSTUVWZYZ '
  54. include=''
  55. exclude=''
  56.  
  57. do while parms<>''
  58.    parse var parms key parms
  59.    parse var key . '/' key . '=' value .
  60.    key=transkey(key)
  61.    select
  62.       when key='TYPES' then ?.0types=0=0
  63.       when key='CASESENSITIVE' then ?.0case=0=0
  64.       when key='MAJOR' then ?.0major=value
  65.       when key='MAXDATALENGTH' then ?.0maxdatalength=value
  66.       when key='MINORSTART' then ?.0minors=value
  67.       when key='RETEP' then ?.0retep=0=0
  68.       when key='MODNAME' then ?.0modname=value
  69.       when key='TEMPLATE' then rc=readtmplt(value)
  70.       when key='LOGSTACK' & value<>'' then ?.0logstack=value
  71.       when key='LOGSTACK' & value='' then ?.0logstack=16
  72.       when key='LOGRETURN' then ?.0logreturn=0=0
  73.       when key='EXCLUDE' then exclude=value
  74.       when key='INCLUDE' then include=value
  75.       when key='REGISTERS' then ?.0regs=translate(value,tout,tin)
  76.       when key='GROUPS' then ?.0groups=translate(value,tout,tin)
  77.    otherwise
  78.    call emsg  'Invalid or ambiguous parameter:' key
  79.    call syntax_help
  80.    return 8
  81.    end  /* select */
  82. end /* do */
  83.  
  84. if ?.0case then do
  85.    if exclude <> '' then ?.0exclude=translate(exclude,' ',',')
  86.    if include <> '' then ?.0include=translate(include,' ',',')
  87. end /* do */
  88. else do
  89.    if exclude <> '' then ?.0exclude=translate(exclude,tout,tin)
  90.    if include <> '' then ?.0include=translate(include,tout,tin)
  91. end /* do */
  92.  
  93. /* sort into length order */
  94. ?.0include=sortbylen(?.0include)
  95. ?.0exclude=sortbylen(?.0exclude)
  96.  
  97. if ?.0regs<>'' then do i=1 to words(?.0regs)
  98.    r=word(?.0regs,i)
  99.    if length(r)=3 | r='EFLAGS' then ?.0rfmt=?.0rfmt r'=%F'
  100.    else ?.0rfmt=?.0rfmt r'=%W'
  101. end /* do */
  102. ?.0rfmt=strip(?.0rfmt,'b',' ')
  103. ?.0regs=translate(?.0regs,',',' ')
  104.  
  105. return rc
  106.  
  107. transkey: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  108.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  109. arg key
  110. if pos(key,'CASESENSITIVE')=1 & length(key)>0 then return 'CASESENSITIVE'
  111. if pos(key,'EXCLUDE')=1       & length(key)>0 then return 'EXCLUDE'
  112. if pos(key,'GROUPS')=1        & length(key)>0 then return 'GROUPS'
  113. if pos(key,'INCLUDE')=1       & length(key)>0 then return 'INCLUDE'
  114. if pos(key,'LOGRETURN')=1     & length(key)>3 then return 'LOGRETURN'
  115. if pos(key,'LOGSTACK')=1      & length(key)>3 then return 'LOGSTACK'
  116. if pos(key,'MAJOR')=1         & length(key)>2 then return 'MAJOR'
  117. if pos(key,'MAXDATALENGTH')=1 & length(key)>2 then return 'MAXDATALENGTH'
  118. if pos(key,'MINORSTART')=1    & length(key)>1 then return 'MINORSTART'
  119. if pos(key,'MODNAME')=1       & length(key)>1 then return 'MODNAME'
  120. if pos(key,'REGISTERS')=1     & length(key)>2 then return 'REGISTERS'
  121. if pos(key,'REGS')=1          & length(key)>2 then return 'REGISTERS'
  122. if pos(key,'RETEP')=1         & length(key)>2 then return 'RETEP'
  123. if pos(key,'TEMPLATE')=1      & length(key)>1 then return 'TEMPLATE'
  124. if pos(key,'TYPES')=1         & length(key)>1 then return 'TYPES'
  125. return key
  126.  
  127. syntax_help: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  128.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  129. call emsg  'MAPTSF map_file [/MAJOR=major_code]'
  130. call emsg  '                [/MODNAME=name]'
  131. call emsg  '                [/MAXDATALENGTH=max_data_length]'
  132. call emsg  '                [/MINORSTART=minor_code]'
  133. call emsg  '                [/TEMPLATE=template_file]'
  134. call emsg  '                [/LOGSTACK=stack_bytes]'
  135. call emsg  '                [/EXCLUDE=string[*],....]'
  136. call emsg  '                [/INCLUDE=string[*],....]'
  137. call emsg  '                [/REGISTERS=reg[,reg]...]'
  138. call emsg  '                [/LOGRETURN]'
  139. call emsg  '                [/RETEP]'
  140. call emsg  '                [/CASESENSITIVE]'
  141. call emsg  '                [/TYPES]'
  142. call emsg  '                [/GROUPS=string,...]'
  143. call emsg  ''
  144. call emsg  'Minimum abbreviations for keywords are permissible'
  145. call emsg  'Template file contains one to four template TRACEPOINT definitions in'
  146. call emsg  'TRCUST syntax, where:'
  147. call emsg  '      TP=@16           signifies a 16-bit entry-point'
  148. call emsg  '      TP=@16,RETEP     signifies a 16-bit return-point'
  149. call emsg  '      TP=@32           signifies a 32-bit entry-point'
  150. call emsg  '      TP=@32,RETEP     signifies a 32-bit return-point'
  151. call emsg  ''
  152. return
  153.  
  154. readmap: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  155.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  156.  
  157. ?.0codeobjs=0
  158. ?codeobjs.=0=1
  159. ?codeobj16.=0=1
  160. ?publics.=0=1
  161. ?.0tp16=0
  162. ?.0tp32=0
  163. if lines(?.0mapfile)>0 then do
  164.    mapline=getline(?.0mapfile)
  165.    do while words(mapline)<>1 & lines(?.0mapfile)>0
  166.       mapline=getline(?.0mapfile)
  167.    end /* do */
  168.    if words(mapline)=1 & ?.0modname='' then ?.0modname=mapline
  169.    mapline=getline(?.0mapfile)
  170.    do while word(mapline,1)<> 'Start' & lines(?.0mapfile)>0
  171.       mapline=getline(?.0mapfile)
  172.    end /* do */
  173.    mapline=getline(?.0mapfile)
  174.    do while words(mapline)>=4
  175.       parse var mapline obj . ':' off len name class type .
  176.       if (pos('CODE',class)>0 & ¬?codeobjs.obj) then do
  177.          ?codeobjs.obj=0=0
  178.          if length(off)=4 | type='16-bit' then ?codeobj16.obj=0=0
  179.       end /* do */
  180.       mapline=getline(?.0mapfile)
  181.    end /* do */
  182.    do while (lines(?.0mapfile)>0 & pos('Publics by Value',mapline)=0)
  183.       mapline=getline(?.0mapfile)
  184.    end /* do */
  185.    mapline=getline(?.0mapfile)
  186.    do while (lines(?.0mapfile)>0 & substr(mapline,5,1)=':')
  187.       parse var mapline obj . ':' off rest
  188.       if ?codeobjs.obj then do
  189.          parse var rest label .
  190.          if allow(label) then do
  191.             if ¬?publics.obj.off then do
  192.                ?publics.obj.off=0=0
  193.                if ?codeobj16.obj then do
  194.                   k=?.0tp16
  195.                   k=k+1
  196.                   ?tp16.k=label
  197.                   ?.0tp16=k
  198.                end /* do */
  199.                else do
  200.                   k=?.0tp32
  201.                   k=k+1
  202.                   ?tp32.k=label
  203.                   ?.0tp32=k
  204.                end /* do */
  205.             end /* do */
  206.          end /* do */
  207.       end /* do */
  208.       mapline=getline(?.0mapfile)
  209.    end /* do */
  210.    call lineout ?.0mapfile
  211. end /* do */
  212. else do
  213.    call emsg  'Null map file'
  214.    return 8
  215. end /* do */
  216.  
  217. return 0
  218.  
  219.  
  220. gentsf: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  221.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  222.  
  223. say 'MODNAME='?.0modname
  224. if ?.0maxdatalenth<>'' then say 'MAXDATALENGTH='?.0maxdatalength
  225. if ?.0major<>'' then say 'MAJOR='?.0major
  226. say ''
  227.  
  228. if ?.0types then do
  229.    say 'TYPELIST NAME=PRE,ID=1,'
  230.    say '         NAME=POST,ID=2,'
  231.    say '         NAME=PUB,ID=4,'
  232.    say '         NAME=PRIV,ID=8'
  233.    say ''
  234. end /* do */
  235.  
  236. g=words(?.0groups)
  237. if g>0 then do
  238.    if g=1 then say 'GROUPLIST NAME='word(?.0groups,1)',ID=1'
  239.    else do
  240.       say 'GROUPLIST NAME='word(?.0groups,1)',ID=1,'
  241.       do i=2 to g-1
  242.          say '          NAME='word(?.0groups,i)',ID='i','
  243.       end /* do */
  244.       say '          NAME='word(?.0groups,g)',ID='g
  245.    end /* do */
  246. end /* do */
  247.  
  248. if ?.0minors='' then ?.0curmin=1
  249. else ?.0curmin=?.0minors
  250.  
  251. do i=1 to ?.0tp16
  252.    say '/* minor' ?.0curmin '*/'
  253.    say 'TRACE TP=.'?tp16.i','             /* bug */
  254.    if ?.0types then do
  255.       t=strip(?tp16.i,'l','_')
  256.       if datatype(left(t,1),'L') then say '      TYPE=(PRE,PRIV),'
  257.       else say '      TYPE=(PRE,PUB),'
  258.    end /* do */
  259.    grp=getgroup(?tp16.i)
  260.    if grp <> '' then say '      GROUP='grp','
  261.    if ?.0minors<>'' then say '      MINOR='?.0curmin','
  262.    ?.0curmin=?.0curmin+1
  263.    say '      DESC="'?.0modname ?tp16.i 'Entry"'
  264.    if ?.0regs<>'' then do
  265.       say '      REGS=('?.0regs'),'
  266.       say '      FMT="'?.0rfmt'",'
  267.    end /* do */
  268.    if ?.0logstack>0 then do
  269.       say '      REGS=(SP,SS),'
  270.       say '      FMT="Stack pointer SS:SP=%A->",'
  271.       say '      MEM=(RSS+SP,D,'?.0logstack')'
  272.       say '      FMT="%R%W"'
  273.    end /* do */
  274.    do j=1 to ?tmpl16.0
  275.       say '      '?tmpl16.j
  276.    end /* do */
  277.    say ''
  278.    if ?.0retep then do
  279.       say '/* minor' ?.0curmin '*/'
  280.       say 'TRACE TP=.'?tp16.i',RETEP,'             /* bug */
  281.       if ?.0types then do
  282.          t=strip(?tp16.i,'l','_')
  283.          if datatype(left(t,1),'L') then say '      TYPE=(POST,PRIV),'
  284.          else say '      TYPE=(POST,PUB),'
  285.       end /* do */
  286.       grp=getgroup(?tp16.i)
  287.       if grp <> '' then say '      GROUP='grp','
  288.       if ?.0minors<>'' then say '      MINOR='?.0curmin','
  289.       ?.0curmin=?.0curmin+1
  290.       say '      DESC="'?.0modname ?tp16.i 'Return"'
  291.       if ?.0logreturn then do
  292.          say '      REGS=(AX)'
  293.          say '      FMT="Returns (ax) %W"'
  294.       end /* do */
  295.       do j=1 to ?tmpl16ret.0
  296.          say '      '?tmpl16ret.j
  297.       end /* do */
  298.       say ''
  299.    end /* do */
  300. end /* do */
  301.  
  302. do i=1 to ?.0tp32
  303.    say '/* minor' ?.0curmin '*/'
  304.    say 'TRACE TP=.'?tp32.i','
  305.    if ?.0types then do
  306.       t=strip(?tp32.i,'l','_')
  307.       if datatype(left(t,1),'L') then say '      TYPE=(PRE,PRIV),'
  308.       else say '      TYPE=(PRE,PUB),'
  309.    end /* do */
  310.    grp=getgroup(?tp32.i)
  311.    if grp <> '' then say '      GROUP='grp','
  312.    if ?.0minors<>'' then say '      MINOR='?.0curmin','
  313.    ?.0curmin=?.0curmin+1
  314.    say '      DESC="'?.0modname ?tp32.i 'Entry"'
  315.    if ?.0regs<>'' then do
  316.       say '      REGS=('?.0regs'),'
  317.       say '      FMT="'?.0rfmt'",'
  318.    end /* do */
  319.    if ?.0logstack>0 then do
  320.       say '      REGS=(ESP),'
  321.       say '      FMT="Stack pointer ESP=%F->",'
  322.       say '      MEM32=(FESP,D,'?.0logstack')'
  323.       say '      FMT="%R%F"'
  324.    end /* do */
  325.    do j=1 to ?tmpl32.0
  326.       say '      '?tmpl32.j
  327.    end /* do */
  328.    say ''
  329.    if ?.0retep then do
  330.       say '/* minor' ?.0curmin '*/'
  331.       say 'TRACE TP=.'?tp32.i',RETEP,'
  332.       if ?.0types then do
  333.          t=strip(?tp32.i,'l','_')
  334.          if datatype(left(t,1),'L') then say '      TYPE=(POST,PRIV),'
  335.          else say '      TYPE=(POST,PUB),'
  336.       end /* do */
  337.       grp=getgroup(?tp32.i)
  338.       if grp <> '' then say '      GROUP='grp','
  339.       if ?.0minors<>'' then say '      MINOR='?.0curmin','
  340.       ?.0curmin=?.0curmin+1
  341.       say '      DESC="'?.0modname ?tp32.i 'Return"'
  342.       if ?.0logreturn then do
  343.          say '      REGS=(EAX)'
  344.          say '      FMT="Returns (eax) %F"'
  345.       end /* do */
  346.       do j=1 to ?tmpl32ret.0
  347.          say '      '?tmpl32ret.j
  348.       end /* do */
  349.       say ''
  350.    end /* do */
  351. end /* do */
  352.  
  353. return 0
  354.  
  355.  
  356. readtmplt: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32.,
  357.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  358. arg tfile .
  359.  
  360. if lines(tfile)=0 then do
  361.    call emsg 'Null template file' tfile
  362.    return 8
  363. end /* do */
  364.  
  365. do while lines(tfile)>0
  366.    tline=getline(tfile)
  367.    do while word(tline,1)='TRACE' & tline<>''
  368.       parse var tline . 'TP=@' type . ',' ret ',' .
  369.       select
  370.          when type=16 & ret='' then do
  371.             k=0
  372.             if tline='' then do
  373.                call emsg 'Incomplete tracepoint specification in' tfile
  374.                iterate
  375.             end /* do */
  376.             tline=getline(tfile)
  377.             do while word(tline,1)<>'TRACE' & tline<>''
  378.                k=k+1
  379.                ?tmpl16.k=tline
  380.                tline=getline(tfile)
  381.             end /* do */
  382.             ?tmpl16.0=k
  383.          end /* do */
  384.          when type=16 & ret='RETEP' then do
  385.             k=0
  386.             if tline=0 then do
  387.                call emsg 'Incomplete tracepoint specification in' tfile
  388.                iterate
  389.             end /* do */
  390.             tline=getline(tfile)
  391.             do while word(tline,1)<>'TRACE' & tline<>''
  392.                k=k+1
  393.                ?tmpl16ret.k=tline
  394.                tline=getline(tfile)
  395.             end /* do */
  396.             ?tmpl16ret.0=k
  397.          end /* do */
  398.          when type=32 & ret='' then do
  399.             k=0
  400.             if tline='' then do
  401.                call emsg 'Incomplete tracepoint specification in' tfile
  402.                iterate
  403.             end /* do */
  404.             tline=getline(tfile)
  405.             do while word(tline,1)<>'TRACE' & tline<>''
  406.                k=k+1
  407.                ?tmpl32.k=tline
  408.                tline=getline(tfile)
  409.             end /* do */
  410.             ?tmpl32.0=k
  411.          end /* do */
  412.          when type=32 & ret='RETEP' then do
  413.             k=0
  414.             if tline='' then do
  415.                call emsg 'Incomplete tracepoint specification in' tfile
  416.                iterate
  417.             end /* do */
  418.             tline=getline(tfile)
  419.             do while word(tline,1)<>'TRACE' & tline<>''
  420.                k=k+1
  421.                ?tmpl32ret.k=tline
  422.                tline=getline(tfile)
  423.             end /* do */
  424.             ?tmpl32ret.0=k
  425.          end /* do */
  426.       otherwise
  427.       call emsg 'Invalid TP specification in' tfile
  428.       end  /* select */
  429.    end /* do */
  430. end /* do */
  431. call lineout tfile
  432.  
  433. return 0
  434.  
  435.  
  436. getline: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  437.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  438. arg file
  439.  
  440. if lines(file)=0 then return ''
  441. nextline=linein(file)
  442. nextline=translate(nextline,,xrange('00'x,'1f'x),' ')
  443. nextline=strip(nextline,'b',' ')
  444. if nextline='' then nextline=getline(file)
  445. return nextline
  446.  
  447.  
  448. included: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  449.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  450. if ?.0case then parse arg label
  451. else arg label
  452. if ?.0include='' then return 0=0
  453. else do i=1 to words(?.0include)
  454.    w=word(?.0include,i)
  455.    if right(w,1)='*' then do
  456.       if pos(substr(w,1,length(w)-1),label)=1 then return length(w)-1
  457.     end /* do */
  458.    else if w=label then return length(w)
  459. end /* do */
  460. return 0   
  461.  
  462. excluded: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  463.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  464. if ?.0case then parse arg label
  465. else arg label
  466. if ?.0exclude='' then return 0=1
  467. else do i=1 to words(?.0exclude)
  468.    w=word(?.0exclude,i)
  469.    if right(w,1)='*' then do
  470.       if pos(substr(w,1,length(w)-1),label)=1 then return length(w)-1
  471.    end /* do */
  472.    else if w=label then return length(w)
  473. end /* do */
  474. return 0  
  475.  
  476. allow: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  477.                         ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  478. if ?.0case then parse arg label
  479. else arg label
  480. if (?.0exclude<>'' & ?.0include<>'') then,
  481.    return (excluded(label) < included(label))
  482. else if (?.0exclude<>'') then return (excluded(label)=0)
  483. else if (?.0include<>'') then return (included(label)<>0)
  484. else return 0=0
  485.  
  486.  
  487. emsg: procedure
  488. parse arg message
  489.  
  490. x=lineout('STDERR',message)
  491.  
  492. return
  493.  
  494.  
  495. getgroup: procedure expose ?. ?codeobjs. ?publics. ?tp16. ?tp32. ,
  496.                             ?tmpl16. ?tmpl16ret. ?tmpl32. ?tmpl32ret.
  497. arg tp
  498.  
  499. tp=strip(tp,'l','_')
  500. do i=1 to words(?.0groups)
  501.    grp=word(?.0groups,i)
  502.    if pos(grp,tp)=1 then return grp
  503. end /* do */
  504. return ''
  505.  
  506. /* sort generics into length order */
  507. /* after specifics                 */
  508. sortbylen: procedure
  509. parse arg sortstr
  510.  
  511. temp=''
  512. temp2=''
  513. if words(sortstr)>0 then do 
  514.    do i=1 to words(sortstr)
  515.       w=word(sortstr,i)
  516.       l=length(w)
  517.       if right(w,1)='*' then do
  518.          l=l-1
  519.          do j=1 to words(temp)
  520.             if l>=length(word(temp,j)) then do
  521.                j=j-1
  522.                leave
  523.             end /* do */
  524.          end /* do */
  525.          templ = subword(temp,1,j)
  526.          tempr = subword(temp,j+1)
  527.          temp = templ w tempr
  528.       end /* do */
  529.       else temp2 = w temp2
  530.    end /* do */
  531.    temp=strip(temp2 temp,'b',' ')
  532. end /* do */
  533. return temp
  534.