blob: 618f9b31fc02714623acb1073edebc64cfee58ed [file] [log] [blame]
Lawrence Tang02c801a2022-07-18 14:43:52 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CPER generic processor sections.
Lawrence Tang02c801a2022-07-18 14:43:52 +01003 *
4 * Author: Lawrence.Tang@arm.com
5 **/
6
7#include <stdlib.h>
8#include "../../edk/BaseTypes.h"
9#include "../gen-utils.h"
Lawrence Tang67cbed62022-07-18 16:44:51 +010010#include "gen-sections.h"
Lawrence Tang02c801a2022-07-18 14:43:52 +010011
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random generic processor section, saving the resulting address to the given
Lawrence Tang02c801a2022-07-18 14:43:52 +010013//location. Returns the size of the newly created section.
14size_t generate_section_generic(void** location)
15{
16 //Create random bytes.
17 size_t size = generate_random_section(location, 192);
18
19 //Set reserved locations to zero.
20 UINT8* start_byte = (UINT8*)*location;
21 *((UINT64*)start_byte) &= 0xFFF;
22 *(start_byte + 12) &= 0b111;
23 *((UINT16*)(start_byte + 14)) = 0x0;
24
Lawrence Tangaacf0e22022-07-20 13:28:52 +010025 //Ensure CPU brand string does not terminate early.
26 for (int i=0; i<128; i++)
27 {
28 UINT8* byte = start_byte + 24 + i;
29 if (*byte == 0x0)
30 *byte = rand() % 127 + 1;
31
32 //Null terminate last byte.
33 if (i == 127)
34 *byte = 0x0;
35 }
36
Lawrence Tang02c801a2022-07-18 14:43:52 +010037 return size;
38}