]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/postcode.h
9788c35d375e87630cf9182f65737081a00252d0
[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 100000000
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 #if POSTCODE_DELAY
53 #define POSTCODE_AL \
54 outb %al,$(POSTPORT); \
55 movl $(SPINCOUNT), %eax; \
56 1: \
57 CPU_PAUSE(); \
58 decl %eax; \
59 jne 1b
60 #else
61 #define POSTCODE_AL \
62 outb %al,$(POSTPORT)
63 #endif /* POSTCODE_DELAY */
64
65 #define POSTCODE(XX) \
66 mov $(XX), %al; \
67 POSTCODE_AL
68
69 /* Output byte value to postcode, without destoying register eax */
70 #define POSTCODE_SAVE_EAX(XX) \
71 push %eax; \
72 POSTCODE(XX); \
73 pop %eax
74
75 /*
76 * Display a 32-bit value to the post card - low byte to high byte
77 * Entry: value in %ebx
78 * Exit: %ebx preserved; %eax destroyed
79 */
80 #define POSTCODE32_EBX \
81 roll $8, %ebx; \
82 movl %ebx, %eax; \
83 POSTCODE_AL; \
84 \
85 roll $8, %ebx; \
86 movl %ebx, %eax; \
87 POSTCODE_AL; \
88 \
89 roll $8, %ebx; \
90 movl %ebx, %eax; \
91 POSTCODE_AL; \
92 \
93 roll $8, %ebx; \
94 movl %ebx, %eax; \
95 POSTCODE_AL
96
97 #else /* DEBUG */
98 #define POSTCODE_AL
99 #define POSTCODE(X)
100 #define POSTCODE32_EBX
101 #endif /* DEBUG */
102
103 /*
104 * The following postcodes are defined for stages of early startup:
105 */
106
107 #define PSTART_ENTRY 0xFF
108 #define PSTART_PAGE_TABLES 0xFE
109 #define PSTART_BEFORE_PAGING 0xFD
110 #define VSTART_ENTRY 0xFC
111 #define VSTART_STACK_SWITCH 0xFB
112 #define VSTART_EXIT 0xFA
113 #define I386_INIT_ENTRY 0xF9
114 #define CPU_INIT_D 0xF8
115 #define PROCESSOR_BOOTSTRAP_D 0xF7
116 #define PE_INIT_PLATFORM_D 0xF6
117 #define THREAD_BOOTSTRAP_D 0xF5
118
119 #define SLAVE_PSTART_ENTRY 0xEF
120 #define REAL_TO_PROT_ENTRY 0xEE
121 #define REAL_TO_PROT_EXIT 0xED
122 #define STARTPROG_ENTRY 0xEC
123 #define STARTPROG_EXIT 0xEB
124 #define SLAVE_START_ENTRY 0xEA
125 #define SLAVE_START_EXIT 0xE9
126 #define SVSTART_ENTRY 0xE8
127 #define SVSTART_DESC_INIT 0xE7
128 #define SVSTART_STACK_SWITCH 0xE6
129 #define SVSTART_EXIT 0xE5
130 #define I386_INIT_SLAVE 0xE4
131
132 #define MP_KDP_ENTER 0xDB /* Machine in kdp DeBugger */
133 #define PANIC_HLT 0xD1 /* Die an early death */
134
135 #define ACPI_WAKE_START_ENTRY 0xCF
136 #define ACPI_WAKE_PROT_ENTRY 0xCE
137 #define ACPI_WAKE_PAGED_ENTRY 0xCD
138
139 #ifndef ASSEMBLER
140 inline static void
141 _postcode_delay(uint32_t spincount)
142 {
143 asm volatile("1: \n\t"
144 " rep; nop; \n\t"
145 " decl %%eax; \n\t"
146 " jne 1b"
147 : : "a" (spincount));
148 }
149 inline static void
150 _postcode(uint8_t xx)
151 {
152 asm volatile("outb %0, %1" : : "a" (xx), "N" (POSTPORT));
153 }
154 #if DEBUG
155 inline static void
156 postcode(uint8_t xx)
157 {
158 _postcode(xx);
159 #if POSTCODE_DELAY
160 _postcode_delay(SPINCOUNT);
161 #endif
162 }
163 #else
164 #define postcode(xx)
165 #endif
166 #endif
167
168 #endif /* _I386_POSTCODE_H_ */