minix/include/minix/const.h

165 lines
6.5 KiB
C
Raw Normal View History

#ifndef _MINIX_CONST_H
#define _MINIX_CONST_H
2005-04-21 16:53:53 +02:00
#include <machine/archconst.h>
/* The UNUSED annotation tells the compiler or lint not to complain
* about an unused variable or function parameter.
*
* A number of different annotations are used, depending on the
* compiler or checker that is looking at the code.
*
* Note that some variants rename the parameter, so if you use
* the parameter after all, you'll get a complaint about a missing
* variable.
*
* You use it like this:
*
* void foo(int UNUSED(x)){}
*/
#ifndef UNUSED
#if defined _lint
# define UNUSED(v) /*lint -e(715,818)*/ v
#elif defined(__GNUC__)
# define UNUSED(v) UNUSED_ ## v __attribute((unused))
#elif defined __LCLINT__
# define UNUSED(v) /*@unused@*/ v
#else
# define UNUSED(v) _UNUSED_ ## v
#endif
#endif
2005-04-21 16:53:53 +02:00
#define EXTERN extern /* used in *.h files */
#define TRUE 1 /* used for turning integers into Booleans */
#define FALSE 0 /* used for turning integers into Booleans */
#define SUPER_USER ((uid_t) 0) /* uid_t of superuser */
2005-04-21 16:53:53 +02:00
#include <sys/null.h> /* NULL Pointer */
#define SCPVEC_NR 64 /* max # of entries in a SYS_VSAFECOPY request */
#define MAPVEC_NR 64 /* max # of entries in a SYS_VUMAP request */
#define NR_IOREQS 64 /* maximum number of entries in an iorequest */
#define VUA_READ 0x01 /* for SYS_VUMAP: read access */
#define VUA_WRITE 0x02 /* for SYS_VUMAP: write access */
2005-04-21 16:53:53 +02:00
/* Message passing constants. */
#define MESS_SIZE (sizeof(message)) /* might need usizeof from FS here */
/* Memory related constants. */
2005-04-21 16:53:53 +02:00
#define SEGMENT_TYPE 0xFF00 /* bit mask to get segment type */
#define SEGMENT_INDEX 0x00FF /* bit mask to get segment index */
#define PHYS_SEG 0x0400 /* flag indicating entire physical memory */
2005-04-29 17:36:43 +02:00
#define LOCAL_VM_SEG 0x1000 /* same as LOCAL_SEG, but with vm lookup */
#define MEM_GRANT 3
No more intel/minix segments. This commit removes all traces of Minix segments (the text/data/stack memory map abstraction in the kernel) and significance of Intel segments (hardware segments like CS, DS that add offsets to all addressing before page table translation). This ultimately simplifies the memory layout and addressing and makes the same layout possible on non-Intel architectures. There are only two types of addresses in the world now: virtual and physical; even the kernel and processes have the same virtual address space. Kernel and user processes can be distinguished at a glance as processes won't use 0xF0000000 and above. No static pre-allocated memory sizes exist any more. Changes to booting: . The pre_init.c leaves the kernel and modules exactly as they were left by the bootloader in physical memory . The kernel starts running using physical addressing, loaded at a fixed location given in its linker script by the bootloader. All code and data in this phase are linked to this fixed low location. . It makes a bootstrap pagetable to map itself to a fixed high location (also in linker script) and jumps to the high address. All code and data then use this high addressing. . All code/data symbols linked at the low addresses is prefixed by an objcopy step with __k_unpaged_*, so that that code cannot reference highly-linked symbols (which aren't valid yet) or vice versa (symbols that aren't valid any more). . The two addressing modes are separated in the linker script by collecting the unpaged_*.o objects and linking them with low addresses, and linking the rest high. Some objects are linked twice, once low and once high. . The bootstrap phase passes a lot of information (e.g. free memory list, physical location of the modules, etc.) using the kinfo struct. . After this bootstrap the low-linked part is freed. . The kernel maps in VM into the bootstrap page table so that VM can begin executing. Its first job is to make page tables for all other boot processes. So VM runs before RS, and RS gets a fully dynamic, VM-managed address space. VM gets its privilege info from RS as usual but that happens after RS starts running. . Both the kernel loading VM and VM organizing boot processes happen using the libexec logic. This removes the last reason for VM to still know much about exec() and vm/exec.c is gone. Further Implementation: . All segments are based at 0 and have a 4 GB limit. . The kernel is mapped in at the top of the virtual address space so as not to constrain the user processes. . Processes do not use segments from the LDT at all; there are no segments in the LDT any more, so no LLDT is needed. . The Minix segments T/D/S are gone and so none of the user-space or in-kernel copy functions use them. The copy functions use a process endpoint of NONE to realize it's a physical address, virtual otherwise. . The umap call only makes sense to translate a virtual address to a physical address now. . Segments-related calls like newmap and alloc_segments are gone. . All segments-related translation in VM is gone (vir2map etc). . Initialization in VM is simpler as no moving around is necessary. . VM and all other boot processes can be linked wherever they wish and will be mapped in at the right location by the kernel and VM respectively. Other changes: . The multiboot code is less special: it does not use mb_print for its diagnostics any more but uses printf() as normal, saving the output into the diagnostics buffer, only printing to the screen using the direct print functions if a panic() occurs. . The multiboot code uses the flexible 'free memory map list' style to receive the list of free memory if available. . The kernel determines the memory layout of the processes to a degree: it tells VM where the kernel starts and ends and where the kernel wants the top of the process to be. VM then uses this entire range, i.e. the stack is right at the top, and mmap()ped bits of memory are placed below that downwards, and the break grows upwards. Other Consequences: . Every process gets its own page table as address spaces can't be separated any more by segments. . As all segments are 0-based, there is no distinction between virtual and linear addresses, nor between userspace and kernel addresses. . Less work is done when context switching, leading to a net performance increase. (8% faster on my machine for 'make servers'.) . The layout and configuration of the GDT makes sysenter and syscall possible.
2012-05-07 16:03:35 +02:00
#define VIR_ADDR 1
#define VM_D (LOCAL_VM_SEG | VIR_ADDR)
#define VM_GRANT (LOCAL_VM_SEG | MEM_GRANT)
2005-04-21 16:53:53 +02:00
/* Labels used to disable code sections for different reasons. */
#define DEAD_CODE 0 /* unused code in normal configuration */
#define FUTURE_CODE 0 /* new code to be activated + tested later */
#define TEMP_CODE 1 /* active code to be removed later */
/* Miscellaneous */
#define BYTE 0377 /* mask for 8 bits */
#define READING 0 /* copy data to user */
#define WRITING 1 /* copy data from user */
#define PEEKING 2 /* retrieve FS data without copying */
2005-04-21 16:53:53 +02:00
#define HAVE_SCATTERED_IO 1 /* scattered I/O is now standard */
/* Memory is allocated in clicks. */
#if defined(__i386__) || defined(__arm__)
#define CLICK_SIZE 4096 /* unit in which memory is allocated */
#define CLICK_SHIFT 12 /* log2 of CLICK_SIZE */
#else
#error Unsupported arch
2005-04-21 16:53:53 +02:00
#endif
/* Click alignment macros. */
#define CLICK_FLOOR(n) (((vir_bytes)(n) / CLICK_SIZE) * CLICK_SIZE)
#define CLICK_CEIL(n) CLICK_FLOOR((vir_bytes)(n) + CLICK_SIZE-1)
/* Sizes of memory tables. The boot monitor distinguishes three memory areas,
* namely low mem below 1M, 1M-16M, and mem after 16M. More chunks are needed
* for DOS MINIX.
*/
2011-09-01 00:01:59 +02:00
#define NR_MEMS 16
2011-05-04 18:51:43 +02:00
#define CLICK2ABS(v) ((v) << CLICK_SHIFT)
#define ABS2CLICK(a) ((a) >> CLICK_SHIFT)
2005-04-21 16:53:53 +02:00
/* Flag bits for i_mode in the inode. */
#define I_TYPE 0170000 /* this field gives inode type */
#define I_UNIX_SOCKET 0140000 /* unix domain socket */
#define I_SYMBOLIC_LINK 0120000 /* file is a symbolic link */
2005-04-21 16:53:53 +02:00
#define I_REGULAR 0100000 /* regular file, not dir or special */
#define I_BLOCK_SPECIAL 0060000 /* block special file */
#define I_DIRECTORY 0040000 /* file is a directory */
#define I_CHAR_SPECIAL 0020000 /* character special file */
#define I_NAMED_PIPE 0010000 /* named pipe (FIFO) */
2005-04-21 16:53:53 +02:00
#define I_SET_UID_BIT 0004000 /* set effective uid_t on exec */
#define I_SET_GID_BIT 0002000 /* set effective gid_t on exec */
#define I_SET_STCKY_BIT 0001000 /* sticky bit */
#define ALL_MODES 0007777 /* all bits for user, group and others */
2005-04-21 16:53:53 +02:00
#define RWX_MODES 0000777 /* mode bits for RWX only */
#define R_BIT 0000004 /* Rwx protection bit */
#define W_BIT 0000002 /* rWx protection bit */
#define X_BIT 0000001 /* rwX protection bit */
#define I_NOT_ALLOC 0000000 /* this inode is free */
/* Some limits. */
#define MAX_INODE_NR ((ino_t) 037777777777) /* largest inode number */
#define MAX_FILE_POS ((off_t) 0x7FFFFFFF) /* largest legal file offset */
#define UMAX_FILE_POS ((unsigned) 0x7FFFFFFF) /* largest legal file offset */
2005-04-21 16:53:53 +02:00
#define MAX_SYM_LOOPS 8 /* how many symbolic links are recursed */
2005-04-21 16:53:53 +02:00
#define NO_BLOCK ((block_t) 0) /* absence of a block number */
#define NO_ENTRY ((ino_t) 0) /* absence of a dir entry */
#define NO_ZONE ((zone_t) 0) /* absence of a zone number */
#define NO_DEV ((dev_t) 0) /* absence of a device numb */
2010-05-28 11:39:18 +02:00
#define NO_LINK ((nlink_t) 0) /* absence of incoming links */
#define INVAL_UID ((uid_t) -1) /* invalid uid value */
#define INVAL_GID ((gid_t) -1) /* invalid gid value */
#define SERVARNAME "cttyline"
#define ARCHVARNAME "arch"
#define BOARDVARNAME "board"
#define SERBAUDVARNAME "cttybaud"
Rewrite of boot process KERNEL CHANGES: - The kernel only knows about privileges of kernel tasks and the root system process (now RS). - Kernel tasks and the root system process are the only processes that are made schedulable by the kernel at startup. All the other processes in the boot image don't get their privileges set at startup and are inhibited from running by the RTS_NO_PRIV flag. - Removed the assumption on the ordering of processes in the boot image table. System processes can now appear in any order in the boot image table. - Privilege ids can now be assigned both statically or dynamically. The kernel assigns static privilege ids to kernel tasks and the root system process. Each id is directly derived from the process number. - User processes now all share the static privilege id of the root user process (now INIT). - sys_privctl split: we have more calls now to let RS set privileges for system processes. SYS_PRIV_ALLOW / SYS_PRIV_DISALLOW are only used to flip the RTS_NO_PRIV flag and allow / disallow a process from running. SYS_PRIV_SET_SYS / SYS_PRIV_SET_USER are used to set privileges for a system / user process. - boot image table flags split: PROC_FULLVM is the only flag that has been moved out of the privilege flags and is still maintained in the boot image table. All the other privilege flags are out of the kernel now. RS CHANGES: - RS is the only user-space process who gets to run right after in-kernel startup. - RS uses the boot image table from the kernel and three additional boot image info table (priv table, sys table, dev table) to complete the initialization of the system. - RS checks that the entries in the priv table match the entries in the boot image table to make sure that every process in the boot image gets schedulable. - RS only uses static privilege ids to set privileges for system services in the boot image. - RS includes basic memory management support to allocate the boot image buffer dynamically during initialization. The buffer shall contain the executable image of all the system services we would like to restart after a crash. - First step towards decoupling between resource provisioning and resource requirements in RS: RS must know what resources it needs to restart a process and what resources it has currently available. This is useful to tradeoff reliability and resource consumption. When required resources are missing, the process cannot be restarted. In that case, in the future, a system flag will tell RS what to do. For example, if CORE_PROC is set, RS should trigger a system-wide panic because the system can no longer function correctly without a core system process. PM CHANGES: - The process tree built at initialization time is changed to have INIT as root with pid 0, RS child of INIT and all the system services children of RS. This is required to make RS in control of all the system services. - PM no longer registers labels for system services in the boot image. This is now part of RS's initialization process.
2009-12-11 01:08:19 +01:00
/* Bits for s_flags in the privilege structure. */
2010-07-07 00:05:21 +02:00
#define PREEMPTIBLE 0x002 /* kernel tasks are not preemptible */
#define BILLABLE 0x004 /* some processes are not billable */
#define DYN_PRIV_ID 0x008 /* privilege id assigned dynamically */
2010-07-07 00:05:21 +02:00
#define SYS_PROC 0x010 /* system processes have own priv structure */
#define CHECK_IO_PORT 0x020 /* check if I/O request is allowed */
#define CHECK_IRQ 0x040 /* check if IRQ can be used */
#define CHECK_MEM 0x080 /* check if (VM) mem map request is allowed */
#define ROOT_SYS_PROC 0x100 /* this is a root system process instance */
#define VM_SYS_PROC 0x200 /* this is a vm system process instance */
#define LU_SYS_PROC 0x400 /* this is a live updated sys proc instance */
#define RST_SYS_PROC 0x800 /* this is a restarted sys proc instance */
/* Values for the "verbose" boot monitor variable */
#define VERBOSEBOOT_QUIET 0
#define VERBOSEBOOT_BASIC 1
#define VERBOSEBOOT_EXTRA 2
#define VERBOSEBOOT_MAX 3
#define VERBOSEBOOTVARNAME "verbose"
/* magic value to put in struct proc entries for sanity checks. */
#define PMAGIC 0xC0FFEE1
/* MINIX_KERNFLAGS flags */
#define MKF_I386_INTEL_SYSENTER (1L << 0) /* SYSENTER available and supported */
#define MKF_I386_AMD_SYSCALL (1L << 1) /* SYSCALL available and supported */
#endif /* _MINIX_CONST_H */