functionality). Currently working on memory allocation (not yet finished).
PRIVATE int m_device; /* current device */
PRIVATE struct kinfo kinfo; /* need kernel info */
PRIVATE struct machine machine; /* need machine info */
-PRIVATE struct memory mem[NR_MEMS]; /* physical memory chunks */
-FORWARD _PROTOTYPE( int alloc_mem, (phys_bytes size, phys_bytes *base) );
FORWARD _PROTOTYPE( char *m_name, (void) );
FORWARD _PROTOTYPE( struct device *m_prepare, (int device) );
FORWARD _PROTOTYPE( int m_transfer, (int proc_nr, int opcode, off_t position,
chunk = (left > ZERO_BUF_SIZE) ? ZERO_BUF_SIZE : left;
if (OK != (s=sys_vircopy(SELF, D, (vir_bytes) zero,
proc_nr, D, user_vir, chunk)))
- printf("MEMORY: sys_vircopy failed: %d\n", s);
+ report("MEM","sys_vircopy failed", s);
left -= chunk;
}
}
#if (CHIP == INTEL) && ENABLE_USERPRIV && ENABLE_USERIOPL
if (m_device == MEM_DEV || m_device == KMEM_DEV) {
sys_enable_iop(m_ptr->PROC_NR);
- printf("MEMORY: sys_enable_iop for proc nr %d.\n", m_ptr->PROC_NR);
+ report("MEM", "sys_enable_iop for proc nr", m_ptr->PROC_NR);
}
#endif
/* Initialize this task. All minor devices are initialized one by one. */
int i, s;
- /* Get memory addresses from the kernel. */
- if (OK != (s=sys_getmemchunks(&mem))) {
- panic("MEM","Couldn't get memory chunks.",s);
- }
if (OK != (s=sys_getkinfo(&kinfo))) {
panic("MEM","Couldn't get kernel information.",s);
}
#endif /* !(CHIP == INTEL) */
/* Initialization succeeded. Print welcome message. */
- printf("User-space memory driver (RAM disk, etc.) has been initialized.\n");
+ report("MEM","user-space memory driver has been initialized.", NO_NUM);
}
/* FS wants to create a new RAM disk with the given size. */
phys_bytes ramdev_size;
phys_bytes ramdev_base;
+ message m;
int s;
if (m_ptr->PROC_NR != FS_PROC_NR) return(EPERM);
/* Try to allocate a piece of memory for the RAM disk. */
ramdev_size = m_ptr->POSITION;
- if (OK != (s=alloc_mem(ramdev_size, &ramdev_base)))
- panic("MEM","Couldn't allocate kernel memory", s);
- dv->dv_base = cvul64(ramdev_base);
- dv->dv_size = cvul64(ramdev_size);
- printf("Test MEM: base 0x%06x, size 0x%06x\n", dv->dv_base, dv->dv_size);
+
+ printf("MEM: about to send to PM (ramdev_size %u)\n", ramdev_size);
+ m.m_type = MEM_ALLOC;
+ m.m4_l1 = ramdev_size;
+ if (OK != (s=sendrec(PM_PROC_NR, &m)))
+ report("MEM", "Couldn't sendrec to PM", s);
+ dv->dv_size = cvul64(m.m4_l1);
+ dv->dv_base = cvul64(m.m4_l2);
+ printf("MEM: PM (s=%d) gave base 0x%06x, size 0x%06x\n", s, dv->dv_base, dv->dv_size);
if (OK != (s=sys_kmalloc(ramdev_size, &ramdev_base)))
panic("MEM","Couldn't allocate kernel memory", s);
dv->dv_base = cvul64(ramdev_base);
dv->dv_size = cvul64(ramdev_size);
- printf("Real MEM: base 0x%06x, size 0x%06x\n", dv->dv_base, dv->dv_size);
+ printf("MEM allocated: base 0x%06x, size 0x%06x\n", dv->dv_base, dv->dv_size);
if (OK != (s=sys_segctl(&m_seg[RAM_DEV], (u16_t *) &s, (vir_bytes *) &s,
ramdev_base, ramdev_size))) {
panic("MEM","Couldn't install remote segment.",s);
entry->sectors = 32;
}
-/*===========================================================================*
- * malloc_mem *
- *===========================================================================*/
-PRIVATE int alloc_mem(chunk_size, chunk_base)
-phys_bytes chunk_size; /* number of bytes requested */
-phys_bytes *chunk_base; /* base of memory area found */
-{
-/* Request a piece of memory from one of the free memory chunks. */
- phys_clicks tot_clicks;
- struct memory *memp;
-
- tot_clicks = (chunk_size+ CLICK_SIZE-1) >> CLICK_SHIFT;
- memp = &mem[NR_MEMS];
- while ((--memp)->size < tot_clicks) {
- if (memp == mem) {
- return(ENOMEM);
- }
- }
- memp->size -= tot_clicks;
- *chunk_base = (memp->base + memp->size) << CLICK_SHIFT;
- return(OK);
-}
-#define NCALLS 83 /* number of system calls allowed */
+#define NCALLS 85 /* number of system calls allowed */
#define EXIT 1
#define FORK 2
#define SIGPROCMASK 74
#define SIGRETURN 75
-#define REBOOT 76
+#define REBOOT 76 /* to PM */
/* MINIX specific calls, e.g., to support system services. */
#define SVRCTL 77
-#define CMOSTIME 78
-#define GETSYSINFO 79 /* to MM or FS */
-#define GETPROCNR 80 /* to MM */
+#define CMOSTIME 78 /* to FS */
+#define GETSYSINFO 79 /* to PM or FS */
+#define GETPROCNR 80 /* to PM */
-#define FSTATFS 82
+#define FSTATFS 82 /* to FS */
+#define MEM_ALLOC 83 /* to PM */
+#define MEM_FREE 84 /* to PM */
_PROTOTYPE( char *crypt, (const char *_key, const char *_salt) );
_PROTOTYPE( int getsysinfo, (int who, int what, void *where) );
_PROTOTYPE( int getprocnr, (int *proc_nr) );
+_PROTOTYPE( int findproc, (char *proc_name, int *proc_nr) );
#endif
_PROTOTYPE( int setcache, (int kb));
allow(1, IS_PROC_NR) /* output diagnostics */ \
allow(1, SYSTASK) \
allow(1, TTY) \
+ allow(1, MEMORY) \
allow(1, CLOCK) \
allow(1, INIT_PROC_NR) \
allow(1, FS_PROC_NR) \
allow(1, SYSTASK) /* system functionality needed */ \
allow(1, CLOCK) /* check clock alarms */ \
allow(1, TTY) /* output diagnostics */ \
+ allow(1, PM_PROC_NR) /* PM alloc mem */ \
allow(1, FS_PROC_NR) /* FS is interface to the driver */
#define PRN_SENDMASK \
$(LIBRARY)(_svrctl.o) \
$(LIBRARY)(_getsysinfo.o) \
$(LIBRARY)(_getprocnr.o) \
+ $(LIBRARY)(_findproc.o) \
$(LIBRARY)(asynchio.o) \
$(LIBRARY)(configfile.o) \
$(LIBRARY)(crypt.o) \
$(LIBRARY)(_getprocnr.o): _getprocnr.c
$(CC1) _getprocnr.c
+$(LIBRARY)(_findproc.o): _findproc.c
+ $(CC1) _findproc.c
+
$(LIBRARY)(_getsysinfo.o): _getsysinfo.c
$(CC1) _getsysinfo.c
--- /dev/null
+#include <lib.h>
+#define findproc _findproc
+#include <unistd.h>
+#include <string.h>
+
+
+PUBLIC int findproc(proc_name, proc_nr)
+char *proc_name; /* name of process to search for */
+int *proc_nr; /* return process number here */
+{
+ message m;
+
+ m.m1_p1 = proc_name;
+ m.m1_i1 = strlen(proc_name) + 1;
+ if (_syscall(MM, GETPROCNR, &m) < 0) return(-1);
+ *proc_nr = m.m1_i1;
+ return(0);
+}
+
int *proc_nr; /* return process number here */
{
message m;
-
+ m.m1_i1 = 0; /* tell PM to get own process nr */
if (_syscall(MM, GETPROCNR, &m) < 0) return(-1);
*proc_nr = m.m1_i1;
return(0);
$(LIBRARY)(getppid.o) \
$(LIBRARY)(getuid.o) \
$(LIBRARY)(getprocnr.o) \
+ $(LIBRARY)(findproc.o) \
$(LIBRARY)(ioctl.o) \
$(LIBRARY)(isatty.o) \
$(LIBRARY)(kill.o) \
$(LIBRARY)(getprocnr.o): getprocnr.s
$(CC1) getprocnr.s
+$(LIBRARY)(findproc.o): findproc.s
+ $(CC1) findproc.s
+
$(LIBRARY)(getuid.o): getuid.s
$(CC1) getuid.s
--- /dev/null
+.sect .text
+.extern __findproc
+.define _findproc
+.align 2
+
+_findproc:
+ jmp __findproc
#include "fproc.h"
#include "dmap.h"
#include <string.h>
+#include <unistd.h>
#include <minix/com.h>
#include <minix/utils.h>
for (dp = drivertab;
dp < drivertab + sizeof(drivertab)/sizeof(drivertab[0]); dp++) {
if (strcmp(ctrlr_type, dp->wini_type) == 0) { /* found driver name */
+#if DEAD_CODE
if ((s=sys_getprocnr(&proc_nr, /* lookup proc nr */
dp->proc_name, strlen(dp->proc_name)+1)) == OK) {
+#endif
+ if ((s=findproc(dp->proc_name, &proc_nr)) == OK) {
for (i=0; i< max_major; i++) { /* find mapping */
if (dmap[i].dmap_driver == CTRLR(c)) {
if (map_driver(i, proc_nr, STYLE_DEV) == OK) {
/* Normally wait for new input. However, if 'reviving' is
* nonzero, a suspended process must be awakened.
*/
-
register struct fproc *rp;
if (reviving != 0) {
{
/* Initialize global variables, tables, etc. */
register struct inode *rip;
+ register struct fproc *rfp;
int key, s, i;
message mess;
- /* Certain relations must hold for the file system to work at all. Some
+ /* Initialize the process table with help of the process manager messages.
+ * Expect one message for each system process with its slot number and pid.
+ * When no more processes follow, the magic process number NONE is sent.
+ * Then, stop and synchronize with the PM.
+ */
+ do {
+ if (OK != (s=receive(PM_PROC_NR, &mess)))
+ panic(__FILE__,"FS couldn't receive from PM", s);
+ if (NONE == mess.PR_PROC_NR) break;
+
+ rfp = &fproc[mess.PR_PROC_NR];
+ rfp->fp_pid = mess.PR_PID;
+ rfp->fp_realuid = (uid_t) SYS_UID;
+ rfp->fp_effuid = (uid_t) SYS_UID;
+ rfp->fp_realgid = (gid_t) SYS_GID;
+ rfp->fp_effgid = (gid_t) SYS_GID;
+ rfp->fp_umask = ~0;
+
+ } while (TRUE); /* continue until process NONE */
+ mess.m_type = OK; /* tell PM that we succeeded */
+ s=send(PM_PROC_NR, &mess); /* send synchronization message */
+
+
+ /* All process table entries have been set. Continue with FS initialization.
+ * Certain relations must hold for the file system to work at all. Some
* extra block_size requirements are checked at super-block-read-in time.
*/
if (OPEN_MAX > 127) panic(__FILE__,"OPEN_MAX > 127", NO_NUM);
fp = (struct fproc *) NULL;
who = FS_PROC_NR;
- map_controllers(); /* map controller devices to drivers */
buf_pool(); /* initialize buffer pool */
+ map_controllers(); /* map controller devices to drivers */
load_ram(); /* init RAM disk, load if it is root */
load_super(root_dev); /* load super block for root device */
- /* Initialize the process table with help of the process manager messages.
- * Expect one message for each system process with its slot number and pid.
- * When no more processes follow, the magic process number NONE is sent.
- * Then, stop and synchronize with the PM.
- */
- do {
- if (OK != (s=receive(PM_PROC_NR, &mess)))
- panic(__FILE__,"FS couldn't receive from PM", s);
- if (NONE == mess.PR_PROC_NR) break;
-
- fp = &fproc[mess.PR_PROC_NR];
- fp->fp_pid = mess.PR_PID;
- rip = get_inode(root_dev, ROOT_INODE);
- dup_inode(rip);
- fp->fp_rootdir = rip;
- fp->fp_workdir = rip;
- fp->fp_realuid = (uid_t) SYS_UID;
- fp->fp_effuid = (uid_t) SYS_UID;
- fp->fp_realgid = (gid_t) SYS_GID;
- fp->fp_effgid = (gid_t) SYS_GID;
- fp->fp_umask = ~0;
-
- } while (TRUE); /* continue until process NONE */
- mess.m_type = OK; /* tell PM that we succeeded */
- s=send(PM_PROC_NR, &mess); /* send synchronization message */
+ /* The root device can now be accessed; set process directories. */
+ for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
+ if (rfp->fp_pid != PID_FREE) {
+ rip = get_inode(root_dev, ROOT_INODE);
+ dup_inode(rip);
+ rfp->fp_rootdir = rip;
+ rfp->fp_workdir = rip;
+ }
+ }
/* Register function keys with TTY. */
for (key=SF5; key<=SF6; key++) {
no_sys, /* 80 = unused */
no_sys, /* 81 = unused */
do_fstatfs, /* 82 = fstatfs */
+ no_sys, /* 83 = memalloc */
+ no_sys, /* 84 = memfree */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
if (svrctl(SYSSIGNON, (void *) NULL) == -1) pause();
/* Our new identity as a server. */
+#if DEAD_CODE
if (get_proc_nr(&this_proc, NULL) != OK)
- ip_panic(( "unable to find own process nr\n"));
+#endif
+ if (getprocnr(&this_proc) != OK)
+ ip_panic(( "unable to get own process nr\n"));
/* Register the device group. */
device.dev= ip_dev;
#include "generic/sr.h"
#include <minix/syslib.h>
+#define _MINIX
+#include <unistd.h>
THIS_FILE
for (i= 0, eth_port= eth_port_table, ecp= eth_conf;
i<eth_conf_nr; i++, eth_port++, ecp++)
{
- printf("INET: sys_getprocnr() for %s\n", ecp->ec_task);
+#if DEAD_CODE
r = sys_getprocnr(&tasknr, ecp->ec_task, strlen(ecp->ec_task));
+#endif
+ r = findproc(ecp->ec_task, &tasknr);
if (r != OK)
{
ip_panic(( "unable to find task %s: %d\n",
* The entry points into this file are:
* do_reboot: kill all processes, then reboot system
* do_svrctl: process manager control
- * do_getsysinfo: request copy of PM data structure
- * do_getprocnr: get process slot number (like getpid)
+ * do_getsysinfo: request copy of PM data structure (Jorrit N. Herder)
+ * do_getprocnr: lookup process slot number (Jorrit N. Herder)
+ * do_memalloc: allocate a chunk of memory (Jorrit N. Herder)
+ * do_memfree: deallocate a chunk of memory (Jorrit N. Herder)
*/
#include "pm.h"
/* PM gets a copy of all boot monitor parameters. */
PRIVATE char monitor_params[128*sizeof(char *)];
+/*=====================================================================*
+ * do_memalloc *
+ *=====================================================================*/
+PUBLIC int do_memalloc()
+{
+ vir_clicks mem_clicks;
+ phys_clicks mem_base;
+ printf("PM got request to allocate %u KB\n", m_in.memsize);
+
+ mem_clicks = (m_in.memsize + CLICK_SIZE -1 ) >> CLICK_SHIFT;
+ mem_base = alloc_mem(mem_clicks);
+ if (mem_base == NO_MEM) return(ENOMEM);
+ mp->mp_reply.membase = (phys_bytes) (mem_base << CLICK_SHIFT);
+ return(OK);
+}
+
+/*=====================================================================*
+ * do_memfree *
+ *=====================================================================*/
+PUBLIC int do_memfree()
+{
+ return(OK);
+}
+
/*=====================================================================*
* do_getsysinfo *
*=====================================================================*/
*=====================================================================*/
PUBLIC int do_getprocnr()
{
- mp->mp_reply.procnr = who;
+ register struct mproc *rmp;
+ static char search_key[PROC_NAME_LEN];
+ int key_len;
+ int s;
+
+ if (m_in.namelen > 0) { /* lookup process by name */
+ key_len = MAX(m_in.namelen, PROC_NAME_LEN);
+ if (OK != (s=sys_datacopy(who, (vir_bytes) m_in.addr,
+ SELF, (vir_bytes) search_key, key_len)))
+ return(s);
+ search_key[key_len] = '\0'; /* terminate for safety */
+ for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
+ if (rmp->mp_flags & IN_USE &&
+ strncmp(rmp->mp_name, search_key, key_len)==0) {
+ mp->mp_reply.procnr = (int) (rmp - mproc);
+ return(OK);
+ }
+ }
+ return(ESRCH);
+ }
+ else { /* return own process number */
+ mp->mp_reply.procnr = who;
+ }
return(OK);
}
#define svrctl_req m2_i1
#define svrctl_argp m2_p1
#define stime m2_l1
+#define memsize m4_l1
+#define membase m4_l2
/* The following names are synonyms for the variables in a reply message. */
#define reply_res m_type
_PROTOTYPE( int do_getsysinfo, (void) );
_PROTOTYPE( int do_getprocnr, (void) );
_PROTOTYPE( int do_svrctl, (void) );
+_PROTOTYPE( int do_memalloc, (void) );
+_PROTOTYPE( int do_memfree, (void) );
_PROTOTYPE( int do_mstats, (void) );
#if (MACHINE == MACINTOSH)
do_getsysinfo, /* 79 = getsysinfo */
do_getprocnr, /* 80 = getprocnr */
no_sys, /* 81 = unused */
- no_sys, /* 82 = unused */
+ no_sys, /* 82 = fstatfs */
+ do_memalloc, /* 83 = memalloc */
+ do_memfree, /* 84 = memfree */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
#define NIL_MPROC ((struct mproc *) 0)
-FORWARD _PROTOTYPE( struct mproc *findproc, (pid_t lpid) );
+FORWARD _PROTOTYPE( struct mproc *find_proc, (pid_t lpid) );
/*===========================================================================*
* do_trace *
mp->mp_reply.reply_trace = 0;
return(OK);
}
- if ((child=findproc(m_in.pid))==NIL_MPROC || !(child->mp_flags & STOPPED)) {
+ if ((child=find_proc(m_in.pid))==NIL_MPROC || !(child->mp_flags & STOPPED)) {
return(ESRCH);
}
/* all the other calls are made by the parent fork of the debugger to
}
/*===========================================================================*
- * findproc *
+ * find_proc *
*===========================================================================*/
-PRIVATE struct mproc *findproc(lpid)
+PRIVATE struct mproc *find_proc(lpid)
pid_t lpid;
{
register struct mproc *rmp;