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

Subversion Repositories mblite

[/] [mblite/] [trunk/] [hw/] [core/] [core_Pkg.vhd] - Blame information for rev 7

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

Line No. Rev Author Line
1 2 takar
----------------------------------------------------------------------------------------------
2
--
3
--      Input file         : core_Pkg.vhd
4
--      Design name        : core_Pkg
5
--      Author             : Tamar Kranenburg
6
--      Company            : Delft University of Technology
7
--                         : Faculty EEMCS, Department ME&CE
8
--                         : Systems and Circuits group
9
--
10
--      Description        : Package with components and type definitions for the interface
11
--                           of the components
12
--
13
--
14
----------------------------------------------------------------------------------------------
15
 
16
LIBRARY ieee;
17
USE ieee.std_logic_1164.ALL;
18
USE ieee.std_logic_unsigned.ALL;
19
 
20
LIBRARY mblite;
21
USE mblite.config_Pkg.ALL;
22
USE mblite.std_Pkg.ALL;
23
 
24
PACKAGE core_Pkg IS
25
 
26
----------------------------------------------------------------------------------------------
27
-- TYPES USED IN MB-LITE
28
----------------------------------------------------------------------------------------------
29
 
30
    TYPE alu_operation     IS (ALU_ADD, ALU_OR, ALU_AND, ALU_XOR, ALU_SHIFT, ALU_SEXT8, ALU_SEXT16, ALU_MUL, ALU_BS);
31
    TYPE src_type_a        IS (ALU_SRC_REGA, ALU_SRC_NOT_REGA, ALU_SRC_PC, ALU_SRC_ZERO);
32
    TYPE src_type_b        IS (ALU_SRC_REGB, ALU_SRC_NOT_REGB, ALU_SRC_IMM, ALU_SRC_NOT_IMM);
33
    TYPE carry_type        IS (CARRY_ZERO, CARRY_ONE, CARRY_ALU, CARRY_ARITH);
34
    TYPE carry_keep_type   IS (CARRY_NOT_KEEP, CARRY_KEEP);
35
    TYPE branch_condition  IS (NOP, BNC, BEQ, BNE, BLT, BLE, BGT, BGE);
36
    TYPE transfer_size     IS (WORD, HALFWORD, BYTE);
37
 
38
    TYPE ctrl_execution IS RECORD
39
        alu_op      : alu_operation;
40
        alu_src_a   : src_type_a;
41
        alu_src_b   : src_type_b;
42 6 takar
        operation   : std_logic;
43 2 takar
        carry       : carry_type;
44
        carry_keep  : carry_keep_type;
45
        branch_cond : branch_condition;
46 6 takar
        delay       : std_logic;
47 2 takar
    END RECORD;
48
 
49
    TYPE ctrl_memory IS RECORD
50 6 takar
        mem_write     : std_logic;
51
        mem_read      : std_logic;
52 2 takar
        transfer_size : transfer_size;
53
    END RECORD;
54
 
55
    TYPE ctrl_memory_writeback_type IS RECORD
56 6 takar
        mem_read      : std_logic;
57 2 takar
        transfer_size : transfer_size;
58
    END RECORD;
59
 
60
    TYPE forward_type IS RECORD
61 6 takar
        reg_d     : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
62
        reg_write : std_logic;
63 2 takar
    END RECORD;
64
 
65
    TYPE imem_in_type IS RECORD
66 6 takar
        dat_i : std_logic_vector(CFG_IMEM_WIDTH - 1 DOWNTO 0);
67 2 takar
    END RECORD;
68
 
69
    TYPE imem_out_type IS RECORD
70 6 takar
        adr_o : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
71
        ena_o : std_logic;
72 2 takar
    END RECORD;
73
 
74
    TYPE fetch_in_type IS RECORD
75 6 takar
        hazard : std_logic;
76
        branch : std_logic;
77
        branch_target : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
78 2 takar
    END RECORD;
79
 
80
    TYPE fetch_out_type IS RECORD
