source: mainline/kernel/arch/mips64/src/mips64.c@ a522999

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a522999 was 3c50cddc, checked in by Jakub Jermar <jakub@…>, 13 years ago

Use msim printer and kayboard only for the msim machine.

  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * Copyright (c) 2003-2004 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mips64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <typedefs.h>
37#include <errno.h>
38#include <interrupt.h>
39#include <macros.h>
40#include <str.h>
41#include <memstr.h>
42#include <userspace.h>
43#include <console/console.h>
44#include <syscall/syscall.h>
45#include <sysinfo/sysinfo.h>
46#include <arch/debug.h>
47#include <arch/debugger.h>
48#ifdef MACHINE_msim
49#include <arch/drivers/msim.h>
50#endif
51#include <genarch/fb/fb.h>
52#include <genarch/drivers/dsrln/dsrlnin.h>
53#include <genarch/drivers/dsrln/dsrlnout.h>
54#include <genarch/srln/srln.h>
55
56/* Size of the code jumping to the exception handler code
57 * - J+NOP
58 */
59#define EXCEPTION_JUMP_SIZE 8
60
61#define TLB_EXC ((char *) 0xffffffff80000000)
62#define NORM_EXC ((char *) 0xffffffff80000180)
63#define CACHE_EXC ((char *) 0xffffffff80000100)
64
65
66/* Why the linker moves the variable 64K away in assembler
67 * when not in .text section?
68 */
69
70/* Stack pointer saved when entering user mode */
71uintptr_t supervisor_sp __attribute__ ((section (".text")));
72
73size_t cpu_count = 0;
74
75/** Performs mips64-specific initialization before main_bsp() is called. */
76void arch_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
77{
78 init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
79
80 size_t i;
81 for (i = 0; i < init.cnt; i++) {
82 init.tasks[i].paddr = KA2PA(bootinfo->tasks[i].addr);
83 init.tasks[i].size = bootinfo->tasks[i].size;
84 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
85 bootinfo->tasks[i].name);
86 }
87
88 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
89 if ((bootinfo->cpumap & (1 << i)) != 0)
90 cpu_count++;
91 }
92}
93
94void arch_pre_mm_init(void)
95{
96 /* It is not assumed by default */
97 interrupts_disable();
98
99 /* Initialize dispatch table */
100 exception_init();
101
102 /* Copy the exception vectors to the right places */
103 memcpy(TLB_EXC, (char *) tlb_refill_entry, EXCEPTION_JUMP_SIZE);
104 smc_coherence_block(TLB_EXC, EXCEPTION_JUMP_SIZE);
105 memcpy(NORM_EXC, (char *) exception_entry, EXCEPTION_JUMP_SIZE);
106 smc_coherence_block(NORM_EXC, EXCEPTION_JUMP_SIZE);
107 memcpy(CACHE_EXC, (char *) cache_error_entry, EXCEPTION_JUMP_SIZE);
108 smc_coherence_block(CACHE_EXC, EXCEPTION_JUMP_SIZE);
109
110 /*
111 * Switch to BEV normal level so that exception vectors point to the
112 * kernel. Clear the error level.
113 */
114 cp0_status_write(cp0_status_read() &
115 ~(cp0_status_bev_bootstrap_bit | cp0_status_erl_error_bit));
116
117 /*
118 * Mask all interrupts
119 */
120 cp0_mask_all_int();
121
122 debugger_init();
123}
124
125void arch_post_mm_init(void)
126{
127 interrupt_init();
128
129#ifdef CONFIG_MSIM_PRN
130 outdev_t *dsrlndev = dsrlnout_init((ioport8_t *) MSIM_KBD_ADDRESS);
131 if (dsrlndev)
132 stdout_wire(dsrlndev);
133#endif
134}
135
136void arch_post_cpu_init(void)
137{
138}
139
140void arch_pre_smp_init(void)
141{
142}
143
144void arch_post_smp_init(void)
145{
146 static const char *platform;
147
148 /* Set platform name. */
149#ifdef MACHINE_msim
150 platform = "msim";
151#endif
152 sysinfo_set_item_data("platform", NULL, (void *) platform,
153 str_size(platform));
154
155#ifdef CONFIG_MSIM_KBD
156 /*
157 * Initialize the msim keyboard port. Then initialize the serial line
158 * module and connect it to the msim keyboard. Enable keyboard
159 * interrupts.
160 */
161 dsrlnin_instance_t *dsrlnin_instance
162 = dsrlnin_init((dsrlnin_t *) MSIM_KBD_ADDRESS, MSIM_KBD_IRQ);
163 if (dsrlnin_instance) {
164 srln_instance_t *srln_instance = srln_init();
165 if (srln_instance) {
166 indev_t *sink = stdin_wire();
167 indev_t *srln = srln_wire(srln_instance, sink);
168 dsrlnin_wire(dsrlnin_instance, srln);
169 cp0_unmask_int(MSIM_KBD_IRQ);
170 }
171 }
172
173 /*
174 * This is the necessary evil until the userspace driver is entirely
175 * self-sufficient.
176 */
177 sysinfo_set_item_val("kbd", NULL, true);
178 sysinfo_set_item_val("kbd.inr", NULL, MSIM_KBD_IRQ);
179 sysinfo_set_item_val("kbd.address.virtual", NULL, MSIM_KBD_ADDRESS);
180#endif
181}
182
183void calibrate_delay_loop(void)
184{
185}
186
187void userspace(uspace_arg_t *kernel_uarg)
188{
189 /* EXL = 1, UM = 1, IE = 1 */
190 cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
191 cp0_status_um_bit | cp0_status_ie_enabled_bit));
192 cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
193 userspace_asm(((uintptr_t) kernel_uarg->uspace_stack +
194 kernel_uarg->uspace_stack_size),
195 (uintptr_t) kernel_uarg->uspace_uarg,
196 (uintptr_t) kernel_uarg->uspace_entry);
197
198 while (1);
199}
200
201/** Perform mips64 specific tasks needed before the new task is run. */
202void before_task_runs_arch(void)
203{
204}
205
206/** Perform mips64 specific tasks needed before the new thread is scheduled. */
207void before_thread_runs_arch(void)
208{
209 supervisor_sp =
210 (uintptr_t) &THREAD->kstack[STACK_SIZE - SP_DELTA];
211}
212
213void after_thread_ran_arch(void)
214{
215}
216
217/** Set thread-local-storage pointer
218 *
219 * We have it currently in K1, it is
220 * possible to have it separately in the future.
221 */
222sysarg_t sys_tls_set(uintptr_t addr)
223{
224 return EOK;
225}
226
227void arch_reboot(void)
228{
229 ___halt();
230 while (1);
231}
232
233/** Construct function pointer
234 *
235 * @param fptr function pointer structure
236 * @param addr function address
237 * @param caller calling function address
238 *
239 * @return address of the function pointer
240 *
241 */
242void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
243{
244 return addr;
245}
246
247void irq_initialize_arch(irq_t *irq)
248{
249 (void) irq;
250}
251
252/** @}
253 */
Note: See TracBrowser for help on using the repository browser.