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