1 |
2 |
jamieiles |
// Copyright Jamie Iles, 2017
|
2 |
|
|
//
|
3 |
|
|
// This file is part of s80x86.
|
4 |
|
|
//
|
5 |
|
|
// s80x86 is free software: you can redistribute it and/or modify
|
6 |
|
|
// it under the terms of the GNU General Public License as published by
|
7 |
|
|
// the Free Software Foundation, either version 3 of the License, or
|
8 |
|
|
// (at your option) any later version.
|
9 |
|
|
//
|
10 |
|
|
// s80x86 is distributed in the hope that it will be useful,
|
11 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
// GNU General Public License for more details.
|
14 |
|
|
//
|
15 |
|
|
// You should have received a copy of the GNU General Public License
|
16 |
|
|
// along with s80x86. If not, see .
|
17 |
|
|
|
18 |
|
|
module ALU(input logic [15:0] a,
|
19 |
|
|
input logic [15:0] b,
|
20 |
|
|
output logic [31:0] out,
|
21 |
|
|
input logic is_8_bit,
|
22 |
|
|
input logic [`MC_ALUOp_t_BITS-1:0] op,
|
23 |
|
|
input logic [15:0] flags_in,
|
24 |
|
|
output logic [15:0] flags_out,
|
25 |
|
|
input logic multibit_shift,
|
26 |
|
|
input logic [4:0] shift_count,
|
27 |
|
|
output logic busy);
|
28 |
|
|
|
29 |
|
|
always_comb begin
|
30 |
|
|
flags_out = flags_in;
|
31 |
|
|
out = 32'b0;
|
32 |
|
|
busy = 1'b0;
|
33 |
|
|
|
34 |
|
|
case (op)
|
35 |
|
|
ALUOp_SELA: out[15:0] = a;
|
36 |
|
|
ALUOp_SELB: out[15:0] = b;
|
37 |
|
|
ALUOp_ADD: do_add(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
38 |
|
|
ALUOp_ADC: do_adc(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
39 |
|
|
ALUOp_AND: do_and(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
40 |
|
|
ALUOp_XOR: do_xor(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
41 |
|
|
ALUOp_OR: do_or(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
42 |
|
|
ALUOp_BOUNDH: do_bound(a, b, flags_in, flags_out);
|
43 |
|
|
ALUOp_BOUNDL: do_bound(b, a, flags_in, flags_out);
|
44 |
|
|
ALUOp_SUB: do_sub(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
45 |
|
|
ALUOp_SUBREV: do_sub(out[15:0], is_8_bit, b, a, flags_in, flags_out);
|
46 |
|
|
ALUOp_SBB: do_sbb(out[15:0], is_8_bit, a, b, flags_in, flags_out);
|
47 |
|
|
ALUOp_SBBREV: do_sbb(out[15:0], is_8_bit, b, a, flags_in, flags_out);
|
48 |
|
|
ALUOp_ENTER_FRAME_TEMP_ADDR: do_enter_frame_temp_addr(out[15:0], a, b[4:0]);
|
49 |
|
|
ALUOp_GETFLAGS: out[15:0] = flags_in;
|
50 |
|
|
ALUOp_SETFLAGSA: flags_out = a;
|
51 |
|
|
ALUOp_SETFLAGSB: flags_out = b;
|
52 |
|
|
ALUOp_CMC: flags_out[CF_IDX] = ~flags_in[CF_IDX];
|
53 |
|
|
ALUOp_SHR: do_shr(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
54 |
|
|
multibit_shift);
|
55 |
|
|
ALUOp_SHL: do_shl(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
56 |
|
|
multibit_shift);
|
57 |
|
|
ALUOp_SAR: do_sar(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
58 |
|
|
multibit_shift);
|
59 |
|
|
ALUOp_ROR: do_ror(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
60 |
|
|
multibit_shift);
|
61 |
|
|
ALUOp_ROL: do_rol(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
62 |
|
|
multibit_shift);
|
63 |
|
|
ALUOp_RCL: do_rcl(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
64 |
|
|
multibit_shift);
|
65 |
|
|
ALUOp_RCR: do_rcr(out, is_8_bit, a, shift_count, flags_in, flags_out, busy,
|
66 |
|
|
multibit_shift);
|
67 |
|
|
ALUOp_NOT: do_not(out[15:0], a, flags_in, flags_out);
|
68 |
|
|
ALUOp_AAA: do_aaa(out[15:0], a, flags_in, flags_out);
|
69 |
|
|
ALUOp_AAS: do_aas(out[15:0], a, flags_in, flags_out);
|
70 |
|
|
ALUOp_DAA: do_daa(out[15:0], a, flags_in, flags_out);
|
71 |
|
|
ALUOp_DAS: do_das(out[15:0], a, flags_in, flags_out);
|
72 |
|
|
ALUOp_MUL: do_mul(out, is_8_bit, a, b, flags_in, flags_out, 1'b0);
|
73 |
|
|
ALUOp_IMUL: do_mul(out, is_8_bit, a, b, flags_in, flags_out, 1'b1);
|
74 |
|
|
ALUOp_EXTEND: do_extend(out[15:0], is_8_bit, a);
|
75 |
|
|
ALUOp_DIV: ; // Handled by Divider, shares the enumeration.
|
76 |
|
|
ALUOp_IDIV: ; // Handled by Divider, shares the enumeration.
|
77 |
|
|
ALUOp_NEXT: begin
|
78 |
|
|
if (flags_in[DF_IDX])
|
79 |
|
|
do_sub(out[15:0], 1'b0, a, b, flags_in, flags_out);
|
80 |
|
|
else
|
81 |
|
|
do_add(out[15:0], 1'b0, a, b, flags_in, flags_out);
|
82 |
|
|
end
|
83 |
|
|
// verilator coverage_off
|
84 |
|
|
default: begin
|
85 |
|
|
`ifdef verilator
|
86 |
|
|
invalid_opcode_assertion: assert(0) begin
|
87 |
|
|
$display("oops!");
|
88 |
|
|
end
|
89 |
|
|
`endif // verilator
|
90 |
|
|
end
|
91 |
|
|
// verilator coverage_on
|
92 |
|
|
endcase
|
93 |
|
|
end
|
94 |
|
|
|
95 |
|
|
endmodule
|