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