Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
|
|
|
#ifndef _I386_ACONST_H
|
|
|
|
#define _I386_ACONST_H 1
|
|
|
|
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/interrupt.h>
|
|
|
|
#include <machine/memory.h>
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Constants for protected mode. */
|
|
|
|
|
|
|
|
/* Table sizes. */
|
2009-11-16 22:41:44 +01:00
|
|
|
#define IDT_SIZE 256 /* the table is set to it's maximal size */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
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
|
|
|
/* GDT layout (SYSENTER/SYSEXIT compliant) */
|
|
|
|
#define KERN_CS_INDEX 1
|
|
|
|
#define KERN_DS_INDEX 2
|
|
|
|
#define USER_CS_INDEX 3
|
|
|
|
#define USER_DS_INDEX 4
|
|
|
|
#define LDT_INDEX 5
|
|
|
|
#define TSS_INDEX_FIRST 6
|
|
|
|
#define TSS_INDEX(cpu) (TSS_INDEX_FIRST + (cpu)) /* per cpu kernel tss */
|
|
|
|
#define GDT_SIZE (TSS_INDEX(CONFIG_MAX_CPUS)) /* LDT descriptor */
|
|
|
|
|
|
|
|
#define SEG_SELECTOR(i) ((i)*8)
|
|
|
|
#define KERN_CS_SELECTOR SEG_SELECTOR(KERN_CS_INDEX)
|
|
|
|
#define KERN_DS_SELECTOR SEG_SELECTOR(KERN_DS_INDEX)
|
|
|
|
#define USER_CS_SELECTOR (SEG_SELECTOR(USER_CS_INDEX) | USER_PRIVILEGE)
|
|
|
|
#define USER_DS_SELECTOR (SEG_SELECTOR(USER_DS_INDEX) | USER_PRIVILEGE)
|
|
|
|
#define LDT_SELECTOR SEG_SELECTOR(LDT_INDEX)
|
|
|
|
#define TSS_SELECTOR(cpu) SEG_SELECTOR(TSS_INDEX(cpu))
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-07-13 00:54:27 +02:00
|
|
|
#define DESC_SIZE 8
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Privileges. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define INTR_PRIVILEGE 0 /* kernel and interrupt handlers */
|
|
|
|
#define USER_PRIVILEGE 3 /* servers and user processes */
|
Primary goal for these changes is:
- 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
2009-09-21 16:31:52 +02:00
|
|
|
#define RPL_MASK 0x03 /* bits in selector RPL */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* 286 hardware constants. */
|
|
|
|
|
|
|
|
/* Exception vector numbers. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define BOUNDS_VECTOR 5 /* bounds check failed */
|
|
|
|
#define INVAL_OP_VECTOR 6 /* invalid opcode */
|
|
|
|
#define COPROC_NOT_VECTOR 7 /* coprocessor not available */
|
|
|
|
#define DOUBLE_FAULT_VECTOR 8
|
|
|
|
#define COPROC_SEG_VECTOR 9 /* coprocessor segment overrun */
|
|
|
|
#define INVAL_TSS_VECTOR 10 /* invalid TSS */
|
|
|
|
#define SEG_NOT_VECTOR 11 /* segment not present */
|
|
|
|
#define STACK_FAULT_VECTOR 12 /* stack exception */
|
|
|
|
#define PROTECTION_VECTOR 13 /* general protection */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Selector bits. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define TI 0x04 /* table indicator */
|
|
|
|
#define RPL 0x03 /* requester privilege level */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Base and limit sizes and shifts. */
|
|
|
|
#define BASE_MIDDLE_SHIFT 16 /* shift for base --> base_middle */
|
|
|
|
|
|
|
|
/* Access-byte and type-byte bits. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define PRESENT 0x80 /* set for descriptor present */
|
|
|
|
#define DPL 0x60 /* descriptor privilege level mask */
|
|
|
|
#define DPL_SHIFT 5
|
|
|
|
#define SEGMENT 0x10 /* set for segment-type descriptors */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Access-byte bits. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define EXECUTABLE 0x08 /* set for executable segment */
|
|
|
|
#define CONFORMING 0x04 /* set for conforming segment if executable */
|
|
|
|
#define EXPAND_DOWN 0x04 /* set for expand-down segment if !executable*/
|
|
|
|
#define READABLE 0x02 /* set for readable segment if executable */
|
|
|
|
#define WRITEABLE 0x02 /* set for writeable segment if !executable */
|
|
|
|
#define TSS_BUSY 0x02 /* set if TSS descriptor is busy */
|
|
|
|
#define ACCESSED 0x01 /* set if segment accessed */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Special descriptor types. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define AVL_286_TSS 1 /* available 286 TSS */
|
|
|
|
#define LDT 2 /* local descriptor table */
|
|
|
|
#define BUSY_286_TSS 3 /* set transparently to the software */
|
|
|
|
#define CALL_286_GATE 4 /* not used */
|
|
|
|
#define TASK_GATE 5 /* only used by debugger */
|
|
|
|
#define INT_286_GATE 6 /* interrupt gate, used for all vectors */
|
|
|
|
#define TRAP_286_GATE 7 /* not used */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-11-16 22:41:44 +01:00
|
|
|
#define INT_GATE_TYPE (INT_286_GATE | DESC_386_BIT)
|
|
|
|
#define TSS_TYPE (AVL_286_TSS | DESC_386_BIT)
|
|
|
|
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Extra 386 hardware constants. */
|
|
|
|
|
|
|
|
/* Exception vector numbers. */
|
|
|
|
#define PAGE_FAULT_VECTOR 14
|
|
|
|
#define COPROC_ERR_VECTOR 16 /* coprocessor error */
|
2009-12-02 14:01:48 +01:00
|
|
|
#define ALIGNMENT_CHECK_VECTOR 17
|
|
|
|
#define MACHINE_CHECK_VECTOR 18
|
|
|
|
#define SIMD_EXCEPTION_VECTOR 19 /* SIMD Floating-Point Exception (#XM) */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Descriptor structure offsets. */
|
|
|
|
#define DESC_GRANULARITY 6 /* to granularity byte */
|
|
|
|
#define DESC_BASE_HIGH 7 /* to base_high */
|
|
|
|
|
|
|
|
/* Type-byte bits. */
|
2005-08-29 18:47:18 +02:00
|
|
|
#define DESC_386_BIT 0x08 /* 386 types are obtained by ORing with this */
|
2005-04-21 16:53:53 +02:00
|
|
|
/* LDT's and TASK_GATE's don't need it */
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
/* Base and limit sizes and shifts. */
|
|
|
|
#define BASE_HIGH_SHIFT 24 /* shift for base --> base_high */
|
|
|
|
#define BYTE_GRAN_MAX 0xFFFFFL /* maximum size for byte granular segment */
|
|
|
|
#define GRANULARITY_SHIFT 16 /* shift for limit --> granularity */
|
|
|
|
#define OFFSET_HIGH_SHIFT 16 /* shift for (gate) offset --> offset_high */
|
|
|
|
#define PAGE_GRAN_SHIFT 12 /* extra shift for page granular limits */
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Granularity byte. */
|
2005-09-11 18:44:06 +02:00
|
|
|
#define GRANULAR 0x80 /* set for 4K granularilty */
|
|
|
|
#define DEFAULT 0x40 /* set for 32-bit defaults (executable seg) */
|
|
|
|
#define BIG 0x40 /* set for "BIG" (expand-down seg) */
|
|
|
|
#define AVL 0x10 /* 0 for available */
|
|
|
|
#define LIMIT_HIGH 0x0F /* mask for high bits of limit */
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
|
|
|
|
/* Program stack words and masks. */
|
|
|
|
#define INIT_PSW 0x0200 /* initial psw */
|
|
|
|
#define INIT_TASK_PSW 0x1200 /* initial psw for tasks (with IOPL 1) */
|
|
|
|
#define TRACEBIT 0x0100 /* OR this with psw in proc[] for tracing */
|
|
|
|
#define SETPSW(rp, new) /* permits only certain bits to be set */ \
|
2011-07-18 19:44:17 +02:00
|
|
|
((rp)->p_reg.psw = ((rp)->p_reg.psw & ~0xCD5) | ((new) & 0xCD5))
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#define IF_MASK 0x00000200
|
|
|
|
#define IOPL_MASK 0x003000
|
|
|
|
|
2009-11-16 22:41:44 +01:00
|
|
|
#define INTEL_CPUID_GEN_EBX 0x756e6547 /* ASCII value of "Genu" */
|
|
|
|
#define INTEL_CPUID_GEN_EDX 0x49656e69 /* ASCII value of "ineI" */
|
|
|
|
#define INTEL_CPUID_GEN_ECX 0x6c65746e /* ASCII value of "ntel" */
|
|
|
|
|
|
|
|
#define AMD_CPUID_GEN_EBX 0x68747541 /* ASCII value of "Auth" */
|
|
|
|
#define AMD_CPUID_GEN_EDX 0x69746e65 /* ASCII value of "enti" */
|
|
|
|
#define AMD_CPUID_GEN_ECX 0x444d4163 /* ASCII value of "cAMD" */
|
|
|
|
|
2010-09-23 16:42:19 +02:00
|
|
|
#define CPU_VENDOR_INTEL 0
|
|
|
|
#define CPU_VENDOR_AMD 2
|
|
|
|
#define CPU_VENDOR_UNKNOWN 0xff
|
|
|
|
|
2009-12-02 14:01:48 +01:00
|
|
|
/* fpu context should be saved in 16-byte aligned memory */
|
|
|
|
#define FPUALIGN 16
|
2009-11-16 22:41:44 +01:00
|
|
|
|
2010-07-23 16:24:34 +02:00
|
|
|
/* Poweroff 16-bit code address */
|
|
|
|
#define BIOS_POWEROFF_ENTRY 0x1000
|
|
|
|
|
2010-09-15 16:09:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* defines how many bytes are reserved at the top of the kernel stack for global
|
|
|
|
* information like currently scheduled process or current cpu id
|
|
|
|
*/
|
|
|
|
#define X86_STACK_TOP_RESERVED (2 * sizeof(reg_t))
|
|
|
|
|
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 PG_ALLOCATEME ((phys_bytes)-1)
|
|
|
|
|
2012-06-10 19:50:17 +02:00
|
|
|
/* MSRs */
|
|
|
|
#define INTEL_MSR_PERFMON_CRT0 0xc1
|
|
|
|
#define INTEL_MSR_SYSENTER_CS 0x174
|
|
|
|
#define INTEL_MSR_SYSENTER_ESP 0x175
|
|
|
|
#define INTEL_MSR_SYSENTER_EIP 0x176
|
|
|
|
#define INTEL_MSR_PERFMON_SEL0 0x186
|
|
|
|
|
|
|
|
#define INTEL_MSR_PERFMON_SEL0_ENABLE (1 << 22)
|
|
|
|
|
|
|
|
#define AMD_EFER_SCE (1L << 0) /* SYSCALL/SYSRET enabled */
|
|
|
|
#define AMD_MSR_EFER 0xC0000080 /* extended features msr */
|
|
|
|
#define AMD_MSR_STAR 0xC0000081 /* SYSCALL params msr */
|
|
|
|
|
|
|
|
/* trap styles recorded on kernel entry and exit */
|
|
|
|
#define KTS_NONE 1 /* invalid */
|
|
|
|
#define KTS_INT_HARD 2 /* exception / hard interrupt */
|
|
|
|
#define KTS_INT_ORIG 3 /* soft interrupt from libc */
|
|
|
|
#define KTS_INT_UM 4 /* soft interrupt from usermapped code */
|
|
|
|
#define KTS_FULLCONTEXT 5 /* must restore full context */
|
|
|
|
#define KTS_SYSENTER 6 /* SYSENTER instruction (usermapped) */
|
|
|
|
#define KTS_SYSCALL 7 /* SYSCALL instruction (usermapped) */
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#endif /* _I386_ACONST_H */
|