-revert janderwalds change until because it breaks the gcc 4.x build
[reactos.git] / reactos / boot / freeldr / freeldr / include / arch.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #ifndef __ARCH_H
22 #define __ARCH_H
23
24 /* Defines needed for switching between real and protected mode */
25 #define NULL_DESC 0x00 /* NULL descriptor */
26 #define PMODE_CS 0x08 /* PMode code selector, base 0 limit 4g */
27 #define PMODE_DS 0x10 /* PMode data selector, base 0 limit 4g */
28 #define RMODE_CS 0x18 /* RMode code selector, base 0 limit 64k */
29 #define RMODE_DS 0x20 /* RMode data selector, base 0 limit 64k */
30
31 #define CR0_PE_SET 0x00000001 /* OR this value with CR0 to enable pmode */
32 #define CR0_PE_CLR 0xFFFFFFFE /* AND this value with CR0 to disable pmode */
33
34 #define STACK16ADDR 0x7000 /* The 16-bit stack top will be at 0000:7000 */
35 #define STACK32ADDR 0x78000 /* The 32-bit stack top will be at 7000:8000, or 0x78000 */
36
37 #define BIOSCALLBUFFER 0x78000 /* Buffer to store temporary data for any Int386() call */
38 #define BIOSCALLBUFSEGMENT 0x7800 /* Buffer to store temporary data for any Int386() call */
39 #define BIOSCALLBUFOFFSET 0x0000 /* Buffer to store temporary data for any Int386() call */
40 #define FILESYSBUFFER 0x80000 /* Buffer to store file system data (e.g. cluster buffer for FAT) */
41 #define DISKREADBUFFER 0x90000 /* Buffer to store data read in from the disk via the BIOS */
42
43 /* Makes "x" a global variable or label */
44 #define EXTERN(x) .global x; x:
45
46
47
48
49 #ifndef ASM
50
51
52 typedef struct
53 {
54 unsigned long eax;
55 unsigned long ebx;
56 unsigned long ecx;
57 unsigned long edx;
58
59 unsigned long esi;
60 unsigned long edi;
61
62 unsigned short ds;
63 unsigned short es;
64 unsigned short fs;
65 unsigned short gs;
66
67 unsigned long eflags;
68
69 } PACKED DWORDREGS;
70
71 typedef struct
72 {
73 unsigned short ax, _upper_ax;
74 unsigned short bx, _upper_bx;
75 unsigned short cx, _upper_cx;
76 unsigned short dx, _upper_dx;
77
78 unsigned short si, _upper_si;
79 unsigned short di, _upper_di;
80
81 unsigned short ds;
82 unsigned short es;
83 unsigned short fs;
84 unsigned short gs;
85
86 unsigned short flags, _upper_flags;
87
88 } PACKED WORDREGS;
89
90 typedef struct
91 {
92 unsigned char al;
93 unsigned char ah;
94 unsigned short _upper_ax;
95 unsigned char bl;
96 unsigned char bh;
97 unsigned short _upper_bx;
98 unsigned char cl;
99 unsigned char ch;
100 unsigned short _upper_cx;
101 unsigned char dl;
102 unsigned char dh;
103 unsigned short _upper_dx;
104
105 unsigned short si, _upper_si;
106 unsigned short di, _upper_di;
107
108 unsigned short ds;
109 unsigned short es;
110 unsigned short fs;
111 unsigned short gs;
112
113 unsigned short flags, _upper_flags;
114
115 } PACKED BYTEREGS;
116
117 typedef union
118 {
119 DWORDREGS x;
120 DWORDREGS d;
121 WORDREGS w;
122 BYTEREGS b;
123 } REGS;
124
125 // Int386()
126 //
127 // Real mode interrupt vector interface
128 //
129 // (E)FLAGS can *only* be returned by this function, not set.
130 // Make sure all memory pointers are in SEG:OFFS format and
131 // not linear addresses, unless the interrupt handler
132 // specifically handles linear addresses.
133 int Int386(int ivec, REGS* in, REGS* out);
134
135 // Flag Masks
136 #define I386FLAG_CF 0x0001 // Carry Flag
137 #define I386FLAG_RESV1 0x0002 // Reserved - Must be 1
138 #define I386FLAG_PF 0x0004 // Parity Flag
139 #define I386FLAG_RESV2 0x0008 // Reserved - Must be 0
140 #define I386FLAG_AF 0x0010 // Auxiliary Flag
141 #define I386FLAG_RESV3 0x0020 // Reserved - Must be 0
142 #define I386FLAG_ZF 0x0040 // Zero Flag
143 #define I386FLAG_SF 0x0080 // Sign Flag
144 #define I386FLAG_TF 0x0100 // Trap Flag (Single Step)
145 #define I386FLAG_IF 0x0200 // Interrupt Flag
146 #define I386FLAG_DF 0x0400 // Direction Flag
147 #define I386FLAG_OF 0x0800 // Overflow Flag
148
149 // This macro tests the Carry Flag
150 // If CF is set then the call failed (usually)
151 #define INT386_SUCCESS(regs) ((regs.x.eflags & I386FLAG_CF) == 0)
152
153 void EnableA20(void);
154
155 VOID ChainLoadBiosBootSectorCode(VOID); // Implemented in boot.S
156 VOID SoftReboot(VOID); // Implemented in boot.S
157
158 VOID DetectHardware(VOID); // Implemented in hardware.c
159
160 #endif /* ! ASM */
161
162
163 #endif // #defined __ARCH_H