version 1.4, 2000/06/17 12:01:55
|
version 1.11, 2007/12/31 19:02:24
|
Line 1
|
Line 1
|
|
|
\ bernd thallner 9725890 881 |
|
\ assembler in forth for alpha |
\ assembler in forth for alpha |
|
|
\ require ../../code.fs |
\ Copyright (C) 1999,2000,2007 Free Software Foundation, Inc. |
|
|
|
\ This file is part of Gforth. |
|
|
|
\ Gforth is free software; you can redistribute it and/or |
|
\ modify it under the terms of the GNU General Public License |
|
\ as published by the Free Software Foundation, either version 3 |
|
\ of the License, or (at your option) any later version. |
|
|
|
\ This program is distributed in the hope that it will be useful, |
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
\ GNU General Public License for more details. |
|
|
|
\ You should have received a copy of the GNU General Public License |
|
\ along with this program. If not, see http://www.gnu.org/licenses/. |
|
|
|
\ contributed by Bernd Thallner |
|
|
|
require ./../../code.fs |
|
|
get-current |
get-current |
also assembler definitions |
also assembler definitions |
Line 81 endif
|
Line 98 endif
|
4 allot |
4 allot |
; |
; |
|
|
\ format |
\ operands |
|
|
: Bra ( oo ) \ branch instruction format |
|
create , |
|
does> ( ra, branch_disp, addr ) |
|
@ 26 lshift |
|
swap $1fffff and or |
|
swap $1f and 21 lshift or h, |
|
; |
|
|
|
: Mbr ( oo.h ) \ memory branch instruction format |
|
create 2, |
|
does> ( ra, rb, hint, addr ) |
|
2@ 14 lshift |
|
swap 26 lshift or |
|
swap $3fff and or |
|
swap $1f and 16 lshift or |
|
swap $1f and 21 lshift or |
|
h, |
|
; |
|
|
|
: F-P ( oo.fff ) \ floating-point operate instruction format |
|
create 2, |
|
does> ( fa, fb, fc, addr ) |
|
2@ 5 lshift |
|
swap 26 lshift or |
|
swap $1f and or |
|
swap $1f and 16 lshift or |
|
swap $1f and 21 lshift or |
|
h, |
|
; |
|
|
|
: Mem ( oo ) \ memory instruction format |
|
create , |
|
does> ( ra, memory_disp, rb, addr ) |
|
@ 26 lshift |
|
swap $1f and 16 lshift or |
|
swap $ffff and or |
|
swap $1f and 21 lshift or |
|
h, |
|
; |
|
|
|
: Mfc ( oo.ffff ) \ memory instruction with function code format |
|
create 2, |
|
does> ( ra, rb, addr ) |
|
2@ |
|
swap 26 lshift or |
|
swap $1f and 16 lshift or |
|
swap $1f and 21 lshift or |
|
h, |
|
; |
|
|
|
: Opr ( oo.ff ) \ operate instruction format |
: check-range ( u1 u2 u3 -- ) |
create 2, |
within 0= -24 and throw ; |
does> ( ra, rb, rc, addr ) |
|
2@ |
|
5 lshift |
|
swap 26 lshift or |
|
swap $1f and or |
|
swap $1f and 16 lshift or |
|
swap $1f and 21 lshift or |
|
h, |
|
; |
|
|
|
: Opr# ( oo.ff ) \ operate instruction format |
: rega ( rega code -- code ) |
create 2, |
\ ra field, named rega to avoid conflict with register ra |
does> ( ra, lit, rc, addr ) |
swap dup 0 $20 check-range |
2@ |
21 lshift or ; |
5 lshift |
|
swap 26 lshift or |
: rb ( rb code -- code ) |
1 12 lshift or |
swap dup 0 $20 check-range |
swap $1f and or |
16 lshift or ; |
swap $ff and 13 lshift or |
|
swap $1f and 21 lshift or |
: rc ( rc code -- code ) |
h, |
swap dup 0 $20 check-range |
; |
or ; |
|
|
: Pcd ( oo ) \ palcode instruction format |
: hint ( addr code -- code ) |
create , |
swap 2 rshift $3fff and or ; |
does> ( palcode, addr ) |
|
@ 26 lshift |
: disp ( n code -- code ) |
swap $3ffffff and or |
swap dup -$8000 $8000 check-range |
h, |
$ffff and or ; |
; |
|
|
: branch-rel ( n code -- code ) |
|
swap dup 3 and 0<> -24 and throw |
|
2/ 2/ |
|
dup -$100000 $100000 check-range |
|
$1fffff and or ; |
|
|
|
: branch-disp ( addr code -- code ) |
|
swap here 4 + - swap branch-rel ; |
|
|
|
: imm ( u code -- code ) |
|
swap dup 0 $100 check-range |
|
13 lshift or ; |
|
|
|
: palcode ( u code -- code ) |
|
swap dup 0 $4000000 check-range or ; |
|
|
|
\ formats |
|
|
|
: Bra ( opcode -- ) \ branch instruction format |
|
create 26 lshift , |
|
does> ( rega target-addr -- ) |
|
@ branch-disp rega h, ; |
|
|
|
: Mbr ( opcode hint -- ) \ memory branch instruction format |
|
create 14 lshift swap 26 lshift or , |
|
does> ( rega rb hint -- ) |
|
@ hint rb rega h, ; |
|
|
|
: F-P ( opcode func -- ) \ floating-point operate instruction format |
|
create 5 lshift swap 26 lshift or , |
|
does> ( fa fb fc -- ) |
|
@ rc rb rega h, ; |
|
|
|
: Mem ( opcode -- ) \ memory instruction format |
|
create 26 lshift , |
|
does> ( rega memory_disp rb -- ) |
|
@ rb disp rega h, ; |
|
|
|
: Mfc ( opcode func -- ) \ memory instruction with function code format |
|
create swap 26 lshift or , |
|
does> ( rega rb -- ) |
|
@ rb rega h, ; |
|
|
|
: Opr ( opcode.ff ) \ operate instruction format |
|
create 5 lshift swap 26 lshift or , |
|
does> ( rega rb rc -- ) |
|
@ rc rb rega h, ; |
|
|
|
: Opr# ( opcode func -- ) \ operate instruction format |
|
create 5 lshift swap 26 lshift or 1 12 lshift or , |
|
does> ( rega imm rc -- ) |
|
@ rc imm rega h, ; |
|
|
|
: Pcd ( opcode -- ) \ palcode instruction format |
|
create 26 lshift , |
|
does> ( palcode addr -- ) |
|
@ palcode h, ; |
|
|
\ instructions |
\ instructions |
|
|
Line 193 $38 Bra blbc,
|
Line 208 $38 Bra blbc,
|
$3c Bra blbs, |
$3c Bra blbs, |
$3b Bra ble, |
$3b Bra ble, |
$3a Bra blt, |
$3a Bra blt, |
$3d Bra bne, |
$3d Bra bne, |
$30 Bra br, |
$30 Bra br, |
$34 Bra bsr, |
$34 Bra bsr, |
$00 Pcd call_pal, |
$00 Pcd call_pal, |
Line 402 $12 $30 Opr# zap#,
|
Line 417 $12 $30 Opr# zap#,
|
$12 $31 Opr zapnot, |
$12 $31 Opr zapnot, |
$12 $31 Opr# zapnot#, |
$12 $31 Opr# zapnot#, |
|
|
\ structures |
\ conditions; they are reversed because of the if and until logic (the |
|
\ stuff enclosed by if is performed if the branch around has the |
|
\ inverse condition). |
|
|
|
' beq, constant ne |
|
' bge, constant lt |
|
' bgt, constant le |
|
' blbc, constant lbs |
|
' blbs, constant lbc |
|
' ble, constant gt |
|
' blt, constant ge |
|
' bne, constant eq |
|
' fbeq, constant fne |
|
' fbge, constant flt |
|
' fbgt, constant fle |
|
' fble, constant fgt |
|
' fblt, constant fge |
|
' fbne, constant feq |
|
|
|
\ control structures |
|
|
|
: magic-asm ( u1 u2 -- u3 u4 ) |
|
\ turns a magic number into an asm-magic number or back |
|
$fedcba0987654321 xor ; |
|
|
|
: patch-branch ( behind-branch-addr target-addr -- ) |
|
\ there is a branch just before behind-branch-addr; PATCH-BRANCH |
|
\ patches this branch to branch to target-addr |
|
over - ( behind-branch-addr rel ) |
|
swap 4 - dup >r ( rel branch-addr R:branch-addr ) |
|
h@ branch-rel r> h! ; \ !! relies on the imm field being 0 before |
|
|
|
: if, ( reg xt -- asm-orig ) |
|
\ xt is for a branch word ( reg addr -- ) |
|
here 4 + swap execute \ put 0 into the disp field |
|
here live-orig magic-asm live-orig ; |
|
|
|
: ahead, ( -- asm-orig ) |
|
zero ['] br, if, ; |
|
|
|
: then, ( asm-orig -- ) |
|
orig? magic-asm orig? |
|
here patch-branch ; |
|
|
|
: begin, ( -- asm-dest ) |
|
here dest magic-asm dest ; |
|
|
|
: until, ( asm-dest reg xt -- ) |
|
\ xt is a condition ( reg addr -- ) |
|
here 4 + swap execute |
|
dest? magic-asm dest? |
|
here swap patch-branch ; |
|
|
|
: again, ( asm-dest -- ) |
|
zero ['] br, until, ; |
|
|
|
: while, ( asm-dest -- asm-orig asm-dest ) |
|
if, 1 cs-roll ; |
|
|
\ <register_number> if, <if_code> [ else, <else_code> ] endif, |
: else, ( asm-orig1 -- asm-orig2 ) |
|
ahead, 1 cs-roll then, ; |
|
|
: ahead, ( -- asmorig ) |
: repeat, ( asm-orig asm-dest -- ) |
31 0 br, |
again, then, ; |
here 4 - |
|
; |
|
|
|
: if, ( -- asmorig ) |
: endif, ( asm-orig -- ) |
0 beq, |
then, ; |
here 4 - |
|
; |
|
|
|
: endif, ( asmorig -- ) |
|
dup here swap - 4 - 4 / |
|
$1fffff and |
|
over h@ or swap h! |
|
; |
|
|
|
: else, ( asmorig1 -- asmorig2 ) |
|
ahead, |
|
swap |
|
endif, |
|
; |
|
|
|
\ begin, <code> again, |
|
|
|
: begin, ( -- asmdest ) |
|
here |
|
; |
|
|
|
: again, ( asmdest -- ) |
|
here - 4 - 4 / |
|
$1fffff and |
|
31 swap br, |
|
; |
|
|
|
\ begin, <code> <register_number> until, |
|
|
|
: until, ( asmdest -- ) |
|
here rot swap - 4 - 4 / |
|
$1fffff and |
|
bne, |
|
; |
|
|
|
\ begin, <register_number> while, <code> repeat, |
|
|
|
: while, ( asmdest -- asmorig asmdest ) |
|
if, |
|
swap |
|
; |
|
|
|
: repeat, ( asmorig asmdest -- ) |
|
again, |
|
endif, |
|
; |
|
|
|
\ \ jump marks |
\ \ jump marks |
|
|
Line 563 $12 $31 Opr# zapnot#,
|
Line 588 $12 $31 Opr# zapnot#,
|
previous set-current |
previous set-current |
|
|
|
|
|
|