Miscellaneous clean ups and fixes to the kernel.

Support for FLOPPY in boot image. (Set controller=fd at boot monitor.)
Moved major device numbers to <minix/dmap.h> (maybe rename to dev.h?)
This commit is contained in:
Jorrit Herder
2005-08-04 09:26:36 +00:00
parent 5e3b213f05
commit e561081545
29 changed files with 163 additions and 178 deletions

View File

@@ -297,8 +297,5 @@ PUBLIC unsigned long read_clock()
#endif /* (CHIP == INTEL) */
#if (CHIP == M68000)
/* Initialize the timer C in the MFP 68901: implement init_clock() here. */
#endif /* (CHIP == M68000) */

View File

@@ -5,7 +5,8 @@
* kernel buffers and to enable or disable debugging code, timing features,
* and individual kernel calls.
*
* Created: Jul 11, 2005 Jorrit N. Herder
* Changes:
* Jul 11, 2005 Created. (Jorrit N. Herder)
*/
/* In embedded and sensor applications, not all the kernel calls may be

View File

@@ -1,6 +1,9 @@
#ifndef IPC_H
#define IPC_H
/* This header file defines constants for MINIX inter-process communication.
* These definitions are used in the file proc.c.
*/
#include <minix/com.h>
/* Masks and flags for system calls. */

View File

@@ -8,7 +8,8 @@
* user processes share one structure. This setup provides a clear separation
* between common and privileged process fields and is very space efficient.
*
* Created: Jul 1, 2005 Jorrit N. Herder
* Changes:
* Jul 01, 2005 Created. (Jorrit N. Herder)
*/
#include <minix/com.h>
#include "protect.h"

View File

@@ -13,12 +13,12 @@
* lock_sched: a process has run too long; schedule another one
*
* Changes:
* Jul 25, 2005 better protection in sys_call() (Jorrit N. Herder)
* May 26, 2005 optimized message passing functions (Jorrit N. Herder)
* Jul 25, 2005 protection and checks in sys_call() (Jorrit N. Herder)
* May 26, 2005 rewrite of message passing functions (Jorrit N. Herder)
* May 24, 2005 new, queued NOTIFY system call (Jorrit N. Herder)
* Oct 28, 2004 new, non-blocking SEND and RECEIVE (Jorrit N. Herder)
* Oct 28, 2004 rewrite of sys_call() function (Jorrit N. Herder)
* Aug 19, 2004 generalized multilevel scheduling (Jorrit N. Herder)
* Aug 19, 2004 rewrite of multilevel scheduling (Jorrit N. Herder)
*
* The code here is critical to make everything work and is important for the
* overall performance of the system. A large fraction of the code deals with

View File

