Subversion Repositories shark

Rev

Rev 1621 | 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
 
1621 fabio 24
#include <arch/i386/stdlib.h>
2 pj 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
 
1001 trimarchi 49
void debug_info(void) {
50
  static DWORD fault_ip;
51
  static DWORD fault_cs;
52
  static DWORD error_code;
53
  static DWORD fault_eflag;
54
  static DWORD sp;
55
  static DWORD fault_sp;
56
  static DWORD data0;
57
  static DWORD data1;
58
  static DWORD data2;
59
  static DWORD sdata4;
60
  static DWORD sdata8;
61
 
62
  asm (" movl %%esp,%0\n\t":"=r"(sp));
63
  asm (" movl -8(%%ebp),%0\n\t":"=r"(sdata8));
64
  asm (" movl -4(%%ebp),%0\n\t":"=r"(sdata4));
65
  asm (" movl 0(%%ebp),%0\n\t":"=r"(data0));
66
  asm (" movl 4(%%ebp),%0\n\t":"=r"(error_code));
67
  asm (" movl 8(%%ebp),%0\n\t":"=r"(fault_ip));    
68
  asm (" movl 12(%%ebp),%0\n\t":"=r"(fault_cs));        
69
  asm (" movl 16(%%ebp),%0\n\t":"=r"(fault_eflag));
70
  asm (" movl 20(%%ebp),%0\n\t":"=r"(fault_sp));
71
  asm (" movl 24(%%ebp),%0\n\t":"=r"(data1));
72
  message(":F -8: %lx:", sdata8);  
73
  message(":F -4: %lx:", sdata4);  
74
  message(":F 0: %lx:", data0);
75
  message(":F ec/4: %lx:", error_code);
76
  message(":F ip/8: %lx:", fault_ip);
77
  message(":F cs/12 : %lx:", fault_cs);
78
  message(":F eflag/16 : %lx:", fault_eflag);
79
  message(":F sp/20    : %lx:", fault_sp);
80
  message(":F 24    : %lx:", data1);
81
 
82
}
83
 
84
 
2 pj 85
void ll_exc_hook(int i)
86
{
1001 trimarchi 87
 
88
  static char *exc_mess[] = {
2 pj 89
        "#Division by 0",
90
        "#Debug fault",
91
        "#NMI detected",
92
        "#Breakpoint trap",
93
        "#Overflow detected on INTO",
94
        "#BOUND limit exceeded",
95
        "*Unvalid opcode",
40 pj 96
        "1FPU context switch", /* Handled in the llCtx.Asm/S File */
2 pj 97
        "*Double defect",
98
        "#INTEL reserved",
99
        "*Unvalid TSS",
100
        "*Segment not present",
101
        "*Stack exception",
102
        "*General protection fault",
103
        "#Page fault",
104
        "#INTEL reserved",
105
        "2Coprocessor error"
40 pj 106
        };
2 pj 107
 
40 pj 108
        static int exc_code[] = {
2 pj 109
        DIV_BY_0, NMI_EXC, DEBUG_EXC, BREAKPOINT_EXC,
110
        HW_FAULT, HW_FAULT, HW_FAULT,
40 pj 111
        0,              /* This is the FPU ctx Switch */
2 pj 112
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
113
        HW_FAULT, HW_FAULT, HW_FAULT, HW_FAULT,
114
        MATH_EXC
40 pj 115
        };
2 pj 116
 
40 pj 117
        char code = *exc_mess[i];
118
        #ifdef __LL_DEBUG__
119
        extern long int ndp_called,ndp_switched;
120
        extern wu_called;
121
        extern ai_called;
122
        extern DWORD *smain;
123
        #endif
2 pj 124
 
1001 trimarchi 125
 
126
 
127
        /* Math error! FPU has to be acknowledgded */
40 pj 128
        if (code == '2') ll_out(0x0F0,0);
129
 
130
        message("Exception %d occurred\n", i);
131
        message("%s\n", &exc_mess[i][1]);
132
 
133
 
134
        #ifdef __LL_DEBUG__
135
        if (code == '*') {
136
                /* Dump additional info */
137
                message("DS:%nx CS:%nx\n",get_DS(),get_CS());
138
                /* message("WU : %d AI : %d\n",wu_called,ai_called); */
139
                message("Actual stack : %x\n",get_SP());
140
                /* message("Main stack : %p\n",smain); */
141
                dump_TSS(get_TR());
142
        }
143
        #endif
144
        /* halt(); */
1001 trimarchi 145
 
146
        message("Actual stack : %x\n",get_SP());
147
 
148
        dump_TSS(get_TR());              
149
 
40 pj 150
        ll_abort(exc_code[i]);
2 pj 151
}
152
 