81 6 takar
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
82 2 takar
    END RECORD;
83
 
84
    TYPE gprf_out_type IS RECORD
85 6 takar
        dat_a_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
86
        dat_b_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
87
        dat_d_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
88 2 takar
    END RECORD;
89
 
90
    TYPE decode_in_type IS RECORD
91 6 takar
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
92
        instruction     : std_logic_vector(CFG_IMEM_WIDTH - 1 DOWNTO 0);
93 2 takar
        ctrl_wb         : forward_type;
94
        ctrl_mem_wb     : ctrl_memory_writeback_type;
95 6 takar
        mem_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
96
        alu_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
97
        interrupt       : std_logic;
98
        flush_id        : std_logic;
99 2 takar
    END RECORD;
100
 
101
    TYPE decode_out_type IS RECORD
102 6 takar
        reg_a           : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
103
        reg_b           : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
104
        imm             : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
105
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
106
        hazard          : std_logic;
107 2 takar
        ctrl_ex         : ctrl_execution;
108
        ctrl_mem        : ctrl_memory;
109
        ctrl_wb         : forward_type;
110 6 takar
        fwd_dec_result  : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
111 2 takar
        fwd_dec         : forward_type;
112
    END RECORD;
113
 
114
    TYPE gprf_in_type IS RECORD
115 6 takar
        adr_a_i : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
116
        adr_b_i : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
117
        adr_d_i : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
118
        dat_w_i : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
119
        adr_w_i : std_logic_vector(CFG_GPRF_SIZE - 1 DOWNTO 0);
120
        wre_i   : std_logic;
121 2 takar
    END RECORD;
122
 
123
    TYPE execute_out_type IS RECORD
124 6 takar
        alu_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
125
        dat_d           : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
126
        branch          : std_logic;
127
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
128
        flush_id        : std_logic;
129 2 takar
        ctrl_mem        : ctrl_memory;
130
        ctrl_wb         : forward_type;
131
    END RECORD;
132
 
133
    TYPE execute_in_type IS RECORD
134 6 takar
        reg_a           : std_logic_vector(CFG_GPRF_SIZE  - 1 DOWNTO 0);
135
        dat_a           : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
136
        reg_b           : std_logic_vector(CFG_GPRF_SIZE  - 1 DOWNTO 0);
137
        dat_b           : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
138
        dat_d           : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
139
        imm             : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
140
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
141 2 takar
        fwd_dec         : forward_type;
142 6 takar
        fwd_dec_result  : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
143 2 takar
        fwd_mem         : forward_type;
144
        ctrl_ex         : ctrl_execution;
145
        ctrl_mem        : ctrl_memory;
146
        ctrl_wb         : forward_type;
147
        ctrl_mem_wb     : ctrl_memory_writeback_type;
148 6 takar
        mem_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
149
        alu_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
150 2 takar
 
151
    END RECORD;
152
 
153
    TYPE mem_in_type IS RECORD
154 6 takar
        dat_d           : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
155
        alu_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
156
        mem_result      : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
157
        program_counter : std_logic_vector(CFG_IMEM_SIZE - 1 DOWNTO 0);
158
        branch          : std_logic;
159 2 takar
        ctrl_mem        : ctrl_memory;
160
        ctrl_wb         : forward_type;
161
    END RECORD;
162
 
163
    TYPE mem_out_type IS RECORD
164 6 takar
        alu_result  : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
165 2 takar
        ctrl_wb     : forward_type;
166
        ctrl_mem_wb : ctrl_memory_writeback_type;
167
    END RECORD;
168
 
169
    TYPE dmem_in_type IS RECORD
170 6 takar
        dat_i : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
171
        ena_i : std_logic;
172 2 takar
    END RECORD;
173
 
174
    TYPE dmem_out_type IS RECORD
175 6 takar
        dat_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
176
        adr_o : std_logic_vector(CFG_DMEM_SIZE - 1 DOWNTO 0);
177
        sel_o : std_logic_vector(3 DOWNTO 0);
178
        we_o  : std_logic;
