blob: cecb3190b8ccd22ca17eb6dcb54959813fc0d4d5 [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.
Ed Tanousfedd4572024-07-12 13:56:00 -07003 *
Lawrence Tangde9707f2022-07-19 10:54:31 +01004 * 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 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.
John Chungf8fc7052024-05-03 20:05:29 +080014size_t generate_section_memory(void **location)
Lawrence Tangde9707f2022-07-19 10:54:31 +010015{
John Chungf8fc7052024-05-03 20:05:29 +080016 //Create random bytes.
17 int size = 80;
18 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010019
John Chungf8fc7052024-05-03 20:05:29 +080020 //Set reserved areas to zero.
21 UINT64 *validation = (UINT64 *)bytes;
22 *validation &= 0x2FFFFF; //Validation 22-63
23 *(bytes + 73) &= ~0x1C; //Extended bits 2-4
Lawrence Tangde9707f2022-07-19 10:54:31 +010024
John Chungf8fc7052024-05-03 20:05:29 +080025 //Fix values that could be above range.
26 *(bytes + 72) = rand() % 16; //Memory error type
Lawrence Tangde9707f2022-07-19 10:54:31 +010027
John Chungf8fc7052024-05-03 20:05:29 +080028 //Fix error status.
29 create_valid_error_section(bytes + 8);
30
31 //Set return values, exit.
32 *location = bytes;
33 return size;
Lawrence Tangde9707f2022-07-19 10:54:31 +010034}
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.
John Chungf8fc7052024-05-03 20:05:29 +080038size_t generate_section_memory2(void **location)
Lawrence Tangde9707f2022-07-19 10:54:31 +010039{
John Chungf8fc7052024-05-03 20:05:29 +080040 //Create random bytes.
41 int size = 96;
42 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010043
John Chungf8fc7052024-05-03 20:05:29 +080044 //Set reserved areas to zero.
45 UINT64 *validation = (UINT64 *)bytes;
46 *validation &= 0x2FFFFF; //Validation 22-63
47 *(bytes + 63) = 0; //Reserved byte 63
Lawrence Tangde9707f2022-07-19 10:54:31 +010048
John Chungf8fc7052024-05-03 20:05:29 +080049 //Fix values that could be above range.
50 *(bytes + 61) = rand() % 16; //Memory error type
51 *(bytes + 62) = rand() % 2; //Status
Lawrence Tangde9707f2022-07-19 10:54:31 +010052
John Chungf8fc7052024-05-03 20:05:29 +080053 //Fix error status.
54 create_valid_error_section(bytes + 8);
55
56 //Set return values, exit.
57 *location = bytes;
58 return size;
59}