xref: /xnu-8019.80.24/osfmk/arm/lowmem_vectors.c (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1 /*
2  * Copyright (c) 2012-2013 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 #include <mach_kdp.h>
30 #include <mach/vm_param.h>
31 #include <arm/lowglobals.h>
32 #include <vm/vm_object.h>
33 #include <vm/vm_page.h>
34 
35 extern vm_offset_t vm_kernel_stext;
36 extern void     *version;
37 extern void     *kmod;
38 extern void     *kdp_trans_off;
39 extern void     *osversion;
40 extern void     *flag_kdp_trigger_reboot;
41 extern void     *manual_pkt;
42 extern struct vm_object pmap_object_store;      /* store pt pages */
43 
44 lowglo lowGlo __attribute__ ((aligned(PAGE_MAX_SIZE))) = {
45 	.lgVerCode = { 'O', 'c', 't', 'o', 'p', 'u', 's', ' ' },
46 	// Increment the major version for changes that break the current Astris
47 	// usage of lowGlo values
48 	// Increment the minor version for changes that provide additonal info/function
49 	// but does not break current usage
50 	.lgLayoutMajorVersion = 3,
51 	.lgLayoutMinorVersion = 2,
52 	.lgLayoutMagic = LOWGLO_LAYOUT_MAGIC,
53 	.lgVersion = (uint32_t)&version,
54 	.lgKmodptr = (uint32_t)&kmod,
55 	.lgPageShift = PAGE_SHIFT,
56 #if MACH_KDP
57 	.lgTransOff = (uint32_t)&kdp_trans_off,
58 #endif
59 	.lgOSVersion = (uint32_t)&osversion,
60 #if MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING
61 	.lgRebootFlag   = (uint32_t)&flag_kdp_trigger_reboot,
62 	.lgManualPktAddr = (uint32_t)&manual_pkt,
63 #endif
64 	.lgPmapMemQ = (uint32_t)&(pmap_object_store.memq),
65 	.lgPmapMemPageOffset = offsetof(struct vm_page_with_ppnum, vmp_phys_page),
66 	.lgPmapMemChainOffset = offsetof(struct vm_page, vmp_listq),
67 	.lgPmapMemPagesize = (uint32_t)sizeof(struct vm_page),
68 	.lgPmapMemStartAddr = -1,
69 	.lgPmapMemEndAddr = -1,
70 	.lgPmapMemFirstppnum = -1,
71 	.lgVmFirstPhys = -1,
72 	.lgVmLastPhys = -1
73 };
74 
75 void
patch_low_glo(void)76 patch_low_glo(void)
77 {
78 	lowGlo.lgStext = (uint32_t)vm_kernel_stext;
79 }
80 
81 void
patch_low_glo_static_region(uint32_t address,uint32_t size)82 patch_low_glo_static_region(uint32_t address, uint32_t size)
83 {
84 	lowGlo.lgStaticAddr = address;
85 	lowGlo.lgStaticSize = size;
86 
87 	/**
88 	 * These values are set in pmap_bootstrap() and represent the range of
89 	 * kernel managed memory.
90 	 */
91 	extern const pmap_paddr_t vm_first_phys;
92 	extern const pmap_paddr_t vm_last_phys;
93 	assertf((vm_first_phys != 0) && (vm_last_phys != 0),
94 	    "Tried setting the Low Globals before pmap_bootstrap()");
95 	lowGlo.lgVmFirstPhys = vm_first_phys;
96 	lowGlo.lgVmLastPhys = vm_last_phys;
97 }
98 
99 void
patch_low_glo_vm_page_info(void * start_addr,void * end_addr,uint32_t first_ppnum)100 patch_low_glo_vm_page_info(void * start_addr, void * end_addr, uint32_t first_ppnum)
101 {
102 	lowGlo.lgPmapMemStartAddr = (uint32_t)start_addr;
103 	lowGlo.lgPmapMemEndAddr = (uint32_t)end_addr;
104 	lowGlo.lgPmapMemFirstppnum = first_ppnum;
105 }
106