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