Subversion Repositories shark

Rev

Rev 3 | Rev 619 | 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
/*      Xlib initialization code        */
23
 
24
#include <ll/i386/mem.h>
25
#include <ll/i386/cons.h>
26
#include <ll/i386/mb-info.h>
27
#include <ll/i386/error.h>
28
#include <ll/i386/pit.h>
29
#include <ll/i386/pic.h>
30
 
31
#include <ll/i386/tss-ctx.h>
32
#include <ll/i386/hw-arch.h>
33
 
40 pj 34
FILE(X-Init);
2 pj 35
 
40 pj 36
extern DWORD ll_irq_table[256];
2 pj 37
 
38
#ifdef __VIRCSW__
39
int activeInt = 0;
40
#endif
41
 
42
/* Assembly external routines!      */
43
/* Setup the TR register of the 80386, to initialize context switch */
44
 
45
extern void init_TR(WORD v);
40 pj 46
TSS main_tss;
2 pj 47
 
40 pj 48
/* Architecture definition */
49
LL_ARCH ll_arch;
2 pj 50
 
40 pj 51
/* The following stuff is in llCxA.Asm/S    */
2 pj 52
 
53
static void dummyfun(int i)
54
{
40 pj 55
#if 0
56
  if (i < 32) {
57
    cputs("Unhandled Exc occured!!!\n");
58
  } else {
59
    cputs("Unhandled Int occured!!!\n");
60
  }
61
#else
2 pj 62
  message("Unhandled Exc or Int %d occured!!!\n", i);
40 pj 63
#endif
64
  halt();
2 pj 65
}
66
 
40 pj 67
void l1_int_bind(int i, void *f)
2 pj 68
{
40 pj 69
  ll_irq_table[i] = (DWORD)f;
2 pj 70
}
71
 
72
void *l1_init(void)
73
{
40 pj 74
  register int i;
75
  struct ll_cpuInfo cpuInfo;
76
  extern BYTE X86_fpu;
77
        LIN_ADDR b;
78
 
79
 
80
  for(i = 0; i < 256; i++) {
81
    ll_irq_table[i] = (DWORD)dummyfun;
82
  }
83
 
84
  X86_get_CPU(&cpuInfo);
85
  X86_get_FPU();
86
  ll_arch.x86.arch = __LL_ARCH__;
87
  ll_arch.x86.cpu = cpuInfo.X86_cpu;
88
  ll_arch.x86.fpu = X86_fpu;
89
  memcpy(&(ll_arch.x86.vendor), &(cpuInfo.X86_vendor_1), 12);
90
 
91
  /* TODO! Need to map featuresXXX & Signature onto ll_arch!  */
92
  /* TODO! Need to check for CPU bugs!!           */
93
 
2 pj 94
#ifdef __LL_DEBUG__
40 pj 95
  message("LL Architecture: %s\n", __LL_ARCH__);
96
  message("CPU : %u\nFPU : %u\n", cpuInfo.X86_cpu, X86_fpu);
97
  message("Signature : 0x%lx\nVendor: %s\n", cpuInfo.X86_signature,
98
          ll_arch.x86.vendor);
99
  message("Features #1: 0x%lx\n", cpuInfo.X86_IntelFeature_1);
100
  message("Features #2: 0x%lx\n", cpuInfo.X86_IntelFeature_2);
101
  message("Features #3: 0x%lx\n", cpuInfo.X86_StandardFeature);
102
#endif /* __LL_DEBUG__ */
103
 
104
  IDT_init();
2 pj 105
 
40 pj 106
  /* Init coprocessor & assign it to main() */
107
  /* OK... Now I know the sense of all this... :
108
     We need a initial value for the FPU context (to be used for creating
109
     new FPU contexts, as init value)...
110
     ... And we get it in this strange way!!!!
111
  */
112
  reset_fpu();
113
  init_fpu();
114
 
115
  /* Init PIC controllers & unmask timer */
116
  PIC_init();
117
 
118
  /* Set the TR initial value */
119
  b = (LIN_ADDR)(&main_tss);
120
  GDT_place(MAIN_SEL, (DWORD)b, sizeof(TSS), FREE_TSS386, GRAN_16);
121
  init_TR(MAIN_SEL);
122
 
123
  return mbi_address();
2 pj 124
}
125
 
126
 
127
void l1_end(void)
128
{
40 pj 129
  outp(0x21,0xFF);
130
  outp(0xA1,0xFF);
131
  /* Back to DOS settings */
132
  PIC_end();
133
  /* Reset the timer chip according DOS specification */
134
  /* Mode: Binary/Mode 3/16 bit Time_const/Counter 0 */
2 pj 135
#if 0
40 pj 136
  outp(0x43,0x36);
137
  /* Time_const = 65536; write 0 in CTR */
138
  outp(0x40,0);
139
  outp(0x40,0);
2 pj 140
#endif
40 pj 141
  pit_init(0, TMR_MD3, 0);    /* Timer 0, Mode 3, Time constant 0 */
142
  if(ll_arch.x86.cpu > 4) {    
143
    pit_init(1, TMR_MD2, 18);
144
  } else {
145
    pit_init(2, TMR_MD0, 0);
146
    outp(0x61, 0);              /* Stop channel 2 */
147
  }
2 pj 148
}