1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2004 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
8 | *
|
---|
9 | * ä¸è¨è使¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
11 | * ã«ãã£ã¦å
|
---|
12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
15 | å¸ï¼ä»¥ä¸ï¼
|
---|
16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
21 | * ç¨ã§ããå½¢ã§åé
|
---|
22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
24 | * è
|
---|
25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
30 | * ã¨ï¼
|
---|
31 | * (a) åé
|
---|
32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
34 | * 使¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
35 | * (b) åé
|
---|
36 | å¸ã®å½¢æ
|
---|
37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
38 | * å ±åãããã¨ï¼
|
---|
39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
40 | * 害ãããï¼ä¸è¨è使¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
42 | 責ãããã¨ï¼
|
---|
43 | *
|
---|
44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨è使¨©è
|
---|
45 | ã
|
---|
46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæå®³ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
49 | *
|
---|
50 | * @(#) $Id: cpu_config.c,v 1.3 2004/09/03 17:32:25 honda Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * ããã»ããµä¾åã¢ã¸ã¥ã¼ã«ï¼Nios2ç¨ï¼
|
---|
55 | */
|
---|
56 | #include "jsp_kernel.h"
|
---|
57 | #include "check.h"
|
---|
58 | #include "task.h"
|
---|
59 | #include <nios2.h>
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * å²ãè¾¼ã¿ãã³ãã©/ããããã¹ã¯ãã¼ãã«
|
---|
63 | */
|
---|
64 | FP int_handler_table[MAX_INT_NUM];
|
---|
65 | UW int_bit_table[MAX_INT_NUM];
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * CPUä¾å¤ãã³ãã©ãã¼ãã«
|
---|
69 | */
|
---|
70 | FP exc_handler_table[MAX_EXC_NUM];
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * å²ãè¾¼ã¿ã®ãã¹ãåæ°ã®ã«ã¦ã³ã
|
---|
74 | * ã«ã¼ãã«èµ·åæã¯ã¿ã¹ã¯ç¬ç«é¨ã¨ã¿ãªããã1ã§åæåãã
|
---|
75 | */
|
---|
76 | UW interrupt_count = 1;
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * ããã»ããµä¾åã®åæå
|
---|
80 | */
|
---|
81 | void
|
---|
82 | cpu_initialize()
|
---|
83 | {
|
---|
84 | int i;
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * int_handler_table[],int_plevel_table[]ã®åæå
|
---|
88 | * æªç»é²ã®å²è¾¼ã¿çºçæã«cpu_interrup()ãå¼ã³åºãããããã«
|
---|
89 | * no_reg_interrup()ãç»é²ãã
|
---|
90 | */
|
---|
91 | for(i = 0; i < MAX_INT_NUM; i++){
|
---|
92 | int_handler_table[i] = no_reg_interrupt;
|
---|
93 | int_bit_table[i] = 1 << i; /* ããããã¿ã¼ã³ã®çæ */
|
---|
94 | }
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * CPUä¾å¤ãã³ãã©ãã¼ãã«
|
---|
98 | */
|
---|
99 | for(i = 0; i < MAX_EXC_NUM; i++){
|
---|
100 | exc_handler_table[i] = no_reg_exception;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * ããã»ããµä¾åã®çµäºå¦ç
|
---|
106 | * å²è¾¼ã¿ç¦æ¢
|
---|
107 | */
|
---|
108 | void
|
---|
109 | cpu_terminate()
|
---|
110 | {
|
---|
111 | disint();
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * å²è¾¼ã¿ã®è¨±å¯/ç¦æ¢
|
---|
117 | */
|
---|
118 | SYSCALL ER
|
---|
119 | ena_int(INTNO intno){
|
---|
120 | set_ienable((1 << intno) | current_ienable());
|
---|
121 | }
|
---|
122 |
|
---|
123 | SYSCALL ER
|
---|
124 | dis_int(INTNO intno){
|
---|
125 | set_ienable(~(1 << intno) & current_ienable());
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * æªç»é²ã®å²è¾¼ã¿ãçºçããå ´åã«å¼ã³åºããã
|
---|
131 | */
|
---|
132 | void
|
---|
133 | no_reg_interrupt(void)
|
---|
134 | {
|
---|
135 | syslog(LOG_EMERG, "Unregisted Interrupt Occur!");
|
---|
136 | while(1);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /*
|
---|
140 | * æªç»é²ã®ä¾å¤ãçºçããå ´åã«å¼ã³åºããã
|
---|
141 | */
|
---|
142 | void
|
---|
143 | no_reg_exception(void)
|
---|
144 | {
|
---|
145 | syslog(LOG_EMERG, "Unregisted Exception Occur!");
|
---|
146 | while(1);
|
---|
147 | }
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * å²è¾¼ã¿è¦å ã®å¤å®ã¨å²è¾¼ã¿ãã³ãã©ã®å¼ã³åºã
|
---|
151 | */
|
---|
152 | void
|
---|
153 | int_handler_call(){
|
---|
154 | UW status;
|
---|
155 | UW mask;
|
---|
156 | int i;
|
---|
157 |
|
---|
158 | interrupt_count++;
|
---|
159 | status = current_ipending();
|
---|
160 | for(i = 0; i < 32; i++){
|
---|
161 | if((status & (1 << i)) != 0x00){
|
---|
162 | mask = current_ienable();
|
---|
163 | set_ienable(~int_bit_table[i] & mask);
|
---|
164 |
|
---|
165 | enaint();
|
---|
166 | (int_handler_table[i])();
|
---|
167 | disint();
|
---|
168 |
|
---|
169 | set_ienable(mask);
|
---|
170 | break;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | interrupt_count--;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*
|
---|
177 | * ä¾å¤ã®å¤å®ã¨CPUä¾å¤ãã³ãã©ã®å¼ã³åºã
|
---|
178 | * ç¾å¨ã¯æªå®è£
|
---|
179 | å½ä»¤ä¾å¤ã®ã¿ããµãã¼ã
|
---|
180 | */
|
---|
181 | void
|
---|
182 | exc_handler_call(VP p_excinf){
|
---|
183 | interrupt_count++;
|
---|
184 |
|
---|
185 | enaint();
|
---|
186 | (exc_handler_table[0])(p_excinf);
|
---|
187 | disint();
|
---|
188 |
|
---|
189 | interrupt_count--;
|
---|
190 | }
|
---|