minix/kernel/system.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

217 lines
6 KiB
C

/* Function prototypes for the system library. The prototypes in this file
* are undefined to NULL if the kernel call is not enabled in config.h.
* The implementation is contained in src/kernel/system/.
*
* The system library allows to access system services by doing a kernel call.
* System calls are transformed into request messages to the SYS task that is
* responsible for handling the call. By convention, sys_call() is transformed
* into a message with type SYS_CALL that is handled in a function do_call().
*
* Changes:
* Mar 01, 2010 SYS_CLEAR and SYS_EXIT split (Cristiano Giuffrida)
* Jul 30, 2005 created SYS_INT86 to support BIOS driver (Philip Homburg)
* Jul 13, 2005 created SYS_PRIVCTL to manage services (Jorrit N. Herder)
* Jul 09, 2005 updated SYS_KILL to signal services (Jorrit N. Herder)
* Jun 21, 2005 created SYS_NICE for nice(2) kernel call (Ben J. Gras)
* Jun 21, 2005 created SYS_MEMSET to speed up exec(2) (Ben J. Gras)
* Jan 20, 2005 updated SYS_COPY for virtual_copy() (Jorrit N. Herder)
* Oct 24, 2004 created SYS_GETKSIG to support PM (Jorrit N. Herder)
* Oct 10, 2004 created handler for unused calls (Jorrit N. Herder)
* Sep 09, 2004 updated SYS_EXIT to let services exit (Jorrit N. Herder)
* Aug 25, 2004 rewrote SYS_SETALARM to clean up code (Jorrit N. Herder)
* Jul 13, 2004 created SYS_SEGCTL to support drivers (Jorrit N. Herder)
* May 24, 2004 created SYS_SDEVIO to support drivers (Jorrit N. Herder)
* May 24, 2004 created SYS_GETINFO to retrieve info (Jorrit N. Herder)
* Apr 18, 2004 created SYS_VDEVIO to support drivers (Jorrit N. Herder)
* Feb 24, 2004 created SYS_IRQCTL to support drivers (Jorrit N. Herder)
* Feb 02, 2004 created SYS_DEVIO to support drivers (Jorrit N. Herder)
*/
#ifndef SYSTEM_H
#define SYSTEM_H
/* Common includes for the system library. */
#include "debug.h"
#include "kernel.h"
#include "proto.h"
#include "proc.h"
int do_exec(struct proc * caller, message *m_ptr);
#if ! USE_EXEC
#define do_exec NULL
#endif
int do_fork(struct proc * caller, message *m_ptr);
#if ! USE_FORK
#define do_fork NULL
#endif
int do_clear(struct proc * caller, message *m_ptr);
#if ! USE_CLEAR
#define do_clear NULL
#endif
int do_trace(struct proc * caller, message *m_ptr);
#if ! USE_TRACE
#define do_trace NULL
#endif
int do_runctl(struct proc * caller, message *m_ptr);
#if ! USE_RUNCTL
#define do_runctl NULL
#endif
int do_update(struct proc * caller, message *m_ptr);
#if ! USE_UPDATE
#define do_update NULL
#endif
int do_exit(struct proc * caller, message *m_ptr);
#if ! USE_EXIT
#define do_exit NULL
#endif
int do_copy(struct proc * caller, message *m_ptr);
#define do_vircopy do_copy
#if ! (USE_VIRCOPY || USE_PHYSCOPY)
#define do_copy NULL
#endif
int do_umap(struct proc * caller, message *m_ptr);
#if ! USE_UMAP
#define do_umap NULL
#endif
int do_umap_remote(struct proc * caller, message *m_ptr);
#if ! USE_UMAP_REMOTE
#define do_umap_remote NULL
#endif
int do_vumap(struct proc * caller, message *m_ptr);
#if ! USE_VUMAP
#define do_vumap NULL
#endif
int do_memset(struct proc * caller, message *m_ptr);
#if ! USE_MEMSET
#define do_memset NULL
#endif
int do_abort(struct proc * caller, message *m_ptr);
#if ! USE_ABORT
#define do_abort NULL
#endif
int do_getinfo(struct proc * caller, message *m_ptr);
#if ! USE_GETINFO
#define do_getinfo NULL
#endif
int do_privctl(struct proc * caller, message *m_ptr);
#if ! USE_PRIVCTL
#define do_privctl NULL
#endif
int do_irqctl(struct proc * caller, message *m_ptr);
#if ! USE_IRQCTL
#define do_irqctl NULL
#endif
int do_devio(struct proc * caller, message *m_ptr);
#if ! USE_DEVIO
#define do_devio NULL
#endif
int do_vdevio(struct proc * caller, message *m_ptr);
#if ! USE_VDEVIO
#define do_vdevio NULL
#endif
int do_sdevio(struct proc * caller, message *m_ptr);
#if ! USE_SDEVIO
#define do_sdevio NULL
#endif
int do_kill(struct proc * caller, message *m_ptr);
#if ! USE_KILL
#define do_kill NULL
#endif
int do_getksig(struct proc * caller, message *m_ptr);
#if ! USE_GETKSIG
#define do_getksig NULL
#endif
int do_endksig(struct proc * caller, message *m_ptr);
#if ! USE_ENDKSIG
#define do_endksig NULL
#endif
int do_sigsend(struct proc * caller, message *m_ptr);
#if ! USE_SIGSEND
#define do_sigsend NULL
#endif
int do_sigreturn(struct proc * caller, message *m_ptr);
#if ! USE_SIGRETURN
#define do_sigreturn NULL
#endif
int do_times(struct proc * caller, message *m_ptr);
#if ! USE_TIMES
#define do_times NULL
#endif
int do_setalarm(struct proc * caller, message *m_ptr);
#if ! USE_SETALARM
#define do_setalarm NULL
#endif
int do_stime(struct proc * caller, message *m_ptr);
int do_vtimer(struct proc * caller, message *m_ptr);
#if ! USE_VTIMER
#define do_vtimer NULL
#endif
int do_safecopy_to(struct proc * caller, message *m_ptr);
int do_safecopy_from(struct proc * caller, message *m_ptr);
int do_vsafecopy(struct proc * caller, message *m_ptr);
int do_iopenable(struct proc * caller, message *m_ptr);
int do_vmctl(struct proc * caller, message *m_ptr);
int do_setgrant(struct proc * caller, message *m_ptr);
int do_readbios(struct proc * caller, message *m_ptr);
int do_safemap(struct proc * caller, message *m_ptr);
int do_saferevmap(struct proc * caller, message *m_ptr);
int do_safeunmap(struct proc * caller, message *m_ptr);
int do_sprofile(struct proc * caller, message *m_ptr);
#if ! SPROFILE
#define do_sprofile NULL
#endif
int do_cprofile(struct proc * caller, message *m_ptr);
int do_profbuf(struct proc * caller, message *m_ptr);
#if ! CPROFILE
#define do_cprofile NULL
#define do_profbuf NULL
#endif
int do_getmcontext(struct proc * caller, message *m_ptr);
int do_setmcontext(struct proc * caller, message *m_ptr);
#if ! USE_MCONTEXT
#define do_getmcontext NULL
#define do_setmcontext NULL
#endif
int do_schedule(struct proc * caller, message *m_ptr);
int do_schedctl(struct proc * caller, message *m_ptr);
int do_statectl(struct proc * caller, message *m_ptr);
#if ! USE_STATECTL
#define do_statectl NULL
#endif
#endif /* SYSTEM_H */