-- This -*- vhdl -*- file was generated from numeric_std-body.proto -- This -*- vhdl -*- file is part of GHDL. -- IEEE 1076.3 compliant numeric std package body. -- The implementation is based only on the specifications. -- Copyright (C) 2015 Tristan Gingold -- -- 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 2 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 . package body NUMERIC_STD is constant NO_WARNING : Boolean := False; constant null_unsigned : unsigned (0 downto 1) := (others => '0'); constant null_signed : signed (0 downto 1) := (others => '0'); subtype nat1 is natural range 0 to 1; type nat1_to_sl_type is array (nat1) of std_ulogic; constant nat1_to_01 : nat1_to_sl_type := (0 => '0', 1 => '1'); subtype sl_01 is std_ulogic range '0' to '1'; subtype sl_x01 is std_ulogic range 'X' to '1'; type carry_array is array (sl_01, sl_01, sl_01) of sl_01; constant compute_carry : carry_array := ('0' => ('0' => ('0' => '0', '1' => '0'), '1' => ('0' => '0', '1' => '1')), '1' => ('0' => ('0' => '0', '1' => '1'), '1' => ('0' => '1', '1' => '1'))); constant compute_sum : carry_array := ('0' => ('0' => ('0' => '0', '1' => '1'), '1' => ('0' => '1', '1' => '0')), '1' => ('0' => ('0' => '1', '1' => '0'), '1' => ('0' => '0', '1' => '1'))); type sl_to_x01_array is array (std_ulogic) of sl_x01; constant sl_to_x01 : sl_to_x01_array := ('0' | 'L' => '0', '1' | 'H' => '1', others => 'X'); type compare_type is (compare_unknown, compare_lt, compare_eq, compare_gt); -- Match. -- '-' matches with everything. -- '0'/'L' matches, '1'/'H' matches. type match_table_type is array (std_ulogic, std_ulogic) of boolean; constant match_table: match_table_type := ('0' | 'L' => ('0' | 'L' | '-' => true, others => false), '1' | 'H' => ('1' | 'H' | '-' => true, others => false), '-' => (others => true), others => ('-' => true, others => false)); function MAX (L, R : natural) return natural is begin if L > R then return L; else return R; end if; end MAX; function TO_INTEGER (ARG : UNSIGNED) return NATURAL is variable argn : UNSIGNED (ARG'Length -1 downto 0); variable res : natural := 0; begin if argn'length = 0 then assert NO_WARNING report "NUMERIC_STD.TO_INTEGER: null array detected, returning 0" severity warning; return 0; end if; argn := TO_01 (ARG, 'X'); if argn (0) = 'X' then assert NO_WARNING report "NUMERIC_STD.TO_INTEGER: non logical value detected, returning 0" severity warning; return 0; end if; for i in argn'range loop res := res + res; if argn (i) = '1' then res := res + 1; end if; end loop; return res; end TO_INTEGER; function TO_INTEGER (ARG : SIGNED) return INTEGER is variable argn : SIGNED (ARG'Length -1 downto 0); variable res : integer := 0; variable b : STD_ULOGIC; begin if argn'length = 0 then assert NO_WARNING report "NUMERIC_STD.TO_INTEGER: null array detected, returning 0" severity warning; return 0; end if; argn := TO_01 (ARG, 'X'); if argn (0) = 'X' then assert NO_WARNING report "NUMERIC_STD.TO_INTEGER: non logical value detected, returning 0" severity warning; return 0; end if; if argn (argn'left) = '1' then -- Negative value b := '0'; else b := '1'; end if; for i in argn'range loop res := res + res; if argn (i) = b then res := res + 1; end if; end loop; if b = '0' then -- Avoid overflow. res := -res - 1; end if; return res; end TO_INTEGER; function TO_01 (S : SIGNED; XMAP : STD_LOGIC := '0') return SIGNED is subtype res_type is SIGNED (S'Length - 1 downto 0); variable res : res_type; alias snorm: res_type is S; begin if S'length = 0 then assert NO_WARNING report "NUMERIC_STD.TO_01: null array detected" severity warning; return null_signed; else for i in res_type'range loop case snorm (i) is when '0' | 'L' => res (i) := '0'; when '1' | 'H' => res (i) := '1'; when others => assert NO_WARNING report "NUMERIC_STD.TO_01: non logical value detected" severity warning; res := (others => XMAP); exit; end case; end loop; end if; return res; end TO_01; function TO_01 (S : UNSIGNED; XMAP : STD_LOGIC := '0') return UNSIGNED is subtype res_type is UNSIGNED (S'Length - 1 downto 0); variable res : res_type; alias snorm: res_type is S; begin if S'length = 0 then assert NO_WARNING report "NUMERIC_STD.TO_01: null array detected" severity warning; return null_unsigned; else for i in res_type'range loop case snorm (i) is when '0' | 'L' => res (i) := '0'; when '1' | 'H' => res (i) := '1'; when others => assert NO_WARNING report "NUMERIC_STD.TO_01: non logical value detected" severity warning; res := (others => XMAP); exit; end case; end loop; end if; return res; end TO_01; function TO_UNSIGNED (ARG, SIZE : NATURAL) return UNSIGNED is variable res : UNSIGNED (SIZE - 1 downto 0); variable a : natural := arg; variable d : nat1; begin if size = 0 then return null_unsigned; end if; for i in res'reverse_range loop d := a rem 2; res (i) := nat1_to_01 (d); a := a / 2; end loop; if a /= 0 then assert NO_WARNING report "NUMERIC_STD.TO_UNSIGNED: vector is truncated" severity warning; end if; return res; end TO_UNSIGNED; function TO_SIGNED (ARG : INTEGER; SIZE : NATURAL) return SIGNED is variable res : SIGNED (SIZE - 1 downto 0); variable v : integer := arg; variable b0, b1 : std_ulogic; variable d : nat1; begin if size = 0 then return null_signed; end if; if arg < 0 then -- Use one complement to avoid overflow: -- -v = (not v) + 1 -- not v = -v - 1 -- not v = -(v + 1) v := -(arg + 1); b0 := '1'; b1 := '0'; else v := arg; b0 := '0'; b1 := '1'; end if; for i in res'reverse_range loop d := v rem 2; v := v / 2; if d = 0 then res (i) := b0; else res (i) := b1; end if; end loop; if v /= 0 or res (res'left) /= b0 then assert NO_WARNING report "NUMERIC_STD.TO_SIGNED: vector is truncated" severity warning; end if; return res; end TO_SIGNED; function std_match (l, r : std_ulogic) return boolean is begin return match_table (l, r); end std_match; function std_match (l, r : std_ulogic_vector) return boolean is alias la : std_ulogic_vector (l'length downto 1) is l; alias ra : std_ulogic_vector (r'length downto 1) is r; begin if la'left = 0 or ra'left = 0 then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: null argument, returning false" severity warning; return false; elsif la'left /= ra'left then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: args length mismatch, returning false" severity warning; return false; else for i in la'range loop if not match_table (la (i), ra (i)) then return false; end if; end loop; return true; end if; end std_match; function std_match (l, r : std_logic_vector) return boolean is alias la : std_logic_vector (l'length downto 1) is l; alias ra : std_logic_vector (r'length downto 1) is r; begin if la'left = 0 or ra'left = 0 then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: null argument, returning false" severity warning; return false; elsif la'left /= ra'left then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: args length mismatch, returning false" severity warning; return false; else for i in la'range loop if not match_table (la (i), ra (i)) then return false; end if; end loop; return true; end if; end std_match; function std_match (l, r : UNSIGNED) return boolean is alias la : UNSIGNED (l'length downto 1) is l; alias ra : UNSIGNED (r'length downto 1) is r; begin if la'left = 0 or ra'left = 0 then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: null argument, returning false" severity warning; return false; elsif la'left /= ra'left then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: args length mismatch, returning false" severity warning; return false; else for i in la'range loop if not match_table (la (i), ra (i)) then return false; end if; end loop; return true; end if; end std_match; function std_match (l, r : SIGNED) return boolean is alias la : SIGNED (l'length downto 1) is l; alias ra : SIGNED (r'length downto 1) is r; begin if la'left = 0 or ra'left = 0 then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: null argument, returning false" severity warning; return false; elsif la'left /= ra'left then assert NO_WARNING report "NUMERIC_STD.STD_MATCH: args length mismatch, returning false" severity warning; return false; else for i in la'range loop if not match_table (la (i), ra (i)) then return false; end if; end loop; return true; end if; end std_match; function "+" (l, r : UNSIGNED) return UNSIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is UNSIGNED (lft downto 0); alias la : UNSIGNED (l'length - 1 downto 0) is l; alias ra : UNSIGNED (r'length - 1 downto 0) is r; variable res : res_type; variable lb, rb, carry : sl_x01; begin if la'left < 0 or ra'left < 0 then return null_UNSIGNED; end if; carry := '0'; for i in 0 to lft loop if i > la'left then lb := '0'; else lb := sl_to_x01 (la (i)); end if; if i > ra'left then rb := '0'; else rb := sl_to_x01 (ra (i)); end if; if lb = 'X' or rb = 'X' then assert NO_WARNING report "NUMERIC_STD.""+"": non logical value detected" severity warning; res := (others => 'X'); exit; end if; res (i) := compute_sum (carry, rb, lb); carry := compute_carry (carry, rb, lb); end loop; return res; end "+"; function "+" (l, r : SIGNED) return SIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is SIGNED (lft downto 0); alias la : SIGNED (l'length - 1 downto 0) is l; alias ra : SIGNED (r'length - 1 downto 0) is r; variable res : res_type; variable lb, rb, carry : sl_x01; begin if la'left < 0 or ra'left < 0 then return null_SIGNED; end if; carry := '0'; for i in 0 to lft loop if i > la'left then lb := l (l'left); else lb := sl_to_x01 (la (i)); end if; if i > ra'left then rb := r (r'left); else rb := sl_to_x01 (ra (i)); end if; if lb = 'X' or rb = 'X' then assert NO_WARNING report "NUMERIC_STD.""+"": non logical value detected" severity warning; res := (others => 'X'); exit; end if; res (i) := compute_sum (carry, rb, lb); carry := compute_carry (carry, rb, lb); end loop; return res; end "+"; function "+" (l : UNSIGNED; r : NATURAL) return UNSIGNED is subtype res_type is UNSIGNED (l'l
/*
 * sh73a0 processor support - INTC hardware block
 *
 * Copyright (C) 2010  Magnus Damm
 *
 * 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; version 2 of the License.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/sh_intc.h>
#include <asm/hardware/gic.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>

enum {
	UNUSED = 0,

	/* interrupt sources INTCS */
	PINTCS_PINT1, PINTCS_PINT2,
	RTDMAC_0_DEI0, RTDMAC_0_DEI1, RTDMAC_0_DEI2, RTDMAC_0_DEI3,
	CEU, MFI, BBIF2, VPU, TSIF1, _3DG_SGX543, _2DDMAC_2DDM0,
	RTDMAC_1_DEI4, RTDMAC_1_DEI5, RTDMAC_1_DADERR,
	KEYSC_KEY, VINT, MSIOF,
	TMU0_TUNI00, TMU0_TUNI01, TMU0_TUNI02,
	CMT0, TSIF0, CMT2, LMB, MSUG, MSU_MSU, MSU_MSU2,
	CTI, RWDT0, ICB, PEP, ASA, JPU_JPEG, LCDC, LCRC,
	RTDMAC_2_DEI6, RTDMAC_2_DEI7, RTDMAC_2_DEI8, RTDMAC_2_DEI9,
	RTDMAC_3_DEI10, RTDMAC_3_DEI11,
	FRC, GCU, LCDC1, CSIRX,
	DSITX0_DSITX00, DSITX0_DSITX01,
	SPU2_SPU0, SPU2_SPU1, FSI,
	TMU1_TUNI10, TMU1_TUNI11, TMU1_TUNI12,
	TSIF2, CMT4, MFIS2, CPORTS2R, TSG, DMASCH1, SCUW,
	VIO60, VIO61, CEU21, CSI21, DSITX1_DSITX10, DSITX1_DSITX11,
	DISP, DSRV, EMUX2_EMUX20I, EMUX2_EMUX21I,
	MSTIF0_MST00I, MSTIF0_MST01I, MSTIF1_MST10I, MSTIF1_MST11I,
	SPUV,

	/* interrupt groups INTCS */
	RTDMAC_0, RTDMAC_1, RTDMAC_2, RTDMAC_3,
	DSITX0, SPU2, TMU1, MSU,
};

static struct intc_vect intcs_vectors[] = {
	INTCS_VECT(PINTCS_PINT1, 0x0600), INTCS_VECT(PINTCS_PINT2, 0x0620),
	INTCS_VECT(RTDMAC_0_DEI0, 0x0800), INTCS_VECT(RTDMAC_0_DEI1, 0x0820),
	INTCS_VECT(RTDMAC_0_DEI2, 0x0840), INTCS_VECT(RTDMAC_0_DEI3, 0x0860),
	INTCS_VECT(CEU, 0x0880), INTCS_VECT(MFI, 0x0900),
	INTCS_VECT(BBIF2, 0x0960), INTCS_VECT(VPU, 0x0980),
	INTCS_VECT(TSIF1, 0x09a0), INTCS_VECT(_3DG_SGX543, 0x09e0),
	INTCS_VECT(_2DDMAC_2DDM0, 0x0a00),
	INTCS_VECT(RTDMAC_1_DEI4, 0x0b80), INTCS_VECT(RTDMAC_1_DEI5, 0x0ba0),
	INTCS_VECT(RTDMAC_1_DADERR, 0x0bc0),
	INTCS_VECT(KEYSC_KEY, 0x0be0), INTCS_VECT(VINT, 0x0c80),
	INTCS_VECT(MSIOF, 0x0d20),
	INTCS_VECT(TMU0_TUNI00, 0x0e80), INTCS_VECT(TMU0_TUNI01, 0x0ea0),
	INTCS_VECT(TMU0_TUNI02, 0x0ec0),
	INTCS_VECT(CMT0, 0x0f00), INTCS_VECT(TSIF0, 0x0f20),
	INTCS_VECT(CMT2, 0x0f40), INTCS_VECT(LMB, 0x0f60),
	INTCS_VECT(MSUG, 0x0f80),
	INTCS_VECT(MSU_MSU, 0x0fa0), INTCS_VECT(MSU_MSU2, 0x0fc0),
	INTCS_VECT(CTI, 0x0400), INTCS_VECT(RWDT0, 0x0440),
	INTCS_VECT(ICB, 0x0480), INTCS_VECT(PEP, 0x04a0),
	INTCS_VECT(ASA, 0x04c0), INTCS_VECT(JPU_JPEG, 0x0560),
	INTCS_VECT(LCDC, 0x0580), INTCS_VECT(LCRC, 0x05a0),
	INTCS_VECT(RTDMAC_2_DEI6, 0x1300), INTCS_VECT(RTDMAC_2_DEI7, 0x1320),
	INTCS_VECT(RTDMAC_2_DEI8, 0x1340), INTCS_VECT(RTDMAC_2_DEI9, 0x1360),
	INTCS_VECT(RTDMAC_3_DEI10, 0x1380), INTCS_VECT(RTDMAC_3_DEI11, 0x13a0),
	INTCS_VECT(FRC, 0x1700), INTCS_VECT(GCU, 0x1760),
	INTCS_VECT(LCDC1, 0x1780), INTCS_VECT(CSIRX, 0x17a0),
	INTCS_VECT(DSITX0_DSITX00, 0x17c0), INTCS_VECT(DSITX0_DSITX01, 0x17e0),
	INTCS_VECT(SPU2_SPU0, 0x1800), INTCS_VECT(SPU2_SPU1, 0x1820),
	INTCS_VECT(FSI, 0x1840),
	INTCS_VECT(TMU1_TUNI10, 0x1900), INTCS_VECT(TMU1_TUNI11, 0x1920),
	INTCS_VECT(TMU1_TUNI12, 0x1940),
	INTCS_VECT(TSIF2, 0x1960), INTCS_VECT(CMT4, 0x1980),
	INTCS_VECT(MFIS2, 0x1a00), INTCS_VECT(CPORTS2R, 0x1a20),
	INTCS_VECT(TSG, 0x1ae0), INTCS_VECT(DMASCH1, 0x1b00),
	INTCS_VECT(SCUW, 0x1b40),
	INTCS_VECT(VIO60, 0x1b60), INTCS_VECT(VIO61, 0x1b80),
	INTCS_VECT(CEU21, 0x1ba0), INTCS_VECT(CSI21, 0x1be0),
	INTCS_VECT(DSITX1_DSITX10, 0x1c00), INTCS_VECT(DSITX1_DSITX11, 0x1c20),
	INTCS_VECT(DISP, 0x1c40), INTCS_VECT(DSRV, 0x1c60),
	INTCS_VECT(EMUX2_EMUX20I, 0x1c80), INTCS_VECT(EMUX2_EMUX21I, 0x1ca0),
	INTCS_VECT(MSTIF0_MST00I, 0x1cc0), INTCS_VECT(MSTIF0_MST01I, 0x1ce0),
	INTCS_VECT(MSTIF1_MST10I, 0x1d00), INTCS_VECT(MSTIF1_MST11I, 0x1d20),
	INTCS_VECT(SPUV, 0x2300),
};

