----------------------------------------------------------------
-- description of core                                       --
-- version v0.1                                               --
-- 9 november 1993                                            --
----------------------------------------------------------------

entity core is
    port (
    ad_n     : inout BIT_VECTOR(31 DOWNTO 0);   -- nad
    datain_n : in    BIT_VECTOR(31 DOWNTO 0);   -- ndatain
    dataout_n: out   BIT_VECTOR(31 DOWNTO 0);   -- ndataout
    it       : in    BIT_VECTOR(3 DOWNTO 0);    -- it
    scin     : in    BIT;                       -- scin
    scout    : out   BIT;                       -- scout
    test     : in    BIT;                       -- fonc
    reset    : in    BIT;                       -- reset
    frz      : in    BIT;                       -- gel
    byte     : out   BIT_VECTOR(3 downto 0);    -- byte
    rw       : out   BIT;                       -- rw
    rw_ctl   : out   BIT;                       -- rw_ctl
    nfrz_ctl : out   BIT;                       -- nfrz_ctl
    ck       : in    BIT;                       -- ckm
    vdd      : in    BIT;                       -- vdd
    vss      : in    BIT                        -- vss
    );
end core ;

architecture struct of core is

component dlxm_seq 
  PORT (
  ck 		: in BIT;  			-- ck
  frz 		: in BIT; 			-- frz
  rqs 		: in BIT;      			-- excp | reset | it
  reset		: in BIT;			-- external reset
  resnul 	: in BIT;      			-- resnul
  ir_opcod 	: in bit_vector(5 DOWNTO 0) ;  	-- ir_opcod
  ir_tvr 	: in BIT;      			-- ir_tvr
  ir_iar 	: in BIT;      			-- ir_iar
  ir_sr 	: in BIT;       		-- ir_sr
  vdd 		: in BIT; 			-- vdd
  vss 		: in BIT; 			-- vss
  scin          : in BIT;                       -- scin
  test          : in BIT;                       -- test
  ovr_en 	: out BIT;     			-- ovr_en
  ico_en 	: out BIT;     			-- ico_en
  ctlopx 	: out bit_vector(5 DOWNTO 0) ; 	-- ctlopx
  ctlopy 	: out bit_vector(4 DOWNTO 0) ; 	-- ctlopy
  ctlalu 	: out bit_vector(4 DOWNTO 0) ; 	-- ctlalu
  wenable 	: out bit_vector(8 DOWNTO 0) ; 	-- wenable
  ctlrw 	: out bit_vector(3 DOWNTO 0) ;  -- ctlrw
  scout  	: out BIT     			-- scout 
  );
end component ;
  
component dlxm_dpt

