@@ -13,6 +13,7 @@ SECTIONS
*(.rodata*)
. = ALIGN(16);
}
+ . = ALIGN(4096);
_etext = .;
_text_size = . - _text;
.dynamic : { *(.dynamic) }
@@ -301,9 +301,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
struct efi_boot_memmap *map = &(efi_bootinfo->mem_map);
efi_memory_desc_t *buffer = *map->map;
efi_memory_desc_t *d = NULL;
- struct mem_region r;
- uintptr_t text = (uintptr_t)&_text, etext = ALIGN((uintptr_t)&_etext, 4096);
- uintptr_t data = (uintptr_t)&_data, edata = ALIGN((uintptr_t)&_edata, 4096);
+ struct mem_region r, *code, *data;
const void *fdt = efi_bootinfo->fdt;
/*
@@ -337,21 +335,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
r.flags = MR_F_IO;
break;
case EFI_LOADER_CODE:
- if (r.start <= text && r.end > text) {
- /* This is the unit test region. Flag the code separately. */
- phys_addr_t tmp = r.end;
-
- assert(etext <= data);
- assert(edata <= r.end);
- r.flags = MR_F_CODE;
- r.end = data;
- memregions_add(&r);
- r.start = data;
- r.end = tmp;
- r.flags = 0;
- } else {
- r.flags = MR_F_RESERVED;
- }
+ r.flags = MR_F_CODE;
break;
case EFI_CONVENTIONAL_MEMORY:
if (free_mem_pages < d->num_pages) {
@@ -361,15 +345,27 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
break;
}
- if (!(r.flags & MR_F_IO)) {
- if (r.start < __phys_offset)
- __phys_offset = r.start;
- if (r.end > __phys_end)
- __phys_end = r.end;
- }
memregions_add(&r);
}
+ memregions_split((unsigned long)&_etext, &code, &data);
+ assert(code && (code->flags & MR_F_CODE));
+ if (data)
+ data->flags &= ~MR_F_CODE;
+
+ for (struct mem_region *m = mem_regions; m->end; ++m) {
+ if (m != code && (m->flags & MR_F_CODE))
+ m->flags = MR_F_RESERVED;
+
+ if (!(m->flags & MR_F_IO)) {
+ if (m->start < __phys_offset)
+ __phys_offset = m->start;
+ if (m->end > __phys_end)
+ __phys_end = m->end;
+ }
+ }
+ __phys_end &= PHYS_MASK;
+
if (fdt) {
unsigned long old_start = free_mem_start;
void *freemem = (void *)free_mem_start;
@@ -380,7 +376,6 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
free_mem_pages = (free_mem_start - old_start) >> EFI_PAGE_SHIFT;
}
- __phys_end &= PHYS_MASK;
asm_mmu_disable();
if (free_mem_pages == 0)