static struct intc_group intcs_groups[] __initdata = {
	INTC_GROUP(RTDMAC_0, RTDMAC_0_DEI0, RTDMAC_0_DEI1,
		   RTDMAC_0_DEI2, RTDMAC_0_DEI3),
	INTC_GROUP(RTDMAC_1, RTDMAC_1_DEI4, RTDMAC_1_DEI5, RTDMAC_1_DADERR),
	INTC_GROUP(RTDMAC_2, RTDMAC_2_DEI6, RTDMAC_2_DEI7,
		   RTDMAC_2_DEI8, RTDMAC_2_DEI9),
	INTC_GROUP(RTDMAC_3, RTDMAC_3_DEI10, RTDMAC_3_DEI11),
	INTC_GROUP(TMU1, TMU1_TUNI12, TMU1_TUNI11, TMU1_TUNI10),
	INTC_GROUP(DSITX0, DSITX0_DSITX00, DSITX0_DSITX01),
	INTC_GROUP(SPU2, SPU2_SPU0, SPU2_SPU1),
	INTC_GROUP(MSU, MSU_MSU, MSU_MSU2),
};

static struct intc_mask_reg intcs_mask_registers[] = {
	{ 0xffd20184, 0xffd201c4, 8, /* IMR1SA / IMCR1SA */
	  { 0, 0, 0, CEU,
	    0, 0, 0, 0 } },
	{ 0xffd20188, 0xffd201c8, 8, /* IMR2SA / IMCR2SA */
	  { 0, 0, 0, VPU,
	    BBIF2, 0, 0, MFI } },
	{ 0xffd2018c, 0xffd201cc, 8, /* IMR3SA / IMCR3SA */
	  { 0, 0, 0, _2DDMAC_2DDM0,
	    0, ASA, PEP, ICB } },
	{ 0xffd20190, 0xffd201d0, 8, /* IMR4SA / IMCR4SA */
	  { 0, 0, 0, CTI,
	    JPU_JPEG, 0, LCRC, LCDC } },
	{ 0xffd20194, 0xffd201d4, 8, /* IMR5SA / IMCR5SA */
	  { KEYSC_KEY, RTDMAC_1_DADERR, RTDMAC_1_DEI5, RTDMAC_1_DEI4,
	    RTDMAC_0_DEI3, RTDMAC_0_DEI2, RTDMAC_0_DEI1, RTDMAC_0_DEI0 } },
	{ 0xffd20198, 0xffd201d8, 8, /* IMR6SA / IMCR6SA */
	  { 0, 0, MSIOF, 0,
	    _3DG_SGX543, 0, 0, 0 } },
	{ 0xffd2019c, 0xffd201dc, 8, /* IMR7SA / IMCR7SA */
	  { 0, TMU0_TUNI02, TMU0_TUNI01, TMU0_TUNI00,
	    0, 0, 0, 0 } },
	{ 0xffd201a0, 0xffd201e0, 8, /* IMR8SA / IMCR8SA */
	  { 0, 0, 0, 0,
	    0, MSU_MSU, MSU_MSU2, MSUG } },
	{ 0xffd201a4, 0xffd201e4, 8, /* IMR9SA / IMCR9SA */
	  { 0, RWDT0, CMT2, CMT0,
	    0, 0, 0, 0 } },
	{ 0xffd201ac, 0xffd201ec, 8, /* IMR11SA / IMCR11SA */
	  { 0, 0, 0, 0,
	    0, TSIF1, LMB, TSIF0 } },
	{ 0xffd201b0, 0xffd201f0, 8, /* IMR12SA / IMCR12SA */
	  { 0, 0, 0, 0,
	    0, 0, PINTCS_PINT2, PINTCS_PINT1 } },
	{ 0xffd50180, 0xffd501c0, 8, /* IMR0SA3 / IMCR0SA3 */
	  { RTDMAC_2_DEI6, RTDMAC_2_DEI7, RTDMAC_2_DEI8, RTDMAC_2_DEI9,
	    RTDMAC_3_DEI10, RTDMAC_3_DEI11, 0, 0 } },
	{ 0xffd50190, 0xffd501d0, 8, /* IMR4SA3 / IMCR4SA3 */
	  { FRC, 0, 0, GCU,
	    LCDC1, CSIRX, DSITX0_DSITX00, DSITX0_DSITX01 } },
	{ 0xffd50194, 0xffd501d4, 8, /* IMR5SA3 / IMCR5SA3 */
	  { SPU2_SPU0, SPU2_SPU1, FSI, 0,
	    0, 0, 0, 0 } },
	{ 0xffd50198, 0xffd501d8, 8, /* IMR6SA3 / IMCR6SA3 */
	  { TMU1_TUNI10, TMU1_TUNI11, TMU1_TUNI12, 0,
	    TSIF2, CMT4, 0, 0 } },
	{ 0xffd5019c, 0xffd501dc, 8, /* IMR7SA3 / IMCR7SA3 */
	  { MFIS2, CPORTS2R, 0, 0,
	    0, 0, 0, TSG } },
	{ 0xffd501a0, 0xffd501e0, 8, /* IMR8SA3 / IMCR8SA3 */
	  { DMASCH1, 0, SCUW, VIO60,
	    VIO61, CEU21, 0, CSI21 } },
	{ 0xffd501a4, 0xffd501e4, 8, /* IMR9SA3 / IMCR9SA3 */
	  { DSITX1_DSITX10, DSITX1_DSITX11, DISP, DSRV,
	    EMUX2_EMUX20I, EMUX2_EMUX21I, MSTIF0_MST00I, MSTIF0_MST01I } },
	{ 0xffd501a8, 0xffd501e8, 8, /* IMR10SA3 / IMCR10SA3 */
	  { MSTIF0_MST00I, MSTIF0_MST01I, 0, 0,
	    0, 0, 0, 0  } },
	{ 0xffd60180, 0xffd601c0, 8, /* IMR0SA4 / IMCR0SA4 */
	  { SPUV, 0, 0, 0,
	    0, 0, 0, 0  } },
};