PORT(
        -- Power supply terminals.

    vdd : in    bit;
    vss : in    bit;

    -- Control connectors of registers PC, IAR, AD, IR, DT.
    -- Select the function mode (enable SCAN mode when set to one).

     pc_test  : in    bit;
     ad_test  : in    bit;
    tvr_test  : in    bit;
    iar_test  : in    bit;
     sr_test  : in    bit;
     ir_test  : in    bit;
     dt_test  : in    bit;

    -- Scan-Path connectors.

     pc_scin  : in    bit;
     ad_scin  : in    bit;
    tvr_scin  : in    bit;
    iar_scin  : in    bit;
     sr_scin  : in    bit;
     ir_scin  : in    bit;
     dt_scin  : in    bit;
     pc_scout : out bit;
     ad_scout : out bit;
    tvr_scout : out bit;
    iar_scout : out bit;
     sr_scout : out bit;
     ir_scout : out bit;
     dt_scout : out bit;

    -- Clock connectors.

     pc_ck    : in    bit;
     ad_ck    : in    bit;
    tvr_ck    : in    bit;
    iar_ck    : in    bit;
     sr_ck    : in    bit;
     ir_ck    : in    bit;
     dt_ck    : in    bit;

    -- Write enable, active only in normal mode.
    -- (enable writing when set to one)

     pc_wen   : in    bit;
     ad_wen   : in    bit;
    tvr_wen   : in    bit;
    iar_wen   : in    bit;
     sr_wen   : in    bit;
     ir_wen   : in    bit;
     dt_wen   : in    bit;

    -- Control connectors of the register file.

    rf_ck  : in    bit;  
    rf_wen : in    bit; 
    rf_aw  : in    bit_vector(4 downto 0); -- Write address.
    rf_ar  : in    bit_vector(4 downto 0); -- Read adress.

        -- Controls connectors of the SR block.

        sr_mx    : in    bit; -- Select what to write in SR[15:0].

        -- Flags to write in SR from the CTRL block.

        sr_mode  :   out bit;
        sr_mask  :   out bit; 
        sr_reset : in    bit;
        sr_iav   : in    bit; 
        sr_ico   : in    bit; 
        sr_dav   : in    bit; 
        sr_ovr   : in    bit; 
        sr_it0   : in    bit; 
        sr_it1   : in    bit; 
        sr_it2   : in    bit; 
        sr_it3   : in    bit; 

    -- Control connectors of X multiplexer.
    -- Select between CH , CB , C0 , R[i] , SR , TVR, IAR , AD , PC.

    opx_ts4 : in    bit; 
    opx_ts3 : in    bit; 
    opx_ts2 : in    bit; 
    opx_ts1 : in    bit; 
    opx_ts0 : in    bit; 
    opx_mx4 : in    bit; 
    opx_mx3 : in    bit; 
    opx_mx2 : in    bit; 
    opx_mx1 : in    bit; 

        -- Sign of X operand ( opx_out[31] )

    opx_sign :   out bit;

    -- Control connectors of Y multiplexer.
    -- Select between C16, C4, C0, I16, I18, I28, DT, AD, SRFLAGS.

    opy_ts4 : in    bit; 
    opy_ts3 : in    bit; 
    opy_ts2 : in    bit; 
    opy_ts1 : in    bit; 
    opy_mx4 : in    bit; 
    opy_mx3 : in    bit; 
    opy_mx2 : in    bit; 
    opy_mx1 : in    bit; 

        -- When one byte is read, tells which one in a word.

    opy_byte : in    bit; 
    opy_rb1  : in    bit; 
    opy_rb0  : in    bit; 

        -- Fields of the IR register.

    opy_codop :   out bit_vector( 5 downto 0); 
    opy_rs    :   out bit_vector( 4 downto 0); 
    opy_rdrt  :   out bit_vector( 4 downto 0); 
    opy_rd    :   out bit_vector( 4 downto 0); 

        -- Fields of the IR register.

    opy_tvr   :   out bit;                     
    opy_sr    :   out bit;                     
    opy_iar   :   out bit;                     

        -- Sign of Y operand ( opy_out[31] )

    opy_sign  :   out bit;

        -- Main data bus input, from the plot.

    data_in_n : in    bit_vector(31 downto 0);

    -- Control connectors of ALU multiplexer.

    alu_mx4i0  : in    bit;  
    alu_mx3i0  : in    bit;  
    alu_mx2i1  : in    bit;  
    alu_mx2i0  : in    bit;  
    alu_mx1i2  : in    bit; 
    alu_mx1i1  : in    bit;  
    alu_mx1i0  : in    bit;  
    alu_mx0i0  : in    bit;  

    -- Auxiliary ALU inputs/outputs.

    alu_byte   : in    bit;  
    alu_shrot  : in    bit;  
    alu_test_n : in    bit;  
    alu_c31_n  :   out bit;  
    alu_c30_n  :   out bit;  
    alu_nul    :   out bit;  
    alu_sign   :   out bit;  

        -- Main data bus output, to the plots.

    data_out_n :   out bit_vector(31 downto 0);

    -- Control connectors of ADROUT multiplexer.

    out_mx0i0 : in    bit; -- Select between AD and PC.

    -- Main adress bus output, to the plots.

    out_adr_n : out   bit_vector(31 downto 0)

    );

end component ;

component dlxm_sts

