Rev 3675 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3675 | Rev 4377 | ||
---|---|---|---|
Line 31... | Line 31... | ||
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch.h> |
35 | #include <arch.h> |
36 | #include <arch/ski/ski.h> |
36 | #include <arch/drivers/ski.h> |
37 | #include <arch/drivers/it.h> |
37 | #include <arch/drivers/it.h> |
38 | #include <arch/interrupt.h> |
38 | #include <arch/interrupt.h> |
39 | #include <arch/barrier.h> |
39 | #include <arch/barrier.h> |
40 | #include <arch/asm.h> |
40 | #include <arch/asm.h> |
41 | #include <arch/register.h> |
41 | #include <arch/register.h> |
Line 48... | Line 48... | ||
48 | #include <userspace.h> |
48 | #include <userspace.h> |
49 | #include <console/console.h> |
49 | #include <console/console.h> |
50 | #include <proc/uarg.h> |
50 | #include <proc/uarg.h> |
51 | #include <syscall/syscall.h> |
51 | #include <syscall/syscall.h> |
52 | #include <ddi/irq.h> |
52 | #include <ddi/irq.h> |
53 | #include <ddi/device.h> |
- | |
54 | #include <arch/drivers/ega.h> |
- | |
55 | #include <arch/bootinfo.h> |
53 | #include <arch/bootinfo.h> |
- | 54 | #include <genarch/drivers/legacy/ia32/io.h> |
|
- | 55 | #include <genarch/drivers/ega/ega.h> |
|
56 | #include <genarch/kbd/i8042.h> |
56 | #include <genarch/kbrd/kbrd.h> |
57 | #include <genarch/kbd/ns16550.h> |
57 | #include <genarch/srln/srln.h> |
- | 58 | #include <genarch/drivers/i8042/i8042.h> |
|
- | 59 | #include <genarch/drivers/ns16550/ns16550.h> |
|
- | 60 | #include <arch/drivers/kbd.h> |
|
58 | #include <smp/smp.h> |
61 | #include <smp/smp.h> |
59 | #include <smp/ipi.h> |
62 | #include <smp/ipi.h> |
60 | #include <arch/atomic.h> |
63 | #include <arch/atomic.h> |
61 | #include <panic.h> |
64 | #include <panic.h> |
62 | #include <print.h> |
65 | #include <print.h> |
63 | #include <sysinfo/sysinfo.h> |
66 | #include <sysinfo/sysinfo.h> |
- | 67 | #include <string.h> |
|
64 | 68 | ||
65 | /*NS16550 as a COM 1*/ |
69 | /* NS16550 as a COM 1 */ |
66 | #define NS16550_IRQ (4+LAGACY_INTERRUPT_BASE) |
70 | #define NS16550_IRQ (4 + LEGACY_INTERRUPT_BASE) |
67 | #define NS16550_PORT 0x3f8 |
- | |
68 | 71 | ||
69 | bootinfo_t *bootinfo; |
72 | bootinfo_t *bootinfo; |
70 | 73 | ||
71 | static uint64_t iosapic_base=0xfec00000; |
74 | static uint64_t iosapic_base = 0xfec00000; |
72 | 75 | ||
- | 76 | /** Performs ia64-specific initialization before main_bsp() is called. */ |
|
73 | void arch_pre_main(void) |
77 | void arch_pre_main(void) |
74 | { |
78 | { |
75 | /* Setup usermode init tasks. */ |
79 | /* Setup usermode init tasks. */ |
76 | 80 | ||
77 | //#ifdef I460GX |
- | |
78 | unsigned int i; |
81 | unsigned int i; |
79 | 82 | ||
80 | init.cnt = bootinfo->taskmap.count; |
83 | init.cnt = bootinfo->taskmap.count; |
81 | 84 | ||
82 | for (i = 0; i < init.cnt; i++) { |
85 | for (i = 0; i < init.cnt; i++) { |
- | 86 | init.tasks[i].addr = |
|
83 | init.tasks[i].addr = ((unsigned long) bootinfo->taskmap.tasks[i].addr) | VRN_MASK; |
87 | ((unsigned long) bootinfo->taskmap.tasks[i].addr) | |
- | 88 | VRN_MASK; |
|
84 | init.tasks[i].size = bootinfo->taskmap.tasks[i].size; |
89 | init.tasks[i].size = bootinfo->taskmap.tasks[i].size; |
- | 90 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN, |
|
- | 91 | bootinfo->taskmap.tasks[i].name); |
|
85 | } |
92 | } |
86 | /* |
- | |
87 | #else |
- | |
88 | init.cnt = 8; |
- | |
89 | init.tasks[0].addr = INIT0_ADDRESS; |
- | |
90 | init.tasks[0].size = INIT0_SIZE; |
- | |
91 | init.tasks[1].addr = INIT0_ADDRESS + 0x400000; |
- | |
92 | init.tasks[1].size = INIT0_SIZE; |
- | |
93 | init.tasks[2].addr = INIT0_ADDRESS + 0x800000; |
- | |
94 | init.tasks[2].size = INIT0_SIZE; |
- | |
95 | init.tasks[3].addr = INIT0_ADDRESS + 0xc00000; |
- | |
96 | init.tasks[3].size = INIT0_SIZE; |
- | |
97 | init.tasks[4].addr = INIT0_ADDRESS + 0x1000000; |
- | |
98 | init.tasks[4].size = INIT0_SIZE; |
- | |
99 | init.tasks[5].addr = INIT0_ADDRESS + 0x1400000; |
- | |
100 | init.tasks[5].size = INIT0_SIZE; |
- | |
101 | init.tasks[6].addr = INIT0_ADDRESS + 0x1800000; |
- | |
102 | init.tasks[6].size = INIT0_SIZE; |
- | |
103 | init.tasks[7].addr = INIT0_ADDRESS + 0x1c00000; |
- | |
104 | init.tasks[7].size = INIT0_SIZE; |
- | |
105 | #endif*/ |
- | |
106 | } |
93 | } |
107 | 94 | ||
108 | void arch_pre_mm_init(void) |
95 | void arch_pre_mm_init(void) |
109 | { |
96 | { |
- | 97 | /* |
|
110 | /* Set Interruption Vector Address (i.e. location of interruption vector table). */ |
98 | * Set Interruption Vector Address (i.e. location of interruption vector |
- | 99 | * table). |
|
- | 100 | */ |
|
111 | iva_write((uintptr_t) &ivt); |
101 | iva_write((uintptr_t) &ivt); |
112 | srlz_d(); |
102 | srlz_d(); |
113 | 103 | ||
114 | } |
104 | } |
115 | 105 | ||
116 | static void iosapic_init(void) |
106 | static void iosapic_init(void) |
117 | { |
107 | { |
118 | - | ||
119 | uint64_t IOSAPIC = PA2KA((unative_t)(iosapic_base))|FW_OFFSET; |
108 | uint64_t IOSAPIC = PA2KA((unative_t)(iosapic_base)) | FW_OFFSET; |
120 | int i; |
109 | int i; |
121 | 110 | ||
122 | int myid,myeid; |
111 | int myid, myeid; |
123 | 112 | ||
124 | myid=ia64_get_cpu_id(); |
113 | myid = ia64_get_cpu_id(); |
125 | myeid=ia64_get_cpu_eid(); |
114 | myeid = ia64_get_cpu_eid(); |
126 | 115 | ||
127 | for(i=0;i<16;i++) |
116 | for (i = 0; i < 16; i++) { |
128 | { |
117 | if (i == 2) |
129 | - | ||
130 | if(i==2) continue; //Disable Cascade interrupt |
118 | continue; /* Disable Cascade interrupt */ |
131 | ((uint32_t*)(IOSAPIC+0x00))[0]=0x10+2*i; |
119 | ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i; |
132 | srlz_d(); |
120 | srlz_d(); |
133 | ((uint32_t*)(IOSAPIC+0x10))[0]=LAGACY_INTERRUPT_BASE+i; |
121 | ((uint32_t *)(IOSAPIC + 0x10))[0] = LEGACY_INTERRUPT_BASE + i; |
134 | srlz_d(); |
122 | srlz_d(); |
135 | ((uint32_t*)(IOSAPIC+0x00))[0]=0x10+2*i+1; |
123 | ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i + 1; |
136 | srlz_d(); |
124 | srlz_d(); |
137 | ((uint32_t*)(IOSAPIC+0x10))[0]=myid<<(56-32) | myeid<<(48-32); |
125 | ((uint32_t *)(IOSAPIC + 0x10))[0] = myid << (56 - 32) | |
- | 126 | myeid << (48 - 32); |
|
138 | srlz_d(); |
127 | srlz_d(); |
139 | } |
128 | } |
140 | 129 | ||
141 | } |
130 | } |
142 | 131 | ||
143 | - | ||
144 | void arch_post_mm_init(void) |
132 | void arch_post_mm_init(void) |
145 | { |
133 | { |
146 | if(config.cpu_active==1) |
134 | if (config.cpu_active == 1) { |
147 | { |
- | |
148 | iosapic_init(); |
135 | iosapic_init(); |
149 | - | ||
150 | irq_init(INR_COUNT, INR_COUNT); |
136 | irq_init(INR_COUNT, INR_COUNT); |
151 | #ifdef SKI |
- | |
152 | ski_init_console(); |
- | |
153 | #else |
- | |
154 | ega_init(); |
- | |
155 | #endif |
- | |
156 | } |
137 | } |
157 | it_init(); |
138 | it_init(); |
158 | - | ||
159 | } |
139 | } |
160 | 140 | ||
161 | void arch_post_cpu_init(void) |
141 | void arch_post_cpu_init(void) |
162 | { |
142 | { |
163 | } |
143 | } |
164 | 144 | ||
165 | void arch_pre_smp_init(void) |
145 | void arch_pre_smp_init(void) |
166 | { |
146 | { |
167 | } |
147 | } |
168 | 148 | ||
169 | - | ||
170 | #ifdef I460GX |
- | |
171 | #define POLL_INTERVAL 50000 /* 50 ms */ |
- | |
172 | /** Kernel thread for polling keyboard. */ |
- | |
173 | static void i8042_kkbdpoll(void *arg) |
149 | void arch_post_smp_init(void) |
174 | { |
150 | { |
175 | while (1) { |
- | |
176 | #ifdef CONFIG_NS16550 |
151 | #ifdef MACHINE_ski |
177 | #ifndef CONFIG_NS16550_INTERRUPT_DRIVEN |
152 | ski_instance_t *ski_instance = skiin_init(); |
178 | ns16550_poll(); |
153 | if (ski_instance) { |
179 | #endif |
- | |
180 | #else |
- | |
181 | #ifndef CONFIG_I8042_INTERRUPT_DRIVEN |
154 | srln_instance_t *srln_instance = srln_init(); |
182 | i8042_poll(); |
155 | if (srln_instance) { |
183 | #endif |
156 | indev_t *sink = stdin_wire(); |
184 | #endif |
157 | indev_t *srln = srln_wire(srln_instance, sink); |
185 | thread_usleep(POLL_INTERVAL); |
158 | skiin_wire(ski_instance, srln); |
- | 159 | } |
|
186 | } |
160 | } |
187 | } |
161 | |
- | 162 | skiout_init(); |
|
188 | #endif |
163 | #endif |
189 | - | ||
190 | - | ||
191 | void end_of_irq_void(void *cir_arg __attribute__((unused)),inr_t inr __attribute__((unused))); |
- | |
192 | void end_of_irq_void(void *cir_arg __attribute__((unused)),inr_t inr __attribute__((unused))) |
- | |
193 | { |
- | |
194 | return; |
- | |
195 | } |
- | |
196 | - | ||
197 | - | ||
198 | void arch_post_smp_init(void) |
- | |
199 | { |
- | |
200 | - | ||
201 | { |
164 | |
202 | /* |
- | |
203 | * Create thread that polls keyboard. |
- | |
204 | */ |
- | |
205 | #ifdef SKI |
- | |
206 | thread_t *t; |
- | |
207 | t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
- | |
208 | if (!t) |
- | |
209 | panic("cannot create kkbdpoll\n"); |
- | |
210 | thread_ready(t); |
- | |
211 | #endif |
- | |
212 | - | ||
213 | #ifdef I460GX |
- | |
214 | devno_t kbd = device_assign_devno(); |
- | |
215 | /* keyboard controller */ |
- | |
216 | - | ||
217 | #ifdef CONFIG_NS16550 |
165 | #ifdef CONFIG_EGA |
218 | ns16550_init(kbd, NS16550_PORT, NS16550_IRQ,end_of_irq_void,NULL); // as a COM 1 |
- | |
219 | #else |
- | |
220 | devno_t mouse = device_assign_devno(); |
- | |
221 | i8042_init(kbd, IRQ_KBD, mouse, IRQ_MOUSE); |
166 | ega_init(EGA_BASE, EGA_VIDEORAM); |
222 | #endif |
167 | #endif |
- | 168 | ||
223 | thread_t *t; |
169 | #ifdef CONFIG_NS16550 |
- | 170 | ns16550_instance_t *ns16550_instance |
|
224 | t = thread_create(i8042_kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
171 | = ns16550_init((ns16550_t *) NS16550_BASE, NS16550_IRQ, NULL, NULL); |
225 | if (!t) |
172 | if (ns16550_instance) { |
226 | panic("cannot create kkbdpoll\n"); |
173 | srln_instance_t *srln_instance = srln_init(); |
227 | thread_ready(t); |
174 | if (srln_instance) { |
- | 175 | indev_t *sink = stdin_wire(); |
|
- | 176 | indev_t *srln = srln_wire(srln_instance, sink); |
|
- | 177 | ns16550_wire(ns16550_instance, srln); |
|
- | 178 | } |
|
- | 179 | } |
|
228 | 180 | ||
- | 181 | sysinfo_set_item_val("kbd", NULL, true); |
|
- | 182 | sysinfo_set_item_val("kbd.inr", NULL, NS16550_IRQ); |
|
- | 183 | sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550); |
|
- | 184 | sysinfo_set_item_val("kbd.address.physical", NULL, |
|
- | 185 | (uintptr_t) NS16550_BASE); |
|
- | 186 | sysinfo_set_item_val("kbd.address.kernel", NULL, |
|
- | 187 | (uintptr_t) NS16550_BASE); |
|
229 | #endif |
188 | #endif |
230 | 189 | ||
- | 190 | #ifdef CONFIG_I8042 |
|
- | 191 | i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD); |
|
- | 192 | if (i8042_instance) { |
|
- | 193 | kbrd_instance_t *kbrd_instance = kbrd_init(); |
|
- | 194 | if (kbrd_instance) { |
|
- | 195 | indev_t *sink = stdin_wire(); |
|
- | 196 | indev_t *kbrd = kbrd_wire(kbrd_instance, sink); |
|
- | 197 | i8042_wire(i8042_instance, kbrd); |
|
- | 198 | } |
|
231 | } |
199 | } |
232 | 200 | ||
- | 201 | sysinfo_set_item_val("kbd", NULL, true); |
|
- | 202 | sysinfo_set_item_val("kbd.inr", NULL, IRQ_KBD); |
|
- | 203 | sysinfo_set_item_val("kbd.type", NULL, KBD_LEGACY); |
|
- | 204 | sysinfo_set_item_val("kbd.address.physical", NULL, |
|
- | 205 | (uintptr_t) I8042_BASE); |
|
- | 206 | sysinfo_set_item_val("kbd.address.kernel", NULL, |
|
- | 207 | (uintptr_t) I8042_BASE); |
|
- | 208 | #endif |
|
- | 209 | ||
233 | sysinfo_set_item_val("ia64_iospace", NULL, true); |
210 | sysinfo_set_item_val("ia64_iospace", NULL, true); |
234 | sysinfo_set_item_val("ia64_iospace.address", NULL, true); |
211 | sysinfo_set_item_val("ia64_iospace.address", NULL, true); |
235 | sysinfo_set_item_val("ia64_iospace.address.virtual", NULL, IO_OFFSET); |
212 | sysinfo_set_item_val("ia64_iospace.address.virtual", NULL, IO_OFFSET); |
236 | - | ||
237 | - | ||
238 | - | ||
239 | - | ||
240 | - | ||
241 | } |
213 | } |
242 | 214 | ||
243 | 215 | ||
244 | /** Enter userspace and never return. */ |
216 | /** Enter userspace and never return. */ |
245 | void userspace(uspace_arg_t *kernel_uarg) |
217 | void userspace(uspace_arg_t *kernel_uarg) |
Line 247... | Line 219... | ||
247 | psr_t psr; |
219 | psr_t psr; |
248 | rsc_t rsc; |
220 | rsc_t rsc; |
249 | 221 | ||
250 | psr.value = psr_read(); |
222 | psr.value = psr_read(); |
251 | psr.cpl = PL_USER; |
223 | psr.cpl = PL_USER; |
252 | psr.i = true; /* start with interrupts enabled */ |
224 | psr.i = true; /* start with interrupts enabled */ |
253 | psr.ic = true; |
225 | psr.ic = true; |
254 | psr.ri = 0; /* start with instruction #0 */ |
226 | psr.ri = 0; /* start with instruction #0 */ |
255 | psr.bn = 1; /* start in bank 0 */ |
227 | psr.bn = 1; /* start in bank 0 */ |
256 | 228 | ||
257 | asm volatile ("mov %0 = ar.rsc\n" : "=r" (rsc.value)); |
229 | asm volatile ("mov %0 = ar.rsc\n" : "=r" (rsc.value)); |
258 | rsc.loadrs = 0; |
230 | rsc.loadrs = 0; |
259 | rsc.be = false; |
231 | rsc.be = false; |
260 | rsc.pl = PL_USER; |
232 | rsc.pl = PL_USER; |
261 | rsc.mode = 3; /* eager mode */ |
233 | rsc.mode = 3; /* eager mode */ |
262 | 234 | ||
263 | switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry, |
235 | switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry, |
264 | ((uintptr_t) kernel_uarg->uspace_stack)+PAGE_SIZE-ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT), |
236 | ((uintptr_t) kernel_uarg->uspace_stack) + PAGE_SIZE - |
265 | ((uintptr_t) kernel_uarg->uspace_stack)+PAGE_SIZE, |
237 | ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT), |
266 | (uintptr_t) kernel_uarg->uspace_uarg, |
238 | ((uintptr_t) kernel_uarg->uspace_stack) + PAGE_SIZE, |
267 | psr.value, rsc.value); |
239 | (uintptr_t) kernel_uarg->uspace_uarg, psr.value, rsc.value); |
268 | 240 | ||
269 | while (1) { |
241 | while (1) |
270 | ; |
242 | ; |
271 | } |
- | |
272 | } |
243 | } |
273 | 244 | ||
274 | /** Set thread-local-storage pointer. |
245 | /** Set thread-local-storage pointer. |
275 | * |
246 | * |
276 | * We use r13 (a.k.a. tp) for this purpose. |
247 | * We use r13 (a.k.a. tp) for this purpose. |
Line 283... | Line 254... | ||
283 | /** Acquire console back for kernel |
254 | /** Acquire console back for kernel |
284 | * |
255 | * |
285 | */ |
256 | */ |
286 | void arch_grab_console(void) |
257 | void arch_grab_console(void) |
287 | { |
258 | { |
288 | #ifdef SKI |
259 | #ifdef MACHINE_ski |
289 | ski_kbd_grab(); |
260 | ski_kbd_grab(); |
290 | #else |
- | |
291 | #ifdef CONFIG_NS16550 |
- | |
292 | ns16550_grab(); |
- | |
293 | #else |
- | |
294 | i8042_grab(); |
- | |
295 | #endif |
- | |
296 | #endif |
261 | #endif |
297 | } |
262 | } |
- | 263 | ||
298 | /** Return console to userspace |
264 | /** Return console to userspace |
299 | * |
265 | * |
300 | */ |
266 | */ |
301 | void arch_release_console(void) |
267 | void arch_release_console(void) |
302 | { |
268 | { |
303 | #ifdef SKI |
269 | #ifdef MACHINE_ski |
304 | ski_kbd_release(); |
270 | ski_kbd_release(); |
305 | #else |
- | |
306 | #ifdef CONFIG_NS16550 |
- | |
307 | ns16550_release(); |
- | |
308 | #else |
- | |
309 | i8042_release(); |
- | |
310 | #endif |
- | |
311 | - | ||
312 | #endif |
271 | #endif |
313 | } |
272 | } |
314 | 273 | ||
315 | void arch_reboot(void) |
274 | void arch_reboot(void) |
316 | { |
275 | { |
317 | outb(0x64,0xfe); |
276 | pio_write_8((ioport8_t *)0x64, 0xfe); |
318 | while (1); |
277 | while (1) |
- | 278 | ; |
|
- | 279 | } |
|
- | 280 | ||
- | 281 | /** Construct function pointer |
|
- | 282 | * |
|
- | 283 | * @param fptr function pointer structure |
|
- | 284 | * @param addr function address |
|
- | 285 | * @param caller calling function address |
|
- | 286 | * |
|
- | 287 | * @return address of the function pointer |
|
- | 288 | * |
|
- | 289 | */ |
|
- | 290 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller) |
|
- | 291 | { |
|
- | 292 | fptr->fnc = (unative_t) addr; |
|
- | 293 | fptr->gp = ((unative_t *) caller)[1]; |
|
- | 294 | ||
- | 295 | return (void *) fptr; |
|
319 | } |
296 | } |
320 | 297 | ||
321 | /** @} |
298 | /** @} |
322 | */ |
299 | */ |