Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * Functions for generating psuedo-random CCIX PER error sections. |
| 3 | * |
| 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | #include "../../edk/BaseTypes.h" |
| 9 | #include "../gen-utils.h" |
| 10 | #include "gen-sections.h" |
| 11 | |
| 12 | //Generates a single psuedo-random CCIX PER error section, saving the resulting address to the given |
| 13 | //location. Returns the size of the newly created section. |
| 14 | size_t generate_section_ccix_per(void** location) |
| 15 | { |
| 16 | //Create a random length for the CCIX PER log. |
| 17 | //The log attached here does not necessarily conform to the CCIX specification, and is simply random. |
| 18 | int log_len = (rand() % 5 + 1) * 32; |
| 19 | |
| 20 | //Create random bytes. |
| 21 | int size = 16 + log_len; |
| 22 | UINT8* bytes = generate_random_bytes(size); |
| 23 | |
| 24 | //Set reserved areas to zero. |
| 25 | UINT64* validation = (UINT64*)(bytes + 4); |
| 26 | *validation &= 0b111; //Validation bits 3-63. |
| 27 | *(bytes + 13) &= 0b11111; //CCIX port ID bits 5-7. |
| 28 | UINT16* reserved = (UINT16*)(bytes + 14); |
| 29 | *reserved = 0; //Reserved bytes 14-15. |
| 30 | |
| 31 | //Set return values, exit. |
| 32 | *location = bytes; |
| 33 | return size; |
| 34 | } |