Changes in kernel/arch/amd64/src/amd64.c [36df4109:4a5ba372] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/amd64.c
r36df4109 r4a5ba372 34 34 35 35 #include <arch.h> 36 #include <arch/arch.h>37 36 #include <typedefs.h> 38 37 #include <errno.h> … … 50 49 #include <genarch/drivers/ega/ega.h> 51 50 #include <genarch/drivers/i8042/i8042.h> 52 #include <genarch/drivers/ns16550/ns16550.h>53 51 #include <genarch/drivers/legacy/ia32/io.h> 54 52 #include <genarch/fb/bfb.h> 55 53 #include <genarch/kbrd/kbrd.h> 56 #include <genarch/srln/srln.h>57 54 #include <genarch/multiboot/multiboot.h> 58 55 #include <genarch/multiboot/multiboot2.h> 59 #include <arch/pm.h>60 #include <arch/vreg.h>61 #include <arch/kseg.h>62 56 63 57 #ifdef CONFIG_SMP … … 65 59 #endif 66 60 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; 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 } 82 90 83 91 /** Perform amd64-specific initialization before main_bsp() is called. … … 87 95 * 88 96 */ 89 void a md64_pre_main(uint32_t signature, void *info)97 void arch_pre_main(uint32_t signature, void *info) 90 98 { 91 99 /* Parse multiboot information obtained from the bootloader. */ … … 100 108 } 101 109 102 void a md64_pre_mm_init(void)110 void arch_pre_mm_init(void) 103 111 { 104 112 /* Enable no-execute pages */ 105 write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_NXE);113 set_efer_flag(AMD_NXE_FLAG); 106 114 /* Enable FPU */ 107 115 cpu_setup_fpu(); … … 110 118 pm_init(); 111 119 112 /* Disable I/O on nonprivileged levels, clear the nested-thread flag */ 113 write_rflags(read_rflags() & ~(RFLAGS_IOPL | RFLAGS_NT)); 120 /* Disable I/O on nonprivileged levels 121 * clear the NT (nested-thread) flag 122 */ 123 clean_IOPL_NT_flags(); 114 124 /* Disable alignment check */ 115 write_cr0(read_cr0() & ~CR0_AM);125 clean_AM_flag(); 116 126 117 127 if (config.cpu_active == 1) { … … 124 134 } 125 135 126 void amd64_post_mm_init(void) 127 { 128 vreg_init(); 129 kseg_init(); 130 136 137 void arch_post_mm_init(void) 138 { 131 139 if (config.cpu_active == 1) { 132 140 /* Initialize IRQ routing */ … … 160 168 } 161 169 162 void a md64_post_cpu_init(void)170 void arch_post_cpu_init() 163 171 { 164 172 #ifdef CONFIG_SMP … … 170 178 } 171 179 172 void a md64_pre_smp_init(void)180 void arch_pre_smp_init(void) 173 181 { 174 182 if (config.cpu_active == 1) { … … 179 187 } 180 188 181 void a md64_post_smp_init(void)189 void arch_post_smp_init(void) 182 190 { 183 191 /* Currently the only supported platform for amd64 is 'pc'. */ … … 204 212 } 205 213 #endif 206 207 #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))208 /*209 * Initialize the ns16550 controller.210 */211 #ifdef CONFIG_NS16550_OUT212 outdev_t *ns16550_out;213 outdev_t **ns16550_out_ptr = &ns16550_out;214 #else215 outdev_t **ns16550_out_ptr = NULL;216 #endif217 ns16550_instance_t *ns16550_instance218 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,219 ns16550_out_ptr);220 if (ns16550_instance) {221 #ifdef CONFIG_NS16550222 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 #endif230 #ifdef CONFIG_NS16550_OUT231 if (ns16550_out) {232 stdout_wire(ns16550_out);233 }234 #endif235 }236 #endif237 214 238 215 if (irqs_info != NULL) … … 252 229 } 253 230 231 /** Set thread-local-storage pointer 232 * 233 * TLS pointer is set in FS register. Unfortunately the 64-bit 234 * 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 254 247 /** Construct function pointer 255 248 *
Note:
See TracChangeset
for help on using the changeset viewer.