I have a bit of C code, reproduced below. It is my understanding that it is setting certain bits of the BootPML4 array to a certain value. Could someone please explain how the BootPML4
array below is filled? Also, how do I ensure that unused values in the array are zeroed, while ensuring that the two settings below remain intact?
typedef uint64_t pml4_entry_t;
#define PML4_PROT (INTEL_PTE_VALID | INTEL_PTE_WRITE)
pml4_entry_t BootPML4[PTE_PER_PAGE] __attribute__((section("__HIB, __bootPT"))) = {
[0] = ((uint64_t)(PAGE_SIZE) | PML4_PROT),
[KERNEL_PML4_INDEX] = ((uint64_t)(PAGE_SIZE) | PML4_PROT),
};
This is using designated initializers which was added in C99, The Forward section of the C99 draft standard in paragraph 5 says:
and has the following bullet:
and the details are covered in section
6.7.8
Initialization and provides the following example in paragraph 36 and 37:The gcc doc on designated initializers has a better example: