00001 /* 00002 * Copyright (C) 2005 Ondrej Palkovsky 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 00035 #include <arch.h> 00036 00037 #include <arch/types.h> 00038 00039 #include <config.h> 00040 00041 #include <proc/thread.h> 00042 #include <arch/drivers/ega.h> 00043 #include <arch/drivers/vesa.h> 00044 #include <genarch/i8042/i8042.h> 00045 #include <arch/drivers/i8254.h> 00046 #include <arch/drivers/i8259.h> 00047 00048 #include <arch/bios/bios.h> 00049 #include <arch/mm/memory_init.h> 00050 #include <arch/cpu.h> 00051 #include <print.h> 00052 #include <arch/cpuid.h> 00053 #include <genarch/acpi/acpi.h> 00054 #include <panic.h> 00055 #include <interrupt.h> 00056 #include <arch/syscall.h> 00057 #include <arch/debugger.h> 00058 #include <syscall/syscall.h> 00059 #include <console/console.h> 00060 00061 00066 static void clean_IOPL_NT_flags(void) 00067 { 00068 asm 00069 ( 00070 "pushfq;" 00071 "pop %%rax;" 00072 "and $~(0x7000),%%rax;" 00073 "pushq %%rax;" 00074 "popfq;" 00075 : 00076 : 00077 :"%rax" 00078 ); 00079 } 00080 00085 static void clean_AM_flag(void) 00086 { 00087 asm 00088 ( 00089 "mov %%cr0,%%rax;" 00090 "and $~(0x40000),%%rax;" 00091 "mov %%rax,%%cr0;" 00092 : 00093 : 00094 :"%rax" 00095 ); 00096 } 00097 00098 void arch_pre_mm_init(void) 00099 { 00100 struct cpu_info cpuid_s; 00101 00102 cpuid(AMD_CPUID_EXTENDED,&cpuid_s); 00103 if (! (cpuid_s.cpuid_edx & (1<<AMD_EXT_NOEXECUTE))) 00104 panic("Processor does not support No-execute pages.\n"); 00105 00106 cpuid(INTEL_CPUID_STANDARD,&cpuid_s); 00107 if (! (cpuid_s.cpuid_edx & (1<<INTEL_FXSAVE))) 00108 panic("Processor does not support FXSAVE/FXRESTORE.\n"); 00109 00110 if (! (cpuid_s.cpuid_edx & (1<<INTEL_SSE2))) 00111 panic("Processor does not support SSE2 instructions.\n"); 00112 00113 /* Enable No-execute pages */ 00114 set_efer_flag(AMD_NXE_FLAG); 00115 /* Enable FPU */ 00116 cpu_setup_fpu(); 00117 00118 /* Initialize segmentation */ 00119 pm_init(); 00120 00121 /* Disable I/O on nonprivileged levels 00122 * clear the NT(nested-thread) flag 00123 */ 00124 clean_IOPL_NT_flags(); 00125 /* Disable alignment check */ 00126 clean_AM_flag(); 00127 00128 if (config.cpu_active == 1) { 00129 bios_init(); 00130 i8259_init(); /* PIC */ 00131 i8254_init(); /* hard clock */ 00132 00133 #ifdef CONFIG_SMP 00134 exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", 00135 tlb_shootdown_ipi); 00136 #endif /* CONFIG_SMP */ 00137 } 00138 } 00139 00140 void arch_post_mm_init(void) 00141 { 00142 if (config.cpu_active == 1) { 00143 #ifdef CONFIG_FB 00144 if (vesa_present()) 00145 vesa_init(); 00146 else 00147 #endif 00148 ega_init(); /* video */ 00149 /* Enable debugger */ 00150 debugger_init(); 00151 /* Merge all memory zones to 1 big zone */ 00152 zone_merge_all(); 00153 } 00154 /* Setup fast SYSCALL/SYSRET */ 00155 syscall_setup_cpu(); 00156 00157 } 00158 00159 void arch_pre_smp_init(void) 00160 { 00161 if (config.cpu_active == 1) { 00162 memory_print_map(); 00163 00164 #ifdef CONFIG_SMP 00165 acpi_init(); 00166 #endif /* CONFIG_SMP */ 00167 } 00168 } 00169 00170 void arch_post_smp_init(void) 00171 { 00172 i8042_init(); /* keyboard controller */ 00173 } 00174 00175 void calibrate_delay_loop(void) 00176 { 00177 i8254_calibrate_delay_loop(); 00178 i8254_normal_operation(); 00179 } 00180 00189 __native sys_tls_set(__native addr) 00190 { 00191 THREAD->arch.tls = addr; 00192 write_msr(AMD_MSR_FS, addr); 00193 return 0; 00194 } 00195 00199 void arch_grab_console(void) 00200 { 00201 i8042_grab(); 00202 } 00206 void arch_release_console(void) 00207 { 00208 i8042_release(); 00209 } 00210