1/*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Header files for the Low Memory Globals (lg)
30 */
31#ifndef _LOW_MEMORY_GLOBALS_H_
32#define _LOW_MEMORY_GLOBALS_H_
33
34#include <mach/mach_types.h>
35#include <mach/vm_types.h>
36#include <mach/machine/vm_types.h>
37#include <mach/vm_prot.h>
38
39#ifndef __arm64__
40#error Wrong architecture - this file is meant for arm64
41#endif
42
43#define LOWGLO_LAYOUT_MAGIC 0xC0DEC0DE
44
45/*
46 * This structure is bound to lowmem_vectors.c. Make sure changes here are
47 * reflected there as well.
48 */
49
50#pragma pack(8) /* Make sure the structure stays as we defined it */
51typedef struct lowglo {
52 unsigned char lgVerCode[8]; /* 0xffffff8000002000 System verification code */
53 uint64_t lgZero; /* 0xffffff8000002008 Constant 0 */
54 uint64_t lgStext; /* 0xffffff8000002010 Start of kernel text */
55 uint64_t lgVersion; /* 0xffffff8000002018 Pointer to kernel version string */
56 uint64_t lgOSVersion; /* 0xffffff8000002020 Pointer to OS version string */
57 uint64_t lgKmodptr; /* 0xffffff8000002028 Pointer to kmod, debugging aid */
58 uint64_t lgTransOff; /* 0xffffff8000002030 Pointer to kdp_trans_off, debugging aid */
59 uint64_t lgRebootFlag; /* 0xffffff8000002038 Pointer to debugger reboot trigger */
60 uint64_t lgManualPktAddr; /* 0xffffff8000002040 Pointer to manual packet structure */
61 uint64_t lgAltDebugger; /* 0xffffff8000002048 Pointer to reserved space for alternate kernel debugger */
62 uint64_t lgPmapMemQ; /* 0xffffff8000002050 Pointer to PMAP memory queue */
63 uint64_t lgPmapMemPageOffset;/* 0xffffff8000002058 Offset of physical page member in vm_page_t or vm_page_with_ppnum_t */
64 uint64_t lgPmapMemChainOffset;/*0xffffff8000002060 Offset of listq in vm_page_t or vm_page_with_ppnum_t */
65 uint64_t lgStaticAddr; /* 0xffffff8000002068 Static allocation address */
66 uint64_t lgStaticSize; /* 0xffffff8000002070 Static allocation size */
67 uint64_t lgLayoutMajorVersion; /* 0xffffff8000002078 Lowglo major layout version */
68 uint64_t lgLayoutMagic; /* 0xffffff8000002080 Magic value evaluated to determine if lgLayoutVersion is valid */
69 uint64_t lgPmapMemStartAddr; /* 0xffffff8000002088 Pointer to start of vm_page_t array */
70 uint64_t lgPmapMemEndAddr; /* 0xffffff8000002090 Pointer to end of vm_page_t array */
71 uint64_t lgPmapMemPagesize; /* 0xffffff8000002098 size of vm_page_t */
72 uint64_t lgPmapMemFromArrayMask; /* 0xffffff80000020A0 Mask to indicate page is from vm_page_t array */
73 uint64_t lgPmapMemFirstppnum; /* 0xffffff80000020A8 physical page number of the first vm_page_t in the array */
74 uint64_t lgPmapMemPackedShift; /* 0xffffff80000020B0 alignment of packed pointer */
75 uint64_t lgPmapMemPackedBaseAddr;/* 0xffffff80000020B8 base address of that packed pointers are relative to */
76 uint64_t lgLayoutMinorVersion; /* 0xffffff80000020C0 Lowglo minor layout version */
77 uint64_t lgPageShift; /* 0xffffff80000020C8 number of shifts from page number to size */
78} lowglo;
79#pragma pack()
80
81extern lowglo lowGlo;
82
83void patch_low_glo(void);
84void patch_low_glo_static_region(uint64_t address, uint64_t size);
85void patch_low_glo_vm_page_info(void *, void *, uint32_t);
86
87#endif /* _LOW_MEMORY_GLOBALS_H_ */
88