Port( ck        : in  bit ;                      -- external clock
      frz       : in  bit ;                      -- external freeze
      reset     : in  bit ;                      -- external reset connector
      test      : in  bit ;                      -- test mode

      ctlalu    : in  bit_vector(4 downto 0) ;
      opx_sign  : in  bit ;                      -- signes des operandes et
      opy_sign  : in  bit ;                      -- du resultat pour calcul
      alu_sign  : in  bit ;                      -- du resultat du test
      alu_nul   : in  bit ;                      -- demande

      alu_c31_n : in  bit ;                      -- carry 31 et carry 30 pour
      alu_c30_n : in  bit ;                      -- pour le calcul de ovr

      ovr_en    : in  bit ;                      -- write enable des registres
      ico_en    : in  bit ;

      rs        : in  bit_vector(4 downto 0);
      rd        : in  bit_vector(4 downto 0);
      rdrt      : in  bit_vector(4 downto 0);
      mxrs_rdrt : in  bit ;

      codop     : in  bit_vector(5 downto 0) ;

      wenable_in: in  bit_vector(8 downto 0) ;   
      ctlrw_in  : in  bit_vector(3 downto 0) ;

      sr_mode   : in  bit ;                      -- mode 0-user 1-superuser
      sr_mask   : in  bit ;                      -- masque d'interruption
      adr0      : in  bit ;
      adr1      : in  bit ;
      adr31     : in  bit ;

      intrqs    : in  bit_vector(3 downto 0) ;   -- interruptions externes

      scin      : in  bit ;

      alu_test  : out bit ;                      -- resultat du test demande

      redpnt    : out bit_vector(4 downto 0) ;
      wrtpnt    : out bit_vector(4 downto 0) ;

      wenable_out:out bit_vector(5 downto 0) ;   -- vers DP
      ctlrw_out : out bit_vector(3 downto 2) ;   -- vers DP

      sr_ovr    : out bit ;                      -- flags d'exceptions
      sr_dav    : out bit ;
      sr_iav    : out bit ;
      sr_ico    : out bit ;
      sr_it0    : out bit ;
      sr_it1    : out bit ;
      sr_it2    : out bit ;
      sr_it3    : out bit ;
      sr_reset  : out bit ;

      rqs       : out bit ;                      -- exception non masquable

      rw        : out bit ;                      -- ext read write
      rw_ctl    : out bit ;                      -- pour les plots input output
      nfrz_ctl  : out bit ;                      -- pour les plots output

      byte      : out bit_vector(3 downto 0) ;
      scout     : out bit ;

      zero      : out bit ;
      vdd       : in  bit ;
      vss       : in  bit ) ;

end component ;


signal seq_ovr_en    : bit ;
signal seq_ico_en    : bit ;
signal seq_ctlopx    : bit_vector (5 downto 0) ;
signal seq_ctlopy    : bit_vector (4 downto 0) ;
signal seq_ctlalu    : bit_vector (4 downto 0) ;
signal seq_wenable   : bit_vector (8 downto 0) ;
signal sts_wenable   : bit_vector (5 downto 0) ;
signal seq_ctlrw     : bit_vector (3 downto 0) ;
signal sts_ctlrw     : bit_vector (3 downto 2) ;
signal seq_scout     : bit ;
signal dp_sr_mask    : bit ;
signal dp_sr_mode    : bit ;
signal dp_opx_sign   : bit ;
signal dp_codop      : bit_vector (5 downto 0) ;
signal dp_rs         : bit_vector (4 downto 0) ;
signal dp_rdrt       : bit_vector (4 downto 0) ;
signal dp_rd         : bit_vector (4 downto 0) ;
signal dp_ir_tvr     : bit ;
signal dp_ir_iar     : bit ;
signal dp_ir_sr      : bit ;
signal dp_opy_sign   : bit ;
signal dp_alu_c31_n  : bit ;
signal dp_alu_c30_n  : bit ;
signal dp_alu_nul    : bit ;
signal dp_alu_sign   : bit ;
signal sts_alu_test  : bit ;
signal sts_redpnt    : bit_vector (4 downto 0) ;
signal sts_wrtpnt    : bit_vector (4 downto 0) ;
signal sts_sr_ovr    : bit ;
signal sts_sr_dav    : bit ;
signal sts_sr_iav    : bit ;
signal sts_sr_ico    : bit ;
signal sts_sr_it0    : bit ;
signal sts_sr_it1    : bit ;
signal sts_sr_it2    : bit ;
signal sts_sr_it3    : bit ;
signal sts_sr_reset  : bit ;
signal sts_rqs       : bit ;
signal dp_scout      : bit ;
signal pc_scout      : bit ;
signal ad_scout      : bit ;
signal tvr_scout     : bit ;
signal iar_scout     : bit ;
signal sr_scout      : bit ;
signal ir_scout      : bit ;
signal sts_zero      : bit ;

