For /dev/mem, map in memory to be copied to memory's own address space
[minix3.git] / kernel / table.c
blobf10ea97c3d9798f3a25585da764c1c3bfadc8fc7
1 /* The object file of "table.c" contains most kernel data. Variables that
2 * are declared in the *.h files appear with EXTERN in front of them, as in
4 * EXTERN int x;
6 * Normally EXTERN is defined as extern, so when they are included in another
7 * file, no storage is allocated. If EXTERN were not present, but just say,
9 * int x;
11 * then including this file in several source files would cause 'x' to be
12 * declared several times. While some linkers accept this, others do not,
13 * so they are declared extern when included normally. However, it must be
14 * declared for real somewhere. That is done here, by redefining EXTERN as
15 * the null string, so that inclusion of all *.h files in table.c actually
16 * generates storage for them.
18 * Various variables could not be declared EXTERN, but are declared PUBLIC
19 * or PRIVATE. The reason for this is that extern variables cannot have a
20 * default initialization. If such variables are shared, they must also be
21 * declared in one of the *.h files without the initialization. Examples
22 * include 'boot_image' (this file) and 'idt' and 'gdt' (protect.c).
24 * Changes:
25 * Aug 02, 2005 set privileges and minimal boot image (Jorrit N. Herder)
26 * Oct 17, 2004 updated above and tasktab comments (Jorrit N. Herder)
27 * May 01, 2004 changed struct for system image (Jorrit N. Herder)
29 #define _TABLE
31 #include "kernel.h"
32 #include "proc.h"
33 #include "ipc.h"
34 #include <minix/com.h>
36 /* Define stack sizes for the kernel tasks included in the system image. */
37 #define NO_STACK 0
38 #define SMALL_STACK (256 * sizeof(char *))
39 #define IDL_S SMALL_STACK /* 3 intr, 3 temps, 4 db for Intel */
40 #define HRD_S NO_STACK /* dummy task, uses kernel stack */
41 #define TSK_S SMALL_STACK /* system and clock task */
43 /* Stack space for all the task stacks. Declared as (char *) to align it. */
44 #define TOT_STACK_SPACE (IDL_S + HRD_S + (2 * TSK_S))
45 PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)];
47 /* Define flags for the various process types. */
48 #define IDL_F (SYS_PROC | PREEMPTIBLE | BILLABLE) /* idle task */
49 #define TSK_F (SYS_PROC) /* kernel tasks */
50 #define SRV_F (SYS_PROC | PREEMPTIBLE) /* system services */
51 #define USR_F (BILLABLE | PREEMPTIBLE) /* user processes */
53 /* Define system call traps for the various process types. These call masks
54 * determine what system call traps a process is allowed to make.
56 #define TSK_T (1 << RECEIVE) /* clock and system */
57 #define SRV_T (~0) /* system services */
58 #define USR_T ((1 << SENDREC) | (1 << ECHO)) /* user processes */
60 /* Send masks determine to whom processes can send messages or notifications.
61 * The values here are used for the processes in the boot image. We rely on
62 * the initialization code in main() to match the s_nr_to_id() mapping for the
63 * processes in the boot image, so that the send mask that is defined here
64 * can be directly copied onto map[0] of the actual send mask. Privilege
65 * structure 0 is shared by user processes.
67 #define s(n) (1 << (s_nr_to_id(n)))
68 #define NUL_M 0
69 #define SRV_M (~0)
70 #define SYS_M (~0)
71 #define USR_M (s(PM_PROC_NR) | s(FS_PROC_NR) | s(RS_PROC_NR) | s(SYSTEM))
72 #define DRV_M (USR_M | s(SYSTEM) | s(CLOCK) | s(DS_PROC_NR) | s(LOG_PROC_NR) | s(TTY_PROC_NR))
74 /* Define kernel calls that processes are allowed to make. This is not looking
75 * very nice, but we need to define the access rights on a per call basis.
76 * Note that the reincarnation server has all bits on, because it should
77 * be allowed to distribute rights to services that it starts.
79 * Calls are unordered lists, converted by the kernel to bitmasks
80 * once at runtime.
82 #define FS_C SYS_KILL, SYS_VIRCOPY, SYS_SAFECOPYFROM, SYS_SAFECOPYTO, \
83 SYS_VIRVCOPY, SYS_UMAP, SYS_GETINFO, SYS_EXIT, SYS_TIMES, SYS_SETALARM, \
84 SYS_PRIVCTL, SYS_TRACE , SYS_SETGRANT, SYS_PROFBUF
85 #define DRV_C FS_C, SYS_SEGCTL, SYS_IRQCTL, SYS_INT86, SYS_DEVIO, \
86 SYS_SDEVIO, SYS_VDEVIO, SYS_SETGRANT, SYS_PROFBUF
88 PRIVATE int
89 fs_c[] = { FS_C },
90 pm_c[] = { SYS_ALL_CALLS },
91 rs_c[] = { SYS_ALL_CALLS },
92 ds_c[] = { SYS_ALL_CALLS },
93 drv_c[] = { DRV_C },
94 tty_c[] = { DRV_C, SYS_ABORT, SYS_VM_MAP, SYS_IOPENABLE, SYS_READBIOS },
95 mem_c[] = { DRV_C, SYS_PHYSCOPY, SYS_PHYSVCOPY, SYS_VM_MAP, SYS_IOPENABLE };
97 /* The system image table lists all programs that are part of the boot image.
98 * The order of the entries here MUST agree with the order of the programs
99 * in the boot image and all kernel tasks must come first.
101 * Each entry provides the process number, flags, quantum size, scheduling
102 * queue, allowed traps, ipc mask, and a name for the process table. The
103 * initial program counter and stack size is also provided for kernel tasks.
105 * Note: the quantum size must be positive in all cases!
107 #define c(calls) calls, (sizeof(calls) / sizeof((calls)[0]))
108 #define no_c { 0 }, 0
110 PUBLIC struct boot_image image[] = {
111 /* process nr, pc,flags, qs, queue, stack, traps, ipcto, call, name */
112 {IDLE, idle_task,IDL_F, 8, IDLE_Q, IDL_S, 0, 0, no_c,"idle" },
113 {CLOCK,clock_task,TSK_F, 8, TASK_Q, TSK_S, TSK_T, 0, no_c,"clock" },
114 {SYSTEM, sys_task,TSK_F, 8, TASK_Q, TSK_S, TSK_T, 0, no_c,"system"},
115 {HARDWARE, 0,TSK_F, 8, TASK_Q, HRD_S, 0, 0, no_c,"kernel"},
116 {PM_PROC_NR, 0,SRV_F, 32, 3, 0, SRV_T, SRV_M, c(pm_c),"pm" },
117 {FS_PROC_NR, 0,SRV_F, 32, 4, 0, SRV_T, SRV_M, c(fs_c),"vfs" },
118 {RS_PROC_NR, 0,SRV_F, 4, 3, 0, SRV_T, SYS_M, c(rs_c),"rs" },
119 {DS_PROC_NR, 0,SRV_F, 4, 3, 0, SRV_T, SYS_M, c(ds_c),"ds" },
120 {TTY_PROC_NR, 0,SRV_F, 4, 1, 0, SRV_T, SYS_M,c(tty_c),"tty" },
121 {MEM_PROC_NR, 0,SRV_F, 4, 2, 0, SRV_T, SYS_M,c(mem_c),"memory"},
122 {LOG_PROC_NR, 0,SRV_F, 4, 2, 0, SRV_T, SYS_M,c(drv_c),"log" },
123 {MFS_PROC_NR, 0,SRV_F, 32, 4, 0, SRV_T, SRV_M, c(fs_c),"mfs" },
124 {INIT_PROC_NR, 0,USR_F, 8, USER_Q, 0, USR_T, USR_M, no_c,"init" },
127 /* Verify the size of the system image table at compile time. Also verify that
128 * the first chunk of the ipc mask has enough bits to accommodate the processes
129 * in the image.
130 * If a problem is detected, the size of the 'dummy' array will be negative,
131 * causing a compile time error. Note that no space is actually allocated
132 * because 'dummy' is declared extern.
134 extern int dummy[(NR_BOOT_PROCS==sizeof(image)/
135 sizeof(struct boot_image))?1:-1];
136 extern int dummy[(BITCHUNK_BITS > NR_BOOT_PROCS - 1) ? 1 : -1];