1 /* $NetBSD: macrom.h,v 1.20 2024/04/18 10:32:03 andvar Exp $ */ 2 3 /*- 4 * Copyright (C) 1994 Bradley A. Grantham 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 29 #include <sys/types.h> 30 #include <machine/frame.h> 31 32 33 /* Low-memory Globals */ 34 extern void * ROMBase; /* Base address of ROM space */ 35 extern void * ADBBase; /* Base address of ADB scratch */ 36 extern void * ADBYMM; /* Base address of yet more ADB mem */ 37 extern void * ADBState; /* Base address of ADB scratch ? */ 38 extern void (*JADBProc)(void); /* ADBReInit pre/post processing */ 39 extern void (*Lvl1DT[8])(void); /* VIA1 interrupt table by bit */ 40 extern void (*Lvl2DT[8])(void); /* VIA2 interrupt table by bit */ 41 extern void (*jADBOp)(void); /* low memory pointer to ADBOp */ 42 extern void (*jUnimplTrap)(void); /* Unimplemented trap */ 43 /* loglob(KbdLast, 0x218) * addr of last kbd to send */ 44 /* loglob(KbdType, 0x21E) * type of last kbd to send */ 45 extern void (*JKybdTask)(void); /* Keyboard task ptr? */ 46 extern u_char CPUFlag; /* Type of CPU in this machine */ 47 extern void (*MacJmp)(void); /* ??? */ 48 extern u_long Lo3Bytes; /* 0x00ffffff */ 49 extern u_long MinusOne; /* 0xffffffff */ 50 extern u_short MMU32Bit; /* MMU mode; short? */ 51 extern u_char Scratch8[8]; /* 8-byte scratch */ 52 extern u_char Scratch20[20]; /* 20-byte scratch */ 53 extern u_long Ticks; /* ticks since startup */ 54 extern u_long Time; /* ticks since startup */ 55 extern u_short TimeDBRA; /* DBRA's per milli */ 56 extern u_short ADBDelay; /* DBRAs per ADB loop, / 8 */ 57 extern u_char ToolScratch[8]; /* Yet another 8-byte scratch area */ 58 extern void * VIA; /* VIA1 base address */ 59 extern void * mrg_VIA2; /* VIA2 base address */ 60 extern void * SCCRd; /* SCC read base address */ 61 extern u_char FinderName[20]; /* FinderName - Pascal string */ 62 extern void (*jSwapMMU)(void); /* Pointer to MMU Swap routine */ 63 extern void (*jEgret)(void); /* Pointer to MMU Swap routine */ 64 extern u_int16_t HwCfgFlags; /* Hardware config flags */ 65 extern u_int32_t HwCfgFlags2; /* more hardware config flags */ 66 extern u_int32_t HwCfgFlags3; /* more hardware config flags */ 67 extern u_int32_t ADBReInit_JTBL; /* pointer to patch table */ 68 extern void (*jClkNoMem)(void); /* pointer to ClkNoMem */ 69 extern u_char SysParam[20]; /* Place where PRam data gets stored */ 70 extern void * ExpandMem; /* pointer to Expanded Memory used by */ 71 /* newer ADB routines (since LCIII) */ 72 extern u_int16_t VBLQueue; /* Vertical blanking Queue, unused ? */ 73 extern void * VBLQueue_head; /* Vertical blanking Queue, head */ 74 extern void * VBLQueue_tail; /* Vertical blanking Queue, tail */ 75 extern void * jDTInstall; /* Deferred task mgr trap handler */ 76 77 extern u_int32_t **InitEgretJTVec; /* pointer to a jump table for */ 78 /* InitEgret on AV machines */ 79 80 /* Types */ 81 82 typedef void *Ptr; 83 typedef void **Handle; 84 85 /* ADB Manager */ 86 typedef struct { 87 Ptr siServiceRtPtr; 88 Ptr siDataAreaAddr; 89 } ADBSetInfoBlock; 90 typedef struct { 91 unsigned char devType; 92 unsigned char origADBAddr; 93 Ptr dbServiceRtPtr; 94 Ptr dbDataAreaAddr; 95 } ADBDataBlock; 96 97 98 /* Trap Flesh; these functions are C, not Pascal */ 99 100 /* trap tests */ 101 int MyOwnTrap(void); 102 void KnownRTS(void); 103 104 #ifdef MRG_ADB 105 /* 106 * These functions are defined in adb_direct.c if we are not using 107 * the MRG method of accessing the ADB/PRAM/RTC. 108 */ 109 /* ADB Manager */ 110 int SetADBInfo(ADBSetInfoBlock *, int); 111 int CountADBs(void); 112 int GetIndADB(ADBDataBlock *, int); 113 int GetADBInfo(ADBDataBlock *, int); 114 void ADBReInit(void); 115 /* note different order of parameters */ 116 int ADBOp(Ptr, Ptr, Ptr, short); 117 void ADBAlternateInit(void); 118 #endif 119 120 /* Memory Manager */ 121 Ptr NewPtr(int); 122 int DisposPtr(Ptr); 123 int GetPtrSize(Ptr); 124 int SetPtrSize(Ptr, int); 125 126 /* Resource Manager */ 127 Handle GetResource(u_int, short); 128 short ResError(void); 129 short mrg_CountResources(u_int32_t); 130 short Count_Resources(u_int32_t); 131 void * *mrg_GetIndResource(u_int16_t, u_int32_t); 132 133 134 /* Mac ROM Glue globals for BSD kernel */ 135 extern void *mrg_romadbintr; 136 extern void *mrg_ADBIntrPtr; 137 extern u_char mrg_GetResource[]; /* type is almost a lie; 138 call it an array of bytes of code */ 139 extern u_char mrg_ResError[]; 140 141 142 /* MacOS Error Codes */ 143 #define noErr 0 144 #define memFullErr -108 145 #define memWZErr -111 146 #define resNotFound -192 147 148 149 /* Dump instruction trace */ 150 void dumptrace(void); 151 152 153 /* Stuff for configuring ROM Glue */ 154 typedef struct rsrc_s { 155 u_int16_t unknown[4]; /* ???? */ 156 u_int32_t next; /* pointer to next resource in list */ 157 u_int32_t body; /* pointer to resource body? */ 158 u_int32_t name; /* resource name */ 159 u_int16_t index; /* ???? */ 160 } rsrc_t; 161 162 typedef struct romvec_s { 163 const char *romident; /* just to print it out */ 164 void *adbintr; /* where is ADB interrupt */ 165 void *pmintr; /* where is ADB/PM interrupt, on machines */ 166 /* that have it */ 167 void *adb130intr; /* ADBBase[0x130] interrupt; don't know */ 168 /* what it is, but it's important. Don't */ 169 /* you love reverse engineering? */ 170 void *CountADBs; 171 void *GetIndADB; 172 void *GetADBInfo; 173 void *SetADBInfo; 174 void *ADBReInit; 175 void *ADBOp; 176 void *PMgrOp; /* On machines that have it */ 177 void *WriteParam; 178 void *SetDateTime; 179 void *InitUtil; 180 void *ReadXPRam; 181 void *WriteXPRam; 182 void *jClkNoMem; 183 void *ADBAlternateInit; /* more fundamental than ABDReInit */ 184 void *Egret; 185 void *InitEgret; /* Set up Buffer for Egret routines */ 186 void *ADBReInit_JTBL; 187 void *ROMResourceMap; /* Address of first Resource in linked list */ 188 void *FixDiv; 189 void *FixMul; 190 } romvec_t; 191 192 /* 193 * Function prototypes. 194 */ 195 196 /* macrom.c */ 197 void mrg_setvectors(romvec_t *); 198 int mrg_romready(void); 199 void * *Get_Ind_Resource(u_int32_t, u_int16_t); 200 void mrg_initadbintr(void); 201 long mrg_adbintr(void); 202 long mrg_pmintr(void); 203 void mrg_fixupROMBase(void *, void *); 204 int mrg_Delay(void); 205 void mrg_DTInstall(void); 206 void mrg_execute_deferred(void); 207 void mrg_VBLQueue(void); 208 void mrg_init_stub_1(void); 209 void mrg_init_stub_2(void); 210 void mrg_1sec_timer_tick(void); 211 void mrg_lvl1dtpanic(void); 212 void mrg_lvl2dtpanic(void); 213 void mrg_jadbprocpanic(void); 214 void mrg_jswapmmupanic(void); 215 void mrg_jkybdtaskpanic(void); 216 void mrg_notrap(void); 217 int myowntrap(void); 218 int mrg_NewPtr(void); 219 int mrg_DisposPtr(void); 220 int mrg_GetPtrSize(void); 221 int mrg_SetPtrSize(void); 222 int mrg_PostEvent(void); 223 int mrg_SetTrapAddress(void); 224 void mrg_StripAddress(void); 225 void mrg_aline_super(struct frame *); 226 void mrg_init(void); 227 void mrg_FixDiv(void); 228 void mrg_FixMul(void); 229 230 /* machdep.c */ 231 int mach_cputype(void); 232 233 /* Tracing aids */ 234 235 /* trace all instructions, not just flow changes. */ 236 #define tron() \ 237 __asm("movw %%sr, %%d0 ; orw #0x8000, %%d0 ; movw %%d0, %%sr" : : : "d0") 238 #define troff() \ 239 __asm("movw %%sr, %%d0 ; andw #0x3fff, %%d0 ; movw %%d0, %%sr" : : : "d0") 240