cd8b915ed9
- no longer have kernel have its own page table that is loaded on every kernel entry (trap, interrupt, exception). the primary purpose is to reduce the number of required reloads. Result: - kernel can only access memory of process that was running when kernel was entered - kernel must be mapped into every process page table, so traps to kernel keep working Problem: - kernel must often access memory of arbitrary processes (e.g. send arbitrary processes messages); this can't happen directly any more; usually because that process' page table isn't loaded at all, sometimes because that memory isn't mapped in at all, sometimes because it isn't mapped in read-write. So: - kernel must be able to map in memory of any process, in its own address space. Implementation: - VM and kernel share a range of memory in which addresses of all page tables of all processes are available. This has two purposes: . Kernel has to know what data to copy in order to map in a range . Kernel has to know where to write the data in order to map it in That last point is because kernel has to write in the currently loaded page table. - Processes and kernel are separated through segments; kernel segments haven't changed. - The kernel keeps the process whose page table is currently loaded in 'ptproc.' - If it wants to map in a range of memory, it writes the value of the page directory entry for that range into the page directory entry in the currently loaded map. There is a slot reserved for such purposes. The kernel can then access this memory directly. - In order to do this, its segment has been increased (and the segments of processes start where it ends). - In the pagefault handler, detect if the kernel is doing 'trappable' memory access (i.e. a pagefault isn't a fatal error) and if so, - set the saved instruction pointer to phys_copy_fault, breaking out of phys_copy - set the saved eax register to the address of the page fault, both for sanity checking and for checking in which of the two ranges that phys_copy was called with the fault occured - Some boot-time processes do not have their own page table, and are mapped in with the kernel, and separated with segments. The kernel detects this using HASPT. If such a process has to be scheduled, any page table will work and no page table switch is done. Major changes in kernel are - When accessing user processes memory, kernel no longer explicitly checks before it does so if that memory is OK. It simply makes the mapping (if necessary), tries to do the operation, and traps the pagefault if that memory isn't present; if that happens, the copy function returns EFAULT. So all of the CHECKRANGE_OR_SUSPEND macros are gone. - Kernel no longer has to copy/read and parse page tables. - A message copying optimisation: when messages are copied, and the recipient isn't mapped in, they are copied into a buffer in the kernel. This is done in QueueMess. The next time the recipient is scheduled, this message is copied into its memory. This happens in schedcheck(). This eliminates the mapping/copying step for messages, and makes it easier to deliver messages. This eliminates soft_notify. - Kernel no longer creates a page table at all, so the vm_setbuf and pagetable writing in memory.c is gone. Minor changes in kernel are - ipc_stats thrown out, wasn't used - misc flags all renamed to MF_* - NOREC_* macros to enter and leave functions that should not be called recursively; just sanity checks really - code to fully decode segment selectors and descriptors to print on exceptions - lots of vmassert()s added, only executed if DEBUG_VMASSERT is 1
75 lines
2.6 KiB
C
75 lines
2.6 KiB
C
|
|
#ifndef _I386_TYPES_H
|
|
#define _I386_TYPES_H
|
|
|
|
#include <minix/sys_config.h>
|
|
#include "archconst.h"
|
|
|
|
typedef unsigned reg_t; /* machine register */
|
|
typedef reg_t segdesc_t;
|
|
|
|
/* The stack frame layout is determined by the software, but for efficiency
|
|
* it is laid out so the assembly code to use it is as simple as possible.
|
|
* 80286 protected mode and all real modes use the same frame, built with
|
|
* 16-bit registers. Real mode lacks an automatic stack switch, so little
|
|
* is lost by using the 286 frame for it. The 386 frame differs only in
|
|
* having 32-bit registers and more segment registers. The same names are
|
|
* used for the larger registers to avoid differences in the code.
|
|
*/
|
|
struct stackframe_s { /* proc_ptr points here */
|
|
u16_t gs; /* last item pushed by save */
|
|
u16_t fs; /* ^ */
|
|
u16_t es; /* | */
|
|
u16_t ds; /* | */
|
|
reg_t di; /* di through cx are not accessed in C */
|
|
reg_t si; /* order is to match pusha/popa */
|
|
reg_t fp; /* bp */
|
|
reg_t st; /* hole for another copy of sp */
|
|
reg_t bx; /* | */
|
|
reg_t dx; /* | */
|
|
reg_t cx; /* | */
|
|
reg_t retreg; /* ax and above are all pushed by save */
|
|
reg_t retadr; /* return address for assembly code save() */
|
|
reg_t pc; /* ^ last item pushed by interrupt */
|
|
reg_t cs; /* | */
|
|
reg_t psw; /* | */
|
|
reg_t sp; /* | */
|
|
reg_t ss; /* these are pushed by CPU during interrupt */
|
|
};
|
|
|
|
struct segdesc_s { /* segment descriptor for protected mode */
|
|
u16_t limit_low;
|
|
u16_t base_low;
|
|
u8_t base_middle;
|
|
u8_t access; /* |P|DL|1|X|E|R|A| */
|
|
u8_t granularity; /* |G|X|0|A|LIMT| */
|
|
u8_t base_high;
|
|
};
|
|
|
|
#define LDT_SIZE (2 + NR_REMOTE_SEGS) /* CS, DS and remote segments */
|
|
|
|
/* Fixed local descriptors. */
|
|
#define CS_LDT_INDEX 0 /* process CS */
|
|
#define DS_LDT_INDEX 1 /* process DS=ES=FS=GS=SS */
|
|
#define EXTRA_LDT_INDEX 2 /* first of the extra LDT entries */
|
|
|
|
typedef struct segframe {
|
|
reg_t p_ldt_sel; /* selector in gdt with ldt base and limit */
|
|
reg_t p_cr3; /* page table root */
|
|
struct segdesc_s p_ldt[LDT_SIZE]; /* CS, DS and remote */
|
|
} segframe_t;
|
|
|
|
/* Page fault event. Stored in process table. Only valid if PAGEFAULT
|
|
* set in p_rts_flags.
|
|
*/
|
|
struct pagefault
|
|
{
|
|
u32_t pf_virtual; /* Address causing fault (CR2). */
|
|
u32_t pf_flags; /* Pagefault flags on stack. */
|
|
};
|
|
|
|
#define INMEMORY(p) (!p->p_seg.p_cr3 || ptproc == p)
|
|
|
|
#endif /* #ifndef _I386_TYPES_H */
|
|
|