/* Priority is needed for INTCA to receive the INTCS interrupt */
static struct intc_prio_reg intcs_prio_registers[] = {
	{ 0xffd20000, 0, 16, 4, /* IPRAS */ { CTI, 0, _2DDMAC_2DDM0, ICB } },
	{ 0xffd20004, 0, 16, 4, /* IPRBS */ { JPU_JPEG, LCDC, 0, LCRC } },
	{ 0xffd20008, 0, 16, 4, /* IPRCS */ { BBIF2, 0, 0, 0 } },
	{ 0xffd2000c, 0, 16, 4, /* IPRDS */ { PINTCS_PINT1, PINTCS_PINT2,
					      0, 0 } },
	{ 0xffd20010, 0, 16, 4, /* IPRES */ { RTDMAC_0, CEU, MFI, VPU } },
	{ 0xffd20014, 0, 16, 4, /* IPRFS */ { KEYSC_KEY, RTDMAC_1,
					      CMT2, CMT0 } },
	{ 0xffd20018, 0, 16, 4, /* IPRGS */ { TMU0_TUNI00, TMU0_TUNI01,
					      TMU0_TUNI02, TSIF1 } },
	{ 0xffd2001c, 0, 16, 4, /* IPRHS */ { VINT, 0, 0, 0 } },
	{ 0xffd20020, 0, 16, 4, /* IPRIS */ { 0, MSIOF, TSIF0, 0 } },
	{ 0xffd20024, 0, 16, 4, /* IPRJS */ { 0, _3DG_SGX543, MSUG, MSU } },
	{ 0xffd20028, 0, 16, 4, /* IPRKS */ { 0, ASA, LMB, PEP } },
	{ 0xffd20030, 0, 16, 4, /* IPRMS */ { 0, 0, 0, RWDT0 } },
	{ 0xffd50000, 0, 16, 4, /* IPRAS3 */ { RTDMAC_2, 0, 0, 0 } },
	{ 0xffd50004, 0, 16, 4, /* IPRBS3 */ { RTDMAC_3, 0, 0, 0 } },
	{ 0xffd50020, 0, 16, 4, /* IPRIS3 */ { FRC, 0, 0, 0 } },
	{ 0xffd50024, 0, 16, 4, /* IPRJS3 */ { LCDC1, CSIRX, DSITX0, 0 } },
	{ 0xffd50028, 0, 16, 4, /* IPRKS3 */ { SPU2, 0, FSI, 0 } },
	{ 0xffd50030, 0, 16, 4, /* IPRMS3 */ { TMU1, 0, 0, TSIF2 } },
	{ 0xffd50034, 0, 16, 4, /* IPRNS3 */ { CMT4, 0, 0, 0 } },
	{ 0xffd50038, 0, 16, 4, /* IPROS3 */ { MFIS2, CPORTS2R, 0, 0 } },
	{ 0xffd50040, 0, 16, 4, /* IPRQS3 */ { DMASCH1, 0, SCUW, VIO60 } },
	{ 0xffd50044, 0, 16, 4, /* IPRRS3 */ { VIO61, CEU21, 0, CSI21 } },
	{ 0xffd50048, 0, 16, 4, /* IPRSS3 */ { DSITX1_DSITX10, DSITX1_DSITX11,
					       DISP, DSRV } },
	{ 0xffd5004c, 0, 16, 4, /* IPRTS3 */ { EMUX2_EMUX20I, EMUX2_EMUX21I,
					       MSTIF0_MST00I, MSTIF0_MST01I } },
	{ 0xffd50050, 0, 16, 4, /* IPRUS3 */ { MSTIF1_MST10I, MSTIF1_MST11I,
					       0, 0 } },
	{ 0xffd60000, 0, 16, 4, /* IPRAS4 */ { SPUV, 0, 0, 0 } },
};

