📄 probe_nlist.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)probe_nlist.c 1.1 92/07/30 Copyright Sun Micro";#endif/* * Copyright (c) 1988 by Sun Microsystems, Inc. */#include <stdio.h>#include <ctype.h>#include <errno.h>#include <kvm.h>#include <nlist.h>#include <signal.h>#ifdef SVR4#include <dirent.h>#include <string.h>#else SVR4#include <strings.h>#endif SVR4#include <fcntl.h>#include <sys/types.h>#include <sys/conf.h>#ifndef SVR4#include <mon/openprom.h>#include <sys/dir.h>#include <sys/param.h>#endif SVR4#include <sys/file.h>#include <sys/stat.h>#include <sys/buf.h>#include <sys/vmmac.h>#ifdef SVR4#include <sys/cpu.h>#include <sys/param.h>#else SVR4#include <machine/mmu.h>#include <machine/cpu.h>#include <machine/param.h>#include <machine/pte.h>#endif SVR4#include <vm/anon.h>#ifdef SVR4#include <sys/dkio.h>#include <sys/sireg.h>#else SVR4#include <sun/dkio.h>#include <sundev/mbvar.h>#include <sundev/screg.h>#include <sundev/sireg.h>#include <sundev/scsi.h>#endif SVR4#include "probe.h"#include "../../lib/include/probe_sundiag.h"#include "sdrtns.h"#include "../../lib/include/libonline.h"#define NL_PHYSMEM 0#define NL_ROMP 1#define NL_PHYSMEMORY 2#define NL_ANONINFO 3#define NL_MBDINIT 4#define NL_SCSINTYPE 5#define NL_SCSIUNITSUBR 6#define FPUEXISTS 7 #define NL_TOPDEVINFO 8 #define NL_LAST 9#ifndef sun386struct nlist nl[] = {#ifdef SVR4 { "cputype", 0, 0, 0, 0, 0 }, {"physmem", 0, 0, 0, 0, 0 }, {"anoninfo", 0, 0, 0, 0, 0 }, { "mbdinit", 0, 0, 0, 0, 0 }, { "scsi_ntype", 0, 0, 0, 0, 0 }, { "scsi_unit_subr", 0, 0, 0, 0, 0 }, {"fpu_exists", 0, 0, 0, 0, 0 }, {"top_devinfo",0, 0, 0, 0, 0 }, { "" },#else SVR4 {"_physmem", 0, 0, 0, 0 }, { "_romp", 0, 0, 0, 0 }, { "_physmemory", 0, 0, 0, 0 }, {"_anoninfo", 0, 0, 0, 0 }, { "_mbdinit", 0, 0, 0, 0 }, { "_scsi_ntype", 0, 0, 0, 0 }, { "_scsi_unit_subr", 0, 0, 0, 0 },#ifdef sun3 {"_fppstate", 0, 0, 0, 0 }, {"_fpa_exist", 0, 0, 0, 0 }, { "" },#endif#ifdef sun4 {"_fpu_exists", 0, 0, 0, 0 }, {"_top_devinfo",0, 0, 0, 0 }, { "" },#endif#endif SVR4}; #else sun386#define NL_CPU 0#define NL_PHYSMEM 1#define NL_SANON 2#define NL_MBDINIT 3#define NL_SCSINTYPE 4#define NL_SCSIUNITSUBR 5struct nlist nl[] = { { "cpu", 0, 0, 0, 0 }, { "physmem", 0, 0, 0, 0 }, { "anoninfo", 0, 0, 0, 0 }, { "mbdinit", 0, 0, 0, 0 }, { "scsi_ntype", 0, 0, 0, 0 }, { "scsi_unit_subr", 0, 0, 0, 0 }, { "" },};#include <setjmp.h>jmp_buf error_buf;#endif sun386struct sunromvec *sunrom, romvec;struct memlist **pm, *pmlist, pmem;extern int devno;static int cpu_type;extern struct found_dev found[MAXDEVS];/* for SPARCstation 1 only */int numdev=0;struct mb_devinfo mbdinfo[MAXDEVS];extern kvm_t *kvm_open();extern char *malloc();extern char *calloc();extern long lseek();extern void save_mem(), save_dev();extern void check_dev_files();void get_c_devices();#define MAX_SCSI_DEV_NAME_LENGTH 3 struct mb_device *mbdinit;static struct mb_driver *scdriver;static int scsi_ntype;static struct scsi_unit_subr *scsi_unit_subr=(struct scsi_unit_subr *)0;static kvm_t *mem;static char *get_cpuname();static int get_physmem(), get_vmem();static int openboot_prom=FALSE, nlvar=0;#ifdef SVR4static int get_fpu();static long _fsr_temp;#else SVR4/* #ifdef sun3 */static int get_fpp();/* #endif *//* #ifdef sun4 */static long fsr_temp;static int get_fpa();/* #endif */static void get_scsi_names(), get_devices();static void get_drivers();#endif SVR4/********************************************************************* This sun_probe routines can probe any device as specified by user, and return TRUE/FALSE to indicate device availability. This routine also provide for some information about the probed device, and error message if failed.*********************************************************************/intsun_probe(dev_name, f_dev, makedevs)char *dev_name; /* device to probe */struct f_devs *f_dev;int makedevs;{ char *vmunix, *getenv(); char *cpuname; int physmem, vmem; int fpp, fpa, fpu; char error_msg[BUFSIZ]; #ifdef sun386 int bus(), segv();#endif func_name = "sun_probe"; TRACE_IN check_superuser(); /* begin probe */ vmunix = getenv("KERNELNAME"); if ((mem = kvm_open(vmunix, NULL, NULL, O_RDONLY, NULL)) == NULL) { send_message(1, FATAL, "kvm_open: %s, kvm_open failed", errmsg(errno)); } if (kvm_nlist(mem, nl) == -1) { send_message(1, FATAL,"kvm_nlist: %s, kvm_nlist failed", errmsg(errno)); } #ifndef SVR4 if (sun_arch() != ARCH4) openboot_prom = TRUE; if (!check_nlist()) { send_message(1, FATAL, "no namelist"); } #endif SVR4 #ifdef SVR4 get_c_devices(mem); cpuname = get_cpuname(mem); physmem = get_physmem(mem); vmem = get_vmem(mem); fpu = get_fpu(mem);#else SVR4 cpuname = get_cpuname(mem); physmem = get_physmem(mem); vmem = get_vmem(mem); if (sun_arch() != ARCH4) get_c_devices(mem); else { get_scsi_names(mem); get_devices(mem); get_drivers(mem); } fpu = get_fpu(mem);#endif SVR4 (void)kvm_close(mem); /* end of probe */ f_dev->cputype = cpu_type; f_dev->cpuname = cpuname; save_mem(MEM, physmem); save_mem(KMEM, vmem); if (fpu) save_dev(FPUU, 0, fpu); #ifndef SVR4 check_dev_files(makedevs, fpa, dev_name);#endif SVR4 f_dev->num = devno; f_dev->found_dev = &found[0]; TRACE_OUT return (devno);} static intcheck_nlist(error_msg)char *error_msg;{ unsigned arch_code; func_name = "check_nlist"; TRACE_IN arch_code = sun_arch(); if(arch_code == ARCH4) { if (nl[NL_MBDINIT].n_type == 0 ) { TRACE_OUT return(0); /* FATAL */ } } TRACE_OUT return(1);}/* * from autoconf.c: * We set the cpu type and associated variables. Should there get to * be too many variables, they should be collected together in a * structure and indexed by cpu type. */static char *get_cpuname(mem) int mem;{ static char *cpuname;#ifdef SVR4 struct mb_devinfo *mdc; mdc = mbdinfo;#endif SVR4 func_name = "get_cpuname"; TRACE_IN if ((cpuname = malloc(MAXNAMLEN)) == NULL) { send_message(1, FATAL, "malloc cpuname: %s", errmsg(errno)); } (void) strcpy(cpuname, "Unknown machine type"); /* default CPU type */#ifndef SVR4 switch (cpu_type = sun_cpu()) {#ifdef sun3 case CPU_SUN3X_470: (void) strcpy(cpuname, "Sun-3X/460,3X/470,3X/480"); /* they can be 460, 470, or 480 */ break; case CPU_SUN3X_80: (void) strcpy(cpuname, "Sun-3X/80"); break; case CPU_SUN3_160: (void) strcpy(cpuname, "Sun-3/75, 3/160, 3/180"); break; case CPU_SUN3_50: (void) strcpy(cpuname, "Sun-3/50"); break; case CPU_SUN3_260: (void) strcpy(cpuname, "Sun-3/260, 3/280"); break; case CPU_SUN3_110: (void) strcpy(cpuname, "Sun-3/110"); break; case CPU_SUN3_60: (void) strcpy(cpuname, "Sun-3/60"); break; case CPU_SUN3_E: (void) strcpy(cpuname, "Sun-3/E"); break; default: (void) strcpy(cpuname, "Sun-3, unknown type"); break;#endif#ifdef sun4 case CPU_SUN4_890: (void) strcpy(cpuname, "Sun-4/890"); break; case CPU_SUN4_460: (void) strcpy(cpuname, "Sun-4/470, 4/490"); break; case CPU_SUN4_330: (void) strcpy(cpuname, "Sun-4/330, 4/370, 4/390"); break; case CPU_SUN4_260: (void) strcpy(cpuname, "Sun-4/260, 4/280"); break; case CPU_SUN4_110: (void) strcpy(cpuname, "Sun-4/110"); break; case CPU_SUN4C_60: (void) strcpy(cpuname, "SPARCstation 1"); break; case CPU_SUN4C_40: (void) strcpy(cpuname, "Sun-4/40"); break; case CPU_SUN4C_65: (void) strcpy(cpuname, "SPARCstation 1+"); break; case CPU_SUN4C_20: (void) strcpy(cpuname, "Sun-4/20"); break; case CPU_SUN4C_75: (void) strcpy(cpuname, "Sun-4/75"); break; case CPU_SUN4C_30: (void) strcpy(cpuname, "Sun-4/30"); break; case CPU_SUN4C_50: (void) strcpy(cpuname, "Sun-4/50"); break; case GALAXY: (void) strcpy(cpuname, "SPARCsystem 600 MP"); break; case C2: (void) strcpy(cpuname, "SPARCstation 10"); break; default: switch (sun_arch()) { case ARCH4: (void)strcpy(cpuname, "Sun-4, unknown type"); break; case ARCH4M: (void)strcpy(cpuname, "Sun-4m, unknown type"); break; default: (void)strcpy(cpuname, "Sun-4c, unknown type"); }#endif#ifdef sun386 case CPU_SUN386_150: (void) strcpy(cpuname, "Sun-386i"); break; case 32: /* do this properly with define ASAP */ (void) strcpy(cpuname, "Sun-486i"); break; default: (void) strcpy(cpuname, "Sun-x86i, unknown type"); break;#endif } #else SVR4 strcpy(cpuname, mdc->info.devi_name);#endif SVR4 send_message (0, VERBOSE, "cpuname = %s", cpuname);#ifndef SVR4 send_message (0, VERBOSE, "cputype = %x", cpu_type);#endif SVR4 TRACE_OUT return(cpuname);}/* * from machdep.c: * memory size in pages, patch if you want less * If physmem is patched to be non-zero, use it instead of * the monitor value unless physmem is larger than the total * amount of memory on hand. * Adjust physmem down for the pages stolen by the monitor. * Comment: how can a user find out how many pages the monitor has? */static intget_physmem(mem) int mem;{ int physmem = 0; func_name = "get_physmem"; TRACE_IN nlvar = openboot_prom ? NL_ROMP : NL_PHYSMEM; if (openboot_prom) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -