/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1990 MIPS Computer Systems, Inc.            |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 52.227-7013.   |
 * |         MIPS Computer Systems, Inc.                       |
 * |         928 Arques Avenue                                 |
 * |         Sunnyvale, CA 94086                               |
 * |-----------------------------------------------------------|
 */
#ident	"$Header: main.c,v 1.2.2.3 92/11/19 16:25:04 marker Exp $"

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

/*
 * Purpose of this programm is to print out kernel tunable parameters
 * of currently running unix (RISCos). 
 */

#include "crash.h"


/*sysdef includes */
/*#include	<a.out.h>*/
#include	<sys/tuneable.h>
#include	<sys/ipc.h>
#include	<sys/msg.h>
#include	<sys/sem.h>
#include	<sys/shm.h>
#include	<sys/flock.h>
#define _KERNEL 1
#include	<sys/utsname.h>
#undef _KERNEL
#include	<sys/conf.h>
#include	<sys/stat.h>
#include	<sys/sysinfo.h>

#define NARGS 25		/* number of arguments to one function */
#define LINESIZE 256		/* size of function input line */

int mem;			/* file descriptor for dump file */
char *namelist = "/unix";
char *dumpfile = "/dev/mem";
struct user *ubp;			/* pointer to ublock buffer */
FILE *fp;				/* output file pointer */
FILE *rp;				/* redirect file pointer */
int opipe = 0;				/* open pipe flag */
struct var vbuf;			/* var structure buffer */
int Procslot;				/* current process slot */
int Virtmode = 1;			/* virtual or physical mode flag*/
long pipesig;				/* pipe signal catch */
int target_pagesize;			/* pagesize of target system */
int pte_to_pfn_shift;			/* pte "pfn" field to page addr */
int pfn_to_byte_shift;			/* convert page to byte address */
int rev_shift;				/* mask for 4k tlb entries */
int Usize;				/* number of pages in U-area */
int Npgpt;				/* number of ptes in a "segment" */
int mips2 = 0;				/* mips2 program? */
int mips3 = 0;				/* mips3 program? */
uint Pde_pg_vr,				/* pte "valid" mask */
     Pde_pg_g,				/* pte "global" mask */
     Pde_pg_m,				/* pte "modified" mask */
     Pde_pg_n,				/* pte "noncached" mask */
     Pde_pg_lock,			/* pte "page locked" mask */
     Pde_pg_sv,				/* pte "page valid" mask */
     Pde_pg_cw;				/* pte "copy-on-write" mask */
int (*Prtlb)();

short N_TEXT;		/* used in symtab.c */
short N_DATA;		/* used in symtab.c */
short N_BSS;		/* used in symtab.c */
int active;	/* Flag set if crash is examining an active system */
jmp_buf	jmp,syn;	/* labels for jump */
void exit();

char *args[NARGS];		/* argument array */
int argcnt;			/* argument count */
char outfile[100];		/* output file for redirection */
static int tabsize;		/* size of function table */

/* main program with call to functions */
main(argc,argv)
int argc;
char **argv;
{
	struct func *a,*f;
	int c,i,found;
	extern int opterr;
	int arglength;


	fp = stdout;
	strcpy(outfile,"stdout");
	init();
	sysdef();
	if (mem)
		close(mem);
	exit(0);
}

