Greetings -
As I understand it, the CPU switch table (cpusw) contains vectors to
various routines, and PAL & PROM locations. Can anybody shed some light
on how to grab data from seg1 addresses? How do I obtain the VPtPtr address?
The manuals I've got leave me hanging at this point, or am I barking up
the wrong tree here?
When I attempt to read the cpusw->system_string via a program, I get as
far as a seg1? address. What I've got thus far is as follows:
#include <errno.h> /* for standard errors */
#include <mach/machine.h> /* for machine structs and CPU stats */
#include <machine/cpuconf.h> /* for cpusw structure */
#include <nlist.h> /* for nlist struct and lseeking kernel */
#include <stdio.h> /* for standard i/o */
#include <sys/file.h> /* for open() definitions */
#include <sys/types.h> /* for type definitions used */
#define NM_CPUSW (0) /* cpu switch table is first in namelist*/
struct cpusw *p_cpusw;
struct nlist namelist[] = {
{ "cpusw" },
{ 0 } };
off_t lseek();
unsigned long int sys_str_addr;
int kmem, level1, level2, level3, offset;
char kernel[] = "/vmunix";
#define getbits(a, b, c) ((a >> (b + 1 - c)) & ~(~0 << c))
/* u_long a, int b,c; gets right adjusted 'c'-bit field of
'a' beginning at 'b' where 'b' is left-most numbered bit
starting from zero */
main()
{
p_cpusw = (struct cpusw *)malloc(sizeof(*p_cpusw));
(void)nlist(kernel, namelist);
if( -1 == (kmem = open( "/dev/kmem", O_RDONLY, NULL)) )
err_dump("/dev/kmem open failed, (%d)", errno);
if( -1 == lseek( kmem, (off_t)namelist[NM_CPUSW].n_value, SEEK_SET) )
err_dump("/dev/kmem lseek failed, (%d)", errno);
if( -1 == read( kmem, p_cpusw, sizeof(struct cpusw)) )
err_dump("/dev/kmem read failed, (%d)", errno);
sys_str_addr = (int)p_cpusw->system_string;
level1 = getbits(sys_str_addr, 42, 10);
level2 = getbits(sys_str_addr, 32, 10);
level3 = getbits(sys_str_addr, 22, 10);
offset = getbits(sys_str_addr, 12, 13);
fprintf(stdout, "sys_str_addr: (0x%lx)\n", sys_str_addr);
for( i = 63; i > -1 ; i-- )
fprintf(stdout, "%s%d", ((i+1) % 8)?"":" ", getbits(sys_str_addr, i, 1));
fprintf(stdout, "level 1 page table number: (0x%lx) %lu\n", level1, level1);
fprintf(stdout, "level 2 page table number: (0x%lx) %lu\n", level2, level2);
fprintf(stdout, "level 3 page table number: (0x%lx) %lu\n", level3, level3);
fprintf(stdout, "byte offset into page: (0x%lx) %lu\n", offset, offset);
exit(0);
}
# cpu_str
sys_str_addr: (0xffffffffff8005c8)
11111111 11111111 11111111 11111111 11111111 10000000 00000101 11001000
level 1 page table number: (0x3ff) 1023
level 2 page table number: (0x3ff) 1023
level 3 page table number: (0x0) 0
byte offset into page: (0x5c8) 1480
Thanks a bunch.
Randy M. Hayman
haymanr_at_icefog.alaska.edu
Received on Wed Mar 13 1996 - 00:53:22 NZDT