source: mainline/kernel/arch/mips32/src/mips32.c@ 2b95d13

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

Merge mainline changes.

  • Property mode set to 100644
File size: 5.6 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 mips32
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 <syscall/syscall.h>
44#include <sysinfo/sysinfo.h>
45#include <arch/debug.h>
46#include <arch/debugger.h>
47#include <arch/machine_func.h>
48
49/* Size of the code jumping to the exception handler code
50 * - J+NOP
51 */
52#define EXCEPTION_JUMP_SIZE 8
53
54#define TLB_EXC ((char *) 0x80000000)
55#define NORM_EXC ((char *) 0x80000180)
56#define CACHE_EXC ((char *) 0x80000100)
57
58
59/* Why the linker moves the variable 64K away in assembler
60 * when not in .text section?
61 */
62
63/* Stack pointer saved when entering user mode */
64uintptr_t supervisor_sp __attribute__ ((section (".text")));
65
66size_t cpu_count = 0;
67
68#if defined(MACHINE_lmalta) || defined(MACHINE_bmalta)
69size_t sdram_size = 0;
70#endif
71
72/** Performs mips32-specific initialization before main_bsp() is called. */
73void arch_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
74{
75 init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
76
77 size_t i;
78 for (i = 0; i < init.cnt; i++) {
79 init.tasks[i].paddr = KA2PA(bootinfo->tasks[i].addr);
80 init.tasks[i].size = bootinfo->tasks[i].size;
81 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
82 bootinfo->tasks[i].name);
83 }
84
85 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
86 if ((bootinfo->cpumap & (1 << i)) != 0)
87 cpu_count++;
88 }
89
90#if defined(MACHINE_lmalta) || defined(MACHINE_bmalta)
91 sdram_size = bootinfo->sdram_size;
92#endif
93
94 /* Initialize machine_ops pointer. */
95 machine_ops_init();
96}
97
98void arch_pre_mm_init(void)
99{
100 /* It is not assumed by default */
101 interrupts_disable();
102
103 /* Initialize dispatch table */
104 exception_init();
105
106 /* Copy the exception vectors to the right places */
107 memcpy(TLB_EXC, (char *) tlb_refill_entry, EXCEPTION_JUMP_SIZE);
108 smc_coherence_block(TLB_EXC, EXCEPTION_JUMP_SIZE);
109 memcpy(NORM_EXC, (char *) exception_entry, EXCEPTION_JUMP_SIZE);
110 smc_coherence_block(NORM_EXC, EXCEPTION_JUMP_SIZE);
111 memcpy(CACHE_EXC, (char *) cache_error_entry, EXCEPTION_JUMP_SIZE);
112 smc_coherence_block(CACHE_EXC, EXCEPTION_JUMP_SIZE);
113
114 /*
115 * Switch to BEV normal level so that exception vectors point to the
116 * kernel. Clear the error level.
117 */
118 cp0_status_write(cp0_status_read() &
119 ~(cp0_status_bev_bootstrap_bit | cp0_status_erl_error_bit));
120
121 /*
122 * Mask all interrupts
123 */
124 cp0_mask_all_int();
125
126 debugger_init();
127}
128
129void arch_post_mm_init(void)
130{
131 interrupt_init();
132
133 machine_init();
134 machine_output_init();
135}
136
137void arch_post_cpu_init(void)
138{
139}
140
141void arch_pre_smp_init(void)
142{
143}
144
145void arch_post_smp_init(void)
146{
147 /* Set platform name. */
148 sysinfo_set_item_data("platform", NULL,
149 (void *) machine_get_platform_name(),
150 str_size(machine_get_platform_name()));
151
152 machine_input_init();
153}
154
155void calibrate_delay_loop(void)
156{
157}
158
159void userspace(uspace_arg_t *kernel_uarg)
160{
161 /* EXL = 1, UM = 1, IE = 1 */
162 cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
163 cp0_status_um_bit | cp0_status_ie_enabled_bit));
164 cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
165 userspace_asm(((uintptr_t) kernel_uarg->uspace_stack +
166 kernel_uarg->uspace_stack_size),
167 (uintptr_t) kernel_uarg->uspace_uarg,
168 (uintptr_t) kernel_uarg->uspace_entry);
169
170 while (1);
171}
172
173/** Perform mips32 specific tasks needed before the new task is run. */
174void before_task_runs_arch(void)
175{
176}
177
178/** Perform mips32 specific tasks needed before the new thread is scheduled. */
179void before_thread_runs_arch(void)
180{
181 supervisor_sp =
182 (uintptr_t) &THREAD->kstack[STACK_SIZE];
183}
184
185void after_thread_ran_arch(void)
186{
187}
188
189/** Set thread-local-storage pointer
190 *
191 * We have it currently in K1, it is
192 * possible to have it separately in the future.
193 */
194sysarg_t sys_tls_set(uintptr_t addr)
195{
196 return EOK;
197}
198
199void arch_reboot(void)
200{
201 ___halt();
202 while (1);
203}
204
205/** Construct function pointer
206 *
207 * @param fptr function pointer structure
208 * @param addr function address
209 * @param caller calling function address
210 *
211 * @return address of the function pointer
212 *
213 */
214void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
215{
216 return addr;
217}
218
219void irq_initialize_arch(irq_t *irq)
220{
221 (void) irq;
222}
223
224/** @}
225 */
Note: See TracBrowser for help on using the repository browser.