179
        ena_o : std_logic;
180 2 takar
    END RECORD;
181
 
182
    TYPE dmem_in_array_type IS ARRAY(NATURAL RANGE <>) OF dmem_in_type;
183
    TYPE dmem_out_array_type IS ARRAY(NATURAL RANGE <>) OF dmem_out_type;
184
 
185
    -- WB-master inputs from the wb-slaves
186
    TYPE wb_mst_in_type IS RECORD
187 6 takar
        clk_i : std_logic;                      -- master clock input
188
        rst_i : std_logic;                      -- synchronous active high reset
189
        dat_i : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0); -- databus input
190
        ack_i : std_logic;                      -- buscycle acknowledge input
191
        int_i : std_logic;                      -- interrupt request input
192 2 takar
    END RECORD;
193
 
194
    -- WB-master outputs to the wb-slaves
195
    TYPE wb_mst_out_type IS RECORD
196 6 takar
        adr_o : std_logic_vector(CFG_DMEM_SIZE - 1 DOWNTO 0);  -- address bits
197
        dat_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0); -- databus output
198
        we_o  : std_logic;                      -- write enable output
199
        stb_o : std_logic;                      -- strobe signals
200
        sel_o : std_logic_vector(3 DOWNTO 0);   -- select output array
201
        cyc_o : std_logic;                      -- valid BUS cycle output
202 2 takar
    END RECORD;
203
 
204
    -- WB-slave inputs, from the WB-master
205
    TYPE wb_slv_in_type IS RECORD
206 6 takar
        clk_i : std_logic;                     -- master clock input
207
        rst_i : std_logic;                     -- synchronous active high reset
208
        adr_i : std_logic_vector(CFG_DMEM_SIZE - 1 DOWNTO 0); -- address bits
209
        dat_i : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0); -- Databus input
210
        we_i  : std_logic;                     -- Write enable input
211
        stb_i : std_logic;                     -- strobe signals / core select signal
212
        sel_i : std_logic_vector(3 DOWNTO 0);   -- select output array
213
        cyc_i : std_logic;                     -- valid BUS cycle input
214 2 takar
    END RECORD;
215
 
216
    -- WB-slave outputs to the WB-master
217
    TYPE wb_slv_out_type IS RECORD
218 6 takar
        dat_o : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0); -- Databus output
219
        ack_o : std_logic;                     -- Bus cycle acknowledge output
220
        int_o : std_logic;                     -- interrupt request output
221 2 takar
    END RECORD;
222
 
223
----------------------------------------------------------------------------------------------
224
-- COMPONENTS USED IN MB-LITE
225
----------------------------------------------------------------------------------------------
226
 
227
    COMPONENT core GENERIC
228
    (
229
        G_INTERRUPT  : boolean := CFG_INTERRUPT;
230
        G_USE_HW_MUL : boolean := CFG_USE_HW_MUL;
231
        G_USE_BARREL : boolean := CFG_USE_BARREL;
232
        G_DEBUG      : boolean := CFG_DEBUG
233
    );
234
    PORT
235
    (
236
        imem_o : OUT imem_out_type;
237
        dmem_o : OUT dmem_out_type;
238
        imem_i : IN imem_in_type;
239
        dmem_i : IN dmem_in_type;
240 6 takar
        int_i  : IN std_logic;
241
        rst_i  : IN std_logic;
242
        clk_i  : IN std_logic
243 2 takar
    );
244
    END COMPONENT;
245
 
246
    COMPONENT core_wb GENERIC
247
    (
248
        G_INTERRUPT  : boolean := CFG_INTERRUPT;
249
        G_USE_HW_MUL : boolean := CFG_USE_HW_MUL;
250
        G_USE_BARREL : boolean := CFG_USE_BARREL;
251
        G_DEBUG      : boolean := CFG_DEBUG
252
    );
253
    PORT
254
    (
255
        imem_o : OUT imem_out_type;
256
        wb_o   : OUT wb_mst_out_type;
257
        imem_i : IN imem_in_type;
258
        wb_i   : IN wb_mst_in_type
259
    );
