Skip to content

Commit

Permalink
Handle case of no mem_size_actual
Browse files Browse the repository at this point in the history
Newer machines do not always have mem_size_actual filled in in the
boot args.  When that happens, use mem_size and mask it to a page
boundary.

Signed-off-by: Daniel Berlin <[email protected]>
  • Loading branch information
dberlin committed Dec 1, 2023
1 parent 736acde commit 897ccc3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "utils.h"
#include "xnuboot.h"

#define PAGE_SIZE 0x4000
#define PAGE_SIZE 0x4000
/* Cache line size on M3+ is 128 bytes, so we will just invalidate unnecessarily here */
#define CACHE_LINE_SIZE 64

#define CACHE_RANGE_OP(func, op) \
Expand Down Expand Up @@ -411,7 +412,14 @@ static void mmu_add_default_mappings(void)
* With SPRR enabled, this becomes RW.
* This range includes all real RAM, including carveouts
*/
mmu_add_mapping(ram_base, ram_base, cur_boot_args.mem_size_actual, MAIR_IDX_NORMAL, PERM_RWX);

/*
* Newer machines (m3+) do not always have mem_size_actual filled in. In this case,
* use mem size. Either way, mask it to a page boundary.
*/
u64 mem_size =
cur_boot_args.mem_size_actual ? cur_boot_args.mem_size_actual : cur_boot_args.mem_size;
mmu_add_mapping(ram_base, ram_base, mem_size & ~(PAGE_SIZE), MAIR_IDX_NORMAL, PERM_RWX);

/* Unmap carveout regions */
mcc_unmap_carveouts();
Expand Down

0 comments on commit 897ccc3

Please sign in to comment.