xref: /netbsd-src/sys/arch/sun3/include/mon.h (revision d1b93bab8c7801129a73a508d678c429e8f0fa6a)
1 /*	$NetBSD: mon.h,v 1.30 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  */
69 struct 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  */
85 struct 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  */
99 struct 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 
123 	/*
124 	 * Keyboard input (scanned by monitor nmi routine)
125 	 */
126 
127 	int	(*getKey)(void);	/* Get next key if one exists */
128 	int	(*initGetKey)(void *); /* Initialize get key */
129 	u_int	*translation;		/* Kbd translation selector
130 					   (see keyboard.h in sun
131 					    monitor code) */
132 	u_char	*keyBid;		/* Keyboard ID byte */
133 	int	*screen_x;		/* V2: Screen x pos (R/O) */
134 	int	*screen_y;		/* V2: Screen y pos (R/O) */
135 	struct keybuf	*keyBuf;	/* Up/down keycode buffer */
136 
137 	/*
138 	 * Monitor revision level.
139 	 */
140 
141 	char		*monId;
142 
143 	/*
144 	 * Frame buffer output and terminal emulation
145 	 */
146 
147 	int	(*fbWriteChar)(int); /* Write a character to FB */
148 	int	*fbAddr;		/* Address of frame buffer */
149 	char	**font;			/* Font table for FB */
150 	/* Quickly write string to FB */
151 	int	(*fbWriteStr)(char *buf, int len);
152 
153 	/*
154 	 * Reboot interface routine -- resets and reboots system.  No return.
155 	 */
156 
157 	int	(*reBoot)(const char *);	/* e.g. reBoot("xy()vmunix") */
158 
159 	/*
160 	 * Line input and parsing
161 	 */
162 
163 	u_char	*lineBuf;	/* The line input buffer */
164 	u_char	**linePtr;	/* Cur pointer into linebuf */
165 	int		*lineSize;	/* length of line in linebuf */
166 	int	(*getLine)(int);	/* Get line from user */
167 	u_char	(*getNextChar)(void); /* Get next char from linebuf */
168 	u_char	(*peekNextChar)(void);	/* Peek at next char */
169 	int		*fbThere;		/* =1 if frame buffer there */
170 	int		(*getNum)(void);	/* Grab hex num from line */
171 
172 	/*
173 	 * Print formatted output to current output sink
174 	 */
175 
176 	int	(*printf)(const char *, ...);	/* Like kernel printf */
177 	int	(*printHex)(int, int);	/* Format N digits in hex */
178 
179 	/*
180 	 * Led stuff
181 	 */
182 
183 	u_char	*leds;			/* RAM copy of LED register */
184 	int	(*setLeds)(int);	/* Sets LED's and RAM copy */
185 
186 	/*
187 	 * Non-maskable interrupt  (nmi) information
188 	 */
189 
190 	int	(*nmiAddr)(void *);	/* Addr for level 7 vector */
191 	int	(*abortEntry)(void *); /* Entry for keyboard abort */
192 	int	*nmiClock;		/* Counts up in msec */
193 
194 	/*
195 	 * Frame buffer type: see <sun/fbio.h>
196 	 */
197 
198 	int		*fbType;
199 
200 	/*
201 	 * Assorted other things
202 	 */
203 
204 	u_int	romvecVersion;		/* Version # of Romvec */
205 	struct globram  *globRam;	/* monitor global variables */
206 	void	*kbdZscc;		/* Addr of keyboard in use */
207 
208 	int	*keyrInit;		/* ms before kbd repeat */
209 	u_char	*keyrTick; 		/* ms between repetitions */
210 	u_int	*memoryAvail;		/* V1: Main mem usable size */
211 	long	*resetAddr;		/* where to jump on a reset */
212 	long	*resetMap;		/* pgmap entry for resetaddr */
213 					/* Really struct pgmapent *  */
214 	int	(*exitToMon)(void); /* Exit from user program */
215 	u_char	**memorybitmap;		/* V1: &{0 or &bits} */
216 
217 	/****************************************************************
218 	 * Note: from here on, things vary per-architecture!
219 	 ****************************************************************/
220 	union {
221 		void *un_pad[8]; /* this determines the size */
222 		struct {
223 			/* Set seg in all contexts (ctx, va, sme) */
224 			void	(*un3_setcxsegmap)(int, int, int);
225 			/* V2: Handler for 'v' cmd */
226 			void	(**un3_vector_cmd)(int, char *);
227 		} un3;
228 		struct {
229 			/* V2: Handler for 'v' cmd */
230 			void	(**un3x_vector_cmd)(int, char *);
231 			/* Address of low memory PTEs (maps at least 4MB) */
232 			int	**un3x_lomemptaddr;
233 			/*
234 			 * Address of debug/mon PTEs which map the 2MB space
235 			 * starting at MON_KDB_BASE, ending at MONEND.
236 			 */
237 			int	**un3x_monptaddr;
238 			/*
239 			 * Address of dvma PTEs.  This is a VA that maps the I/O MMU
240 			 * page table, but only the last part, which corresponds to
241 			 * the CPU virtual space at MON_DVMA_BASE (see below).
242 			 */
243 			int	**un3x_dvmaptaddr;
244 			/*
245 			 * Physical Address of the debug/mon PTEs found at the
246 			 * virtual address given by *romVectorPtr->monptaddr;
247 			 */
248 			int	**un3x_monptphysaddr;
249 			/*
250 			 * Address of shadow copy of DVMA PTEs.  This is a VA that
251 			 * maps the PTEs used by the CPU to map the same physical
252 			 * pages as the I/O MMU into the CPU virtual space starting
253 			 * at MON_DVMA_BASE, length MON_DVMA_SIZE (see below).
254 			 */
255 			int	**un3x_shadowpteaddr;
256 			/* Ptr to memory list for 3/80 */
257 			struct physmemory *un3x_physmemory;
258 		} un3x;
259 	} mon_un;
260 } __attribute__((packed));
261 
262 /*
263  * Functions defined in the vector:
264  *
265  *
266  * getChar -- Return the next character from the input source
267  *
268  *     u_char getChar()
269  *
270  * putChar -- Write the given character to the output source.
271  *
272  *     void putChar(ch)
273  *	   char ch;
274  *
275  * mayGet -- Maybe get a character from the current input source.  Return -1
276  *           if don't return a character.
277  *
278  * 	int mayGet()
279  *
280  * mayPut -- Maybe put a character to the current output source.   Return -1
281  *           if no character output.
282  *
283  *	int  mayPut(ch)
284  *	    char ch;
285  *
286  * getKey -- Returns a key code (if up/down codes being returned),
287  * 	     a byte of ASCII (if that's requested),
288  * 	     NOKEY (if no key has been hit).
289  *
290  *	int getKey()
291  *
292  * initGetKey --  Initialize things for get key.
293  *
294  *	void initGetKey()
295  *
296  * fbWriteChar -- Write a character to the frame buffer
297  *
298  *	void fwritechar(ch)
299  *	    u_char ch;
300  *
301  * fbWriteStr -- Write a string to the frame buffer.
302  *
303  *   	void fwritestr(addr,len)
304  *  	    u_char *addr;	/ * String to be written * /
305  *  	    short len;		/ * Length of string * /
306  *
307  * getLine -- read the next input line into a global buffer
308  *
309  *	getline(echop)
310  *          int echop;	/ * 1 if should echo input, 0 if not * /
311  *
312  * getNextChar -- return the next character from the global line buffer.
313  *
314  *	u_char getNextChar()
315  *
316  * peekNextChar -- look at the next character in the global line buffer.
317  *
318  *	u_char peekNextChar()
319  *
320  * getNum -- Grab hex num from the global line buffer.
321  *
322  *	int getNum()
323  *
324  * printf -- Scaled down version of C library printf.  Only %d, %x, %s, and %c
325  * 	     are recognized.
326  *
327  * printhex -- prints rightmost <digs> hex digits of <val>
328  *
329  *      printhex(val, digs)
330  *          int val;
331  *     	    int digs;
332  *
333  * abortEntry -- Entry for keyboard abort.
334  *
335  *     abortEntry()
336  */
337 
338 /*
339  * Functions and defines to access the monitor.
340  */
341 
342 #define mon_printf (romVectorPtr->printf)
343 #define mon_putchar (romVectorPtr->putChar)
344 #define mon_may_getchar (romVectorPtr->mayGet)
345 #define mon_exit_to_mon (romVectorPtr->exitToMon)
346 #define mon_reboot (romVectorPtr->reBoot)
347 
348 
349 /*
350  * Sun3 specific stuff...
351  */
352 
353 #ifdef	_SUN3_
354 #define setcxsegmap 	mon_un.un3.un3_setcxsegmap
355 #define vector_cmd  	mon_un.un3.un3_vector_cmd
356 #define	romVectorPtr	((struct sunromvec *) SUN3_PROM_BASE)
357 #endif	/* SUN3 */
358 
359 /*
360  * MONSTART and MONEND denote the range used by the monitor.
361  * PROM_BASE is the virtual address of the PROM.
362  */
363 #define SUN3_MONSTART		0x0FE00000
364 #define SUN3_PROM_BASE		0x0FEF0000
365 #define SUN3_MONEND		0x0FF00000
366 
367 /*
368  * These describe the monitor's short segment (one it can reach using
369  * short PC-relative addressing) which it uses to map its data page.
370  * MONSHORTPAGE is the page; MONSHORTSEG is the containing segment.
371  * Its mapping must not be removed or the PROM monitor will fail.
372  * MONSHORTPAGE is also where the "ie" puts its SCP.
373  */
374 #define SUN3_MONSHORTPAGE	0x0FFFE000
375 #define SUN3_MONSHORTSEG	0x0FFE0000
376 
377 #ifdef	_SUN3_	/* XXX */
378 #define SUN_MONSTART		SUN3_MONSTART
379 #define SUN_MONEND		SUN3_MONEND
380 #endif /* _SUN3_ */
381 
382 /*
383  * Sun3X specific stuff...
384  */
385 
386 #ifdef	_SUN3X_
387 #define vector_cmd  	mon_un.un3x.un3x_vector_cmd
388 #define lomemptaddr 	mon_un.un3x.un3x_lomemptaddr
389 #define monptaddr   	mon_un.un3x.un3x_monptaddr
390 #define dvmaptaddr  	mon_un.un3x.un3x_dvmaptaddr
391 #define monptphysaddr	mon_un.un3x.un3x_monptphysaddr
392 #define shadowpteaddr	mon_un.un3x.un3x_shadowpteaddr
393 #define v_physmemory	mon_un.un3x.un3x_physmemory
394 #define	romVectorPtr	((struct sunromvec *) SUN3X_PROM_BASE)
395 #endif	/* SUN3X */
396 
397 /*
398  * We don't have a separate kernel debugger like sun kadb,
399  * but this range is setup by the monitor for such a thing.
400  * We might as well preserve the mappings anyway.
401  */
402 #define SUN3X_MON_KDB_BASE	0xFEE00000
403 #define	SUN3X_MON_KDB_SIZE	  0x100000
404 
405 /*
406  * MONSTART and MONEND define the range used by the monitor.
407  * MONDATA is its data page (do not touch!)
408  * PROM_BASE is where the boot PROM lives.
409  */
410 #define SUN3X_MONSTART    	0xFEF00000
411 #define SUN3X_MONDATA     	0xFEF72000
412 #define SUN3X_PROM_BASE   	0xFEFE0000
413 #define SUN3X_MONEND      	0xFF000000
414 
415 #ifdef	_SUN3X_	/* XXX */
416 #define SUN_MONSTART		SUN3X_MONSTART
417 #define SUN_MONEND		SUN3X_MONEND
418 #endif /* _SUN3X_ */
419 
420 /*
421  * These define the CPU virtual address range mapped by the
422  * PROM for use as DVMA space.  The physical pages mapped in
423  * this range are also mapped by the I/O MMU.  Note that the
424  * last page is reserved for the PROM (really for the "ie").
425  */
426 #define SUN3X_MON_DVMA_BASE	0xFFF00000
427 #define SUN3X_MON_DVMA_SIZE	  0x100000	/* 1MB */
428 
429 #ifdef	_STANDALONE
430 /* The libsa code uses a pointer... */
431 extern struct sunromvec *_romvec;
432 #undef	romVectorPtr
433 #define	romVectorPtr	_romvec
434 #endif	/* _STANDALONE */
435 
436 #endif	/* _MACHINE_MON_H */
437