Add Bound checks in Decoder stage

This commit is contained in:
John Ring 2022-02-01 13:40:56 +01:00
parent 98e50e89a9
commit 84220120e5
3 changed files with 27 additions and 9 deletions

View File

@ -107,8 +107,10 @@ NAME DIRECTION CONNECTED
* GET_<NAME>_LENGTH
The first decode_stage is similar to a 4-byte primitive decode stage and latches the length of the
sequence into the <NAME>_len_latch. If the length is equal zero, the decode_stage of the next
declared member is taken, instead of the GET_<NAME>. A special <NAME>_cnt counter (used to
index the type specific memory) is initialized to 0.
declared member is taken, instead of the GET_<NAME>. If on the other hand, the length if greater
than the MAX sequence length specified in the type package, the length is set to the value of the
type package. A special <NAME>_cnt counter (used to index the type specific memory) is initialized to 0.
NOTE: It could be configured, that instead of truncating larger sequences, a decode error is triggered.
* GET_<NAME>
This stage is similar to the respective primitive decode_stage with following valiations:
The <NAME>_cnt is used to set the current <NAME>_mem_addr. On sucessful latch
@ -118,11 +120,11 @@ NAME DIRECTION CONNECTED
ARRAY
-----
Array is similar to the sequence, but has no length encoding (since it always has the smae size).
Array is similar to the sequence, but has no length encoding (since it always has the same size).
That means that there is no <NAME>_len port signal, <NAME>_len_latch latch, and also no
GET_<NAME>_LENGTH stage.
The initialization of the <NAME>_cnt has to be done in the previous decode_stage.
The <NAME>_cnt is compared against the fixed array length consatnt form the type package.
The <NAME>_cnt is compared against the fixed array length constant form the type package.
MAP
---
@ -133,7 +135,7 @@ struct <NAME>_Entry {
};
sequence<<NAME>_Entry> <NAME>;
For simplicity the name of the structure is ignored.
For simplicity the name of the <NAME>_Entry struct is ignored.
(I.e. the generated names are <NAME>_key, <NAME>_value instead of
<NAME>_<NAME>_Entry_key and <NAME>_<NAME>_Entry_value)

View File

@ -339,7 +339,11 @@ begin
stage_next <= SKIP_PAYLOAD;
else
decode_stage_next <= GET_TESTSEQUENCE_TESTARRAY;
if (tmp_length > TESTSEQUENCE_MAX_DEPTH) then
TestSequence_len_latch_next <= to_unsigned(TESTSEQUENCE_MAX_DEPTH, TestSequence_len_latch_next'length);
else
TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length);
end if;
TestSequence_cnt_next <= 0;
-- DES: For array types the _cnt has to be initialized in the previous member stage
TestSequence_TestArray_cnt_next <= 0;

View File

@ -684,7 +684,11 @@ begin
decode_stage_next <= GET_TESTMAP_LENGTH;
else
decode_stage_next <= GET_TESTSEQUENCE_TESTARRAY;
if (tmp_length > TESTSEQUENCE_MAX_DEPTH) then
TestSequence_len_latch_next <= to_unsigned(TESTSEQUENCE_MAX_DEPTH, TestSequence_len_latch_next'length);
else
TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length);
end if;
TestSequence_cnt_next <= 0;
-- DES: For array types the _cnt has to be initialized in the previous member stage
TestSequence_TestArray_cnt_next <= 0;
@ -872,8 +876,12 @@ begin
if (tmp_length = 0) then
-- Next Member
decode_stage_next <= GET_TESTENUM;
else
if (tmp_length > TESTMAP_MAX_DEPTH) then
TestMap_len_latch_next <= to_unsigned(TESTMAP_MAX_DEPTH, TestMap_len_latch_next'length);
else
TestMap_len_latch_next <= resize(tmp_length, TestMap_len_latch_next'length);
end if;
TestMap_cnt_next <= 0;
decode_stage_next <= GET_TESTMAP_KEY;
end if;
@ -1032,8 +1040,12 @@ begin
if (tmp_length = 0) then
-- DONE
stage_next <= SKIP_PAYLOAD;
else
if (tmp_length > TESTSTRING_MAX_DEPTH) then
TestString_len_latch_next <= to_unsigned(TESTSTRING_MAX_DEPTH, TestString_len_latch_next'length);
else
TestString_len_latch_next <= resize(tmp_length, TestString_len_latch_next'length);
end if;
TestString_cnt_next <= 0;
decode_stage_next <= GET_TESTSTRING;
end if;