begin

seq: dlxm_seq 

port map (
           
	ck	 => ck,
        frz	 => frz,
	rqs	 => sts_rqs,
	reset    => reset,
	resnul	 => dp_alu_nul,                    
	ir_opcod => dp_codop,                    
	ir_tvr	 => dp_ir_tvr,                    
	ir_iar	 => dp_ir_iar,                    
	ir_sr	 => dp_ir_sr,                    
	vdd	 => vdd,                    
	vss	 => vss,                    
	scin	 => dp_scout,                    
	test	 => test,                    
        ovr_en	 => seq_ovr_en,                    
        ico_en 	 => seq_ico_en,                    
	ctlopx	 => seq_ctlopx,                    
	ctlopy	 => seq_ctlopy,                    
	ctlalu	 => seq_ctlalu,                    
        wenable	 => seq_wenable,                    
	ctlrw	 => seq_ctlrw,                    
	scout	 => seq_scout                    
      ) ;


dp : dlxm_dpt

port map (
	pc_test    => test,
	ad_test    => test,
	tvr_test   => test,
	iar_test   => test,
	sr_test    => test,
	ir_test    => test,
	dt_test    => test,
	pc_scin    => scin,
	ad_scin    => pc_scout,
	tvr_scin   => ad_scout,
	iar_scin   => tvr_scout,
	sr_scin    => iar_scout,
	ir_scin    => sr_scout,
	dt_scin    => ir_scout,
	pc_scout   => pc_scout,
	ad_scout   => ad_scout,
	tvr_scout  => tvr_scout,
	iar_scout  => iar_scout,
	sr_scout   => sr_scout,
	ir_scout   => ir_scout,
	dt_scout   => dp_scout,
	pc_ck      => ck,
	ad_ck      => ck,
	tvr_ck     => ck,
	iar_ck     => ck,
	sr_ck      => ck,
	ir_ck      => ck,
	dt_ck      => ck,
	pc_wen     => sts_wenable(0),
	ad_wen     => sts_wenable(1),
	tvr_wen    => sts_wenable(4),
	iar_wen    => sts_wenable(3),
	sr_wen     => sts_wenable(5),
	ir_wen     => sts_ctlrw(3),
	dt_wen     => sts_ctlrw(2),
	rf_ck      => ck,
	rf_wen     => sts_wenable(2),
	rf_aw      => sts_wrtpnt,
	rf_ar      => sts_redpnt,
	sr_mx      => seq_wenable(7),
	sr_mask    => dp_sr_mask,
	sr_mode    => dp_sr_mode,
	sr_reset   => sts_sr_reset,
	sr_iav     => sts_sr_iav,
	sr_ico     => sts_sr_ico,
	sr_dav     => sts_sr_dav,
	sr_ovr     => sts_sr_ovr,
	sr_it0     => sts_sr_it0,
	sr_it1     => sts_sr_it1,
	sr_it2     => sts_sr_it2,
	sr_it3     => sts_sr_it3,
	opx_ts4    => seq_ctlopx(5),
	opx_ts3    => seq_ctlopx(4),
	opx_ts2    => seq_ctlopx(3),
	opx_ts1    => seq_ctlopx(2),
	opx_ts0    => seq_ctlopx(1),
	opx_mx4    => seq_ctlopx(0),
	opx_mx3    => seq_ctlopx(0),
	opx_mx2    => seq_ctlopx(0),
	opx_mx1    => seq_ctlopx(0),
	opx_sign   => dp_opx_sign,
	opy_ts4    => seq_ctlopy(4),
	opy_ts3    => seq_ctlopy(3),
	opy_ts2    => seq_ctlopy(2),
	opy_ts1    => seq_ctlopy(1),
	opy_mx4    => seq_ctlopy(0),
	opy_mx3    => seq_ctlopy(0),
	opy_mx2    => seq_ctlopy(0),
	opy_mx1    => seq_ctlopy(0),
	opy_byte   => seq_ctlrw(1),
	opy_rb1    => ad_n(1),
	opy_rb0    => ad_n(0),
	opy_codop  => dp_codop,
	opy_rs     => dp_rs,
	opy_rdrt   => dp_rdrt,
	opy_rd     => dp_rd,
	opy_tvr    => dp_ir_tvr,
	opy_iar    => dp_ir_iar,
	opy_sr     => dp_ir_sr,
	opy_sign   => dp_opy_sign,
	data_in_n  => datain_n,
	alu_mx4i0  => seq_ctlalu(4),
	alu_mx3i0  => seq_ctlalu(3),
	alu_mx2i1  => seq_ctlalu(2),
	alu_mx2i0  => seq_ctlalu(2),
	alu_mx1i2  => seq_ctlalu(1),
	alu_mx1i1  => seq_ctlalu(1),
	alu_mx1i0  => seq_ctlalu(1),
	alu_mx0i0  => seq_ctlalu(0),
	alu_byte   => seq_ctlrw(1),
	alu_shrot  => sts_zero,
	alu_test_n => sts_alu_test,
	alu_c31_n  => dp_alu_c31_n,
	alu_c30_n  => dp_alu_c30_n,
	alu_nul    => dp_alu_nul,
	alu_sign   => dp_alu_sign,
	data_out_n => dataout_n,
	out_mx0i0  => seq_ctlrw(3),
	out_adr_n  => ad_n,
	vdd        => vdd,
	vss        => vss                       
    );