struct var v;
struct tune jtune;
struct msginfo jminfo;
struct seminfo sinfo;
struct shminfo shinfo;
struct flckinfo flinfo;
struct utsname utsname;
char strmedfrac, strlofrac;
int nstrpush;
int nstrevent;
int strmsgsz;
int strctlsz;
int maxsepgcnt;
int nmuxlink;
int kmemmapsz;
int maxbucket;
int maxallocsave;
long nfs_maxdupreqs;
struct shlbinfo jshlbinfo;
int putbufsz;
/*xxxxx*/
sysdef()
{
struct syment *sp;
int rcnt,i,fd;
int data[1000];

sp = symsrch("v");
readmem(sp->n_value,1,0,&v,sizeof(struct var),sp->n_name);
sp = symsrch("tune");
readmem(sp->n_value,1,0,&jtune,sizeof(struct tune),sp->n_name);
sp = symsrch("msginfo");
readmem(sp->n_value,1,0,&jminfo,sizeof(struct msginfo),sp->n_name);
sp = symsrch("seminfo");
readmem(sp->n_value,1,0,&sinfo,sizeof(struct seminfo),sp->n_name);
sp = symsrch("shminfo");
readmem(sp->n_value,1,0,&shinfo,sizeof(struct shminfo),sp->n_name);
sp = symsrch("flckinfo");
readmem(sp->n_value,1,0,&flinfo,sizeof(struct flckinfo),sp->n_name);
sp = symsrch("utsname");
readmem(sp->n_value,1,0,&utsname,sizeof(struct utsname),sp->n_name);
sp = symsrch("strmedfrac");
readmem(sp->n_value,1,0,&strmedfrac,sizeof(char),sp->n_name);
sp = symsrch("strlofrac");
readmem(sp->n_value,1,0,&strlofrac,sizeof(char),sp->n_name);
sp = symsrch("nstrevent");
readmem(sp->n_value,1,0,&nstrevent,sizeof(int),sp->n_name);
sp = symsrch("maxsepgcnt");
readmem(sp->n_value,1,0,&maxsepgcnt,sizeof(int),sp->n_name);
sp = symsrch("strmsgsz");
readmem(sp->n_value,1,0,&strmsgsz,sizeof(int),sp->n_name);
sp = symsrch("strctlsz");
readmem(sp->n_value,1,0,&strctlsz,sizeof(int),sp->n_name);
sp = symsrch("nstrpush");
readmem(sp->n_value,1,0,&nstrpush,sizeof(int),sp->n_name);
sp = symsrch("nmuxlink");
readmem(sp->n_value,1,0,&nmuxlink,sizeof(int),sp->n_name);
sp = symsrch("kmemmapsz");
readmem(sp->n_value,1,0,&kmemmapsz,sizeof(int),sp->n_name);
sp = symsrch("maxbucket");
readmem(sp->n_value,1,0,&maxbucket,sizeof(int),sp->n_name);
sp = symsrch("maxallocsave");
readmem(sp->n_value,1,0,&maxallocsave,sizeof(int),sp->n_name);
sp = symsrch("putbufsz");
readmem(sp->n_value,1,0,&putbufsz,sizeof(int),sp->n_name);
sp = symsrch("nfs_maxdupreqs");
readmem(sp->n_value,1,0,&nfs_maxdupreqs,sizeof(long),sp->n_name);
sp = symsrch("shlbinfo");
readmem(sp->n_value,1,0,&jshlbinfo,sizeof(struct shlbinfo),sp->n_name);

prsysdef();
}
prsysdef()
{
	printf("*\n* Kernel CONFIGURATION\n");
	printf("*\n*\n* TUNABLE PARAMETERS\n*\n");
	printf("%6d	buffers in buffer cache (NBUF) (dynamically allocated area)\n",v.v_buf);
	printf("%6d	entries in callout table (NCALL)\n",v.v_call);
	printf("%6d	inodes  (NINODE)\n",v.v_inode);
	printf("%6d	entries in file table (NFILE)\n",v.v_file);
	printf("%6d	entries in proc table (NPROC)\n",v.v_proc);
	printf("%6d	entries in shared region table (NREGION)\n",
		v.v_region);
	printf("%6d	processes per user id (MAXUP)\n",v.v_maxup);
	printf("%6d	hash slots for buffer cache (NHBUF) (dynamically allocated area)\n",v.v_hbuf);
	printf("%6d	buffers for physical I/O (NPBUF)\n",v.v_pbuf);
	printf("%6d	size of system virtual space map (SPTMAP)\n",
		v.v_sptmap);
	printf("%6d	maximum physical memory to use (MAXPMEM)(value not used)\n",
		v.v_maxpmem);
	printf("%6d	auto update time limit in seconds (NAUTOUP)\n",
		v.v_autoup);
	printf("%6d	maximum number of open files per process (NOFILES)\n",
		v.v_nofiles);

	printf("%6d  maximum size of user's virtual address space in pages (MAXUMEM)\n", jtune.t_maxumem);
	printf("%6d  for package compatibility equal to MAXUMEM (MAXMEM)\n", 
   jtune.t_maxumem);
	printf("%6d  bdflush run rate (BDFLUSHR)\n", jtune.t_bdflushr);
	printf("%6d  minimum resident memory for avoiding deadlock (MINARMEM)\n",
		jtune.t_minarmem);
	printf("%6d  minimum swapable memory for avoiding deadlock (MINASMEM)\n",
		jtune.t_minasmem);

	printf("*\n* Utsname Tunables\n*\n");
	printf("%16s  release (REL)\n",utsname.release);
	printf("%16s  node name (NODE)\n",utsname.nodename);
	printf("%16s  system name (SYS)\n",utsname.sysname);
	printf("%16s  version (VER)\n",utsname.version);
	printf("%16s  machine (MACHINE)\n",utsname.machine);
	printf("%16s  m_type (MACH_TYPE)\n",utsname.m_type);
	printf("%16s  base_rel (BASE_REL)\n",utsname.base_rel);

	printf("*\n* Streams Tunables\n*\n");
	printf("%6d	number of multiplexor links (NMUXLINK)\n", nmuxlink);
	printf("%6d	maximum number of pushes allowed (NSTRPUSH)\n", nstrpush);
	printf("%6d	initial number of stream event calls (NSTREVENT)\n", nstrevent);
	printf("%6d	page limit for event cell allocation (MAXSEPGCNT)\n", maxsepgcnt);
	printf("%6d	maximum stream message size (STRMSGSZ)\n", strmsgsz);
	printf("%6d	max size of ctl part of message (STRCTLSZ)\n", strctlsz);
	printf("%6d	max low priority % block usage (STRLOFRAC)\n", strlofrac);
	printf("%6d	max medium priority % block usage (STRMEDFRAC)\n", strmedfrac);
	printf("(Note that the streams storage is dynamically managed,\n");
	printf(" so these numbers for buffers do not represent hard upper limits.)\n");
	printf("%6d	number of 4096 bytes stream buffers (NBLK4096)\n",
		v.v_nblk4096);
	printf("%6d	number of 2048 bytes stream buffers (NBLK2048)\n",
		v.v_nblk2048);
	printf("%6d	number of 1024 bytes stream buffers (NBLK1024)\n",
		v.v_nblk1024);
	printf("%6d	number of 512 bytes stream buffers (NBLK512)\n",
		v.v_nblk512);
	printf("%6d	number of 256 bytes stream buffers (NBLK256)\n",
		v.v_nblk256);
	printf("%6d	number of 128 bytes stream buffers (NBLK128)\n",
		v.v_nblk128);
	printf("%6d	number of 64 bytes stream buffers (NBLK64)\n",
		v.v_nblk64);
	printf("%6d	number of 16 bytes stream buffers (NBLK16)\n",
		v.v_nblk16);
	printf("%6d	number of 4 bytes stream buffers (NBLK4)\n",
		v.v_nblk4);

	printf("*\n* IPC Messages\n*\n");
	printf("%6d	entries in msg map (MSGMAP)\n",jminfo.msgmap);
	printf("%6d	max message size (MSGMAX)\n",jminfo.msgmax);
	printf("%6d	max bytes on queue (MSGMNB)\n",jminfo.msgmnb);
	printf("%6d	message queue identifiers (MSGMNI)\n",jminfo.msgmni);
	printf("%6d	message segment size (MSGSSZ)\n",jminfo.msgssz);
	printf("%6d	system message headers (MSGTQL)\n",jminfo.msgtql);
	printf("%6u	message segments (MSGSEG)\n",jminfo.msgseg);

	printf("*\n* IPC Semaphores\n*\n");
	printf("%6d	entries in semaphore map (SEMMAP)\n",sinfo.semmap);
	printf("%6d	semaphore identifiers (SEMMNI)\n",sinfo.semmni);
	printf("%6d	semaphores in system (SEMMNS)\n",sinfo.semmns);
	printf("%6d	undo structures in system (SEMMNU)\n",sinfo.semmnu);
	printf("%6d	max semaphores per id (SEMMSL)\n",sinfo.semmsl);
	printf("%6d	max operations per semop call (SEMOPM)\n",sinfo.semopm);
	printf("%6d	max undo entries per process (SEMUME)\n",sinfo.semume);
	printf("%6d	semaphore maximum value (SEMVMX)\n",sinfo.semvmx);
	printf("%6d	adjust on exit max value (SEMAEM)\n",sinfo.semaem);
	printf("*\n* IPC Shared Memory\n*\n");
	printf("%6d	max shared memory segment size (SHMMAX)\n",shinfo.shmmax);
	printf("%6d	min shared memory segment size (SHMMIN)\n",shinfo.shmmin);
	printf("%6d	shared memory identifiers (SHMMNI)\n",shinfo.shmmni);
	printf("%6d	max attached shm segments per process (SHMSEG)\n",shinfo.shmseg);
	printf("%6d	max in use shared memory (SHMALL)\n",shinfo.shmall);

	printf("*\n* File and Record Locking\n*\n");
	printf("%6d	records configured on system (FLCKREC) (value not used)\n",flinfo.recs);

	printf("*\n* Kernel Memory Allocator\n*\n");
	printf("%6d	size of kemem map (KMEMMAP)\n",kmemmapsz);
	printf("%6d	maximum number of buckets (MAXBUCKET)\n",maxbucket);
	printf("%6d	maximum memory allocation saved (MAXALLOCSAVE)\n",maxallocsave);

	printf("*\n* Miscellaneous Tuneables\n*\n");
	printf("%6d	putbuf size (PUTBUFSZ)\n",putbufsz);
	printf("%6d	nfs duplicator (NFS_MAXDUPREQS)\n",nfs_maxdupreqs);
	printf("*\n* Shared Library Tuneables\n*\n");
	printf("%6d	maximum shared libraries (SHLBMAX)\n",jshlbinfo.shlbs);
	printf("0x%8x shared library address (SHLBADDR)\n",jshlbinfo.shlbaddr);
}
