File:  [gforth] / gforth / arch / alpha / asm.fs
Revision 1.2: download - view: text, annotated - select for diffs
Thu Sep 30 14:01:09 1999 UTC (22 years, 10 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added disasm.fs (Bernd Thallner)
added control structures to asm.fs (Bernd Thallner)

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

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