OpenCores
URL https://opencores.org/ocsvn/pdp8/pdp8/trunk

Subversion Repositories pdp8

[/] [pdp8/] [trunk/] [pdp8/] [cpu/] [alu.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 trurl
------------------------------------------------------------------
2
--!
3
--! PDP-8 Processor
4
--!
5
--! \brief
6
--!      CPU Arithmetic Logic Unit (ALU) Register
7
--!
8
--! \details
9
--!      The ALU 'owns' the Link Register (L) and Accumulator
10
--!      Register (AC).  This device performs every operation
11
--!      that manipules either the Link Register or Accumulator.
12
--!
13
--!      This code operates on the Link Register and Accumulator
14
--!      as if it were a single 13-bit wide register.  The Link
15
--!      Register is LAC(0) while the Accumlator is LAC(1 to 12).
16
--!
17
--! \todo
18
--!      Although the CPU is knitted together with a 'rats nest'
19
--!      of interconnections, this file is 'rattier' than most.
20
--!      It could stand a good cleanup.   Any cleanup should also
21
--!      address EAE and how that fits with the ALU.
22
--!
23
--! \file
24
--!      alu.vhd
25
--!
26
--! \author
27
--!      Rob Doyle - doyle (at) cox (dot) net
28
--!
29
--------------------------------------------------------------------
30
--
31
--  Copyright (C) 2009, 2010, 2011, 2012 Rob Doyle
32
--
33
-- This source file may be used and distributed without
34
-- restriction provided that this copyright statement is not
35
-- removed from the file and that any derivative work contains
36
-- the original copyright notice and the associated disclaimer.
37
--
38
-- This source file is free software; you can redistribute it
39
-- and/or modify it under the terms of the GNU Lesser General
40
-- Public License as published by the Free Software Foundation;
41
-- version 2.1 of the License.
42
--
43
-- This source is distributed in the hope that it will be
44
-- useful, but WITHOUT ANY WARRANTY; without even the implied
45
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
46
-- PURPOSE. See the GNU Lesser General Public License for more
47
-- details.
48
--
49
-- You should have received a copy of the GNU Lesser General
50
-- Public License along with this source; if not, download it
51
-- from http://www.gnu.org/licenses/lgpl.txt
52
--
53
--------------------------------------------------------------------
54
--
55
-- Comments are formatted for doxygen
56
--
57
 
58
library ieee;                                   --! IEEE Library
59
use ieee.std_logic_1164.all;                    --! IEEE 1164
60
use ieee.numeric_std.all;                       --! IEEE Numeric Standard
61
use work.cpu_types.all;                         --! Types
62
 
63
--
64
--! CPU Arithmetic Logic Unit (ALU) Register Entity
65
--
66
 
67
entity eALU is port (
68
    sys    : in  sys_t;                         --! Clock/Reset
69
    acOP   : in  acOP_t;                        --! AC Operation
70
    BTSTRP : in  std_logic;                     --! Bootstrap Flag
71
    GTF    : in  std_logic;                     --! Greater Than Flag
72
    HLTTRP : in  std_logic;                     --! Hlttrp Flag
73
    IE     : in  std_logic;                     --! Interrupt Enable Flip-Flop
74
    IRQ    : in  std_logic;                     --! Interrupt Request flag
75
    PNLTRP : in  std_logic;                     --! Panel Trap Flag
76
    PWRTRP : in  std_logic;                     --! Power-on Trap Flag
77
    DF     : in  field_t;                       --! DF Input
78
    EAE    : in  eae_t;                         --! EAE Input
79
    INF    : in  field_t;                       --! INF Input
80
    IR     : in  data_t;                        --! IR Input
81
    MA     : in  addr_t;                        --! MA Input
82
    MD     : in  data_t;                        --! MB Input
83
    MQ     : in  data_t;                        --! MQ Input
84
    PC     : in  addr_t;                        --! PC Input
85
    SC     : in  sc_t;                          --! SC Input
86
    SF     : in  sf_t;                          --! SF Input
87
    SP1    : in  addr_t;                        --! SP1 Input
88
    SP2    : in  addr_t;                        --! SP2 Input
89
    SR     : in  data_t;                        --! SR Input
90
    UF     : in  std_logic;                     --! UF Input
91
    LAC    : out ldata_t                        --! ALU Output
92
);
93
end eALU;
94
 
95
--
96
--! CPU Arithmetic Logic Unit (ALU) Register RTL
97
--
98
 
99
architecture rtl of eALU is
100
 
101
    signal   lacREG         : ldata_t;          --! Link and Accumulator Register
102
    signal   lacMUX         : ldata_t;          --! Link and Accumulator Multiplexer
103
 
104
    --!
105
    --! ALU Operations
106
    --!
107
 
108
    signal   opIAC          : ldata_t;          --! Increment accumulator
109
    signal   opBSW          : ldata_t;          --! Byte swap
110
    signal   opRAL          : ldata_t;          --! 
111
    signal   opRTL          : ldata_t;          --! 
112
    signal   opR3L          : ldata_t;          --! 
113
    signal   opRAR          : ldata_t;          --! 
114
    signal   opRTR          : ldata_t;          --! 
115
    signal   opSHL0         : ldata_t;          --! 
116
    signal   opSHL1         : ldata_t;          --! 
117
    signal   opLSR          : ldata_t;          --! 
118
    signal   opASR          : ldata_t;          --!
119
    signal   opUNDEF1       : ldata_t;          --! Undefined Operation #1
120
    signal   opUNDEF2       : ldata_t;          --! Undefined Operation #2
121
    signal   opPC           : ldata_t;          --! Undefined Operation #1,2
122
    signal   opCML          : ldata_t;          --! 
123
    signal   opCMA          : ldata_t;          --! 
124
    signal   opCMACML       : ldata_t;          --! 
125
    signal   opCLL          : ldata_t;          --! 
126
    signal   opCLLCML       : ldata_t;          --! 
127
    signal   opCLLCMA       : ldata_t;          --! 
128
    signal   opCLLCMACML    : ldata_t;          --! 
129
    signal   opCLA          : ldata_t;          --! 
130
    signal   opCLACML       : ldata_t;          --! 
131
    signal   opCLACMA       : ldata_t;          --! 
132
    signal   opCLACMACML    : ldata_t;          --! 
133
    signal   opCLACLL       : ldata_t;          --! 
134
    signal   opCLACLLCML    : ldata_t;          --! 
135
    signal   opCLACLLCMA    : ldata_t;          --! 
136
    signal   opCLACLLCMACML : ldata_t;          --! 
137
 
138
    --!
139
    --! KM8E
140
    --!
141
 
142
    signal   opRDF0         : ldata_t;          --! RDF0 (HD6120)
143
    signal   opRIF0         : ldata_t;          --! RIF0 (HD6120)
144
    signal   opRIB0         : ldata_t;          --! RIB0 (HD6120)
145
    signal   opRDF1         : ldata_t;          --! RDF1 (PDP8)
146
    signal   opRIF1         : ldata_t;          --! RIF1 (PDP8)
147
    signal   opRIB1         : ldata_t;          --! RIB1 (PDP8)
148
 
149
    --!
150
    --! EAE
151
    --!
152
 
153
    signal   opEAELAC       : ldata_t;          --! LAC <- EAE(0 to 12)
154
    signal   opEAEZAC       : ldata_t;          --! LAC <- '0' & EAE(1 to 12)
155
 
156
    --!
157
    --! Flags
158
    --!
159
 
160
    signal   opPRS          : ldata_t;          --!
161
    signal   opGTF1         : ldata_t;          --!
162
    signal   opGTF2         : ldata_t;          --!
163
    signal   opGCF          : ldata_t;          --!
164
 
165
    --!
166
    --! MD operations
167
    --!
168
 
169
    signal   opSUBMD        : ldata_t;          --! LAC <- LAC - MD
170
    signal   opADDMD        : ldata_t;          --! LAC <- LAC + MD
171
    signal   opADDMDP1      : ldata_t;          --! LAC <- LAC + MD + 1
172
    signal   opANDMD        : ldata_t;          --! LAC <- L & (AC and MD)
173
    signal   opORMD         : ldata_t;          --! LAC <- L & (AC or  MD)
174
 
175
    --!
176
    --! MQ Operations
177
    --!
178
 
179
    signal   opMQSUB        : ldata_t;          --! LAC <- MQ - AC
180
    signal   opMQ           : ldata_t;          --! LAC <- L & MQ
181
    signal   opZMQ          : ldata_t;          --! LAC <- '0' & MQ
182
    signal   opMQP1         : ldata_t;          --! LAC <-  MQ + 1
183
    signal   opNEGMQ        : ldata_t;          --! LAC <- -MQ
184
    signal   opNOTMQ        : ldata_t;          --! LAC <- not(MQ)
185
    signal   opORMQ         : ldata_t;          --! LAC <- L & (AC or MQ)
186
 
187
    --!
188
    --! SC Operations
189
    --!
190
 
191
    signal   opSCA          : ldata_t;          --! LAC <- L & (AC or  SC)
192
 
193
    --!
194
    --! SP Operations
195
    --!
196
 
197
    signal   opSP1          : ldata_t;          --! LAC <- '0' & SP1
198
    signal   opSP2          : ldata_t;          --! LAC <- '0' & SP2
199
 
200
    --!
201
    --! SR Operations
202
    --!
203
 
204
    signal   opOSR          : ldata_t;          --! LAC <- L & (AC or SR)
205
    signal   opLAS          : ldata_t;          --! LAC <- L & SR
206
 
207
begin
208
 
209
    -- group1 sequence 4 operations
210
    opIAC           <= std_logic_vector(unsigned(lacREG) + "1");
211
    opBSW           <= lacREG(0) & lacREG(7 to 12) & lacREG(1 to 6);
212
    -- rotate lefts
213
    opRAL           <= lacREG( 1 to 12) & lacREG(0);
214
    opRTL           <= lacREG( 2 to 12) & lacREG(0 to 1);
215
    opR3L           <= lacREG( 3 to 12) & lacREG(0 to 2);
216
    -- rotate rights
217
    opRAR           <= lacREG(12)       & lacREG(0 to 11);
218
    opRTR           <= lacREG(11 to 12) & lacREG(0 to 10);
219
    -- shift lefts
220
    opSHL0          <= lacREG( 1 to 12) & '0';
221
    opSHL1          <= lacREG( 1 to 12) & '1';
222
    -- shift rights
223
    opLSR           <= '0' & lacREG(0 to 11);
224
    opASR           <= lacREG(1) & lacREG(1) & lacREG(1 to 11);
225
    -- undefs
226
    opUNDEF1        <= lacREG(0) & (lacREG(1 to 12) and IR);
227
    opUNDEF2        <= lacREG(0) & MA(0 to 4) & IR(5 to 11);
228
    opPC            <= lacREG(0) & PC;
229
    -- group 1 operations
230
    opCML           <= not(lacREG(0)) &     lacREG(1 to 12);
231
    opCMA           <=     lacREG(0)  & not(lacREG(1 to 12));
232
    opCMACML        <= not(lacREG(0)) & not(lacREG(1 to 12));
233
    opCLL           <= '0'            &     lacREG(1 to 12);
234
    opCLLCML        <= '1'            &     lacREG(1 to 12);
235
    opCLLCMA        <= '0'            & not(lacREG(1 to 12));
236
    opCLLCMACML     <= '1'            & not(lacREG(1 to 12));
237
    opCLA           <=     lacREG(0)  & o"0000";
238
    opCLACML        <= not(lacREG(0)) & o"0000";
239
    opCLACMA        <=     lacREG(0)  & o"7777";
240
    opCLACMACML     <= not(lacREG(0)) & o"7777";
241
    opCLACLL        <= '0'            & o"0000";
242
    opCLACLLCML     <= '1'            & o"0000";
243
    opCLACLLCMA     <= '0'            & o"7777";
244
    opCLACLLCMACML  <= '1'            & o"7777";
245
    -- KM8E ops
246
    opRDF0          <= lacREG(0 to  6) & DF  & lacREG(10 to 12);
247
    opRIF0          <= lacREG(0 to  6) & INF & lacREG(10 to 12);
248
    opRIB0          <= lacREG(0 to  5) & SF;
249
    opRDF1          <= lacREG(0 to 12) or ("0000000" & DF  & "000");
250
    opRIF1          <= lacREG(0 to 12) or ("0000000" & INF & "000");
251
    opRIB1          <= lacREG(0 to 12) or ("000000"  & SF);
252
    -- Flags
253
    opPRS           <= lacREG(0) & BTSTRP    & PNLTRP & IRQ & PWRTRP & HLTTRP & '0'   & "000"      & "000";
254
    opGTF1          <= lacREG(0) & lacREG(0) & GTF    & IRQ & PWRTRP & '1'    & '0'   & SF(1 to 3) & SF(4 to 6);
255
    opGTF2          <= lacREG(0) & lacREG(0) & GTF    & IRQ &  '0'   & IE     & SF(0) & SF(1 to 3) & SF(4 to 6);
256
    opGCF           <= lacREG(0) & lacREG(0) & GTF    & IRQ & PWRTRP & IE     & '0'   & INF        & DF;
257
    -- EAE
258
    opEAELAC        <= EAE(0 to 12);
259
    opEAEZAC        <= '0' & EAE(1 to 12);
260
    -- MD
261
    opADDMD         <= std_logic_vector(unsigned(lacREG(0 to 12)) + unsigned('0' & MD));
262
    opADDMDP1       <= std_logic_vector(unsigned(lacREG(0 to 12)) + unsigned('0' & MD) + "1");
263
    opSUBMD         <= std_logic_vector(unsigned(lacREG(0 to 12)) - unsigned('0' & MD));
264
    opANDMD         <= lacREG(0) & (lacREG(1 to 12) and MD);
265
    opORMD          <= lacREG(0) & (lacREG(1 to 12) or  MD);
266
    -- MQ
267
    opMQSUB         <= std_logic_vector(unsigned('0' & MQ) + unsigned('0' & not(lacREG(1 to 12))) + "1");
268
    opMQ            <= lacREG(0) & MQ;
269
    opZMQ           <= '0' & MQ;
270
    opMQP1          <= std_logic_vector(unsigned('0' & MQ) + "1");
271
    opNEGMQ         <= std_logic_vector(unsigned('0' & not(MQ)) + "1");
272
    opNOTMQ         <= '0' & not(MQ);
273
    opORMQ          <= lacREG(0) & (lacREG(1 to 12) or MQ);
274
    -- SC
275
    opSCA           <= lacREG(0 to 7) & (lacREG(8 to 12) or SC);
276
    -- SP
277
    opSP1           <= lacREG(0) & SP1;
278
    opSP2           <= lacREG(0) & SP2;
279
    -- SR
280
    opLAS           <= lacREG(0) & SR;
281
    opOSR           <= lacREG(0) & (lacREG(1 to 12) or SR);
282
 
283
    --
284
    -- Adder input #2 mux.
285
    --
286
 
287
    with acOP select
288
        lacMUX <= lacREG          when acopNOP,         -- LAC <- LAC
289
                  opIAC           when acopIAC,         -- LAC <- LAC + 1
290
                  opBSW           when acopBSW,         -- LAC <- L & AC(6:12) & AC(0:5);
291
                  opRAL           when acopRAL,         -- LAC <- AC(0:11) & L
292
                  opRTL           when acopRTL,         -- LAC <- AC(1:11) & L & AC(0)
293
                  opR3L           when acopR3L,         -- LAC <- AC(2:11) & L & AC(0:1)
294
                  opRAR           when acopRAR,         -- LAC <- AC(11) & L & & AC(0:10);
295
                  opRTR           when acopRTR,         -- LAC <- AC(10:11) & L & & AC(0:9);
296
                  opSHL0          when acopSHL0,        -- LAC <- (LAC << 1) & '0'
297
                  opSHL1          when acopSHL1,        -- LAC <- (LAC << 1) & '1'
298
                  opLSR           when acopLSR,         -- LAC <- '0' & (LAC >> 1)
299
                  opASR           when acopASR,         -- LAC <-  L  & (LAC >> 1)
300
                  opUNDEF1        when acopUNDEF1,      -- LAC <-  L  & (AC and IR);
301
                  opUNDEF2        when acopUNDEF2,      -- LAC <-  L  & MA(0:4) & IR(5:11)
302
                  opPC            when acopPC,          -- LAC <- PC
303
                  opCML           when acopCML,         -- LAC <-  0   0   0  CML
304
                  opCMA           when acopCMA,         -- LAC <-  0   0  CMA  0
305
                  opCMACML        when acopCMACML,      -- LAC <-  0   0  CMA CML
306
                  opCLL           when acopCLL,         -- LAC <-  0  CLL  0   0
307
                  opCLLCML        when acopCLLCML,      -- LAC <-  0  CLL  0  CML
308
                  opCLLCMA        when acopCLLCMA,      -- LAC <-  0  CLL CMA  0
309
                  opCLLCMACML     when acopCLLCMACML,   -- LAC <-  0  CLL CMA CML
310
                  opCLA           when acopCLA,         -- LAC <- CLA  0   0   0
311
                  opCLACML        when acopCLACML,      -- LAC <- CLA  0   0  CML 
312
                  opCLACMA        when acopCLACMA,      -- LAC <- CLA  0  CMA  0
313
                  opCLACMACML     when acopCLACMACML,   -- LAC <- CLA  0  CMA CML
314
                  opCLACLL        when acopCLACLL,      -- LAC <- CLA CLL  0   0
315
                  opCLACLLCML     when acopCLACLLCML,   -- LAC <- CLA CLL  0  CML
316
                  opCLACLLCMA     when acopCLACLLCMA,   -- LAC <- CLA CLL CMA  0
317
                  opCLACLLCMACML  when acopCLACLLCMACML,-- LAC <- CLA CLL CMA CML
318
                  opRDF0          when acopRDF0,        -- LAC <- LAC(0 to  6) & DF  & LAC(10 to 12)
319
                  opRIF0          when acopRIF0,        -- LAC <- LAC(0 to  6) & INF & LAC(10 to 12);
320
                  opRIB0          when acopRIB0,        -- LAC <- LAC(0 to  5) & SF
321
                  opRDF1          when acopRDF1,        -- LAC <- LAC(0 to 12) or ("0000000" & DF  & "000");
322
                  opRIF1          when acopRIF1,        -- LAC <- LAC(0 to 12) or ("0000000" & INF & "000")
323
                  opRIB1          when acopRIB1,        -- LAC <- LAC(0 to 12) or ("000000"  & SF);
324
                  opPRS           when acopPRS,         -- LAC <- LAC(0) & BTSTRP    & PNLTRP & IRQ & PWRTRP & HLTTRP & '0'   & "000"      & "000";
325
                  opGTF1          when acopGTF1,        -- HD6120 GTF
326
                  opGTF2          when acopGTF2,        -- PDP8 GTF
327
                  opGCF           when acopGCF,         -- LAC <- LAC(0) & LAC(0) & GTF    & IRQ & PWRTRP & IE     & '0'   & INF        & DF;
328
                  opEAELAC        when acopEAELAC,      -- LAC <- EAE(0 to 12)
329
                  opEAEZAC        when acopEAEZAC,      -- LAC <- '0' & EAE(1 to 12);
330
                  opSUBMD         when acopSUBMD,       -- LAC <- LAC - MD <- LAC + NOT(MD) + 1
331
                  opADDMD         when acopADDMD,       -- LAC <- LAC + MD
332
                  opADDMDP1       when acopADDMDP1,     -- LAC <- LAC + MD + 1
333
                  opANDMD         when acopANDMD,       -- LAC <- L & (AC and MD)
334
                  opORMD          when acopORMD,        -- LAC <- L & (AC or MD)
335
                  opMQSUB         when acopMQSUB,       -- LAC <- MQ - AC <- MQ + NOT(AC) + 1
336
                  opMQ            when acopMQ,          -- LAC <- L & MQ
337
                  opZMQ           when acopZMQ,         -- LAC <- 0 & MQ
338
                  opMQP1          when acopMQP1,        -- LAC <- MQ + 1
339
                  opNEGMQ         when acopNEGMQ,       -- LAC <- -MQ <- NOT(MQ) + 1
340
                  opNOTMQ         when acopNOTMQ,       -- LAC <- NOT(MQ)
341
                  opORMQ          when acopORMQ,        -- LAC <- L & (AC or MQ)
342
                  opSCA           when acopSCA,         -- LAC <- LAC(0 to 7) & (LAC(8 to 12) or SC)
343
                  opSP1           when acopSP1,         -- LAC <- LAC(0) & SP1
344
                  opSP2           when acopSP2,         -- LAC <- LAC(0) & SP2
345
                  opLAS           when acopLAS,         -- LAC <- SR
346
                  opOSR           when acopOSR,         -- LAC <- LAC(0) & (LAC(1 to 12) or SR)
347
                  (others => '0') when others;          -- 
348
 
349
    --
350
    --! ALU Register
351
    --
352
 
353
    REG_ALU : process(sys)
354
    begin
355
        if sys.rst = '1' then
356
            lacREG <= (others => '0');
357
        elsif rising_edge(sys.clk) then
358
            lacREG <= lacMUX;
359
        end if;
360
    end process REG_ALU;
361
 
362
    LAC <= lacREG;
363
 
364
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.