Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 3 → Rev 40

/shark/trunk/oslib/kl/init.c
28,6 → 28,7
#include <ll/i386/mb-info.h>
#include <ll/i386/error.h>
#include <ll/i386/pit.h>
#include <ll/i386/pic.h>
 
#include <ll/i386/tss-ctx.h>
#include <ll/i386/hw-arch.h>
34,14 → 35,19
#include <ll/sys/ll/ll-func.h>
#include <ll/sys/ll/ll-mem.h>
#include <ll/sys/ll/ll-instr.h>
#include <ll/sys/ll/event.h> /* for irq_bind() & irq_init() */
#include <ll/sys/ll/exc.h> /* These are the HW exceptions */
#include <ll/sys/ll/event.h> /* for irq_bind() & irq_init() */
#include <ll/sys/ll/exc.h> /* These are the HW exceptions */
 
FILE(LL - Init);
FILE(LL-Init);
 
/* These are declared in llCx32b.C */
TSS TSS_table[TSSMax];
WORD TSS_control[TSSMax];
BYTE ll_FPU_stdctx[FPU_CONTEXT_SIZE];
 
void ll_exc_hook(int i)
{
static char *exc_mess[] = {
static char *exc_mess[] = {
"#Division by 0",
"#Debug fault",
"#NMI detected",
49,7 → 55,7
"#Overflow detected on INTO",
"#BOUND limit exceeded",
"*Unvalid opcode",
"1FPU context switch", /* Handled in the llCtx.Asm/S File */
"1FPU context switch", /* Handled in the llCtx.Asm/S File */
"*Double defect",
"#INTEL reserved",
"*Unvalid TSS",
59,103 → 65,131
"#Page fault",
"#INTEL reserved",
"2Coprocessor error"
};
};
 
static int exc_code[] = {
static int exc_code[] = {
DIV_BY_0, NMI_EXC, DEBUG_EXC, BREAKPOINT_EXC,
HW_FAULT, HW_FAULT, HW_FAULT,
0, /* This is the FPU ctx Switch */
0, /* This is the FPU ctx Switch */
HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
MATH_EXC
};
};
 
char code = *exc_mess[i];
#ifdef __LL_DEBUG__
extern long int ndp_called, ndp_switched;
extern wu_called;
extern ai_called;
extern DWORD *smain;
#endif
char code = *exc_mess[i];
#ifdef __LL_DEBUG__
extern long int ndp_called,ndp_switched;
extern wu_called;
extern ai_called;
extern DWORD *smain;
#endif
 
/* Math error! FPU has to be acknowledgded */
if (code == '2')
ll_out(0x0F0, 0);
 
message("Exception %d occurred\n", i);
message("%s\n", &exc_mess[i][1]);
 
 
#ifdef __LL_DEBUG__
if (code == '*') {
/* Dump additional info */
message("DS:%nx CS:%nx\n", get_DS(), get_CS());
/* message("WU : %d AI : %d\n",wu_called,ai_called); */
message("Actual stack : %x\n", get_SP());
/* message("Main stack : %p\n",smain); */
dump_TSS(get_TR());
}
#endif
/* halt(); */
ll_abort(exc_code[i]);
/* Math error! FPU has to be acknowledgded */
if (code == '2') ll_out(0x0F0,0);
message("Exception %d occurred\n", i);
message("%s\n", &exc_mess[i][1]);
#ifdef __LL_DEBUG__
if (code == '*') {
/* Dump additional info */
message("DS:%nx CS:%nx\n",get_DS(),get_CS());
/* message("WU : %d AI : %d\n",wu_called,ai_called); */
message("Actual stack : %x\n",get_SP());
/* message("Main stack : %p\n",smain); */
dump_TSS(get_TR());
}
#endif
/* halt(); */
ll_abort(exc_code[i]);
}
 
void *ll_init(void)
{
void *p;
int i;
LIN_ADDR b;
DWORD s;
BYTE *base;
void *p;
int i;
LIN_ADDR b;
/*
DWORD s;
BYTE *base;
*/
TSS dummy_tss; /* Very dirty, but we need it, in order to
get an initial value for the FPU
context...
*/
p = l1_init();
/* First of all, init the exc and irq tables... */
irq_init();
for(i = 0; i < 32; i++) {
 
p = l1_init();
/* First of all, init the exc and irq tables... */
irq_init();
for (i = 0; i < 16; i++) {
void act_int(int i);
 
/* Warning!!! The hw exceptions should be 32.... Fix it!!! */
 
/*
ll_irq_table[i] = (DWORD)act_int;
ll_exc_table[i] = (DWORD)ll_exc_hook;
*/
l1_irq_bind(i, act_int);
l1_exc_bind(i, ll_exc_hook);
}
l1_exc_bind(i, ll_exc_hook);
}
for(i = 0; i < 16; i++) {
void act_int(int i);
l1_irq_bind(i, act_int);
}
 
/* ll_mem_init must be explicitelly called by program... */
 
/* Init TSS table & put the corrispondent selectors into GDT */
TSS_control[TSSMain] |= TSS_USED;
for (i = 0; i < TSSMax; i++) {
/* b = appl2linear(&TSS_table[i]); */
b = (LIN_ADDR)(&TSS_table[i]);
GDT_place(TSSindex2sel(i),(DWORD)b,sizeof(TSS),FREE_TSS386, GRAN_16);
}
 
#if 0
/* Get info about extended memory! We suppose that X has loaded */
/* there the application; if you switch to DOS memory, then you */
/* have to change the stuff in order it works; check X_... for */
/* details. */
X_meminfo(&b, &s, NULL, NULL);
base = (BYTE *) b;
#ifdef __MEM_DEBUG__
message("PM Free Mem Base : %lx\n", b);
message("PM null addr (0L) : %lx\n", appl2linear((void *) 0L));
message("PM Free Mem Base (Cnvrtd): %lp\n", base);
ll_FPU_save();
memcpy(ll_FPU_stdctx,ll_FPU_savearea,FPU_CONTEXT_SIZE);
#else
save_fpu(&dummy_tss); /* OK???*/
memcpy(ll_FPU_stdctx, dummy_tss.ctx_FPU, FPU_CONTEXT_SIZE);
#endif
ll_mem_init(base, s);
#ifdef __MEM_DEBUG__
ll_mem_dump();
init_fpu();
 
/* ll_mem_init must be explicitelly called by program... */
#if 0
/* Get info about extended memory! We suppose that X has loaded */
/* there the application; if you switch to DOS memory, then you */
/* have to change the stuff in order it works; check X_... for */
/* details. */
X_meminfo(&b,&s,NULL,NULL);
base = (BYTE *)b;
#ifdef __MEM_DEBUG__
message("PM Free Mem Base : %lx\n",b);
message("PM null addr (0L) : %lx\n",appl2linear((void *)0L));
message("PM Free Mem Base (Cnvrtd): %lp\n",base);
#endif
ll_mem_init(base,s);
#ifdef __MEM_DEBUG__
ll_mem_dump();
#endif
#endif
#endif
 
 
return p;
return p;
}
 
void abort_tail(int code)
{
message("ABORT %d !!!", code);
l1_end();
sti();
l1_exit(1);
message("ABORT %d !!!",code);
l1_end();
sti();
l1_exit(1);
}
 
void ll_end(void)
{
l1_end();
l1_end();
}