Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 1 | /** |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 2 | * Functions for generating pseudo-random CCIX PER error sections. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame] | 3 | * |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 8 | #include <libcper/BaseTypes.h> |
| 9 | #include <libcper/generator/gen-utils.h> |
| 10 | #include <libcper/generator/sections/gen-section.h> |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 11 | |
Lawrence Tang | efe17e2 | 2022-08-08 09:16:23 +0100 | [diff] [blame] | 12 | //Generates a single pseudo-random CCIX PER error section, saving the resulting address to the given |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 13 | //location. Returns the size of the newly created section. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 14 | size_t generate_section_ccix_per(void **location, |
| 15 | GEN_VALID_BITS_TEST_TYPE validBitsType) |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 16 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 17 | //Create a random length for the CCIX PER log. |
| 18 | //The log attached here does not necessarily conform to the CCIX specification, and is simply random. |
| 19 | int log_len = (rand() % 5 + 1) * 32; |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 20 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 21 | //Create random bytes. |
| 22 | int size = 16 + log_len; |
| 23 | UINT8 *bytes = generate_random_bytes(size); |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 24 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 25 | //Set reserved areas to zero. |
| 26 | UINT32 *validation = (UINT32 *)(bytes + 4); |
| 27 | *validation &= 0x7; //Validation bits 3-63. |
| 28 | *(validation + 1) = 0; //Validation bits 3-63. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 29 | if (validBitsType == ALL_VALID) { |
| 30 | *validation = 0x7; |
| 31 | } else if (validBitsType == SOME_VALID) { |
| 32 | *validation = 0x5; |
| 33 | } |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 34 | *(bytes + 13) &= 0x1F; //CCIX port ID bits 5-7. |
| 35 | UINT16 *reserved = (UINT16 *)(bytes + 14); |
| 36 | *reserved = 0; //Reserved bytes 14-15. |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 37 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 38 | //Set expected values. |
| 39 | UINT32 *length = (UINT32 *)bytes; |
| 40 | *length = size; |
| 41 | |
| 42 | //Set return values, exit. |
| 43 | *location = bytes; |
| 44 | return size; |
| 45 | } |