Skip to content

Instantly share code, notes, and snippets.

@mhansen
Created October 22, 2009 23:02
Show Gist options
  • Save mhansen/216440 to your computer and use it in GitHub Desktop.
Save mhansen/216440 to your computer and use it in GitHub Desktop.
#include "../drivers.h"
PUBLIC void get_bootenv(char *buf, int bufSize) {
int status;
char *char_p;
status = sys_getmonparams(buf, bufSize);
if (status != OK) printf("PROC: sys_getmonparams failed: %d", status);
/* Convert nulls between params into new lines */
char_p = buf;
do {
char_p += strlen(char_p);
*char_p = '\n';
char_p++;
} while (*char_p != 0);
}
#include "../drivers.h"
#include <stdio.h>
#include "../../kernel/ipc.h"
#include "../../kernel/config.h"
#include "../../kernel/type.h"
FORWARD _PROTOTYPE( char *s_traps_str, (int flags) );
FORWARD _PROTOTYPE( char *s_flags_str, (int flags) );
struct boot_image image[NR_BOOT_PROCS];
void get_bootimage(char *buf, int bufSize) {
int status, i, m, j;
struct boot_image *ip;
static char ipc_to[BITCHUNK_BITS*2];
status = sys_getimage(image);
if (status != OK) {
report("PROC", "warning: couldn't get copy of image table", status);
*buf = '\0';
return;
}
buf+=sprintf(buf,"---name-- -nr- -flags- -traps- -sq- ----pc- -stack- -ipc_to[0]--------\n");
for (m=0; m<NR_BOOT_PROCS; m++) {
ip = &image[m];
for (i=j=0; i < BITCHUNK_BITS; i++, j++) {
ipc_to[j] = (ip->ipc_to & (1<<i)) ? '1' : '0';
if (i % 8 == 7) ipc_to[++j] = ' ';
}
ipc_to[j] = '\0';
buf+=sprintf(buf, "%8s %4d %s %s %3d %7lu %7lu %s\n",
ip->proc_name, ip->proc_nr,
s_flags_str(ip->flags), s_traps_str(ip->trap_mask),
ip->priority, (long)ip->initial_pc, ip->stksize, ipc_to);
}
}
PRIVATE char *s_flags_str(int flags)
{
static char str[10];
str[0] = (flags & PREEMPTIBLE) ? 'P' : '-';
str[1] = '-';
str[2] = (flags & BILLABLE) ? 'B' : '-';
str[3] = (flags & SYS_PROC) ? 'S' : '-';
str[4] = '-';
str[5] = '\0';
return str;
}
PRIVATE char *s_traps_str(int flags)
{
static char str[10];
str[0] = (flags & (1 << SEND)) ? 'S' : '-';
str[1] = (flags & (1 << SENDA)) ? 'A' : '-';
str[2] = (flags & (1 << RECEIVE)) ? 'R' : '-';
str[3] = (flags & (1 << SENDREC)) ? 'B' : '-';
str[4] = (flags & (1 << NOTIFY)) ? 'N' : '-';
str[5] = '\0';
return str;
}
#include "../drivers.h"
#include <stdio.h>
PUBLIC void get_cpuinfo(char *buf, int bufSize) {
int status, ch = 0;
struct machine machine;
status = sys_getmachine(&machine);
if (status != OK) printf("PROC: sys_getmachine failed: %d", status);
buf+=sprintf(buf, "PC_AT: %3d\n", machine.pc_at);
buf+=sprintf(buf, "PS_MCA: %3d\n", machine.ps_mca);
buf+=sprintf(buf, "Processor: %3d\n", machine.processor);
buf+=sprintf(buf, "Padding: %3d\n", machine.padding);
buf+=sprintf(buf, "EGA: %3d\n", machine.vdu_ega);
buf+=sprintf(buf, "VGA: %3d\n", machine.vdu_vga);
}
#include <stdio.h>
#include <time.h>
void get_Hz(char *buf, int bufSize)
{
sprintf(buf, "%d ticks per second\n", CLOCKS_PER_SEC );
}
#include "../drivers.h"
#include <stdio.h>
#include "../../servers/pm/mproc.h"
FORWARD _PROTOTYPE (char *flags_str, (int flags) );
struct mproc mprocs[NR_PROCS];
PUBLIC void get_processes(char *buf, int bufSize) {
int i, status;
struct mproc *proc;
status = getsysinfo(PM_PROC_NR, SI_PROC_TAB, mprocs);
if (status != OK) printf("PROC: get_processes failed: %d", status);
buf+=sprintf(buf, "-process- -nr-prnt- -pid ppid grp- -uid--gid- -nice- -flags------\n");
for (i=0; i<NR_PROCS; i++) {
proc = &mprocs[i];
if (proc->mp_pid == 0 && i != PM_PROC_NR) continue;
buf+=sprintf(buf, "%8.8s %4d%4d %5d %5d %5d ",
proc->mp_name, i, proc->mp_parent, proc->mp_pid,
mprocs[proc->mp_parent].mp_pid, proc->mp_procgrp);
buf+=sprintf(buf, "%2d(%2d) %2d(%2d) ",
proc->mp_realuid, proc->mp_effuid,
proc->mp_realgid, proc->mp_effgid);
buf+=sprintf(buf, " %3d %s \n",
proc->mp_nice, flags_str(proc->mp_flags));
}
}
PRIVATE char *flags_str(int flags)
{
static char str[13];
str[0] = (flags & WAITING) ? 'W' : '-';
str[1] = (flags & ZOMBIE) ? 'Z' : '-';
str[2] = (flags & PAUSED) ? 'P' : '-';
str[3] = (flags & ALARM_ON) ? 'A' : '-';
str[4] = (flags & TRACED) ? 'T' : '-';
str[5] = (flags & STOPPED) ? 'S' : '-';
str[6] = (flags & SIGSUSPENDED) ? 'U' : '-';
str[7] = (flags & REPLY) ? 'R' : '-';
str[8] = (flags & PRIV_PROC) ? 'p' : '-';
str[9] = (flags & PM_SIG_PENDING) ? 's' : '-';
str[10] = (flags & PARTIAL_EXEC) ? 'x' : '-';
str[11] = (flags & EXITING) ? 'E' : '-';
str[12] = '\0';
return str;
}
#include "../drivers.h"
#include <stdio.h>
#include <time.h>
PUBLIC void get_uptime(char *buf, int bufSize)
{
clock_t user_time, sys_time, uptime;
int status, uptime_in_seconds;
int proc_nr = PROC_PROC_NR; /* arbitrary, we aren't using the proc's times */
status = sys_times(proc_nr, &user_time, &sys_time, &uptime);
if (status != OK) printf("PROC: couldn't get uptime: %d",status);
uptime_in_seconds = uptime / CLOCKS_PER_SEC;
sprintf(buf, "%d seconds since boot\n", uptime_in_seconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment