]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/postcode.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / i386 / postcode.h
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #ifndef _I386_POSTCODE_H_
32 #define _I386_POSTCODE_H_
33
34 #ifndef DEBUG
35 #include <debug.h>
36 #endif
37
38 /* Define this to delay about 1 sec after posting each code */
39 /* #define POSTCODE_DELAY 1 */
40
41 /* The POSTCODE is port 0x80 */
42 #define POSTPORT 0x80
43
44 #define SPINCOUNT 300000000
45 #define CPU_PAUSE() rep; nop
46
47 #if DEBUG
48 /*
49 * Macro to output byte value to postcode, destoying register al.
50 * Additionally, if POSTCODE_DELAY, spin for about a second.
51 */
52
53 #if POSTCODE_DELAY
54 #define POSTCODE_AL \
55 outb %al,$(POSTPORT); \
56 movl $(SPINCOUNT), %eax; \
57 1: \
58 CPU_PAUSE(); \
59 decl %eax; \
60 jne 1b
61 #else
62 #define POSTCODE_AL \
63 outb %al,$(POSTPORT)
64 #endif /* POSTCODE_DELAY */
65
66 #define POSTCODE(XX) \
67 mov $(XX), %al; \
68 POSTCODE_AL
69
70 /* Output byte value to postcode, without destoying register eax */
71 #define POSTCODE_SAVE_EAX(XX) \
72 push %eax; \
73 POSTCODE(XX); \
74 pop %eax
75
76 /*
77 * Display a 32-bit value to the post card - low byte to high byte
78 * Entry: value in %ebx
79 * Exit: %ebx preserved; %eax destroyed
80 */
81 #define POSTCODE32_EBX \
82 roll $8, %ebx; \
83 movl %ebx, %eax; \
84 POSTCODE_AL; \
85 \
86 roll $8, %ebx; \
87 movl %ebx, %eax; \
88 POSTCODE_AL; \
89 \
90 roll $8, %ebx; \
91 movl %ebx, %eax; \
92 POSTCODE_AL; \
93 \
94 roll $8, %ebx; \
95 movl %ebx, %eax; \
96 POSTCODE_AL
97
98 #else /* DEBUG */
99 #define POSTCODE_AL
100 #define POSTCODE(X)
101 #define POSTCODE32_EBX
102 #endif /* DEBUG */
103
104 /*
105 * The following postcodes are defined for stages of early startup:
106 */
107
108 #define _PSTART_ENTRY 0xFF
109 #define _PSTART_RELOC 0xFE
110 #define PSTART_ENTRY 0xFD
111 #define PSTART_PAGE_TABLES 0xFC
112 #define PSTART_BEFORE_PAGING 0xFB
113 #define VSTART_ENTRY 0xFA
114 #define VSTART_STACK_SWITCH 0xF9
115 #define VSTART_EXIT 0xF8
116 #define I386_INIT_ENTRY 0xF7
117 #define CPU_INIT_D 0xF6
118 #define PE_INIT_PLATFORM_D 0xF5
119
120 #define SLAVE_RSTART_ENTRY 0xEF
121 #define SLAVE_REAL_TO_PROT_ENTRY 0xEE
122 #define SLAVE_REAL_TO_PROT_EXIT 0xED
123 #define SLAVE_STARTPROG_ENTRY 0xEC
124 #define SLAVE_STARTPROG_EXIT 0xEB
125 #define SLAVE_PSTART_ENTRY 0xEA
126 #define SLAVE_PSTART_EXIT 0xE9
127 #define SLAVE_VSTART_ENTRY 0xE8
128 #define SLAVE_VSTART_DESC_INIT 0xE7
129 #define SLAVE_VSTART_STACK_SWITCH 0xE6
130 #define SLAVE_VSTART_EXIT 0xE5
131 #define I386_INIT_SLAVE 0xE4
132
133 #define PANIC_DOUBLE_FAULT 0xDF /* Double Fault exception */
134 #define PANIC_MACHINE_CHECK 0xDE /* Machine-Check */
135 #define MP_KDP_ENTER 0xDB /* Machine in kdp DeBugger */
136 #define PANIC_HLT 0xD1 /* Die an early death */
137 #define NO_64BIT 0x64 /* No 64-bit support yet */
138
139 #define ACPI_WAKE_START_ENTRY 0xCF
140 #define ACPI_WAKE_PROT_ENTRY 0xCE
141 #define ACPI_WAKE_PAGED_ENTRY 0xCD
142
143 #define CPU_IA32_ENABLE_ENTRY 0xBF
144 #define CPU_IA32_ENABLE_EXIT 0xBE
145 #define ML_LOAD_DESC64_ENTRY 0xBD
146 #define ML_LOAD_DESC64_GDT 0xBC
147 #define ML_LOAD_DESC64_IDT 0xBB
148 #define ML_LOAD_DESC64_LDT 0xBA
149 #define ML_LOAD_DESC64_EXIT 0xB9
150 #define CPU_IA32_DISABLE_ENTRY 0xB8
151 #define CPU_IA32_DISABLE_EXIT 0xB7
152
153 #ifndef ASSEMBLER
154 inline static void
155 _postcode_delay(uint32_t spincount)
156 {
157 asm volatile("1: \n\t"
158 " rep; nop; \n\t"
159 " decl %%eax; \n\t"
160 " jne 1b"
161 : : "a" (spincount));
162 }
163 inline static void
164 _postcode(uint8_t xx)
165 {
166 asm volatile("outb %0, %1" : : "a" (xx), "N" (POSTPORT));
167 }
168 #if DEBUG
169 inline static void
170 postcode(uint8_t xx)
171 {
172 _postcode(xx);
173 #if POSTCODE_DELAY
174 _postcode_delay(SPINCOUNT);
175 #endif
176 }
177 #else
178 #define postcode(xx)
179 #endif
180 #endif
181
182 #endif /* _I386_POSTCODE_H_ */