- Update address of Free Software Foundation.
[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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20
21 #ifndef __ARCH_H
22 #define __ARCH_H
23
24 #ifdef _M_AMD64
25 #include <arch/amd64/amd64.h>
26 #endif
27
28 #if defined (_M_IX86)
29 /* Defines needed for switching between real and protected mode */
30 #define NULL_DESC 0x00 /* NULL descriptor */
31 #define PMODE_CS 0x08 /* PMode code selector, base 0 limit 4g */
32 #define PMODE_DS 0x10 /* PMode data selector, base 0 limit 4g */
33 #define RMODE_CS 0x18 /* RMode code selector, base 0 limit 64k */
34 #define RMODE_DS 0x20 /* RMode data selector, base 0 limit 64k */
35 #endif
36
37 #define CR0_PE_SET 0x00000001 /* OR this value with CR0 to enable pmode */
38 #define CR0_PE_CLR 0xFFFFFFFE /* AND this value with CR0 to disable pmode */
39
40 #define STACK16ADDR 0x7000 /* The 16-bit stack top will be at 0000:7000 */
41 #define STACK32ADDR 0x78000 /* The 32-bit stack top will be at 7000:8000, or 0x78000 */
42
43 #if defined (_M_IX86) || defined (_M_AMD64)
44 #define BIOSCALLBUFFER 0x78000 /* Buffer to store temporary data for any Int386() call */
45 #define BIOSCALLBUFSEGMENT 0x7800 /* Buffer to store temporary data for any Int386() call */
46 #define BIOSCALLBUFOFFSET 0x0000 /* Buffer to store temporary data for any Int386() call */
47 #define FILESYSBUFFER 0x80000 /* Buffer to store file system data (e.g. cluster buffer for FAT) */
48 #define DISKREADBUFFER 0x90000 /* Buffer to store data read in from the disk via the BIOS */
49 #define DISKREADBUFFER_SIZE 512
50 #elif defined(_M_PPC) || defined(_M_MIPS) || defined(_M_ARM)
51 #define DISKREADBUFFER 0x80000000
52 #define FILESYSBUFFER 0x80000000
53 #endif
54
55 /* Makes "x" a global variable or label */
56 #define EXTERN(x) .global x; x:
57
58
59
60
61 #ifndef ASM
62
63 #include <pshpack1.h>
64 typedef struct
65 {
66 unsigned long eax;
67 unsigned long ebx;
68 unsigned long ecx;
69 unsigned long edx;
70
71 unsigned long esi;
72 unsigned long edi;
73
74 unsigned short ds;
75 unsigned short es;
76 unsigned short fs;
77 unsigned short gs;
78
79 unsigned long eflags;
80
81 } DWORDREGS;
82
83 typedef struct
84 {
85 unsigned short ax, _upper_ax;
86 unsigned short bx, _upper_bx;
87 unsigned short cx, _upper_cx;
88 unsigned short dx, _upper_dx;
89
90 unsigned short si, _upper_si;
91 unsigned short di, _upper_di;
92
93 unsigned short ds;
94 unsigned short es;
95 unsigned short fs;
96 unsigned short gs;
97
98 unsigned short flags, _upper_flags;
99
100 } WORDREGS;
101
102 typedef struct
103 {
104 unsigned char al;
105 unsigned char ah;
106 unsigned short _upper_ax;
107 unsigned char bl;
108 unsigned char bh;
109 unsigned short _upper_bx;
110 unsigned char cl;
111 unsigned char ch;
112 unsigned short _upper_cx;
113 unsigned char dl;
114 unsigned char dh;
115 unsigned short _upper_dx;
116
117 unsigned short si, _upper_si;
118 unsigned short di, _upper_di;
119
120 unsigned short ds;
121 unsigned short es;
122 unsigned short fs;
123 unsigned short gs;
124
125 unsigned short flags, _upper_flags;
126
127 } BYTEREGS;
128
129
130 typedef union
131 {
132 DWORDREGS x;
133 DWORDREGS d;
134 WORDREGS w;
135 BYTEREGS b;
136 } REGS;
137 #include <poppack.h>
138
139 // Int386()
140 //
141 // Real mode interrupt vector interface
142 //
143 // (E)FLAGS can *only* be returned by this function, not set.
144 // Make sure all memory pointers are in SEG:OFFS format and
145 // not linear addresses, unless the interrupt handler
146 // specifically handles linear addresses.
147 int Int386(int ivec, REGS* in, REGS* out);
148
149 // Flag Masks
150 #define I386FLAG_CF 0x0001 // Carry Flag
151 #define I386FLAG_RESV1 0x0002 // Reserved - Must be 1
152 #define I386FLAG_PF 0x0004 // Parity Flag
153 #define I386FLAG_RESV2 0x0008 // Reserved - Must be 0
154 #define I386FLAG_AF 0x0010 // Auxiliary Flag
155 #define I386FLAG_RESV3 0x0020 // Reserved - Must be 0
156 #define I386FLAG_ZF 0x0040 // Zero Flag
157 #define I386FLAG_SF 0x0080 // Sign Flag
158 #define I386FLAG_TF 0x0100 // Trap Flag (Single Step)
159 #define I386FLAG_IF 0x0200 // Interrupt Flag
160 #define I386FLAG_DF 0x0400 // Direction Flag
161 #define I386FLAG_OF 0x0800 // Overflow Flag
162
163 // This macro tests the Carry Flag
164 // If CF is set then the call failed (usually)
165 #define INT386_SUCCESS(regs) ((regs.x.eflags & I386FLAG_CF) == 0)
166
167 void EnableA20(void);
168
169 VOID ChainLoadBiosBootSectorCode(VOID); // Implemented in boot.S
170 VOID SoftReboot(VOID); // Implemented in boot.S
171
172 VOID DetectHardware(VOID); // Implemented in hardware.c
173
174 #endif /* ! ASM */
175
176
177 #endif // #defined __ARCH_H