Subversion Repositories shark

Rev

Rev 1683 | 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;
648 mauro 76
  extern unsigned char X86_apic;
77
  extern unsigned char X86_tsc;
40 pj 78
  extern BYTE X86_fpu;
619 mauro 79
  LIN_ADDR b;
40 pj 80
 
81
  for(i = 0; i < 256; i++) {
82
    ll_irq_table[i] = (DWORD)dummyfun;
83
  }
84
 
85
  X86_get_CPU(&cpuInfo);
86
  X86_get_FPU();
87
  ll_arch.x86.arch = __LL_ARCH__;
88
  ll_arch.x86.cpu = cpuInfo.X86_cpu;
89
  ll_arch.x86.fpu = X86_fpu;
90
  memcpy(&(ll_arch.x86.vendor), &(cpuInfo.X86_vendor_1), 12);
91
 
704 giacomo 92
  X86_apic = (cpuInfo.X86_StandardFeature>>9) & 1;
93
  X86_tsc  = (cpuInfo.X86_StandardFeature>>4) & 1;
619 mauro 94
 
40 pj 95
  /* TODO! Need to map featuresXXX & Signature onto ll_arch!  */
96
  /* TODO! Need to check for CPU bugs!!           */
97
 
2 pj 98
#ifdef __LL_DEBUG__
40 pj 99
  message("LL Architecture: %s\n", __LL_ARCH__);
100
  message("CPU : %u\nFPU : %u\n", cpuInfo.X86_cpu, X86_fpu);
101
  message("Signature : 0x%lx\nVendor: %s\n", cpuInfo.X86_signature,
102
          ll_arch.x86.vendor);
103
  message("Features #1: 0x%lx\n", cpuInfo.X86_IntelFeature_1);
104
  message("Features #2: 0x%lx\n", cpuInfo.X86_IntelFeature_2);
105
  message("Features #3: 0x%lx\n", cpuInfo.X86_StandardFeature);
619 mauro 106
  message("Has APIC: %s\n", X86_apic);
107
  message("Has TSC: %s\n", X86_tsc);
40 pj 108
#endif /* __LL_DEBUG__ */
619 mauro 109
 
40 pj 110
  IDT_init();
2 pj 111
 
40 pj 112
  /* Init coprocessor & assign it to main() */
113
  /* OK... Now I know the sense of all this... :
114
     We need a initial value for the FPU context (to be used for creating
115
     new FPU contexts, as init value)...
116
     ... And we get it in this strange way!!!!
117
  */
118
  reset_fpu();
119
  init_fpu();
120
 
121
  /* Init PIC controllers & unmask timer */
122
  PIC_init();
123
 
124
  /* Set the TR initial value */
125
  b = (LIN_ADDR)(&main_tss);
126
  GDT_place(MAIN_SEL, (DWORD)b, sizeof(TSS), FREE_TSS386, GRAN_16);
127
  init_TR(MAIN_SEL);
128
 
129
  return mbi_address();
2 pj 130
}
131
 
132
 
133
void l1_end(void)
134
{
40 pj 135
  outp(0x21,0xFF);
136
  outp(0xA1,0xFF);
137
  /* Back to DOS settings */
138
  PIC_end();
139
  /* Reset the timer chip according DOS specification */
140
  /* Mode: Binary/Mode 3/16 bit Time_const/Counter 0 */
2 pj 141
#if 0
40 pj 142
  outp(0x43,0x36);
143
  /* Time_const = 65536; write 0 in CTR */
144
  outp(0x40,0);
145
  outp(0x40,0);
2 pj 146
#endif
40 pj 147
  pit_init(0, TMR_MD3, 0);    /* Timer 0, Mode 3, Time constant 0 */
148
  if(ll_arch.x86.cpu > 4) {    
149
    pit_init(1, TMR_MD2, 18);
150
  } else {
151
    pit_init(2, TMR_MD0, 0);
152
    outp(0x61, 0);              /* Stop channel 2 */
153
  }
2 pj 154
}