Changeset 811770c in mainline for kernel/arch/amd64/src
- Timestamp:
- 2016-05-05T12:06:04Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 57c2a87
- Parents:
- 0f17bff
- Location:
- kernel/arch/amd64/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/amd64.c
r0f17bff r811770c 64 64 #endif 65 65 66 /** Disable I/O on non-privileged levels67 *68 * Clean IOPL(12,13) and NT(14) flags in EFLAGS register69 */70 static void clean_IOPL_NT_flags(void)71 {72 asm volatile (73 "pushfq\n"74 "pop %%rax\n"75 "and $~(0x7000), %%rax\n"76 "pushq %%rax\n"77 "popfq\n"78 ::: "%rax"79 );80 }81 82 /** Disable alignment check83 *84 * Clean AM(18) flag in CR0 register85 */86 static void clean_AM_flag(void)87 {88 asm volatile (89 "mov %%cr0, %%rax\n"90 "and $~(0x40000), %%rax\n"91 "mov %%rax, %%cr0\n"92 ::: "%rax"93 );94 }95 96 66 /** Perform amd64-specific initialization before main_bsp() is called. 97 67 * … … 116 86 { 117 87 /* Enable no-execute pages */ 118 set_efer_flag(AMD_NXE_FLAG);88 write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_NXE); 119 89 /* Enable FPU */ 120 90 cpu_setup_fpu(); … … 123 93 pm_init(); 124 94 125 /* Disable I/O on nonprivileged levels 126 * clear the NT (nested-thread) flag 127 */ 128 clean_IOPL_NT_flags(); 95 /* Disable I/O on nonprivileged levels, clear the nested-thread flag */ 96 write_rflags(read_rflags() & ~(RFLAGS_IOPL | RFLAGS_NT)); 129 97 /* Disable alignment check */ 130 clean_AM_flag();98 write_cr0(read_cr0() & ~CR0_AM); 131 99 132 100 if (config.cpu_active == 1) { -
kernel/arch/amd64/src/asm.S
r0f17bff r811770c 33 33 #include <arch/kseg_struct.h> 34 34 #include <arch/cpu.h> 35 #include <arch/smp/apic.h> 35 36 36 37 .text … … 93 94 94 95 /* Flip the ID bit */ 95 btcl $21, %edx96 xorl $RFLAGS_ID, %edx 96 97 97 98 /* Store RFLAGS */ … … 102 103 /* Get the ID bit again */ 103 104 popq %rdx 104 andl $ (1 << 21), %eax105 andl $ (1 << 21), %edx105 andl $RFLAGS_ID, %eax 106 andl $RFLAGS_ID, %edx 106 107 107 108 /* 0 if not supported, 1 if supported */ … … 127 128 FUNCTION_END(cpuid) 128 129 129 FUNCTION_BEGIN(set_efer_flag) 130 movl $0xc0000080, %ecx 130 /** Enable local APIC 131 * 132 * Enable local APIC in MSR. 133 * 134 */ 135 FUNCTION_BEGIN(enable_l_apic_in_msr) 136 movl $AMD_MSR_APIC_BASE, %ecx 131 137 rdmsr 132 btsl %edi, %eax138 orl $(L_APIC_BASE | AMD_APIC_BASE_GE), %eax 133 139 wrmsr 134 140 ret 135 FUNCTION_END(set_efer_flag) 136 137 FUNCTION_BEGIN(read_efer_flag) 138 movl $0xc0000080, %ecx 139 rdmsr 140 ret 141 FUNCTION_END(read_efer_flag) 141 FUNCTION_END(enable_l_apic_in_msr) 142 142 143 143 /* … … 541 541 ret 542 542 FUNCTION_END(early_putchar) 543 -
kernel/arch/amd64/src/boot/multiboot.S
r0f17bff r811770c 168 168 169 169 movl %cr4, %eax 170 btsl $5, %eax170 orl $CR4_PAE, %eax 171 171 movl %eax, %cr4 172 172 … … 176 176 177 177 /* Enable long mode */ 178 movl $ EFER_MSR_NUM, %ecx178 movl $AMD_MSR_EFER, %ecx 179 179 rdmsr /* read EFER */ 180 btsl $AMD_LME_FLAG, %eax/* set LME = 1 */180 orl $AMD_LME, %eax /* set LME = 1 */ 181 181 wrmsr 182 182 183 183 /* Enable paging to activate long mode (set CR0.PG = 1) */ 184 184 movl %cr0, %eax 185 btsl $31, %eax185 orl $CR0_PG, %eax 186 186 movl %eax, %cr0 187 187 -
kernel/arch/amd64/src/boot/multiboot2.S
r0f17bff r811770c 209 209 210 210 movl %cr4, %eax 211 btsl $5, %eax211 orl $CR4_PAE, %eax 212 212 movl %eax, %cr4 213 213 … … 217 217 218 218 /* Enable long mode */ 219 movl $ EFER_MSR_NUM, %ecx219 movl $AMD_MSR_EFER, %ecx 220 220 rdmsr /* read EFER */ 221 btsl $AMD_LME_FLAG, %eax/* set LME = 1 */221 orl $AMD_LME, %eax /* set LME = 1 */ 222 222 wrmsr 223 223 224 224 /* Enable paging to activate long mode (set CR0.PG = 1) */ 225 225 movl %cr0, %eax 226 btsl $31, %eax226 orl $CR0_PG, %eax 227 227 movl %eax, %cr0 228 228 -
kernel/arch/amd64/src/cpu/cpu.c
r0f17bff r811770c 76 76 void cpu_setup_fpu(void) 77 77 { 78 asm volatile ( 79 "movq %%cr0, %%rax\n" 80 "btsq $1, %%rax\n" /* cr0.mp */ 81 "btrq $2, %%rax\n" /* cr0.em */ 82 "movq %%rax, %%cr0\n" 83 84 "movq %%cr4, %%rax\n" 85 "bts $9, %%rax\n" /* cr4.osfxsr */ 86 "movq %%rax, %%cr4\n" 87 ::: "%rax" 88 ); 78 write_cr0((read_cr0() & ~CR0_EM) | CR0_MP); 79 write_cr4(read_cr4() | CR4_OSFXSR); 89 80 } 90 81 … … 97 88 void fpu_disable(void) 98 89 { 99 asm volatile ( 100 "mov %%cr0, %%rax\n" 101 "bts $3, %%rax\n" 102 "mov %%rax, %%cr0\n" 103 ::: "%rax" 104 ); 90 write_cr0(read_cr0() | CR0_TS); 105 91 } 106 92 107 93 void fpu_enable(void) 108 94 { 109 asm volatile ( 110 "mov %%cr0, %%rax\n" 111 "btr $3, %%rax\n" 112 "mov %%rax, %%cr0\n" 113 ::: "%rax" 114 ); 95 write_cr0(read_cr0() & ~CR0_TS); 115 96 } 116 97 -
kernel/arch/amd64/src/smp/ap.S
r0f17bff r811770c 75 75 76 76 movl %cr4, %eax 77 btsl $5, %eax77 orl $CR4_PAE, %eax 78 78 movl %eax, %cr4 79 79 … … 82 82 83 83 # Enable long mode 84 movl $ EFER_MSR_NUM, %ecx # EFER MSR number84 movl $AMD_MSR_EFER, %ecx # EFER MSR number 85 85 rdmsr # Read EFER 86 btsl $AMD_LME_FLAG, %eax# Set LME=186 orl $AMD_LME, %eax # Set LME=1 87 87 wrmsr # Write EFER 88 88 89 89 # Enable paging to activate long mode (set CR0.PG = 1) 90 90 movl %cr0, %eax 91 btsl $31, %eax91 orl $CR0_PG, %eax 92 92 movl %eax, %cr0 93 93 -
kernel/arch/amd64/src/syscall.c
r0f17bff r811770c 48 48 { 49 49 /* Enable SYSCALL/SYSRET */ 50 set_efer_flag(AMD_SCE_FLAG);50 write_msr(AMD_MSR_EFER, read_msr(AMD_MSR_EFER) | AMD_SCE); 51 51 52 52 /* Setup syscall entry address */ -
kernel/arch/amd64/src/userspace.c
r0f17bff r811770c 48 48 void userspace(uspace_arg_t *kernel_uarg) 49 49 { 50 ipl_t ipl = interrupts_disable();50 uint64_t rflags = read_rflags(); 51 51 52 ipl &= ~(RFLAGS_CF | RFLAGS_PF | RFLAGS_AF | RFLAGS_ZF | RFLAGS_SF |53 RFLAGS_DF | RFLAGS_OF);52 rflags &= ~RFLAGS_NT; 53 rflags |= RFLAGS_IF; 54 54 55 55 asm volatile ( 56 56 "pushq %[udata_des]\n" 57 57 "pushq %[stack_top]\n" 58 "pushq %[ ipl]\n"58 "pushq %[rflags]\n" 59 59 "pushq %[utext_des]\n" 60 60 "pushq %[entry]\n" … … 67 67 [stack_top] "r" ((uint8_t *) kernel_uarg->uspace_stack + 68 68 kernel_uarg->uspace_stack_size), 69 [ ipl] "r" (ipl),69 [rflags] "r" (rflags), 70 70 [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER), 71 71 [entry] "r" (kernel_uarg->uspace_entry),
Note:
See TracChangeset
for help on using the changeset viewer.
