blob: 1780af7cf5a319bc2d1346d59329fe9e1401996e [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CCIX PER error sections.
Lawrence Tangde9707f2022-07-19 10:54:31 +01003 *
4 * Author: Lawrence.Tang@arm.com
5 **/
6
7#include <stdlib.h>
8#include "../../edk/BaseTypes.h"
9#include "../gen-utils.h"
Lawrence Tang8f977452022-08-24 14:55:07 +010010#include "gen-section.h"
Lawrence Tangde9707f2022-07-19 10:54:31 +010011
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random CCIX PER error section, saving the resulting address to the given
Lawrence Tangde9707f2022-07-19 10:54:31 +010013//location. Returns the size of the newly created section.
John Chungf8fc7052024-05-03 20:05:29 +080014size_t generate_section_ccix_per(void **location)
Lawrence Tangde9707f2022-07-19 10:54:31 +010015{
John Chungf8fc7052024-05-03 20:05:29 +080016 //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;
Lawrence Tangde9707f2022-07-19 10:54:31 +010019
John Chungf8fc7052024-05-03 20:05:29 +080020 //Create random bytes.
21 int size = 16 + log_len;
22 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010023
John Chungf8fc7052024-05-03 20:05:29 +080024 //Set reserved areas to zero.
25 UINT32 *validation = (UINT32 *)(bytes + 4);
26 *validation &= 0x7; //Validation bits 3-63.
27 *(validation + 1) = 0; //Validation bits 3-63.
28 *(bytes + 13) &= 0x1F; //CCIX port ID bits 5-7.
29 UINT16 *reserved = (UINT16 *)(bytes + 14);
30 *reserved = 0; //Reserved bytes 14-15.
Lawrence Tangd34f2b12022-07-19 15:36:31 +010031
John Chungf8fc7052024-05-03 20:05:29 +080032 //Set expected values.
33 UINT32 *length = (UINT32 *)bytes;
34 *length = size;
35
36 //Set return values, exit.
37 *location = bytes;
38 return size;
39}