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