2005-05-13 10:57:08 +02:00
|
|
|
/* This file contains the main program of the process manager and some related
|
2005-05-03 17:35:52 +02:00
|
|
|
* procedures. When MINIX starts up, the kernel runs for a little while,
|
2005-05-13 10:57:08 +02:00
|
|
|
* initializing itself and its tasks, and then it runs PM and FS. Both PM
|
2005-06-17 11:10:30 +02:00
|
|
|
* and FS initialize themselves as far as they can. PM asks the kernel for
|
|
|
|
* all free memory and starts serving requests.
|
2005-05-03 17:35:52 +02:00
|
|
|
*
|
|
|
|
* The entry points into this file are:
|
2005-05-13 10:57:08 +02:00
|
|
|
* main: starts PM running
|
|
|
|
* setreply: set the reply to be sent to process making an PM system call
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
#include "pm.h"
|
|
|
|
#include <minix/keymap.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
#include <minix/endpoint.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <signal.h>
|
2005-06-17 11:10:30 +02:00
|
|
|
#include <stdlib.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include <fcntl.h>
|
2005-08-22 17:14:11 +02:00
|
|
|
#include <sys/resource.h>
|
2005-05-13 10:57:08 +02:00
|
|
|
#include <string.h>
|
2005-05-03 17:35:52 +02:00
|
|
|
#include "mproc.h"
|
|
|
|
#include "param.h"
|
|
|
|
|
2005-05-31 11:50:51 +02:00
|
|
|
#include "../../kernel/const.h"
|
2005-07-14 17:16:12 +02:00
|
|
|
#include "../../kernel/config.h"
|
2005-05-13 10:57:08 +02:00
|
|
|
#include "../../kernel/type.h"
|
2005-08-22 17:14:11 +02:00
|
|
|
#include "../../kernel/proc.h"
|
2005-05-13 10:57:08 +02:00
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
FORWARD _PROTOTYPE( void get_work, (void) );
|
2005-05-13 10:57:08 +02:00
|
|
|
FORWARD _PROTOTYPE( void pm_init, (void) );
|
2005-09-11 18:45:46 +02:00
|
|
|
FORWARD _PROTOTYPE( int get_nice_value, (int queue) );
|
2005-06-17 11:10:30 +02:00
|
|
|
FORWARD _PROTOTYPE( void get_mem_chunks, (struct memory *mem_chunks) );
|
|
|
|
FORWARD _PROTOTYPE( void patch_mem_chunks, (struct memory *mem_chunks,
|
|
|
|
struct mem_map *map_ptr) );
|
2005-09-30 14:56:00 +02:00
|
|
|
FORWARD _PROTOTYPE( void do_x86_vm, (struct memory mem_chunks[NR_MEMS]) );
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
#define click_to_round_k(n) \
|
|
|
|
((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* main *
|
|
|
|
*===========================================================================*/
|
2005-08-25 14:05:09 +02:00
|
|
|
PUBLIC int main()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Main routine of the process manager. */
|
2005-05-27 15:10:58 +02:00
|
|
|
int result, s, proc_nr;
|
2005-05-03 17:35:52 +02:00
|
|
|
struct mproc *rmp;
|
2005-07-19 14:11:11 +02:00
|
|
|
sigset_t sigset;
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
pm_init(); /* initialize process manager tables */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* This is PM's main loop- get work and do it, forever and forever. */
|
2005-05-03 17:35:52 +02:00
|
|
|
while (TRUE) {
|
2005-05-13 10:57:08 +02:00
|
|
|
get_work(); /* wait for an PM system call */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
/* Check for system notifications first. Special cases. */
|
2005-08-05 12:45:54 +02:00
|
|
|
if (call_nr == SYN_ALARM) {
|
|
|
|
pm_expire_timers(m_in.NOTIFY_TIMESTAMP);
|
2005-07-14 17:16:12 +02:00
|
|
|
result = SUSPEND; /* don't reply */
|
2005-08-02 17:29:17 +02:00
|
|
|
} else if (call_nr == SYS_SIG) { /* signals pending */
|
2005-07-19 14:11:11 +02:00
|
|
|
sigset = m_in.NOTIFY_ARG;
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (sigismember(&sigset, SIGKSIG)) {
|
|
|
|
(void) ksig_pending();
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
result = SUSPEND; /* don't reply */
|
|
|
|
}
|
|
|
|
/* Else, if the system call number is valid, perform the call. */
|
|
|
|
else if ((unsigned) call_nr >= NCALLS) {
|
|
|
|
result = ENOSYS;
|
|
|
|
} else {
|
|
|
|
result = (*call_vec[call_nr])();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the results back to the user to indicate completion. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (result != SUSPEND) setreply(who_p, result);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
|
|
|
swap_in(); /* maybe a process can be swapped in? */
|
|
|
|
|
|
|
|
/* Send out all pending reply messages, including the answer to
|
|
|
|
* the call just made above. The processes must not be swapped out.
|
|
|
|
*/
|
|
|
|
for (proc_nr=0, rmp=mproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
|
2005-07-04 17:20:46 +02:00
|
|
|
/* In the meantime, the process may have been killed by a
|
|
|
|
* signal (e.g. if a lethal pending signal was unblocked)
|
|
|
|
* without the PM realizing it. If the slot is no longer in
|
|
|
|
* use or just a zombie, don't try to reply.
|
|
|
|
*/
|
|
|
|
if ((rmp->mp_flags & (REPLY | ONSWAP | IN_USE | ZOMBIE)) ==
|
|
|
|
(REPLY | IN_USE)) {
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if ((s=send(rmp->mp_endpoint, &rmp->mp_reply)) != OK) {
|
|
|
|
panic(__FILE__,"PM can't reply to",
|
|
|
|
rmp->mp_endpoint);
|
2005-05-27 15:10:58 +02:00
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
rmp->mp_flags &= ~REPLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-25 14:05:09 +02:00
|
|
|
return(OK);
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_work *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void get_work()
|
|
|
|
{
|
|
|
|
/* Wait for the next message and extract useful information from it. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if (receive(ANY, &m_in) != OK)
|
|
|
|
panic(__FILE__,"PM receive error", NO_NUM);
|
|
|
|
who_e = m_in.m_source; /* who sent the message */
|
|
|
|
if(pm_isokendpt(who_e, &who_p) != OK)
|
|
|
|
panic(__FILE__, "PM got message from invalid endpoint", who_e);
|
2005-05-03 17:35:52 +02:00
|
|
|
call_nr = m_in.m_type; /* system call number */
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Process slot of caller. Misuse PM's own process slot if the kernel is
|
2005-07-19 14:11:11 +02:00
|
|
|
* calling. This can happen in case of synchronous alarms (CLOCK) or or
|
|
|
|
* event like pending kernel signals (SYSTEM).
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mp = &mproc[who_p < 0 ? PM_PROC_NR : who_p];
|
|
|
|
if(who_p >= 0 && mp->mp_endpoint != who_e) {
|
|
|
|
panic(__FILE__, "PM endpoint number out of sync with source",
|
|
|
|
mp->mp_endpoint);
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* setreply *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void setreply(proc_nr, result)
|
|
|
|
int proc_nr; /* process to reply to */
|
2005-05-13 10:57:08 +02:00
|
|
|
int result; /* result of call (usually OK or error #) */
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
|
|
|
/* Fill in a reply message to be sent later to a user process. System calls
|
|
|
|
* may occasionally fill in other fields, this is only for the main return
|
|
|
|
* value, and for setting the "must send reply" flag.
|
|
|
|
*/
|
|
|
|
register struct mproc *rmp = &mproc[proc_nr];
|
|
|
|
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
if(proc_nr < 0 || proc_nr >= NR_PROCS)
|
|
|
|
panic(__FILE__,"setreply arg out of range", proc_nr);
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
rmp->mp_reply.reply_res = result;
|
|
|
|
rmp->mp_flags |= REPLY; /* reply pending */
|
|
|
|
|
|
|
|
if (rmp->mp_flags & ONSWAP)
|
|
|
|
swap_inqueue(rmp); /* must swap this process back in */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-05-13 10:57:08 +02:00
|
|
|
* pm_init *
|
2005-05-03 17:35:52 +02:00
|
|
|
*===========================================================================*/
|
2005-05-13 10:57:08 +02:00
|
|
|
PRIVATE void pm_init()
|
2005-05-03 17:35:52 +02:00
|
|
|
{
|
2005-08-16 13:37:33 +02:00
|
|
|
/* Initialize the process manager.
|
|
|
|
* Memory use info is collected from the boot monitor, the kernel, and
|
|
|
|
* all processes compiled into the system image. Initially this information
|
|
|
|
* is put into an array mem_chunks. Elements of mem_chunks are struct memory,
|
|
|
|
* and hold base, size pairs in units of clicks. This array is small, there
|
|
|
|
* should be no more than 8 chunks. After the array of chunks has been built
|
|
|
|
* the contents are used to initialize the hole list. Space for the hole list
|
|
|
|
* is reserved as an array with twice as many elements as the maximum number
|
|
|
|
* of processes allowed. It is managed as a linked list, and elements of the
|
|
|
|
* array are struct hole, which, in addition to storage for a base and size in
|
|
|
|
* click units also contain space for a link, a pointer to another element.
|
|
|
|
*/
|
2005-08-25 14:05:09 +02:00
|
|
|
int s;
|
2005-07-29 17:00:49 +02:00
|
|
|
static struct boot_image image[NR_BOOT_PROCS];
|
|
|
|
register struct boot_image *ip;
|
2005-05-03 17:35:52 +02:00
|
|
|
static char core_sigs[] = { SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
|
|
|
|
SIGEMT, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2 };
|
2006-01-30 17:27:49 +01:00
|
|
|
static char ign_sigs[] = { SIGCHLD, SIGWINCH, SIGCONT };
|
2005-10-12 17:07:38 +02:00
|
|
|
static char mess_sigs[] = { SIGTERM, SIGHUP, SIGABRT, SIGQUIT };
|
2005-05-03 17:35:52 +02:00
|
|
|
register struct mproc *rmp;
|
2005-10-12 17:07:38 +02:00
|
|
|
register int i;
|
2005-05-03 17:35:52 +02:00
|
|
|
register char *sig_ptr;
|
2005-06-24 18:21:21 +02:00
|
|
|
phys_clicks total_clicks, minix_clicks, free_clicks;
|
2005-05-03 17:35:52 +02:00
|
|
|
message mess;
|
2005-06-17 11:10:30 +02:00
|
|
|
struct mem_map mem_map[NR_LOCAL_SEGS];
|
|
|
|
struct memory mem_chunks[NR_MEMS];
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-07-14 17:16:12 +02:00
|
|
|
/* Initialize process table, including timers. */
|
|
|
|
for (rmp=&mproc[0]; rmp<&mproc[NR_PROCS]; rmp++) {
|
|
|
|
tmr_inittimer(&rmp->mp_timer);
|
|
|
|
}
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
/* Build the set of signals which cause core dumps, and the set of signals
|
|
|
|
* that are by default ignored.
|
|
|
|
*/
|
|
|
|
sigemptyset(&core_sset);
|
|
|
|
for (sig_ptr = core_sigs; sig_ptr < core_sigs+sizeof(core_sigs); sig_ptr++)
|
|
|
|
sigaddset(&core_sset, *sig_ptr);
|
|
|
|
sigemptyset(&ign_sset);
|
|
|
|
for (sig_ptr = ign_sigs; sig_ptr < ign_sigs+sizeof(ign_sigs); sig_ptr++)
|
|
|
|
sigaddset(&ign_sset, *sig_ptr);
|
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Obtain a copy of the boot monitor parameters and the kernel info struct.
|
|
|
|
* Parse the list of free memory chunks. This list is what the boot monitor
|
|
|
|
* reported, but it must be corrected for the kernel and system processes.
|
|
|
|
*/
|
|
|
|
if ((s=sys_getmonparams(monitor_params, sizeof(monitor_params))) != OK)
|
|
|
|
panic(__FILE__,"get monitor params failed",s);
|
2005-08-16 13:37:33 +02:00
|
|
|
get_mem_chunks(mem_chunks);
|
2005-06-17 11:10:30 +02:00
|
|
|
if ((s=sys_getkinfo(&kinfo)) != OK)
|
|
|
|
panic(__FILE__,"get kernel info failed",s);
|
|
|
|
|
2005-05-03 17:35:52 +02:00
|
|
|
/* Get the memory map of the kernel to see how much memory it uses. */
|
2005-06-17 11:10:30 +02:00
|
|
|
if ((s=get_mem_map(SYSTASK, mem_map)) != OK)
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"couldn't get memory map of SYSTASK",s);
|
2005-06-17 11:10:30 +02:00
|
|
|
minix_clicks = (mem_map[S].mem_phys+mem_map[S].mem_len)-mem_map[T].mem_phys;
|
|
|
|
patch_mem_chunks(mem_chunks, mem_map);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Initialize PM's process table. Request a copy of the system image table
|
|
|
|
* that is defined at the kernel level to see which slots to fill in.
|
2005-05-03 17:35:52 +02:00
|
|
|
*/
|
2005-06-24 18:21:21 +02:00
|
|
|
if (OK != (s=sys_getimage(image)))
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"couldn't get image table: %d\n", s);
|
2005-05-13 10:57:08 +02:00
|
|
|
procs_in_use = 0; /* start populating table */
|
2005-08-05 00:01:50 +02:00
|
|
|
printf("Building process table:"); /* show what's happening */
|
2005-07-14 17:16:12 +02:00
|
|
|
for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {
|
2005-05-13 10:57:08 +02:00
|
|
|
if (ip->proc_nr >= 0) { /* task have negative nrs */
|
|
|
|
procs_in_use += 1; /* found user process */
|
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Set process details found in the image table. */
|
|
|
|
rmp = &mproc[ip->proc_nr];
|
2005-05-13 10:57:08 +02:00
|
|
|
strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN);
|
2005-08-23 13:31:32 +02:00
|
|
|
rmp->mp_parent = RS_PROC_NR;
|
2005-08-22 17:14:11 +02:00
|
|
|
rmp->mp_nice = get_nice_value(ip->priority);
|
2005-10-12 17:07:38 +02:00
|
|
|
sigemptyset(&rmp->mp_sig2mess);
|
|
|
|
sigemptyset(&rmp->mp_ignore);
|
|
|
|
sigemptyset(&rmp->mp_sigmask);
|
|
|
|
sigemptyset(&rmp->mp_catch);
|
2005-07-19 14:11:11 +02:00
|
|
|
if (ip->proc_nr == INIT_PROC_NR) { /* user process */
|
2006-02-03 15:54:20 +01:00
|
|
|
rmp->mp_procgrp = rmp->mp_pid = INIT_PID;
|
2005-07-19 14:11:11 +02:00
|
|
|
rmp->mp_flags |= IN_USE;
|
|
|
|
}
|
|
|
|
else { /* system process */
|
|
|
|
rmp->mp_pid = get_free_pid();
|
|
|
|
rmp->mp_flags |= IN_USE | DONT_SWAP | PRIV_PROC;
|
2005-10-12 17:07:38 +02:00
|
|
|
for (sig_ptr = mess_sigs;
|
|
|
|
sig_ptr < mess_sigs+sizeof(mess_sigs);
|
|
|
|
sig_ptr++)
|
|
|
|
sigaddset(&rmp->mp_sig2mess, *sig_ptr);
|
2005-07-19 14:11:11 +02:00
|
|
|
}
|
2005-05-13 10:57:08 +02:00
|
|
|
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
/* Get kernel endpoint identifier. */
|
|
|
|
rmp->mp_endpoint = ip->endpoint;
|
|
|
|
|
2005-05-13 10:57:08 +02:00
|
|
|
/* Get memory map for this process from the kernel. */
|
|
|
|
if ((s=get_mem_map(ip->proc_nr, rmp->mp_seg)) != OK)
|
2005-06-01 16:31:00 +02:00
|
|
|
panic(__FILE__,"couldn't get process entry",s);
|
2005-05-13 10:57:08 +02:00
|
|
|
if (rmp->mp_seg[T].mem_len != 0) rmp->mp_flags |= SEPARATE;
|
|
|
|
minix_clicks += rmp->mp_seg[S].mem_phys +
|
|
|
|
rmp->mp_seg[S].mem_len - rmp->mp_seg[T].mem_phys;
|
2005-06-17 11:10:30 +02:00
|
|
|
patch_mem_chunks(mem_chunks, rmp->mp_seg);
|
2005-05-13 10:57:08 +02:00
|
|
|
|
|
|
|
/* Tell FS about this system process. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_SLOT = ip->proc_nr;
|
2005-05-13 10:57:08 +02:00
|
|
|
mess.PR_PID = rmp->mp_pid;
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_ENDPT = rmp->mp_endpoint;
|
2005-05-13 10:57:08 +02:00
|
|
|
if (OK != (s=send(FS_PROC_NR, &mess)))
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"can't sync up with FS", s);
|
2005-08-03 16:17:28 +02:00
|
|
|
printf(" %s", ip->proc_name); /* display process name */
|
2005-05-13 10:57:08 +02:00
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
2005-08-03 16:17:28 +02:00
|
|
|
printf(".\n"); /* last process done */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-10-12 17:07:38 +02:00
|
|
|
/* Override some details. INIT, PM, FS and RS are somewhat special. */
|
|
|
|
mproc[PM_PROC_NR].mp_pid = PM_PID; /* PM has magic pid */
|
|
|
|
mproc[RS_PROC_NR].mp_parent = INIT_PROC_NR; /* INIT is root */
|
|
|
|
sigfillset(&mproc[PM_PROC_NR].mp_ignore); /* guard against signals */
|
2005-06-24 18:21:21 +02:00
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Tell FS that no more system processes follow and synchronize. */
|
endpoint-aware conversion of servers.
'who', indicating caller number in pm and fs and some other servers, has
been removed in favour of 'who_e' (endpoint) and 'who_p' (proc nr.).
In both PM and FS, isokendpt() convert endpoints to process slot
numbers, returning OK if it was a valid and consistent endpoint number.
okendpt() does the same but panic()s if it doesn't succeed. (In PM,
this is pm_isok..)
pm and fs keep their own records of process endpoints in their proc tables,
which are needed to make kernel calls about those processes.
message field names have changed.
fs drivers are endpoints.
fs now doesn't try to get out of driver deadlock, as the protocol isn't
supposed to let that happen any more. (A warning is printed if ELOCKED
is detected though.)
fproc[].fp_task (indicating which driver the process is suspended on)
became an int.
PM and FS now get endpoint numbers of initial boot processes from the
kernel. These happen to be the same as the old proc numbers, to let
user processes reach them with the old numbers, but FS and PM don't know
that. All new processes after INIT, even after the generation number
wraps around, get endpoint numbers with generation 1 and higher, so
the first instances of the boot processes are the only processes ever
to have endpoint numbers in the old proc number range.
More return code checks of sys_* functions have been added.
IS has become endpoint-aware. Ditched the 'text' and 'data' fields
in the kernel dump (which show locations, not sizes, so aren't terribly
useful) in favour of the endpoint number. Proc number is still visible.
Some other dumps (e.g. dmap, rs) show endpoint numbers now too which got
the formatting changed.
PM reading segments using rw_seg() has changed - it uses other fields
in the message now instead of encoding the segment and process number and
fd in the fd field. For that it uses _read_pm() and _write_pm() which to
_taskcall()s directly in pm/misc.c.
PM now sys_exit()s itself on panic(), instead of sys_abort().
RS also talks in endpoints instead of process numbers.
2006-03-03 11:20:58 +01:00
|
|
|
mess.PR_ENDPT = NONE;
|
2005-05-13 10:57:08 +02:00
|
|
|
if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK)
|
2005-08-05 12:45:54 +02:00
|
|
|
panic(__FILE__,"can't sync up with FS", NO_NUM);
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-08-10 11:45:49 +02:00
|
|
|
#if ENABLE_BOOTDEV
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Possibly we must correct the memory chunks for the boot device. */
|
|
|
|
if (kinfo.bootdev_size > 0) {
|
|
|
|
mem_map[T].mem_phys = kinfo.bootdev_base >> CLICK_SHIFT;
|
|
|
|
mem_map[T].mem_len = 0;
|
|
|
|
mem_map[D].mem_len = (kinfo.bootdev_size+CLICK_SIZE-1) >> CLICK_SHIFT;
|
|
|
|
patch_mem_chunks(mem_chunks, mem_map);
|
|
|
|
}
|
2005-08-10 11:45:49 +02:00
|
|
|
#endif /* ENABLE_BOOTDEV */
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-09-30 14:56:00 +02:00
|
|
|
/* Withhold some memory from x86 VM */
|
|
|
|
do_x86_vm(mem_chunks);
|
|
|
|
|
2005-06-17 11:10:30 +02:00
|
|
|
/* Initialize tables to all physical memory and print memory information. */
|
2005-08-05 18:46:27 +02:00
|
|
|
printf("Physical memory:");
|
2005-06-17 11:10:30 +02:00
|
|
|
mem_init(mem_chunks, &free_clicks);
|
|
|
|
total_clicks = minix_clicks + free_clicks;
|
2005-08-03 18:06:35 +02:00
|
|
|
printf(" total %u KB,", click_to_round_k(total_clicks));
|
|
|
|
printf(" system %u KB,", click_to_round_k(minix_clicks));
|
2005-08-03 18:58:22 +02:00
|
|
|
printf(" free %u KB.\n", click_to_round_k(free_clicks));
|
2005-06-17 11:10:30 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_nice_value *
|
|
|
|
*===========================================================================*/
|
2005-08-22 17:14:11 +02:00
|
|
|
PRIVATE int get_nice_value(queue)
|
|
|
|
int queue; /* store mem chunks here */
|
|
|
|
{
|
|
|
|
/* Processes in the boot image have a priority assigned. The PM doesn't know
|
|
|
|
* about priorities, but uses 'nice' values instead. The priority is between
|
|
|
|
* MIN_USER_Q and MAX_USER_Q. We have to scale between PRIO_MIN and PRIO_MAX.
|
|
|
|
*/
|
|
|
|
int nice_val = (queue - USER_Q) * (PRIO_MAX-PRIO_MIN+1) /
|
|
|
|
(MIN_USER_Q-MAX_USER_Q+1);
|
|
|
|
if (nice_val > PRIO_MAX) nice_val = PRIO_MAX; /* shouldn't happen */
|
|
|
|
if (nice_val < PRIO_MIN) nice_val = PRIO_MIN; /* shouldn't happen */
|
|
|
|
return nice_val;
|
|
|
|
}
|
2005-06-17 11:10:30 +02:00
|
|
|
|
2005-08-05 00:01:50 +02:00
|
|
|
#if _WORD_SIZE == 2
|
2005-06-17 11:10:30 +02:00
|
|
|
/* In real mode only 1M can be addressed, and in 16-bit protected we can go
|
|
|
|
* no further than we can count in clicks. (The 286 is further limited by
|
|
|
|
* its 24 bit address bus, but we can assume in that case that no more than
|
|
|
|
* 16M memory is reported by the BIOS.)
|
|
|
|
*/
|
|
|
|
#define MAX_REAL 0x00100000L
|
|
|
|
#define MAX_16BIT (0xFFF0L << CLICK_SHIFT)
|
2005-08-05 00:01:50 +02:00
|
|
|
#endif
|
2005-06-17 11:10:30 +02:00
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_mem_chunks *
|
|
|
|
*===========================================================================*/
|
2005-06-17 11:10:30 +02:00
|
|
|
PRIVATE void get_mem_chunks(mem_chunks)
|
|
|
|
struct memory *mem_chunks; /* store mem chunks here */
|
|
|
|
{
|
|
|
|
/* Initialize the free memory list from the 'memory' boot variable. Translate
|
|
|
|
* the byte offsets and sizes in this list to clicks, properly truncated. Also
|
|
|
|
* make sure that we don't exceed the maximum address space of the 286 or the
|
|
|
|
* 8086, i.e. when running in 16-bit protected mode or real mode.
|
|
|
|
*/
|
|
|
|
long base, size, limit;
|
|
|
|
char *s, *end; /* use to parse boot variable */
|
2005-06-20 01:16:08 +02:00
|
|
|
int i, done = 0;
|
2005-06-17 11:10:30 +02:00
|
|
|
struct memory *memp;
|
|
|
|
#if _WORD_SIZE == 2
|
|
|
|
unsigned long max_address;
|
|
|
|
struct machine machine;
|
|
|
|
if (OK != (i=sys_getmachine(&machine)))
|
|
|
|
panic(__FILE__, "sys_getmachine failed", i);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize everything to zero. */
|
|
|
|
for (i = 0; i < NR_MEMS; i++) {
|
|
|
|
memp = &mem_chunks[i]; /* next mem chunk is stored here */
|
|
|
|
memp->base = memp->size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The available memory is determined by MINIX' boot loader as a list of
|
|
|
|
* (base:size)-pairs in boothead.s. The 'memory' boot variable is set in
|
|
|
|
* in boot.s. The format is "b0:s0,b1:s1,b2:s2", where b0:s0 is low mem,
|
|
|
|
* b1:s1 is mem between 1M and 16M, b2:s2 is mem above 16M. Pairs b1:s1
|
|
|
|
* and b2:s2 are combined if the memory is adjacent.
|
|
|
|
*/
|
|
|
|
s = find_param("memory"); /* get memory boot variable */
|
2005-06-20 01:16:08 +02:00
|
|
|
for (i = 0; i < NR_MEMS && !done; i++) {
|
2005-06-17 11:10:30 +02:00
|
|
|
memp = &mem_chunks[i]; /* next mem chunk is stored here */
|
|
|
|
base = size = 0; /* initialize next base:size pair */
|
|
|
|
if (*s != 0) { /* get fresh data, unless at end */
|
|
|
|
|
|
|
|
/* Read fresh base and expect colon as next char. */
|
|
|
|
base = strtoul(s, &end, 0x10); /* get number */
|
|
|
|
if (end != s && *end == ':') s = ++end; /* skip ':' */
|
|
|
|
else *s=0; /* terminate, should not happen */
|
|
|
|
|
|
|
|
/* Read fresh size and expect comma or assume end. */
|
|
|
|
size = strtoul(s, &end, 0x10); /* get number */
|
|
|
|
if (end != s && *end == ',') s = ++end; /* skip ',' */
|
2005-06-20 01:16:08 +02:00
|
|
|
else done = 1;
|
2005-06-17 11:10:30 +02:00
|
|
|
}
|
|
|
|
limit = base + size;
|
|
|
|
#if _WORD_SIZE == 2
|
|
|
|
max_address = machine.protected ? MAX_16BIT : MAX_REAL;
|
|
|
|
if (limit > max_address) limit = max_address;
|
|
|
|
#endif
|
|
|
|
base = (base + CLICK_SIZE-1) & ~(long)(CLICK_SIZE-1);
|
|
|
|
limit &= ~(long)(CLICK_SIZE-1);
|
|
|
|
if (limit <= base) continue;
|
|
|
|
memp->base = base >> CLICK_SHIFT;
|
|
|
|
memp->size = (limit - base) >> CLICK_SHIFT;
|
|
|
|
}
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* patch_mem_chunks *
|
|
|
|
*===========================================================================*/
|
2005-06-17 11:10:30 +02:00
|
|
|
PRIVATE void patch_mem_chunks(mem_chunks, map_ptr)
|
|
|
|
struct memory *mem_chunks; /* store mem chunks here */
|
|
|
|
struct mem_map *map_ptr; /* memory to remove */
|
|
|
|
{
|
|
|
|
/* Remove server memory from the free memory list. The boot monitor
|
|
|
|
* promises to put processes at the start of memory chunks. The
|
|
|
|
* tasks all use same base address, so only the first task changes
|
|
|
|
* the memory lists. The servers and init have their own memory
|
|
|
|
* spaces and their memory will be removed from the list.
|
|
|
|
*/
|
|
|
|
struct memory *memp;
|
|
|
|
for (memp = mem_chunks; memp < &mem_chunks[NR_MEMS]; memp++) {
|
|
|
|
if (memp->base == map_ptr[T].mem_phys) {
|
|
|
|
memp->base += map_ptr[T].mem_len + map_ptr[D].mem_len;
|
|
|
|
memp->size -= map_ptr[T].mem_len + map_ptr[D].mem_len;
|
|
|
|
}
|
|
|
|
}
|
2005-05-03 17:35:52 +02:00
|
|
|
}
|
2005-06-17 11:10:30 +02:00
|
|
|
|
2005-09-30 14:56:00 +02:00
|
|
|
#define PAGE_SIZE 4096
|
|
|
|
#define PAGE_TABLE_COVER (1024*PAGE_SIZE)
|
|
|
|
/*=========================================================================*
|
|
|
|
* do_x86_vm *
|
|
|
|
*=========================================================================*/
|
|
|
|
PRIVATE void do_x86_vm(mem_chunks)
|
|
|
|
struct memory mem_chunks[NR_MEMS];
|
|
|
|
{
|
|
|
|
phys_bytes high, bytes;
|
|
|
|
phys_clicks clicks, base_click;
|
|
|
|
unsigned pages;
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
/* Compute the highest memory location */
|
|
|
|
high= 0;
|
|
|
|
for (i= 0; i<NR_MEMS; i++)
|
|
|
|
{
|
|
|
|
if (mem_chunks[i].size == 0)
|
|
|
|
continue;
|
|
|
|
if (mem_chunks[i].base + mem_chunks[i].size > high)
|
|
|
|
high= mem_chunks[i].base + mem_chunks[i].size;
|
|
|
|
}
|
|
|
|
|
|
|
|
high <<= CLICK_SHIFT;
|
2005-10-21 21:37:31 +02:00
|
|
|
#if VERBOSE_VM
|
2005-09-30 14:56:00 +02:00
|
|
|
printf("do_x86_vm: found high 0x%x\n", high);
|
2005-10-21 21:37:31 +02:00
|
|
|
#endif
|
2005-09-30 14:56:00 +02:00
|
|
|
|
|
|
|
/* The number of pages we need is one for the page directory, enough
|
|
|
|
* page tables to cover the memory, and one page for alignement.
|
|
|
|
*/
|
|
|
|
pages= 1 + (high + PAGE_TABLE_COVER-1)/PAGE_TABLE_COVER + 1;
|
|
|
|
bytes= pages*PAGE_SIZE;
|
|
|
|
clicks= (bytes + CLICK_SIZE-1) >> CLICK_SHIFT;
|
|
|
|
|
2005-10-21 21:37:31 +02:00
|
|
|
#if VERBOSE_VM
|
2005-09-30 14:56:00 +02:00
|
|
|
printf("do_x86_vm: need %d pages\n", pages);
|
|
|
|
printf("do_x86_vm: need %d bytes\n", bytes);
|
|
|
|
printf("do_x86_vm: need %d clicks\n", clicks);
|
2005-10-21 21:37:31 +02:00
|
|
|
#endif
|
2005-09-30 14:56:00 +02:00
|
|
|
|
|
|
|
for (i= 0; i<NR_MEMS; i++)
|
|
|
|
{
|
|
|
|
if (mem_chunks[i].size <= clicks)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= NR_MEMS)
|
|
|
|
panic("PM", "not enough memory for VM page tables?", NO_NUM);
|
|
|
|
base_click= mem_chunks[i].base;
|
|
|
|
mem_chunks[i].base += clicks;
|
|
|
|
mem_chunks[i].size -= clicks;
|
|
|
|
|
2005-10-21 21:37:31 +02:00
|
|
|
#if VERBOSE_VM
|
2005-09-30 14:56:00 +02:00
|
|
|
printf("do_x86_vm: using 0x%x clicks @ 0x%x\n", clicks, base_click);
|
2005-10-21 21:37:31 +02:00
|
|
|
#endif
|
2005-09-30 14:56:00 +02:00
|
|
|
r= sys_vm_setbuf(base_click << CLICK_SHIFT, clicks << CLICK_SHIFT,
|
|
|
|
high);
|
|
|
|
if (r != 0)
|
|
|
|
printf("do_x86_vm: sys_vm_setbuf failed: %d\n", r);
|
|
|
|
}
|