2 * Copyright (c) 1997 Helmut Wirth <hfwirth@ping.at>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 * $FreeBSD: src/usr.bin/doscmd/ems.h,v 1.3 1999/08/28 01:00:13 peter Exp $
34 /* Header for ems.c, the EMS emulation */
36 /* Global definitions, some of them will be configurable in the future */
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 */
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
62 /* LIM EMS 4.0 calls */
63 /* Global subfunctions for the LIM EMS 4.0 calls */
66 /* Modes for Map/Unmap and AlterandCall/AlterAndJump */
70 /* Page map functions */
72 #define PAGE_MAP_PARTIAL 0x4f
73 /* Page map subfunctions */
77 #define MAP_UNMAP_MULTI_HANDLE 0x50
79 #define REALLOC_PAGES 0x51
81 #define HANDLE_ATTRIBUTES 0x52
83 #define HANDLE_CAPABILITY 0x2
85 #define HANDLE_NAME 0x53
87 #define HANDLE_DIRECTORY 0x54
88 #define HANDLE_SEARCH 0x1
89 #define GET_TOTAL_HANDLES 0x2
91 #define ALTER_PAGEMAP_JUMP 0x55
92 #define ALTER_PAGEMAP_CALL 0x56
93 /* Subfunction for call */
94 #define GET_STACK_SIZE 0x2
96 #define MOVE_MEMORY_REGION 0x57
101 #define GET_MAPPABLE_PHYS_ADDR 0x58
103 #define GET_ARRAY 0x0
104 #define GET_ARRAY_ENTRIES 0x1
106 #define GET_HW_CONFIGURATION 0x59
108 #define GET_HW_ARRAY 0x0
109 #define GET_RAW_PAGE_COUNT 0x1
111 #define ALLOCATE_PAGES 0x5a
113 #define ALLOC_STANDARD 0x0
114 #define ALLOC_RAW 0x1
116 #define ALTERNATE_MAP_REGISTER 0x5b
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
126 #define PREPARE_WARMBOOT 0x5c
128 #define OS_FUNCTION_SET 0x5d
132 #define RETURN_KEY 0x2
134 /* End of call definitions */
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
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.
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;
185 /* This union is for copying operations of the handle name only */
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
201 /* Will grow here, depending on allocation */
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
211 short handle; /* The handle this page belongs to */
213 #define EMS_ALLOCED 1
215 u_short status; /* room for misc information */
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.
231 u_long ua_addr; /* Conventional address pointer */
232 EMS_combi ua_emsaddr; /* EMS address pointer */
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
240 * EMS info structure, only used to pass information to and from
245 u_short handle __attribute__ ((packed)); /* handle */
246 u_short npages __attribute__ ((packed)); /* pages allocated */
250 * EMS map/unmap multiple, only used to pass information to and from
255 u_short log __attribute__ ((packed)); /* logical page number */
256 u_short phys __attribute__ ((packed)); /* physical page (position) or
257 segment address inside frame */
261 * EMS handle directory, only used to pass information to and from
266 u_short log __attribute__ ((packed)); /* logical page number */
267 Hname name __attribute__ ((packed)); /* Handle name */
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.
279 u_short magic; /* Magic number */
280 u_short checksum; /* Checksum over entire structure */
281 EMS_mapping_context ems_saved_context;
285 * EMS physical address array, only used to pass information to and from
290 u_short segm __attribute__ ((packed)); /* segment address inside frame */
291 u_short phys __attribute__ ((packed)); /* physical page (position) */
295 * EMS move memory call structure, only used to pass information to and from
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 */