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

Subversion Repositories klc32

[/] [klc32/] [trunk/] [rtl/] [verilog/] [REGFETCHA.v] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
// (C) 2011 Robert Finch
3
// All Rights Reserved.
4
// robfinch<remove>@opencores.org
5
//
6
// KLC32 - 32 bit CPU
7
// REGFETCHA.v - fetch register A / execute some instructions
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
REGFETCHA:
25
        begin
26
                a <= rfo;
27
                b <= 32'd0;
28
                Rn <= ir[20:16];
29 7 robfinch
                if (opcode==`RR || opcode==`RRR || opcode==`SW || opcode==`SH || opcode==`SB) begin
30 2 robfinch
                        state <= REGFETCHB;
31
                end
32
                else begin
33 7 robfinch
                        // RIX format ?
34 2 robfinch
                        if ((hasConst16 && ir[15:0]==16'h8000) || (isStop))
35
                                state <= FETCH_IMM32;
36
                        else begin
37
                                imm <= {{16{ir[15]}},ir[15:0]};
38
                                state <= EXECUTE;
39
                        end
40
                end
41
                case(opcode)
42
                `MISC:
43
                        case(func)
44
                        `TRACE_ON:
45
                                        if (!sf) begin
46
                                                vector <= `PRIVILEGE_VIOLATION;
47
                                                state <= TRAP;
48
                                        end
49
                                        else begin
50
                                                tf <= 1'b1;
51
                                                state <= IFETCH;
52
                                        end
53
                        `TRACE_OFF:
54
                                        if (!sf) begin
55
                                                vector <= `PRIVILEGE_VIOLATION;
56
                                                state <= TRAP;
57
                                        end
58
                                        else begin
59
                                                tf <= 1'b0;
60
                                                state <= IFETCH;
61
                                        end
62
                        `SET_IM:
63
                                        if (!sf) begin
64
                                                vector <= `PRIVILEGE_VIOLATION;
65
                                                state <= TRAP;
66
                                        end
67
                                        else begin
68
                                                im <= ir[2:0];
69
                                                state <= IFETCH;
70
                                        end
71
                        `USER_MODE: begin sf <= 1'b0; state <= IFETCH; end
72
                        `JMP32: state <= JMP32;
73
                        `JSR32: state <= JSR32;
74
                        `RTS: state <= RTS;
75
                        `RTI:
76
                                if (!sf) begin
77
                                        vector <= `PRIVILEGE_VIOLATION;
78
                                        state <= TRAP;
79
                                end
80
                                else
81
                                        state <= RTI1;
82
                        `RST:
83
                                if (!sf) begin
84
                                        vector <= `PRIVILEGE_VIOLATION;
85
                                        state <= TRAP;
86
                                end
87
                                else begin
88
                                        rst_o <= 1'b1;
89
                                        state <= IFETCH;
90
                                end
91
                        endcase
92 7 robfinch
                `R:
93
                        case(func)
94
                        `UNLK:  state <= UNLK;
95
                        endcase
96 2 robfinch
                `NOP: state <= IFETCH;
97
                `JSR: begin tgt <= {pc[31:26],ir[25:2],2'b00}; state <= JSR1; end
98
                `JMP: begin pc[25:2] <= ir[25:2]; state <= IFETCH; end
99
                `Bcc:
100
                        case(cond)
101
                        `BRA:   begin pc <= pc + brdisp; state <= IFETCH; end
102
                        `BEQ:   begin if ( cr_zf) pc <= pc + brdisp; state <= IFETCH; end
103
                        `BNE:   begin if (!cr_zf) pc <= pc + brdisp; state <= IFETCH; end
104
                        `BMI:   begin if ( cr_nf) pc <= pc + brdisp; state <= IFETCH; end
105
                        `BPL:   begin if (!cr_zf) pc <= pc + brdisp; state <= IFETCH; end
106
                        `BHI:   begin if (!cr_cf & !cr_zf) pc <= pc + brdisp; state <= IFETCH; end
107
                        `BLS:   begin if (cf |zf) pc <= pc + brdisp; state <= IFETCH; end
108
                        `BHS:   begin if (!cr_cf) pc <= pc + brdisp; state <= IFETCH; end
109
                        `BLO:   begin if ( cr_cf) pc <= pc + brdisp; state <= IFETCH; end
110
                        `BGT:   begin if ((cr_nf & cr_vf & !cr_zf)|(!cr_nf & !cr_vf & !cr_zf)) pc <= pc + brdisp; state <= IFETCH; end
111
                        `BLE:   begin if (cr_zf | (cr_nf & !cr_vf) | (!cr_nf & cr_vf)) pc <= pc + brdisp; state <= IFETCH; end
112
                        `BGE:   begin if ((cr_nf & cr_vf)|(!cr_nf & !cr_vf)) pc <= pc + brdisp; state <= IFETCH; end
113
                        `BLT:   begin if ((cr_nf & !cr_vf)|(!cr_nf & cr_vf)) pc <= pc + brdisp; state <= IFETCH; end
114
                        `BVS:   begin if ( cr_vf) pc <= pc + brdisp; state <= IFETCH; end
115
                        `BVC:   begin if (!cr_vf) pc <= pc + brdisp; state <= IFETCH; end
116
                        endcase
117
                `TRAPcc:
118
                        case(cond)
119
                        `TRAP:  begin vector <= `TRAP_VECTOR + {ir[3:0],2'b00}; state <= TRAP; end
120
                        `TEQ:   begin if ( cr_zf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
121
                        `TNE:   begin if (!cr_zf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
122
                        `TMI:   begin if ( cr_nf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
123
                        `TPL:   begin if (!cr_zf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
124
                        `THI:   begin if (!cr_cf & !cr_zf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
125
                        `TLS:   begin if (cf |zf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
126
                        `THS:   begin if (!cr_cf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
127
                        `TLO:   begin if ( cr_cf) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
128
                        `TGT:   begin if ((cr_nf & cr_vf & !cr_zf)|(!cr_nf & !cr_vf & !cr_zf)) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
129
                        `TLE:   begin if (cr_zf | (cr_nf & !cr_vf) | (!cr_nf & cr_vf)) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
130
                        `TGE:   begin if ((cr_nf & cr_vf)|(!cr_nf & !cr_vf)) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
131
                        `TLT:   begin if ((cr_nf & !cr_vf)|(!cr_nf & cr_vf)) begin vector <= `TRAP_VECTOR; state <= TRAP; end else state <= IFETCH; end
132
                        `TVS:   begin if ( cr_vf) begin vector <= `TRAPV_VECTOR; state <= TRAP; end else state <= IFETCH; end
133
                        `TVC:   begin if (!cr_vf) begin vector <= `TRAPV_VECTOR; state <= TRAP; end else state <= IFETCH; end
134
                        endcase
135
                `SETcc: Rn <= ir[15:11];
136
                `PUSH:  state <= PUSH1;
137
                `POP:   state <= POP1;
138
                endcase
139
                if (isIllegalOpcode) begin
140
                        vector <= `ILLEGAL_INSN;
141
                        state <= TRAP;
142
                end
143
        end
144
 

powered by: WebSVN 2.1.0

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