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