File:  [gforth] / gforth / arch / alpha / asm.fs
Revision 1.4: download - view: text, annotated - select for diffs
Sat Jun 17 12:01:55 2000 UTC (22 years, 1 month ago) by anton
Branches: MAIN
CVS tags: HEAD
Assembler and disassembler are included in gforth.fi if available
Alpha assembler and disassembler tweaks

    1: 
    2: \ bernd thallner 9725890 881
    3: \ assembler in forth for alpha
    4: 
    5: \ require ../../code.fs
    6: 
    7: get-current
    8: also assembler definitions
    9: 
   10: \ register
   11: 
   12:  $0 constant v0
   13:  $1 constant t0
   14:  $2 constant t1
   15:  $3 constant t2
   16:  $4 constant t3
   17:  $5 constant t4
   18:  $6 constant t5
   19:  $7 constant t6
   20:  $8 constant t7
   21:  $9 constant s0
   22:  $a constant s1
   23:  $b constant s2
   24:  $c constant s3
   25:  $d constant s4
   26:  $e constant s5
   27:  $f constant fp
   28: \ commented out to avoid shadowing hex numbers
   29: \  $10 constant a0
   30: \  $11 constant a1
   31: \  $12 constant a2
   32: \  $13 constant a3
   33: \  $14 constant a4
   34: \  $15 constant a5
   35: $16 constant t8
   36: $17 constant t9
   37: $18 constant t10
   38: $19 constant t11
   39: $1a constant ra
   40: $1b constant t12
   41: $1c constant at
   42: $1d constant gp
   43: $1e constant sp
   44: $1f constant zero
   45: 
   46: \ util
   47: 
   48: : h@ ( addr -- n )		\ 32 bit fetch
   49: dup dup aligned = if
   50:   @
   51:   $00000000ffffffff and
   52: else
   53:   4 - @
   54:   $20 rshift
   55: endif
   56: ;
   57: 
   58: : h! ( n addr -- )		\ 32 bit store
   59: dup dup aligned = if
   60:   dup @
   61:   $ffffffff00000000 and
   62:   rot or
   63:   swap !
   64: else
   65:   4 - dup @
   66:   $00000000ffffffff and
   67:   rot $20 lshift or
   68:   swap !
   69: endif
   70: ;
   71: 
   72: : h, ( h -- )			\ 32 bit store + allot
   73: here here aligned = if
   74:   here !
   75: else
   76:   32 lshift
   77:   here 4 - dup
   78:   @ rot or
   79:   swap !
   80: endif
   81: 4 allot
   82: ;
   83: 
   84: \ format
   85: 
   86: : Bra ( oo )			\ branch instruction format
   87:   create ,
   88: does> ( ra, branch_disp, addr )
   89:   @ 26 lshift
   90:   swap $1fffff and or
   91:   swap $1f and 21 lshift or h,
   92: ;
   93: 
   94: : Mbr ( oo.h )			\ memory branch instruction format
   95:   create 2,
   96: does> ( ra, rb, hint, addr )
   97:   2@ 14 lshift
   98:   swap 26 lshift or
   99:   swap $3fff and or
  100:   swap $1f and 16 lshift or
  101:   swap $1f and 21 lshift or
  102:   h,
  103: ; 
  104: 
  105: : F-P ( oo.fff )		\ floating-point operate instruction format
  106:   create 2,
  107: does> ( fa, fb, fc, addr )
  108:   2@ 5 lshift
  109:   swap 26 lshift or
  110:   swap $1f and or
  111:   swap $1f and 16 lshift or
  112:   swap $1f and 21 lshift or
  113:   h,
  114: ;
  115: 
  116: : Mem ( oo )			\ memory instruction format
  117:   create ,
  118: does> ( ra, memory_disp, rb, addr )
  119:   @ 26 lshift
  120:   swap $1f and 16 lshift or
  121:   swap $ffff and or 
  122:   swap $1f and 21 lshift or
  123:   h,
  124: ;
  125: 
  126: : Mfc ( oo.ffff )		\ memory instruction with function code format
  127:   create 2,
  128: does> ( ra, rb, addr )
  129:   2@
  130:   swap 26 lshift or
  131:   swap $1f and 16 lshift or
  132:   swap $1f and 21 lshift or
  133:   h,
  134: ;
  135: 
  136: : Opr ( oo.ff )			\ operate instruction format
  137:   create 2,
  138: does> ( ra, rb, rc, addr )
  139:   2@
  140:   5 lshift
  141:   swap 26 lshift or
  142:   swap $1f and or
  143:   swap $1f and 16 lshift or
  144:   swap $1f and 21 lshift or
  145:   h, 
  146: ;
  147: 
  148: : Opr# ( oo.ff )		\ operate instruction format
  149:   create 2,
  150: does> ( ra, lit, rc, addr )
  151:   2@
  152:   5 lshift
  153:   swap 26 lshift or
  154:   1 12 lshift or
  155:   swap $1f and or
  156:   swap $ff and 13 lshift or
  157:   swap $1f and 21 lshift or
  158:   h, 
  159: ;
  160: 
  161: : Pcd ( oo )			\ palcode instruction format
  162:   create ,
  163: does> ( palcode, addr )
  164:   @ 26 lshift
  165:   swap $3ffffff and or
  166:   h,
  167: ;
  168: 
  169: \ instructions
  170: 
  171: $15 $80   F-P  addf,
  172: $15 $a0   F-P  addg,
  173: $10 $00   Opr  addl,
  174: $10 $00   Opr# addl#,
  175: $10 $40   Opr  addlv,
  176: $10 $40   Opr# addlv#,
  177: $10 $20   Opr  addq,
  178: $10 $20   Opr# addq#,
  179: $10 $60   Opr  addqv,
  180: $10 $60   Opr# addqv#,
  181: $16 $80   F-P  adds,
  182: $16 $a0   F-P  addt,
  183: $11 $00   Opr  and,
  184: $11 $00   Opr# and#,
  185: $39       Bra  beq,
  186: $3e       Bra  bge,
  187: $3f       Bra  bgt,
  188: $11 $08   Opr  bic,
  189: $11 $08   Opr# bic#,
  190: $11 $20   Opr  bis,
  191: $11 $20   Opr# bis#,
  192: $38       Bra  blbc,
  193: $3c       Bra  blbs,
  194: $3b       Bra  ble,
  195: $3a       Bra  blt,
  196: $3d       Bra  bne,
  197: $30       Bra  br,
  198: $34       Bra  bsr,
  199: $00       Pcd  call_pal,
  200: $11 $24   Opr  cmoveq,
  201: $11 $24   Opr# cmoveq#,
  202: $11 $46   Opr  cmovge,
  203: $11 $46   Opr# cmovge#,
  204: $11 $66   Opr  cmovgt,
  205: $11 $66   Opr# cmovgt#,
  206: $11 $16   Opr  cmovlbc,
  207: $11 $16   Opr# cmovlbc#,
  208: $11 $14   Opr  cmovlbs,
  209: $11 $14   Opr# cmovlbs#,
  210: $11 $64   Opr  cmovle,
  211: $11 $64   Opr# cmovle#,
  212: $11 $44   Opr  cmovlt,
  213: $11 $44   Opr# cmovlt#,
  214: $11 $26   Opr  cmovne,
  215: $11 $26   Opr# cmovne#,
  216: $10 $0f   Opr  cmpbge,
  217: $10 $0f   Opr# cmpbge#,
  218: $10 $2d   Opr  cmpeq,
  219: $10 $2d   Opr# cmpeq#,
  220: $15 $a5   F-P  cmpgeq,
  221: $15 $a7   F-P  cmpgle,
  222: $15 $a6   F-P  cmpglt,
  223: $10 $6d   Opr  cmple,
  224: $10 $6d   Opr# cmple#,
  225: $10 $4d   Opr  cmplt,
  226: $10 $4d   Opr# cmplt#,
  227: $16 $a5   F-P  cmpteq,
  228: $16 $a7   F-P  cmptle,
  229: $16 $a6   F-P  cmptlt,
  230: $16 $a4   F-P  cmptun,
  231: $10 $3d   Opr  cmpule,
  232: $10 $3d   Opr# cmpule#,
  233: $10 $1d   Opr  cmpult,
  234: $10 $1d   Opr# cmpult#,
  235: $17 $20   F-P  cpys,
  236: $17 $22   F-P  cpyse,
  237: $17 $21   F-P  cpysn,
  238: $15 $9e   F-P  cvtdg,
  239: $15 $ad   F-P  cvtgd,
  240: $15 $ac   F-P  cvtgf,
  241: $15 $af   F-P  cvtgq,
  242: $17 $10   F-P  cvtlq,
  243: $15 $bc   F-P  cvtqf,
  244: $15 $be   F-P  cvtqg,
  245: $17 $30   F-P  cvtql,
  246: $17 $530  F-P  cvtqlsv,
  247: $17 $130  F-P  cvtqlv,
  248: $16 $bc   F-P  cvtqs,
  249: $16 $be   F-P  cvtqt,
  250: $16 $2ac  F-P  cvtst,
  251: $16 $af   F-P  cvttq,
  252: $16 $ac   F-P  cvtts,
  253: $15 $83   F-P  divf,
  254: $15 $a3   F-P  divg,
  255: $16 $83   F-P  divs,
  256: $16 $a3   F-P  divt,
  257: $11 $48   Opr  eqv,
  258: $11 $48   Opr# eqv#,
  259: $18 $400  Mfc  excb,
  260: $12 $06   Opr  extbl,
  261: $12 $06   Opr# extbl#,
  262: $12 $6a   Opr  extlh,
  263: $12 $6a   Opr# extlh#,
  264: $12 $26   Opr  extll,
  265: $12 $26   Opr# extll#,
  266: $12 $7a   Opr  extqh,
  267: $12 $7a   Opr# extqh#,
  268: $12 $36   Opr  extql,
  269: $12 $36   Opr# extql#,
  270: $12 $5a   Opr  extwh,
  271: $12 $5a   Opr# extwh#,
  272: $12 $16   Opr  extwl,
  273: $12 $16   Opr# extwl#,
  274: $31       Bra  fbeq,
  275: $36       Bra  fbge,
  276: $37       Bra  fbgt,
  277: $33       Bra  fble,
  278: $32       Bra  fblt,
  279: $35       Bra  fbne,
  280: $17 $2a   F-P  fcmoveq,
  281: $17 $2d   F-P  fcmovge,
  282: $17 $2f   F-P  fcmovgt,
  283: $17 $2e   F-P  fcmovle,
  284: $17 $2c   F-P  fcmovlt,
  285: $17 $2b   F-P  fcmovne,
  286: $18 $8000 Mfc  fetch,
  287: $18 $a000 Mfc  fetch_m,
  288: $12 $0b   Opr  insbl,
  289: $12 $0b   Opr# insbl#,
  290: $12 $67   Opr  inslh,
  291: $12 $67   Opr# inslh#,
  292: $12 $2b   Opr  insll,
  293: $12 $2b   Opr# insll#,
  294: $12 $77   Opr  insqh,
  295: $12 $77   Opr# insqh#,
  296: $12 $3b   Opr  insql,
  297: $12 $3b   Opr# insql#,
  298: $12 $57   Opr  inswh,
  299: $12 $57   Opr# inswh#,
  300: $12 $1b   Opr  inswl,
  301: $12 $1b   Opr# inswl#,
  302: $1a $00   Mbr  jmp,
  303: $1a $01   Mbr  jsr,
  304: $1a $03   Mbr  jsr_coroutine,
  305: $08       Mem  lda,
  306: $09       Mem  ldah,
  307: $20       Mem  ldf,
  308: $21       Mem  ldg,
  309: $28       Mem  ldl,
  310: $2a       Mem  ldl_l,
  311: $29       Mem  ldq,
  312: $2b       Mem  ldq_l,
  313: $0b       Mem  ldq_u,
  314: $22       Mem  lds,
  315: $23       Mem  ldt,
  316: $18 $4000 Mfc  mb,
  317: $17 $25   F-P  mf_fpcr,
  318: $12 $02   Opr  mskbl,
  319: $12 $02   Opr# mskbl#,
  320: $12 $62   Opr  msklh,
  321: $12 $62   Opr# msklh#,
  322: $12 $22   Opr  mskll,
  323: $12 $22   Opr# mskll#,
  324: $12 $72   Opr  mskqh,
  325: $12 $72   Opr# mskqh#,
  326: $12 $32   Opr  mskql,
  327: $12 $32   Opr# mskql#,
  328: $12 $52   Opr  mskwh,
  329: $12 $52   Opr# mskwh#,
  330: $12 $12   Opr  mskwl,
  331: $12 $12   Opr# mskwl#,
  332: $17 $24   F-P  mt_fpcr,
  333: $15 $82   F-P  mulf,
  334: $15 $a2   F-P  mulg,
  335: $13 $00   Opr  mull,
  336: $13 $00   Opr# mull#,
  337: $13 $40   Opr  mullv,
  338: $13 $40   Opr# mullv#,
  339: $13 $20   Opr  mullq,
  340: $13 $20   Opr# mullq#,
  341: $13 $60   Opr  mullqv,
  342: $13 $60   Opr# mullqv#,
  343: $16 $82   F-P  mulls,
  344: $16 $a2   F-P  mullt,
  345: $11 $28   Opr  ornot,
  346: $11 $28   Opr# ornot#,
  347: $18 $e000 Mfc  rc,
  348: $1a $02   Mbr  ret,
  349: $18 $c000 Mfc  rpcc,
  350: $18 $f000 Mfc  rs,
  351: $10 $02   Opr  s4addl,
  352: $10 $02   Opr# s4addl#,
  353: $10 $22   Opr  s4addq,
  354: $10 $22   Opr# s4addq#,
  355: $10 $0b   Opr  s4subl,
  356: $10 $0b   Opr# s4subl#,
  357: $10 $2b   Opr  s4subq,
  358: $10 $2b   Opr# s4subq#,
  359: $10 $12   Opr  s8addl,
  360: $10 $12   Opr# s8addl#,
  361: $10 $32   Opr  s8addq,
  362: $10 $32   Opr# s8addq#,
  363: $10 $1b   Opr  s8ubl,
  364: $10 $1b   Opr# s8ubl#,
  365: $10 $3b   Opr  s8ubq,
  366: $10 $3b   Opr# s8ubq#,
  367: $12 $39   Opr  sll,
  368: $12 $39   Opr# sll#,
  369: $12 $3c   Opr  sra,
  370: $12 $3c   Opr# sra#,
  371: $12 $34   Opr  srl,
  372: $12 $34   Opr# srl#,
  373: $24       Mem  stf,
  374: $25       Mem  stg,
  375: $26       Mem  sts,
  376: $2c       Mem  stl,
  377: $2e       Mem  stl_c,
  378: $2d       Mem  stq,
  379: $2f       Mem  stq_c,
  380: $0f       Mem  stq_u,
  381: $27       Mem  stt,
  382: $15 $81   F-P  subf,
  383: $15 $a1   F-P  subg,
  384: $10 $09   Opr  subl,
  385: $10 $09   Opr# subl#,
  386: $10 $49   Opr  sublv,
  387: $10 $49   Opr# sublv#,
  388: $10 $29   Opr  subq,
  389: $10 $29   Opr# subq#,
  390: $10 $69   Opr  subqv,
  391: $10 $69   Opr# subqv#,
  392: $16 $81   F-P  subs,
  393: $16 $a1   F-P  subt,
  394: $18 $00   Mfc  trapb,
  395: $13 $30   Opr  umulh,
  396: $13 $30   Opr# umulh#,
  397: $18 $4400 Mfc  wmb,
  398: $11 $40   Opr  xor,
  399: $11 $40   Opr# xor#,
  400: $12 $30   Opr  zap,
  401: $12 $30   Opr# zap#,
  402: $12 $31   Opr  zapnot,
  403: $12 $31   Opr# zapnot#,
  404: 
  405: \ structures
  406: 
  407: \ <register_number> if, <if_code> [ else, <else_code> ] endif,
  408: 
  409: : ahead, ( -- asmorig )
  410:     31 0 br,
  411:     here 4 -
  412: ;
  413: 
  414: : if, ( -- asmorig )
  415:   0 beq,
  416:   here 4 -
  417: ;
  418: 
  419: : endif, ( asmorig -- )
  420:   dup here swap - 4 - 4 /
  421:   $1fffff and
  422:   over h@ or swap h!
  423: ;
  424: 
  425: : else, ( asmorig1 -- asmorig2 )
  426:     ahead,
  427:     swap
  428:     endif,
  429: ;
  430: 
  431: \ begin, <code> again,
  432: 
  433: : begin, ( -- asmdest )
  434:   here
  435: ;
  436: 
  437: : again, ( asmdest -- )
  438:   here - 4 - 4 /
  439:   $1fffff and
  440:   31 swap br,
  441: ;
  442: 
  443: \ begin, <code> <register_number> until,
  444: 
  445: : until, ( asmdest -- )
  446:   here rot swap - 4 - 4 /
  447:   $1fffff and
  448:   bne,
  449: ;
  450: 
  451: \ begin, <register_number> while, <code> repeat,
  452: 
  453: : while, ( asmdest -- asmorig asmdest )
  454:   if,
  455:   swap
  456: ;
  457: 
  458: : repeat, ( asmorig asmdest -- )
  459:   again,
  460:   endif,
  461: ;
  462: 
  463: \  \ jump marks
  464: 
  465: \  \ example:
  466: 
  467: \  \ init_marktbl		\ initializes mark table
  468: \  \ 31 0 br,
  469: \  \ 0 store_branch	\ store jump address for mark 0
  470: \  \ 1 2 3 addf,
  471: \  \ 0 set_mark		\ store mark 0
  472: \  \ 2 3 4 addf,
  473: \  \ 2 0 beq,
  474: \  \ 0 store_branch	\ store jump address for mark 0
  475: \  \ calculate_marks       \ calculate all jumps
  476: 
  477: \  \ with <mark_address> <jump_address> calculate_branch you can calculate the
  478: \  \ displacement field without the mark_table for one branch
  479: 
  480: \  \ example:
  481: \  \ here 31 0 br,
  482: \  \ here 1 2 3 addf,
  483: \  \ calculate_branch
  484: 
  485: \  5 constant mark_numbers
  486: \  5 constant mark_uses
  487: 
  488: \  create mark_table
  489: \  mark_numbers mark_uses 1+ * cells allot
  490: 
  491: \  : init_marktbl ( -- )			\ initializes mark table
  492: \    mark_table mark_numbers mark_uses 1+ * cells +
  493: \    mark_table
  494: \    begin
  495: \      over over >
  496: \    while
  497: \      dup 0 swap !
  498: \      1 cells +
  499: \    repeat
  500: \    drop drop
  501: \  ;
  502: 
  503: \  : set_mark ( mark_number -- )		\ sets mark, store address in mark table
  504: \    dup mark_numbers >= abort" error, illegal mark number"
  505: \    mark_uses 1+ * cells
  506: \    mark_table + here 8 - swap !
  507: \  ;
  508: 
  509: \  : store_branch ( mark_number -- )	\ stores address of branch in mark table
  510: \    dup mark_numbers >= abort" error, illegal mark number"
  511: \    mark_uses 1+ * cells
  512: \    mark_table + 1 cells +
  513: \    dup mark_uses cells + swap
  514: \    begin
  515: \      over over > over @ and 
  516: \    while
  517: \      1 cells +
  518: \    repeat
  519: \    swap over = abort" error, not enough space in mark_table, increase mark_uses"
  520: \    here 4 - swap !
  521: \  ;
  522: 
  523: \  : calculate_branch ( mark_addr branch_addr -- ) \ calculate branch displacement field for one branch
  524: \    swap over - 4 + 4 /
  525: \    $1fffff and
  526: \    over h@ or swap h!
  527: \  ;
  528: 
  529: \  : calculate_mark ( tb mark_address -- tb )	\ calculates branch displacement field for one mark
  530: \    over 1 cells +
  531: \    dup mark_uses cells + swap
  532: \    begin
  533: \      over over >
  534: \    while
  535: \      2over swap drop ( ei i markaddr ej j markaddr )
  536: \      over @
  537: \      dup if
  538: \        calculate_branch
  539: \      else
  540: \        drop drop
  541: \      endif
  542: \      1 cells +
  543: \    repeat drop drop drop
  544: \  ;
  545: 
  546: \  : calculate_marks ( -- )		\ calculates branch displacement field for all marks
  547: \    mark_table mark_numbers 1- mark_uses 1+ * cells +
  548: \    mark_table
  549: \    begin
  550: \      over over >=
  551: \    while
  552: \      dup @
  553: \        dup if \ used mark
  554: \          calculate_mark
  555: \        else
  556: \          drop
  557: \        endif
  558: \      mark_uses 1+ cells +
  559: \    repeat
  560: \    drop drop
  561: \  ;
  562: 
  563: previous set-current
  564: 
  565: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>