260
    END COMPONENT;
261
 
262
    COMPONENT core_wb_adapter PORT
263
    (
264
        dmem_i : OUT dmem_in_type;
265
        wb_o   : OUT wb_mst_out_type;
266
        dmem_o : IN dmem_out_type;
267
        wb_i   : IN wb_mst_in_type
268
    );
269
    END COMPONENT;
270
 
271
    COMPONENT core_wb_async_adapter PORT
272
    (
273
        dmem_i : OUT dmem_in_type;
274
        wb_o   : OUT wb_mst_out_type;
275
        dmem_o : IN dmem_out_type;
276
        wb_i   : IN wb_mst_in_type
277
    );
278
    END COMPONENT;
279
 
280
    COMPONENT fetch PORT
281
    (
282
        fetch_o : OUT fetch_out_type;
283
        imem_o  : OUT imem_out_type;
284
        fetch_i : IN fetch_in_type;
285 6 takar
        rst_i   : IN std_logic;
286
        ena_i   : IN std_logic;
287
        clk_i   : IN std_logic
288 2 takar
    );
289
    END COMPONENT;
290
 
291
    COMPONENT decode GENERIC
292
    (
293
        G_INTERRUPT  : boolean := CFG_INTERRUPT;
294
        G_USE_HW_MUL : boolean := CFG_USE_HW_MUL;
295
        G_USE_BARREL : boolean := CFG_USE_BARREL;
296
        G_DEBUG      : boolean := CFG_DEBUG
297
    );
298
    PORT
299
    (
300
        decode_o : OUT decode_out_type;
301
        gprf_o   : OUT gprf_out_type;
302
        decode_i : IN decode_in_type;
303 6 takar
        ena_i    : IN std_logic;
304
        rst_i    : IN std_logic;
305
        clk_i    : IN std_logic
306 2 takar
    );
307
    END COMPONENT;
308
 
309
    COMPONENT gprf PORT
310
    (
311
        gprf_o : OUT gprf_out_type;
312
        gprf_i : IN gprf_in_type;
313 6 takar
        ena_i  : IN std_logic;
314
        clk_i  : IN std_logic
315 2 takar
    );
316
    END COMPONENT;
317
 
318
    COMPONENT execute GENERIC
319
    (
320
        G_USE_HW_MUL : boolean := CFG_USE_HW_MUL;
321
        G_USE_BARREL : boolean := CFG_USE_BARREL
322
    );
323
    PORT
324
    (
325
        exec_o : OUT execute_out_type;
326
        exec_i : IN execute_in_type;
327 6 takar
        ena_i  : IN std_logic;
328
        rst_i  : IN std_logic;
329
        clk_i  : IN std_logic
330 2 takar
    );
331
    END COMPONENT;
332
 
333
    COMPONENT mem PORT
334
    (
335
        mem_o  : OUT mem_out_type;
336
        dmem_o : OUT dmem_out_type;
337
        mem_i  : IN mem_in_type;
338 6 takar
        ena_i  : IN std_logic;
339
        rst_i  : IN std_logic;
340
        clk_i  : IN std_logic
341 2 takar
    );
342
    END COMPONENT;
343
 
344
    COMPONENT core_address_decoder GENERIC
345
    (
346
        G_NUM_SLAVES : positive := CFG_NUM_SLAVES
347
    );
348
    PORT
349
    (
350
        m_dmem_i : OUT dmem_in_type;
351
        s_dmem_o : OUT dmem_out_array_type;
352
        m_dmem_o : IN dmem_out_type;
353
        s_dmem_i : IN dmem_in_array_type;
354 6 takar
        clk_i    : IN std_logic
355 2 takar
    );
356
    END COMPONENT;
357
----------------------------------------------------------------------------------------------
358
-- FUNCTIONS USED IN MB-LITE
359
----------------------------------------------------------------------------------------------
360
 
361 6 takar
    FUNCTION select_register_data(reg_dat, reg, wb_dat : std_logic_vector; write : std_logic) RETURN std_logic_vector;
