2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains the main program of MINIX as well as its shutdown code.
|
|
|
|
* The routine main() initializes the system and starts the ball rolling by
|
|
|
|
* setting up the process table, interrupt vectors, and scheduling each task
|
|
|
|
* to run to initialize itself.
|
2005-06-24 18:24:40 +02:00
|
|
|
* The routine shutdown() does the opposite and brings down MINIX.
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* The entries into this file are:
|
|
|
|
* main: MINIX main program
|
|
|
|
* prepare_shutdown: prepare to take MINIX down
|
|
|
|
*/
|
|
|
|
#include "kernel.h"
|
|
|
|
#include <signal.h>
|
2005-07-20 17:25:38 +02:00
|
|
|
#include <string.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <a.out.h>
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
#include <minix/endpoint.h>
|
2009-12-02 12:52:26 +01:00
|
|
|
#include <minix/u64.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "proc.h"
|
Primary goal for these changes is:
- no longer have kernel have its own page table that is loaded
on every kernel entry (trap, interrupt, exception). the primary
purpose is to reduce the number of required reloads.
Result:
- kernel can only access memory of process that was running when
kernel was entered
- kernel must be mapped into every process page table, so traps to
kernel keep working
Problem:
- kernel must often access memory of arbitrary processes (e.g. send
arbitrary processes messages); this can't happen directly any more;
usually because that process' page table isn't loaded at all, sometimes
because that memory isn't mapped in at all, sometimes because it isn't
mapped in read-write.
So:
- kernel must be able to map in memory of any process, in its own
address space.
Implementation:
- VM and kernel share a range of memory in which addresses of
all page tables of all processes are available. This has two purposes:
. Kernel has to know what data to copy in order to map in a range
. Kernel has to know where to write the data in order to map it in
That last point is because kernel has to write in the currently loaded
page table.
- Processes and kernel are separated through segments; kernel segments
haven't changed.
- The kernel keeps the process whose page table is currently loaded
in 'ptproc.'
- If it wants to map in a range of memory, it writes the value of the
page directory entry for that range into the page directory entry
in the currently loaded map. There is a slot reserved for such
purposes. The kernel can then access this memory directly.
- In order to do this, its segment has been increased (and the
segments of processes start where it ends).
- In the pagefault handler, detect if the kernel is doing
'trappable' memory access (i.e. a pagefault isn't a fatal
error) and if so,
- set the saved instruction pointer to phys_copy_fault,
breaking out of phys_copy
- set the saved eax register to the address of the page
fault, both for sanity checking and for checking in
which of the two ranges that phys_copy was called
with the fault occured
- Some boot-time processes do not have their own page table,
and are mapped in with the kernel, and separated with
segments. The kernel detects this using HASPT. If such a
process has to be scheduled, any page table will work and
no page table switch is done.
Major changes in kernel are
- When accessing user processes memory, kernel no longer
explicitly checks before it does so if that memory is OK.
It simply makes the mapping (if necessary), tries to do the
operation, and traps the pagefault if that memory isn't present;
if that happens, the copy function returns EFAULT.
So all of the CHECKRANGE_OR_SUSPEND macros are gone.
- Kernel no longer has to copy/read and parse page tables.
- A message copying optimisation: when messages are copied, and
the recipient isn't mapped in, they are copied into a buffer
in the kernel. This is done in QueueMess. The next time
the recipient is scheduled, this message is copied into
its memory. This happens in schedcheck().
This eliminates the mapping/copying step for messages, and makes
it easier to deliver messages. This eliminates soft_notify.
- Kernel no longer creates a page table at all, so the vm_setbuf
and pagetable writing in memory.c is gone.
Minor changes in kernel are
- ipc_stats thrown out, wasn't used
- misc flags all renamed to MF_*
- NOREC_* macros to enter and leave functions that should not
be called recursively; just sanity checks really
- code to fully decode segment selectors and descriptors
to print on exceptions
- lots of vmassert()s added, only executed if DEBUG_VMASSERT is 1
2009-09-21 16:31:52 +02:00
|
|
|
#include "debug.h"
|
2009-11-06 10:04:15 +01:00
|
|
|
#include "clock.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-05-02 16:30:04 +02:00
|
|
|
/* Prototype declarations for PRIVATE functions. */
|
|
|
|
FORWARD _PROTOTYPE( void announce, (void));
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2005-09-11 18:44:06 +02:00
|
|
|
* main *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void main()
|
|
|
|
{
|
|
|
|
/* Start the ball rolling. */
|
2005-07-29 17:26:23 +02:00
|
|
|
struct boot_image *ip; /* boot image pointer */
|
2005-07-20 17:25:38 +02:00
|
|
|
register struct proc *rp; /* process pointer */
|
|
|
|
register struct priv *sp; /* privilege structure pointer */
|
2007-04-23 15:46:54 +02:00
|
|
|
register int i, j, s;
|
2005-04-21 16:53:53 +02:00
|
|
|
int hdrindex; /* index to array of a.out headers */
|
2005-06-20 13:26:48 +02:00
|
|
|
phys_clicks text_base;
|
2006-05-11 16:49:46 +02:00
|
|
|
vir_clicks text_clicks, data_clicks, st_clicks;
|
2005-04-21 16:53:53 +02:00
|
|
|
reg_t ktsb; /* kernel task stack base */
|
|
|
|
struct exec e_hdr; /* for a copy of an a.out header */
|
|
|
|
|
2009-10-03 13:30:35 +02:00
|
|
|
/* Global value to test segment sanity. */
|
|
|
|
magictest = MAGICTEST;
|
2009-08-30 16:55:30 +02:00
|
|
|
|
2005-06-24 18:24:40 +02:00
|
|
|
/* Clear the process table. Anounce each slot as empty and set up mappings
|
2005-07-14 17:12:12 +02:00
|
|
|
* for proc_addr() and proc_nr() macros. Do the same for the table with
|
2005-07-26 14:48:34 +02:00
|
|
|
* privilege structures for the system processes.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
for (rp = BEG_PROC_ADDR, i = -NR_TASKS; rp < END_PROC_ADDR; ++rp, ++i) {
|
2009-11-10 10:11:13 +01:00
|
|
|
rp->p_rts_flags = RTS_SLOT_FREE; /* initialize free slot */
|
2009-05-12 13:35:01 +02:00
|
|
|
#if DEBUG_SCHED_CHECK
|
|
|
|
rp->p_magic = PMAGIC;
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
rp->p_nr = i; /* proc number from ptr */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
rp->p_endpoint = _ENDPOINT(0, rp->p_nr); /* generation no. 0 */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-07-14 17:12:12 +02:00
|
|
|
for (sp = BEG_PRIV_ADDR, i = 0; sp < END_PRIV_ADDR; ++sp, ++i) {
|
|
|
|
sp->s_proc_nr = NONE; /* initialize as free */
|
|
|
|
sp->s_id = i; /* priv structure index */
|
|
|
|
ppriv_addr[i] = sp; /* priv ptr from number */
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-10-02 21:02:05 +02:00
|
|
|
/* Set up proc table entries for processes in boot image. The stacks of the
|
2005-04-21 16:53:53 +02:00
|
|
|
* kernel tasks are initialized to an array in data space. The stacks
|
|
|
|
* of the servers have been added to the data segment by the monitor, so
|
|
|
|
* the stack pointer is set to the end of the data segment. All the
|
|
|
|
* processes are in low memory on the 8086. On the 386 only the kernel
|
|
|
|
* is in low memory, the rest is loaded in extended memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Task stacks. */
|
|
|
|
ktsb = (reg_t) t_stack;
|
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
for (i=0; i < NR_BOOT_PROCS; ++i) {
|
2006-06-20 11:56:06 +02:00
|
|
|
int ci;
|
|
|
|
bitchunk_t fv;
|
2009-05-12 13:35:01 +02:00
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
ip = &image[i]; /* process' attributes */
|
|
|
|
rp = proc_addr(ip->proc_nr); /* get process pointer */
|
'proc number' is process slot, 'endpoint' are generation-aware process
instance numbers, encoded and decoded using macros in <minix/endpoint.h>.
proc number -> endpoint migration
. proc_nr in the interrupt hook is now an endpoint, proc_nr_e.
. m_source for messages and notifies is now an endpoint, instead of
proc number.
. isokendpt() converts an endpoint to a process number, returns
success (but fails if the process number is out of range, the
process slot is not a living process, or the given endpoint
number does not match the endpoint number in the process slot,
indicating an old process).
. okendpt() is the same as isokendpt(), but panic()s if the conversion
fails. This is mainly used for decoding message.m_source endpoints,
and other endpoint numbers in kernel data structures, which should
always be correct.
. if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt()
get passed the __FILE__ and __LINE__ of the calling lines, and
print messages about what is wrong with the endpoint number
(out of range proc, empty proc, or inconsistent endpoint number),
with the caller, making finding where the conversion failed easy
without having to include code for every call to print where things
went wrong. Sometimes this is harmless (wrong arg to a kernel call),
sometimes it's a fatal internal inconsistency (bogus m_source).
. some process table fields have been appended an _e to indicate it's
become and endpoint.
. process endpoint is stored in p_endpoint, without generation number.
it turns out the kernel never needs the generation number, except
when fork()ing, so it's decoded then.
. kernel calls all take endpoints as arguments, not proc numbers.
the one exception is sys_fork(), which needs to know in which slot
to put the child.
2006-03-03 11:00:02 +01:00
|
|
|
ip->endpoint = rp->p_endpoint; /* ipc endpoint */
|
2005-06-30 17:55:19 +02:00
|
|
|
rp->p_max_priority = ip->priority; /* max scheduling priority */
|
|
|
|
rp->p_priority = ip->priority; /* current priority */
|
|
|
|
rp->p_quantum_size = ip->quantum; /* quantum size in ticks */
|
2005-08-22 17:14:11 +02:00
|
|
|
rp->p_ticks_left = ip->quantum; /* current credit */
|
2005-07-21 20:36:40 +02:00
|
|
|
strncpy(rp->p_name, ip->proc_name, P_NAME_LEN); /* set process name */
|
2005-07-26 14:48:34 +02:00
|
|
|
(void) get_priv(rp, (ip->flags & SYS_PROC)); /* assign structure */
|
|
|
|
priv(rp)->s_flags = ip->flags; /* process flags */
|
2005-08-04 21:23:03 +02:00
|
|
|
priv(rp)->s_trap_mask = ip->trap_mask; /* allowed traps */
|
2006-06-20 11:56:06 +02:00
|
|
|
|
2009-07-02 18:25:31 +02:00
|
|
|
/* Warn about violations of the boot image table order consistency. */
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
if (priv_id(rp) != s_nr_to_id(ip->proc_nr) && (ip->flags & SYS_PROC))
|
2009-07-02 18:25:31 +02:00
|
|
|
kprintf("Warning: boot image table has wrong process order\n");
|
|
|
|
|
2006-06-20 11:56:06 +02:00
|
|
|
/* Initialize call mask bitmap from unordered set.
|
|
|
|
* A single SYS_ALL_CALLS is a special case - it
|
|
|
|
* means all calls are allowed.
|
|
|
|
*/
|
|
|
|
if(ip->nr_k_calls == 1 && ip->k_calls[0] == SYS_ALL_CALLS)
|
|
|
|
fv = ~0; /* fill call mask */
|
|
|
|
else
|
|
|
|
fv = 0; /* clear call mask */
|
|
|
|
|
|
|
|
for(ci = 0; ci < CALL_MASK_SIZE; ci++) /* fill or clear call mask */
|
|
|
|
priv(rp)->s_k_call_mask[ci] = fv;
|
|
|
|
if(!fv) /* not all full? enter calls bit by bit */
|
|
|
|
for(ci = 0; ci < ip->nr_k_calls; ci++)
|
|
|
|
SET_BIT(priv(rp)->s_k_call_mask,
|
|
|
|
ip->k_calls[ci]-KERNEL_CALL);
|
|
|
|
|
2009-07-02 18:25:31 +02:00
|
|
|
for (j = 0; j < NR_SYS_PROCS && j < BITCHUNK_BITS; j++)
|
|
|
|
if (ip->ipc_to & (1 << j))
|
|
|
|
set_sendto_bit(rp, j); /* restrict targets */
|
2007-04-23 15:46:54 +02:00
|
|
|
|
2005-07-26 14:48:34 +02:00
|
|
|
if (iskerneln(proc_nr(rp))) { /* part of the kernel? */
|
2005-06-30 17:55:19 +02:00
|
|
|
if (ip->stksize > 0) { /* HARDWARE stack size is 0 */
|
2005-07-14 17:12:12 +02:00
|
|
|
rp->p_priv->s_stack_guard = (reg_t *) ktsb;
|
|
|
|
*rp->p_priv->s_stack_guard = STACK_GUARD;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2005-06-30 17:55:19 +02:00
|
|
|
ktsb += ip->stksize; /* point to high end of stack */
|
2005-04-21 16:53:53 +02:00
|
|
|
rp->p_reg.sp = ktsb; /* this task's initial stack ptr */
|
|
|
|
hdrindex = 0; /* all use the first a.out header */
|
|
|
|
} else {
|
2005-07-26 14:48:34 +02:00
|
|
|
hdrindex = 1 + i-NR_TASKS; /* servers, drivers, INIT */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Architecture-specific way to find out aout header of this
|
|
|
|
* boot process.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2008-11-19 13:26:10 +01:00
|
|
|
arch_get_aout_headers(hdrindex, &e_hdr);
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Convert addresses to clicks and build process memory map */
|
|
|
|
text_base = e_hdr.a_syms >> CLICK_SHIFT;
|
|
|
|
text_clicks = (e_hdr.a_text + CLICK_SIZE-1) >> CLICK_SHIFT;
|
2006-05-11 16:49:46 +02:00
|
|
|
data_clicks = (e_hdr.a_data+e_hdr.a_bss + CLICK_SIZE-1) >> CLICK_SHIFT;
|
|
|
|
st_clicks= (e_hdr.a_total + CLICK_SIZE-1) >> CLICK_SHIFT;
|
|
|
|
if (!(e_hdr.a_flags & A_SEP))
|
|
|
|
{
|
|
|
|
data_clicks= (e_hdr.a_text+e_hdr.a_data+e_hdr.a_bss +
|
|
|
|
CLICK_SIZE-1) >> CLICK_SHIFT;
|
|
|
|
text_clicks = 0; /* common I&D */
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
rp->p_memmap[T].mem_phys = text_base;
|
|
|
|
rp->p_memmap[T].mem_len = text_clicks;
|
|
|
|
rp->p_memmap[D].mem_phys = text_base + text_clicks;
|
|
|
|
rp->p_memmap[D].mem_len = data_clicks;
|
2006-05-11 16:49:46 +02:00
|
|
|
rp->p_memmap[S].mem_phys = text_base + text_clicks + st_clicks;
|
|
|
|
rp->p_memmap[S].mem_vir = st_clicks;
|
|
|
|
rp->p_memmap[S].mem_len = 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Set initial register values. The processor status word for tasks
|
|
|
|
* is different from that of other processes because tasks can
|
|
|
|
* access I/O; this is not allowed to less-privileged processes
|
|
|
|
*/
|
2005-06-30 17:55:19 +02:00
|
|
|
rp->p_reg.pc = (reg_t) ip->initial_pc;
|
2005-06-24 18:24:40 +02:00
|
|
|
rp->p_reg.psw = (iskernelp(rp)) ? INIT_TASK_PSW : INIT_PSW;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Initialize the server stack pointer. Take it down one word
|
|
|
|
* to give crtso.s something to use as "argc".
|
|
|
|
*/
|
2005-07-26 14:48:34 +02:00
|
|
|
if (isusern(proc_nr(rp))) { /* user-space process? */
|
2005-04-21 16:53:53 +02:00
|
|
|
rp->p_reg.sp = (rp->p_memmap[S].mem_vir +
|
|
|
|
rp->p_memmap[S].mem_len) << CLICK_SHIFT;
|
|
|
|
rp->p_reg.sp -= sizeof(reg_t);
|
|
|
|
}
|
2008-12-11 15:15:23 +01:00
|
|
|
|
Primary goal for these changes is:
- no longer have kernel have its own page table that is loaded
on every kernel entry (trap, interrupt, exception). the primary
purpose is to reduce the number of required reloads.
Result:
- kernel can only access memory of process that was running when
kernel was entered
- kernel must be mapped into every process page table, so traps to
kernel keep working
Problem:
- kernel must often access memory of arbitrary processes (e.g. send
arbitrary processes messages); this can't happen directly any more;
usually because that process' page table isn't loaded at all, sometimes
because that memory isn't mapped in at all, sometimes because it isn't
mapped in read-write.
So:
- kernel must be able to map in memory of any process, in its own
address space.
Implementation:
- VM and kernel share a range of memory in which addresses of
all page tables of all processes are available. This has two purposes:
. Kernel has to know what data to copy in order to map in a range
. Kernel has to know where to write the data in order to map it in
That last point is because kernel has to write in the currently loaded
page table.
- Processes and kernel are separated through segments; kernel segments
haven't changed.
- The kernel keeps the process whose page table is currently loaded
in 'ptproc.'
- If it wants to map in a range of memory, it writes the value of the
page directory entry for that range into the page directory entry
in the currently loaded map. There is a slot reserved for such
purposes. The kernel can then access this memory directly.
- In order to do this, its segment has been increased (and the
segments of processes start where it ends).
- In the pagefault handler, detect if the kernel is doing
'trappable' memory access (i.e. a pagefault isn't a fatal
error) and if so,
- set the saved instruction pointer to phys_copy_fault,
breaking out of phys_copy
- set the saved eax register to the address of the page
fault, both for sanity checking and for checking in
which of the two ranges that phys_copy was called
with the fault occured
- Some boot-time processes do not have their own page table,
and are mapped in with the kernel, and separated with
segments. The kernel detects this using HASPT. If such a
process has to be scheduled, any page table will work and
no page table switch is done.
Major changes in kernel are
- When accessing user processes memory, kernel no longer
explicitly checks before it does so if that memory is OK.
It simply makes the mapping (if necessary), tries to do the
operation, and traps the pagefault if that memory isn't present;
if that happens, the copy function returns EFAULT.
So all of the CHECKRANGE_OR_SUSPEND macros are gone.
- Kernel no longer has to copy/read and parse page tables.
- A message copying optimisation: when messages are copied, and
the recipient isn't mapped in, they are copied into a buffer
in the kernel. This is done in QueueMess. The next time
the recipient is scheduled, this message is copied into
its memory. This happens in schedcheck().
This eliminates the mapping/copying step for messages, and makes
it easier to deliver messages. This eliminates soft_notify.
- Kernel no longer creates a page table at all, so the vm_setbuf
and pagetable writing in memory.c is gone.
Minor changes in kernel are
- ipc_stats thrown out, wasn't used
- misc flags all renamed to MF_*
- NOREC_* macros to enter and leave functions that should not
be called recursively; just sanity checks really
- code to fully decode segment selectors and descriptors
to print on exceptions
- lots of vmassert()s added, only executed if DEBUG_VMASSERT is 1
2009-09-21 16:31:52 +02:00
|
|
|
/* scheduling functions depend on proc_ptr pointing somewhere. */
|
|
|
|
if(!proc_ptr) proc_ptr = rp;
|
|
|
|
|
2008-12-11 15:15:23 +01:00
|
|
|
/* If this process has its own page table, VM will set the
|
|
|
|
* PT up and manage it. VM will signal the kernel when it has
|
|
|
|
* done this; until then, don't let it run.
|
|
|
|
*/
|
|
|
|
if(priv(rp)->s_flags & PROC_FULLVM)
|
2009-11-10 10:11:13 +01:00
|
|
|
RTS_SET(rp, RTS_VMINHIBIT);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Set ready. The HARDWARE task is never ready. */
|
2009-11-10 10:11:13 +01:00
|
|
|
if (rp->p_nr == HARDWARE) RTS_SET(rp, RTS_PROC_STOP);
|
2009-11-12 09:42:18 +01:00
|
|
|
/* IDLE task is never put on a run queue as it is never ready to run */
|
|
|
|
if (rp->p_nr == IDLE) RTS_SET(rp, RTS_PROC_STOP);
|
2009-11-10 10:11:13 +01:00
|
|
|
RTS_UNSET(rp, RTS_SLOT_FREE); /* remove RTS_SLOT_FREE and schedule */
|
2005-04-21 16:53:53 +02:00
|
|
|
alloc_segments(rp);
|
|
|
|
}
|
|
|
|
|
2009-11-16 22:41:44 +01:00
|
|
|
/* Architecture-dependent initialization. */
|
|
|
|
arch_init();
|
|
|
|
|
2006-10-30 16:53:38 +01:00
|
|
|
#if SPROFILE
|
|
|
|
sprofiling = 0; /* we're not profiling until instructed to */
|
|
|
|
#endif /* SPROFILE */
|
|
|
|
cprof_procs_no = 0; /* init nr of hash table slots used */
|
|
|
|
|
2009-12-02 12:52:26 +01:00
|
|
|
#ifdef CONFIG_IDLE_TSC
|
|
|
|
idle_tsc = cvu64(0);
|
|
|
|
#endif
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
vm_running = 0;
|
2009-04-02 17:24:44 +02:00
|
|
|
krandom.random_sources = RANDOM_SOURCES;
|
|
|
|
krandom.random_elements = RANDOM_ELEMENTS;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2005-06-17 11:09:54 +02:00
|
|
|
/* MINIX is now ready. All boot image processes are on the ready queue.
|
|
|
|
* Return to the assembly code to start running the current process.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
Primary goal for these changes is:
- no longer have kernel have its own page table that is loaded
on every kernel entry (trap, interrupt, exception). the primary
purpose is to reduce the number of required reloads.
Result:
- kernel can only access memory of process that was running when
kernel was entered
- kernel must be mapped into every process page table, so traps to
kernel keep working
Problem:
- kernel must often access memory of arbitrary processes (e.g. send
arbitrary processes messages); this can't happen directly any more;
usually because that process' page table isn't loaded at all, sometimes
because that memory isn't mapped in at all, sometimes because it isn't
mapped in read-write.
So:
- kernel must be able to map in memory of any process, in its own
address space.
Implementation:
- VM and kernel share a range of memory in which addresses of
all page tables of all processes are available. This has two purposes:
. Kernel has to know what data to copy in order to map in a range
. Kernel has to know where to write the data in order to map it in
That last point is because kernel has to write in the currently loaded
page table.
- Processes and kernel are separated through segments; kernel segments
haven't changed.
- The kernel keeps the process whose page table is currently loaded
in 'ptproc.'
- If it wants to map in a range of memory, it writes the value of the
page directory entry for that range into the page directory entry
in the currently loaded map. There is a slot reserved for such
purposes. The kernel can then access this memory directly.
- In order to do this, its segment has been increased (and the
segments of processes start where it ends).
- In the pagefault handler, detect if the kernel is doing
'trappable' memory access (i.e. a pagefault isn't a fatal
error) and if so,
- set the saved instruction pointer to phys_copy_fault,
breaking out of phys_copy
- set the saved eax register to the address of the page
fault, both for sanity checking and for checking in
which of the two ranges that phys_copy was called
with the fault occured
- Some boot-time processes do not have their own page table,
and are mapped in with the kernel, and separated with
segments. The kernel detects this using HASPT. If such a
process has to be scheduled, any page table will work and
no page table switch is done.
Major changes in kernel are
- When accessing user processes memory, kernel no longer
explicitly checks before it does so if that memory is OK.
It simply makes the mapping (if necessary), tries to do the
operation, and traps the pagefault if that memory isn't present;
if that happens, the copy function returns EFAULT.
So all of the CHECKRANGE_OR_SUSPEND macros are gone.
- Kernel no longer has to copy/read and parse page tables.
- A message copying optimisation: when messages are copied, and
the recipient isn't mapped in, they are copied into a buffer
in the kernel. This is done in QueueMess. The next time
the recipient is scheduled, this message is copied into
its memory. This happens in schedcheck().
This eliminates the mapping/copying step for messages, and makes
it easier to deliver messages. This eliminates soft_notify.
- Kernel no longer creates a page table at all, so the vm_setbuf
and pagetable writing in memory.c is gone.
Minor changes in kernel are
- ipc_stats thrown out, wasn't used
- misc flags all renamed to MF_*
- NOREC_* macros to enter and leave functions that should not
be called recursively; just sanity checks really
- code to fully decode segment selectors and descriptors
to print on exceptions
- lots of vmassert()s added, only executed if DEBUG_VMASSERT is 1
2009-09-21 16:31:52 +02:00
|
|
|
bill_ptr = proc_addr(IDLE); /* it has to point somewhere */
|
2005-06-17 11:09:54 +02:00
|
|
|
announce(); /* print MINIX startup banner */
|
2009-11-06 10:04:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* enable timer interrupts and clock task on the boot CPU
|
|
|
|
*/
|
|
|
|
if (boot_cpu_init_timer(system_hz)) {
|
|
|
|
minix_panic("FATAL : failed to initialize timer interrupts, "
|
|
|
|
"cannot continue without any clock source!",
|
|
|
|
NO_NUM);
|
|
|
|
}
|
|
|
|
|
Primary goal for these changes is:
- no longer have kernel have its own page table that is loaded
on every kernel entry (trap, interrupt, exception). the primary
purpose is to reduce the number of required reloads.
Result:
- kernel can only access memory of process that was running when
kernel was entered
- kernel must be mapped into every process page table, so traps to
kernel keep working
Problem:
- kernel must often access memory of arbitrary processes (e.g. send
arbitrary processes messages); this can't happen directly any more;
usually because that process' page table isn't loaded at all, sometimes
because that memory isn't mapped in at all, sometimes because it isn't
mapped in read-write.
So:
- kernel must be able to map in memory of any process, in its own
address space.
Implementation:
- VM and kernel share a range of memory in which addresses of
all page tables of all processes are available. This has two purposes:
. Kernel has to know what data to copy in order to map in a range
. Kernel has to know where to write the data in order to map it in
That last point is because kernel has to write in the currently loaded
page table.
- Processes and kernel are separated through segments; kernel segments
haven't changed.
- The kernel keeps the process whose page table is currently loaded
in 'ptproc.'
- If it wants to map in a range of memory, it writes the value of the
page directory entry for that range into the page directory entry
in the currently loaded map. There is a slot reserved for such
purposes. The kernel can then access this memory directly.
- In order to do this, its segment has been increased (and the
segments of processes start where it ends).
- In the pagefault handler, detect if the kernel is doing
'trappable' memory access (i.e. a pagefault isn't a fatal
error) and if so,
- set the saved instruction pointer to phys_copy_fault,
breaking out of phys_copy
- set the saved eax register to the address of the page
fault, both for sanity checking and for checking in
which of the two ranges that phys_copy was called
with the fault occured
- Some boot-time processes do not have their own page table,
and are mapped in with the kernel, and separated with
segments. The kernel detects this using HASPT. If such a
process has to be scheduled, any page table will work and
no page table switch is done.
Major changes in kernel are
- When accessing user processes memory, kernel no longer
explicitly checks before it does so if that memory is OK.
It simply makes the mapping (if necessary), tries to do the
operation, and traps the pagefault if that memory isn't present;
if that happens, the copy function returns EFAULT.
So all of the CHECKRANGE_OR_SUSPEND macros are gone.
- Kernel no longer has to copy/read and parse page tables.
- A message copying optimisation: when messages are copied, and
the recipient isn't mapped in, they are copied into a buffer
in the kernel. This is done in QueueMess. The next time
the recipient is scheduled, this message is copied into
its memory. This happens in schedcheck().
This eliminates the mapping/copying step for messages, and makes
it easier to deliver messages. This eliminates soft_notify.
- Kernel no longer creates a page table at all, so the vm_setbuf
and pagetable writing in memory.c is gone.
Minor changes in kernel are
- ipc_stats thrown out, wasn't used
- misc flags all renamed to MF_*
- NOREC_* macros to enter and leave functions that should not
be called recursively; just sanity checks really
- code to fully decode segment selectors and descriptors
to print on exceptions
- lots of vmassert()s added, only executed if DEBUG_VMASSERT is 1
2009-09-21 16:31:52 +02:00
|
|
|
/* Warnings for sanity checks that take time. These warnings are printed
|
|
|
|
* so it's a clear warning no full release should be done with them
|
|
|
|
* enabled.
|
|
|
|
*/
|
|
|
|
#if DEBUG_SCHED_CHECK
|
|
|
|
FIXME("DEBUG_SCHED_CHECK enabled");
|
|
|
|
#endif
|
|
|
|
#if DEBUG_VMASSERT
|
|
|
|
FIXME("DEBUG_VMASSERT enabled");
|
|
|
|
#endif
|
|
|
|
#if DEBUG_PROC_CHECK
|
|
|
|
FIXME("PROC check enabled");
|
|
|
|
#endif
|
2009-11-06 10:04:15 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
restart();
|
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* announce *
|
|
|
|
*===========================================================================*/
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE void announce(void)
|
|
|
|
{
|
|
|
|
/* Display the MINIX startup banner. */
|
2005-10-06 12:21:24 +02:00
|
|
|
kprintf("\nMINIX %s.%s. "
|
2007-03-30 17:17:32 +02:00
|
|
|
#ifdef _SVN_REVISION
|
|
|
|
"(" _SVN_REVISION ")\n"
|
2007-03-21 14:35:06 +01:00
|
|
|
#endif
|
2009-05-14 17:54:02 +02:00
|
|
|
"Copyright 2009, Vrije Universiteit, Amsterdam, The Netherlands\n",
|
2005-07-20 17:25:38 +02:00
|
|
|
OS_RELEASE, OS_VERSION);
|
2009-05-14 17:54:02 +02:00
|
|
|
kprintf("MINIX is open source software, see http://www.minix3.org\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* prepare_shutdown *
|
|
|
|
*===========================================================================*/
|
2005-07-27 16:32:16 +02:00
|
|
|
PUBLIC void prepare_shutdown(how)
|
|
|
|
int how;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-07-27 16:32:16 +02:00
|
|
|
/* This function prepares to shutdown MINIX. */
|
2005-07-21 20:36:40 +02:00
|
|
|
static timer_t shutdown_timer;
|
2005-07-29 17:26:23 +02:00
|
|
|
register struct proc *rp;
|
2005-05-24 12:06:17 +02:00
|
|
|
message m;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-10-05 11:51:50 +02:00
|
|
|
/* Continue after 1 second, to give processes a chance to get scheduled to
|
|
|
|
* do shutdown work. Set a watchog timer to call shutdown(). The timer
|
2005-07-20 17:25:38 +02:00
|
|
|
* argument passes the shutdown status.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2005-07-21 20:36:40 +02:00
|
|
|
kprintf("MINIX will now be shut down ...\n");
|
|
|
|
tmr_arg(&shutdown_timer)->ta_int = how;
|
2008-12-11 15:15:23 +01:00
|
|
|
set_timer(&shutdown_timer, get_uptime() + system_hz, minix_shutdown);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* shutdown *
|
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void minix_shutdown(tp)
|
2005-05-27 14:44:14 +02:00
|
|
|
timer_t *tp;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* This function is called from prepare_shutdown or stop_sequence to bring
|
2005-06-24 18:24:40 +02:00
|
|
|
* down MINIX. How to shutdown is in the argument: RBT_HALT (return to the
|
|
|
|
* monitor), RBT_MONITOR (execute given code), RBT_RESET (hard reset).
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2009-11-06 10:04:15 +01:00
|
|
|
arch_stop_local_timer();
|
2009-11-16 22:41:44 +01:00
|
|
|
intr_init(INTS_ORIG, 0);
|
2008-11-19 13:26:10 +01:00
|
|
|
arch_shutdown(tp ? tmr_arg(tp)->ta_int : RBT_PANIC);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|