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
This commit is contained in:
Executable
+81
@@ -0,0 +1,81 @@
|
||||
# Makefile for kernel
|
||||
|
||||
include /etc/make.conf
|
||||
|
||||
ARCHAR=$(ARCH).a
|
||||
|
||||
# objects, excluding first-stage code, which is $(HEAD).
|
||||
# the HEAD variable is passed as an argument to this Makefile
|
||||
# by an upper level Makefile.
|
||||
|
||||
OBJS=$(ARCHAR)(exception.o) \
|
||||
$(ARCHAR)(i8259.o) \
|
||||
$(ARCHAR)(memory.o) \
|
||||
$(ARCHAR)(protect.o) \
|
||||
$(ARCHAR)(system.o) \
|
||||
$(ARCHAR)(clock.o) \
|
||||
$(ARCHAR)(klib386.o) \
|
||||
$(ARCHAR)(do_readbios.o) \
|
||||
$(ARCHAR)(do_int86.o) \
|
||||
$(ARCHAR)(do_sdevio.o) \
|
||||
$(ARCHAR)(do_iopenable.o)
|
||||
|
||||
CPPFLAGS=-Iinclude
|
||||
CFLAGS=$(CPPFLAGS) -Wall
|
||||
|
||||
build: $(HEAD) $(ARCHAR)
|
||||
|
||||
$(ARCHAR): $(OBJS)
|
||||
aal cr $@ *.o
|
||||
|
||||
depend:
|
||||
/usr/bin/mkdep "$(CC) -E $(CPPFLAGS)" *.c *.s > .depend
|
||||
|
||||
clean:
|
||||
rm -f *.a *.o *~
|
||||
|
||||
# How to build it
|
||||
$(ARCHAR)(exception.o): exception.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(i8259.o): i8259.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(memory.o): memory.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(protect.o): protect.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(system.o): system.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(do_int86.o): do_int86.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(do_iopenable.o): do_iopenable.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(do_readbios.o): do_readbios.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(do_sdevio.o): do_sdevio.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(clock.o): clock.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
$(ARCHAR)(klib386.o): klib386.s
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
.s.o:
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(HEAD): mpx386.o
|
||||
cp $< $@
|
||||
|
||||
# Include generated dependencies.
|
||||
include .depend
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
|
||||
/* i386-specific clock functions. */
|
||||
|
||||
#include <ibm/ports.h>
|
||||
#include <minix/portio.h>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
#define CLOCK_ACK_BIT 0x80 /* PS/2 clock interrupt acknowledge bit */
|
||||
|
||||
/* Clock parameters. */
|
||||
#define COUNTER_FREQ (2*TIMER_FREQ) /* counter frequency using square wave */
|
||||
#define LATCH_COUNT 0x00 /* cc00xxxx, c = channel, x = any */
|
||||
#define SQUARE_WAVE 0x36 /* ccaammmb, a = access, m = mode, b = BCD */
|
||||
/* 11x11, 11 = LSB then MSB, x11 = sq wave */
|
||||
#define TIMER_FREQ 1193182 /* clock frequency for timer in PC and AT */
|
||||
#define TIMER_COUNT (TIMER_FREQ/HZ) /* initial value for counter*/
|
||||
|
||||
/*===========================================================================*
|
||||
* arch_init_clock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int arch_init_clock(void)
|
||||
{
|
||||
/* Initialize channel 0 of the 8253A timer to, e.g., 60 Hz,
|
||||
* and register the CLOCK task's interrupt handler to be run
|
||||
* on every clock tick.
|
||||
*/
|
||||
outb(TIMER_MODE, SQUARE_WAVE); /* run continuously */
|
||||
outb(TIMER0, (TIMER_COUNT & 0xff)); /* timer low byte */
|
||||
outb(TIMER0, TIMER_COUNT >> 8); /* timer high byte */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* clock_stop *
|
||||
*===========================================================================*/
|
||||
PUBLIC void clock_stop(void)
|
||||
{
|
||||
/* Reset the clock to the BIOS rate. (For rebooting.) */
|
||||
outb(TIMER_MODE, 0x36);
|
||||
outb(TIMER0, 0);
|
||||
outb(TIMER0, 0);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* read_clock *
|
||||
*===========================================================================*/
|
||||
PUBLIC clock_t read_clock(void)
|
||||
{
|
||||
/* Read the counter of channel 0 of the 8253A timer. This counter
|
||||
* counts down at a rate of TIMER_FREQ and restarts at
|
||||
* TIMER_COUNT-1 when it reaches zero. A hardware interrupt
|
||||
* (clock tick) occurs when the counter gets to zero and restarts
|
||||
* its cycle.
|
||||
*/
|
||||
u32_t count;
|
||||
|
||||
outb(TIMER_MODE, LATCH_COUNT);
|
||||
count = inb(TIMER0);
|
||||
count |= (inb(TIMER0) << 8);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_INT86
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* m1_p1: INT86_REG86
|
||||
*/
|
||||
|
||||
#include "../../system.h"
|
||||
#include <minix/type.h>
|
||||
#include <minix/endpoint.h>
|
||||
#include <minix/portio.h>
|
||||
#include <ibm/int86.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
struct reg86u reg86;
|
||||
|
||||
/*===========================================================================*
|
||||
* do_int86 *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_int86(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
vir_bytes caller_vir;
|
||||
phys_bytes caller_phys, kernel_phys;
|
||||
|
||||
caller_vir = (vir_bytes) m_ptr->INT86_REG86;
|
||||
caller_phys = umap_local(proc_addr(who_p), D, caller_vir, sizeof(reg86));
|
||||
if (0 == caller_phys) return(EFAULT);
|
||||
kernel_phys = vir2phys(®86);
|
||||
phys_copy(caller_phys, kernel_phys, (phys_bytes) sizeof(reg86));
|
||||
|
||||
level0(int86);
|
||||
|
||||
/* Copy results back to the caller */
|
||||
phys_copy(kernel_phys, caller_phys, (phys_bytes) sizeof(reg86));
|
||||
|
||||
/* The BIOS call eats interrupts. Call get_randomness to generate some
|
||||
* entropy. Normally, get_randomness is called from an interrupt handler.
|
||||
* Figuring out the exact source is too complicated. CLOCK_IRQ is normally
|
||||
* not very random.
|
||||
*/
|
||||
lock(0, "do_int86");
|
||||
get_randomness(CLOCK_IRQ);
|
||||
unlock(0);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* The system call implemented in this file:
|
||||
* m_type: SYS_IOPENABLE
|
||||
*
|
||||
* The parameters for this system call are:
|
||||
* m2_i2: IO_ENDPT (process to give I/O Protection Level bits)
|
||||
*
|
||||
* Author:
|
||||
* Jorrit N. Herder <jnherder@cs.vu.nl>
|
||||
*/
|
||||
|
||||
#include "../../system.h"
|
||||
#include "../../kernel.h"
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
/*===========================================================================*
|
||||
* do_iopenable *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_iopenable(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr;
|
||||
|
||||
#if 1 /* ENABLE_USERPRIV && ENABLE_USERIOPL */
|
||||
if (m_ptr->IO_ENDPT == SELF) {
|
||||
proc_nr = who_p;
|
||||
} else if(!isokendpt(m_ptr->IO_ENDPT, &proc_nr))
|
||||
return(EINVAL);
|
||||
enable_iop(proc_addr(proc_nr));
|
||||
return(OK);
|
||||
#else
|
||||
return(EPERM);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_READBIOS
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* m2_i1: RDB_SIZE number of bytes to copy
|
||||
* m2_l1: RDB_ADDR absolute address in BIOS area
|
||||
* m2_p1: RDB_BUF buffer address in requesting process
|
||||
*/
|
||||
|
||||
#include "../../system.h"
|
||||
#include <minix/type.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* do_readbios *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_readbios(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr;
|
||||
struct proc *p;
|
||||
phys_bytes address, phys_buf, phys_bios;
|
||||
vir_bytes buf;
|
||||
size_t size;
|
||||
|
||||
address = m_ptr->RDB_ADDR;
|
||||
buf = (vir_bytes)m_ptr->RDB_BUF;
|
||||
size = m_ptr->RDB_SIZE;
|
||||
|
||||
okendpt(m_ptr->m_source, &proc_nr);
|
||||
p = proc_addr(proc_nr);
|
||||
phys_buf = umap_local(p, D, buf, size);
|
||||
if (phys_buf == 0)
|
||||
return EFAULT;
|
||||
phys_bios = umap_bios(p, address, size);
|
||||
if (phys_bios == 0)
|
||||
return EPERM;
|
||||
phys_copy(phys_bios, phys_buf, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_SDEVIO
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* m2_i3: DIO_REQUEST (request input or output)
|
||||
* m2_i1: DIO_TYPE (flag indicating byte, word, or long)
|
||||
* m2_l1: DIO_PORT (port to read/ write)
|
||||
* m2_p1: DIO_VEC_ADDR (virtual address of buffer)
|
||||
* m2_l2: DIO_VEC_SIZE (number of elements)
|
||||
* m2_i2: DIO_VEC_PROC (process where buffer is)
|
||||
*/
|
||||
|
||||
#include "../../system.h"
|
||||
#include <minix/devio.h>
|
||||
#include <minix/endpoint.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
#if USE_SDEVIO
|
||||
|
||||
/*===========================================================================*
|
||||
* do_sdevio *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_sdevio(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr, proc_nr_e = m_ptr->DIO_VEC_ENDPT;
|
||||
int count = m_ptr->DIO_VEC_SIZE;
|
||||
long port = m_ptr->DIO_PORT;
|
||||
phys_bytes phys_buf;
|
||||
int i, req_type, req_dir, io_type, size, nr_io_range;
|
||||
struct proc *rp;
|
||||
struct priv *privp;
|
||||
struct io_range *iorp;
|
||||
|
||||
/* Allow safe copies and accesses to SELF */
|
||||
if ((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) != _DIO_SAFE &&
|
||||
proc_nr_e != SELF)
|
||||
{
|
||||
static int first= 1;
|
||||
if (first)
|
||||
{
|
||||
first= 0;
|
||||
kprintf("do_sdevio: for %d, req %d\n",
|
||||
m_ptr->m_source, m_ptr->DIO_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if process endpoint is OK.
|
||||
* A driver may directly provide a pointer to a buffer at the user-process
|
||||
* that initiated the device I/O. Kernel processes, of course, are denied.
|
||||
*/
|
||||
if (proc_nr_e == SELF)
|
||||
proc_nr = who_p;
|
||||
else
|
||||
if(!isokendpt(proc_nr_e, &proc_nr))
|
||||
return(EINVAL);
|
||||
if (iskerneln(proc_nr)) return(EPERM);
|
||||
|
||||
/* Extract direction (in or out) and type (size). */
|
||||
req_dir = m_ptr->DIO_REQUEST & _DIO_DIRMASK;
|
||||
req_type = m_ptr->DIO_REQUEST & _DIO_TYPEMASK;
|
||||
|
||||
/* Check for 'safe' variants. */
|
||||
if((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) == _DIO_SAFE) {
|
||||
/* Map grant address to physical address. */
|
||||
if ((phys_buf = umap_verify_grant(proc_addr(proc_nr), who_e,
|
||||
(vir_bytes) m_ptr->DIO_VEC_ADDR,
|
||||
(vir_bytes) m_ptr->DIO_OFFSET, count,
|
||||
req_dir == _DIO_INPUT ? CPF_WRITE : CPF_READ)) == 0)
|
||||
return(EPERM);
|
||||
} else {
|
||||
if(proc_nr != who_p)
|
||||
kprintf("unsafe sdevio by %d in %d\n", who_e, proc_nr_e);
|
||||
/* Get and check physical address. */
|
||||
if ((phys_buf = numap_local(proc_nr,
|
||||
(vir_bytes) m_ptr->DIO_VEC_ADDR, count)) == 0)
|
||||
return(EFAULT);
|
||||
}
|
||||
|
||||
rp= proc_addr(who_p);
|
||||
if (privp && privp->s_flags & CHECK_IO_PORT)
|
||||
{
|
||||
switch (io_type)
|
||||
{
|
||||
case _DIO_BYTE: size= 1; break;
|
||||
case _DIO_WORD: size= 2; break;
|
||||
case _DIO_LONG: size= 4; break;
|
||||
default: size= 4; break; /* Be conservative */
|
||||
}
|
||||
port= m_ptr->DIO_PORT;
|
||||
nr_io_range= privp->s_nr_io_range;
|
||||
for (i= 0, iorp= privp->s_io_tab; i<nr_io_range; i++, iorp++)
|
||||
{
|
||||
if (port >= iorp->ior_base && port+size-1 <= iorp->ior_limit)
|
||||
break;
|
||||
}
|
||||
if (i >= nr_io_range)
|
||||
{
|
||||
kprintf(
|
||||
"do_sdevio: I/O port check failed for proc %d, port 0x%x\n",
|
||||
m_ptr->m_source, port);
|
||||
return EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform device I/O for bytes and words. Longs are not supported. */
|
||||
if (req_dir == _DIO_INPUT) {
|
||||
switch (req_type) {
|
||||
case _DIO_BYTE: phys_insb(port, phys_buf, count); break;
|
||||
case _DIO_WORD: phys_insw(port, phys_buf, count); break;
|
||||
default: return(EINVAL);
|
||||
}
|
||||
} else if (req_dir == _DIO_OUTPUT) {
|
||||
switch (req_type) {
|
||||
case _DIO_BYTE: phys_outsb(port, phys_buf, count); break;
|
||||
case _DIO_WORD: phys_outsw(port, phys_buf, count); break;
|
||||
default: return(EINVAL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return(EINVAL);
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
#endif /* USE_SDEVIO */
|
||||
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
/* This file contains a simple exception handler. Exceptions in user
|
||||
* processes are converted to signals. Exceptions in a kernel task cause
|
||||
* a panic.
|
||||
*/
|
||||
|
||||
#include "../../kernel.h"
|
||||
#include <signal.h>
|
||||
#include "../../proc.h"
|
||||
|
||||
/*===========================================================================*
|
||||
* exception *
|
||||
*===========================================================================*/
|
||||
PUBLIC void exception(unsigned vec_nr)
|
||||
{
|
||||
/* An exception or unexpected interrupt has occurred. */
|
||||
|
||||
struct ex_s {
|
||||
char *msg;
|
||||
int signum;
|
||||
int minprocessor;
|
||||
};
|
||||
static struct ex_s ex_data[] = {
|
||||
{ "Divide error", SIGFPE, 86 },
|
||||
{ "Debug exception", SIGTRAP, 86 },
|
||||
{ "Nonmaskable interrupt", SIGBUS, 86 },
|
||||
{ "Breakpoint", SIGEMT, 86 },
|
||||
{ "Overflow", SIGFPE, 86 },
|
||||
{ "Bounds check", SIGFPE, 186 },
|
||||
{ "Invalid opcode", SIGILL, 186 },
|
||||
{ "Coprocessor not available", SIGFPE, 186 },
|
||||
{ "Double fault", SIGBUS, 286 },
|
||||
{ "Copressor segment overrun", SIGSEGV, 286 },
|
||||
{ "Invalid TSS", SIGSEGV, 286 },
|
||||
{ "Segment not present", SIGSEGV, 286 },
|
||||
{ "Stack exception", SIGSEGV, 286 }, /* STACK_FAULT already used */
|
||||
{ "General protection", SIGSEGV, 286 },
|
||||
{ "Page fault", SIGSEGV, 386 }, /* not close */
|
||||
{ NIL_PTR, SIGILL, 0 }, /* probably software trap */
|
||||
{ "Coprocessor error", SIGFPE, 386 },
|
||||
};
|
||||
register struct ex_s *ep;
|
||||
struct proc *saved_proc;
|
||||
|
||||
/* Save proc_ptr, because it may be changed by debug statements. */
|
||||
saved_proc = proc_ptr;
|
||||
|
||||
ep = &ex_data[vec_nr];
|
||||
|
||||
if (vec_nr == 2) { /* spurious NMI on some machines */
|
||||
kprintf("got spurious NMI\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* If an exception occurs while running a process, the k_reenter variable
|
||||
* will be zero. Exceptions in interrupt handlers or system traps will make
|
||||
* k_reenter larger than zero.
|
||||
*/
|
||||
if (k_reenter == 0 && ! iskernelp(saved_proc)) {
|
||||
#if 0
|
||||
{
|
||||
kprintf(
|
||||
"exception for process %d, pc = 0x%x:0x%x, sp = 0x%x:0x%x\n",
|
||||
proc_nr(saved_proc),
|
||||
saved_proc->p_reg.cs, saved_proc->p_reg.pc,
|
||||
saved_proc->p_reg.ss, saved_proc->p_reg.sp);
|
||||
kprintf("edi = 0x%x\n", saved_proc->p_reg.di);
|
||||
|
||||
#if DEBUG_STACKTRACE
|
||||
stacktrace(saved_proc);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
cause_sig(proc_nr(saved_proc), ep->signum);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Exception in system code. This is not supposed to happen. */
|
||||
if (ep->msg == NIL_PTR || machine.processor < ep->minprocessor)
|
||||
kprintf("\nIntel-reserved exception %d\n", vec_nr);
|
||||
else
|
||||
kprintf("\n%s\n", ep->msg);
|
||||
kprintf("k_reenter = %d ", k_reenter);
|
||||
kprintf("process %d (%s), ", proc_nr(saved_proc), saved_proc->p_name);
|
||||
kprintf("pc = %u:0x%x", (unsigned) saved_proc->p_reg.cs,
|
||||
(unsigned) saved_proc->p_reg.pc);
|
||||
|
||||
panic("exception in a kernel task", NO_NUM);
|
||||
}
|
||||
|
||||
#if DEBUG_STACKTRACE
|
||||
/*===========================================================================*
|
||||
* stacktrace *
|
||||
*===========================================================================*/
|
||||
PUBLIC void stacktrace(struct proc *proc)
|
||||
{
|
||||
reg_t bp, v_bp, v_pc, v_hbp;
|
||||
|
||||
v_bp = proc->p_reg.fp;
|
||||
|
||||
kprintf("stacktrace: ");
|
||||
while(v_bp) {
|
||||
phys_bytes p;
|
||||
if(!(p = umap_local(proc, D, v_bp, sizeof(v_bp)))) {
|
||||
kprintf("(bad bp %lx)", v_bp);
|
||||
break;
|
||||
}
|
||||
phys_copy(p+sizeof(v_pc), vir2phys(&v_pc), sizeof(v_pc));
|
||||
phys_copy(p, vir2phys(&v_hbp), sizeof(v_hbp));
|
||||
kprintf("0x%lx ", (unsigned long) v_pc);
|
||||
if(v_hbp != 0 && v_hbp <= v_bp) {
|
||||
kprintf("(bad hbp %lx)", v_hbp);
|
||||
break;
|
||||
}
|
||||
v_bp = v_hbp;
|
||||
}
|
||||
kprintf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
/* This file contains routines for initializing the 8259 interrupt controller:
|
||||
* put_irq_handler: register an interrupt handler
|
||||
* rm_irq_handler: deregister an interrupt handler
|
||||
* intr_handle: handle a hardware interrupt
|
||||
* intr_init: initialize the interrupt controller(s)
|
||||
*/
|
||||
|
||||
#include "../../kernel.h"
|
||||
#include "../../proc.h"
|
||||
#include "proto.h"
|
||||
#include <minix/com.h>
|
||||
#include <minix/portio.h>
|
||||
#include <ibm/cpu.h>
|
||||
|
||||
#define ICW1_AT 0x11 /* edge triggered, cascade, need ICW4 */
|
||||
#define ICW1_PC 0x13 /* edge triggered, no cascade, need ICW4 */
|
||||
#define ICW1_PS 0x19 /* level triggered, cascade, need ICW4 */
|
||||
#define ICW4_AT_SLAVE 0x01 /* not SFNM, not buffered, normal EOI, 8086 */
|
||||
#define ICW4_AT_MASTER 0x05 /* not SFNM, not buffered, normal EOI, 8086 */
|
||||
#define ICW4_PC_SLAVE 0x09 /* not SFNM, buffered, normal EOI, 8086 */
|
||||
#define ICW4_PC_MASTER 0x0D /* not SFNM, buffered, normal EOI, 8086 */
|
||||
|
||||
#define set_vec(nr, addr) ((void)0)
|
||||
|
||||
/*===========================================================================*
|
||||
* intr_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int intr_init(mine)
|
||||
int mine;
|
||||
{
|
||||
/* Initialize the 8259s, finishing with all interrupts disabled. This is
|
||||
* only done in protected mode, in real mode we don't touch the 8259s, but
|
||||
* use the BIOS locations instead. The flag "mine" is set if the 8259s are
|
||||
* to be programmed for MINIX, or to be reset to what the BIOS expects.
|
||||
*/
|
||||
int i;
|
||||
|
||||
intr_disable();
|
||||
|
||||
/* The AT and newer PS/2 have two interrupt controllers, one master,
|
||||
* one slaved at IRQ 2. (We don't have to deal with the PC that
|
||||
* has just one controller, because it must run in real mode.)
|
||||
*/
|
||||
outb( INT_CTL, machine.ps_mca ? ICW1_PS : ICW1_AT);
|
||||
outb( INT_CTLMASK, mine ? IRQ0_VECTOR : BIOS_IRQ0_VEC);
|
||||
/* ICW2 for master */
|
||||
outb( INT_CTLMASK, (1 << CASCADE_IRQ));
|
||||
/* ICW3 tells slaves */
|
||||
outb( INT_CTLMASK, ICW4_AT_MASTER);
|
||||
outb( INT_CTLMASK, ~(1 << CASCADE_IRQ)); /* IRQ 0-7 mask */
|
||||
outb( INT2_CTL, machine.ps_mca ? ICW1_PS : ICW1_AT);
|
||||
outb( INT2_CTLMASK, mine ? IRQ8_VECTOR : BIOS_IRQ8_VEC);
|
||||
/* ICW2 for slave */
|
||||
outb( INT2_CTLMASK, CASCADE_IRQ); /* ICW3 is slave nr */
|
||||
outb( INT2_CTLMASK, ICW4_AT_SLAVE);
|
||||
outb( INT2_CTLMASK, ~0); /* IRQ 8-15 mask */
|
||||
|
||||
/* Copy the BIOS vectors from the BIOS to the Minix location, so we
|
||||
* can still make BIOS calls without reprogramming the i8259s.
|
||||
*/
|
||||
#if IRQ0_VECTOR != BIOS_IRQ0_VEC
|
||||
phys_copy(BIOS_VECTOR(0) * 4L, VECTOR(0) * 4L, 8 * 4L);
|
||||
#endif
|
||||
#if IRQ8_VECTOR != BIOS_IRQ8_VEC
|
||||
phys_copy(BIOS_VECTOR(8) * 4L, VECTOR(8) * 4L, 8 * 4L);
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* intr_disabled *
|
||||
*===========================================================================*/
|
||||
PUBLIC int intr_disabled(void)
|
||||
{
|
||||
if(!(read_cpu_flags() & X86_FLAG_I))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
|
||||
#ifndef _I386_ACONST_H
|
||||
#define _I386_ACONST_H 1
|
||||
|
||||
#include <ibm/interrupt.h>
|
||||
#include <ibm/memory.h>
|
||||
|
||||
#define NR_REMOTE_SEGS 3 /* # remote memory regions (variable) */
|
||||
|
||||
/* Constants for protected mode. */
|
||||
|
||||
/* Table sizes. */
|
||||
#define GDT_SIZE (FIRST_LDT_INDEX + NR_TASKS + NR_PROCS)
|
||||
/* spec. and LDT's */
|
||||
#define IDT_SIZE (IRQ8_VECTOR + 8) /* only up to the highest vector */
|
||||
|
||||
/* Fixed global descriptors. 1 to 7 are prescribed by the BIOS. */
|
||||
#define GDT_INDEX 1 /* GDT descriptor */
|
||||
#define IDT_INDEX 2 /* IDT descriptor */
|
||||
#define DS_INDEX 3 /* kernel DS */
|
||||
#define ES_INDEX 4 /* kernel ES (386: flag 4 Gb at startup) */
|
||||
#define SS_INDEX 5 /* kernel SS (386: monitor SS at startup) */
|
||||
#define CS_INDEX 6 /* kernel CS */
|
||||
#define MON_CS_INDEX 7 /* temp for BIOS (386: monitor CS at startup) */
|
||||
#define TSS_INDEX 8 /* kernel TSS */
|
||||
#define DS_286_INDEX 9 /* scratch 16-bit source segment */
|
||||
#define ES_286_INDEX 10 /* scratch 16-bit destination segment */
|
||||
#define A_INDEX 11 /* 64K memory segment at A0000 */
|
||||
#define B_INDEX 12 /* 64K memory segment at B0000 */
|
||||
#define C_INDEX 13 /* 64K memory segment at C0000 */
|
||||
#define D_INDEX 14 /* 64K memory segment at D0000 */
|
||||
#define FIRST_LDT_INDEX 15 /* rest of descriptors are LDT's */
|
||||
|
||||
#define GDT_SELECTOR 0x08 /* (GDT_INDEX * DESC_SIZE) bad for asld */
|
||||
#define IDT_SELECTOR 0x10 /* (IDT_INDEX * DESC_SIZE) */
|
||||
#define DS_SELECTOR 0x18 /* (DS_INDEX * DESC_SIZE) */
|
||||
#define ES_SELECTOR 0x20 /* (ES_INDEX * DESC_SIZE) */
|
||||
#define FLAT_DS_SELECTOR 0x21 /* less privileged ES */
|
||||
#define SS_SELECTOR 0x28 /* (SS_INDEX * DESC_SIZE) */
|
||||
#define CS_SELECTOR 0x30 /* (CS_INDEX * DESC_SIZE) */
|
||||
#define MON_CS_SELECTOR 0x38 /* (MON_CS_INDEX * DESC_SIZE) */
|
||||
#define TSS_SELECTOR 0x40 /* (TSS_INDEX * DESC_SIZE) */
|
||||
#define DS_286_SELECTOR 0x49 /* (DS_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
|
||||
#define ES_286_SELECTOR 0x51 /* (ES_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
|
||||
|
||||
/* Privileges. */
|
||||
#define INTR_PRIVILEGE 0 /* kernel and interrupt handlers */
|
||||
#define TASK_PRIVILEGE 1 /* kernel tasks */
|
||||
#define USER_PRIVILEGE 3 /* servers and user processes */
|
||||
|
||||
/* 286 hardware constants. */
|
||||
|
||||
/* Exception vector numbers. */
|
||||
#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 */
|
||||
|
||||
/* Selector bits. */
|
||||
#define TI 0x04 /* table indicator */
|
||||
#define RPL 0x03 /* requester privilege level */
|
||||
|
||||
/* Descriptor structure offsets. */
|
||||
#define DESC_BASE 2 /* to base_low */
|
||||
#define DESC_BASE_MIDDLE 4 /* to base_middle */
|
||||
#define DESC_ACCESS 5 /* to access byte */
|
||||
#define DESC_SIZE 8 /* sizeof (struct segdesc_s) */
|
||||
|
||||
/* Base and limit sizes and shifts. */
|
||||
#define BASE_MIDDLE_SHIFT 16 /* shift for base --> base_middle */
|
||||
|
||||
/* Access-byte and type-byte bits. */
|
||||
#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 */
|
||||
|
||||
/* Access-byte bits. */
|
||||
#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 */
|
||||
|
||||
/* Special descriptor types. */
|
||||
#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 */
|
||||
|
||||
/* Extra 386 hardware constants. */
|
||||
|
||||
/* Exception vector numbers. */
|
||||
#define PAGE_FAULT_VECTOR 14
|
||||
#define COPROC_ERR_VECTOR 16 /* coprocessor error */
|
||||
|
||||
/* Descriptor structure offsets. */
|
||||
#define DESC_GRANULARITY 6 /* to granularity byte */
|
||||
#define DESC_BASE_HIGH 7 /* to base_high */
|
||||
|
||||
/* Type-byte bits. */
|
||||
#define DESC_386_BIT 0x08 /* 386 types are obtained by ORing with this */
|
||||
/* LDT's and TASK_GATE's don't need it */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* Granularity byte. */
|
||||
#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 */
|
||||
|
||||
/* 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 */ \
|
||||
((rp)->p_reg.psw = (rp)->p_reg.psw & ~0xCD5 | (new) & 0xCD5)
|
||||
#define IF_MASK 0x00000200
|
||||
#define IOPL_MASK 0x003000
|
||||
|
||||
/* Sizes of memory tables. The boot monitor distinguishes three memory areas,
|
||||
* namely low mem below 1M, 1M-16M, and mem after 16M. More chunks are needed
|
||||
* for DOS MINIX.
|
||||
*/
|
||||
#define NR_MEMS 8
|
||||
|
||||
#define vir2phys(vir) (kinfo.data_base + (vir_bytes) (vir))
|
||||
|
||||
#endif /* _I386_ACONST_H */
|
||||
@@ -0,0 +1,62 @@
|
||||
|
||||
#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 */
|
||||
struct segdesc_s p_ldt[2+NR_REMOTE_SEGS]; /* CS, DS and remote */
|
||||
} segframe_t;
|
||||
|
||||
#endif /* #ifndef _I386_TYPES_H */
|
||||
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
/* Constants for protected mode. */
|
||||
|
||||
/* Table sizes. */
|
||||
#define GDT_SIZE (FIRST_LDT_INDEX + NR_TASKS + NR_PROCS)
|
||||
/* spec. and LDT's */
|
||||
#define IDT_SIZE (IRQ8_VECTOR + 8) /* only up to the highest vector */
|
||||
#define LDT_SIZE (2 + NR_REMOTE_SEGS) /* CS, DS and remote segments */
|
||||
|
||||
/* Fixed global descriptors. 1 to 7 are prescribed by the BIOS. */
|
||||
#define GDT_INDEX 1 /* GDT descriptor */
|
||||
#define IDT_INDEX 2 /* IDT descriptor */
|
||||
#define DS_INDEX 3 /* kernel DS */
|
||||
#define ES_INDEX 4 /* kernel ES (386: flag 4 Gb at startup) */
|
||||
#define SS_INDEX 5 /* kernel SS (386: monitor SS at startup) */
|
||||
#define CS_INDEX 6 /* kernel CS */
|
||||
#define MON_CS_INDEX 7 /* temp for BIOS (386: monitor CS at startup) */
|
||||
#define TSS_INDEX 8 /* kernel TSS */
|
||||
#define DS_286_INDEX 9 /* scratch 16-bit source segment */
|
||||
#define ES_286_INDEX 10 /* scratch 16-bit destination segment */
|
||||
#define A_INDEX 11 /* 64K memory segment at A0000 */
|
||||
#define B_INDEX 12 /* 64K memory segment at B0000 */
|
||||
#define C_INDEX 13 /* 64K memory segment at C0000 */
|
||||
#define D_INDEX 14 /* 64K memory segment at D0000 */
|
||||
#define FIRST_LDT_INDEX 15 /* rest of descriptors are LDT's */
|
||||
|
||||
#define GDT_SELECTOR 0x08 /* (GDT_INDEX * DESC_SIZE) bad for asld */
|
||||
#define IDT_SELECTOR 0x10 /* (IDT_INDEX * DESC_SIZE) */
|
||||
#define DS_SELECTOR 0x18 /* (DS_INDEX * DESC_SIZE) */
|
||||
#define ES_SELECTOR 0x20 /* (ES_INDEX * DESC_SIZE) */
|
||||
#define FLAT_DS_SELECTOR 0x21 /* less privileged ES */
|
||||
#define SS_SELECTOR 0x28 /* (SS_INDEX * DESC_SIZE) */
|
||||
#define CS_SELECTOR 0x30 /* (CS_INDEX * DESC_SIZE) */
|
||||
#define MON_CS_SELECTOR 0x38 /* (MON_CS_INDEX * DESC_SIZE) */
|
||||
#define TSS_SELECTOR 0x40 /* (TSS_INDEX * DESC_SIZE) */
|
||||
#define DS_286_SELECTOR 0x49 /* (DS_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
|
||||
#define ES_286_SELECTOR 0x51 /* (ES_286_INDEX*DESC_SIZE+TASK_PRIVILEGE) */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* Privileges. */
|
||||
#define INTR_PRIVILEGE 0 /* kernel and interrupt handlers */
|
||||
#define TASK_PRIVILEGE 1 /* kernel tasks */
|
||||
#define USER_PRIVILEGE 3 /* servers and user processes */
|
||||
|
||||
/* 286 hardware constants. */
|
||||
|
||||
/* Exception vector numbers. */
|
||||
#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 */
|
||||
|
||||
/* Selector bits. */
|
||||
#define TI 0x04 /* table indicator */
|
||||
#define RPL 0x03 /* requester privilege level */
|
||||
|
||||
/* Descriptor structure offsets. */
|
||||
#define DESC_BASE 2 /* to base_low */
|
||||
#define DESC_BASE_MIDDLE 4 /* to base_middle */
|
||||
#define DESC_ACCESS 5 /* to access byte */
|
||||
#define DESC_SIZE 8 /* sizeof (struct segdesc_s) */
|
||||
|
||||
/* Base and limit sizes and shifts. */
|
||||
#define BASE_MIDDLE_SHIFT 16 /* shift for base --> base_middle */
|
||||
|
||||
/* Access-byte and type-byte bits. */
|
||||
#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 */
|
||||
|
||||
/* Access-byte bits. */
|
||||
#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 */
|
||||
|
||||
/* Special descriptor types. */
|
||||
#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 */
|
||||
|
||||
/* Extra 386 hardware constants. */
|
||||
|
||||
/* Exception vector numbers. */
|
||||
#define PAGE_FAULT_VECTOR 14
|
||||
#define COPROC_ERR_VECTOR 16 /* coprocessor error */
|
||||
|
||||
/* Descriptor structure offsets. */
|
||||
#define DESC_GRANULARITY 6 /* to granularity byte */
|
||||
#define DESC_BASE_HIGH 7 /* to base_high */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* Type-byte bits. */
|
||||
#define DESC_386_BIT 0x08 /* 386 types are obtained by ORing with this */
|
||||
/* LDT's and TASK_GATE's don't need it */
|
||||
|
||||
/* Granularity byte. */
|
||||
#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 */
|
||||
Executable
+616
@@ -0,0 +1,616 @@
|
||||
#
|
||||
! sections
|
||||
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
|
||||
#include <minix/config.h>
|
||||
#include <minix/const.h>
|
||||
#include <ibm/interrupt.h>
|
||||
#include <archconst.h>
|
||||
#include "../../const.h"
|
||||
#include "sconst.h"
|
||||
|
||||
! This file contains a number of assembly code utility routines needed by the
|
||||
! kernel. They are:
|
||||
|
||||
.define _monitor ! exit Minix and return to the monitor
|
||||
.define _int86 ! let the monitor make an 8086 interrupt call
|
||||
.define _cp_mess ! copies messages from source to destination
|
||||
.define _exit ! dummy for library routines
|
||||
.define __exit ! dummy for library routines
|
||||
.define ___exit ! dummy for library routines
|
||||
.define ___main ! dummy for GCC
|
||||
.define _phys_insw ! transfer data from (disk controller) port to memory
|
||||
.define _phys_insb ! likewise byte by byte
|
||||
.define _phys_outsw ! transfer data from memory to (disk controller) port
|
||||
.define _phys_outsb ! likewise byte by byte
|
||||
.define _intr_unmask ! enable an irq at the 8259 controller
|
||||
.define _intr_mask ! disable an irq
|
||||
.define _phys_copy ! copy data from anywhere to anywhere in memory
|
||||
.define _phys_memset ! write pattern anywhere in memory
|
||||
.define _mem_rdw ! copy one word from [segment:offset]
|
||||
.define _reset ! reset the system
|
||||
.define _idle_task ! task executed when there is no work
|
||||
.define _level0 ! call a function at level 0
|
||||
.define _read_tsc ! read the cycle counter (Pentium and up)
|
||||
.define _read_cpu_flags ! read the cpu flags
|
||||
.define _read_cr0 ! read cr0
|
||||
.define _write_cr0 ! write a value in cr0
|
||||
.define _write_cr3 ! write a value in cr3 (root of the page table)
|
||||
|
||||
! The routines only guarantee to preserve the registers the C compiler
|
||||
! expects to be preserved (ebx, esi, edi, ebp, esp, segment registers, and
|
||||
! direction bit in the flags).
|
||||
|
||||
.sect .text
|
||||
!*===========================================================================*
|
||||
!* monitor *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void monitor();
|
||||
! Return to the monitor.
|
||||
|
||||
_monitor:
|
||||
mov esp, (_mon_sp) ! restore monitor stack pointer
|
||||
o16 mov dx, SS_SELECTOR ! monitor data segment
|
||||
mov ds, dx
|
||||
mov es, dx
|
||||
mov fs, dx
|
||||
mov gs, dx
|
||||
mov ss, dx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
o16 retf ! return to the monitor
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* int86 *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void int86();
|
||||
_int86:
|
||||
cmpb (_mon_return), 0 ! is the monitor there?
|
||||
jnz 0f
|
||||
movb ah, 0x01 ! an int 13 error seems appropriate
|
||||
movb (_reg86+ 0), ah ! reg86.w.f = 1 (set carry flag)
|
||||
movb (_reg86+13), ah ! reg86.b.ah = 0x01 = "invalid command"
|
||||
ret
|
||||
0: push ebp ! save C registers
|
||||
push esi
|
||||
push edi
|
||||
push ebx
|
||||
pushf ! save flags
|
||||
cli ! no interruptions
|
||||
|
||||
inb INT2_CTLMASK
|
||||
movb ah, al
|
||||
inb INT_CTLMASK
|
||||
push eax ! save interrupt masks
|
||||
mov eax, (_irq_use) ! map of in-use IRQ's
|
||||
and eax, ~[1<<CLOCK_IRQ] ! keep the clock ticking
|
||||
outb INT_CTLMASK ! enable all unused IRQ's and vv.
|
||||
movb al, ah
|
||||
outb INT2_CTLMASK
|
||||
|
||||
mov eax, SS_SELECTOR ! monitor data segment
|
||||
mov ss, ax
|
||||
xchg esp, (_mon_sp) ! switch stacks
|
||||
push (_reg86+36) ! parameters used in INT call
|
||||
push (_reg86+32)
|
||||
push (_reg86+28)
|
||||
push (_reg86+24)
|
||||
push (_reg86+20)
|
||||
push (_reg86+16)
|
||||
push (_reg86+12)
|
||||
push (_reg86+ 8)
|
||||
push (_reg86+ 4)
|
||||
push (_reg86+ 0)
|
||||
mov ds, ax ! remaining data selectors
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
push cs
|
||||
push return ! kernel return address and selector
|
||||
o16 jmpf 20+2*4+10*4+2*4(esp) ! make the call
|
||||
return:
|
||||
pop (_reg86+ 0)
|
||||
pop (_reg86+ 4)
|
||||
pop (_reg86+ 8)
|
||||
pop (_reg86+12)
|
||||
pop (_reg86+16)
|
||||
pop (_reg86+20)
|
||||
pop (_reg86+24)
|
||||
pop (_reg86+28)
|
||||
pop (_reg86+32)
|
||||
pop (_reg86+36)
|
||||
lgdt (_gdt+GDT_SELECTOR) ! reload global descriptor table
|
||||
jmpf CS_SELECTOR:csinit ! restore everything
|
||||
csinit: mov eax, DS_SELECTOR
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
xchg esp, (_mon_sp) ! unswitch stacks
|
||||
lidt (_gdt+IDT_SELECTOR) ! reload interrupt descriptor table
|
||||
andb (_gdt+TSS_SELECTOR+DESC_ACCESS), ~0x02 ! clear TSS busy bit
|
||||
mov eax, TSS_SELECTOR
|
||||
ltr ax ! set TSS register
|
||||
|
||||
pop eax
|
||||
outb INT_CTLMASK ! restore interrupt masks
|
||||
movb al, ah
|
||||
outb INT2_CTLMASK
|
||||
|
||||
add (_lost_ticks), ecx ! record lost clock ticks
|
||||
|
||||
popf ! restore flags
|
||||
pop ebx ! restore C registers
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* cp_mess *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void cp_mess(int src, phys_clicks src_clicks, vir_bytes src_offset,
|
||||
! phys_clicks dst_clicks, vir_bytes dst_offset);
|
||||
! This routine makes a fast copy of a message from anywhere in the address
|
||||
! space to anywhere else. It also copies the source address provided as a
|
||||
! parameter to the call into the first word of the destination message.
|
||||
!
|
||||
! Note that the message size, "Msize" is in DWORDS (not bytes) and must be set
|
||||
! correctly. Changing the definition of message in the type file and not
|
||||
! changing it here will lead to total disaster.
|
||||
|
||||
CM_ARGS = 4 + 4 + 4 + 4 + 4 ! 4 + 4 + 4 + 4 + 4
|
||||
! es ds edi esi eip proc scl sof dcl dof
|
||||
|
||||
.align 16
|
||||
_cp_mess:
|
||||
cld
|
||||
push esi
|
||||
push edi
|
||||
push ds
|
||||
push es
|
||||
|
||||
mov eax, FLAT_DS_SELECTOR
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
mov esi, CM_ARGS+4(esp) ! src clicks
|
||||
shl esi, CLICK_SHIFT
|
||||
add esi, CM_ARGS+4+4(esp) ! src offset
|
||||
mov edi, CM_ARGS+4+4+4(esp) ! dst clicks
|
||||
shl edi, CLICK_SHIFT
|
||||
add edi, CM_ARGS+4+4+4+4(esp) ! dst offset
|
||||
|
||||
mov eax, CM_ARGS(esp) ! process number of sender
|
||||
stos ! copy number of sender to dest message
|
||||
add esi, 4 ! do not copy first word
|
||||
mov ecx, Msize - 1 ! remember, first word does not count
|
||||
rep
|
||||
movs ! copy the message
|
||||
|
||||
pop es
|
||||
pop ds
|
||||
pop edi
|
||||
pop esi
|
||||
ret ! that is all folks!
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* exit *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void exit();
|
||||
! Some library routines use exit, so provide a dummy version.
|
||||
! Actual calls to exit cannot occur in the kernel.
|
||||
! GNU CC likes to call ___main from main() for nonobvious reasons.
|
||||
|
||||
_exit:
|
||||
__exit:
|
||||
___exit:
|
||||
sti
|
||||
jmp ___exit
|
||||
|
||||
___main:
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_insw *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_insw(Port_t port, phys_bytes buf, size_t count);
|
||||
! Input an array from an I/O port. Absolute address version of insw().
|
||||
|
||||
_phys_insw:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
cld
|
||||
push edi
|
||||
push es
|
||||
mov ecx, FLAT_DS_SELECTOR
|
||||
mov es, cx
|
||||
mov edx, 8(ebp) ! port to read from
|
||||
mov edi, 12(ebp) ! destination addr
|
||||
mov ecx, 16(ebp) ! byte count
|
||||
shr ecx, 1 ! word count
|
||||
rep o16 ins ! input many words
|
||||
pop es
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_insb *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_insb(Port_t port, phys_bytes buf, size_t count);
|
||||
! Input an array from an I/O port. Absolute address version of insb().
|
||||
|
||||
_phys_insb:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
cld
|
||||
push edi
|
||||
push es
|
||||
mov ecx, FLAT_DS_SELECTOR
|
||||
mov es, cx
|
||||
mov edx, 8(ebp) ! port to read from
|
||||
mov edi, 12(ebp) ! destination addr
|
||||
mov ecx, 16(ebp) ! byte count
|
||||
! shr ecx, 1 ! word count
|
||||
rep insb ! input many bytes
|
||||
pop es
|
||||
pop edi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_outsw *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_outsw(Port_t port, phys_bytes buf, size_t count);
|
||||
! Output an array to an I/O port. Absolute address version of outsw().
|
||||
|
||||
.align 16
|
||||
_phys_outsw:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
cld
|
||||
push esi
|
||||
push ds
|
||||
mov ecx, FLAT_DS_SELECTOR
|
||||
mov ds, cx
|
||||
mov edx, 8(ebp) ! port to write to
|
||||
mov esi, 12(ebp) ! source addr
|
||||
mov ecx, 16(ebp) ! byte count
|
||||
shr ecx, 1 ! word count
|
||||
rep o16 outs ! output many words
|
||||
pop ds
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_outsb *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_outsb(Port_t port, phys_bytes buf, size_t count);
|
||||
! Output an array to an I/O port. Absolute address version of outsb().
|
||||
|
||||
.align 16
|
||||
_phys_outsb:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
cld
|
||||
push esi
|
||||
push ds
|
||||
mov ecx, FLAT_DS_SELECTOR
|
||||
mov ds, cx
|
||||
mov edx, 8(ebp) ! port to write to
|
||||
mov esi, 12(ebp) ! source addr
|
||||
mov ecx, 16(ebp) ! byte count
|
||||
rep outsb ! output many bytes
|
||||
pop ds
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
!*==========================================================================*
|
||||
!* intr_unmask *
|
||||
!*==========================================================================*/
|
||||
! PUBLIC void intr_unmask(irq_hook_t *hook)
|
||||
! Enable an interrupt request line by clearing an 8259 bit.
|
||||
! Equivalent C code for hook->irq < 8:
|
||||
! if ((irq_actids[hook->irq] &= ~hook->id) == 0)
|
||||
! outb(INT_CTLMASK, inb(INT_CTLMASK) & ~(1 << irq));
|
||||
|
||||
.align 16
|
||||
_intr_unmask:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
pushf
|
||||
cli
|
||||
mov eax, 8(ebp) ! hook
|
||||
mov ecx, 8(eax) ! irq
|
||||
mov eax, 12(eax) ! id bit
|
||||
not eax
|
||||
and _irq_actids(ecx*4), eax ! clear this id bit
|
||||
jnz en_done ! still masked by other handlers?
|
||||
movb ah, ~1
|
||||
rolb ah, cl ! ah = ~(1 << (irq % 8))
|
||||
mov edx, INT_CTLMASK ! enable irq < 8 at the master 8259
|
||||
cmpb cl, 8
|
||||
jb 0f
|
||||
mov edx, INT2_CTLMASK ! enable irq >= 8 at the slave 8259
|
||||
0: inb dx
|
||||
andb al, ah
|
||||
outb dx ! clear bit at the 8259
|
||||
en_done:popf
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
!*==========================================================================*
|
||||
!* intr_mask *
|
||||
!*==========================================================================*/
|
||||
! PUBLIC int intr_mask(irq_hook_t *hook)
|
||||
! Disable an interrupt request line by setting an 8259 bit.
|
||||
! Equivalent C code for irq < 8:
|
||||
! irq_actids[hook->irq] |= hook->id;
|
||||
! outb(INT_CTLMASK, inb(INT_CTLMASK) | (1 << irq));
|
||||
! Returns true iff the interrupt was not already disabled.
|
||||
|
||||
.align 16
|
||||
_intr_mask:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
pushf
|
||||
cli
|
||||
mov eax, 8(ebp) ! hook
|
||||
mov ecx, 8(eax) ! irq
|
||||
mov eax, 12(eax) ! id bit
|
||||
or _irq_actids(ecx*4), eax ! set this id bit
|
||||
movb ah, 1
|
||||
rolb ah, cl ! ah = (1 << (irq % 8))
|
||||
mov edx, INT_CTLMASK ! disable irq < 8 at the master 8259
|
||||
cmpb cl, 8
|
||||
jb 0f
|
||||
mov edx, INT2_CTLMASK ! disable irq >= 8 at the slave 8259
|
||||
0: inb dx
|
||||
testb al, ah
|
||||
jnz dis_already ! already disabled?
|
||||
orb al, ah
|
||||
outb dx ! set bit at the 8259
|
||||
mov eax, 1 ! disabled by this function
|
||||
popf
|
||||
leave
|
||||
ret
|
||||
dis_already:
|
||||
xor eax, eax ! already disabled
|
||||
popf
|
||||
leave
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_copy *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_copy(phys_bytes source, phys_bytes destination,
|
||||
! phys_bytes bytecount);
|
||||
! Copy a block of physical memory.
|
||||
|
||||
PC_ARGS = 4 + 4 + 4 + 4 ! 4 + 4 + 4
|
||||
! es edi esi eip src dst len
|
||||
|
||||
.align 16
|
||||
_phys_copy:
|
||||
cld
|
||||
push esi
|
||||
push edi
|
||||
push es
|
||||
|
||||
mov eax, FLAT_DS_SELECTOR
|
||||
mov es, ax
|
||||
|
||||
mov esi, PC_ARGS(esp)
|
||||
mov edi, PC_ARGS+4(esp)
|
||||
mov eax, PC_ARGS+4+4(esp)
|
||||
|
||||
cmp eax, 10 ! avoid align overhead for small counts
|
||||
jb pc_small
|
||||
mov ecx, esi ! align source, hope target is too
|
||||
neg ecx
|
||||
and ecx, 3 ! count for alignment
|
||||
sub eax, ecx
|
||||
rep
|
||||
eseg movsb
|
||||
mov ecx, eax
|
||||
shr ecx, 2 ! count of dwords
|
||||
rep
|
||||
eseg movs
|
||||
and eax, 3
|
||||
pc_small:
|
||||
xchg ecx, eax ! remainder
|
||||
rep
|
||||
eseg movsb
|
||||
|
||||
pop es
|
||||
pop edi
|
||||
pop esi
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* phys_memset *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void phys_memset(phys_bytes source, unsigned long pattern,
|
||||
! phys_bytes bytecount);
|
||||
! Fill a block of physical memory with pattern.
|
||||
|
||||
.align 16
|
||||
_phys_memset:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push ebx
|
||||
push ds
|
||||
mov esi, 8(ebp)
|
||||
mov eax, 16(ebp)
|
||||
mov ebx, FLAT_DS_SELECTOR
|
||||
mov ds, bx
|
||||
mov ebx, 12(ebp)
|
||||
shr eax, 2
|
||||
fill_start:
|
||||
mov (esi), ebx
|
||||
add esi, 4
|
||||
dec eax
|
||||
jnz fill_start
|
||||
! Any remaining bytes?
|
||||
mov eax, 16(ebp)
|
||||
and eax, 3
|
||||
remain_fill:
|
||||
cmp eax, 0
|
||||
jz fill_done
|
||||
movb bl, 12(ebp)
|
||||
movb (esi), bl
|
||||
add esi, 1
|
||||
inc ebp
|
||||
dec eax
|
||||
jmp remain_fill
|
||||
fill_done:
|
||||
pop ds
|
||||
pop ebx
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* mem_rdw *
|
||||
!*===========================================================================*
|
||||
! PUBLIC u16_t mem_rdw(U16_t segment, u16_t *offset);
|
||||
! Load and return word at far pointer segment:offset.
|
||||
|
||||
.align 16
|
||||
_mem_rdw:
|
||||
mov cx, ds
|
||||
mov ds, 4(esp) ! segment
|
||||
mov eax, 4+4(esp) ! offset
|
||||
movzx eax, (eax) ! word to return
|
||||
mov ds, cx
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* reset *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void reset();
|
||||
! Reset the system by loading IDT with offset 0 and interrupting.
|
||||
|
||||
_reset:
|
||||
lidt (idt_zero)
|
||||
int 3 ! anything goes, the 386 will not like it
|
||||
.sect .data
|
||||
idt_zero: .data4 0, 0
|
||||
.sect .text
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* idle_task *
|
||||
!*===========================================================================*
|
||||
_idle_task:
|
||||
! This task is called when the system has nothing else to do. The HLT
|
||||
! instruction puts the processor in a state where it draws minimum power.
|
||||
push halt
|
||||
call _level0 ! level0(halt)
|
||||
pop eax
|
||||
jmp _idle_task
|
||||
halt:
|
||||
sti
|
||||
hlt
|
||||
cli
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* level0 *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void level0(void (*func)(void))
|
||||
! Call a function at permission level 0. This allows kernel tasks to do
|
||||
! things that are only possible at the most privileged CPU level.
|
||||
!
|
||||
_level0:
|
||||
mov eax, 4(esp)
|
||||
mov (_level0_func), eax
|
||||
int LEVEL0_VECTOR
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* read_tsc *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void read_tsc(unsigned long *high, unsigned long *low);
|
||||
! Read the cycle counter of the CPU. Pentium and up.
|
||||
.align 16
|
||||
_read_tsc:
|
||||
.data1 0x0f ! this is the RDTSC instruction
|
||||
.data1 0x31 ! it places the TSC in EDX:EAX
|
||||
push ebp
|
||||
mov ebp, 8(esp)
|
||||
mov (ebp), edx
|
||||
mov ebp, 12(esp)
|
||||
mov (ebp), eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* read_flags *
|
||||
!*===========================================================================*
|
||||
! PUBLIC unsigned long read_cpu_flags(void);
|
||||
! Read CPU status flags from C.
|
||||
.align 16
|
||||
_read_cpu_flags:
|
||||
pushf
|
||||
mov eax, (esp)
|
||||
popf
|
||||
ret
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* read_cr0 *
|
||||
!*===========================================================================*
|
||||
! PUBLIC unsigned long read_cr0(void);
|
||||
_read_cr0:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, cr0
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* write_cr0 *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void write_cr0(unsigned long value);
|
||||
_write_cr0:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, 8(ebp)
|
||||
mov cr0, eax
|
||||
jmp 0f ! A jump is required for some flags
|
||||
0:
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* write_cr3 *
|
||||
!*===========================================================================*
|
||||
! PUBLIC void write_cr3(unsigned long value);
|
||||
_write_cr3:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, 8(ebp)
|
||||
mov cr3, eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
|
||||
#include "../../kernel.h"
|
||||
#include "../../proc.h"
|
||||
|
||||
#include <minix/type.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/vm.h>
|
||||
|
||||
#include <minix/portio.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
/* VM functions and data. */
|
||||
|
||||
PRIVATE int vm_needs_init= 1;
|
||||
PRIVATE u32_t vm_cr3;
|
||||
|
||||
FORWARD _PROTOTYPE( void phys_put32, (phys_bytes addr, u32_t value) );
|
||||
FORWARD _PROTOTYPE( u32_t phys_get32, (phys_bytes addr) );
|
||||
FORWARD _PROTOTYPE( void vm_set_cr3, (u32_t value) );
|
||||
FORWARD _PROTOTYPE( void set_cr3, (void) );
|
||||
FORWARD _PROTOTYPE( void vm_enable_paging, (void) );
|
||||
|
||||
/* *** Internal VM Functions *** */
|
||||
|
||||
PUBLIC void vm_init(void)
|
||||
{
|
||||
int o;
|
||||
phys_bytes p, pt_size;
|
||||
phys_bytes vm_dir_base, vm_pt_base, phys_mem;
|
||||
u32_t entry;
|
||||
unsigned pages;
|
||||
|
||||
if (!vm_size)
|
||||
panic("i386_vm_init: no space for page tables", NO_NUM);
|
||||
|
||||
/* Align page directory */
|
||||
o= (vm_base % PAGE_SIZE);
|
||||
if (o != 0)
|
||||
o= PAGE_SIZE-o;
|
||||
vm_dir_base= vm_base+o;
|
||||
|
||||
/* Page tables start after the page directory */
|
||||
vm_pt_base= vm_dir_base+PAGE_SIZE;
|
||||
|
||||
pt_size= (vm_base+vm_size)-vm_pt_base;
|
||||
pt_size -= (pt_size % PAGE_SIZE);
|
||||
|
||||
/* Compute the number of pages based on vm_mem_high */
|
||||
pages= (vm_mem_high-1)/PAGE_SIZE + 1;
|
||||
|
||||
if (pages * I386_VM_PT_ENT_SIZE > pt_size)
|
||||
panic("i386_vm_init: page table too small", NO_NUM);
|
||||
|
||||
for (p= 0; p*I386_VM_PT_ENT_SIZE < pt_size; p++)
|
||||
{
|
||||
phys_mem= p*PAGE_SIZE;
|
||||
entry= phys_mem | I386_VM_USER | I386_VM_WRITE |
|
||||
I386_VM_PRESENT;
|
||||
if (phys_mem >= vm_mem_high)
|
||||
entry= 0;
|
||||
phys_put32(vm_pt_base + p*I386_VM_PT_ENT_SIZE, entry);
|
||||
}
|
||||
|
||||
for (p= 0; p < I386_VM_DIR_ENTRIES; p++)
|
||||
{
|
||||
phys_mem= vm_pt_base + p*PAGE_SIZE;
|
||||
entry= phys_mem | I386_VM_USER | I386_VM_WRITE |
|
||||
I386_VM_PRESENT;
|
||||
if (phys_mem >= vm_pt_base + pt_size)
|
||||
entry= 0;
|
||||
phys_put32(vm_dir_base + p*I386_VM_PT_ENT_SIZE, entry);
|
||||
}
|
||||
vm_set_cr3(vm_dir_base);
|
||||
level0(vm_enable_paging);
|
||||
}
|
||||
|
||||
PRIVATE void phys_put32(addr, value)
|
||||
phys_bytes addr;
|
||||
u32_t value;
|
||||
{
|
||||
phys_copy(vir2phys((vir_bytes)&value), addr, sizeof(value));
|
||||
}
|
||||
|
||||
PRIVATE u32_t phys_get32(addr)
|
||||
phys_bytes addr;
|
||||
{
|
||||
u32_t value;
|
||||
|
||||
phys_copy(addr, vir2phys((vir_bytes)&value), sizeof(value));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
PRIVATE void vm_set_cr3(value)
|
||||
u32_t value;
|
||||
{
|
||||
vm_cr3= value;
|
||||
level0(set_cr3);
|
||||
}
|
||||
|
||||
PRIVATE void set_cr3()
|
||||
{
|
||||
write_cr3(vm_cr3);
|
||||
}
|
||||
|
||||
PRIVATE void vm_enable_paging(void)
|
||||
{
|
||||
u32_t cr0;
|
||||
|
||||
cr0= read_cr0();
|
||||
write_cr0(cr0 | I386_CR0_PG);
|
||||
}
|
||||
|
||||
PUBLIC void vm_map_range(base, size, offset)
|
||||
u32_t base;
|
||||
u32_t size;
|
||||
u32_t offset;
|
||||
{
|
||||
u32_t curr_pt, curr_pt_addr, entry;
|
||||
int dir_ent, pt_ent;
|
||||
|
||||
if (base % PAGE_SIZE != 0)
|
||||
panic("map_range: bad base", base);
|
||||
if (size % PAGE_SIZE != 0)
|
||||
panic("map_range: bad size", size);
|
||||
if (offset % PAGE_SIZE != 0)
|
||||
panic("map_range: bad offset", offset);
|
||||
|
||||
curr_pt= -1;
|
||||
curr_pt_addr= 0;
|
||||
while (size != 0)
|
||||
{
|
||||
dir_ent= (base >> I386_VM_DIR_ENT_SHIFT);
|
||||
pt_ent= (base >> I386_VM_PT_ENT_SHIFT) & I386_VM_PT_ENT_MASK;
|
||||
if (dir_ent != curr_pt)
|
||||
{
|
||||
/* Get address of page table */
|
||||
curr_pt= dir_ent;
|
||||
curr_pt_addr= phys_get32(vm_cr3 +
|
||||
dir_ent * I386_VM_PT_ENT_SIZE);
|
||||
curr_pt_addr &= I386_VM_ADDR_MASK;
|
||||
}
|
||||
entry= offset | I386_VM_USER | I386_VM_WRITE |
|
||||
I386_VM_PRESENT;
|
||||
#if 0 /* Do we need this for memory mapped I/O? */
|
||||
entry |= I386_VM_PCD | I386_VM_PWT;
|
||||
#endif
|
||||
phys_put32(curr_pt_addr + pt_ent * I386_VM_PT_ENT_SIZE, entry);
|
||||
offset += PAGE_SIZE;
|
||||
base += PAGE_SIZE;
|
||||
size -= PAGE_SIZE;
|
||||
}
|
||||
|
||||
/* reload root of page table. */
|
||||
vm_set_cr3(vm_cr3);
|
||||
}
|
||||
|
||||
PUBLIC vir_bytes alloc_remote_segment(u32_t *selector,
|
||||
segframe_t *segments, int index, phys_bytes phys, vir_bytes size,
|
||||
int priv)
|
||||
{
|
||||
phys_bytes offset = 0;
|
||||
/* Check if the segment size can be recorded in bytes, that is, check
|
||||
* if descriptor's limit field can delimited the allowed memory region
|
||||
* precisely. This works up to 1MB. If the size is larger, 4K pages
|
||||
* instead of bytes are used.
|
||||
*/
|
||||
if (size < BYTE_GRAN_MAX) {
|
||||
init_dataseg(&segments->p_ldt[EXTRA_LDT_INDEX+index],
|
||||
phys, size, priv);
|
||||
*selector = ((EXTRA_LDT_INDEX+index)*0x08) | (1*0x04) | priv;
|
||||
offset = 0;
|
||||
} else {
|
||||
init_dataseg(&segments->p_ldt[EXTRA_LDT_INDEX+index],
|
||||
phys & ~0xFFFF, 0, priv);
|
||||
*selector = ((EXTRA_LDT_INDEX+index)*0x08) | (1*0x04) | priv;
|
||||
offset = phys & 0xFFFF;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
PUBLIC phys_bytes umap_remote(struct proc* rp, int seg,
|
||||
vir_bytes vir_addr, vir_bytes bytes)
|
||||
{
|
||||
/* Calculate the physical memory address for a given virtual address. */
|
||||
struct far_mem *fm;
|
||||
|
||||
if (bytes <= 0) return( (phys_bytes) 0);
|
||||
if (seg < 0 || seg >= NR_REMOTE_SEGS) return( (phys_bytes) 0);
|
||||
|
||||
fm = &rp->p_priv->s_farmem[seg];
|
||||
if (! fm->in_use) return( (phys_bytes) 0);
|
||||
if (vir_addr + bytes > fm->mem_len) return( (phys_bytes) 0);
|
||||
|
||||
return(fm->mem_phys + (phys_bytes) vir_addr);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* umap_local *
|
||||
*===========================================================================*/
|
||||
PUBLIC phys_bytes umap_local(rp, seg, vir_addr, bytes)
|
||||
register struct proc *rp; /* pointer to proc table entry for process */
|
||||
int seg; /* T, D, or S segment */
|
||||
vir_bytes vir_addr; /* virtual address in bytes within the seg */
|
||||
vir_bytes bytes; /* # of bytes to be copied */
|
||||
{
|
||||
/* Calculate the physical memory address for a given virtual address. */
|
||||
vir_clicks vc; /* the virtual address in clicks */
|
||||
phys_bytes pa; /* intermediate variables as phys_bytes */
|
||||
phys_bytes seg_base;
|
||||
|
||||
if (bytes <= 0) return( (phys_bytes) 0);
|
||||
if (vir_addr + bytes <= vir_addr) return 0; /* overflow */
|
||||
vc = (vir_addr + bytes - 1) >> CLICK_SHIFT; /* last click of data */
|
||||
|
||||
if (seg != T)
|
||||
seg = (vc < rp->p_memmap[D].mem_vir + rp->p_memmap[D].mem_len ? D : S);
|
||||
|
||||
if ((vir_addr>>CLICK_SHIFT) >= rp->p_memmap[seg].mem_vir +
|
||||
rp->p_memmap[seg].mem_len) return( (phys_bytes) 0 );
|
||||
|
||||
if (vc >= rp->p_memmap[seg].mem_vir +
|
||||
rp->p_memmap[seg].mem_len) return( (phys_bytes) 0 );
|
||||
|
||||
seg_base = (phys_bytes) rp->p_memmap[seg].mem_phys;
|
||||
seg_base = seg_base << CLICK_SHIFT; /* segment origin in bytes */
|
||||
pa = (phys_bytes) vir_addr;
|
||||
pa -= rp->p_memmap[seg].mem_vir << CLICK_SHIFT;
|
||||
return(seg_base + pa);
|
||||
}
|
||||
|
||||
Executable
+535
@@ -0,0 +1,535 @@
|
||||
#
|
||||
! This file, mpx386.s, is included by mpx.s when Minix is compiled for
|
||||
! 32-bit Intel CPUs. The alternative mpx88.s is compiled for 16-bit CPUs.
|
||||
|
||||
! This file is part of the lowest layer of the MINIX kernel. (The other part
|
||||
! 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().
|
||||
|
||||
! Every transition to the kernel goes through this file. Transitions to the
|
||||
! kernel may be nested. The initial entry may be with a system call (i.e.,
|
||||
! send or receive a message), an exception or a hardware interrupt; kernel
|
||||
! reentries may only be made by hardware interrupts. The count of reentries
|
||||
! is kept in "k_reenter". It is important for deciding whether to switch to
|
||||
! the kernel stack and for protecting the message passing code in "proc.c".
|
||||
|
||||
! For the message passing trap, most of the machine state is saved in the
|
||||
! proc table. (Some of the registers need not be saved.) Then the stack is
|
||||
! switched to "k_stack", and interrupts are reenabled. Finally, the system
|
||||
! call handler (in C) is called. When it returns, interrupts are disabled
|
||||
! again and the code falls into the restart routine, to finish off held-up
|
||||
! interrupts and run the process or task whose pointer is in "proc_ptr".
|
||||
|
||||
! Hardware interrupt handlers do the same, except (1) The entire state must
|
||||
! be saved. (2) There are too many handlers to do this inline, so the save
|
||||
! routine is called. A few cycles are saved by pushing the address of the
|
||||
! appropiate restart routine for a return later. (3) A stack switch is
|
||||
! avoided when the stack is already switched. (4) The (master) 8259 interrupt
|
||||
! controller is reenabled centrally in save(). (5) Each interrupt handler
|
||||
! masks its interrupt line using the 8259 before enabling (other unmasked)
|
||||
! interrupts, and unmasks it after servicing the interrupt. This limits the
|
||||
! nest level to the number of lines and protects the handler from itself.
|
||||
|
||||
! 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.
|
||||
|
||||
! sections
|
||||
|
||||
.sect .text
|
||||
begtext:
|
||||
.sect .rom
|
||||
begrom:
|
||||
.sect .data
|
||||
begdata:
|
||||
.sect .bss
|
||||
begbss:
|
||||
|
||||
#include <minix/config.h>
|
||||
#include <minix/const.h>
|
||||
#include <minix/com.h>
|
||||
#include <ibm/interrupt.h>
|
||||
#include <archconst.h>
|
||||
#include "../../const.h"
|
||||
#include "sconst.h"
|
||||
|
||||
/* Selected 386 tss offsets. */
|
||||
#define TSS3_S_SP0 4
|
||||
|
||||
! Exported functions
|
||||
! Note: in assembly language the .define statement applied to a function name
|
||||
! is loosely equivalent to a prototype in C code -- it makes it possible to
|
||||
! link to an entity declared in the assembly code but does not create
|
||||
! the entity.
|
||||
|
||||
.define _restart
|
||||
.define save
|
||||
|
||||
.define _divide_error
|
||||
.define _single_step_exception
|
||||
.define _nmi
|
||||
.define _breakpoint_exception
|
||||
.define _overflow
|
||||
.define _bounds_check
|
||||
.define _inval_opcode
|
||||
.define _copr_not_available
|
||||
.define _double_fault
|
||||
.define _copr_seg_overrun
|
||||
.define _inval_tss
|
||||
.define _segment_not_present
|
||||
.define _stack_exception
|
||||
.define _general_protection
|
||||
.define _page_fault
|
||||
.define _copr_error
|
||||
|
||||
.define _hwint00 ! handlers for hardware interrupts
|
||||
.define _hwint01
|
||||
.define _hwint02
|
||||
.define _hwint03
|
||||
.define _hwint04
|
||||
.define _hwint05
|
||||
.define _hwint06
|
||||
.define _hwint07
|
||||
.define _hwint08
|
||||
.define _hwint09
|
||||
.define _hwint10
|
||||
.define _hwint11
|
||||
.define _hwint12
|
||||
.define _hwint13
|
||||
.define _hwint14
|
||||
.define _hwint15
|
||||
|
||||
.define _s_call
|
||||
.define _p_s_call
|
||||
.define _level0_call
|
||||
|
||||
! Exported variables.
|
||||
.define begbss
|
||||
.define begdata
|
||||
|
||||
.sect .text
|
||||
!*===========================================================================*
|
||||
!* MINIX *
|
||||
!*===========================================================================*
|
||||
MINIX: ! this is the entry point for the MINIX kernel
|
||||
jmp over_flags ! skip over the next few bytes
|
||||
.data2 CLICK_SHIFT ! for the monitor: memory granularity
|
||||
flags:
|
||||
.data2 0x01FD ! boot monitor flags:
|
||||
! call in 386 mode, make bss, make stack,
|
||||
! load high, don't patch, will return,
|
||||
! uses generic INT, memory vector,
|
||||
! new boot code return
|
||||
nop ! extra byte to sync up disassembler
|
||||
over_flags:
|
||||
|
||||
! Set up a C stack frame on the monitor stack. (The monitor sets cs and ds
|
||||
! right. The ss descriptor still references the monitor data segment.)
|
||||
movzx esp, sp ! monitor stack is a 16 bit stack
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
push edi
|
||||
cmp 4(ebp), 0 ! monitor return vector is
|
||||
jz noret ! nonzero if return possible
|
||||
inc (_mon_return)
|
||||
noret: mov (_mon_sp), esp ! save stack pointer for later return
|
||||
|
||||
! Copy the monitor global descriptor table to the address space of kernel and
|
||||
! switch over to it. Prot_init() can then update it with immediate effect.
|
||||
|
||||
sgdt (_gdt+GDT_SELECTOR) ! get the monitor gdtr
|
||||
mov esi, (_gdt+GDT_SELECTOR+2) ! absolute address of GDT
|
||||
mov ebx, _gdt ! address of kernel GDT
|
||||
mov ecx, 8*8 ! copying eight descriptors
|
||||
copygdt:
|
||||
eseg movb al, (esi)
|
||||
movb (ebx), al
|
||||
inc esi
|
||||
inc ebx
|
||||
loop copygdt
|
||||
mov eax, (_gdt+DS_SELECTOR+2) ! base of kernel data
|
||||
and eax, 0x00FFFFFF ! only 24 bits
|
||||
add eax, _gdt ! eax = vir2phys(gdt)
|
||||
mov (_gdt+GDT_SELECTOR+2), eax ! set base of GDT
|
||||
lgdt (_gdt+GDT_SELECTOR) ! switch over to kernel GDT
|
||||
|
||||
! Locate boot parameters, set up kernel segment registers and stack.
|
||||
mov ebx, 8(ebp) ! boot parameters offset
|
||||
mov edx, 12(ebp) ! boot parameters length
|
||||
mov eax, 16(ebp) ! address of a.out headers
|
||||
mov (_aout), eax
|
||||
mov ax, ds ! kernel data
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
mov esp, k_stktop ! set sp to point to the top of kernel stack
|
||||
|
||||
! Call C startup code to set up a proper environment to run main().
|
||||
push edx
|
||||
push ebx
|
||||
push SS_SELECTOR
|
||||
push DS_SELECTOR
|
||||
push CS_SELECTOR
|
||||
call _cstart ! cstart(cs, ds, mds, parmoff, parmlen)
|
||||
add esp, 5*4
|
||||
|
||||
! Reload gdtr, idtr and the segment registers to global descriptor table set
|
||||
! up by prot_init().
|
||||
|
||||
lgdt (_gdt+GDT_SELECTOR)
|
||||
lidt (_gdt+IDT_SELECTOR)
|
||||
|
||||
jmpf CS_SELECTOR:csinit
|
||||
csinit:
|
||||
o16 mov ax, DS_SELECTOR
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ss, ax
|
||||
o16 mov ax, TSS_SELECTOR ! no other TSS is used
|
||||
ltr ax
|
||||
push 0 ! set flags to known good state
|
||||
popf ! esp, clear nested task and int enable
|
||||
|
||||
jmp _main ! main()
|
||||
|
||||
|
||||
!*===========================================================================*
|
||||
!* interrupt handlers *
|
||||
!* interrupt handlers for 386 32-bit protected mode *
|
||||
!*===========================================================================*
|
||||
|
||||
!*===========================================================================*
|
||||
!* hwint00 - 07 *
|
||||
!*===========================================================================*
|
||||
! Note this is a macro, it just looks like a subroutine.
|
||||
#define hwint_master(irq) \
|
||||
call save /* save interrupted process state */;\
|
||||
push (_irq_handlers+4*irq) /* irq_handlers[irq] */;\
|
||||
call _intr_handle /* intr_handle(irq_handlers[irq]) */;\
|
||||
pop ecx ;\
|
||||
cmp (_irq_actids+4*irq), 0 /* interrupt still active? */;\
|
||||
jz 0f ;\
|
||||
inb INT_CTLMASK /* get current mask */ ;\
|
||||
orb al, [1<<irq] /* mask irq */ ;\
|
||||
outb INT_CTLMASK /* disable the irq */;\
|
||||
0: movb al, END_OF_INT ;\
|
||||
outb INT_CTL /* reenable master 8259 */;\
|
||||
ret /* restart (another) process */
|
||||
|
||||
! Each of these entry points is an expansion of the hwint_master macro
|
||||
.align 16
|
||||
_hwint00: ! Interrupt routine for irq 0 (the clock).
|
||||
hwint_master(0)
|
||||
|
||||
.align 16
|
||||
_hwint01: ! Interrupt routine for irq 1 (keyboard)
|
||||
hwint_master(1)
|
||||
|
||||
.align 16
|
||||
_hwint02: ! Interrupt routine for irq 2 (cascade!)
|
||||
hwint_master(2)
|
||||
|
||||
.align 16
|
||||
_hwint03: ! Interrupt routine for irq 3 (second serial)
|
||||
hwint_master(3)
|
||||
|
||||
.align 16
|
||||
_hwint04: ! Interrupt routine for irq 4 (first serial)
|
||||
hwint_master(4)
|
||||
|
||||
.align 16
|
||||
_hwint05: ! Interrupt routine for irq 5 (XT winchester)
|
||||
hwint_master(5)
|
||||
|
||||
.align 16
|
||||
_hwint06: ! Interrupt routine for irq 6 (floppy)
|
||||
hwint_master(6)
|
||||
|
||||
.align 16
|
||||
_hwint07: ! 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) \
|
||||
call save /* save interrupted process state */;\
|
||||
push (_irq_handlers+4*irq) /* irq_handlers[irq] */;\
|
||||
call _intr_handle /* intr_handle(irq_handlers[irq]) */;\
|
||||
pop ecx ;\
|
||||
cmp (_irq_actids+4*irq), 0 /* interrupt still active? */;\
|
||||
jz 0f ;\
|
||||
inb INT2_CTLMASK ;\
|
||||
orb al, [1<<[irq-8]] ;\
|
||||
outb INT2_CTLMASK /* disable the irq */;\
|
||||
0: movb al, END_OF_INT ;\
|
||||
outb INT_CTL /* reenable master 8259 */;\
|
||||
outb INT2_CTL /* reenable slave 8259 */;\
|
||||
ret /* restart (another) process */
|
||||
|
||||
! Each of these entry points is an expansion of the hwint_slave macro
|
||||
.align 16
|
||||
_hwint08: ! Interrupt routine for irq 8 (realtime clock)
|
||||
hwint_slave(8)
|
||||
|
||||
.align 16
|
||||
_hwint09: ! Interrupt routine for irq 9 (irq 2 redirected)
|
||||
hwint_slave(9)
|
||||
|
||||
.align 16
|
||||
_hwint10: ! Interrupt routine for irq 10
|
||||
hwint_slave(10)
|
||||
|
||||
.align 16
|
||||
_hwint11: ! Interrupt routine for irq 11
|
||||
hwint_slave(11)
|
||||
|
||||
.align 16
|
||||
_hwint12: ! Interrupt routine for irq 12
|
||||
hwint_slave(12)
|
||||
|
||||
.align 16
|
||||
_hwint13: ! Interrupt routine for irq 13 (FPU exception)
|
||||
hwint_slave(13)
|
||||
|
||||
.align 16
|
||||
_hwint14: ! Interrupt routine for irq 14 (AT winchester)
|
||||
hwint_slave(14)
|
||||
|
||||
.align 16
|
||||
_hwint15: ! Interrupt routine for irq 15
|
||||
hwint_slave(15)
|
||||
|
||||
!*===========================================================================*
|
||||
!* save *
|
||||
!*===========================================================================*
|
||||
! Save for protected mode.
|
||||
! This is much simpler than for 8086 mode, because the stack already points
|
||||
! into the process table, or has already been switched to the kernel stack.
|
||||
|
||||
.align 16
|
||||
save:
|
||||
cld ! set direction flag to a known value
|
||||
pushad ! save "general" registers
|
||||
o16 push ds ! save ds
|
||||
o16 push es ! save es
|
||||
o16 push fs ! save fs
|
||||
o16 push gs ! save gs
|
||||
mov dx, ss ! ss is kernel data segment
|
||||
mov ds, dx ! load rest of kernel segments
|
||||
mov es, dx ! kernel does not use fs, gs
|
||||
mov eax, esp ! prepare to return
|
||||
incb (_k_reenter) ! from -1 if not reentering
|
||||
jnz set_restart1 ! stack is already kernel stack
|
||||
mov esp, k_stktop
|
||||
push _restart ! build return address for int handler
|
||||
xor ebp, ebp ! for stacktrace
|
||||
jmp RETADR-P_STACKBASE(eax)
|
||||
|
||||
.align 4
|
||||
set_restart1:
|
||||
push restart1
|
||||
jmp RETADR-P_STACKBASE(eax)
|
||||
|
||||
!*===========================================================================*
|
||||
!* _s_call *
|
||||
!*===========================================================================*
|
||||
.align 16
|
||||
_s_call:
|
||||
_p_s_call:
|
||||
cld ! set direction flag to a known value
|
||||
sub esp, 6*4 ! skip RETADR, eax, ecx, edx, ebx, est
|
||||
push ebp ! stack already points into proc table
|
||||
push esi
|
||||
push edi
|
||||
o16 push ds
|
||||
o16 push es
|
||||
o16 push fs
|
||||
o16 push gs
|
||||
mov si, ss ! ss is kernel data segment
|
||||
mov ds, si ! load rest of kernel segments
|
||||
mov es, si ! kernel does not use fs, gs
|
||||
incb (_k_reenter) ! increment kernel entry count
|
||||
mov esi, esp ! assumes P_STACKBASE == 0
|
||||
mov esp, k_stktop
|
||||
xor ebp, ebp ! for stacktrace
|
||||
! end of inline save
|
||||
! now set up parameters for sys_call()
|
||||
push edx ! event set or flags bit map
|
||||
push ebx ! pointer to user message
|
||||
push eax ! source / destination
|
||||
push ecx ! call number (ipc primitive to use)
|
||||
call _sys_call ! sys_call(call_nr, src_dst, m_ptr, bit_map)
|
||||
! caller is now explicitly in proc_ptr
|
||||
mov AXREG(esi), eax ! sys_call MUST PRESERVE si
|
||||
|
||||
! Fall into code to restart proc/task running.
|
||||
|
||||
!*===========================================================================*
|
||||
!* restart *
|
||||
!*===========================================================================*
|
||||
_restart:
|
||||
|
||||
! Restart the current process or the next process if it is set.
|
||||
|
||||
cmp (_next_ptr), 0 ! see if another process is scheduled
|
||||
jz 0f
|
||||
mov eax, (_next_ptr)
|
||||
mov (_proc_ptr), eax ! schedule new process
|
||||
mov (_next_ptr), 0
|
||||
0: mov esp, (_proc_ptr) ! will assume P_STACKBASE == 0
|
||||
lldt P_LDT_SEL(esp) ! enable process' segment descriptors
|
||||
lea eax, P_STACKTOP(esp) ! arrange for next interrupt
|
||||
mov (_tss+TSS3_S_SP0), eax ! to save state in process table
|
||||
restart1:
|
||||
decb (_k_reenter)
|
||||
o16 pop gs
|
||||
o16 pop fs
|
||||
o16 pop es
|
||||
o16 pop ds
|
||||
popad
|
||||
add esp, 4 ! skip return adr
|
||||
iretd ! continue process
|
||||
|
||||
!*===========================================================================*
|
||||
!* exception handlers *
|
||||
!*===========================================================================*
|
||||
_divide_error:
|
||||
push DIVIDE_VECTOR
|
||||
jmp exception
|
||||
|
||||
_single_step_exception:
|
||||
push DEBUG_VECTOR
|
||||
jmp exception
|
||||
|
||||
_nmi:
|
||||
push NMI_VECTOR
|
||||
jmp exception
|
||||
|
||||
_breakpoint_exception:
|
||||
push BREAKPOINT_VECTOR
|
||||
jmp exception
|
||||
|
||||
_overflow:
|
||||
push OVERFLOW_VECTOR
|
||||
jmp exception
|
||||
|
||||
_bounds_check:
|
||||
push BOUNDS_VECTOR
|
||||
jmp exception
|
||||
|
||||
_inval_opcode:
|
||||
push INVAL_OP_VECTOR
|
||||
jmp exception
|
||||
|
||||
_copr_not_available:
|
||||
push COPROC_NOT_VECTOR
|
||||
jmp exception
|
||||
|
||||
_double_fault:
|
||||
push DOUBLE_FAULT_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_copr_seg_overrun:
|
||||
push COPROC_SEG_VECTOR
|
||||
jmp exception
|
||||
|
||||
_inval_tss:
|
||||
push INVAL_TSS_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_segment_not_present:
|
||||
push SEG_NOT_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_stack_exception:
|
||||
push STACK_FAULT_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_general_protection:
|
||||
push PROTECTION_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_page_fault:
|
||||
push PAGE_FAULT_VECTOR
|
||||
jmp errexception
|
||||
|
||||
_copr_error:
|
||||
push COPROC_ERR_VECTOR
|
||||
jmp exception
|
||||
|
||||
!*===========================================================================*
|
||||
!* exception *
|
||||
!*===========================================================================*
|
||||
! This is called for all exceptions which do not push an error code.
|
||||
|
||||
.align 16
|
||||
exception:
|
||||
sseg mov (trap_errno), 0 ! clear trap_errno
|
||||
sseg pop (ex_number)
|
||||
jmp exception1
|
||||
|
||||
!*===========================================================================*
|
||||
!* errexception *
|
||||
!*===========================================================================*
|
||||
! This is called for all exceptions which push an error code.
|
||||
|
||||
.align 16
|
||||
errexception:
|
||||
sseg pop (ex_number)
|
||||
sseg pop (trap_errno)
|
||||
exception1: ! Common for all exceptions.
|
||||
push eax ! eax is scratch register
|
||||
mov eax, 0+4(esp) ! old eip
|
||||
sseg mov (old_eip), eax
|
||||
movzx eax, 4+4(esp) ! old cs
|
||||
sseg mov (old_cs), eax
|
||||
mov eax, 8+4(esp) ! old eflags
|
||||
sseg mov (old_eflags), eax
|
||||
pop eax
|
||||
call save
|
||||
push (old_eflags)
|
||||
push (old_cs)
|
||||
push (old_eip)
|
||||
push (trap_errno)
|
||||
push (ex_number)
|
||||
call _exception ! (ex_number, trap_errno, old_eip,
|
||||
! old_cs, old_eflags)
|
||||
add esp, 5*4
|
||||
ret
|
||||
|
||||
!*===========================================================================*
|
||||
!* level0_call *
|
||||
!*===========================================================================*
|
||||
_level0_call:
|
||||
call save
|
||||
jmp (_level0_func)
|
||||
|
||||
!*===========================================================================*
|
||||
!* data *
|
||||
!*===========================================================================*
|
||||
|
||||
.sect .rom ! Before the string table please
|
||||
.data2 0x526F ! this must be the first data entry (magic #)
|
||||
|
||||
.sect .bss
|
||||
k_stack:
|
||||
.space K_STACK_BYTES ! kernel stack
|
||||
k_stktop: ! top of kernel stack
|
||||
.comm ex_number, 4
|
||||
.comm trap_errno, 4
|
||||
.comm old_eip, 4
|
||||
.comm old_cs, 4
|
||||
.comm old_eflags, 4
|
||||
Executable
+324
@@ -0,0 +1,324 @@
|
||||
/* This file contains code for initialization of protected mode, to initialize
|
||||
* code and data segment descriptors, and to initialize global descriptors
|
||||
* for local descriptors in the process table.
|
||||
*/
|
||||
|
||||
#include "../../kernel.h"
|
||||
#include "../../proc.h"
|
||||
#include <archconst.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
#define INT_GATE_TYPE (INT_286_GATE | DESC_386_BIT)
|
||||
#define TSS_TYPE (AVL_286_TSS | DESC_386_BIT)
|
||||
|
||||
struct desctableptr_s {
|
||||
char limit[sizeof(u16_t)];
|
||||
char base[sizeof(u32_t)]; /* really u24_t + pad for 286 */
|
||||
};
|
||||
|
||||
struct gatedesc_s {
|
||||
u16_t offset_low;
|
||||
u16_t selector;
|
||||
u8_t pad; /* |000|XXXXX| ig & trpg, |XXXXXXXX| task g */
|
||||
u8_t p_dpl_type; /* |P|DL|0|TYPE| */
|
||||
u16_t offset_high;
|
||||
};
|
||||
|
||||
struct tss_s {
|
||||
reg_t backlink;
|
||||
reg_t sp0; /* stack pointer to use during interrupt */
|
||||
reg_t ss0; /* " segment " " " " */
|
||||
reg_t sp1;
|
||||
reg_t ss1;
|
||||
reg_t sp2;
|
||||
reg_t ss2;
|
||||
reg_t cr3;
|
||||
reg_t ip;
|
||||
reg_t flags;
|
||||
reg_t ax;
|
||||
reg_t cx;
|
||||
reg_t dx;
|
||||
reg_t bx;
|
||||
reg_t sp;
|
||||
reg_t bp;
|
||||
reg_t si;
|
||||
reg_t di;
|
||||
reg_t es;
|
||||
reg_t cs;
|
||||
reg_t ss;
|
||||
reg_t ds;
|
||||
reg_t fs;
|
||||
reg_t gs;
|
||||
reg_t ldt;
|
||||
u16_t trap;
|
||||
u16_t iobase;
|
||||
/* u8_t iomap[0]; */
|
||||
};
|
||||
|
||||
PUBLIC struct segdesc_s gdt[GDT_SIZE]; /* used in klib.s and mpx.s */
|
||||
PRIVATE struct gatedesc_s idt[IDT_SIZE]; /* zero-init so none present */
|
||||
PUBLIC struct tss_s tss; /* zero init */
|
||||
|
||||
FORWARD _PROTOTYPE( void int_gate, (unsigned vec_nr, vir_bytes offset,
|
||||
unsigned dpl_type) );
|
||||
FORWARD _PROTOTYPE( void sdesc, (struct segdesc_s *segdp, phys_bytes base,
|
||||
vir_bytes size) );
|
||||
|
||||
/*===========================================================================*
|
||||
* enable_iop *
|
||||
*===========================================================================*/
|
||||
PUBLIC void enable_iop(struct proc *pp)
|
||||
{
|
||||
/* Allow a user process to use I/O instructions. Change the I/O Permission
|
||||
* Level bits in the psw. These specify least-privileged Current Permission
|
||||
* Level allowed to execute I/O instructions. Users and servers have CPL 3.
|
||||
* You can't have less privilege than that. Kernel has CPL 0, tasks CPL 1.
|
||||
*/
|
||||
pp->p_reg.psw |= 0x3000;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* seg2phys *
|
||||
*===========================================================================*/
|
||||
PUBLIC phys_bytes seg2phys(U16_t seg)
|
||||
{
|
||||
/* Return the base address of a segment, with seg being a
|
||||
* register, or a 286/386 segment selector.
|
||||
*/
|
||||
phys_bytes base;
|
||||
struct segdesc_s *segdp;
|
||||
|
||||
segdp = &gdt[seg >> 3];
|
||||
base = ((u32_t) segdp->base_low << 0)
|
||||
| ((u32_t) segdp->base_middle << 16)
|
||||
| ((u32_t) segdp->base_high << 24);
|
||||
return base;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* phys2seg *
|
||||
*===========================================================================*/
|
||||
PUBLIC void phys2seg(u16_t *seg, vir_bytes *off, phys_bytes phys)
|
||||
{
|
||||
/* Return a segment selector and offset that can be used to reach a physical
|
||||
* address, for use by a driver doing memory I/O in the A0000 - DFFFF range.
|
||||
*/
|
||||
*seg = FLAT_DS_SELECTOR;
|
||||
*off = phys;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* init_dataseg *
|
||||
*===========================================================================*/
|
||||
PUBLIC void init_dataseg(register struct segdesc_s *segdp,
|
||||
phys_bytes base, vir_bytes size, int privilege)
|
||||
{
|
||||
/* Build descriptor for a data segment. */
|
||||
sdesc(segdp, base, size);
|
||||
segdp->access = (privilege << DPL_SHIFT) | (PRESENT | SEGMENT |
|
||||
WRITEABLE);
|
||||
/* EXECUTABLE = 0, EXPAND_DOWN = 0, ACCESSED = 0 */
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* init_codeseg *
|
||||
*===========================================================================*/
|
||||
PUBLIC void init_codeseg(register struct segdesc_s *segdp, phys_bytes base,
|
||||
vir_bytes size, int privilege)
|
||||
{
|
||||
/* Build descriptor for a code segment. */
|
||||
sdesc(segdp, base, size);
|
||||
segdp->access = (privilege << DPL_SHIFT)
|
||||
| (PRESENT | SEGMENT | EXECUTABLE | READABLE);
|
||||
/* CONFORMING = 0, ACCESSED = 0 */
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* prot_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC void prot_init(void)
|
||||
{
|
||||
/* Set up tables for protected mode.
|
||||
* All GDT slots are allocated at compile time.
|
||||
*/
|
||||
struct gate_table_s *gtp;
|
||||
struct desctableptr_s *dtp;
|
||||
unsigned ldt_index;
|
||||
register struct proc *rp;
|
||||
|
||||
static struct gate_table_s {
|
||||
_PROTOTYPE( void (*gate), (void) );
|
||||
unsigned char vec_nr;
|
||||
unsigned char privilege;
|
||||
}
|
||||
gate_table[] = {
|
||||
{ divide_error, DIVIDE_VECTOR, INTR_PRIVILEGE },
|
||||
{ single_step_exception, DEBUG_VECTOR, INTR_PRIVILEGE },
|
||||
{ nmi, NMI_VECTOR, INTR_PRIVILEGE },
|
||||
{ breakpoint_exception, BREAKPOINT_VECTOR, USER_PRIVILEGE },
|
||||
{ overflow, OVERFLOW_VECTOR, USER_PRIVILEGE },
|
||||
{ bounds_check, BOUNDS_VECTOR, INTR_PRIVILEGE },
|
||||
{ inval_opcode, INVAL_OP_VECTOR, INTR_PRIVILEGE },
|
||||
{ copr_not_available, COPROC_NOT_VECTOR, INTR_PRIVILEGE },
|
||||
{ double_fault, DOUBLE_FAULT_VECTOR, INTR_PRIVILEGE },
|
||||
{ copr_seg_overrun, COPROC_SEG_VECTOR, INTR_PRIVILEGE },
|
||||
{ inval_tss, INVAL_TSS_VECTOR, INTR_PRIVILEGE },
|
||||
{ segment_not_present, SEG_NOT_VECTOR, INTR_PRIVILEGE },
|
||||
{ stack_exception, STACK_FAULT_VECTOR, INTR_PRIVILEGE },
|
||||
{ general_protection, PROTECTION_VECTOR, INTR_PRIVILEGE },
|
||||
{ page_fault, PAGE_FAULT_VECTOR, INTR_PRIVILEGE },
|
||||
{ copr_error, COPROC_ERR_VECTOR, INTR_PRIVILEGE },
|
||||
{ hwint00, VECTOR( 0), INTR_PRIVILEGE },
|
||||
{ hwint01, VECTOR( 1), INTR_PRIVILEGE },
|
||||
{ hwint02, VECTOR( 2), INTR_PRIVILEGE },
|
||||
{ hwint03, VECTOR( 3), INTR_PRIVILEGE },
|
||||
{ hwint04, VECTOR( 4), INTR_PRIVILEGE },
|
||||
{ hwint05, VECTOR( 5), INTR_PRIVILEGE },
|
||||
{ hwint06, VECTOR( 6), INTR_PRIVILEGE },
|
||||
{ hwint07, VECTOR( 7), INTR_PRIVILEGE },
|
||||
{ hwint08, VECTOR( 8), INTR_PRIVILEGE },
|
||||
{ hwint09, VECTOR( 9), INTR_PRIVILEGE },
|
||||
{ hwint10, VECTOR(10), INTR_PRIVILEGE },
|
||||
{ hwint11, VECTOR(11), INTR_PRIVILEGE },
|
||||
{ hwint12, VECTOR(12), INTR_PRIVILEGE },
|
||||
{ hwint13, VECTOR(13), INTR_PRIVILEGE },
|
||||
{ hwint14, VECTOR(14), INTR_PRIVILEGE },
|
||||
{ hwint15, VECTOR(15), INTR_PRIVILEGE },
|
||||
{ s_call, SYS386_VECTOR, USER_PRIVILEGE }, /* 386 system call */
|
||||
{ level0_call, LEVEL0_VECTOR, TASK_PRIVILEGE },
|
||||
};
|
||||
|
||||
/* Build gdt and idt pointers in GDT where the BIOS expects them. */
|
||||
dtp= (struct desctableptr_s *) &gdt[GDT_INDEX];
|
||||
* (u16_t *) dtp->limit = (sizeof gdt) - 1;
|
||||
* (u32_t *) dtp->base = vir2phys(gdt);
|
||||
|
||||
dtp= (struct desctableptr_s *) &gdt[IDT_INDEX];
|
||||
* (u16_t *) dtp->limit = (sizeof idt) - 1;
|
||||
* (u32_t *) dtp->base = vir2phys(idt);
|
||||
|
||||
/* Build segment descriptors for tasks and interrupt handlers. */
|
||||
init_codeseg(&gdt[CS_INDEX],
|
||||
kinfo.code_base, kinfo.code_size, INTR_PRIVILEGE);
|
||||
init_dataseg(&gdt[DS_INDEX],
|
||||
kinfo.data_base, kinfo.data_size, INTR_PRIVILEGE);
|
||||
init_dataseg(&gdt[ES_INDEX], 0L, 0, TASK_PRIVILEGE);
|
||||
|
||||
/* Build scratch descriptors for functions in klib88. */
|
||||
init_dataseg(&gdt[DS_286_INDEX], 0L, 0, TASK_PRIVILEGE);
|
||||
init_dataseg(&gdt[ES_286_INDEX], 0L, 0, TASK_PRIVILEGE);
|
||||
|
||||
/* Build local descriptors in GDT for LDT's in process table.
|
||||
* The LDT's are allocated at compile time in the process table, and
|
||||
* initialized whenever a process' map is initialized or changed.
|
||||
*/
|
||||
for (rp = BEG_PROC_ADDR, ldt_index = FIRST_LDT_INDEX;
|
||||
rp < END_PROC_ADDR; ++rp, ldt_index++) {
|
||||
init_dataseg(&gdt[ldt_index], vir2phys(rp->p_seg.p_ldt),
|
||||
sizeof(rp->p_seg.p_ldt), INTR_PRIVILEGE);
|
||||
gdt[ldt_index].access = PRESENT | LDT;
|
||||
rp->p_seg.p_ldt_sel = ldt_index * DESC_SIZE;
|
||||
}
|
||||
|
||||
/* Build main TSS.
|
||||
* This is used only to record the stack pointer to be used after an
|
||||
* interrupt.
|
||||
* The pointer is set up so that an interrupt automatically saves the
|
||||
* current process's registers ip:cs:f:sp:ss in the correct slots in the
|
||||
* process table.
|
||||
*/
|
||||
tss.ss0 = DS_SELECTOR;
|
||||
init_dataseg(&gdt[TSS_INDEX], vir2phys(&tss), sizeof(tss), INTR_PRIVILEGE);
|
||||
gdt[TSS_INDEX].access = PRESENT | (INTR_PRIVILEGE << DPL_SHIFT) | TSS_TYPE;
|
||||
|
||||
/* Build descriptors for interrupt gates in IDT. */
|
||||
for (gtp = &gate_table[0];
|
||||
gtp < &gate_table[sizeof gate_table / sizeof gate_table[0]]; ++gtp) {
|
||||
int_gate(gtp->vec_nr, (vir_bytes) gtp->gate,
|
||||
PRESENT | INT_GATE_TYPE | (gtp->privilege << DPL_SHIFT));
|
||||
}
|
||||
|
||||
/* Complete building of main TSS. */
|
||||
tss.iobase = sizeof tss; /* empty i/o permissions map */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*===========================================================================*
|
||||
* sdesc *
|
||||
*===========================================================================*/
|
||||
PRIVATE void sdesc(segdp, base, size)
|
||||
register struct segdesc_s *segdp;
|
||||
phys_bytes base;
|
||||
vir_bytes size;
|
||||
{
|
||||
/* Fill in the size fields (base, limit and granularity) of a descriptor. */
|
||||
segdp->base_low = base;
|
||||
segdp->base_middle = base >> BASE_MIDDLE_SHIFT;
|
||||
segdp->base_high = base >> BASE_HIGH_SHIFT;
|
||||
|
||||
--size; /* convert to a limit, 0 size means 4G */
|
||||
if (size > BYTE_GRAN_MAX) {
|
||||
segdp->limit_low = size >> PAGE_GRAN_SHIFT;
|
||||
segdp->granularity = GRANULAR | (size >>
|
||||
(PAGE_GRAN_SHIFT + GRANULARITY_SHIFT));
|
||||
} else {
|
||||
segdp->limit_low = size;
|
||||
segdp->granularity = size >> GRANULARITY_SHIFT;
|
||||
}
|
||||
segdp->granularity |= DEFAULT; /* means BIG for data seg */
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* int_gate *
|
||||
*===========================================================================*/
|
||||
PRIVATE void int_gate(vec_nr, offset, dpl_type)
|
||||
unsigned vec_nr;
|
||||
vir_bytes offset;
|
||||
unsigned dpl_type;
|
||||
{
|
||||
/* Build descriptor for an interrupt gate. */
|
||||
register struct gatedesc_s *idp;
|
||||
|
||||
idp = &idt[vec_nr];
|
||||
idp->offset_low = offset;
|
||||
idp->selector = CS_SELECTOR;
|
||||
idp->p_dpl_type = dpl_type;
|
||||
idp->offset_high = offset >> OFFSET_HIGH_SHIFT;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* alloc_segments *
|
||||
*===========================================================================*/
|
||||
PUBLIC void alloc_segments(register struct proc *rp)
|
||||
{
|
||||
/* This is called at system initialization from main() and by do_newmap().
|
||||
* The code has a separate function because of all hardware-dependencies.
|
||||
* Note that IDLE is part of the kernel and gets TASK_PRIVILEGE here.
|
||||
*/
|
||||
phys_bytes code_bytes;
|
||||
phys_bytes data_bytes;
|
||||
int privilege;
|
||||
|
||||
data_bytes = (phys_bytes) (rp->p_memmap[S].mem_vir +
|
||||
rp->p_memmap[S].mem_len) << CLICK_SHIFT;
|
||||
if (rp->p_memmap[T].mem_len == 0)
|
||||
code_bytes = data_bytes; /* common I&D, poor protect */
|
||||
else
|
||||
code_bytes = (phys_bytes) rp->p_memmap[T].mem_len << CLICK_SHIFT;
|
||||
privilege = (iskernelp(rp)) ? TASK_PRIVILEGE : USER_PRIVILEGE;
|
||||
init_codeseg(&rp->p_seg.p_ldt[CS_LDT_INDEX],
|
||||
(phys_bytes) rp->p_memmap[T].mem_phys << CLICK_SHIFT,
|
||||
code_bytes, privilege);
|
||||
init_dataseg(&rp->p_seg.p_ldt[DS_LDT_INDEX],
|
||||
(phys_bytes) rp->p_memmap[D].mem_phys << CLICK_SHIFT,
|
||||
data_bytes, privilege);
|
||||
rp->p_reg.cs = (CS_LDT_INDEX * DESC_SIZE) | TI | privilege;
|
||||
rp->p_reg.gs =
|
||||
rp->p_reg.fs =
|
||||
rp->p_reg.ss =
|
||||
rp->p_reg.es =
|
||||
rp->p_reg.ds = (DS_LDT_INDEX*DESC_SIZE) | TI | privilege;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
#ifndef _I386_PROTO_H
|
||||
#define _I386_PROTO_H
|
||||
|
||||
/* Hardware interrupt handlers. */
|
||||
_PROTOTYPE( void hwint00, (void) );
|
||||
_PROTOTYPE( void hwint01, (void) );
|
||||
_PROTOTYPE( void hwint02, (void) );
|
||||
_PROTOTYPE( void hwint03, (void) );
|
||||
_PROTOTYPE( void hwint04, (void) );
|
||||
_PROTOTYPE( void hwint05, (void) );
|
||||
_PROTOTYPE( void hwint06, (void) );
|
||||
_PROTOTYPE( void hwint07, (void) );
|
||||
_PROTOTYPE( void hwint08, (void) );
|
||||
_PROTOTYPE( void hwint09, (void) );
|
||||
_PROTOTYPE( void hwint10, (void) );
|
||||
_PROTOTYPE( void hwint11, (void) );
|
||||
_PROTOTYPE( void hwint12, (void) );
|
||||
_PROTOTYPE( void hwint13, (void) );
|
||||
_PROTOTYPE( void hwint14, (void) );
|
||||
_PROTOTYPE( void hwint15, (void) );
|
||||
|
||||
|
||||
/* Exception handlers (real or protected mode), in numerical order. */
|
||||
void _PROTOTYPE( int00, (void) ), _PROTOTYPE( divide_error, (void) );
|
||||
void _PROTOTYPE( int01, (void) ), _PROTOTYPE( single_step_exception, (void) );
|
||||
void _PROTOTYPE( int02, (void) ), _PROTOTYPE( nmi, (void) );
|
||||
void _PROTOTYPE( int03, (void) ), _PROTOTYPE( breakpoint_exception, (void) );
|
||||
void _PROTOTYPE( int04, (void) ), _PROTOTYPE( overflow, (void) );
|
||||
void _PROTOTYPE( int05, (void) ), _PROTOTYPE( bounds_check, (void) );
|
||||
void _PROTOTYPE( int06, (void) ), _PROTOTYPE( inval_opcode, (void) );
|
||||
void _PROTOTYPE( int07, (void) ), _PROTOTYPE( copr_not_available, (void) );
|
||||
void _PROTOTYPE( double_fault, (void) );
|
||||
void _PROTOTYPE( copr_seg_overrun, (void) );
|
||||
void _PROTOTYPE( inval_tss, (void) );
|
||||
void _PROTOTYPE( segment_not_present, (void) );
|
||||
void _PROTOTYPE( stack_exception, (void) );
|
||||
void _PROTOTYPE( general_protection, (void) );
|
||||
void _PROTOTYPE( page_fault, (void) );
|
||||
void _PROTOTYPE( copr_error, (void) );
|
||||
|
||||
/* Software interrupt handlers, in numerical order. */
|
||||
_PROTOTYPE( void trp, (void) );
|
||||
_PROTOTYPE( void s_call, (void) ), _PROTOTYPE( p_s_call, (void) );
|
||||
_PROTOTYPE( void level0_call, (void) );
|
||||
|
||||
/* klib386.s */
|
||||
_PROTOTYPE( void level0, (void (*func)(void)) );
|
||||
_PROTOTYPE( void monitor, (void) );
|
||||
_PROTOTYPE( void reset, (void) );
|
||||
_PROTOTYPE( void int86, (void) );
|
||||
_PROTOTYPE( unsigned long read_cr0, (void) );
|
||||
_PROTOTYPE( void write_cr0, (unsigned long value) );
|
||||
_PROTOTYPE( void write_cr3, (unsigned long value) );
|
||||
_PROTOTYPE( unsigned long read_cpu_flags, (void) );
|
||||
_PROTOTYPE( void phys_insb, (U16_t port, phys_bytes buf, size_t count) );
|
||||
_PROTOTYPE( void phys_insw, (U16_t port, phys_bytes buf, size_t count) );
|
||||
_PROTOTYPE( void phys_outsb, (U16_t port, phys_bytes buf, size_t count) );
|
||||
_PROTOTYPE( void phys_outsw, (U16_t port, phys_bytes buf, size_t count) );
|
||||
|
||||
/* protect.c */
|
||||
_PROTOTYPE( void prot_init, (void) );
|
||||
_PROTOTYPE( void init_codeseg, (struct segdesc_s *segdp, phys_bytes base,
|
||||
vir_bytes size, int privilege) );
|
||||
_PROTOTYPE( void init_dataseg, (struct segdesc_s *segdp, phys_bytes base,
|
||||
vir_bytes size, int privilege) );
|
||||
_PROTOTYPE( void enable_iop, (struct proc *pp) );
|
||||
|
||||
/* functions defined in architecture-independent kernel source. */
|
||||
#include "../../proto.h"
|
||||
|
||||
#endif
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
! Miscellaneous constants used in assembler code.
|
||||
W = _WORD_SIZE ! Machine word size.
|
||||
|
||||
! Offsets in struct proc. They MUST match proc.h.
|
||||
P_STACKBASE = 0
|
||||
GSREG = P_STACKBASE
|
||||
FSREG = GSREG + 2 ! 386 introduces FS and GS segments
|
||||
ESREG = FSREG + 2
|
||||
DSREG = ESREG + 2
|
||||
DIREG = DSREG + 2
|
||||
SIREG = DIREG + W
|
||||
BPREG = SIREG + W
|
||||
STREG = BPREG + W ! hole for another SP
|
||||
BXREG = STREG + W
|
||||
DXREG = BXREG + W
|
||||
CXREG = DXREG + W
|
||||
AXREG = CXREG + W
|
||||
RETADR = AXREG + W ! return address for save() call
|
||||
PCREG = RETADR + W
|
||||
CSREG = PCREG + W
|
||||
PSWREG = CSREG + W
|
||||
SPREG = PSWREG + W
|
||||
SSREG = SPREG + W
|
||||
P_STACKTOP = SSREG + W
|
||||
P_LDT_SEL = P_STACKTOP
|
||||
P_LDT = P_LDT_SEL + W
|
||||
Msize = 9 ! size of a message in 32-bit words
|
||||
@@ -0,0 +1,102 @@
|
||||
/* system dependent functions for use inside the whole kernel. */
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <ibm/cmos.h>
|
||||
#include <ibm/bios.h>
|
||||
#include <minix/portio.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
PUBLIC void arch_shutdown(int how)
|
||||
{
|
||||
/* Mask all interrupts, including the clock. */
|
||||
outb( INT_CTLMASK, ~0);
|
||||
|
||||
if(how != RBT_RESET) {
|
||||
/* return to boot monitor */
|
||||
|
||||
outb( INT_CTLMASK, 0);
|
||||
outb( INT2_CTLMASK, 0);
|
||||
|
||||
/* Return to the boot monitor. Set
|
||||
* the program if not already done.
|
||||
*/
|
||||
if (how != RBT_MONITOR)
|
||||
phys_copy(vir2phys(""), kinfo.params_base, 1);
|
||||
level0(monitor);
|
||||
} else {
|
||||
/* Reset the system by forcing a processor shutdown. First stop
|
||||
* the BIOS memory test by setting a soft reset flag.
|
||||
*/
|
||||
u16_t magic = STOP_MEM_CHECK;
|
||||
phys_copy(vir2phys(&magic), SOFT_RESET_FLAG_ADDR,
|
||||
SOFT_RESET_FLAG_SIZE);
|
||||
level0(reset);
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void system_init(void)
|
||||
{
|
||||
prot_init();
|
||||
}
|
||||
|
||||
#define COM1_BASE 0x3F8
|
||||
#define COM1_THR (COM1_BASE + 0)
|
||||
#define LSR_THRE 0x20
|
||||
#define COM1_LSR (COM1_BASE + 5)
|
||||
|
||||
PUBLIC void ser_putc(char c)
|
||||
{
|
||||
int i;
|
||||
int lsr, thr;
|
||||
|
||||
lsr= COM1_LSR;
|
||||
thr= COM1_THR;
|
||||
for (i= 0; i<100000; i++)
|
||||
{
|
||||
if (inb( lsr) & LSR_THRE)
|
||||
break;
|
||||
}
|
||||
outb( thr, c);
|
||||
}
|
||||
|
||||
#if SPROFILE
|
||||
|
||||
PUBLIC int arch_init_profile_clock(u32_t freq)
|
||||
{
|
||||
int r;
|
||||
/* Set CMOS timer frequency. */
|
||||
outb(RTC_INDEX, RTC_REG_A);
|
||||
outb(RTC_IO, RTC_A_DV_OK | freq);
|
||||
/* Enable CMOS timer interrupts. */
|
||||
outb(RTC_INDEX, RTC_REG_B);
|
||||
r = inb(RTC_IO);
|
||||
outb(RTC_INDEX, RTC_REG_B);
|
||||
outb(RTC_IO, r | RTC_B_PIE);
|
||||
/* Mandatory read of CMOS register to enable timer interrupts. */
|
||||
outb(RTC_INDEX, RTC_REG_C);
|
||||
inb(RTC_IO);
|
||||
|
||||
return CMOS_CLOCK_IRQ;
|
||||
}
|
||||
|
||||
PUBLIC void arch_stop_profile_clock(void)
|
||||
{
|
||||
int r;
|
||||
/* Disable CMOS timer interrupts. */
|
||||
outb(RTC_INDEX, RTC_REG_B);
|
||||
r = inb(RTC_IO);
|
||||
outb(RTC_INDEX, RTC_REG_B);
|
||||
outb(RTC_IO, r & !RTC_B_PIE);
|
||||
}
|
||||
|
||||
PUBLIC void arch_ack_profile_clock(void)
|
||||
{
|
||||
/* Mandatory read of CMOS register to re-enable timer interrupts. */
|
||||
outb(RTC_INDEX, RTC_REG_C);
|
||||
inb(RTC_IO);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user