Formatting .c/.h files and fix memory leakage issues
Signed-off-by: John Chung <john.chung@arm.com>
Change-Id: Id8328f412c2724992d80c0b3f895c8f85bc4ae68
diff --git a/generator/cper-generate-cli.c b/generator/cper-generate-cli.c
index f5b0c85..185702c 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -40,8 +40,9 @@
sections = malloc(sizeof(char *) * num_sections);
i++;
- for (int j = i; j < argc; j++)
+ for (int j = i; j < argc; j++) {
sections[j - i] = argv[j];
+ }
break;
} else {
printf("Unrecognised argument '%s'. For command information, refer to 'cper-generate --help'.\n",
@@ -53,6 +54,9 @@
//If no output file passed as argument, exit.
if (out_file == NULL) {
printf("No output file provided. For command information, refer to 'cper-generate --help'.\n");
+ if (sections) {
+ free(sections);
+ }
return -1;
}
@@ -61,6 +65,9 @@
if (cper_file == NULL) {
printf("Could not get a handle for output file '%s', file handle returned null.\n",
out_file);
+ if (sections) {
+ free(sections);
+ }
return -1;
}
@@ -72,13 +79,17 @@
} else {
//Invalid arguments.
printf("Invalid argument. Either both '--sections' and '--single-section' were set, or neither. For command information, refer to 'cper-generate --help'.\n");
+ if (sections) {
+ free(sections);
+ }
return -1;
}
//Close & free remaining resources.
fclose(cper_file);
- if (sections != NULL)
+ if (sections != NULL) {
free(sections);
+ }
}
//Prints command help for this CPER generator.
@@ -91,10 +102,10 @@
printf("\tWhen the '--single-section' flag is set, the next argument is the single section that should be generated, and\n");
printf("\ta single section (no header, only a section descriptor & section) CPER file is generated.\n\n");
printf("\tValid section type names are the following:\n");
- for (int i=0; i<generator_definitions_len; i++) {
+ for (size_t i = 0; i < generator_definitions_len; i++) {
printf("\t\t- %s\n", generator_definitions[i].ShortName);
}
printf("\t\t- unknown\n");
printf("\n:: --help\n");
printf("\tDisplays help information to the console.\n");
-}
\ No newline at end of file
+}
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index c8819f6..c14cbd3 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -57,18 +57,20 @@
header->TimeStamp.Seconds = int_to_bcd(rand() % 60);
//Turn all validation bits on.
- header->ValidationBits = 0b11;
+ header->ValidationBits = 0x3;
//Generate the section descriptors given the number of sections.
EFI_ERROR_SECTION_DESCRIPTOR *section_descriptors[num_sections];
- for (int i = 0; i < num_sections; i++)
+ for (int i = 0; i < num_sections; i++) {
section_descriptors[i] = generate_section_descriptor(
types[i], section_lengths, i, num_sections);
+ }
//Calculate total length of structure, set in header.
size_t total_len = sizeof(EFI_COMMON_ERROR_RECORD_HEADER);
- for (int i = 0; i < num_sections; i++)
+ for (int i = 0; i < num_sections; i++) {
total_len += section_lengths[i];
+ }
total_len += num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
header->RecordLength = (UINT32)total_len;
@@ -93,7 +95,7 @@
void generate_single_section_record(char *type, FILE *out)
{
//Generate a section.
- void *section;
+ void *section = NULL;
size_t section_len = generate_section(§ion, type);
//Generate a descriptor, correct the offset.
@@ -110,6 +112,7 @@
//Free remaining resources.
free(section_descriptor);
+ free(section);
}
//Generates a single section descriptor for a section with the given properties.
@@ -127,7 +130,7 @@
descriptor->SectionFlags &= 0xFF;
//Validation bits all set to 'on'.
- descriptor->SecValidMask = 0b11;
+ descriptor->SecValidMask = 0x3;
//Set severity.
descriptor->Severity = rand() % 4;
@@ -137,17 +140,20 @@
descriptor->SectionOffset =
sizeof(EFI_COMMON_ERROR_RECORD_HEADER) +
(num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- for (int i = 0; i < index; i++)
+ for (int i = 0; i < index; i++) {
descriptor->SectionOffset += lengths[i];
+ }
//Ensure the FRU text is not null terminated early.
for (int i = 0; i < 20; i++) {
- if (descriptor->FruString[i] == 0x0)
+ if (descriptor->FruString[i] == 0x0) {
descriptor->FruString[i] = rand() % 127 + 1;
+ }
//Null terminate last byte.
- if (i == 19)
+ if (i == 19) {
descriptor->FruString[i] = 0x0;
+ }
}
//If section type is not "unknown", set section type GUID based on type name.
@@ -156,7 +162,7 @@
section_guid_found = 1;
} else {
//Find the appropriate GUID for this section name.
- for (int i = 0; i < generator_definitions_len; i++) {
+ for (size_t i = 0; i < generator_definitions_len; i++) {
if (strcmp(type, generator_definitions[i].ShortName) ==
0) {
memcpy(&descriptor->SectionType,
@@ -192,7 +198,7 @@
section_generated = 1;
} else {
//Function defined section, switch on the type, generate accordingly.
- for (int i = 0; i < generator_definitions_len; i++) {
+ for (size_t i = 0; i < generator_definitions_len; i++) {
if (strcmp(type, generator_definitions[i].ShortName) ==
0) {
length = generator_definitions[i].Generate(
@@ -211,4 +217,4 @@
}
return length;
-}
\ No newline at end of file
+}
diff --git a/generator/cper-generate.h b/generator/cper-generate.h
index 2874fa5..edbac36 100644
--- a/generator/cper-generate.h
+++ b/generator/cper-generate.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include "../edk/BaseTypes.h"
-void generate_cper_record(char **types, UINT16 num_sections, FILE *cper_file);
+void generate_cper_record(char **types, UINT16 num_sections, FILE *out);
void generate_single_section_record(char *type, FILE *out);
-#endif
\ No newline at end of file
+#endif
diff --git a/generator/gen-utils.c b/generator/gen-utils.c
index c986b09..0fa0237 100644
--- a/generator/gen-utils.c
+++ b/generator/gen-utils.c
@@ -20,8 +20,9 @@
UINT8 *generate_random_bytes(size_t size)
{
UINT8 *bytes = malloc(size);
- for (size_t i = 0; i < size; i++)
+ for (size_t i = 0; i < size; i++) {
bytes[i] = rand();
+ }
return bytes;
}
@@ -31,7 +32,7 @@
{
//Fix reserved bits.
UINT64 *error_section = (UINT64 *)start;
- *error_section &= ~0xFF; //Reserved bits 0-7.
+ *error_section &= ~0xFF; //Reserved bits 0-7.
*error_section &= 0x7FFFFF; //Reserved bits 23-63
//Ensure error type has a valid value.
@@ -44,4 +45,4 @@
void init_random()
{
srand((unsigned int)time(NULL));
-}
\ No newline at end of file
+}
diff --git a/generator/gen-utils.h b/generator/gen-utils.h
index 4c9e30d..0ed28c2 100644
--- a/generator/gen-utils.h
+++ b/generator/gen-utils.h
@@ -5,12 +5,17 @@
#include "../edk/BaseTypes.h"
#include "../common-utils.h"
-#define CPER_ERROR_TYPES_KEYS (int []){1, 16, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}
+#define CPER_ERROR_TYPES_KEYS \
+ (int[]) \
+ { \
+ 1, 16, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, \
+ 26 \
+ }
-size_t generate_random_section(void** location, size_t size);
-UINT8* generate_random_bytes(size_t size);
+size_t generate_random_section(void **location, size_t size);
+UINT8 *generate_random_bytes(size_t size);
void init_random();
-void create_valid_error_section(UINT8* start);
+void create_valid_error_section(UINT8 *start);
UINT8 int_to_bcd(int value);
-#endif
\ No newline at end of file
+#endif
diff --git a/generator/sections/gen-section-arm.c b/generator/sections/gen-section-arm.c
index 7ec94a7..cdd71e1 100644
--- a/generator/sections/gen-section-arm.c
+++ b/generator/sections/gen-section-arm.c
@@ -11,174 +11,175 @@
#include "gen-section.h"
#define ARM_ERROR_INFO_SIZE 32
-void* generate_arm_error_info();
-size_t generate_arm_context_info(void** location);
+void *generate_arm_error_info();
+size_t generate_arm_context_info(void **location);
//Generates a single pseudo-random ARM processor section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_arm(void** location)
+size_t generate_section_arm(void **location)
{
- //Set up for generation of error/context structures.
- UINT16 error_structure_num = rand() % 4 + 1; //Must be at least 1.
- UINT16 context_structure_num = rand() % 3;
- void* error_structures[error_structure_num];
- void* context_structures[context_structure_num];
- size_t context_structure_lengths[context_structure_num];
+ //Set up for generation of error/context structures.
+ UINT16 error_structure_num = rand() % 4 + 1; //Must be at least 1.
+ UINT16 context_structure_num = rand() % 3 + 1;
+ void *error_structures[error_structure_num];
+ void *context_structures[context_structure_num];
+ size_t context_structure_lengths[context_structure_num];
- //Generate the structures.
- for (int i=0; i<error_structure_num; i++)
- error_structures[i] = generate_arm_error_info();
- for (int i=0; i<context_structure_num; i++)
- context_structure_lengths[i] = generate_arm_context_info(context_structures + i);
+ //Generate the structures.
+ for (int i = 0; i < error_structure_num; i++) {
+ error_structures[i] = generate_arm_error_info();
+ }
+ for (int i = 0; i < context_structure_num; i++) {
+ context_structure_lengths[i] =
+ generate_arm_context_info(context_structures + i);
+ }
- //Determine a random amount of vendor specific info.
- int vendor_info_len = rand() % 16;
+ //Determine a random amount of vendor specific info.
+ int vendor_info_len = rand() % 16;
- //Create the section as a whole.
- size_t total_len = 40 + (error_structure_num * ARM_ERROR_INFO_SIZE);
- for (int i=0; i<context_structure_num; i++)
- total_len += context_structure_lengths[i];
- total_len += vendor_info_len;
- UINT8* section = generate_random_bytes(total_len);
+ //Create the section as a whole.
+ size_t total_len = 40 + (error_structure_num * ARM_ERROR_INFO_SIZE);
+ for (int i = 0; i < context_structure_num; i++) {
+ total_len += context_structure_lengths[i];
+ }
+ total_len += vendor_info_len;
+ UINT8 *section = generate_random_bytes(total_len);
- //Set header information.
- UINT16* info_nums = (UINT16*)(section + 4);
- *info_nums = error_structure_num;
- *(info_nums + 1) = context_structure_num;
- UINT32* section_length = (UINT32*)(section + 8);
- *section_length = total_len;
-
- //Error affinity.
- *(section + 12) = rand() % 4;
+ //Set header information.
+ UINT16 *info_nums = (UINT16 *)(section + 4);
+ *info_nums = error_structure_num;
+ *(info_nums + 1) = context_structure_num;
+ UINT32 *section_length = (UINT32 *)(section + 8);
+ *section_length = total_len;
- //Reserved zero bytes.
- UINT64* validation = (UINT64*)section;
- *validation &= 0b111;
- UINT32* running_state = (UINT32*)(section + 32);
- *running_state &= 0b1;
- memset(section + 13, 0, 3);
+ //Error affinity.
+ *(section + 12) = rand() % 4;
- //Copy in the sections/context structures, free resources.
- UINT8* cur_pos = section + 40;
- for (int i=0; i<error_structure_num; i++)
- {
- memcpy(cur_pos, error_structures[i], ARM_ERROR_INFO_SIZE);
- free(error_structures[i]);
- cur_pos += ARM_ERROR_INFO_SIZE;
- }
- for (int i=0; i<context_structure_num; i++)
- {
- memcpy(cur_pos, context_structures[i], context_structure_lengths[i]);
- free(context_structures[i]);
- cur_pos += context_structure_lengths[i];
- }
+ //Reserved zero bytes.
+ UINT64 *validation = (UINT64 *)section;
+ *validation &= 0x7;
+ UINT32 *running_state = (UINT32 *)(section + 32);
+ *running_state &= 0x1;
+ memset(section + 13, 0, 3);
- //Set return values and exit.
- *location = section;
- return total_len;
+ //Copy in the sections/context structures, free resources.
+ UINT8 *cur_pos = section + 40;
+ for (int i = 0; i < error_structure_num; i++) {
+ memcpy(cur_pos, error_structures[i], ARM_ERROR_INFO_SIZE);
+ free(error_structures[i]);
+ cur_pos += ARM_ERROR_INFO_SIZE;
+ }
+ for (int i = 0; i < context_structure_num; i++) {
+ memcpy(cur_pos, context_structures[i],
+ context_structure_lengths[i]);
+ free(context_structures[i]);
+ cur_pos += context_structure_lengths[i];
+ }
+
+ //Set return values and exit.
+ *location = section;
+ return total_len;
}
//Generates a single pseudo-random ARM error info structure. Must be later freed.
-void* generate_arm_error_info()
+void *generate_arm_error_info()
{
- UINT8* error_info = generate_random_bytes(ARM_ERROR_INFO_SIZE);
+ UINT8 *error_info = generate_random_bytes(ARM_ERROR_INFO_SIZE);
- //Version (zero for revision of table referenced), length.
- *error_info = 0;
- *(error_info + 1) = ARM_ERROR_INFO_SIZE;
+ //Version (zero for revision of table referenced), length.
+ *error_info = 0;
+ *(error_info + 1) = ARM_ERROR_INFO_SIZE;
- //Type of error.
- UINT8 error_type = rand() % 4;
- *(error_info + 4) = error_type;
+ //Type of error.
+ UINT8 error_type = rand() % 4;
+ *(error_info + 4) = error_type;
- //Reserved bits for error information.
- UINT16* validation = (UINT16*)(error_info + 2);
- *validation &= 0x1F;
+ //Reserved bits for error information.
+ UINT16 *validation = (UINT16 *)(error_info + 2);
+ *validation &= 0x1F;
- //Make sure reserved bits are zero according with the type.
- UINT64* error_subinfo = (UINT64*)(error_info + 8);
- switch (error_type)
- {
- //Cache/TLB
- case 0:
- case 1:
- *error_subinfo &= 0xFFFFFFF;
- break;
+ //Make sure reserved bits are zero according with the type.
+ UINT64 *error_subinfo = (UINT64 *)(error_info + 8);
+ switch (error_type) {
+ //Cache/TLB
+ case 0:
+ case 1:
+ *error_subinfo &= 0xFFFFFFF;
+ break;
- //Bus
- case 2:
- *error_subinfo &= 0xFFFFFFFFFFF;
- break;
+ //Bus
+ case 2:
+ *error_subinfo &= 0xFFFFFFFFFFF;
+ break;
- //Microarch/other.
- default:
- break;
- }
+ //Microarch/other.
+ default:
+ break;
+ }
- return error_info;
+ return error_info;
}
//Generates a single pseudo-random ARM context info structure. Must be later freed.
-size_t generate_arm_context_info(void** location)
+size_t generate_arm_context_info(void **location)
{
- //Initial length is 8 bytes. Add extra based on type.
- UINT16 reg_type = rand() % 9;
- UINT32 reg_size = 0;
+ //Initial length is 8 bytes. Add extra based on type.
+ UINT16 reg_type = rand() % 9;
+ UINT32 reg_size = 0;
- //Set register size.
- switch (reg_type)
- {
- //AARCH32 GPR, AARCH32 EL2
- case 0:
- case 2:
- reg_size = 64;
- break;
+ //Set register size.
+ switch (reg_type) {
+ //AARCH32 GPR, AARCH32 EL2
+ case 0:
+ case 2:
+ reg_size = 64;
+ break;
- //AARCH32 EL1
- case 1:
- reg_size = 96;
- break;
+ //AARCH32 EL1
+ case 1:
+ reg_size = 96;
+ break;
- //AARCH32 EL3
- case 3:
- reg_size = 8;
- break;
+ //AARCH32 EL3
+ case 3:
+ reg_size = 8;
+ break;
- //AARCH64 GPR
- case 4:
- reg_size = 256;
- break;
+ //AARCH64 GPR
+ case 4:
+ reg_size = 256;
+ break;
- //AARCH64 EL1
- case 5:
- reg_size = 136;
- break;
-
- //AARCH64 EL2
- case 6:
- reg_size = 120;
- break;
+ //AARCH64 EL1
+ case 5:
+ reg_size = 136;
+ break;
- //AARCH64 EL3
- case 7:
- reg_size = 80;
- break;
+ //AARCH64 EL2
+ case 6:
+ reg_size = 120;
+ break;
- //Misc. single register.
- case 8:
- reg_size = 10;
- break;
- }
+ //AARCH64 EL3
+ case 7:
+ reg_size = 80;
+ break;
- //Create context structure randomly.
- int total_size = 8 + reg_size;
- UINT16* context_info = (UINT16*)generate_random_bytes(total_size);
+ //Misc. single register.
+ case 8:
+ reg_size = 10;
+ break;
+ }
- //Set header information.
- *(context_info + 1) = reg_type;
- *((UINT32*)(context_info + 2)) = reg_size;
+ //Create context structure randomly.
+ int total_size = 8 + reg_size;
+ UINT16 *context_info = (UINT16 *)generate_random_bytes(total_size);
- //Set return values and exit.
- *location = context_info;
- return total_size;
-}
\ No newline at end of file
+ //Set header information.
+ *(context_info + 1) = reg_type;
+ *((UINT32 *)(context_info + 2)) = reg_size;
+
+ //Set return values and exit.
+ *location = context_info;
+ return total_size;
+}
diff --git a/generator/sections/gen-section-ccix-per.c b/generator/sections/gen-section-ccix-per.c
index c820d72..1780af7 100644
--- a/generator/sections/gen-section-ccix-per.c
+++ b/generator/sections/gen-section-ccix-per.c
@@ -11,28 +11,29 @@
//Generates a single pseudo-random CCIX PER error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_ccix_per(void** location)
+size_t generate_section_ccix_per(void **location)
{
- //Create a random length for the CCIX PER log.
- //The log attached here does not necessarily conform to the CCIX specification, and is simply random.
- int log_len = (rand() % 5 + 1) * 32;
+ //Create a random length for the CCIX PER log.
+ //The log attached here does not necessarily conform to the CCIX specification, and is simply random.
+ int log_len = (rand() % 5 + 1) * 32;
- //Create random bytes.
- int size = 16 + log_len;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)(bytes + 4);
- *validation &= 0b111; //Validation bits 3-63.
- *(bytes + 13) &= 0b11111; //CCIX port ID bits 5-7.
- UINT16* reserved = (UINT16*)(bytes + 14);
- *reserved = 0; //Reserved bytes 14-15.
+ //Create random bytes.
+ int size = 16 + log_len;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set expected values.
- UINT32* length = (UINT32*)bytes;
- *length = size;
+ //Set reserved areas to zero.
+ UINT32 *validation = (UINT32 *)(bytes + 4);
+ *validation &= 0x7; //Validation bits 3-63.
+ *(validation + 1) = 0; //Validation bits 3-63.
+ *(bytes + 13) &= 0x1F; //CCIX port ID bits 5-7.
+ UINT16 *reserved = (UINT16 *)(bytes + 14);
+ *reserved = 0; //Reserved bytes 14-15.
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Set expected values.
+ UINT32 *length = (UINT32 *)bytes;
+ *length = size;
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-cxl-component.c b/generator/sections/gen-section-cxl-component.c
index 5fb6789..b13a1f5 100644
--- a/generator/sections/gen-section-cxl-component.c
+++ b/generator/sections/gen-section-cxl-component.c
@@ -11,28 +11,29 @@
//Generates a single pseudo-random CXL component error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_cxl_component(void** location)
+size_t generate_section_cxl_component(void **location)
{
- //Create a random length for the CXL component event log.
- //The logs attached here do not necessarily conform to the specification, and are simply random.
- int log_len = rand() % 64;
+ //Create a random length for the CXL component event log.
+ //The logs attached here do not necessarily conform to the specification, and are simply random.
+ int log_len = rand() % 64;
- //Create random bytes.
- int size = 32 + log_len;
- UINT8* bytes = generate_random_bytes(size);
+ //Create random bytes.
+ int size = 32 + log_len;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)(bytes + 4);
- *validation &= 0b111;
- UINT16* slot_number = (UINT16*)(bytes + 21);
- *slot_number &= ~0b111; //Device ID slot number bits 0-2.
- *(bytes + 23) = 0; //Device ID byte 11.
+ //Set reserved areas to zero.
+ UINT32 *validation = (UINT32 *)(bytes + 4);
+ *validation &= 0x7;
+ *(validation + 1) = 0;
+ UINT8 *slot_number = (UINT8 *)(bytes + 21);
+ *slot_number &= ~0x7; //Device ID slot number bits 0-2.
+ *(bytes + 23) = 0; //Device ID byte 11.
- //Set expected values.
- UINT32* length = (UINT32*)bytes;
- *length = size;
-
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Set expected values.
+ UINT32 *length = (UINT32 *)bytes;
+ *length = size;
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-cxl-protocol.c b/generator/sections/gen-section-cxl-protocol.c
index 71a1105..cd9d66d 100644
--- a/generator/sections/gen-section-cxl-protocol.c
+++ b/generator/sections/gen-section-cxl-protocol.c
@@ -11,54 +11,56 @@
//Generates a single pseudo-random CXL protocol error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_cxl_protocol(void** location)
+size_t generate_section_cxl_protocol(void **location)
{
- //Create a random length for the CXL DVSEC and CXL error log.
- //The logs attached here do not necessarily conform to the specification, and are simply random.
- int dvsec_len = rand() % 64;
- int error_log_len = rand() % 64;
+ //Create a random length for the CXL DVSEC and CXL error log.
+ //The logs attached here do not necessarily conform to the specification, and are simply random.
+ int dvsec_len = rand() % 64;
+ int error_log_len = rand() % 64;
- //Create random bytes.
- int size = 116 + dvsec_len + error_log_len;
- UINT8* bytes = generate_random_bytes(size);
+ //Create random bytes.
+ int size = 116 + dvsec_len + error_log_len;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set CXL agent type.
- int cxl_agent_type = rand() % 2;
- *(bytes + 8) = cxl_agent_type;
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0b111111; //Validation bits 6-63.
- for (int i=0; i<7; i++)
- *(bytes + 9 + i) = 0; //Reserved bytes 9-15.
+ //Set CXL agent type.
+ int cxl_agent_type = rand() % 2;
+ *(bytes + 8) = cxl_agent_type;
- //We only reserve bytes if it's a CXL 1.1 device, and not a host downstream port.
- if (cxl_agent_type == 0)
- {
- for (int i=0; i<3; i++)
- *(bytes + 21 + i) = 0; //CXL agent address bytes 5-7.
- }
-
- *(bytes + 34) &= ~0b111; //Device ID byte 10 bits 0-2.
- UINT32* reserved = (UINT32*)(bytes + 36);
- *reserved = 0; //Device ID bytes 12-15.
- reserved = (UINT32*)(bytes + 112);
- *reserved = 0; //Reserved bytes 112-115.
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x3F; //Validation bits 6-63.
+ for (int i = 0; i < 7; i++) {
+ *(bytes + 9 + i) = 0; //Reserved bytes 9-15.
+ }
- //If the device is a host downstream port, serial/capability structure is invalid.
- if (cxl_agent_type != 0)
- {
- for (int i=0; i<68; i++)
- *(bytes + 40 + i) = 0; //Device serial & capability structure.
- }
+ //We only reserve bytes if it's a CXL 1.1 device, and not a host downstream port.
+ if (cxl_agent_type == 0) {
+ for (int i = 0; i < 3; i++) {
+ *(bytes + 21 + i) = 0; //CXL agent address bytes 5-7.
+ }
+ }
- //Set expected values.
- UINT16* dvsec_length_field = (UINT16*)(bytes + 108);
- UINT16* error_log_len_field = (UINT16*)(bytes + 110);
- *dvsec_length_field = dvsec_len;
- *error_log_len_field = error_log_len;
+ *(bytes + 34) &= ~0x7; //Device ID byte 10 bits 0-2.
+ UINT32 *reserved = (UINT32 *)(bytes + 36);
+ *reserved = 0; //Device ID bytes 12-15.
+ reserved = (UINT32 *)(bytes + 112);
+ *reserved = 0; //Reserved bytes 112-115.
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //If the device is a host downstream port, serial/capability structure is invalid.
+ if (cxl_agent_type != 0) {
+ for (int i = 0; i < 68; i++) {
+ *(bytes + 40 + i) =
+ 0; //Device serial & capability structure.
+ }
+ }
+
+ //Set expected values.
+ UINT16 *dvsec_length_field = (UINT16 *)(bytes + 108);
+ UINT16 *error_log_len_field = (UINT16 *)(bytes + 110);
+ *dvsec_length_field = dvsec_len;
+ *error_log_len_field = error_log_len;
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-dmar.c b/generator/sections/gen-section-dmar.c
index 66cc70a..6e405c8 100644
--- a/generator/sections/gen-section-dmar.c
+++ b/generator/sections/gen-section-dmar.c
@@ -11,68 +11,71 @@
//Generates a single pseudo-random generic DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_generic(void** location)
+size_t generate_section_dmar_generic(void **location)
{
- //Create random bytes.
- int size = 32;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* reserved = (UINT64*)(bytes + 16);
- *reserved = 0;
- *(reserved + 1) = 0;
+ //Create random bytes.
+ int size = 32;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set expected values.
- *(bytes + 4) = rand() % 0xC; //Fault reason.
- *(bytes + 5) = rand() % 2; //Access type.
- *(bytes + 6) = rand() % 2; //Address type.
- *(bytes + 7) = rand() % 2 + 1; //Architecture type.
+ //Set reserved areas to zero.
+ UINT64 *reserved = (UINT64 *)(bytes + 16);
+ *reserved = 0;
+ *(reserved + 1) = 0;
- //Set return values, exit.
- *location = bytes;
- return size;
+ //Set expected values.
+ *(bytes + 4) = rand() % 0xC; //Fault reason.
+ *(bytes + 5) = rand() % 2; //Access type.
+ *(bytes + 6) = rand() % 2; //Address type.
+ *(bytes + 7) = rand() % 2 + 1; //Architecture type.
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
}
//Generates a single pseudo-random VT-d DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_vtd(void** location)
+size_t generate_section_dmar_vtd(void **location)
{
- //Create random bytes.
- int size = 144;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- for (int i=0; i<12; i++)
- *(bytes + 36 + i) = 0; //Reserved bytes 36-47.
- UINT8* fault_record = bytes + 48;
- UINT32* reserved = (UINT32*)(fault_record);
- *reserved &= ~0xFFF; //First 12 bits of fault record.
- reserved = (UINT32*)(fault_record + 10);
- *reserved &= ~0x1FFF; //Bits 80-92 of fault record.
- *(fault_record + 15) &= 0x7; //Very last bit of fault record.
+ //Create random bytes.
+ int size = 144;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set return values, exit.
- *location = bytes;
- return size;
+ //Set reserved areas to zero.
+ for (int i = 0; i < 12; i++) {
+ *(bytes + 36 + i) = 0; //Reserved bytes 36-47.
+ }
+ UINT8 *fault_record = bytes + 48;
+ UINT32 *reserved = (UINT32 *)(fault_record);
+ *reserved &= ~0xFFF; //First 12 bits of fault record.
+ reserved = (UINT32 *)(fault_record + 8);
+ *reserved &= ~0x1FFF0000; //Bits 80-92 of fault record.
+ *(fault_record + 15) &= 0x7; //Very last bit of fault record.
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
}
//Generates a single pseudo-random IOMMU DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_iommu(void** location)
+size_t generate_section_dmar_iommu(void **location)
{
- //Create random bytes.
- int size = 144;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- for (int i=0; i<7; i++)
- *(bytes + 1 + i) = 0; //Reserved bytes 1 to 7.
- UINT64* reserved = (UINT64*)(bytes + 24);
- *reserved = 0; //Reserved bytes 24-31.
- for (int i=0; i<16; i++)
- *(bytes + 48 + i) = 0; //Reserved bytes 48-63.
+ //Create random bytes.
+ int size = 144;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Set reserved areas to zero.
+ for (int i = 0; i < 7; i++) {
+ *(bytes + 1 + i) = 0; //Reserved bytes 1 to 7.
+ }
+ UINT64 *reserved = (UINT64 *)(bytes + 24);
+ *reserved = 0; //Reserved bytes 24-31.
+ for (int i = 0; i < 16; i++) {
+ *(bytes + 48 + i) = 0; //Reserved bytes 48-63.
+ }
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-firmware.c b/generator/sections/gen-section-firmware.c
index 7ba93ee..9eb3f69 100644
--- a/generator/sections/gen-section-firmware.c
+++ b/generator/sections/gen-section-firmware.c
@@ -11,23 +11,24 @@
//Generates a single pseudo-random firmware error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_firmware(void** location)
+size_t generate_section_firmware(void **location)
{
- //Create random bytes.
- int size = 32;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- for (int i=0; i<6; i++)
- *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
+ //Create random bytes.
+ int size = 32;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set expected values.
- *(bytes + 1) = 2; //Revision, referenced version of spec is 2.
- UINT64* record_id = (UINT64*)(bytes + 8);
- *record_id = 0; //Record ID, should be forced to NULL.
- *bytes = rand() % 3; //Record type.
+ //Set reserved areas to zero.
+ for (int i = 0; i < 6; i++) {
+ *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
+ }
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Set expected values.
+ *(bytes + 1) = 2; //Revision, referenced version of spec is 2.
+ UINT64 *record_id = (UINT64 *)(bytes + 8);
+ *record_id = 0; //Record ID, should be forced to NULL.
+ *bytes = rand() % 3; //Record type.
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-generic.c b/generator/sections/gen-section-generic.c
index e9a2ea0..061ff10 100644
--- a/generator/sections/gen-section-generic.c
+++ b/generator/sections/gen-section-generic.c
@@ -11,28 +11,29 @@
//Generates a single pseudo-random generic processor section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_generic(void** location)
+size_t generate_section_generic(void **location)
{
- //Create random bytes.
- size_t size = generate_random_section(location, 192);
+ //Create random bytes.
+ size_t size = generate_random_section(location, 192);
- //Set reserved locations to zero.
- UINT8* start_byte = (UINT8*)*location;
- *((UINT64*)start_byte) &= 0xFFF;
- *(start_byte + 12) &= 0b111;
- *((UINT16*)(start_byte + 14)) = 0x0;
-
- //Ensure CPU brand string does not terminate early.
- for (int i=0; i<128; i++)
- {
- UINT8* byte = start_byte + 24 + i;
- if (*byte == 0x0)
- *byte = rand() % 127 + 1;
+ //Set reserved locations to zero.
+ UINT8 *start_byte = (UINT8 *)*location;
+ *((UINT64 *)start_byte) &= 0xFFF;
+ *(start_byte + 12) &= 0x7;
+ *((UINT16 *)(start_byte + 14)) = 0x0;
- //Null terminate last byte.
- if (i == 127)
- *byte = 0x0;
- }
+ //Ensure CPU brand string does not terminate early.
+ for (int i = 0; i < 128; i++) {
+ UINT8 *byte = start_byte + 24 + i;
+ if (*byte == 0x0) {
+ *byte = rand() % 127 + 1;
+ }
- return size;
-}
\ No newline at end of file
+ //Null terminate last byte.
+ if (i == 127) {
+ *byte = 0x0;
+ }
+ }
+
+ return size;
+}
diff --git a/generator/sections/gen-section-ia32x64.c b/generator/sections/gen-section-ia32x64.c
index a01d2b7..2bd9c72 100644
--- a/generator/sections/gen-section-ia32x64.c
+++ b/generator/sections/gen-section-ia32x64.c
@@ -11,155 +11,160 @@
#include "gen-section.h"
#define IA32X64_ERROR_STRUCTURE_SIZE 64
-void* generate_ia32x64_error_structure();
-size_t generate_ia32x64_context_structure(void** location);
+void *generate_ia32x64_error_structure();
+size_t generate_ia32x64_context_structure(void **location);
//Generates a single pseudo-random IA32/x64 section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_ia32x64(void** location)
+size_t generate_section_ia32x64(void **location)
{
- //Set up for generation of error/context structures.
- UINT16 error_structure_num = rand() % 5;
- UINT16 context_structure_num = rand() % 5;
- void* error_structures[error_structure_num];
- void* context_structures[context_structure_num];
- size_t context_structure_lengths[context_structure_num];
+ //Set up for generation of error/context structures.
+ UINT16 error_structure_num = rand() % 4 + 1;
+ UINT16 context_structure_num = rand() % 4 + 1;
+ void *error_structures[error_structure_num];
+ void *context_structures[context_structure_num];
+ size_t context_structure_lengths[context_structure_num];
- //Generate the structures.
- for (int i=0; i<error_structure_num; i++)
- error_structures[i] = generate_ia32x64_error_structure();
- for (int i=0; i<context_structure_num; i++)
- context_structure_lengths[i] = generate_ia32x64_context_structure(context_structures + i);
+ //Generate the structures.
+ for (int i = 0; i < error_structure_num; i++) {
+ error_structures[i] = generate_ia32x64_error_structure();
+ }
+ for (int i = 0; i < context_structure_num; i++) {
+ context_structure_lengths[i] =
+ generate_ia32x64_context_structure(context_structures +
+ i);
+ }
- //Create a valid IA32/x64 section.
- size_t total_len = 64 + (IA32X64_ERROR_STRUCTURE_SIZE * error_structure_num);
- for (int i=0; i<context_structure_num; i++)
- total_len += context_structure_lengths[i];
- UINT8* section = generate_random_bytes(total_len);
+ //Create a valid IA32/x64 section.
+ size_t total_len =
+ 64 + (IA32X64_ERROR_STRUCTURE_SIZE * error_structure_num);
+ for (int i = 0; i < context_structure_num; i++) {
+ total_len += context_structure_lengths[i];
+ }
+ UINT8 *section = generate_random_bytes(total_len);
- //Null extend the end of the CPUID in the header.
- for (int i=0; i<16; i++)
- *(section + 48 + i) = 0x0;
+ //Null extend the end of the CPUID in the header.
+ for (int i = 0; i < 16; i++) {
+ *(section + 48 + i) = 0x0;
+ }
- //Set header information.
- UINT64* validation = (UINT64*)section;
- *validation &= 0b11;
- *validation |= error_structure_num << 2;
- *validation |= context_structure_num << 8;
+ //Set header information.
+ UINT64 *validation = (UINT64 *)section;
+ *validation &= 0x3;
+ *validation |= error_structure_num << 2;
+ *validation |= context_structure_num << 8;
- //Copy in structures, free resources.
- UINT8* cur_pos = section + 64;
- for (int i=0; i<error_structure_num; i++)
- {
- memcpy(cur_pos, error_structures[i], IA32X64_ERROR_STRUCTURE_SIZE);
- free(error_structures[i]);
- cur_pos += IA32X64_ERROR_STRUCTURE_SIZE;
- }
- for (int i=0; i<context_structure_num; i++)
- {
- memcpy(cur_pos, context_structures[i], context_structure_lengths[i]);
- free(context_structures[i]);
- cur_pos += context_structure_lengths[i];
- }
+ //Copy in structures, free resources.
+ UINT8 *cur_pos = section + 64;
+ for (int i = 0; i < error_structure_num; i++) {
+ memcpy(cur_pos, error_structures[i],
+ IA32X64_ERROR_STRUCTURE_SIZE);
+ free(error_structures[i]);
+ cur_pos += IA32X64_ERROR_STRUCTURE_SIZE;
+ }
+ for (int i = 0; i < context_structure_num; i++) {
+ memcpy(cur_pos, context_structures[i],
+ context_structure_lengths[i]);
+ free(context_structures[i]);
+ cur_pos += context_structure_lengths[i];
+ }
- //Set return values, exist.
- *location = section;
- return total_len;
+ //Set return values, exist.
+ *location = section;
+ return total_len;
}
//Generates a single IA32/x64 error structure. Must later be freed.
-void* generate_ia32x64_error_structure()
+void *generate_ia32x64_error_structure()
{
- UINT8* error_structure = generate_random_bytes(IA32X64_ERROR_STRUCTURE_SIZE);
+ UINT8 *error_structure =
+ generate_random_bytes(IA32X64_ERROR_STRUCTURE_SIZE);
- //Set error structure reserved space to zero.
- UINT64* validation = (UINT64*)(error_structure + 16);
- *validation &= 0x1F;
+ //Set error structure reserved space to zero.
+ UINT64 *validation = (UINT64 *)(error_structure + 16);
+ *validation &= 0x1F;
- //Create a random type of error structure.
- EFI_GUID* guid = (EFI_GUID*)error_structure;
- UINT64* check_info = (UINT64*)(error_structure + 24);
- int error_structure_type = rand() % 4;
- switch (error_structure_type)
- {
- //Cache
- case 0:
- memcpy(guid, &gEfiIa32x64ErrorTypeCacheCheckGuid, sizeof(EFI_GUID));
+ //Create a random type of error structure.
+ EFI_GUID *guid = (EFI_GUID *)error_structure;
+ UINT64 *check_info = (UINT64 *)(error_structure + 24);
+ int error_structure_type = rand() % 4;
+ switch (error_structure_type) {
+ //Cache
+ case 0:
+ memcpy(guid, &gEfiIa32x64ErrorTypeCacheCheckGuid,
+ sizeof(EFI_GUID));
- //Set reserved space to zero.
- *check_info &= ~0xFF00;
- *check_info &= 0x3FFFFFFF;
- break;
+ //Set reserved space to zero.
+ *check_info &= ~0x20FF00;
+ *check_info &= 0x3FFFFFFF;
+ break;
- //TLB
- case 1:
- memcpy(guid, &gEfiIa32x64ErrorTypeTlbCheckGuid, sizeof(EFI_GUID));
+ //TLB
+ case 1:
+ memcpy(guid, &gEfiIa32x64ErrorTypeTlbCheckGuid,
+ sizeof(EFI_GUID));
- //Set reserved space to zero.
- *check_info &= ~0xFF00;
- *check_info &= 0x3FFFFFFF;
- break;
+ //Set reserved space to zero.
+ *check_info &= ~0x20FF00;
+ *check_info &= 0x3FFFFFFF;
+ break;
- //Bus
- case 2:
- memcpy(guid, &gEfiIa32x64ErrorTypeBusCheckGuid, sizeof(EFI_GUID));
+ //Bus
+ case 2:
+ memcpy(guid, &gEfiIa32x64ErrorTypeBusCheckGuid,
+ sizeof(EFI_GUID));
- //Set reserved space to zero.
- *check_info &= ~0xF800;
- *check_info &= 0x7FFFFFFFF;
- break;
+ //Set reserved space to zero.
+ *check_info &= ~0x20F800;
+ *check_info &= 0x7FFFFFFFF;
+ break;
- //MS
- case 3:
- memcpy(guid, &gEfiIa32x64ErrorTypeMsCheckGuid, sizeof(EFI_GUID));
+ //MS
+ case 3:
+ memcpy(guid, &gEfiIa32x64ErrorTypeMsCheckGuid,
+ sizeof(EFI_GUID));
- //Set reserved space to zero.
- *check_info &= ~0xFFE0;
- *check_info &= 0xFFFFFF;
- break;
- }
+ //Set reserved space to zero.
+ *check_info &= ~0xFFE0;
+ *check_info &= 0xFFFFFF;
+ break;
+ }
- return error_structure;
+ return error_structure;
}
//Generates a single IA32/x64 context structure. Must later be freed.
-size_t generate_ia32x64_context_structure(void** location)
+size_t generate_ia32x64_context_structure(void **location)
{
- //Initial length is 16 bytes. Add extra based on type.
- int reg_type = rand() % 8;
- int reg_size = 0;
+ //Initial length is 16 bytes. Add extra based on type.
+ int reg_type = rand() % 8;
+ int reg_size = 0;
- //Set register size.
- if (reg_type == 2)
- {
- reg_size = 92; //IA32 registers.
- }
- else if (reg_type == 3)
- {
- reg_size = 244; //x64 registers.
- }
- else
- {
- reg_size = (rand() % 5 + 1) * 32; //Not table defined.
- }
+ //Set register size.
+ if (reg_type == 2) {
+ reg_size = 92; //IA32 registers.
+ } else if (reg_type == 3) {
+ reg_size = 244; //x64 registers.
+ } else {
+ reg_size = (rand() % 5 + 1) * 32; //Not table defined.
+ }
- //Create structure randomly.
- int total_size = 16 + reg_size;
- UINT16* context_structure = (UINT16*)generate_random_bytes(total_size);
+ //Create structure randomly.
+ int total_size = 16 + reg_size;
+ UINT16 *context_structure = (UINT16 *)generate_random_bytes(total_size);
- //If it is x64 registers, set reserved area accordingly.
- if (reg_type == 3)
- {
- UINT8* reg_bytes = (UINT8*)(context_structure + 8);
- UINT32* reserved = (UINT32*)(reg_bytes + 140);
- *reserved = 0;
- }
+ //If it is x64 registers, set reserved area accordingly.
+ if (reg_type == 3) {
+ UINT8 *reg_bytes = (UINT8 *)(context_structure + 8);
+ UINT32 *reserved = (UINT32 *)(reg_bytes + 140);
+ *reserved = 0;
+ }
- //Set header information.
- *(context_structure) = reg_type;
- *(context_structure + 1) = reg_size;
+ //Set header information.
+ *(context_structure) = reg_type;
+ *(context_structure + 1) = reg_size;
- //Set return values and exit.
- *location = context_structure;
- return total_size;
-}
\ No newline at end of file
+ //Set return values and exit.
+ *location = context_structure;
+ return total_size;
+}
diff --git a/generator/sections/gen-section-memory.c b/generator/sections/gen-section-memory.c
index 9d405a4..46eaed3 100644
--- a/generator/sections/gen-section-memory.c
+++ b/generator/sections/gen-section-memory.c
@@ -11,49 +11,49 @@
//Generates a single pseudo-random platform memory error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_memory(void** location)
+size_t generate_section_memory(void **location)
{
- //Create random bytes.
- int size = 80;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0x2FFFFF; //Validation 22-63
- *(bytes + 73) &= ~0b11100; //Extended bits 2-4
+ //Create random bytes.
+ int size = 80;
+ UINT8 *bytes = generate_random_bytes(size);
- //Fix values that could be above range.
- *(bytes + 72) = rand() % 16; //Memory error type
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x2FFFFF; //Validation 22-63
+ *(bytes + 73) &= ~0x1C; //Extended bits 2-4
- //Fix error status.
- create_valid_error_section(bytes + 8);
+ //Fix values that could be above range.
+ *(bytes + 72) = rand() % 16; //Memory error type
- //Set return values, exit.
- *location = bytes;
- return size;
+ //Fix error status.
+ create_valid_error_section(bytes + 8);
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
}
//Generates a single pseudo-random memory 2 error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_memory2(void** location)
+size_t generate_section_memory2(void **location)
{
- //Create random bytes.
- int size = 96;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0x2FFFFF; //Validation 22-63
- *(bytes + 63) = 0; //Reserved byte 63
+ //Create random bytes.
+ int size = 96;
+ UINT8 *bytes = generate_random_bytes(size);
- //Fix values that could be above range.
- *(bytes + 61) = rand() % 16; //Memory error type
- *(bytes + 62) = rand() % 2; //Status
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x2FFFFF; //Validation 22-63
+ *(bytes + 63) = 0; //Reserved byte 63
- //Fix error status.
- create_valid_error_section(bytes + 8);
+ //Fix values that could be above range.
+ *(bytes + 61) = rand() % 16; //Memory error type
+ *(bytes + 62) = rand() % 2; //Status
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Fix error status.
+ create_valid_error_section(bytes + 8);
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-pci-bus.c b/generator/sections/gen-section-pci-bus.c
index 1aee19a..c814069 100644
--- a/generator/sections/gen-section-pci-bus.c
+++ b/generator/sections/gen-section-pci-bus.c
@@ -11,28 +11,28 @@
//Generates a single pseudo-random PCI/PCI-X bus error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pci_bus(void** location)
+size_t generate_section_pci_bus(void **location)
{
- //Create random bytes.
- int size = 72;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0x1FF; //Validation 9-63
- UINT32* reserved = (UINT32*)(bytes + 20);
- *reserved = 0;
- UINT64* bus_command = (UINT64*)(bytes + 40);
- *bus_command &= ((UINT64)0b1 << 56); //Bus command bytes bar bit 56.
+ //Create random bytes.
+ int size = 72;
+ UINT8 *bytes = generate_random_bytes(size);
- //Fix values that could be above range.
- UINT16* error_type = (UINT16*)(bytes + 16);
- *error_type = rand() % 8;
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x1FF; //Validation 9-63
+ UINT32 *reserved = (UINT32 *)(bytes + 20);
+ *reserved = 0;
+ UINT64 *bus_command = (UINT64 *)(bytes + 40);
+ *bus_command &= ((UINT64)0x1 << 56); //Bus command bytes bar bit 56.
- //Fix error status.
- create_valid_error_section(bytes + 8);
+ //Fix values that could be above range.
+ UINT16 *error_type = (UINT16 *)(bytes + 16);
+ *error_type = rand() % 8;
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Fix error status.
+ create_valid_error_section(bytes + 8);
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-pci-dev.c b/generator/sections/gen-section-pci-dev.c
index 339f98c..a164719 100644
--- a/generator/sections/gen-section-pci-dev.c
+++ b/generator/sections/gen-section-pci-dev.c
@@ -11,33 +11,34 @@
//Generates a single pseudo-random PCI component error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pci_dev(void** location)
+size_t generate_section_pci_dev(void **location)
{
- //Generate how many register pairs will be attached to this section.
- UINT32 num_memory_pairs = rand() % 4;
- UINT32 num_io_pairs = rand() % 4;
- UINT32 num_registers = num_memory_pairs + num_io_pairs;
+ //Generate how many register pairs will be attached to this section.
+ UINT32 num_memory_pairs = rand() % 4;
+ UINT32 num_io_pairs = rand() % 4;
+ UINT32 num_registers = num_memory_pairs + num_io_pairs;
- //Create random bytes.
- int size = 40 + (num_registers * 16);
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0b11111; //Validation 5-63
- for (int i=0; i<5; i++)
- *(bytes + 27 + i) = 0; //Bytes 11-15 of ID info.
-
- //Set expected values.
- UINT32* memory_number_field = (UINT32*)(bytes + 32);
- UINT32* io_number_field = (UINT32*)(bytes + 36);
- *memory_number_field = num_memory_pairs;
- *io_number_field = num_io_pairs;
+ //Create random bytes.
+ int size = 40 + (num_registers * 16);
+ UINT8 *bytes = generate_random_bytes(size);
- //Fix error status.
- create_valid_error_section(bytes + 8);
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0x1F; //Validation 5-63
+ for (int i = 0; i < 5; i++) {
+ *(bytes + 27 + i) = 0; //Bytes 11-15 of ID info.
+ }
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Set expected values.
+ UINT32 *memory_number_field = (UINT32 *)(bytes + 32);
+ UINT32 *io_number_field = (UINT32 *)(bytes + 36);
+ *memory_number_field = num_memory_pairs;
+ *io_number_field = num_io_pairs;
+
+ //Fix error status.
+ create_valid_error_section(bytes + 8);
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section-pcie.c b/generator/sections/gen-section-pcie.c
index aa1be6b..82b2031 100644
--- a/generator/sections/gen-section-pcie.c
+++ b/generator/sections/gen-section-pcie.c
@@ -9,37 +9,42 @@
#include "../gen-utils.h"
#include "gen-section.h"
-#define PCIE_PORT_TYPES (int []){0, 1, 4, 5, 6, 7, 8, 9, 10}
+#define PCIE_PORT_TYPES \
+ (int[]) \
+ { \
+ 0, 1, 4, 5, 6, 7, 8, 9, 10 \
+ }
//Generates a single pseudo-random PCIe error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pcie(void** location)
+size_t generate_section_pcie(void **location)
{
- //Create random bytes.
- int size = 208;
- UINT8* bytes = generate_random_bytes(size);
-
- //Set reserved areas to zero.
- UINT64* validation = (UINT64*)bytes;
- *validation &= 0xFF; //Validation 8-63
- UINT32* version = (UINT32*)(bytes + 12);
- *version &= 0xFFFF; //Version bytes 2-3
- UINT32* reserved = (UINT32*)(bytes + 20);
- *reserved = 0; //Reserved bytes 20-24
- *(bytes + 37) &= ~0b111; //Device ID byte 13 bits 0-3
- *(bytes + 39) = 0; //Device ID byte 15
+ //Create random bytes.
+ int size = 208;
+ UINT8 *bytes = generate_random_bytes(size);
- //Set expected values.
- int minor = rand() % 128;
- int major = rand() % 128;
- *version = int_to_bcd(minor);
- *version |= int_to_bcd(major) << 8;
+ //Set reserved areas to zero.
+ UINT64 *validation = (UINT64 *)bytes;
+ *validation &= 0xFF; //Validation 8-63
+ UINT32 *version = (UINT32 *)(bytes + 12);
+ *version &= 0xFFFF; //Version bytes 2-3
+ UINT32 *reserved = (UINT32 *)(bytes + 20);
+ *reserved = 0; //Reserved bytes 20-24
+ *(bytes + 37) &= ~0x7; //Device ID byte 13 bits 0-3
+ *(bytes + 39) = 0; //Device ID byte 15
- //Fix values that could be above range.
- UINT32* port_type = (UINT32*)(bytes + 8);
- *port_type = PCIE_PORT_TYPES[rand() % (sizeof(PCIE_PORT_TYPES) / sizeof(int))];
+ //Set expected values.
+ int minor = rand() % 128;
+ int major = rand() % 128;
+ *version = int_to_bcd(minor);
+ *version |= int_to_bcd(major) << 8;
- //Set return values, exit.
- *location = bytes;
- return size;
-}
\ No newline at end of file
+ //Fix values that could be above range.
+ UINT32 *port_type = (UINT32 *)(bytes + 8);
+ *port_type = PCIE_PORT_TYPES[rand() %
+ (sizeof(PCIE_PORT_TYPES) / sizeof(int))];
+
+ //Set return values, exit.
+ *location = bytes;
+ return size;
+}
diff --git a/generator/sections/gen-section.c b/generator/sections/gen-section.c
index 012f88f..0b07af0 100644
--- a/generator/sections/gen-section.c
+++ b/generator/sections/gen-section.c
@@ -6,25 +6,42 @@
#include "gen-section.h"
CPER_GENERATOR_DEFINITION generator_definitions[] = {
- {&gEfiProcessorGenericErrorSectionGuid, "generic", generate_section_generic},
- {&gEfiIa32X64ProcessorErrorSectionGuid, "ia32x64", generate_section_ia32x64},
- {&gEfiArmProcessorErrorSectionGuid, "arm", generate_section_arm},
- {&gEfiPlatformMemoryErrorSectionGuid, "memory", generate_section_memory},
- {&gEfiPlatformMemoryError2SectionGuid, "memory2", generate_section_memory2},
- {&gEfiPcieErrorSectionGuid, "pcie", generate_section_pcie},
- {&gEfiFirmwareErrorSectionGuid, "firmware", generate_section_firmware},
- {&gEfiPciBusErrorSectionGuid, "pcibus", generate_section_pci_bus},
- {&gEfiPciDevErrorSectionGuid, "pcidev", generate_section_pci_dev},
- {&gEfiDMArGenericErrorSectionGuid, "dmargeneric", generate_section_dmar_generic},
- {&gEfiDirectedIoDMArErrorSectionGuid, "dmarvtd", generate_section_dmar_vtd},
- {&gEfiIommuDMArErrorSectionGuid, "dmariommu", generate_section_dmar_iommu},
- {&gEfiCcixPerLogErrorSectionGuid, "ccixper", generate_section_ccix_per},
- {&gEfiCxlProtocolErrorSectionGuid, "cxlprotocol", generate_section_cxl_protocol},
- {&gEfiCxlGeneralMediaErrorSectionGuid, "cxlcomponent-media", generate_section_cxl_component},
- {&gEfiCxlDramEventErrorSectionGuid, "cxlcomponent-dram", generate_section_cxl_component},
- {&gEfiCxlMemoryModuleErrorSectionGuid, "cxlcomponent-memory", generate_section_cxl_component},
- {&gEfiCxlPhysicalSwitchErrorSectionGuid, "cxlcomponent-pswitch", generate_section_cxl_component},
- {&gEfiCxlVirtualSwitchErrorSectionGuid, "cxlcomponent-vswitch", generate_section_cxl_component},
- {&gEfiCxlMldPortErrorSectionGuid, "cxlcomponent-mld", generate_section_cxl_component},
+ { &gEfiProcessorGenericErrorSectionGuid, "generic",
+ generate_section_generic },
+ { &gEfiIa32X64ProcessorErrorSectionGuid, "ia32x64",
+ generate_section_ia32x64 },
+ { &gEfiArmProcessorErrorSectionGuid, "arm", generate_section_arm },
+ { &gEfiPlatformMemoryErrorSectionGuid, "memory",
+ generate_section_memory },
+ { &gEfiPlatformMemoryError2SectionGuid, "memory2",
+ generate_section_memory2 },
+ { &gEfiPcieErrorSectionGuid, "pcie", generate_section_pcie },
+ { &gEfiFirmwareErrorSectionGuid, "firmware",
+ generate_section_firmware },
+ { &gEfiPciBusErrorSectionGuid, "pcibus", generate_section_pci_bus },
+ { &gEfiPciDevErrorSectionGuid, "pcidev", generate_section_pci_dev },
+ { &gEfiDMArGenericErrorSectionGuid, "dmargeneric",
+ generate_section_dmar_generic },
+ { &gEfiDirectedIoDMArErrorSectionGuid, "dmarvtd",
+ generate_section_dmar_vtd },
+ { &gEfiIommuDMArErrorSectionGuid, "dmariommu",
+ generate_section_dmar_iommu },
+ { &gEfiCcixPerLogErrorSectionGuid, "ccixper",
+ generate_section_ccix_per },
+ { &gEfiCxlProtocolErrorSectionGuid, "cxlprotocol",
+ generate_section_cxl_protocol },
+ { &gEfiCxlGeneralMediaErrorSectionGuid, "cxlcomponent-media",
+ generate_section_cxl_component },
+ { &gEfiCxlDramEventErrorSectionGuid, "cxlcomponent-dram",
+ generate_section_cxl_component },
+ { &gEfiCxlMemoryModuleErrorSectionGuid, "cxlcomponent-memory",
+ generate_section_cxl_component },
+ { &gEfiCxlPhysicalSwitchErrorSectionGuid, "cxlcomponent-pswitch",
+ generate_section_cxl_component },
+ { &gEfiCxlVirtualSwitchErrorSectionGuid, "cxlcomponent-vswitch",
+ generate_section_cxl_component },
+ { &gEfiCxlMldPortErrorSectionGuid, "cxlcomponent-mld",
+ generate_section_cxl_component },
};
-const size_t generator_definitions_len = sizeof(generator_definitions) / sizeof(CPER_GENERATOR_DEFINITION);
\ No newline at end of file
+const size_t generator_definitions_len =
+ sizeof(generator_definitions) / sizeof(CPER_GENERATOR_DEFINITION);
diff --git a/generator/sections/gen-section.h b/generator/sections/gen-section.h
index ac0a024..df1e227 100644
--- a/generator/sections/gen-section.h
+++ b/generator/sections/gen-section.h
@@ -5,30 +5,30 @@
#include "../../edk/Cper.h"
//Section generator function predefinitions.
-size_t generate_section_generic(void** location);
-size_t generate_section_ia32x64(void** location);
-size_t generate_section_arm(void** location);
-size_t generate_section_memory(void** location);
-size_t generate_section_memory2(void** location);
-size_t generate_section_pcie(void** location);
-size_t generate_section_pci_bus(void** location);
-size_t generate_section_pci_dev(void** location);
-size_t generate_section_firmware(void** location);
-size_t generate_section_dmar_generic(void** location);
-size_t generate_section_dmar_vtd(void** location);
-size_t generate_section_dmar_iommu(void** location);
-size_t generate_section_ccix_per(void** location);
-size_t generate_section_cxl_protocol(void** location);
-size_t generate_section_cxl_component(void** location);
+size_t generate_section_generic(void **location);
+size_t generate_section_ia32x64(void **location);
+size_t generate_section_arm(void **location);
+size_t generate_section_memory(void **location);
+size_t generate_section_memory2(void **location);
+size_t generate_section_pcie(void **location);
+size_t generate_section_pci_bus(void **location);
+size_t generate_section_pci_dev(void **location);
+size_t generate_section_firmware(void **location);
+size_t generate_section_dmar_generic(void **location);
+size_t generate_section_dmar_vtd(void **location);
+size_t generate_section_dmar_iommu(void **location);
+size_t generate_section_ccix_per(void **location);
+size_t generate_section_cxl_protocol(void **location);
+size_t generate_section_cxl_component(void **location);
//Definition structure for a single CPER section generator.
typedef struct {
- EFI_GUID* Guid;
- const char* ShortName;
- size_t (*Generate)(void**);
+ EFI_GUID *Guid;
+ const char *ShortName;
+ size_t (*Generate)(void **);
} CPER_GENERATOR_DEFINITION;
extern CPER_GENERATOR_DEFINITION generator_definitions[];
extern const size_t generator_definitions_len;
-#endif
\ No newline at end of file
+#endif