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