@@ -36,15 +36,15 @@ _PROTOTYPE( void cstart, (U16_t cs, U16_t ds, U16_t mds,
U16_t parmoff, U16_t parmsize) );
/* system.c */
_PROTOTYPE( int get_priv, (register struct proc *rc, int proc_type) );
_PROTOTYPE( void send_sig, (int proc_nr, int sig_nr) );
_PROTOTYPE( void cause_sig, (int proc_nr, int sig_nr) );
_PROTOTYPE( int get_priv, (register struct proc *rc, int proc_type) );
_PROTOTYPE( phys_bytes numap_local, (int proc_nr, vir_bytes vir_addr,
vir_bytes bytes) );
_PROTOTYPE( void sys_task, (void) );
_PROTOTYPE( void get_randomness, (int source) );
_PROTOTYPE( int virtual_copy, (struct vir_addr *src, struct vir_addr *dst,
vir_bytes bytes) );
#define numap_local(proc_nr, vir_addr, bytes) \
umap_local(proc_addr(proc_nr), D, (vir_addr), (bytes))
_PROTOTYPE( phys_bytes umap_local, (struct proc *rp, int seg,
vir_bytes vir_addr, vir_bytes bytes) );
_PROTOTYPE( phys_bytes umap_remote, (struct proc *rp, int seg,

View File

@@ -17,14 +17,15 @@
* umap_local: map virtual address in LOCAL_SEG to physical
* umap_remote: map virtual address in REMOTE_SEG to physical
* umap_bios: map virtual address in BIOS_SEG to physical
* numap_local: umap_local D segment from proc nr instead of pointer
* virtual_copy: copy bytes from one virtual address to another
* get_randomness: accumulate randomness in a buffer
*
* Changes:
* 2004 to 2005 many new system calls (see system.h) (Jorrit N. Herder)
* Jul 20, 2005 send signal to services with message (Jorrit N. Herder)
* Jan 15, 2005 new, generalized virtual copy function (Jorrit N. Herder)
* Oct 10, 2004 dispatch system calls from call vector (Jorrit N. Herder)
* Sep 30, 2004 source code documentation updated (Jorrit N. Herder)
* 2004 to 2005 various new syscalls (see system.h) (Jorrit N. Herder)
*/
#include "kernel.h"
@@ -121,11 +122,12 @@ PRIVATE void initialize(void)
call_vec[i] = do_unused;
}
/* Process management. */
map(SYS_FORK, do_fork); /* a process forked a new process */
map(SYS_NEWMAP, do_newmap); /* set up a process memory map */
map(SYS_EXEC, do_exec); /* update process after execute */
map(SYS_EXIT, do_exit); /* clean up after process exit */
map(SYS_NICE, do_nice); /* set scheduling priority */
map(SYS_PRIVCTL, do_privctl); /* system privileges control */
map(SYS_TRACE, do_trace); /* request a trace operation */
/* Signal handling. */
@@ -135,22 +137,17 @@ PRIVATE void initialize(void)
map(SYS_SIGSEND, do_sigsend); /* start POSIX-style signal */
map(SYS_SIGRETURN, do_sigreturn); /* return from POSIX-style signal */
/* Clock functionality. */
map(SYS_TIMES, do_times); /* get uptime and process times */
map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */
/* Device I/O. */
map(SYS_IRQCTL, do_irqctl); /* interrupt control operations */
map(SYS_DEVIO, do_devio); /* inb, inw, inl, outb, outw, outl */
map(SYS_SDEVIO, do_sdevio); /* phys_insb, _insw, _outsb, _outsw */
map(SYS_VDEVIO, do_vdevio); /* vector with devio requests */
map(SYS_INT86, do_int86); /* BIOS call */
map(SYS_INT86, do_int86); /* real-mode BIOS calls */
/* System control. */
map(SYS_ABORT, do_abort); /* abort MINIX */
map(SYS_GETINFO, do_getinfo); /* request system information */
map(SYS_PRIVCTL, do_privctl); /* system privileges control */
/* Memory management. */
map(SYS_NEWMAP, do_newmap); /* set up a process memory map */
map(SYS_SEGCTL, do_segctl); /* add segment and get selector */
map(SYS_MEMSET, do_memset); /* write char to memory area */
/* Copying. */
map(SYS_UMAP, do_umap); /* map virtual to physical address */
@@ -158,7 +155,14 @@ PRIVATE void initialize(void)
map(SYS_PHYSCOPY, do_physcopy); /* use physical addressing */
map(SYS_VIRVCOPY, do_virvcopy); /* vector with copy requests */
map(SYS_PHYSVCOPY, do_physvcopy); /* vector with copy requests */
map(SYS_MEMSET, do_memset); /* write char to memory area */
/* Clock functionality. */
map(SYS_TIMES, do_times); /* get uptime and process times */
map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */
/* System control. */
map(SYS_ABORT, do_abort); /* abort MINIX */
map(SYS_GETINFO, do_getinfo); /* request system information */
}
@@ -184,6 +188,7 @@ int proc_type; /* system or user process flag */
} else {
rc->p_priv = &priv[USER_PRIV_ID]; /* use shared slot */
rc->p_priv->s_proc_nr = INIT_PROC_NR; /* set association */
rc->p_priv->s_flags = 0; /* no initial flags */
}
return(OK);
}
@@ -195,21 +200,18 @@ int proc_type; /* system or user process flag */
PUBLIC void get_randomness(source)
int source;
{
/* Gather random information with help of the CPU's cycle counter. Only use
* the lowest bytes because the highest bytes won't differ that much.
*/
/* On machines with the RDTSC (cycle counter read instruction - pentium
* and up), use that for high-resolution raw entropy gathering. Otherwise,
* use the realtime clock (tick resolution).
*
* Unfortunately this test is run-time - we don't want to bother with
* compiling different kernels for different machines.
*
* On machines without RDTSC, we use read_clock().
*/
int r_next;
unsigned long tsc_high, tsc_low;
/* On machines with the RDTSC (cycle counter read instruction - pentium
* and up), use that for high-resolution raw entropy gathering. Otherwise,
* use the realtime clock (tick resolution).
*
* Unfortunately this test is run-time - we don't want to bother with
* compiling different kernels for different machines..
*
* On machines without RDTSC, we use read_clock().
*/
source %= RANDOM_SOURCES;
r_next= krandom.bin[source].r_next;
if(machine.processor > 486) {
@@ -300,7 +302,7 @@ vir_bytes bytes; /* # of bytes to be copied */
else if (vir_addr >= BASE_MEM_TOP && vir_addr + bytes <= UPPER_MEM_END)
return (phys_bytes) vir_addr;
#if DEAD_CODE /* brutal fix for QEMU and Bochs, if above doesn't work */
#if DEAD_CODE /* brutal fix, if the above is too restrictive */
if (vir_addr >= BIOS_MEM_BEGIN && vir_addr + bytes <= UPPER_MEM_END)
return (phys_bytes) vir_addr;
#endif
@@ -368,22 +370,6 @@ vir_bytes bytes; /* # of bytes to be copied */
#endif
}
/*==========================================================================*
* numap_local *
*==========================================================================*/
PUBLIC phys_bytes numap_local(proc_nr, vir_addr, bytes)
int proc_nr; /* process number to be mapped */
vir_bytes vir_addr; /* virtual address in bytes within D seg */
vir_bytes bytes; /* # of bytes required in segment */
{
/* Do umap_local() starting from a process number instead of a pointer.
* This function is used by device drivers, so they need not know about the
* process table. To save time, there is no 'seg' parameter. The segment
* is always D.
*/
return(umap_local(proc_addr(proc_nr), D, vir_addr, bytes));
}
/*===========================================================================*
* umap_remote *

View File

@@ -13,6 +13,7 @@
/* Common includes for the system library. */
#include "kernel.h"
#include "proto.h"
#include "proc.h"
/* Default handler for unused kernel calls. */

View File

@@ -2,13 +2,10 @@
* m_type: SYS_DEVIO
*
* The parameters for this system call are:
* m2_i3: DIO_REQUEST (request input or output)
* m2_i1: DIO_TYPE (flag indicating byte, word, or long)
* m2_l1: DIO_PORT (port to read/ write)
* m2_l2: DIO_VALUE (value to write/ return value read)
*
* Author:
* Jorrit N. Herder <jnherder@cs.vu.nl>
* m2_i3: DIO_REQUEST (request input or output)
* m2_i1: DIO_TYPE (flag indicating byte, word, or long)
* m2_l1: DIO_PORT (port to read/ write)
* m2_l2: DIO_VALUE (value to write/ return value read)
*/
#include "../system.h"

View File

@@ -32,20 +32,6 @@ register message *m_ptr; /* pointer to request message */
rpc = proc_addr(m_ptr->PR_PROC_NR);
if (isemptyp(rpp) || ! isemptyp(rpc)) return(EINVAL);
#if DEAD_CODE
/* If the parent is a privileged process, ensure the child process also gets
* its own privilege structure for accounting. This is the only part that can
* fail, so do this before allocating the process table slot.
*/
if (priv(rpp)->s_flags & SYS_PROC) {
if (OK != (i=get_priv(rpc, SYS_PROC))) return(i); /* get structure */
for (i=0; i< BITMAP_CHUNKS(NR_SYS_PROCS); i++) /* remove pending: */
priv(rpc)->s_notify_pending.chunk[i] = 0; /* - notifications */
priv(rpc)->s_int_pending = 0; /* - interrupts */
sigemptyset(&priv(rpc)->s_sig_pending); /* - signals */
}
#endif
/* Copy parent 'proc' struct to child. And reinitialize some fields. */
#if (CHIP == INTEL)
old_ldt_sel = rpc->p_ldt_sel; /* backup local descriptors */

View File

@@ -7,9 +7,6 @@
* m1_i1: I_VAL_LEN (maximum length expected, optional)
* m1_p2: I_VAL_PTR2 (second, optional pointer)
* m1_i2: I_VAL_LEN2 (second length or process nr)
*
* Author:
* Jorrit N. Herder <jnherder@cs.vu.nl>
*/
#include "../system.h"

View File

@@ -7,9 +7,6 @@
* m5_i1: IRQ_POLICY (irq policy allows reenabling interrupts)
* m5_l3: IRQ_HOOK_ID (provides index to be returned on interrupt)
* ,, ,, (returns index of irq hook assigned at kernel)
*
* Author:
* Jorrit N. Herder <jnherder@cs.vu.nl>
*/
#include "../system.h"

View File

@@ -48,7 +48,7 @@ message *m_ptr; /* pointer to request message */
*/
if ((i=get_priv(rp, SYS_PROC)) != OK) return(i);
priv_id = priv(rp)->s_id; /* backup privilege id */
*priv(rp) = *priv(caller_ptr); /* copy privileges */
*priv(rp) = *priv(caller_ptr); /* copy from caller */
priv(rp)->s_id = priv_id; /* restore privilege id */
priv(rp)->s_proc_nr = proc_nr; /* reassociate process nr */

View File

@@ -7,9 +7,6 @@
* m4_l1: SEG_SELECT (return segment selector here)
* m4_l2: SEG_OFFSET (return offset within segment here)
* m4_l5: SEG_INDEX (return index into remote memory map here)
*
* Author:
* Jorrit N. Herder <jnherder@cs.vu.nl>
*/
#include "../system.h"
#include "../protect.h"

View File

@@ -22,7 +22,7 @@
* include 'boot_image' (this file) and 'idt' and 'gdt' (protect.c).
*
* Changes:
* Nov 10, 2004 removed controller->driver mappings (Jorrit N. Herder)
* Aug 02, 2005 minimal boot image and cleanup (Jorrit N. Herder)
* Oct 17, 2004 updated above and tasktab comments (Jorrit N. Herder)
* May 01, 2004 changed struct for system image (Jorrit N. Herder)
*/
@@ -37,26 +37,26 @@
/* Define stack sizes for the kernel tasks included in the system image. */
#define NO_STACK 0
#define SMALL_STACK (128 * sizeof(char *))
#define IDLE_S SMALL_STACK /* 3 intr, 3 temps, 4 db for Intel */
#define HRDW_S NO_STACK /* dummy task, uses kernel stack */
#define TASK_S SMALL_STACK /* system and clock task */
#define IDL_S SMALL_STACK /* 3 intr, 3 temps, 4 db for Intel */
#define HRD_S NO_STACK /* dummy task, uses kernel stack */
#define TSK_S SMALL_STACK /* system and clock task */
/* Stack space for all the task stacks. Declared as (char *) to align it. */
#define TOT_STACK_SPACE (IDLE_S + HRDW_S + (2 * TASK_S))
#define TOT_STACK_SPACE (IDL_S + HRD_S + (2 * TSK_S))
PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)];
/* Define flags for the various process types. */
#define IDLE_F (BILLABLE | SYS_PROC) /* idle task */
#define TASK_F (SYS_PROC) /* kernel tasks */
#define SERV_F (PREEMPTIBLE | SYS_PROC) /* system services */
#define USER_F (PREEMPTIBLE | BILLABLE) /* user processes */
#define IDL_F (BILLABLE | SYS_PROC) /* idle task */
#define TSK_F (SYS_PROC) /* kernel tasks */
#define SRV_F (PREEMPTIBLE | SYS_PROC) /* system services */
#define USR_F (PREEMPTIBLE | BILLABLE) /* user processes */
/* Define system call traps for the various process types. These call masks
* determine what system call traps a process is allowed to make.
*/
#define TASK_T (1 << RECEIVE) /* clock and system */
#define SERV_T (~0) /* system services */
#define USER_T ((1 << SENDREC) | (1 << ECHO)) /* user processes */
#define TSK_T (1 << RECEIVE) /* clock and system */
#define SRV_T (~0) /* system services */
#define USR_T ((1 << SENDREC) | (1 << ECHO)) /* user processes */
/* Send masks determine to whom processes can send messages or notifications.
* The values here are used for the processes in the boot image. We rely on
@@ -69,11 +69,10 @@ PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)];
* "BITCHUNK_BITS - NR_TASKS", because a bitchunk_t field is used to store
* the send masks in the table that describes that processes in the image.
*/
#define SERV_M (~0)
#define SYST_M (~0)
#define USER_M (s(PM_PROC_NR)|s(FS_PROC_NR)|s(SM_PROC_NR))
#define DRIV_M (USER_M | \
s(SYSTEM)|s(CLOCK)|s(LOG_PROC_NR)|s(TTY_PROC_NR))
#define SRV_M (~0)
#define SYS_M (~0)
#define USR_M (s(PM_PROC_NR)|s(FS_PROC_NR)|s(SM_PROC_NR))
#define DRV_M (USR_M | s(SYSTEM)|s(CLOCK)|s(LOG_PROC_NR)|s(TTY_PROC_NR))
/* Sanity check to make sure the send masks can be set. */
extern int dummy[(BITCHUNK_BITS-NR_TASKS > INIT_PROC_NR) ? 1 : -1];
@@ -87,19 +86,19 @@ extern int dummy[(BITCHUNK_BITS-NR_TASKS > INIT_PROC_NR) ? 1 : -1];
* initial program counter and stack size is also provided for kernel tasks.
*/
PUBLIC struct boot_image image[] = {
/* process nr, pc, flags, qs, queue, stack, traps, ipc mask, name */
{ IDLE, idle_task, IDLE_F, 32, IDLE_Q, IDLE_S, 0, 0, "IDLE" },
{ CLOCK, clock_task, TASK_F, 0, TASK_Q, TASK_S, TASK_T, 0, "CLOCK" },
{ SYSTEM, sys_task, TASK_F, 0, TASK_Q, TASK_S, TASK_T, 0, "SYSTEM" },
{ HARDWARE, 0, TASK_F, 0, TASK_Q, HRDW_S, 0, 0, "KERNEL" },
{ PM_PROC_NR, 0, SERV_F, 16, 3, 0, SERV_T, SERV_M, "pm" },
{ FS_PROC_NR, 0, SERV_F, 16, 4, 0, SERV_T, SERV_M, "fs" },
{ SM_PROC_NR, 0, SERV_F, 16, 3, 0, SERV_T, SYST_M, "sm" },
{ TTY_PROC_NR, 0, SERV_F, 16, 1, 0, SERV_T, SYST_M, "tty" },
{ MEM_PROC_NR, 0, SERV_F, 16, 2, 0, SERV_T, DRIV_M, "memory" },
{ LOG_PROC_NR, 0, SERV_F, 16, 2, 0, SERV_T, SYST_M, "log" },
{ DRVR_PROC_NR, 0, SERV_F, 16, 2, 0, SERV_T, DRIV_M, "driver" },
{ INIT_PROC_NR, 0, USER_F, 8, USER_Q, 0, USER_T, USER_M, "init" },
/* process nr, pc, flags, qs, queue, stack, traps, ipc, sys, name */
{ IDLE, idle_task, IDL_F, 32, IDLE_Q, IDL_S, 0, 0, 0, "IDLE" },
{ CLOCK,clock_task, TSK_F, 0, TASK_Q, TSK_S, TSK_T, 0, 0, "CLOCK" },
{ SYSTEM, sys_task, TSK_F, 0, TASK_Q, TSK_S, TSK_T, 0, 0, "SYSTEM" },
{ HARDWARE, 0, TSK_F, 0, TASK_Q, HRD_S, 0, 0, 0, "KERNEL" },
{ PM_PROC_NR, 0, SRV_F, 16, 3, 0, SRV_T, SRV_M, ~0, "pm" },
{ FS_PROC_NR, 0, SRV_F, 16, 4, 0, SRV_T, SRV_M, ~0, "fs" },
{ SM_PROC_NR, 0, SRV_F, 16, 3, 0, SRV_T, SYS_M, ~0, "sm" },
{ TTY_PROC_NR, 0, SRV_F, 16, 1, 0, SRV_T, SYS_M, ~0, "tty" },
{ MEM_PROC_NR, 0, SRV_F, 16, 2, 0, SRV_T, DRV_M, ~0, "memory" },
{ LOG_PROC_NR, 0, SRV_F, 16, 2, 0, SRV_T, SYS_M, ~0, "log" },
{ DRVR_PROC_NR, 0, SRV_F, 16, 2, 0, SRV_T, DRV_M, ~0, "driver" },
{ INIT_PROC_NR, 0, USR_F, 8, USER_Q, 0, USR_T, USR_M, 0, "init" },
};
/* Verify the size of the system image table at compile time. If the number

View File

@@ -17,8 +17,9 @@ struct boot_image {
char quantum; /* quantum (tick count) */
int priority; /* scheduling priority */
int stksize; /* stack size for tasks */
short call_mask; /* allowed system calls */
short call_mask; /* allowed system call traps */
bitchunk_t send_mask; /* send mask protection */
long sys_mask; /* system call protection */
char proc_name[P_NAME_LEN]; /* name in process table */
};

View File

@@ -1,9 +1,9 @@
/* This file contains a collection of miscellaneous procedures:
* panic: abort MINIX due to a fatal error
* kprintf: diagnostic output for the kernel
* panic: abort MINIX due to a fatal error
* kprintf: diagnostic output for the kernel
*
* Changes:
* simple printing to circular buffer (Jorrit N. Herder)
* Dec 10, 2004 kernel printing to circular buffer (Jorrit N. Herder)
*
* This file contains the routines that take care of kernel messages, i.e.,
* diagnostic output within the kernel. Kernel messages are not directly