blob: 866fe0c996ef3b82fb77bf54e047d183c487b71f [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>
Thu Nguyene42fb482024-10-15 14:43:11 +00008#include <libcper/BaseTypes.h>
9#include <libcper/generator/gen-utils.h>
10#include <libcper/generator/sections/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.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080014size_t generate_section_memory(void **location,
15 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangde9707f2022-07-19 10:54:31 +010016{
John Chungf8fc7052024-05-03 20:05:29 +080017 //Create random bytes.
18 int size = 80;
19 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010020
John Chungf8fc7052024-05-03 20:05:29 +080021 //Set reserved areas to zero.
22 UINT64 *validation = (UINT64 *)bytes;
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080023 //Validation 22-63 reserved. 19/20=0 for bank
24 *validation &= 0x27FFFF;
25 if (validBitsType == ALL_VALID) {
26 *validation = 0x27FFFF;
27 } else if (validBitsType == SOME_VALID) {
28 *validation = 0x275555;
29 }
30 *(bytes + 73) &= ~0x1C; //Extended bits 2-4
Lawrence Tangde9707f2022-07-19 10:54:31 +010031
John Chungf8fc7052024-05-03 20:05:29 +080032 //Fix values that could be above range.
Ed Tanous2d4d3b62025-03-11 10:34:29 -070033 *(bytes + 72) = cper_rand() % 16; //Memory error type
Lawrence Tangde9707f2022-07-19 10:54:31 +010034
John Chungf8fc7052024-05-03 20:05:29 +080035 //Fix error status.
36 create_valid_error_section(bytes + 8);
37
38 //Set return values, exit.
39 *location = bytes;
40 return size;
Lawrence Tangde9707f2022-07-19 10:54:31 +010041}
42
Lawrence Tangefe17e22022-08-08 09:16:23 +010043//Generates a single pseudo-random memory 2 error section, saving the resulting address to the given
Lawrence Tangde9707f2022-07-19 10:54:31 +010044//location. Returns the size of the newly created section.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080045size_t generate_section_memory2(void **location,
46 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangde9707f2022-07-19 10:54:31 +010047{
John Chungf8fc7052024-05-03 20:05:29 +080048 //Create random bytes.
49 int size = 96;
50 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010051
John Chungf8fc7052024-05-03 20:05:29 +080052 //Set reserved areas to zero.
53 UINT64 *validation = (UINT64 *)bytes;
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080054 //Validation 22-63, 20/21 is 0 since 6 is valid
55 *validation &= 0xFFFFF;
56 if (validBitsType == ALL_VALID) {
57 *validation = 0xFFFFF;
58 } else if (validBitsType == SOME_VALID) {
59 *validation = 0x55555;
60 }
61 *(bytes + 63) = 0; //Reserved byte 63
Lawrence Tangde9707f2022-07-19 10:54:31 +010062
John Chungf8fc7052024-05-03 20:05:29 +080063 //Fix values that could be above range.
Ed Tanous2d4d3b62025-03-11 10:34:29 -070064 *(bytes + 61) = cper_rand() % 16; //Memory error type
65 *(bytes + 62) = cper_rand() % 2; //Status
Lawrence Tangde9707f2022-07-19 10:54:31 +010066
John Chungf8fc7052024-05-03 20:05:29 +080067 //Fix error status.
68 create_valid_error_section(bytes + 8);
69
70 //Set return values, exit.
71 *location = bytes;
72 return size;
73}