minix/servers/rs/const.h
Ben Gras 50e2064049 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-07-15 22:30:15 +02:00

90 lines
3.6 KiB
C

/* Global constants used in RS.
*/
#ifndef RS_CONST_H
#define RS_CONST_H
#define DEBUG_DEFAULT 0
#define PRIV_DEBUG_DEFAULT 0
#ifndef DEBUG
#define DEBUG DEBUG_DEFAULT
#endif
#ifndef PRIV_DEBUG
#define PRIV_DEBUG PRIV_DEBUG_DEFAULT
#endif
/* Space reserved for program and arguments. */
#define MAX_COMMAND_LEN 512 /* maximum argument string length */
#define MAX_SCRIPT_LEN 256 /* maximum restart script name length */
#define MAX_NR_ARGS 10 /* maximum number of arguments */
#define MAX_IPC_LIST 256 /* Max size of list for IPC target
* process names
*/
/* Flag values. */
#define RS_IN_USE 0x001 /* set when process slot is in use */
#define RS_EXITING 0x002 /* set when exit is expected */
#define RS_REFRESHING 0x004 /* set when refresh must be done */
#define RS_NOPINGREPLY 0x008 /* service failed to reply to a ping request */
#define RS_TERMINATED 0x010 /* service has terminated */
#define RS_LATEREPLY 0x020 /* no reply sent to RS_DOWN caller yet */
#define RS_INITIALIZING 0x040 /* set when init is in progress */
#define RS_UPDATING 0x080 /* set when update is in progress */
#define RS_ACTIVE 0x100 /* set for the active instance of a service */
#define RS_REINCARNATE 0x200 /* after exit, restart with a new endpoint */
/* Sys flag values. */
#define SF_CORE_SRV 0x001 /* set for core system services */
#define SF_SYNCH_BOOT 0X002 /* set when process needs synch boot init */
#define SF_NEED_COPY 0x004 /* set when process needs copy to start */
#define SF_USE_COPY 0x008 /* set when process has a copy in memory */
#define SF_NEED_REPL 0x010 /* set when process needs replica to start */
#define SF_USE_REPL 0x020 /* set when process has a replica */
#define IMM_SF \
(SF_CORE_SRV | SF_SYNCH_BOOT | SF_NEED_COPY | SF_NEED_REPL) /* immutable */
/* Constants determining RS period and binary exponential backoff. */
#define RS_INIT_T (system_hz * 10) /* allow T ticks for init */
#define RS_DELTA_T (system_hz) /* check every T ticks */
#define BACKOFF_BITS (sizeof(long)*8) /* bits in backoff field */
#define MAX_BACKOFF 30 /* max backoff in RS_DELTA_T */
/* Magic process table addresses. */
#define BEG_RPROC_ADDR (&rproc[0])
#define END_RPROC_ADDR (&rproc[NR_SYS_PROCS])
/* Constants for live update. */
#define RS_DEFAULT_PREPARE_MAXTIME 2*RS_DELTA_T /* default prepare max time */
#define RS_MAX_PREPARE_MAXTIME 20*RS_DELTA_T /* max prepare max time */
/* Definitions for boot info tables. */
#define NULL_BOOT_NR NR_BOOT_PROCS /* marks a null boot entry */
#define DEFAULT_BOOT_NR NR_BOOT_PROCS /* marks the default boot entry */
/* Define sys flags for the various process types. */
#define SRV_SF (SF_CORE_SRV) /* system services */
#define SRVR_SF (SRV_SF | SF_NEED_REPL) /* services needing a replica */
#define DSRV_SF (0) /* dynamic system services */
#define VM_SF (SRVR_SF) /* vm */
/* Define device flags for the various process types. */
#define SRV_DF (DRV_FORCED) /* system services */
#define DSRV_DF (SRV_DF) /* dynamic system services */
/* Shorthands. */
#define SRV_OR_USR(rp, X, Y) (rp->r_priv.s_flags & SYS_PROC ? X : Y)
/* Reply flags. */
#define RS_DONTREPLY 0
#define RS_REPLY 1
/* Swap flags. */
#define RS_DONTSWAP 0
#define RS_SWAP 1
#endif /* RS_CONST_H */