Changes in kernel/arch/amd64/src/amd64.c [4a5ba372:36df4109] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/amd64.c
r4a5ba372 r36df4109 34 34 35 35 #include <arch.h> 36 #include <arch/arch.h> 36 37 #include <typedefs.h> 37 38 #include <errno.h> … … 49 50 #include <genarch/drivers/ega/ega.h> 50 51 #include <genarch/drivers/i8042/i8042.h> 52 #include <genarch/drivers/ns16550/ns16550.h> 51 53 #include <genarch/drivers/legacy/ia32/io.h> 52 54 #include <genarch/fb/bfb.h> 53 55 #include <genarch/kbrd/kbrd.h> 56 #include <genarch/srln/srln.h> 54 57 #include <genarch/multiboot/multiboot.h> 55 58 #include <genarch/multiboot/multiboot2.h> 59 #include <arch/pm.h> 60 #include <arch/vreg.h> 61 #include <arch/kseg.h> 56 62 57 63 #ifdef CONFIG_SMP … … 59 65 #endif 60 66 61 /** Disable I/O on non-privileged levels 62 * 63 * Clean IOPL(12,13) and NT(14) flags in EFLAGS register 64 */ 65 static void clean_IOPL_NT_flags(void) 66 { 67 asm volatile ( 68 "pushfq\n" 69 "pop %%rax\n" 70 "and $~(0x7000), %%rax\n" 71 "pushq %%rax\n" 72 "popfq\n" 73 ::: "%rax" 74 ); 75 } 76 77 /** Disable alignment check 78 * 79 * Clean AM(18) flag in CR0 register 80 */ 81 static void clean_AM_flag(void) 82 { 83 asm volatile ( 84 "mov %%cr0, %%rax\n" 85 "and $~(0x40000), %%rax\n" 86 "mov %%rax, %%cr0\n" 87 ::: "%rax" 88 ); 89 } 67 static void amd64_pre_mm_init(void); 68 static void amd64_post_mm_init(void); 69 static void amd64_post_cpu_init(void); 70 static void amd64_pre_smp_init(void); 71 static void amd64_post_smp_init(void); 72 73 arch_ops_t amd64_ops = { 74 .pre_mm_init = amd64_pre_mm_init, 75 .post_mm_init = amd64_post_mm_init, 76 .post_cpu_init = amd64_post_cpu_init, 77 .pre_smp_init = amd64_pre_smp_init, 78 .post_smp_init = amd64_post_smp_init 79 }; 80 81 arch_ops_t *arch_ops = &amd64_ops; 90 82 91 83 /** Perform amd64-specific initialization before main_bsp() is called. … … 95 87 * 96 88 */ 97 void a rch_pre_main(uint32_t signature, void *info)89 void amd64_pre_main(uint32_t signature, void *info) 98 90 { 99 91 /* Parse multiboot information obtained from the bootloader. */ … … 108 100 } 109 101 110 void a rch_pre_mm_init(void)102 void amd64_pre_mm_init(void) 111 103 { 112 104 /* Enable no-execute pages */ 113 set_efer_flag(AMD_NXE_FLAG);105 write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_NXE); 114 106 /* Enable FPU */ 115 107 cpu_setup_fpu(); … … 118 110 pm_init(); 119 111 120 /* Disable I/O on nonprivileged levels 121 * clear the NT (nested-thread) flag 122 */ 123 clean_IOPL_NT_flags(); 112 /* Disable I/O on nonprivileged levels, clear the nested-thread flag */ 113 write_rflags(read_rflags() & ~(RFLAGS_IOPL | RFLAGS_NT)); 124 114 /* Disable alignment check */ 125 clean_AM_flag();115 write_cr0(read_cr0() & ~CR0_AM); 126 116 127 117 if (config.cpu_active == 1) { … … 134 124 } 135 125 136 137 void arch_post_mm_init(void) 138 { 126 void amd64_post_mm_init(void) 127 { 128 vreg_init(); 129 kseg_init(); 130 139 131 if (config.cpu_active == 1) { 140 132 /* Initialize IRQ routing */ … … 168 160 } 169 161 170 void a rch_post_cpu_init()162 void amd64_post_cpu_init(void) 171 163 { 172 164 #ifdef CONFIG_SMP … … 178 170 } 179 171 180 void a rch_pre_smp_init(void)172 void amd64_pre_smp_init(void) 181 173 { 182 174 if (config.cpu_active == 1) { … … 187 179 } 188 180 189 void a rch_post_smp_init(void)181 void amd64_post_smp_init(void) 190 182 { 191 183 /* Currently the only supported platform for amd64 is 'pc'. */ … … 212 204 } 213 205 #endif 206 207 #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT)) 208 /* 209 * Initialize the ns16550 controller. 210 */ 211 #ifdef CONFIG_NS16550_OUT 212 outdev_t *ns16550_out; 213 outdev_t **ns16550_out_ptr = &ns16550_out; 214 #else 215 outdev_t **ns16550_out_ptr = NULL; 216 #endif 217 ns16550_instance_t *ns16550_instance 218 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL, 219 ns16550_out_ptr); 220 if (ns16550_instance) { 221 #ifdef CONFIG_NS16550 222 srln_instance_t *srln_instance = srln_init(); 223 if (srln_instance) { 224 indev_t *sink = stdin_wire(); 225 indev_t *srln = srln_wire(srln_instance, sink); 226 ns16550_wire(ns16550_instance, srln); 227 trap_virtual_enable_irqs(1 << IRQ_NS16550); 228 } 229 #endif 230 #ifdef CONFIG_NS16550_OUT 231 if (ns16550_out) { 232 stdout_wire(ns16550_out); 233 } 234 #endif 235 } 236 #endif 214 237 215 238 if (irqs_info != NULL) … … 229 252 } 230 253 231 /** Set thread-local-storage pointer232 *233 * TLS pointer is set in FS register. Unfortunately the 64-bit234 * part can be set only in CPL0 mode.235 *236 * The specs say, that on %fs:0 there is stored contents of %fs register,237 * we need not to go to CPL0 to read it.238 */239 sysarg_t sys_tls_set(uintptr_t addr)240 {241 THREAD->arch.tls = addr;242 write_msr(AMD_MSR_FS, addr);243 244 return EOK;245 }246 247 254 /** Construct function pointer 248 255 *
Note:
See TracChangeset
for help on using the changeset viewer.