1/* $NetBSD: mon.h,v 1.6 2023/06/24 05:31:05 msaitoh Exp $ */ 2 3/*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Adam Glass. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* 33 * This file derived from kernel/mach/sun3.md/machMon.h from the 34 * sprite distribution. 35 * 36 * In particular, this file came out of the Walnut Creek cdrom collection 37 * which contained no warnings about any possible copyright infringement. 38 * It was also identical to a file in the sprite kernel tar file found on 39 * allspice.berkeley.edu. 40 * It also written in the annoying sprite coding style. I've made 41 * efforts not to heavily edit their file, just ifdef parts out. -- glass 42 */ 43 44#ifndef _MACHINE_MON_H 45#define _MACHINE_MON_H 46 47/* 48 * machMon.h -- 49 * 50 * Structures, constants and defines for access to the sun monitor. 51 * These are translated from the sun monitor header file "sunromvec.h". 52 * 53 * NOTE: The file keyboard.h in the monitor directory has all sorts of useful 54 * keyboard stuff defined. I haven't attempted to translate that file 55 * because I don't need it. If anyone wants to use it, be my guest. 56 * 57 * Copyright (C) 1985 Regents of the University of California 58 * All rights reserved. 59 * 60 * 61 * Header: /sprite/src/kernel/mach/sun3.md/RCS/machMon.h,v 9.1 62 * 90/10/03 13:52:34 mgbaker Exp SPRITE (Berkeley) 63 */ 64 65/* 66 * Structure set up by the boot command to pass arguments to the program that 67 * is booted. 68 */ 69struct bootparam { 70 char *argPtr[8]; /* String arguments */ 71 char strings[100]; /* String table for string arguments */ 72 char devName[2]; /* Device name */ 73 int ctlrNum; /* Controller number */ 74 int unitNum; /* Unit number */ 75 int partNum; /* Partition/file number */ 76 char *fileName; /* File name, points into strings */ 77 struct boottab *bootDevice; /* Defined in saio.h */ 78} __attribute__((packed)); 79 80/* 81 * This structure defines a segment of physical memory. To support 82 * sparse physical memory, the PROM constructs a linked list of 83 * these at power-on-self-test time. 84 */ 85struct physmemory { 86 u_int address; 87 u_int size; 88 struct physmemory *next; 89}; 90 91/* 92 * Here is the structure of the vector table found at the front of the boot 93 * rom. The functions defined in here are explained below. 94 * 95 * NOTE: This struct has references to the structures keybuf and globram which 96 * I have not translated. If anyone needs to use these they should 97 * translate these structs into Sprite format. 98 */ 99struct sunromvec { 100 char *init_SP; /* Initial SP for hardware */ 101 char *init_PC; /* Initial PC for hardware */ 102 int *diagberr; /* Bus err handler for diags */ 103 104 /* 105 * Monitor and hardware revision and identification 106 */ 107 108 struct bootparam **bootParam; /* Info for bootstrapped pgm */ 109 u_int *memorySize; /* Usable memory in bytes */ 110 111 /* 112 * Single-character input and output 113 */ 114 115 u_char (*getChar)(void); /* Get char from input source */ 116 int (*putChar)(int); /* Put char to output sink */ 117 int (*mayGet)(void); /* Maybe get char, or -1 */ 118 int (*mayPut)(int); /* Maybe put char, or -1 */ 119 u_char *echo; /* Should getchar echo? */ 120 u_char *inSource; /* Input source selector */ 121 u_char *outSink; /* Output sink selector */ 122#define PROMDEV_KBD 0 /* input from keyboard */ 123#define PROMDEV_SCREEN 0 /* output to screen */ 124#define PROMDEV_TTYA 1 /* in/out to ttya */ 125#define PROMDEV_TTYB 2 /* in/out to ttyb */ 126 127 /* 128 * Keyboard input (scanned by monitor nmi routine) 129 */ 130 131 int (*getKey)(void); /* Get next key if one exists */ 132 int (*initGetKey)(void *); /* Initialize get key */ 133 u_int *translation; /* Kbd translation selector 134 (see keyboard.h in sun 135 monitor code) */ 136 u_char *keyBid; /* Keyboard ID byte */ 137 int *screen_x; /* V2: Screen x pos (R/O) */ 138 int *screen_y; /* V2: Screen y pos (R/O) */ 139 struct keybuf *keyBuf; /* Up/down keycode buffer */ 140 141 /* 142 * Monitor revision level. 143 */ 144 145 char *monId; 146 147 /* 148 * Frame buffer output and terminal emulation 149 */ 150 151 int (*fbWriteChar)(int); /* Write a character to FB */ 152 int *fbAddr; /* Address of frame buffer */ 153 char **font; /* Font table for FB */ 154 /* Quickly write string to FB */ 155 int (*fbWriteStr)(char *, int); 156 157 /* 158 * Reboot interface routine -- resets and reboots system. No return. 159 */ 160 161 int (*reBoot)(const char *); /* e.g. reBoot("xy()vmunix") */ 162 163 /* 164 * Line input and parsing 165 */ 166 167 u_char *lineBuf; /* The line input buffer */ 168 u_char **linePtr; /* Cur pointer into linebuf */ 169 int *lineSize; /* length of line in linebuf */ 170 int (*getLine)(int); /* Get line from user */ 171 u_char (*getNextChar)(void); /* Get next char from linebuf */ 172 u_char (*peekNextChar)(void); /* Peek at next char */ 173 int *fbThere; /* =1 if frame buffer there */ 174 int (*getNum)(void); /* Grab hex num from line */ 175 176 /* 177 * Print formatted output to current output sink 178 */ 179 180 int (*printf)(const char *, ...); /* Like kernel printf */ 181 int (*printHex)(int, int); /* Format N digits in hex */ 182 183 /* 184 * Led stuff 185 */ 186 187 u_char *leds; /* RAM copy of LED register */ 188 int (*setLeds)(int); /* Sets LED's and RAM copy */ 189 190 /* 191 * Non-maskable interrupt (nmi) information 192 */ 193 194 int (*nmiAddr)(void *); /* Addr for level 7 vector */ 195 int (*abortEntry)(void *); /* Entry for keyboard abort */ 196 int *nmiClock; /* Counts up in msec */ 197 198 /* 199 * Frame buffer type: see <sun/fbio.h> 200 */ 201 202 int *fbType; 203 204 /* 205 * Assorted other things 206 */ 207 208 u_int romvecVersion; /* Version # of Romvec */ 209 struct globram *globRam; /* monitor global variables */ 210 void *kbdZscc; /* Addr of keyboard in use */ 211 212 int *keyrInit; /* ms before kbd repeat */ 213 u_char *keyrTick; /* ms between repetitions */ 214 u_int *memoryAvail; /* V1: Main mem usable size */ 215 long *resetAddr; /* where to jump on a reset */ 216 long *resetMap; /* pgmap entry for resetaddr */ 217 /* Really struct pgmapent * */ 218 int (*exitToMon)(void); /* Exit from user program */ 219 u_char **memorybitmap; /* V1: &{0 or &bits} */ 220 221 /**************************************************************** 222 * Note: from here on, things vary per-architecture! 223 ****************************************************************/ 224 union { 225 void *un_pad[8]; /* this determines the size */ 226 struct { 227 /* Set seg in all contexts (ctx, va, sme) */ 228 void (*un3_setcxsegmap)(int, int, int); 229 /* V2: Handler for 'v' cmd */ 230 void (**un3_vector_cmd)(int, char *); 231 } un3; 232 struct { 233 /* V2: Handler for 'v' cmd */ 234 void (**un3x_vector_cmd)(int, char *); 235 /* Address of low memory PTEs (maps at least 4MB) */ 236 int **un3x_lomemptaddr; 237 /* 238 * Address of debug/mon PTEs which map the 2MB space 239 * starting at MON_KDB_BASE, ending at MONEND. 240 */ 241 int **un3x_monptaddr; 242 /* 243 * Address of dvma PTEs. This is a VA that maps the I/O MMU 244 * page table, but only the last part, which corresponds to 245 * the CPU virtual space at MON_DVMA_BASE (see below). 246 */ 247 int **un3x_dvmaptaddr; 248 /* 249 * Physical Address of the debug/mon PTEs found at the 250 * virtual address given by *romVectorPtr->monptaddr; 251 */ 252 int **un3x_monptphysaddr; 253 /* 254 * Address of shadow copy of DVMA PTEs. This is a VA that 255 * maps the PTEs used by the CPU to map the same physical 256 * pages as the I/O MMU into the CPU virtual space starting 257 * at MON_DVMA_BASE, length MON_DVMA_SIZE (see below). 258 */ 259 int **un3x_shadowpteaddr; 260 /* Ptr to memory list for 3/80 */ 261 struct physmemory *un3x_physmemory; 262 } un3x; 263 } mon_un; 264} __attribute__((packed)); 265 266/* 267 * Functions defined in the vector: 268 * 269 * 270 * getChar -- Return the next character from the input source 271 * 272 * u_char getChar() 273 * 274 * putChar -- Write the given character to the output source. 275 * 276 * void putChar(ch) 277 * char ch; 278 * 279 * mayGet -- Maybe get a character from the current input source. Return -1 280 * if don't return a character. 281 * 282 * int mayGet() 283 * 284 * mayPut -- Maybe put a character to the current output source. Return -1 285 * if no character output. 286 * 287 * int mayPut(ch) 288 * char ch; 289 * 290 * getKey -- Returns a key code (if up/down codes being returned), 291 * a byte of ASCII (if that's requested), 292 * NOKEY (if no key has been hit). 293 * 294 * int getKey() 295 * 296 * initGetKey -- Initialize things for get key. 297 * 298 * void initGetKey() 299 * 300 * fbWriteChar -- Write a character to the frame buffer 301 * 302 * void fwritechar(ch) 303 * u_char ch; 304 * 305 * fbWriteStr -- Write a string to the frame buffer. 306 * 307 * void fwritestr(addr,len) 308 * u_char *addr; / * String to be written * / 309 * short len; / * Length of string * / 310 * 311 * getLine -- read the next input line into a global buffer 312 * 313 * getline(echop) 314 * int echop; / * 1 if should echo input, 0 if not * / 315 * 316 * getNextChar -- return the next character from the global line buffer. 317 * 318 * u_char getNextChar() 319 * 320 * peekNextChar -- look at the next character in the global line buffer. 321 * 322 * u_char peekNextChar() 323 * 324 * getNum -- Grab hex num from the global line buffer. 325 * 326 * int getNum() 327 * 328 * printf -- Scaled down version of C library printf. Only %d, %x, %s, and %c 329 * are recognized. 330 * 331 * printhex -- prints rightmost <digs> hex digits of <val> 332 * 333 * printhex(val, digs) 334 * int val; 335 * int digs; 336 * 337 * abortEntry -- Entry for keyboard abort. 338 * 339 * abortEntry() 340 */ 341 342/* 343 * Functions and defines to access the monitor. 344 */ 345 346#define mon_printf (romVectorPtr->printf) 347#define mon_putchar (romVectorPtr->putChar) 348#define mon_may_getchar (romVectorPtr->mayGet) 349#define mon_exit_to_mon (romVectorPtr->exitToMon) 350#define mon_reboot (romVectorPtr->reBoot) 351 352/* 353 * Sun2 specific stuff... 354 */ 355 356/* 357 * MONSTART and MONEND denote the range used by the monitor. 358 * PROM_BASE is the virtual address of the PROM. 359 */ 360#define SUN2_MONSTART 0x00E00000 361#define SUN2_PROM_BASE 0x00EF0000 362#define SUN2_MONEND 0x00F00000 363 364/* 365 * Sun3 specific stuff... 366 */ 367 368#ifdef _SUN3_ 369#define setcxsegmap mon_un.un3.un3_setcxsegmap 370#define vector_cmd mon_un.un3.un3_vector_cmd 371#define romVectorPtr ((struct sunromvec *) SUN3_PROM_BASE) 372#endif /* SUN3 */ 373 374/* 375 * MONSTART and MONEND denote the range used by the monitor. 376 * PROM_BASE is the virtual address of the PROM. 377 */ 378#define SUN3_MONSTART 0x0FE00000 379#define SUN3_PROM_BASE 0x0FEF0000 380#define SUN3_MONEND 0x0FF00000 381 382/* 383 * These describe the monitor's short segment (one it can reach using 384 * short PC-relative addressing) which it uses to map its data page. 385 * MONSHORTPAGE is the page; MONSHORTSEG is the containing segment. 386 * Its mapping must not be removed or the PROM monitor will fail. 387 * MONSHORTPAGE is also where the "ie" puts its SCP. 388 */ 389#define SUN3_MONSHORTPAGE 0x0FFFE000 390#define SUN3_MONSHORTSEG 0x0FFE0000 391 392/* 393 * Sun3X specific stuff... 394 */ 395 396#ifdef _SUN3X_ 397#define vector_cmd mon_un.un3x.un3x_vector_cmd 398#define lomemptaddr mon_un.un3x.un3x_lomemptaddr 399#define monptaddr mon_un.un3x.un3x_monptaddr 400#define dvmaptaddr mon_un.un3x.un3x_dvmaptaddr 401#define monptphysaddr mon_un.un3x.un3x_monptphysaddr 402#define shadowpteaddr mon_un.un3x.un3x_shadowpteaddr 403#define v_physmemory mon_un.un3x.un3x_physmemory 404#define romVectorPtr ((struct sunromvec *) SUN3X_PROM_BASE) 405#endif /* SUN3X */ 406 407/* 408 * We don't have a separate kernel debugger like sun kadb, 409 * but this range is setup by the monitor for such a thing. 410 * We might as well preserve the mappings anyway. 411 */ 412#define SUN3X_MON_KDB_BASE 0xFEE00000 413#define SUN3X_MON_KDB_SIZE 0x100000 414 415/* 416 * MONSTART and MONEND define the range used by the monitor. 417 * MONDATA is its data page (do not touch!) 418 * PROM_BASE is where the boot PROM lives. 419 */ 420#define SUN3X_MONSTART 0xFEF00000 421#define SUN3X_MONDATA 0xFEF72000 422#define SUN3X_PROM_BASE 0xFEFE0000 423#define SUN3X_MONEND 0xFF000000 424 425/* 426 * These define the CPU virtual address range mapped by the 427 * PROM for use as DVMA space. The physical pages mapped in 428 * this range are also mapped by the I/O MMU. Note that the 429 * last page is reserved for the PROM (really for the "ie"). 430 */ 431#define SUN3X_MON_DVMA_BASE 0xFFF00000 432#define SUN3X_MON_DVMA_SIZE 0x100000 /* 1MB */ 433 434#ifdef _STANDALONE 435/* The libsa code uses a pointer... */ 436extern struct sunromvec *_romvec; 437#undef romVectorPtr 438#define romVectorPtr _romvec 439#endif /* _STANDALONE */ 440 441#endif /* _MACHINE_MON_H */ 442