static struct resource intcs_resources[] __initdata = {
	[0] = {
		.start	= 0xffd20000,
		.end	= 0xffd201ff,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= 0xffd50000,
		.end	= 0xffd501ff,
		.flags	= IORESOURCE_MEM,
	},
	[2] = {
		.start	= 0xffd60000,
		.end	= 0xffd601ff,
		.flags	= IORESOURCE_MEM,
	}
};

static struct intc_desc intcs_desc __initdata = {
	.name = "sh73a0-intcs",
	.resource = intcs_resources,
	.num_resources = ARRAY_SIZE(intcs_resources),
	.hw = INTC_HW_DESC(intcs_vectors, intcs_groups, intcs_mask_registers,
			   intcs_prio_registers, NULL, NULL),
};

static struct irqaction sh73a0_intcs_cascade;

static irqreturn_t sh73a0_intcs_demux(int irq, void *dev_id)
{
	unsigned int evtcodeas = ioread32((void __iomem *)dev_id);

	generic_handle_irq(intcs_evt2irq(evtcodeas));

	return IRQ_HANDLED;
}

static int sh73a0_set_wake(struct irq_data *data, unsigned int on)
{
	return 0; /* always allow wakeup */
}

void __init sh73a0_init_irq(void)
{
	void __iomem *gic_dist_base = __io(0xf0001000);
	void __iomem *gic_cpu_base = __io(0xf0000100);
	void __iomem *intevtsa = ioremap_nocache(0xffd20100, PAGE_SIZE);

	gic_init(0, 29, gic_dist_base, gic_cpu_base);
	gic_arch_extn.irq_set_wake = sh73a0_set_wake;

	register_intc_controller(&intcs_desc);

	/* demux using INTEVTSA */
	sh73a0_intcs_cascade.name = "INTCS cascade";
	sh73a0_intcs_cascade.handler = sh73a0_intcs_demux;
	sh73a0_intcs_cascade.dev_id = intevtsa;
	setup_irq(gic_spi(50), &sh73a0_intcs_cascade);
}
as arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_UNSIGNED; end if; if count <= arg1'left then res (res'left downto count) := arg1 (arg1'left - count downto 0); end if; return res; end shift_left; function shift_right (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_UNSIGNED; end if; if count <= arg1'left then res (res'left - count downto 0) := arg1 (arg1'left downto count); end if; return res; end shift_right; function rotate_left (ARG : UNSIGNED; COUNT: natural) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_UNSIGNED; end if; cnt := count rem res'length; res (res'left downto cnt) := arg1 (res'left - cnt downto 0); res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); return res; end rotate_left; function rotate_right (ARG : UNSIGNED; COUNT: natural) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_UNSIGNED; end if; cnt := count rem res'length; res (res'left - cnt downto 0) := arg1 (res'left downto cnt); res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); return res; end rotate_right; function "sll" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_UNSIGNED; end if; if count >= 0 and count <= arg1'left then res (res'left downto count) := arg1 (arg1'left - count downto 0); elsif count < 0 and count >= -arg1'left then res (res'left + count downto 0) := arg1 (arg1'left downto -count); end if; return res; end "sll"; function "srl" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_UNSIGNED; end if; if count >= 0 and count <= arg1'left then res (res'left - count downto 0) := arg1 (arg1'left downto count); elsif count < 0 and count >= -arg1'left then res (res'left downto -count) := arg1 (arg1'left + count downto 0); end if; return res; end "srl"; function "rol" (ARG : UNSIGNED; COUNT: integer) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_UNSIGNED; end if; cnt := count mod res'length; res (res'left downto cnt) := arg1 (res'left - cnt downto 0); res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); return res; end "rol"; function "ror" (ARG : UNSIGNED; COUNT: integer) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_UNSIGNED; end if; cnt := count mod res'length; res (res'left - cnt downto 0) := arg1 (res'left downto cnt); res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); return res; end "ror"; function shift_left (ARG : SIGNED; COUNT: NATURAL) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_SIGNED; end if; if count <= arg1'left then res (res'left downto count) := arg1 (arg1'left - count downto 0); end if; return res; end shift_left; function shift_right (ARG : SIGNED; COUNT: NATURAL) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => arg1 (arg1'left)); begin if res'length = 0 then return null_SIGNED; end if; if count <= arg1'left then res (res'left - count downto 0) := arg1 (arg1'left downto count); end if; return res; end shift_right; function rotate_left (ARG : SIGNED; COUNT: natural) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_SIGNED; end if; cnt := count rem res'length; res (res'left downto cnt) := arg1 (res'left - cnt downto 0); res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); return res; end rotate_left; function rotate_right (ARG : SIGNED; COUNT: natural) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_SIGNED; end if; cnt := count rem res'length; res (res'left - cnt downto 0) := arg1 (res'left downto cnt); res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); return res; end rotate_right; function "sll" (ARG : SIGNED; COUNT: INTEGER) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_SIGNED; end if; if count >= 0 and count <= arg1'left then res (res'left downto count) := arg1 (arg1'left - count downto 0); elsif count < 0 and count >= -arg1'left then res (res'left + count downto 0) := arg1 (arg1'left downto -count); end if; return res; end "sll"; function "srl" (ARG : SIGNED; COUNT: INTEGER) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); begin if res'length = 0 then return null_SIGNED; end if; if count >= 0 and count <= arg1'left then res (res'left - count downto 0) := arg1 (arg1'left downto count); elsif count < 0 and count >= -arg1'left then res (res'left downto -count) := arg1 (arg1'left + count downto 0); end if; return res; end "srl"; function "rol" (ARG : SIGNED; COUNT: integer) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_SIGNED; end if; cnt := count mod res'length; res (res'left downto cnt) := arg1 (res'left - cnt downto 0); res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); return res; end "rol"; function "ror" (ARG : SIGNED; COUNT: integer) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; variable res : res_type := (others => '0'); variable cnt : natural; begin if res'length = 0 then return null_SIGNED; end if; cnt := count mod res'length; res (res'left - cnt downto 0) := arg1 (res'left downto cnt); res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); return res; end "ror"; end NUMERIC_STD;