Subversion Repositories shark

Rev

Rev 40 | Rev 131 | Go to most recent revision | 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>
2 pj 32
 
33
#include <ll/i386/tss-ctx.h>
34
#include <ll/i386/hw-arch.h>
35
#include <ll/sys/ll/ll-func.h>
36
#include <ll/sys/ll/ll-mem.h>
37
#include <ll/sys/ll/ll-instr.h>
40 pj 38
#include <ll/sys/ll/event.h>      /* for irq_bind() & irq_init() */
39
#include <ll/sys/ll/exc.h>        /* These are the HW exceptions */
2 pj 40
 
40 pj 41
FILE(LL-Init);
2 pj 42
 
40 pj 43
/* These are declared in llCx32b.C */
44
TSS  TSS_table[TSSMax];
45
WORD TSS_control[TSSMax];
46
BYTE ll_FPU_stdctx[FPU_CONTEXT_SIZE];
47
 
2 pj 48
void ll_exc_hook(int i)
49
{
40 pj 50
        static char *exc_mess[] = {
2 pj 51
        "#Division by 0",
52
        "#Debug fault",
53
        "#NMI detected",
54
        "#Breakpoint trap",
55
        "#Overflow detected on INTO",
56
        "#BOUND limit exceeded",
57
        "*Unvalid opcode",
40 pj 58
        "1FPU context switch", /* Handled in the llCtx.Asm/S File */
2 pj 59
        "*Double defect",
60
        "#INTEL reserved",
61
        "*Unvalid TSS",
62
        "*Segment not present",
63
        "*Stack exception",
64
        "*General protection fault",
65
        "#Page fault",
66
        "#INTEL reserved",
67
        "2Coprocessor error"
40 pj 68
        };
2 pj 69
 
40 pj 70
        static int exc_code[] = {
2 pj 71
        DIV_BY_0, NMI_EXC, DEBUG_EXC, BREAKPOINT_EXC,
72
        HW_FAULT, HW_FAULT, HW_FAULT,
40 pj 73
        0,              /* This is the FPU ctx Switch */
2 pj 74
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
75
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
76
        MATH_EXC
40 pj 77
        };
2 pj 78
 
40 pj 79
        char code = *exc_mess[i];
80
        #ifdef __LL_DEBUG__
81
        extern long int ndp_called,ndp_switched;
82
        extern wu_called;
83
        extern ai_called;
84
        extern DWORD *smain;
85
        #endif
2 pj 86
 
40 pj 87
        /* Math error! FPU has to be acknowledgded */
88
        if (code == '2') ll_out(0x0F0,0);
89
 
90
        message("Exception %d occurred\n", i);
91
        message("%s\n", &exc_mess[i][1]);
92
 
93
 
94
        #ifdef __LL_DEBUG__
95
        if (code == '*') {
96
                /* Dump additional info */
97
                message("DS:%nx CS:%nx\n",get_DS(),get_CS());
98
                /* message("WU : %d AI : %d\n",wu_called,ai_called); */
99
                message("Actual stack : %x\n",get_SP());
100
                /* message("Main stack : %p\n",smain); */
101
                dump_TSS(get_TR());
102
        }
103
        #endif
104
        /* halt(); */
105
        ll_abort(exc_code[i]);
2 pj 106
}
107
 
108
void *ll_init(void)
109
{
40 pj 110
        void *p;
111
        int i;
112
        LIN_ADDR b;
113
/*
114
        DWORD s;
115
        BYTE *base;
116
*/
117
  TSS dummy_tss;      /* Very dirty, but we need it, in order to
118
                         get an initial value for the FPU
119
                         context...
120
                      */
121
 
122
 
123
        p = l1_init();
124
        /* First of all, init the exc and irq tables... */
125
        irq_init();
126
        for(i = 0; i < 32; i++) {
2 pj 127
 
128
/* Warning!!! The hw exceptions should be 32.... Fix it!!! */
40 pj 129
 
2 pj 130
/*
131
                ll_irq_table[i] = (DWORD)act_int;
132
                ll_exc_table[i] = (DWORD)ll_exc_hook;
133
*/
40 pj 134
                l1_exc_bind(i, ll_exc_hook);
135
        }
136
        for(i = 0; i < 16; i++) {
137
                void act_int(int i);
138
                l1_irq_bind(i, act_int);
139
        }
2 pj 140
 
40 pj 141
 
142
  /* Init TSS table & put the corrispondent selectors into GDT */
143
  TSS_control[TSSMain] |= TSS_USED;
144
  for (i = 0; i < TSSMax; i++) {
145
    /* b = appl2linear(&TSS_table[i]); */
146
    b = (LIN_ADDR)(&TSS_table[i]);
147
    GDT_place(TSSindex2sel(i),(DWORD)b,sizeof(TSS),FREE_TSS386, GRAN_16);
148
  }
149
 
2 pj 150
#if 0
40 pj 151
  ll_FPU_save();
152
  memcpy(ll_FPU_stdctx,ll_FPU_savearea,FPU_CONTEXT_SIZE);
153
#else
154
  save_fpu(&dummy_tss); /* OK???*/
155
  memcpy(ll_FPU_stdctx, dummy_tss.ctx_FPU, FPU_CONTEXT_SIZE);
2 pj 156
#endif
40 pj 157
  init_fpu();
158
 
159
 
160
        /* ll_mem_init must be explicitelly called by program... */
161
#if 0
162
        /* Get info about extended memory! We suppose that X has loaded */
163
        /* there the application; if you switch to DOS memory, then you */
164
        /* have to change the stuff in order it works; check X_...  for */
165
        /* details.                                                     */
166
        X_meminfo(&b,&s,NULL,NULL);
167
        base = (BYTE *)b;
168
        #ifdef __MEM_DEBUG__
169
        message("PM Free Mem Base         : %lx\n",b);
170
        message("PM null addr (0L)        : %lx\n",appl2linear((void *)0L));
171
        message("PM Free Mem Base (Cnvrtd): %lp\n",base);
172
        #endif
173
        ll_mem_init(base,s);
174
        #ifdef __MEM_DEBUG__
175
        ll_mem_dump();
176
        #endif
2 pj 177
#endif
178
 
179
 
40 pj 180
        return p;
2 pj 181
}
182
 
183
void abort_tail(int code)
184
{
40 pj 185
        message("ABORT %d !!!",code);
120 giacomo 186
        restore_CMOS();
187
        l1_end();
40 pj 188
        sti();
189
        l1_exit(1);
2 pj 190
}
191
 
192
void ll_end(void)
193
{
120 giacomo 194
        restore_CMOS();
40 pj 195
        l1_end();
2 pj 196
}
40 pj 197