2012-02-14 19:58:27 +01:00
|
|
|
/* This file is part of the lowest layer of the MINIX kernel. (The other part
|
2009-10-30 17:00:44 +01:00
|
|
|
* is "proc.c".) The lowest layer does process switching and message handling.
|
|
|
|
* Furthermore it contains the assembler startup code for Minix and the 32-bit
|
|
|
|
* interrupt handlers. It cooperates with the code in "start.c" to set up a
|
|
|
|
* good environment for main().
|
|
|
|
*
|
2010-05-18 15:00:39 +02:00
|
|
|
* Kernel is entered either because of kernel-calls, ipc-calls, interrupts or
|
2010-07-23 16:24:34 +02:00
|
|
|
* exceptions. TSS is set so that the kernel stack is loaded. The user context is
|
2010-05-18 15:00:39 +02:00
|
|
|
* saved to the proc table and the handler of the event is called. Once the
|
|
|
|
* handler is done, switch_to_user() function is called to pick a new process,
|
|
|
|
* finish what needs to be done for the next process to run, sets its context
|
|
|
|
* and switch to userspace.
|
2009-10-30 17:00:44 +01:00
|
|
|
*
|
|
|
|
* For communication with the boot monitor at startup time some constant
|
|
|
|
* data are compiled into the beginning of the text segment. This facilitates
|
|
|
|
* reading the data at the start of the boot process, since only the first
|
|
|
|
* sector of the file needs to be read.
|
|
|
|
*
|
|
|
|
* Some data storage is also allocated at the end of this file. This data
|
|
|
|
* will be at the start of the data segment of the kernel and will be read
|
|
|
|
* and modified by the boot monitor before the kernel starts.
|
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/kernel.h" /* configures the kernel */
|
2010-01-16 21:53:55 +01:00
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
/* sections */
|
|
|
|
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/vm.h>
|
2010-09-15 16:09:52 +02:00
|
|
|
#include "../../kernel.h"
|
2009-10-30 17:00:44 +01:00
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/com.h>
|
2010-08-17 18:44:07 +02:00
|
|
|
#include <machine/asm.h>
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/interrupt.h>
|
2010-03-09 10:41:14 +01:00
|
|
|
#include "archconst.h"
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/const.h"
|
|
|
|
#include "kernel/proc.h"
|
2009-10-30 17:00:44 +01:00
|
|
|
#include "sconst.h"
|
2011-06-24 17:20:25 +02:00
|
|
|
#include <machine/multiboot.h>
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-09-15 16:09:52 +02:00
|
|
|
#include "arch_proto.h" /* K_STACK_SIZE */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#include "kernel/smp.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Selected 386 tss offsets. */
|
|
|
|
#define TSS3_S_SP0 4
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
IMPORT(copr_not_available_handler)
|
|
|
|
IMPORT(params_size)
|
|
|
|
IMPORT(params_offset)
|
|
|
|
IMPORT(switch_to_user)
|
2011-05-04 18:51:43 +02:00
|
|
|
IMPORT(multiboot_init)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
|
|
|
.text
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* interrupt handlers */
|
|
|
|
/* interrupt handlers for 386 32-bit protected mode */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-06 10:08:26 +01:00
|
|
|
#define PIC_IRQ_HANDLER(irq) \
|
|
|
|
push $irq ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(irq_handle) /* intr_handle(irq_handlers[irq]) */ ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
add $4, %esp ;
|
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* hwint00 - 07 */
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Note this is a macro, it just looks like a subroutine. */
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
#define hwint_master(irq) \
|
|
|
|
TEST_INT_IN_KERNEL(4, 0f) ;\
|
|
|
|
\
|
|
|
|
SAVE_PROCESS_CTX(0) ;\
|
2010-02-10 16:36:54 +01:00
|
|
|
push %ebp ;\
|
2010-06-02 10:53:49 +02:00
|
|
|
movl $0, %ebp /* for stack trace */ ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop) ;\
|
2010-02-10 16:36:54 +01:00
|
|
|
add $4, %esp ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
PIC_IRQ_HANDLER(irq) ;\
|
|
|
|
movb $END_OF_INT, %al ;\
|
|
|
|
outb $INT_CTL /* reenable interrupts in master pic */ ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
jmp _C_LABEL(switch_to_user) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
\
|
|
|
|
0: \
|
|
|
|
pusha ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop_idle) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
PIC_IRQ_HANDLER(irq) ;\
|
|
|
|
movb $END_OF_INT, %al ;\
|
|
|
|
outb $INT_CTL /* reenable interrupts in master pic */ ;\
|
2010-03-23 14:35:01 +01:00
|
|
|
CLEAR_IF(10*4(%esp)) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
popa ;\
|
|
|
|
iret ;
|
2009-10-30 17:00:44 +01:00
|
|
|
|
|
|
|
/* Each of these entry points is an expansion of the hwint_master macro */
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint00)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 0 (the clock). */
|
|
|
|
hwint_master(0)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint01)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 1 (keyboard) */
|
|
|
|
hwint_master(1)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint02)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 2 (cascade!) */
|
|
|
|
hwint_master(2)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint03)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 3 (second serial) */
|
|
|
|
hwint_master(3)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint04)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 4 (first serial) */
|
|
|
|
hwint_master(4)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint05)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 5 (XT winchester) */
|
|
|
|
hwint_master(5)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint06)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 6 (floppy) */
|
|
|
|
hwint_master(6)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint07)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 7 (printer) */
|
|
|
|
hwint_master(7)
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* hwint08 - 15 */
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Note this is a macro, it just looks like a subroutine. */
|
|
|
|
#define hwint_slave(irq) \
|
2009-11-06 10:08:26 +01:00
|
|
|
TEST_INT_IN_KERNEL(4, 0f) ;\
|
|
|
|
\
|
|
|
|
SAVE_PROCESS_CTX(0) ;\
|
2010-02-10 16:36:54 +01:00
|
|
|
push %ebp ;\
|
2010-06-02 10:53:49 +02:00
|
|
|
movl $0, %ebp /* for stack trace */ ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop) ;\
|
2010-02-10 16:36:54 +01:00
|
|
|
add $4, %esp ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
PIC_IRQ_HANDLER(irq) ;\
|
|
|
|
movb $END_OF_INT, %al ;\
|
|
|
|
outb $INT_CTL /* reenable interrupts in master pic */ ;\
|
|
|
|
outb $INT2_CTL /* reenable slave 8259 */ ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
jmp _C_LABEL(switch_to_user) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
\
|
|
|
|
0: \
|
|
|
|
pusha ;\
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop_idle) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
PIC_IRQ_HANDLER(irq) ;\
|
|
|
|
movb $END_OF_INT, %al ;\
|
|
|
|
outb $INT_CTL /* reenable interrupts in master pic */ ;\
|
|
|
|
outb $INT2_CTL /* reenable slave 8259 */ ;\
|
2010-03-23 14:35:01 +01:00
|
|
|
CLEAR_IF(10*4(%esp)) ;\
|
2009-11-06 10:08:26 +01:00
|
|
|
popa ;\
|
|
|
|
iret ;
|
2009-10-30 17:00:44 +01:00
|
|
|
|
|
|
|
/* Each of these entry points is an expansion of the hwint_slave macro */
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint08)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 8 (realtime clock) */
|
|
|
|
hwint_slave(8)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint09)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 9 (irq 2 redirected) */
|
|
|
|
hwint_slave(9)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint10)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 10 */
|
|
|
|
hwint_slave(10)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint11)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 11 */
|
|
|
|
hwint_slave(11)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint12)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 12 */
|
|
|
|
hwint_slave(12)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint13)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 13 (FPU exception) */
|
|
|
|
hwint_slave(13)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint14)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 14 (AT winchester) */
|
|
|
|
hwint_slave(14)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(hwint15)
|
2009-10-30 17:00:44 +01:00
|
|
|
/* Interrupt routine for irq 15 */
|
|
|
|
hwint_slave(15)
|
|
|
|
|
|
|
|
/*
|
2010-02-09 16:20:09 +01:00
|
|
|
* IPC is only from a process to kernel
|
2009-10-30 17:00:44 +01:00
|
|
|
*/
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(ipc_entry)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2009-11-06 10:08:26 +01:00
|
|
|
SAVE_PROCESS_CTX(0)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2009-11-06 10:08:26 +01:00
|
|
|
/* save the pointer to the current process */
|
|
|
|
push %ebp
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pass the syscall arguments from userspace to the handler.
|
|
|
|
* SAVE_PROCESS_CTX() does not clobber these registers, they are still
|
|
|
|
* set as the userspace have set them
|
|
|
|
*/
|
|
|
|
push %ebx
|
|
|
|
push %eax
|
|
|
|
push %ecx
|
|
|
|
|
2010-02-10 16:36:54 +01:00
|
|
|
/* stop user process cycles */
|
|
|
|
push %ebp
|
2009-11-06 10:08:26 +01:00
|
|
|
/* for stack trace */
|
|
|
|
movl $0, %ebp
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop)
|
2010-06-02 10:53:49 +02:00
|
|
|
add $4, %esp
|
2009-11-06 10:08:26 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(do_ipc)
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
/* restore the current process pointer and save the return value */
|
2010-04-06 13:24:26 +02:00
|
|
|
add $3 * 4, %esp
|
2009-11-06 10:08:26 +01:00
|
|
|
pop %esi
|
|
|
|
mov %eax, AXREG(%esi)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
jmp _C_LABEL(switch_to_user)
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
|
2010-02-09 16:20:09 +01:00
|
|
|
/*
|
|
|
|
* kernel call is only from a process to kernel
|
|
|
|
*/
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(kernel_call_entry)
|
2010-02-09 16:20:09 +01:00
|
|
|
|
|
|
|
SAVE_PROCESS_CTX(0)
|
|
|
|
|
|
|
|
/* save the pointer to the current process */
|
|
|
|
push %ebp
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pass the syscall arguments from userspace to the handler.
|
|
|
|
* SAVE_PROCESS_CTX() does not clobber these registers, they are still
|
|
|
|
* set as the userspace have set them
|
|
|
|
*/
|
|
|
|
push %eax
|
|
|
|
|
2010-02-10 16:36:54 +01:00
|
|
|
/* stop user process cycles */
|
|
|
|
push %ebp
|
|
|
|
/* for stack trace */
|
|
|
|
movl $0, %ebp
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop)
|
2010-06-02 10:53:49 +02:00
|
|
|
add $4, %esp
|
2010-02-10 16:36:54 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(kernel_call)
|
2010-02-09 16:20:09 +01:00
|
|
|
|
|
|
|
/* restore the current process pointer and save the return value */
|
|
|
|
add $8, %esp
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
jmp _C_LABEL(switch_to_user)
|
2010-02-09 16:20:09 +01:00
|
|
|
|
|
|
|
|
2009-11-13 10:30:45 +01:00
|
|
|
.balign 16
|
2009-11-06 10:08:26 +01:00
|
|
|
/*
|
|
|
|
* called by the exception interrupt vectors. If the exception does not push
|
|
|
|
* errorcode, we assume that the vector handler pushed 0 instead. Next pushed
|
|
|
|
* thing is the vector number. From this point on we can continue as if every
|
|
|
|
* exception pushes an error code
|
|
|
|
*/
|
|
|
|
exception_entry:
|
|
|
|
/*
|
|
|
|
* check if it is a nested trap by comparing the saved code segment
|
|
|
|
* descriptor with the kernel CS first
|
|
|
|
*/
|
|
|
|
TEST_INT_IN_KERNEL(12, exception_entry_nested)
|
|
|
|
|
|
|
|
exception_entry_from_user:
|
|
|
|
SAVE_PROCESS_CTX(8)
|
|
|
|
|
2010-02-10 16:36:54 +01:00
|
|
|
/* stop user process cycles */
|
|
|
|
push %ebp
|
2009-11-06 10:08:26 +01:00
|
|
|
/* for stack trace clear %ebp */
|
|
|
|
movl $0, %ebp
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop)
|
2010-06-02 10:53:49 +02:00
|
|
|
add $4, %esp
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* push a pointer to the interrupt state pushed by the cpu and the
|
|
|
|
* vector number pushed by the vector handler just before calling
|
|
|
|
* exception_entry and call the exception handler.
|
|
|
|
*/
|
|
|
|
push %esp
|
|
|
|
push $0 /* it's not a nested exception */
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(exception_handler)
|
2009-11-06 10:08:26 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
jmp _C_LABEL(switch_to_user)
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
exception_entry_nested:
|
|
|
|
|
|
|
|
pusha
|
|
|
|
mov %esp, %eax
|
|
|
|
add $(8 * 4), %eax
|
|
|
|
push %eax
|
|
|
|
pushl $1 /* it's a nested exception */
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(exception_handler)
|
2009-11-06 10:08:26 +01:00
|
|
|
add $8, %esp
|
|
|
|
popa
|
|
|
|
|
|
|
|
/* clear the error code and the exception number */
|
|
|
|
add $8, %esp
|
|
|
|
/* resume execution at the point of exception */
|
|
|
|
iret
|
2009-10-30 17:00:44 +01:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* restart */
|
|
|
|
/*===========================================================================*/
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(restore_user_context)
|
2010-05-18 15:00:39 +02:00
|
|
|
mov 4(%esp), %ebp /* will assume P_STACKBASE == 0 */
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-01-16 21:53:55 +01:00
|
|
|
/* reconstruct the stack for iret */
|
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
|
|
|
push $USER_DS_SELECTOR /* ss */
|
2010-01-16 21:53:55 +01:00
|
|
|
movl SPREG(%ebp), %eax
|
|
|
|
push %eax
|
|
|
|
movl PSWREG(%ebp), %eax
|
|
|
|
push %eax
|
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
|
|
|
push $USER_CS_SELECTOR /* cs */
|
2010-01-16 21:53:55 +01:00
|
|
|
movl PCREG(%ebp), %eax
|
|
|
|
push %eax
|
|
|
|
|
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
|
|
|
/* Restore segments as the user should see them. */
|
|
|
|
movw $USER_DS_SELECTOR, %si
|
|
|
|
movw %si, %ds
|
|
|
|
movw %si, %es
|
|
|
|
movw %si, %fs
|
|
|
|
movw %si, %gs
|
2010-01-16 21:53:55 +01: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
|
|
|
/* Same for general-purpose registers. */
|
|
|
|
RESTORE_GP_REGS(%ebp)
|
2010-01-16 21:53:55 +01: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
|
|
|
movl BPREG(%ebp), %ebp
|
2010-01-16 21:53:55 +01:00
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
iret /* continue process */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* exception handlers */
|
|
|
|
/*===========================================================================*/
|
2009-11-06 10:08:26 +01:00
|
|
|
|
|
|
|
#define EXCEPTION_ERR_CODE(vector) \
|
|
|
|
push $vector ;\
|
|
|
|
jmp exception_entry
|
|
|
|
|
|
|
|
#define EXCEPTION_NO_ERR_CODE(vector) \
|
|
|
|
pushl $0 ;\
|
|
|
|
EXCEPTION_ERR_CODE(vector)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(divide_error)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(DIVIDE_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(single_step_exception)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(DEBUG_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(nmi)
|
2011-07-29 20:36:42 +02:00
|
|
|
#ifndef USE_WATCHDOG
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(NMI_VECTOR)
|
2010-01-16 21:53:55 +01:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* We have to be very careful as this interrupt can occur anytime. On
|
|
|
|
* the other hand, if it interrupts a user process, we will resume the
|
|
|
|
* same process which makes things a little simpler. We know that we are
|
|
|
|
* already on kernel stack whenever it happened and we can be
|
|
|
|
* conservative and save everything as we don't need to be extremely
|
|
|
|
* efficient as the interrupt is infrequent and some overhead is already
|
|
|
|
* expected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* save the important registers. We don't save %cs and %ss and they are
|
|
|
|
* saved and restored by CPU
|
|
|
|
*/
|
|
|
|
pushw %ds
|
|
|
|
pushw %es
|
|
|
|
pushw %fs
|
|
|
|
pushw %gs
|
|
|
|
pusha
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We cannot be sure about the state of the kernel segment register,
|
|
|
|
* however, we always set %ds and %es to the same as %ss
|
|
|
|
*/
|
|
|
|
mov %ss, %si
|
|
|
|
mov %si, %ds
|
|
|
|
mov %si, %es
|
|
|
|
|
|
|
|
push %esp
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(nmi_watchdog_handler)
|
2010-01-16 21:53:55 +01:00
|
|
|
add $4, %esp
|
|
|
|
|
|
|
|
/* restore all the important registers as they were before the trap */
|
|
|
|
popa
|
|
|
|
popw %gs
|
|
|
|
popw %fs
|
|
|
|
popw %es
|
|
|
|
popw %ds
|
|
|
|
|
|
|
|
iret
|
|
|
|
#endif
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(breakpoint_exception)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(BREAKPOINT_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(overflow)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(OVERFLOW_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(bounds_check)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(BOUNDS_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(inval_opcode)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(INVAL_OP_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(copr_not_available)
|
2009-12-02 14:01:48 +01:00
|
|
|
TEST_INT_IN_KERNEL(4, copr_not_available_in_kernel)
|
2010-06-03 13:32:22 +02:00
|
|
|
cld /* set direction flag to a known value */
|
2010-06-07 09:43:17 +02:00
|
|
|
SAVE_PROCESS_CTX(0)
|
2010-03-05 23:23:03 +01:00
|
|
|
/* stop user process cycles */
|
|
|
|
push %ebp
|
2010-06-03 13:32:22 +02:00
|
|
|
mov $0, %ebp
|
2010-08-17 18:44:07 +02:00
|
|
|
call _C_LABEL(context_stop)
|
2012-03-03 19:25:57 +01:00
|
|
|
call _C_LABEL(copr_not_available_handler)
|
|
|
|
/* reached upon failure only */
|
|
|
|
jmp _C_LABEL(switch_to_user)
|
2009-12-02 14:01:48 +01:00
|
|
|
|
|
|
|
copr_not_available_in_kernel:
|
2010-06-02 15:59:55 +02:00
|
|
|
pushl $0
|
|
|
|
pushl $COPROC_NOT_VECTOR
|
|
|
|
jmp exception_entry_nested
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(double_fault)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(DOUBLE_FAULT_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(copr_seg_overrun)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(COPROC_SEG_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(inval_tss)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(INVAL_TSS_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(segment_not_present)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(SEG_NOT_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(stack_exception)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(STACK_FAULT_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(general_protection)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(PROTECTION_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(page_fault)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_ERR_CODE(PAGE_FAULT_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(copr_error)
|
2009-11-06 10:08:26 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(COPROC_ERR_VECTOR)
|
2009-10-30 17:00:44 +01:00
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(alignment_check)
|
2009-12-02 14:01:48 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(ALIGNMENT_CHECK_VECTOR)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(machine_check)
|
2009-12-02 14:01:48 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(MACHINE_CHECK_VECTOR)
|
|
|
|
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(simd_exception)
|
2009-12-02 14:01:48 +01:00
|
|
|
EXCEPTION_NO_ERR_CODE(SIMD_EXCEPTION_VECTOR)
|
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* reload_cr3 */
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* PUBLIC void reload_cr3(void); */
|
2010-08-17 18:44:07 +02:00
|
|
|
ENTRY(reload_cr3)
|
2009-10-30 17:00:44 +01:00
|
|
|
push %ebp
|
|
|
|
mov %esp, %ebp
|
|
|
|
mov %cr3, %eax
|
|
|
|
mov %eax, %cr3
|
|
|
|
pop %ebp
|
|
|
|
ret
|
|
|
|
|
2010-09-15 16:09:52 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
ENTRY(startup_ap_32)
|
|
|
|
/*
|
|
|
|
* we are in protected mode now, %cs is correct and we need to set the
|
|
|
|
* data descriptors before we can touch anything
|
2012-07-13 00:54:27 +02:00
|
|
|
*
|
|
|
|
* first load the regular, highly mapped idt, gdt
|
2010-09-15 16:09:52 +02:00
|
|
|
*/
|
2012-07-13 00:54:27 +02:00
|
|
|
|
2010-09-15 16:09:52 +02:00
|
|
|
/*
|
|
|
|
* use the boot stack for now. The running CPUs are already using their
|
|
|
|
* own stack, the rest is still waiting to be booted
|
|
|
|
*/
|
2012-07-13 00:54:27 +02:00
|
|
|
movw $KERN_DS_SELECTOR, %ax
|
|
|
|
mov %ax, %ds
|
|
|
|
mov %ax, %ss
|
2010-09-15 16:09:52 +02:00
|
|
|
mov $_C_LABEL(k_boot_stktop) - 4, %esp
|
2012-07-13 00:54:27 +02:00
|
|
|
|
|
|
|
/* load the highly mapped idt, gdt, per-cpu tss */
|
|
|
|
call _C_LABEL(prot_load_selectors)
|
|
|
|
|
2010-09-15 16:09:52 +02:00
|
|
|
jmp _C_LABEL(smp_ap_boot)
|
|
|
|
hlt
|
|
|
|
#endif
|
|
|
|
|
2009-10-30 17:00:44 +01:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* data */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
.data
|
|
|
|
.short 0x526F /* this must be the first data entry (magic #) */
|
|
|
|
.bss
|
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
|
|
|
k_initial_stack:
|
|
|
|
.space K_STACK_SIZE
|
|
|
|
LABEL(__k_unpaged_k_initial_stktop)
|
|
|
|
|
2009-11-06 10:08:26 +01:00
|
|
|
/*
|
2010-03-18 17:18:22 +01:00
|
|
|
* the kernel stack
|
2009-11-06 10:08:26 +01:00
|
|
|
*/
|
2010-05-26 20:45:55 +02:00
|
|
|
k_boot_stack:
|
2010-09-15 16:09:52 +02:00
|
|
|
.space K_STACK_SIZE /* kernel stack */ /* FIXME use macro here */
|
2010-08-17 18:44:07 +02:00
|
|
|
LABEL(k_boot_stktop) /* top of kernel stack */
|
2010-09-15 16:09:52 +02:00
|
|
|
|
|
|
|
.balign K_STACK_SIZE
|
|
|
|
LABEL(k_stacks_start)
|
|
|
|
|
|
|
|
/* two pages for each stack, one for data, other as a sandbox */
|
2012-08-19 01:04:51 +02:00
|
|
|
.space 2 * (K_STACK_SIZE * CONFIG_MAX_CPUS)
|
2010-09-15 16:09:52 +02:00
|
|
|
|
|
|
|
LABEL(k_stacks_end)
|
|
|
|
|
|
|
|
/* top of kernel stack */
|