153
void *ll_init(void)
154
{
40 pj 155
        void *p;
156
        int i;
157
        LIN_ADDR b;
158
/*
159
        DWORD s;
160
        BYTE *base;
161
*/
162
  TSS dummy_tss;      /* Very dirty, but we need it, in order to
163
                         get an initial value for the FPU
164
                         context...
165
                      */
166
 
167
 
168
        p = l1_init();
169
        /* First of all, init the exc and irq tables... */
170
        irq_init();
171
        for(i = 0; i < 32; i++) {
2 pj 172
 
173
/* Warning!!! The hw exceptions should be 32.... Fix it!!! */
40 pj 174
 
2 pj 175
/*
176
                ll_irq_table[i] = (DWORD)act_int;
177
                ll_exc_table[i] = (DWORD)ll_exc_hook;
178
*/
40 pj 179
                l1_exc_bind(i, ll_exc_hook);
180
        }
181
        for(i = 0; i < 16; i++) {
182
                void act_int(int i);
183
                l1_irq_bind(i, act_int);
184
        }
2 pj 185
 
40 pj 186
 
187
  /* Init TSS table & put the corrispondent selectors into GDT */
188
  TSS_control[TSSMain] |= TSS_USED;
189
  for (i = 0; i < TSSMax; i++) {
190
    /* b = appl2linear(&TSS_table[i]); */
191
    b = (LIN_ADDR)(&TSS_table[i]);
192
    GDT_place(TSSindex2sel(i),(DWORD)b,sizeof(TSS),FREE_TSS386, GRAN_16);
193
  }
194
 
2 pj 195
#if 0
40 pj 196
  ll_FPU_save();
197
  memcpy(ll_FPU_stdctx,ll_FPU_savearea,FPU_CONTEXT_SIZE);
198
#else
199
  save_fpu(&dummy_tss); /* OK???*/
200
  memcpy(ll_FPU_stdctx, dummy_tss.ctx_FPU, FPU_CONTEXT_SIZE);
2 pj 201
#endif
40 pj 202
  init_fpu();
203
 
204
 
205
        /* ll_mem_init must be explicitelly called by program... */
206
#if 0
207
        /* Get info about extended memory! We suppose that X has loaded */
208
        /* there the application; if you switch to DOS memory, then you */
209
        /* have to change the stuff in order it works; check X_...  for */
210
        /* details.                                                     */
211
        X_meminfo(&b,&s,NULL,NULL);
212
        base = (BYTE *)b;
213
        #ifdef __MEM_DEBUG__
214
        message("PM Free Mem Base         : %lx\n",b);
215
        message("PM null addr (0L)        : %lx\n",appl2linear((void *)0L));
216
        message("PM Free Mem Base (Cnvrtd): %lp\n",base);
217
        #endif
218
        ll_mem_init(base,s);
219
        #ifdef __MEM_DEBUG__
220
        ll_mem_dump();
221
        #endif
2 pj 222
#endif
223
 
224
 
40 pj 225
        return p;
2 pj 226
}
227
 
228
void abort_tail(int code)
229
{
40 pj 230
        message("ABORT %d !!!",code);
301 giacomo 231
        ll_restore_adv();
120 giacomo 232
        l1_end();
40 pj 233
        sti();
234
        l1_exit(1);
2 pj 235
}
236
 
237
void ll_end(void)
238
{
301 giacomo 239
        ll_restore_adv();
40 pj 240
        l1_end();
2 pj 241
}
40 pj 242