blob: 63621dac3042bfa25479794488ad479af46782bd [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CPER platform memory 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"
10#include "gen-sections.h"
11
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random platform memory 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.
14size_t generate_section_memory(void** location)
15{
16 //Create random bytes.
17 int size = 80;
18 UINT8* bytes = generate_random_bytes(size);
19
20 //Set reserved areas to zero.
21 UINT64* validation = (UINT64*)bytes;
22 *validation &= 0x2FFFFF; //Validation 22-63
23 *(bytes + 73) &= ~0b11100; //Extended bits 2-4
24
25 //Fix values that could be above range.
26 *(bytes + 72) = rand() % 16; //Memory error type
27
28 //Fix error status.
29 create_valid_error_section(bytes + 8);
30
31 //Set return values, exit.
32 *location = bytes;
33 return size;
34}
35
Lawrence Tangefe17e22022-08-08 09:16:23 +010036//Generates a single pseudo-random memory 2 error section, saving the resulting address to the given
Lawrence Tangde9707f2022-07-19 10:54:31 +010037//location. Returns the size of the newly created section.
38size_t generate_section_memory2(void** location)
39{
40 //Create random bytes.
41 int size = 96;
42 UINT8* bytes = generate_random_bytes(size);
43
44 //Set reserved areas to zero.
45 UINT64* validation = (UINT64*)bytes;
46 *validation &= 0x2FFFFF; //Validation 22-63
47 *(bytes + 63) = 0; //Reserved byte 63
48
49 //Fix values that could be above range.
50 *(bytes + 61) = rand() % 16; //Memory error type
51 *(bytes + 62) = rand() % 2; //Status
52
53 //Fix error status.
54 create_valid_error_section(bytes + 8);
55
56 //Set return values, exit.
57 *location = bytes;
58 return size;
59}