ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/macos_util.h
Revision: 1.2
Committed: 2003-09-29T20:30:21Z (21 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.1: +5 -5 lines
Log Message:
first round of little endian fixes

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * macos_util.h - MacOS definitions/utility functions
3     *
4     * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #ifndef MACOS_UTIL_H
22     #define MACOS_UTIL_H
23    
24     #include "cpu_emulation.h"
25    
26    
27     /*
28     * General definitions
29     */
30    
31     struct Point {
32     int16 v;
33     int16 h;
34     };
35    
36     struct Rect {
37     int16 top;
38     int16 left;
39     int16 bottom;
40     int16 right;
41     };
42    
43    
44     /*
45     * Queues
46     */
47    
48     enum { // Queue types
49     dummyType = 0,
50     vType = 1,
51     ioQType = 2,
52     drvQType = 3,
53     evType = 4,
54     fsQType = 5,
55     sIQType = 6,
56     dtQType = 7,
57     nmType = 8
58     };
59    
60     enum { // QElem struct
61     qLink = 0,
62     qType = 4,
63     qData = 6
64     };
65    
66     enum { // QHdr struct
67     qFlags = 0,
68     qHead = 2,
69     qTail = 6
70     };
71    
72    
73     /*
74     * Definitions for Deferred Task Manager
75     */
76    
77     enum { // DeferredTask struct
78     dtFlags = 6,
79     dtAddr = 8,
80     dtParam = 12,
81     dtReserved = 16
82     };
83    
84    
85     /*
86     * Definitions for Device Manager
87     */
88    
89     // Error codes
90     enum {
91     noErr = 0,
92     controlErr = -17, /* I/O System Errors */
93     statusErr = -18, /* I/O System Errors */
94     readErr = -19, /* I/O System Errors */
95     writErr = -20, /* I/O System Errors */
96     badUnitErr = -21, /* I/O System Errors */
97     unitEmptyErr = -22, /* I/O System Errors */
98     openErr = -23, /* I/O System Errors */
99     closErr = -24, /* I/O System Errors */
100     abortErr = -27, /* IO call aborted by KillIO */
101     notOpenErr = -28, /* Driver not open */
102     dskFulErr = -34, /* disk full */
103     nsvErr = -35, /* no such volume */
104     ioErr = -36, /* I/O error (bummers) */
105     bdNamErr = -37, /* bad name */
106     fnOpnErr = -38, /* file not open */
107     eofErr = -39, /* End-of-file encountered */
108     posErr = -40, /* tried to position to before start of file (r/w) */
109     tmfoErr = -42, /* too many files open */
110     fnfErr = -43, /* file not found */
111     wPrErr = -44, /* diskette is write protected. */
112     fLckdErr = -45, /* file is locked */
113     fBsyErr = -47, /* file busy, dir not empty */
114     dupFNErr = -48, /* duplicate filename already exists */
115     paramErr = -50, /* error in user parameter list */
116     rfNumErr = -51, /* bad ioRefNum */
117     permErr = -54, /* permission error */
118     nsDrvErr = -56, /* no such driver number */
119     extFSErr = -58, /* external file system */
120     noDriveErr = -64, /* drive not installed */
121     offLinErr = -65, /* r/w requested for an off-line drive */
122     noNybErr = -66, /* couldn't find 5 nybbles in 200 tries */
123     noAdrMkErr = -67, /* couldn't find valid addr mark */
124     dataVerErr = -68, /* read verify compare failed */
125     badCksmErr = -69, /* addr mark checksum didn't check */
126     badBtSlpErr = -70, /* bad addr mark bit slip nibbles */
127     noDtaMkErr = -71, /* couldn't find a data mark header */
128     badDCksum = -72, /* bad data mark checksum */
129     badDBtSlp = -73, /* bad data mark bit slip nibbles */
130     wrUnderrun = -74, /* write underrun occurred */
131     cantStepErr = -75, /* step handshake failed */
132     tk0BadErr = -76, /* track 0 detect doesn't change */
133     initIWMErr = -77, /* unable to initialize IWM */
134     twoSideErr = -78, /* tried to read 2nd side on a 1-sided drive */
135     spdAdjErr = -79, /* unable to correctly adjust disk speed */
136     seekErr = -80, /* track number wrong on address mark */
137     sectNFErr = -81, /* sector number never found on a track */
138     fmt1Err = -82, /* can't find sector 0 after track format */
139     fmt2Err = -83, /* can't get enough sync */
140     verErr = -84, /* track failed to verify */
141     memFullErr = -108,
142     dirNFErr = -120 /* directory not found */
143     };
144    
145     // Misc constants
146     enum {
147     goodbye = -1, /* heap being reinitialized */
148    
149     ioInProgress = 1, /* predefined value of ioResult while I/O is pending */
150     aRdCmd = 2, /* low byte of ioTrap for Read calls */
151     aWrCmd = 3, /* low byte of ioTrap for Write calls */
152     asyncTrpBit = 10, /* trap word modifier */
153     noQueueBit = 9, /* trap word modifier */
154    
155     dReadEnable = 0, /* set if driver responds to read requests */
156     dWritEnable = 1, /* set if driver responds to write requests */
157     dCtlEnable = 2, /* set if driver responds to control requests */
158     dStatEnable = 3, /* set if driver responds to status requests */
159     dNeedGoodBye = 4, /* set if driver needs time for performing periodic tasks */
160     dNeedTime = 5, /* set if driver needs time for performing periodic tasks */
161     dNeedLock = 6, /* set if driver must be locked in memory as soon as it is opened */
162    
163     dOpened = 5, /* driver is open */
164     dRAMBased = 6, /* dCtlDriver is a handle (1) or pointer (0) */
165     drvrActive = 7, /* driver is currently processing a request */
166    
167     rdVerify = 64,
168    
169     fsCurPerm = 0, // Whatever is currently allowed
170     fsRdPerm = 1, // Exclusive read
171     fsWrPerm = 2, // Exclusive write
172     fsRdWrPerm = 3, // Exclusive read/write
173     fsRdWrShPerm = 4, // Shared read/write
174    
175     fsAtMark = 0, // At current mark
176     fsFromStart = 1, // Set mark rel to BOF
177     fsFromLEOF = 2, // Set mark rel to logical EOF
178     fsFromMark = 3, // Set mark rel to current mark
179    
180     sony = 0,
181     hard20 = 1
182     };
183    
184     enum { /* Large Volume Constants */
185     kWidePosOffsetBit = 8,
186     kMaximumBlocksIn4GB = 0x007FFFFF
187     };
188    
189     enum { // IOParam struct
190     ioTrap = 6,
191     ioCmdAddr = 8,
192     ioCompletion = 12,
193     ioResult = 16,
194     ioNamePtr = 18,
195     ioVRefNum = 22,
196     ioRefNum = 24,
197     ioVersNum = 26,
198     ioPermssn = 27,
199     ioMisc = 28,
200     ioBuffer = 32,
201     ioReqCount = 36,
202     ioActCount = 40,
203     ioPosMode = 44,
204     ioPosOffset = 46,
205     ioWPosOffset = 46, // Wide positioning offset when ioPosMode has kWidePosOffsetBit set
206     SIZEOF_IOParam = 50
207     };
208    
209     enum { // CntrlParam struct
210     csCode = 26,
211     csParam = 28
212     };
213    
214     enum { // DrvSts struct
215     dsTrack = 0,
216     dsWriteProt = 2,
217     dsDiskInPlace = 3,
218     dsInstalled = 4,
219     dsSides = 5,
220     dsQLink = 6,
221     dsQType = 10,
222     dsQDrive = 12,
223     dsQRefNum = 14,
224     dsQFSID = 16,
225     dsTwoSideFmt = 18,
226     dsNewIntf = 19,
227     dsDiskErrs = 20,
228     dsMFMDrive = 22,
229     dsMFMDisk = 23,
230     dsTwoMegFmt = 24
231     };
232    
233     enum { // DrvSts2 struct
234     dsDriveSize = 18,
235     dsDriveS1 = 20,
236     dsDriveType = 22,
237     dsDriveManf = 24,
238     dsDriveChar = 26,
239     dsDriveMisc = 28,
240     SIZEOF_DrvSts = 30
241     };
242    
243     enum { // DCtlEntry struct
244     dCtlDriver = 0,
245     dCtlFlags = 4,
246     dCtlQHdr = 6,
247     dCtlPosition = 16,
248     dCtlStorage = 20,
249     dCtlRefNum = 24,
250     dCtlCurTicks = 26,
251     dCtlWindow = 30,
252     dCtlDelay = 34,
253     dCtlEMask = 36,
254     dCtlMenu = 38,
255     dCtlSlot = 40,
256     dCtlSlotId = 41,
257     dCtlDevBase = 42,
258     dCtlOwner = 46,
259     dCtlExtDev = 50,
260     dCtlFillByte = 51,
261     dCtlNodeID = 52
262     };
263    
264    
265     /*
266     * Definitions for native Device Manager
267     */
268    
269     // Registry EntryID
270     struct RegEntryID {
271     uint32 contents[4];
272     };
273    
274     // Command codes
275     enum {
276     kOpenCommand = 0,
277     kCloseCommand = 1,
278     kReadCommand = 2,
279     kWriteCommand = 3,
280     kControlCommand = 4,
281     kStatusCommand = 5,
282     kKillIOCommand = 6,
283     kInitializeCommand = 7, /* init driver and device*/
284     kFinalizeCommand = 8, /* shutdown driver and device*/
285     kReplaceCommand = 9, /* replace an old driver*/
286     kSupersededCommand = 10, /* prepare to be replaced by a new driver*/
287     kSuspendCommand = 11, /* prepare driver to go to sleep*/
288     kResumeCommand = 12 /* wake up sleeping driver*/
289     };
290    
291     // Command kinds
292     enum {
293     kSynchronousIOCommandKind = 0x00000001,
294     kAsynchronousIOCommandKind = 0x00000002,
295     kImmediateIOCommandKind = 0x00000004
296     };
297    
298    
299     /*
300     * Definitions for Mixed Mode Manager
301     */
302    
303     typedef uint32 ProcInfoType;
304     typedef int8 ISAType;
305     typedef uint16 RoutineFlagsType;
306     typedef long (*ProcPtr)();
307     typedef uint8 RDFlagsType;
308    
309     struct RoutineRecord {
310     ProcInfoType procInfo; /* calling conventions */
311     int8 reserved1; /* Must be 0 */
312     ISAType ISA; /* Instruction Set Architecture */
313     RoutineFlagsType routineFlags; /* Flags for each routine */
314     ProcPtr procDescriptor; /* Where is the thing weĠre calling? */
315     uint32 reserved2; /* Must be 0 */
316     uint32 selector; /* For dispatched routines, the selector */
317     };
318    
319     struct RoutineDescriptor {
320     uint16 goMixedModeTrap; /* Our A-Trap */
321     int8 version; /* Current Routine Descriptor version */
322     RDFlagsType routineDescriptorFlags; /* Routine Descriptor Flags */
323     uint32 reserved1; /* Unused, must be zero */
324     uint8 reserved2; /* Unused, must be zero */
325     uint8 selectorInfo; /* If a dispatched routine, calling convention, else 0 */
326     uint16 routineCount; /* Number of routines in this RD */
327     RoutineRecord routineRecords[1]; /* The individual routines */
328     };
329    
330     #define BUILD_PPC_ROUTINE_DESCRIPTOR(procInfo, procedure) \
331     { \
332 gbeauche 1.2 htons(0xAAFE), /* Mixed Mode A-Trap */ \
333 cebix 1.1 7, /* version */ \
334     0, /* RD Flags - not dispatched */ \
335     0, /* reserved 1 */ \
336     0, /* reserved 2 */ \
337     0, /* selector info */ \
338     0, /* number of routines */ \
339     { /* It's an array */ \
340     { /* It's a struct */ \
341 gbeauche 1.2 htonl(procInfo), /* the ProcInfo */ \
342 cebix 1.1 0, /* reserved */ \
343     1, /* ISA and RTA */ \
344 gbeauche 1.2 htons(0 | /* Flags - it's absolute addr */\
345 cebix 1.1 0 | /* It's prepared */ \
346 gbeauche 1.2 4 ), /* Always use native ISA */ \
347     (ProcPtr)htonl((uint32)procedure), /* the procedure */ \
348 cebix 1.1 0, /* reserved */ \
349     0 /* Not dispatched */ \
350     } \
351     } \
352     }
353    
354    
355     // Functions
356     extern void MacOSUtilReset(void);
357     extern void Enqueue(uint32 elem, uint32 list); // Enqueue QElem to list
358     extern int FindFreeDriveNumber(int num); // Find first free drive number, starting at "num"
359     extern void MountVolume(void *fh); // Mount volume with given file handle (see sys.h)
360     extern void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size); // Calculate disk image file layout given file size and first 256 data bytes
361     extern void *FindLibSymbol(char *lib, char *sym); // Find symbol in shared library
362     extern void InitCallUniversalProc(void); // Init CallUniversalProc()
363     extern long CallUniversalProc(void *upp, uint32 info); // CallUniversalProc()
364     extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time
365    
366     // Construct four-character-code from string
367     #define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))
368    
369     // Emulator identification codes (4 and 2 characters)
370     const uint32 EMULATOR_ID_4 = 0x62616168; // 'baah'
371     const uint16 EMULATOR_ID_2 = 0x6261; // 'ba'
372    
373     // Test if basic MacOS initializations (of the ROM) are done
374     static inline bool HasMacStarted(void)
375     {
376     return ReadMacInt32(0xcfc) == FOURCC('W','L','S','C'); // Mac warm start flag
377     }
378    
379     #endif