#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/debug.h>
#include <sys/errno.h>
#include <sys/modctl.h>
#include <sys/kobj.h>
#include <sys/promif.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/reboot.h>
#include <sys/callb.h>
int obpsym_debug = 0;
#define DPRINTF(str) if (obpsym_debug) prom_printf(str)
#define DPRINTF1(str, a) if (obpsym_debug) prom_printf(str, a);
#define DPRINTF2(str, a, b) if (obpsym_debug) prom_printf(str, a, b);
#define DXPRINTF if (obpsym_debug > 1) prom_printf
int obpheld = 1;
int
name_to_value(char *name, uintptr_t *value)
{
register char *symname = name;
register char *modname = "";
char *p;
int retval = 0;
uintptr_t symvalue = 0;
char c = (char)0;
if ((p = strchr(name, ':')) != NULL && p[1] != (char)0) {
symname = p + 1;
modname = name;
c = *p;
*p = (char)0;
}
if (*modname == (char)0) {
symvalue = kobj_getsymvalue(symname, 0);
} else {
struct modctl *mp = &modules;
do {
if (strcmp(modname, mp->mod_modname) == 0) {
symvalue = kobj_lookup(mp->mod_mp, symname);
break;
}
} while ((mp = mp->mod_next) != &modules);
}
if (symvalue == 0)
retval = -1;
if (c != (char)0)
*p = c;
*value = symvalue;
return (retval);
}
ulong_t
value_to_name(uintptr_t value, char *symbol)
{
struct modctl *modp = &modules;
ulong_t offset;
char *name;
DPRINTF1("value_to_name: Looking for %p\n", (void *)value);
do {
if (modp->mod_mp &&
(name = kobj_searchsym(modp->mod_mp, value, &offset))) {
(void) strcpy(symbol, modp->mod_modname);
(void) strcat(symbol, ":");
(void) strcat(symbol, name);
return (offset);
}
} while ((modp = modp->mod_next) != &modules);
*symbol = (char)0;
return ((ulong_t)-1l);
}
static struct modlmisc modlmisc = {
&mod_miscops, "OBP symbol callbacks"
};
static struct modlinkage modlinkage = {
MODREV_1, (void *)&modlmisc, NULL
};
static boolean_t
reset_callbacks(void *arg, int code)
{
extern void set_sym_callbacks();
if (code == CB_CODE_CPR_RESUME)
set_sym_callbacks();
return (B_TRUE);
}
int
_init(void)
{
int retval;
extern int install_callbacks(void);
extern void remove_callbacks(void);
if (install_callbacks() != 0)
return (ENXIO);
if (boothowto & RB_HALT)
debug_enter("obpsym: halt flag (-h) is set.\n");
retval = mod_install(&modlinkage);
if (retval) {
printf("obpsym: Error %d installing OBP syms module\n", retval);
remove_callbacks();
}
else
(void) callb_add(reset_callbacks, 0, CB_CL_CPR_OBP, "obpsym");
return (retval);
}
int
_fini(void)
{
int retval;
extern void remove_callbacks(void);
if (obpheld != 0)
return (EBUSY);
retval = mod_remove(&modlinkage);
if (retval == 0) {
remove_callbacks();
}
return (retval);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}