2023-02-13 16:49:17 +00:00
|
|
|
/* processor.v - implementation of most functions of the 9086 processor
|
|
|
|
|
|
|
|
This file is part of the 9086 project.
|
|
|
|
|
|
|
|
Copyright (c) 2023 Efthymios Kritikos
|
|
|
|
|
|
|
|
This program 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/>. */
|
|
|
|
|
2023-05-11 11:11:17 +00:00
|
|
|
`include "exec_state_def.v"
|
2023-02-11 14:43:53 +00:00
|
|
|
`include "alu_header.v"
|
2023-02-13 15:24:21 +00:00
|
|
|
`include "config.v"
|
2023-02-22 01:28:23 +00:00
|
|
|
`include "ucode_header.v"
|
2023-05-07 12:34:15 +00:00
|
|
|
`include "error_header.v"
|
2023-02-08 09:18:00 +00:00
|
|
|
|
2023-05-11 11:11:17 +00:00
|
|
|
`define PROC_STATE_BITS 3
|
|
|
|
`define PROC_RESET 3'b000
|
|
|
|
`define PROC_DE_STATE_ENTRY 3'b001
|
|
|
|
`define PROC_HALT 3'b011
|
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
//HALT: active high
|
|
|
|
//IOMEM: 1=IO 0=MEM
|
|
|
|
//BHE: active low
|
|
|
|
//write: active low
|
|
|
|
//read: active low
|
|
|
|
//reset: active low
|
|
|
|
|
2023-05-14 15:06:33 +00:00
|
|
|
module processor (
|
|
|
|
/* MISC */ input clock, input reset, output wire HALT,output [`ERROR_BITS-1:0] ERROR
|
|
|
|
/* MEMORY / IO */ ,output [19:0] external_address_bus, inout [15:0] external_data_bus,output read, output write,output BHE,output IOMEM
|
|
|
|
`ifdef CALCULATE_IPC
|
2023-05-27 22:35:00 +00:00
|
|
|
/* STATISTICS */ ,output wire new_instruction
|
2023-05-14 15:06:33 +00:00
|
|
|
`endif
|
|
|
|
`ifdef OTUPUT_JSON_STATISTICS
|
2023-05-21 01:59:53 +00:00
|
|
|
/* */ ,output wire [`L1_CACHE_SIZE-1:0] L1_SIZE_STAT, output wire VALID_INSTRUCTION_STAT, output wire jump_req_debug
|
2023-05-14 15:06:33 +00:00
|
|
|
`endif
|
|
|
|
);
|
2023-05-11 11:11:17 +00:00
|
|
|
|
2023-05-27 22:35:00 +00:00
|
|
|
|
2023-05-21 01:59:53 +00:00
|
|
|
`ifdef OTUPUT_JSON_STATISTICS
|
|
|
|
assign jump_req_debug=biu_jump_req;
|
|
|
|
`endif
|
|
|
|
|
2023-05-11 11:11:17 +00:00
|
|
|
/* If there is an error either from the decoder or execution unit set it to ERROR */
|
2023-05-11 15:28:10 +00:00
|
|
|
assign ERROR=(DE_ERROR!=`ERR_NO_ERROR)?DE_ERROR:(EXEC_ERROR!=`ERR_NO_ERROR)?EXEC_ERROR:`ERR_NO_ERROR;
|
2023-02-14 13:13:40 +00:00
|
|
|
|
2023-02-08 12:07:42 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
/*############ Execution Unit ################################################### */
|
|
|
|
|
|
|
|
wire [1:0] in_alu_sel1, in_alu_sel2;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign in_alu_sel1 = DE_OUTPUT[44:43];
|
|
|
|
assign in_alu_sel2 = DE_OUTPUT[46:45];
|
2023-05-11 11:11:17 +00:00
|
|
|
|
2023-05-27 22:35:00 +00:00
|
|
|
wire valid_exec_data, set_initial_values;
|
2023-05-11 11:11:17 +00:00
|
|
|
|
|
|
|
wire [`ERROR_BITS-1:0] EXEC_ERROR;
|
|
|
|
|
|
|
|
wire use_exec_reg_addr;
|
|
|
|
|
|
|
|
wire [3:0] EXEC_reg_read_port1_addr;
|
|
|
|
wire [15:0] ALU_O;
|
2023-05-27 22:35:00 +00:00
|
|
|
wire [7:0]EX2DE_FLAGS;
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [15:0] PARAM1_INIT, PARAM2_INIT;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign PARAM1_INIT = DE_OUTPUT[23:8];
|
|
|
|
assign PARAM2_INIT = DE_OUTPUT[39:24];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [2:0] IN_MOD,OUT_MOD;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign IN_MOD=DE_OUTPUT[2:0];
|
|
|
|
assign OUT_MOD=DE_OUTPUT[49:47];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [`ALU_OP_BITS-1:0] ALU_OP;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign ALU_OP = DE_OUTPUT[42:40];
|
|
|
|
|
|
|
|
wire [23:0] DE2EX_INSTRUCTION;
|
2023-05-11 11:11:17 +00:00
|
|
|
|
2023-05-17 10:05:20 +00:00
|
|
|
wire next_exec;
|
2023-05-11 11:11:17 +00:00
|
|
|
execute_unit execute_unit (
|
2023-05-27 22:35:00 +00:00
|
|
|
/* GENERAL */ clock, reset, Wbit, Sbit, opcode_size, DE2EX_INSTRUCTION[23:0] , valid_exec_data
|
2023-05-11 11:11:17 +00:00
|
|
|
/* */ ,IN_MOD, OUT_MOD,memio_address_select, ProgCount, RM, EXEC_ERROR, write
|
2023-05-17 10:05:20 +00:00
|
|
|
/* */ ,set_initial_values,next_exec
|
2023-05-11 11:11:17 +00:00
|
|
|
/* PARAM */ ,PARAM1_INIT,PARAM2_INIT
|
2023-05-27 22:35:00 +00:00
|
|
|
/* STATE CONTROL */ ,next_state
|
2023-05-11 11:11:17 +00:00
|
|
|
/* ALU CONTROL */ ,in_alu_sel1, in_alu_sel2, ALU_OP, ALU_O
|
|
|
|
/* REGISTER DATA */ ,reg_read_port1_data, reg_read_port2_data, EXEC_reg_read_port1_addr, use_exec_reg_addr, reg_write_we
|
2023-05-27 22:35:00 +00:00
|
|
|
/* FLAGS */ ,EX2DE_FLAGS
|
2023-05-11 11:11:17 +00:00
|
|
|
/* BIU */ ,BIU_ADDRESS_INPUT, biu_write_request, biu_read_request, BIU_VALID_DATA, BIU_DATA, biu_data_direction, biu_jump_req
|
2023-05-11 15:28:10 +00:00
|
|
|
);
|
2023-05-11 11:11:17 +00:00
|
|
|
|
2023-05-07 12:34:15 +00:00
|
|
|
/*############ Bus Interface Unit ############################################### */
|
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire [15:0] INSTRUCTION_LOCATION, BIU_ADDRESS_INPUT;
|
2023-05-07 12:34:15 +00:00
|
|
|
wire [15:0] BIU_DATA;
|
2023-05-11 15:28:10 +00:00
|
|
|
wire [31:0] INSTRUCTION;
|
|
|
|
wire biu_write_request, biu_read_request, BIU_VALID_DATA;
|
|
|
|
wire biu_jump_req, biu_data_direction,VALID_INSTRUCTION;
|
2023-05-27 22:35:00 +00:00
|
|
|
wire VALID_INSTRUCTION_ACK;
|
2023-05-07 12:34:15 +00:00
|
|
|
|
|
|
|
BIU BIU(
|
2023-05-11 15:28:10 +00:00
|
|
|
/* Outside world */ clock,reset,external_address_bus
|
|
|
|
/* */ ,external_data_bus,read,write,BHE,IOMEM
|
|
|
|
/* Internal */ ,INSTRUCTION,VALID_INSTRUCTION,INSTRUCTION_LOCATION,biu_jump_req
|
|
|
|
/* */ ,BIU_ADDRESS_INPUT,BIU_DATA,biu_write_request,biu_read_request,Wbit,BIU_VALID_DATA,MEM_OR_IO
|
2023-05-27 22:35:00 +00:00
|
|
|
/* */ ,VALID_INSTRUCTION_ACK
|
2023-05-14 15:06:33 +00:00
|
|
|
`ifdef OTUPUT_JSON_STATISTICS
|
|
|
|
/* Statistics */ ,L1_SIZE_STAT, VALID_INSTRUCTION_STAT
|
|
|
|
`endif
|
2023-05-11 15:28:10 +00:00
|
|
|
);
|
2023-05-13 05:51:35 +00:00
|
|
|
|
2023-05-11 11:11:17 +00:00
|
|
|
assign BIU_DATA= biu_data_direction ? 16'hz : (memio_address_select ? reg_read_port1_data : ALU_O);
|
2023-05-07 12:34:15 +00:00
|
|
|
|
2023-02-22 01:28:23 +00:00
|
|
|
/*############ Decoder ########################################################## */
|
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [`EXEC_STATE_BITS+`ERROR_BITS+65:0] DE_OUTPUT;
|
2023-05-13 12:45:15 +00:00
|
|
|
|
2023-02-17 18:08:09 +00:00
|
|
|
decoder decoder(
|
2023-05-27 22:35:00 +00:00
|
|
|
/* GENERAL */ clock, reset,
|
|
|
|
/* INPUT FROM IF */ INSTRUCTION,VALID_INSTRUCTION,INSTRUCTION_LOCATION
|
|
|
|
/* INPUT FROM EX */ ,EX2DE_FLAGS[7:0],next_exec
|
|
|
|
/* OUTPUT TO EX */ ,DE_OUTPUT,DE2EX_INSTRUCTION
|
|
|
|
/* */ ,ProgCount,set_initial_values,valid_exec_data
|
|
|
|
/* OUTPUT TO IF */ ,VALID_INSTRUCTION_ACK
|
|
|
|
`ifdef CALCULATE_IPC
|
|
|
|
/* STATISTICS */ , new_instruction
|
|
|
|
`endif
|
2023-05-11 15:28:10 +00:00
|
|
|
);
|
2023-02-22 01:28:23 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire [2:0] RM;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign RM = DE_OUTPUT[5:3];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire memio_address_select;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign memio_address_select=DE_OUTPUT[6:6];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [3:0] DE_reg_read_port1_addr,DE_reg_read_port2_addr;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign DE_reg_read_port1_addr=DE_OUTPUT[53:50];
|
|
|
|
assign DE_reg_read_port2_addr=DE_OUTPUT[57:54];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [3:0] reg_write_addr;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign reg_write_addr=DE_OUTPUT[61:58];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire MEM_OR_IO;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign MEM_OR_IO = DE_OUTPUT[7:7];
|
2023-02-22 01:28:23 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire Wbit, Sbit, opcode_size;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign opcode_size=DE_OUTPUT[62:62];
|
|
|
|
assign Sbit=DE_OUTPUT[63:63];
|
|
|
|
assign Wbit=DE_OUTPUT[64:64];
|
2023-02-22 01:28:23 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire [`ERROR_BITS-1:0] DE_ERROR;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign HALT = DE_OUTPUT[65:65];
|
|
|
|
assign DE_ERROR = DE_OUTPUT[`ERROR_BITS+65:66];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
wire [`EXEC_STATE_BITS-1:0] next_state;
|
2023-05-27 22:35:00 +00:00
|
|
|
assign next_state=DE_OUTPUT[`EXEC_STATE_BITS+`ERROR_BITS+65:`ERROR_BITS+66];
|
2023-05-11 15:28:10 +00:00
|
|
|
|
|
|
|
/*############ Registers ######################################################## */
|
2023-02-17 18:08:09 +00:00
|
|
|
|
2023-05-27 22:35:00 +00:00
|
|
|
wire [15:0] ProgCount;
|
2023-02-12 01:05:39 +00:00
|
|
|
|
2023-05-11 11:11:17 +00:00
|
|
|
wire [3:0] reg_read_port1_addr;
|
2023-05-11 15:28:10 +00:00
|
|
|
assign reg_read_port1_addr = use_exec_reg_addr ? EXEC_reg_read_port1_addr : DE_reg_read_port1_addr;
|
2023-05-11 11:11:17 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire [15:0] reg_read_port1_data, reg_read_port2_data;
|
2023-03-03 06:29:06 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
wire reg_write_we;
|
2023-03-04 06:22:28 +00:00
|
|
|
|
2023-05-11 15:28:10 +00:00
|
|
|
register_file register_file(
|
|
|
|
/* WRITE */ .write_port1_addr(reg_write_addr),
|
|
|
|
/* */ .write_port1_data(ALU_O),
|
|
|
|
/* */ .write_port1_we(reg_write_we),
|
|
|
|
/* READ 1 */ .read_port1_addr(reg_read_port1_addr),
|
|
|
|
/* */ .read_port1_data(reg_read_port1_data),
|
|
|
|
/* READ 2 */ .read_port2_addr(DE_reg_read_port2_addr),
|
|
|
|
/* */ .read_port2_data(reg_read_port2_data)
|
|
|
|
);
|
2023-02-10 01:45:27 +00:00
|
|
|
|
2023-05-27 22:35:00 +00:00
|
|
|
/*############################################################################### */
|
|
|
|
|
2023-05-13 05:51:35 +00:00
|
|
|
|
2023-02-08 09:18:00 +00:00
|
|
|
endmodule
|