mips32.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00036 #include <arch.h>
00037 #include <arch/boot.h>
00038 #include <arch/cp0.h>
00039 #include <arch/exception.h>
00040 #include <arch/asm.h>
00041 #include <mm/as.h>
00042 
00043 #include <userspace.h>
00044 #include <arch/console.h>
00045 #include <memstr.h>
00046 #include <proc/thread.h>
00047 #include <proc/uarg.h>
00048 #include <print.h>
00049 #include <syscall/syscall.h>
00050 #include <sysinfo/sysinfo.h>
00051 
00052 #include <arch/interrupt.h>
00053 #include <arch/drivers/arc.h>
00054 #include <console/chardev.h>
00055 #include <arch/debugger.h>
00056 #include <genarch/fb/fb.h>
00057 #include <debug.h>
00058 
00059 #include <arch/asm/regname.h>
00060 
00061 /* Size of the code jumping to the exception handler code 
00062  * - J+NOP 
00063  */
00064 #define EXCEPTION_JUMP_SIZE    8
00065 
00066 #define TLB_EXC ((char *) 0x80000000)
00067 #define NORM_EXC ((char *) 0x80000180)
00068 #define CACHE_EXC ((char *) 0x80000100)
00069 
00070 bootinfo_t bootinfo;
00071 
00072 void arch_pre_main(void)
00073 {
00074         /* Setup usermode */
00075         init.cnt = bootinfo.cnt;
00076         
00077         __u32 i;
00078         
00079         for (i = 0; i < bootinfo.cnt; i++) {
00080                 init.tasks[i].addr = bootinfo.tasks[i].addr;
00081                 init.tasks[i].size = bootinfo.tasks[i].size;
00082         }
00083 }
00084 
00085 void arch_pre_mm_init(void)
00086 {
00087         /* It is not assumed by default */
00088         interrupts_disable();
00089         
00090         /* Initialize dispatch table */
00091         exception_init();
00092         arc_init();
00093 
00094         /* Copy the exception vectors to the right places */
00095         memcpy(TLB_EXC, (char *)tlb_refill_entry, EXCEPTION_JUMP_SIZE);
00096         memcpy(NORM_EXC, (char *)exception_entry, EXCEPTION_JUMP_SIZE);
00097         memcpy(CACHE_EXC, (char *)cache_error_entry, EXCEPTION_JUMP_SIZE);
00098 
00099         interrupt_init();
00100         /*
00101          * Switch to BEV normal level so that exception vectors point to the kernel.
00102          * Clear the error level.
00103          */
00104         cp0_status_write(cp0_status_read() & ~(cp0_status_bev_bootstrap_bit|cp0_status_erl_error_bit));
00105 
00106         /* 
00107          * Mask all interrupts 
00108          */
00109         cp0_mask_all_int();
00110 
00111         /*
00112          * Unmask hardware clock interrupt.
00113          */
00114         cp0_unmask_int(TIMER_IRQ);
00115 
00116         console_init();
00117         debugger_init();
00118 }
00119 
00120 void arch_post_mm_init(void)
00121 {
00122 #ifdef CONFIG_FB
00123                 fb_init(0x12000000, 640, 480, 24, 1920); // gxemul framebuffer
00124 #endif
00125                 sysinfo_set_item_val("machine." STRING(MACHINE),NULL,1);
00126 }
00127 
00128 void arch_pre_smp_init(void)
00129 {
00130 }
00131 
00132 void arch_post_smp_init(void)
00133 {
00134 }
00135 
00136 /* Stack pointer saved when entering user mode */
00137 /* TODO: How do we do it on SMP system???? */
00138 
00139 /* Why the linker moves the variable 64K away in assembler
00140  * when not in .text section ????????
00141  */
00142 __address supervisor_sp __attribute__ ((section (".text")));
00143 
00144 void userspace(uspace_arg_t *kernel_uarg)
00145 {
00146         /* EXL=1, UM=1, IE=1 */
00147         cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
00148                                               cp0_status_um_bit |
00149                                               cp0_status_ie_enabled_bit));
00150         cp0_epc_write((__address) kernel_uarg->uspace_entry);
00151         userspace_asm(((__address) kernel_uarg->uspace_stack+PAGE_SIZE), 
00152                       (__address) kernel_uarg->uspace_uarg,
00153                       (__address) kernel_uarg->uspace_entry);
00154         while (1)
00155                 ;
00156 }
00157 
00159 void before_task_runs_arch(void)
00160 {
00161 }
00162 
00164 void before_thread_runs_arch(void)
00165 {
00166         supervisor_sp = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
00167 }
00168 
00169 void after_thread_ran_arch(void)
00170 {
00171 }
00172 
00178 __native sys_tls_set(__native addr)
00179 {
00180         return 0;
00181 }
00182 
00183 

Generated on Sun Jun 18 17:01:57 2006 for HelenOS Kernel (mips32) by  doxygen 1.4.6