362
    FUNCTION forward_condition(reg_write : std_logic; reg_a, reg_d : std_logic_vector) RETURN std_logic;
363
    FUNCTION align_mem_load(data : std_logic_vector; size : transfer_size; address : std_logic_vector) RETURN std_logic_vector;
364
    FUNCTION align_mem_store(data : std_logic_vector; size : transfer_size) RETURN std_logic_vector;
365
    FUNCTION decode_mem_store(address : std_logic_vector(1 DOWNTO 0); size : transfer_size) RETURN std_logic_vector;
366 2 takar
 
367
END core_Pkg;
368
 
369
PACKAGE BODY core_Pkg IS
370
 
371
    -- This function select the register value:
372
    --      A) zero
373
    --      B) bypass value read from register file
374
    --      C) value from register file
375 6 takar
    FUNCTION select_register_data(reg_dat, reg, wb_dat : std_logic_vector; write : std_logic) RETURN std_logic_vector IS
376
        VARIABLE tmp : std_logic_vector(CFG_DMEM_WIDTH - 1 DOWNTO 0);
377 2 takar
    BEGIN
378
        IF CFG_REG_FORCE_ZERO = true AND is_zero(reg) = '1' THEN
379
            tmp := (OTHERS => '0');
380
        ELSIF CFG_REG_FWD_WB = true AND write = '1' THEN
381
            tmp := wb_dat;
382
        ELSE
383
            tmp := reg_dat;
384
        END IF;
385
        RETURN tmp;
386
    END select_register_data;
387
 
388
    -- This function checks if a forwarding condition is met. The condition is met of register A and D match
389
    -- and the signal needs to be written back to the register file.
390 6 takar
    FUNCTION forward_condition(reg_write : std_logic; reg_a, reg_d : std_logic_vector ) RETURN std_logic IS
391 2 takar
    BEGIN
392
        RETURN reg_write AND compare(reg_a, reg_d);
393
    END forward_condition;
394
 
395
    -- This function aligns the memory load operation. The load byte-order is defined here.
396 6 takar
    FUNCTION align_mem_load(data : std_logic_vector; size : transfer_size; address : std_logic_vector ) RETURN std_logic_vector IS
397 2 takar
    BEGIN
398
        IF CFG_BYTE_ORDER = false THEN
399
            -- Little endian decoding
400
            CASE size IS
401
                WHEN byte =>
402
                    CASE address(1 DOWNTO 0) IS
403
                        WHEN "00"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH/4 - 1 DOWNTO 0);
404
                        WHEN "01"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH/2 - 1 DOWNTO CFG_DMEM_WIDTH/4);
405
                        WHEN "10"   => RETURN "000000000000000000000000" & data(3*CFG_DMEM_WIDTH/4 - 1 DOWNTO CFG_DMEM_WIDTH/2);
406
                        WHEN "11"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH - 1 DOWNTO 3*CFG_DMEM_WIDTH/4);
407
                        WHEN OTHERS => RETURN "00000000000000000000000000000000";
408
                    END CASE;
409
                WHEN halfword =>
410
                    CASE address(1 DOWNTO 0) IS
411
                        WHEN "00"   => RETURN "0000000000000000" & data(CFG_DMEM_WIDTH/2 - 1 DOWNTO 0);
412
                        WHEN "10"   => RETURN "0000000000000000" & data(CFG_DMEM_WIDTH - 1 DOWNTO CFG_DMEM_WIDTH/2);
413
                        WHEN OTHERS => RETURN "00000000000000000000000000000000";
414
                    END CASE;
415
                WHEN OTHERS =>
416
                    RETURN data;
417
            END CASE;
418
        ELSE
419
            -- Big endian decoding
420
            CASE size IS
421
                WHEN byte =>
422
                    CASE address(1 DOWNTO 0) IS
423
                        WHEN "00"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH - 1 DOWNTO 3*CFG_DMEM_WIDTH/4);
