Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / doscmd / ems.h
1 /*-
2  * Copyright (c) 1997 Helmut Wirth <hfwirth@ping.at>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice immediately at the beginning of the file, witout modification,
10  *    this list of conditions, and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD: src/usr.bin/doscmd/ems.h,v 1.3 1999/08/28 01:00:13 peter Exp $
29  */
30
31 #ifndef EMS_H
32 #define EMS_H
33
34 /* Header for ems.c, the EMS emulation */
35
36 /* Global definitions, some of them will be configurable in the future */
37
38 #define EMS_NUM_HANDLES         256             /* Includes OS handle 0 */
39 #define EMS_MAXSIZE             10240           /* In kbytes */
40 #define EMS_MAX_PHYS            4               /* Frame is 64kB */
41 #define EMS_FRAME_ADDR          0xe0000
42 #define EMS_VERSION             0x40            /* Version 4.0 */
43 #define EMS_PAGESIZE            (16 *1024)      /* page size in bytes */
44 #define EMS_SAVEMAGIC           0xAFFE          /* magic number */
45
46 /* These are the LIM EMS 3.0 calls */
47 #define GET_MANAGER_STATUS      0x40    
48 #define GET_PAGE_FRAME_SEGMENT  0x41    
49 #define GET_PAGE_COUNTS         0x42    
50 #define GET_HANDLE_AND_ALLOCATE 0x43    
51 #define MAP_UNMAP               0x44    
52 #define DEALLOCATE_HANDLE       0x45    
53 #define GET_EMM_VERSION         0x46    
54 #define SAVE_PAGE_MAP           0x47    
55 #define RESTORE_PAGE_MAP        0x48    
56 #define RESERVED_1              0x49    
57 #define RESERVED_2              0x4a    
58 #define GET_HANDLE_COUNT        0x4b    
59 #define GET_PAGES_OWNED         0x4c    
60 #define GET_PAGES_FOR_ALL       0x4d    
61
62 /* LIM EMS 4.0 calls */
63 /* Global subfunctions for the LIM EMS 4.0 calls */
64 #define GET                     0x0
65 #define SET                     0x1
66 /* Modes for Map/Unmap and AlterandCall/AlterAndJump */
67 #define PHYS_ADDR               0x0
68 #define SEG_ADDR                0x0
69
70 /* Page map functions */
71 #define PAGE_MAP                0x4e
72 #define PAGE_MAP_PARTIAL        0x4f
73 /* Page map subfunctions */
74 #define GET_SET                 0x2
75 #define GET_SIZE                0x3
76
77 #define MAP_UNMAP_MULTI_HANDLE  0x50
78
79 #define REALLOC_PAGES           0x51
80
81 #define HANDLE_ATTRIBUTES       0x52
82 /* Subfunctions */
83 #define HANDLE_CAPABILITY       0x2
84
85 #define HANDLE_NAME             0x53
86
87 #define HANDLE_DIRECTORY        0x54
88 #define HANDLE_SEARCH           0x1
89 #define GET_TOTAL_HANDLES       0x2
90
91 #define ALTER_PAGEMAP_JUMP      0x55
92 #define ALTER_PAGEMAP_CALL      0x56
93 /* Subfunction for call */
94 #define GET_STACK_SIZE          0x2
95
96 #define MOVE_MEMORY_REGION      0x57
97 /* Subfunctions */
98 #define MOVE                    0x0
99 #define EXCHANGE                0x1
100
101 #define GET_MAPPABLE_PHYS_ADDR  0x58
102 /* Subfunctions */
103 #define GET_ARRAY               0x0
104 #define GET_ARRAY_ENTRIES       0x1
105
106 #define GET_HW_CONFIGURATION    0x59
107 /* Subfunctions */
108 #define GET_HW_ARRAY            0x0
109 #define GET_RAW_PAGE_COUNT      0x1
110
111 #define ALLOCATE_PAGES          0x5a
112 /* Subfunctions */
113 #define ALLOC_STANDARD          0x0
114 #define ALLOC_RAW               0x1
115
116 #define ALTERNATE_MAP_REGISTER  0x5b
117 /* Subfunctions */
118 #define GET_SAVE_ARRAY_SIZE     0x2
119 #define ALLOCATE_REGISTER_SET   0x3
120 #define DEALLOCATE_REGISTER_SET 0x4
121 #define ALLOCATE_DMA            0x5
122 #define ENABLE_DMA              0x6
123 #define DISABLE_DMA             0x7
124 #define DEALLOCATE_DMA          0x8
125
126 #define PREPARE_WARMBOOT        0x5c
127
128 #define OS_FUNCTION_SET         0x5d
129 /* Subfunctions */
130 #define ENABLE                  0x0
131 #define DISABLE                 0x1
132 #define RETURN_KEY              0x2
133
134 /* End of call definitions */
135
136 /* EMS errors */
137
138 #define EMS_SUCCESS             0x0
139 #define EMS_SW_MALFUNC          0x80
140 #define EMS_HW_MALFUNC          0x81
141 #define EMS_INV_HANDLE          0x83
142 #define EMS_FUNC_NOSUP          0x84
143 #define EMS_OUT_OF_HANDLES      0x85
144 #define EMS_SAVED_MAP           0x86
145 #define EMS_OUT_OF_PHYS         0x87
146 #define EMS_OUT_OF_LOG          0x88
147 #define EMS_ZERO_PAGES          0x89
148 #define EMS_LOGPAGE_TOOBIG      0x8a
149 #define EMS_ILL_PHYS            0x8b
150 #define EMS_NO_ROOM_TO_SAVE     0x8c
151 #define EMS_ALREADY_SAVED       0x8d
152 #define EMS_NO_SAVED_CONTEXT    0x8e
153 #define EMS_INVALID_SUB         0x8f
154 #define EMS_INVALID_ATTR        0x90
155 #define EMS_FEAT_NOSUP          0x91
156 #define EMS_MOVE_OVERLAP1       0x92
157 #define EMS_MOVE_OVERFLOW       0x93
158 #define EMS_PAGEOFFSET          0x95
159 #define EMS_MOVE_OVERLAP2       0x97
160 #define EMS_HNAME_NOT_FOUND     0xa0
161 #define EMS_NAME_EXISTS         0xa1
162 #define EMS_SAVED_CONTEXT_BAD   0xa3
163 #define EMS_FUNCTION_DISABLED   0xa4
164
165 /*
166  * EMS handles: The handle contains at its end an array of pointers to
167  * its allocated pages. The array is of size npages. Handle structs are
168  * malloced at runtime.
169  * Page numbering: Every page is 16kB, always. The pages are numbered
170  * from 0 to highest page, depending on total EMS memory. Every handle
171  * has pages allocated and this pages too are numbered from 0 to highest
172  * page allocated. This are *not* the same numbers, because there may be
173  * holes in the allocation.
174  * Page numbers are unsigned short, which will give us 65536 * 16 kB (1GB)
175  * pages to handle at maximum. This should be enough for the next years.
176  */ 
177
178 typedef struct {
179     short handle[4];         /* Handle for each mapping */
180     u_char pos_mapped[4];    /* Boolean value, 1 if something is mapped */
181     u_char pos_pagenum[4];   /* Page number currently mapped into position */
182 } EMS_mapping_context;
183
184
185 /* This union is for copying operations of the handle name only */
186 typedef union {
187     u_char uc_hn[8];
188     u_long ul_hn[2];
189 } Hname;
190
191 typedef struct {
192     Hname   hname;
193     u_long npages;
194     /* The mapping context for save/restore page map */ 
195     EMS_mapping_context *mcontext;    
196     /* The pagenum here is the number in the system page array. The 
197      * logical page number connected with this handle is the index into
198      * this array.
199      */
200     u_short pagenum[0];         
201     /* Will grow here, depending on allocation */
202 } EMS_handle;
203
204 /*
205  * The connection between every page in the system and the handles is
206  * maintained by an array of these structs. The array is indexed by the
207  * page numbers.
208  */
209
210 typedef struct {
211     short handle;       /* The handle this page belongs to */
212 #define EMS_FREE    0
213 #define EMS_ALLOCED 1
214 #define EMS_MAPPED  2
215     u_short status;     /* room for misc information */
216 } EMS_page;
217
218 /*
219  * The combined pointer into EMS memory: offs is the offset into an EMS
220  * page, page is the page index inside the region allocated to a handle.
221  * This depends on EMS_PAGESIZE.
222  * This is used for copy and move operations.
223  */
224
225 typedef struct {
226     u_long offs:14;
227     u_long page:18;
228 } EMS_combi;
229
230 typedef union {
231     u_long    ua_addr;          /* Conventional address pointer */
232     EMS_combi ua_emsaddr;       /* EMS address pointer */
233 } EMS_addr;
234
235 #define EMS_OFFS(u) u.ua_emsaddr.offs
236 #define EMS_PAGE(u) u.ua_emsaddr.page
237 #define EMS_PTR(u) u.ua_addr
238
239 /*
240  * EMS info structure, only used to pass information to and from
241  * DOS 
242  */
243
244 typedef struct {
245     u_short handle __attribute__ ((packed));   /* handle */
246     u_short npages __attribute__ ((packed));   /* pages allocated */
247 } EMShandlepage;
248
249 /*
250  * EMS map/unmap multiple, only used to pass information to and from
251  * DOS 
252  */
253
254 typedef struct {
255     u_short log __attribute__ ((packed));   /* logical page number */
256     u_short phys __attribute__ ((packed));  /* physical page (position) or
257                                               segment address inside frame */
258 } EMSmapunmap;
259
260 /*
261  * EMS handle directory, only used to pass information to and from
262  * DOS 
263  */
264
265 typedef struct {
266    u_short log  __attribute__ ((packed));   /* logical page number */
267    Hname   name __attribute__ ((packed));   /* Handle name */
268
269 } EMShandledir;
270
271 /*
272  * Structure for get/set page map: This structure is used to save and
273  * restore the page map from DOS memory. A program can get the mapping
274  * context and later set (restore) it. To avoid errors we add a magic
275  * number and a checksum.
276  */
277
278 typedef struct {
279    u_short magic;               /* Magic number */
280    u_short checksum;            /* Checksum over entire structure */
281    EMS_mapping_context ems_saved_context;
282 } EMScontext;
283
284 /*
285  * EMS physical address array, only used to pass information to and from
286  * DOS 
287  */
288
289 typedef struct {
290    u_short segm __attribute__ ((packed));  /* segment address inside frame */
291    u_short phys __attribute__ ((packed));  /* physical page (position) */
292 } EMSaddrarray;
293
294 /*
295  * EMS move memory call structure, only used to pass information to and from
296  * DOS 
297  */
298
299 typedef struct {
300    u_long  length __attribute__ ((packed));      /* length of region */
301 #define EMS_MOVE_CONV 0
302 #define EMS_MOVE_EMS  1
303    u_char  src_type __attribute__ ((packed));    /* source type (0,1) */
304    u_short src_handle __attribute__ ((packed));  /* source handle */
305    u_short src_offset __attribute__ ((packed));  /* source offset */
306    u_short src_seg __attribute__ ((packed));     /* source type  */
307    u_char  dst_type __attribute__ ((packed));    /* destination type (0,1) */
308    u_short dst_handle __attribute__ ((packed));  /* destination handle */
309    u_short dst_offset __attribute__ ((packed));  /* destination offset */
310    u_short dst_seg __attribute__ ((packed));     /* destination type  */
311 } EMSmovemem;
312
313 #endif /* EMS_H */