1 /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
6 #include <machine/pci.h>
8 #include <minix/dmap.h>
12 static void root_hz(void);
13 static void root_uptime(void);
14 static void root_loadavg(void);
15 static void root_kinfo(void);
16 static void root_meminfo(void);
18 static void root_pci(void);
20 static void root_dmap(void);
21 static void root_ipcvecs(void);
23 struct file root_files
[] = {
24 { "hz", REG_ALL_MODE
, (data_t
) root_hz
},
25 { "uptime", REG_ALL_MODE
, (data_t
) root_uptime
},
26 { "loadavg", REG_ALL_MODE
, (data_t
) root_loadavg
},
27 { "kinfo", REG_ALL_MODE
, (data_t
) root_kinfo
},
28 { "meminfo", REG_ALL_MODE
, (data_t
) root_meminfo
},
30 { "pci", REG_ALL_MODE
, (data_t
) root_pci
},
32 { "dmap", REG_ALL_MODE
, (data_t
) root_dmap
},
34 { "cpuinfo", REG_ALL_MODE
, (data_t
) root_cpuinfo
},
36 { "ipcvecs", REG_ALL_MODE
, (data_t
) root_ipcvecs
},
37 { "mounts", REG_ALL_MODE
, (data_t
) root_mounts
},
41 /*===========================================================================*
43 *===========================================================================*/
44 static void root_hz(void)
46 /* Print the system clock frequency.
49 buf_printf("%lu\n", (long) sys_hz());
52 /*===========================================================================*
54 *===========================================================================*/
55 static void root_loadavg(void)
57 /* Print load averages.
62 if (procfs_getloadavg(loads
, 3) != 3)
65 avg
[0] = ldiv(100L * loads
[0].proc_load
/ loads
[0].ticks
, 100);
66 avg
[1] = ldiv(100L * loads
[1].proc_load
/ loads
[1].ticks
, 100);
67 avg
[2] = ldiv(100L * loads
[2].proc_load
/ loads
[2].ticks
, 100);
69 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
70 avg
[0].quot
, avg
[0].rem
, avg
[1].quot
, avg
[1].rem
,
71 avg
[2].quot
, avg
[2].rem
);
74 /*===========================================================================*
76 *===========================================================================*/
77 static void root_uptime(void)
79 /* Print the current uptime.
84 if (getuptime(&ticks
) != OK
)
86 division
= ldiv(100L * ticks
/ sys_hz(), 100L);
88 buf_printf("%ld.%0.2ld\n", division
.quot
, division
.rem
);
91 /*===========================================================================*
93 *===========================================================================*/
94 static void root_kinfo(void)
96 /* Print general kernel information.
100 if (sys_getkinfo(&kinfo
) != OK
)
103 buf_printf("%u %u\n", kinfo
.nr_procs
, kinfo
.nr_tasks
);
106 /*===========================================================================*
108 *===========================================================================*/
109 static void root_meminfo(void)
111 /* Print general memory information.
113 struct vm_stats_info vsi
;
115 if (vm_info_stats(&vsi
) != OK
)
118 buf_printf("%u %lu %lu %lu %lu\n", vsi
.vsi_pagesize
,
119 vsi
.vsi_total
, vsi
.vsi_free
, vsi
.vsi_largest
, vsi
.vsi_cached
);
122 /*===========================================================================*
124 *===========================================================================*/
125 #if defined(__i386__)
126 static void root_pci(void)
128 /* Print information about PCI devices present in the system.
132 char *slot_name
, *dev_name
;
134 static int first
= TRUE
;
136 /* This should be taken care of behind the scenes by the PCI lib. */
142 /* Iterate over all devices, printing info for each of them. */
143 r
= pci_first_dev(&devind
, &vid
, &did
);
145 slot_name
= pci_slot_name(devind
);
146 dev_name
= pci_dev_name(vid
, did
);
148 bcr
= pci_attr_r8(devind
, PCI_BCR
);
149 scr
= pci_attr_r8(devind
, PCI_SCR
);
150 pifr
= pci_attr_r8(devind
, PCI_PIFR
);
152 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
153 slot_name
? slot_name
: "-",
154 bcr
, scr
, pifr
, vid
, did
,
155 dev_name
? dev_name
: "");
157 r
= pci_next_dev(&devind
, &vid
, &did
);
160 #endif /* defined(__i386__) */
162 /*===========================================================================*
164 *===========================================================================*/
165 static void root_dmap(void)
167 struct dmap dmap
[NR_DEVICES
];
170 if (getsysinfo(VFS_PROC_NR
, SI_DMAP_TAB
, dmap
, sizeof(dmap
)) != OK
)
173 for (i
= 0; i
< NR_DEVICES
; i
++) {
174 if (dmap
[i
].dmap_driver
== NONE
)
177 buf_printf("%u %s %u\n", i
, dmap
[i
].dmap_label
,
178 dmap
[i
].dmap_driver
);
182 /*===========================================================================*
184 *===========================================================================*/
185 static void root_ipcvecs(void)
187 extern struct minix_kerninfo
*_minix_kerninfo
;
188 extern struct minix_ipcvecs _minix_ipcvecs
;
190 /* only print this if the kernel provides the info; otherwise binaries
191 * will be using their own in-libc vectors that are normal symbols in the
194 if(!_minix_kerninfo
|| !(_minix_kerninfo
->ki_flags
& MINIX_KIF_IPCVECS
))
197 /* print the vectors with an descriptive name and the additional (k)
198 * to distinguish them from regular symbols.
200 #define PRINT_ENTRYPOINT(name) \
201 buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name)
203 PRINT_ENTRYPOINT(sendrec
);
204 PRINT_ENTRYPOINT(send
);
205 PRINT_ENTRYPOINT(notify
);
206 PRINT_ENTRYPOINT(senda
);
207 PRINT_ENTRYPOINT(sendnb
);
208 PRINT_ENTRYPOINT(receive
);
209 PRINT_ENTRYPOINT(do_kernel_call
);