1
; Copyright (C) 2000 Panagiotis Manolios
3
; This program is free software; you can redistribute it and/or modify
4
; it under the terms of the GNU General Public License as published by
5
; the Free Software Foundation; either version 2 of the License, or
6
; (at your option) any later version.
8
; This program is distributed in the hope that it will be useful,
9
; but WITHOUT ANY WARRANTY; without even the implied warranty of
10
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
; GNU General Public License for more details.
13
; You should have received a copy of the GNU General Public License
14
; along with this program; if not, write to the Free Software
15
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
; Written by Panagiotis Manolios who can be reached as follows.
19
; Email: pete@cs.utexas.edu
22
; Department of Computer Science
23
; The University of Texas at Austin
24
; Austin, TX 78701 USA
28
The MA specification of Sawada's machine with interrupts.
34
(include-book "isa-int")
35
(include-book "../top/non-det-macros")
37
(defun latch1 (validp op rc ra rb)
38
(list 'latch1 validp op rc ra rb))
40
(defmacro latch1-validp () 1)
42
(defmacro latch1-op () 2)
44
(defmacro latch1-rc () 3)
46
(defmacro latch1-ra () 4)
48
(defmacro latch1-rb () 5)
50
(defun latch2 (validp op rc ra-val rb-val)
51
(list 'latch2 validp op rc ra-val rb-val))
53
(defmacro latch2-validp () 1)
55
(defmacro latch2-op () 2)
57
(defmacro latch2-rc () 3)
59
(defmacro latch2-ra-val () 4)
61
(defmacro latch2-rb-val () 5)
63
(defun MA-state (pc regs mem latch1 latch2 int)
64
(list 'MA pc regs mem latch1 latch2 int))
71
(defmacro MA-regs () 2)
73
(defmacro MA-mem () 3)
75
(defmacro MA-latch1 () 4)
77
(defmacro MA-latch2 () 5)
79
(defmacro MA-int () 6)
81
(defun ALU-output (op val1 val2)
87
(let ((latch2 (nth (MA-latch2) MA)))
88
(if (and (nth (latch2-validp) latch2)
89
(bor (equal (nth (latch2-op) latch2) 0)
90
(equal (nth (latch2-op) latch2) 1)))
91
(update-valuation (nth (latch2-rc) latch2)
92
(ALU-output (nth (latch2-op) latch2)
93
(nth (latch2-ra-val) latch2)
94
(nth (latch2-rb-val) latch2))
98
(defun stall-condp (MA)
99
(let ((latch1 (nth (MA-latch1) MA))
100
(latch2 (nth (MA-latch2) MA)))
101
(and (nth (latch2-validp) latch2)
102
(nth (latch1-validp) latch1)
103
(bor (equal (nth (latch1-ra) latch1)
104
(nth (latch2-rc) latch2))
105
(equal (nth (latch1-rb) latch1)
106
(nth (latch2-rc) latch2))))))
108
(defun step-latch1 (MA)
109
(let ((latch1 (nth (MA-latch1) MA))
110
(inst (value-of (nth (MA-pc) MA) (nth (MA-mem) MA))))
111
(cond ((stall-condp MA)
114
(nth (Inst-opcode) inst)
117
(nth (Inst-rb) inst))))))
119
(defun step-latch2 (MA)
120
(let ((latch1 (nth (MA-latch1) MA)))
121
(if (nth (latch1-validp) latch1)
122
(latch2 (not (stall-condp MA))
123
(nth (latch1-op) latch1)
124
(nth (latch1-rc) latch1)
125
(value-of (nth (latch1-ra) latch1)
127
(value-of (nth (latch1-rb) latch1)
129
(update-nth (latch2-validp) nil (nth (MA-latch2) MA)))))
134
(1+ (nth (MA-pc) MA))))
139
(defun shift-pc (latch1 latch2)
140
(+ (b-to-num (nth (latch1-validp) latch1))
141
(b-to-num (nth (latch2-validp) latch2))))
143
(defun committed-MA (MA)
144
(let ((pc (nth (MA-pc) MA))
145
(regs (nth (MA-regs) MA))
146
(mem (nth (MA-mem) MA))
147
(latch1 (nth (MA-latch1) MA))
148
(latch2 (nth (MA-latch2) MA))
149
(int (nth (MA-int) MA)))
151
(- pc (shift-pc latch1 latch2))
154
(update-nth (latch1-validp) nil latch1)
155
(update-nth (latch2-validp) nil latch2)
158
(defun MA-step (MA i)
159
(cond ((nth (MA-int) MA)
161
(int-handler (nth (MA-regs) MA)
167
(i (update-nth (MA-int) i (committed-MA MA)))
168
(t (MA-state (step-pc MA)