sts : dlxm_sts

port map (

      ck        => ck,
      frz       => frz,                       
      reset     => reset,                       
      test      => test,                       
      ctlalu    => seq_ctlalu,                       
      opx_sign  => dp_opx_sign,                       
      opy_sign  => dp_opy_sign,                       
      alu_sign  => dp_alu_sign,                       
      alu_nul   => dp_alu_nul,                       
      alu_c31_n => dp_alu_c31_n,                       
      alu_c30_n => dp_alu_c30_n,                       
      ovr_en    => seq_ovr_en,                       
      ico_en    => seq_ico_en,                       
      rs        => dp_rs,                       
      rd        => dp_rd,                       
      rdrt      => dp_rdrt,                       
      mxrs_rdrt => seq_ctlopx(0),                       
      codop     => dp_codop,                       
      wenable_in=> seq_wenable,
      ctlrw_in  => seq_ctlrw,                       
      sr_mode   => dp_sr_mode,                       
      sr_mask   => dp_sr_mask,                       
      adr0      => ad_n(0),                       
      adr1      => ad_n(1),                       
      adr31     => ad_n(31),                       
      intrqs    => it,                       
      scin      => seq_scout,                       
      alu_test  => sts_alu_test,                       
      redpnt    => sts_redpnt,                       
      wrtpnt    => sts_wrtpnt,                       
      wenable_out => sts_wenable,
      ctlrw_out => sts_ctlrw,
      sr_ovr    => sts_sr_ovr,                       
      sr_dav    => sts_sr_dav,                       
      sr_iav    => sts_sr_iav,                       
      sr_ico    => sts_sr_ico,                       
      sr_it0    => sts_sr_it0,                       
      sr_it1    => sts_sr_it1,                       
      sr_it2    => sts_sr_it2,                       
      sr_it3    => sts_sr_it3,                       
      sr_reset  => sts_sr_reset,                       
      rqs       => sts_rqs,                       
      byte      => byte,                       
      rw        => rw,                       
      rw_ctl    => rw_ctl,                       
      nfrz_ctl  => nfrz_ctl,                       
      scout     => scout,                       
      zero      => sts_zero,
      vdd       => vdd,                       
      vss       => vss 

      ) ; 

end struct ;