424
                        WHEN "01"   => RETURN "000000000000000000000000" & data(3*CFG_DMEM_WIDTH/4 - 1 DOWNTO CFG_DMEM_WIDTH/2);
425
                        WHEN "10"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH/2 - 1 DOWNTO CFG_DMEM_WIDTH/4);
426
                        WHEN "11"   => RETURN "000000000000000000000000" & data(CFG_DMEM_WIDTH/4 - 1 DOWNTO 0);
427
                        WHEN OTHERS => RETURN "00000000000000000000000000000000";
428
                    END CASE;
429
                WHEN halfword =>
430
                    CASE address(1 DOWNTO 0) IS
431
                        WHEN "00"   => RETURN "0000000000000000" & data(CFG_DMEM_WIDTH - 1 DOWNTO CFG_DMEM_WIDTH/2);
432
                        WHEN "10"   => RETURN "0000000000000000" & data(CFG_DMEM_WIDTH/2 - 1 DOWNTO 0);
433
                        WHEN OTHERS => RETURN "00000000000000000000000000000000";
434
                    END CASE;
435
                WHEN OTHERS =>
436
                    RETURN data;
437
            END CASE;
438
        END IF;
439
    END align_mem_load;
440
 
441
    -- This function repeats the operand to all positions memory store operation.
442 6 takar
    FUNCTION align_mem_store(data : std_logic_vector; size : transfer_size) RETURN std_logic_vector IS
443 2 takar
    BEGIN
444
        CASE size IS
445
            WHEN byte     => RETURN data( 7 DOWNTO 0) & data( 7 DOWNTO 0) & data(7 DOWNTO 0) & data(7 DOWNTO 0);
446
            WHEN halfword => RETURN data(15 DOWNTO 0) & data(15 DOWNTO 0);
447
            WHEN OTHERS   => RETURN data;
448
        END CASE;
449
    END align_mem_store;
450
 
451
    -- This function selects the correct bytes for memory writes. The store byte-order (MSB / LSB) can be defined here.
452 6 takar
    FUNCTION decode_mem_store(address : std_logic_vector(1 DOWNTO 0); size : transfer_size) RETURN std_logic_vector IS
453 2 takar
    BEGIN
454
        IF CFG_BYTE_ORDER = false THEN
455
            -- Little endian encoding
456
            CASE size IS
457
                WHEN BYTE =>
458
                    CASE address IS
459
                        WHEN "00"   => RETURN "0001";
460
                        WHEN "01"   => RETURN "0010";
461
                        WHEN "10"   => RETURN "0100";
462
                        WHEN "11"   => RETURN "1000";
463
                        WHEN OTHERS => RETURN "0000";
464
                    END CASE;
465
                WHEN HALFWORD =>
466
                    CASE address IS
467
                        WHEN "00"   => RETURN "0011";
468
                        WHEN "10"   => RETURN "1100";
469
                        WHEN OTHERS => RETURN "0000";
470
                    END CASE;
471
                WHEN OTHERS =>
472
                    RETURN "1111";
473
            END CASE;
474
        ELSE
475
            -- Big endian encoding
476
            CASE size IS
477
                WHEN BYTE =>
478
                    CASE address IS
479
                        WHEN "00"   => RETURN "1000";
480
                        WHEN "01"   => RETURN "0100";
481
                        WHEN "10"   => RETURN "0010";
482
                        WHEN "11"   => RETURN "0001";
483
                        WHEN OTHERS => RETURN "0000";
484
                    END CASE;
485
                WHEN HALFWORD =>
486
                    CASE address IS
487
                        -- Big endian encoding
488
                        WHEN "10"   => RETURN "0011";
489
                        WHEN "00"   => RETURN "1100";
490
                        WHEN OTHERS => RETURN "0000";
491
                    END CASE;
492
                WHEN OTHERS =>
493
                    RETURN "1111";
494
            END CASE;
495
        END IF;
496
    END decode_mem_store;
497
 
498
END core_Pkg;

powered by: WebSVN 2.1.0

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