Changeset 0f17bff in mainline
- Timestamp:
- 2016-05-05T08:34:45Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 811770c
- Parents:
- 4b0206c
- Location:
- kernel/arch/ia32
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/include/arch/asm.h
r4b0206c r0f17bff 87 87 GEN_WRITE_REG(cr3) 88 88 89 GEN_WRITE_REG(cr0) 90 89 91 GEN_READ_REG(dr0) 90 92 GEN_READ_REG(dr1) … … 232 234 } 233 235 234 /** Enable interrupts. 235 * 236 * Enable interrupts and return previous 237 * value of EFLAGS. 238 * 239 * @return Old interrupt priority level. 240 * 241 */ 242 NO_TRACE static inline ipl_t interrupts_enable(void) 243 { 244 ipl_t v; 245 236 NO_TRACE static inline uint32_t read_eflags(void) 237 { 238 uint32_t eflags; 239 246 240 asm volatile ( 247 241 "pushf\n" 248 242 "popl %[v]\n" 249 "sti\n" 250 : [v] "=r" (v) 251 ); 252 253 return v; 243 : [v] "=r" (eflags) 244 ); 245 246 return eflags; 247 } 248 249 NO_TRACE static inline void write_eflags(uint32_t eflags) 250 { 251 asm volatile ( 252 "pushl %[v]\n" 253 "popf\n" 254 :: [v] "r" (eflags) 255 ); 256 } 257 258 /** Return interrupt priority level. 259 * 260 * @return Current interrupt priority level. 261 */ 262 NO_TRACE static inline ipl_t interrupts_read(void) 263 { 264 return (ipl_t) read_eflags(); 265 } 266 267 /** Enable interrupts. 268 * 269 * Enable interrupts and return the previous interrupt priority level. 270 * 271 * @return Old interrupt priority level. 272 */ 273 NO_TRACE static inline ipl_t interrupts_enable(void) 274 { 275 ipl_t ipl = interrupts_read(); 276 277 asm volatile ("sti\n"); 278 279 return ipl; 254 280 } 255 281 256 282 /** Disable interrupts. 257 283 * 258 * Disable interrupts and return previous 259 * value of EFLAGS. 284 * Disable interrupts and return the previous interrupt priority level. 260 285 * 261 286 * @return Old interrupt priority level. 262 *263 287 */ 264 288 NO_TRACE static inline ipl_t interrupts_disable(void) 265 289 { 266 ipl_t v; 267 268 asm volatile ( 269 "pushf\n" 270 "popl %[v]\n" 271 "cli\n" 272 : [v] "=r" (v) 273 ); 274 275 return v; 290 ipl_t ipl = interrupts_read(); 291 292 asm volatile ("cli\n"); 293 294 return ipl; 276 295 } 277 296 278 297 /** Restore interrupt priority level. 279 298 * 280 * Restore EFLAGS.299 * Restore a saved interrupt priority level. 281 300 * 282 301 * @param ipl Saved interrupt priority level. … … 285 304 NO_TRACE static inline void interrupts_restore(ipl_t ipl) 286 305 { 287 asm volatile ( 288 "pushl %[ipl]\n" 289 "popf\n" 290 :: [ipl] "r" (ipl) 291 ); 292 } 293 294 /** Return interrupt priority level. 295 * 296 * @return EFLAFS. 297 * 298 */ 299 NO_TRACE static inline ipl_t interrupts_read(void) 300 { 301 ipl_t v; 302 303 asm volatile ( 304 "pushf\n" 305 "popl %[v]\n" 306 : [v] "=r" (v) 307 ); 308 309 return v; 306 write_eflags((uint32_t) ipl); 310 307 } 311 308 … … 317 314 NO_TRACE static inline bool interrupts_disabled(void) 318 315 { 319 ipl_t v; 320 321 asm volatile ( 322 "pushf\n" 323 "popl %[v]\n" 324 : [v] "=r" (v) 325 ); 326 327 return ((v & EFLAGS_IF) == 0); 316 return ((read_eflags() & EFLAGS_IF) == 0); 328 317 } 329 318 -
kernel/arch/ia32/include/arch/cpu.h
r4b0206c r0f17bff 36 36 #define KERN_ia32_CPU_H_ 37 37 38 #define EFLAGS_IF (1 << 9) 39 #define EFLAGS_DF (1 << 10) 40 #define EFLAGS_NT (1 << 14) 41 #define EFLAGS_RF (1 << 16) 38 #define EFLAGS_IF (1 << 9) 39 #define EFLAGS_DF (1 << 10) 40 #define EFLAGS_IOPL (3 << 12) 41 #define EFLAGS_NT (1 << 14) 42 #define EFLAGS_RF (1 << 16) 42 43 43 #define CR4_OSFXSR_MASK (1 << 9) 44 #define CR4_OSXMMEXCPT_MASK (1 << 10) 44 #define CR0_AM (1 << 18) 45 #define CR0_NW (1 << 29) 46 #define CR0_CD (1 << 30) 47 #define CR0_PG (1 << 31) 48 49 #define CR4_OSFXSR_MASK (1 << 9) 50 #define CR4_OSXMMEXCPT_MASK (1 << 10) 51 52 #define IA32_APIC_BASE_GE (1 << 11) 53 54 #define IA32_MSR_APIC_BASE 0x01b 45 55 46 56 /* Support for SYSENTER and SYSEXIT */ 47 #define IA32_MSR_SYSENTER_CS 0x174U48 #define IA32_MSR_SYSENTER_ESP 0x175U49 #define IA32_MSR_SYSENTER_EIP 0x176U57 #define IA32_MSR_SYSENTER_CS 0x174 58 #define IA32_MSR_SYSENTER_ESP 0x175 59 #define IA32_MSR_SYSENTER_EIP 0x176 50 60 51 61 #ifndef __ASM__ -
kernel/arch/ia32/include/arch/smp/apic.h
r4b0206c r0f17bff 36 36 #define KERN_ia32_APIC_H_ 37 37 38 #define L_APIC_BASE 0xfee00000 39 #define IO_APIC_BASE 0xfec00000 40 41 #ifndef __ASM__ 42 38 43 #include <typedefs.h> 39 44 #include <cpu.h> … … 364 369 extern void io_apic_enable_irqs(uint16_t); 365 370 371 #endif /* __ASM__ */ 372 366 373 #endif 367 374 -
kernel/arch/ia32/src/asm.S
r4b0206c r0f17bff 36 36 #include <arch/mm/page.h> 37 37 #include <arch/istate_struct.h> 38 #include <arch/smp/apic.h> 38 39 39 40 .text … … 110 111 FUNCTION_BEGIN(paging_on) 111 112 movl %cr0, %edx 112 orl $ (1 << 31), %edx /* paging on */113 orl $CR0_PG, %edx /* paging on */ 113 114 114 115 /* Clear Cache Disable and not Write Though */ 115 andl $~( (1 << 30) | (1 << 29)), %edx116 andl $~(CR0_CD | CR0_NW), %edx 116 117 movl %edx, %cr0 117 118 jmp 0f … … 127 128 */ 128 129 FUNCTION_BEGIN(enable_l_apic_in_msr) 129 movl $ 0x1b, %ecx130 movl $IA32_MSR_APIC_BASE, %ecx 130 131 rdmsr 131 orl $(1 << 11), %eax 132 orl $(0xfee00000), %eax 132 orl $(L_APIC_BASE | IA32_APIC_BASE_GE), %eax 133 133 wrmsr 134 134 ret -
kernel/arch/ia32/src/pm.c
r4b0206c r0f17bff 47 47 #include <arch/boot/boot.h> 48 48 #include <interrupt.h> 49 #include <arch/cpu.h> 49 50 50 51 /* … … 256 257 } 257 258 258 /* Clean IOPL(12,13) and NT(14) flags in EFLAGS register */259 static void clean_IOPL_NT_flags(void)260 {261 asm volatile (262 "pushfl\n"263 "pop %%eax\n"264 "and $0xffff8fff, %%eax\n"265 "push %%eax\n"266 "popfl\n"267 ::: "eax"268 );269 }270 271 /* Clean AM(18) flag in CR0 register */272 static void clean_AM_flag(void)273 {274 asm volatile (275 "mov %%cr0, %%eax\n"276 "and $0xfffbffff, %%eax\n"277 "mov %%eax, %%cr0\n"278 ::: "eax"279 );280 }281 282 259 void pm_init(void) 283 260 { … … 326 303 tr_load(GDT_SELECTOR(TSS_DES)); 327 304 328 clean_IOPL_NT_flags(); /* Disable I/O on nonprivileged levels and clear NT flag. */ 329 clean_AM_flag(); /* Disable alignment check */ 305 /* Disable I/O on nonprivileged levels and clear NT flag. */ 306 write_eflags(read_eflags() & ~(EFLAGS_IOPL | EFLAGS_NT)); 307 308 /* Disable alignment check */ 309 write_cr0(read_cr0() & ~CR0_AM); 330 310 } 331 311 -
kernel/arch/ia32/src/smp/apic.c
r4b0206c r0f17bff 72 72 * 73 73 */ 74 volatile uint32_t *l_apic = (uint32_t *) UINT32_C(0xfee00000);75 volatile uint32_t *io_apic = (uint32_t *) UINT32_C(0xfec00000);74 volatile uint32_t *l_apic = (uint32_t *) L_APIC_BASE; 75 volatile uint32_t *io_apic = (uint32_t *) IO_APIC_BASE; 76 76 77 77 uint32_t apic_id_mask = 0; -
kernel/arch/ia32/src/userspace.c
r4b0206c r0f17bff 39 39 #include <abi/proc/uarg.h> 40 40 #include <mm/as.h> 41 #include <arch/cpu.h> 42 #include <arch/asm.h> 41 43 42 44 /** Enter userspace … … 47 49 void userspace(uspace_arg_t *kernel_uarg) 48 50 { 49 ipl_t ipl = interrupts_disable();51 uint32_t eflags = read_eflags(); 50 52 51 53 asm volatile ( 52 /*53 * Clear nested task flag.54 */55 "pushfl\n"56 "pop %%eax\n"57 "and $0xffffbfff, %%eax\n"58 "push %%eax\n"59 "popfl\n"60 61 54 /* Set up GS register (virtual register segment) */ 62 55 "movl %[vreg_des], %%gs\n" … … 64 57 "pushl %[udata_des]\n" 65 58 "pushl %[stack_top]\n" 66 "pushl %[ ipl]\n"59 "pushl %[eflags]\n" 67 60 "pushl %[utext_des]\n" 68 61 "pushl %[entry]\n" … … 74 67 "iret\n" 75 68 : 76 : [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER), 69 : [eflags_mask] "i" (~EFLAGS_NT), 70 [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER), 77 71 [stack_top] "r" ((uint8_t *) kernel_uarg->uspace_stack + 78 72 kernel_uarg->uspace_stack_size), 79 [ ipl] "r" (ipl),73 [eflags] "r" ((eflags & ~(EFLAGS_NT)) | EFLAGS_IF), 80 74 [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER), 81 75 [entry] "r" (kernel_uarg->uspace_entry),
Note:
See TracChangeset
for help on using the changeset viewer.