Changeset 0f17bff in mainline


Ignore:
Timestamp:
2016-05-05T08:34:45Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
811770c
Parents:
4b0206c
Message:

Replace magic numbers with macros

Location:
kernel/arch/ia32
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/include/arch/asm.h

    r4b0206c r0f17bff  
    8787GEN_WRITE_REG(cr3)
    8888
     89GEN_WRITE_REG(cr0)
     90
    8991GEN_READ_REG(dr0)
    9092GEN_READ_REG(dr1)
     
    232234}
    233235
    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        
     236NO_TRACE static inline uint32_t read_eflags(void)
     237{
     238        uint32_t eflags;
     239
    246240        asm volatile (
    247241                "pushf\n"
    248242                "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
     249NO_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 */
     262NO_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 */
     273NO_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;
    254280}
    255281
    256282/** Disable interrupts.
    257283 *
    258  * Disable interrupts and return previous
    259  * value of EFLAGS.
     284 * Disable interrupts and return the previous interrupt priority level.
    260285 *
    261286 * @return Old interrupt priority level.
    262  *
    263287 */
    264288NO_TRACE static inline ipl_t interrupts_disable(void)
    265289{
    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;
    276295}
    277296
    278297/** Restore interrupt priority level.
    279298 *
    280  * Restore EFLAGS.
     299 * Restore a saved interrupt priority level.
    281300 *
    282301 * @param ipl Saved interrupt priority level.
     
    285304NO_TRACE static inline void interrupts_restore(ipl_t ipl)
    286305{
    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);
    310307}
    311308
     
    317314NO_TRACE static inline bool interrupts_disabled(void)
    318315{
    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);
    328317}
    329318
  • kernel/arch/ia32/include/arch/cpu.h

    r4b0206c r0f17bff  
    3636#define KERN_ia32_CPU_H_
    3737
    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)
    4243
    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
    4555
    4656/* Support for SYSENTER and SYSEXIT */
    47 #define IA32_MSR_SYSENTER_CS   0x174U
    48 #define IA32_MSR_SYSENTER_ESP  0x175U
    49 #define IA32_MSR_SYSENTER_EIP  0x176U
     57#define IA32_MSR_SYSENTER_CS    0x174
     58#define IA32_MSR_SYSENTER_ESP   0x175
     59#define IA32_MSR_SYSENTER_EIP   0x176
    5060
    5161#ifndef __ASM__
  • kernel/arch/ia32/include/arch/smp/apic.h

    r4b0206c r0f17bff  
    3636#define KERN_ia32_APIC_H_
    3737
     38#define L_APIC_BASE     0xfee00000
     39#define IO_APIC_BASE    0xfec00000
     40
     41#ifndef __ASM__
     42
    3843#include <typedefs.h>
    3944#include <cpu.h>
     
    364369extern void io_apic_enable_irqs(uint16_t);
    365370
     371#endif  /* __ASM__ */
     372
    366373#endif
    367374
  • kernel/arch/ia32/src/asm.S

    r4b0206c r0f17bff  
    3636#include <arch/mm/page.h>
    3737#include <arch/istate_struct.h>
     38#include <arch/smp/apic.h>
    3839
    3940.text
     
    110111FUNCTION_BEGIN(paging_on)
    111112        movl %cr0, %edx
    112         orl $(1 << 31), %edx  /* paging on */
     113        orl $CR0_PG, %edx  /* paging on */
    113114       
    114115        /* Clear Cache Disable and not Write Though */
    115         andl $~((1 << 30) | (1 << 29)), %edx
     116        andl $~(CR0_CD | CR0_NW), %edx
    116117        movl %edx, %cr0
    117118        jmp 0f
     
    127128 */
    128129FUNCTION_BEGIN(enable_l_apic_in_msr)
    129         movl $0x1b, %ecx
     130        movl $IA32_MSR_APIC_BASE, %ecx
    130131        rdmsr
    131         orl $(1 << 11), %eax
    132         orl $(0xfee00000), %eax
     132        orl $(L_APIC_BASE | IA32_APIC_BASE_GE), %eax
    133133        wrmsr
    134134        ret
  • kernel/arch/ia32/src/pm.c

    r4b0206c r0f17bff  
    4747#include <arch/boot/boot.h>
    4848#include <interrupt.h>
     49#include <arch/cpu.h>
    4950
    5051/*
     
    256257}
    257258
    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 
    282259void pm_init(void)
    283260{
     
    326303        tr_load(GDT_SELECTOR(TSS_DES));
    327304       
    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);
    330310}
    331311
  • kernel/arch/ia32/src/smp/apic.c

    r4b0206c r0f17bff  
    7272 *
    7373 */
    74 volatile uint32_t *l_apic = (uint32_t *) UINT32_C(0xfee00000);
    75 volatile uint32_t *io_apic = (uint32_t *) UINT32_C(0xfec00000);
     74volatile uint32_t *l_apic = (uint32_t *) L_APIC_BASE;
     75volatile uint32_t *io_apic = (uint32_t *) IO_APIC_BASE;
    7676
    7777uint32_t apic_id_mask = 0;
  • kernel/arch/ia32/src/userspace.c

    r4b0206c r0f17bff  
    3939#include <abi/proc/uarg.h>
    4040#include <mm/as.h>
     41#include <arch/cpu.h>
     42#include <arch/asm.h>
    4143
    4244/** Enter userspace
     
    4749void userspace(uspace_arg_t *kernel_uarg)
    4850{
    49         ipl_t ipl = interrupts_disable();
     51        uint32_t eflags = read_eflags();
    5052       
    5153        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                
    6154                /* Set up GS register (virtual register segment) */
    6255                "movl %[vreg_des], %%gs\n"
     
    6457                "pushl %[udata_des]\n"
    6558                "pushl %[stack_top]\n"
    66                 "pushl %[ipl]\n"
     59                "pushl %[eflags]\n"
    6760                "pushl %[utext_des]\n"
    6861                "pushl %[entry]\n"
     
    7467                "iret\n"
    7568                :
    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),
    7771                  [stack_top] "r" ((uint8_t *) kernel_uarg->uspace_stack +
    7872                      kernel_uarg->uspace_stack_size),
    79                   [ipl] "r" (ipl),
     73                  [eflags] "r" ((eflags & ~(EFLAGS_NT)) | EFLAGS_IF),
    8074                  [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER),
    8175                  [entry] "r" (kernel_uarg->uspace_entry),
Note: See TracChangeset for help on using the changeset viewer.