Subversion Repositories shark

Rev

Rev 120 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/* KL initialization code       */
23
 
24
#include <ll/i386/stdlib.h>
25
#include <ll/i386/x-bios.h>
26
#include <ll/i386/mem.h>
27
#include <ll/i386/cons.h>
28
#include <ll/i386/mb-info.h>
29
#include <ll/i386/error.h>
30
#include <ll/i386/pit.h>
40 pj 31
#include <ll/i386/pic.h>
131 giacomo 32
#include <ll/i386/advtimer.h>
2 pj 33
 
34
#include <ll/i386/tss-ctx.h>
35
#include <ll/i386/hw-arch.h>
36
#include <ll/sys/ll/ll-func.h>
37
#include <ll/sys/ll/ll-mem.h>
38
#include <ll/sys/ll/ll-instr.h>
40 pj 39
#include <ll/sys/ll/event.h>      /* for irq_bind() & irq_init() */
40
#include <ll/sys/ll/exc.h>        /* These are the HW exceptions */
2 pj 41
 
40 pj 42
FILE(LL-Init);
2 pj 43
 
40 pj 44
/* These are declared in llCx32b.C */
45
TSS  TSS_table[TSSMax];
46
WORD TSS_control[TSSMax];
47
BYTE ll_FPU_stdctx[FPU_CONTEXT_SIZE];
48
 
2 pj 49
void ll_exc_hook(int i)
50
{
40 pj 51
        static char *exc_mess[] = {
2 pj 52
        "#Division by 0",
53
        "#Debug fault",
54
        "#NMI detected",
55
        "#Breakpoint trap",
56
        "#Overflow detected on INTO",
57
        "#BOUND limit exceeded",
58
        "*Unvalid opcode",
40 pj 59
        "1FPU context switch", /* Handled in the llCtx.Asm/S File */
2 pj 60
        "*Double defect",
61
        "#INTEL reserved",
62
        "*Unvalid TSS",
63
        "*Segment not present",
64
        "*Stack exception",
65
        "*General protection fault",
66
        "#Page fault",
67
        "#INTEL reserved",
68
        "2Coprocessor error"
40 pj 69
        };
2 pj 70
 
40 pj 71
        static int exc_code[] = {
2 pj 72
        DIV_BY_0, NMI_EXC, DEBUG_EXC, BREAKPOINT_EXC,
73
        HW_FAULT, HW_FAULT, HW_FAULT,
40 pj 74
        0,              /* This is the FPU ctx Switch */
2 pj 75
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
76
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
77
        MATH_EXC
40 pj 78
        };
2 pj 79
 
40 pj 80
        char code = *exc_mess[i];
81
        #ifdef __LL_DEBUG__
82
        extern long int ndp_called,ndp_switched;
83
        extern wu_called;
84
        extern ai_called;
85
        extern DWORD *smain;
86
        #endif
2 pj 87
 
40 pj 88
        /* Math error! FPU has to be acknowledgded */
89
        if (code == '2') ll_out(0x0F0,0);
90
 
91
        message("Exception %d occurred\n", i);
92
        message("%s\n", &exc_mess[i][1]);
93
 
94
 
95
        #ifdef __LL_DEBUG__
96
        if (code == '*') {
97
                /* Dump additional info */
98
                message("DS:%nx CS:%nx\n",get_DS(),get_CS());
99
                /* message("WU : %d AI : %d\n",wu_called,ai_called); */
100
                message("Actual stack : %x\n",get_SP());
101
                /* message("Main stack : %p\n",smain); */
102
                dump_TSS(get_TR());
103
        }
104
        #endif
105
        /* halt(); */
106
        ll_abort(exc_code[i]);
2 pj 107
}
108
 
109
void *ll_init(void)
110
{
40 pj 111
        void *p;
112
        int i;
113
        LIN_ADDR b;
114
/*
115
        DWORD s;
116
        BYTE *base;
117
*/
118
  TSS dummy_tss;      /* Very dirty, but we need it, in order to
119
                         get an initial value for the FPU
120
                         context...
121
                      */
122
 
123
 
124
        p = l1_init();
125
        /* First of all, init the exc and irq tables... */
126
        irq_init();
127
        for(i = 0; i < 32; i++) {
2 pj 128
 
129
/* Warning!!! The hw exceptions should be 32.... Fix it!!! */
40 pj 130
 
2 pj 131
/*
132
                ll_irq_table[i] = (DWORD)act_int;
133
                ll_exc_table[i] = (DWORD)ll_exc_hook;
134
*/
40 pj 135
                l1_exc_bind(i, ll_exc_hook);
136
        }
137
        for(i = 0; i < 16; i++) {
138
                void act_int(int i);
139
                l1_irq_bind(i, act_int);
140
        }
2 pj 141
 
40 pj 142
 
143
  /* Init TSS table & put the corrispondent selectors into GDT */
144
  TSS_control[TSSMain] |= TSS_USED;
145
  for (i = 0; i < TSSMax; i++) {
146
    /* b = appl2linear(&TSS_table[i]); */
147
    b = (LIN_ADDR)(&TSS_table[i]);
148
    GDT_place(TSSindex2sel(i),(DWORD)b,sizeof(TSS),FREE_TSS386, GRAN_16);
149
  }
150
 
2 pj 151
#if 0
40 pj 152
  ll_FPU_save();
153
  memcpy(ll_FPU_stdctx,ll_FPU_savearea,FPU_CONTEXT_SIZE);
154
#else
155
  save_fpu(&dummy_tss); /* OK???*/
156
  memcpy(ll_FPU_stdctx, dummy_tss.ctx_FPU, FPU_CONTEXT_SIZE);
2 pj 157
#endif
40 pj 158
  init_fpu();
159
 
160
 
161
        /* ll_mem_init must be explicitelly called by program... */
162
#if 0
163
        /* Get info about extended memory! We suppose that X has loaded */
164
        /* there the application; if you switch to DOS memory, then you */
165
        /* have to change the stuff in order it works; check X_...  for */
166
        /* details.                                                     */
167
        X_meminfo(&b,&s,NULL,NULL);
168
        base = (BYTE *)b;
169
        #ifdef __MEM_DEBUG__
170
        message("PM Free Mem Base         : %lx\n",b);
171
        message("PM null addr (0L)        : %lx\n",appl2linear((void *)0L));
172
        message("PM Free Mem Base (Cnvrtd): %lp\n",base);
173
        #endif
174
        ll_mem_init(base,s);
175
        #ifdef __MEM_DEBUG__
176
        ll_mem_dump();
177
        #endif
2 pj 178
#endif
179
 
180
 
40 pj 181
        return p;
2 pj 182
}
183
 
184
void abort_tail(int code)
185
{
40 pj 186
        message("ABORT %d !!!",code);
131 giacomo 187
        ll_restore_CMOS();
120 giacomo 188
        l1_end();
40 pj 189
        sti();
190
        l1_exit(1);
2 pj 191
}
192
 
193
void ll_end(void)
194
{
131 giacomo 195
        ll_restore_CMOS();
40 pj 196
        l1_end();
2 pj 197
}
40 pj 198