source: anotherchoice/tags/jsp-1.4.4-full-UTF8/config/ia32/cpu_config.c@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 6.5 KB
Line 
1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2000,2001 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2002 by Monami software, Limited Partners.
9 * Copyright (C) 2008- by Monami Software Limited Partnership, JAPAN
10 *
11 * 上記著作権者
12は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
13 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
14 * 変・再é…
15å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
16 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
17 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
18 * スコード中に含まれていること.
19 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
20 * 用できる形で再é…
21å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
22å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
23 * 者
24マニュアルなど)に,上記の著作権表示,この利用条件および下記
25 * の無保証規定を掲載すること.
26 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
27 * 用できない形で再é…
28å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
29 * と.
30 * (a) 再é…
31å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
32マニュアルなど)に,上記の著
33 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
34 * (b) 再é…
35å¸ƒã®å½¢æ…
36‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
37 * 報告すること.
38 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
39 * 害からも,上記著作権者
40およびTOPPERSプロジェクトをå…
41è²¬ã™ã‚‹ã“と.
42 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
43 * 由に基づく請求からも,上記著作権者
44およびTOPPERSプロジェクトを
45 * å…
46è²¬ã™ã‚‹ã“と.
47 *
48 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
49お
50 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
51 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
52 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
53 * の責任を負わない.
54 *
55 * @(#) $Id: cpu_config.c,v 1.1 2004/07/21 02:49:36 monaka Exp $
56 */
57
58/*
59 * プロセッサ依存モジュール(i386用)
60 */
61
62#include "jsp_kernel.h"
63#include "check.h"
64#include "task.h"
65#include <i386.h>
66
67UW nest = 0; /* 割り込みネスト回数 */
68FP exc_table[0x20]; /* CPU例外ハンドラのテーブル */
69
70static SEGDESC gdt[3]; /* グローバルディスクリプタテーブル */
71static GATEDESC idt[256]; /* 割り込みディスクリプタテーブル */
72
73/*
74 * プロセッサ依存の初期化
75 */
76void
77cpu_initialize()
78{
79 DESCPTR desc_ptr;
80
81 /* Flat model */
82 set_segment_descriptor(0, 0x0, 0x00000, 0x00, 0);
83 set_segment_descriptor(1, 0x0, 0xfffff, I386_TYPE_SEG_CODE | I386_TYPE_SEG_READABLE, 0);
84 set_segment_descriptor(2, 0x0, 0xfffff, I386_TYPE_SEG_DATA | I386_TYPE_SEG_WRITEABLE, 0);
85
86 desc_ptr.limit = sizeof(gdt) - 1;
87 desc_ptr.base = (unsigned)gdt;
88
89 Asm("movl %0, %%eax": : "g"(&desc_ptr) : "eax");
90 Asm("lgdt (%eax) \n"
91 "ljmp $0x8, $csinit \n" /* パイプラインにå…
92ˆèª­ã¿ã—た命令をクリアする */
93 "csinit: \n"
94 "movw $0x10, %ax \n"
95 "movw %ax, %ds \n"
96 "movw %ax, %es \n"
97 "movw %ax, %fs \n"
98 "movw %ax, %gs \n"
99 "movw %ax, %ss");
100
101 set_gate_descriptor( 0, 0x8, exception0, I386_TYPE_GATE_INTR, 0);
102 set_gate_descriptor( 1, 0x8, exception1, I386_TYPE_GATE_INTR, 0);
103 set_gate_descriptor( 2, 0x8, exception2, I386_TYPE_GATE_INTR, 0);
104 set_gate_descriptor( 3, 0x8, exception3, I386_TYPE_GATE_INTR, 0);
105 set_gate_descriptor( 4, 0x8, exception4, I386_TYPE_GATE_INTR, 0);
106 set_gate_descriptor( 5, 0x8, exception5, I386_TYPE_GATE_INTR, 0);
107 set_gate_descriptor( 6, 0x8, exception6, I386_TYPE_GATE_INTR, 0);
108 set_gate_descriptor( 7, 0x8, exception7, I386_TYPE_GATE_INTR, 0);
109 set_gate_descriptor( 8, 0x8, exception8, I386_TYPE_GATE_INTR, 0);
110 set_gate_descriptor( 9, 0x8, exception9, I386_TYPE_GATE_INTR, 0);
111 set_gate_descriptor(10, 0x8, exception10, I386_TYPE_GATE_INTR, 0);
112 set_gate_descriptor(11, 0x8, exception11, I386_TYPE_GATE_INTR, 0);
113 set_gate_descriptor(12, 0x8, exception12, I386_TYPE_GATE_INTR, 0);
114 set_gate_descriptor(13, 0x8, exception13, I386_TYPE_GATE_INTR, 0);
115 set_gate_descriptor(14, 0x8, exception14, I386_TYPE_GATE_INTR, 0);
116 set_gate_descriptor(16, 0x8, exception16, I386_TYPE_GATE_INTR, 0);
117 set_gate_descriptor(17, 0x8, exception17, I386_TYPE_GATE_INTR, 0);
118 set_gate_descriptor(18, 0x8, exception18, I386_TYPE_GATE_INTR, 0);
119 set_gate_descriptor(19, 0x8, exception19, I386_TYPE_GATE_INTR, 0);
120
121 desc_ptr.limit = sizeof(idt) - 1;
122 desc_ptr.base = (unsigned)idt;
123
124 Asm("movl %0, %%eax " : : "g"(&desc_ptr) : "eax");
125 Asm("lidt (%eax) ");
126
127}
128
129/*
130 * プロセッサ依存の終了処理
131 */
132void
133cpu_terminate()
134{
135}
136
137
138/*
139 * i386セグメントデスクリプタの設定
140 */
141void
142set_segment_descriptor(int sel, unsigned addr, unsigned limit, unsigned type, unsigned dpl)
143{
144 SEGDESC *desc;
145 desc = &gdt[sel];
146 desc->base_L = (addr & 0xffffff);
147 desc->base_H = ((addr >> 24) & 0xff);
148 desc->limit_L = (limit & 0xffff);
149 desc->limit_H = ((limit >> 16) & 0xf);
150 desc->type = (type & 0xf);
151 desc->s = 1; /* code/data segment */
152 desc->dpl = dpl;
153 desc->p = 1; /* segment is existing */
154 desc->avl = 0; /* unused */
155 desc->x = 0; /* reserved */
156 desc->db = 1; /* 32bits segment */
157 desc->g = 1; /* 4KB limits */
158}
159
160void
161set_gate_descriptor(int sel, unsigned selector, void *func, unsigned type, unsigned dpl)
162{
163 GATEDESC *desc;
164 desc = &idt[sel];
165 desc->offset_L = ((unsigned)func & 0xffff);
166 desc->offset_H = (((unsigned)func >> 16) & 0xffff);
167 desc->selector = selector;
168 desc->copy = 0;
169 desc->type = type;
170 desc->s = 0;
171 desc->dpl = dpl;
172 desc->p = 1;
173}
174
175
176void
177define_exc(EXCNO excno, FP exchdr)
178{
179#if 0
180 if (inhno >= 0x20 || inthdr == NULL)
181 {
182 return; /*??? Should I generate assertion? */
183 }
184#endif
185 exc_table[excno] = exchdr;
186}
Note: See TracBrowser for help on using the repository browser.