Changeset 57c2a87 in mainline


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

Avoid even more magic numbers

Location:
kernel/arch
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/arch/cpu.h

    r811770c r57c2a87  
    5050#define RFLAGS_ID       (1 << 21)
    5151
     52#define CR0_PE          (1 << 0)
    5253#define CR0_MP          (1 << 1)
    5354#define CR0_EM          (1 << 2)
  • kernel/arch/amd64/src/smp/ap.S

    r811770c r57c2a87  
    5858       
    5959        movl %cr0, %eax
    60         orl $1, %eax
     60        orl $CR0_PE, %eax
    6161        movl %eax, %cr0     # switch to protected mode
    6262        jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
  • kernel/arch/ia32/include/arch/cpu.h

    r811770c r57c2a87  
    4141#define EFLAGS_NT       (1 << 14)
    4242#define EFLAGS_RF       (1 << 16)
     43#define EFLAGS_ID       (1 << 21)
    4344
     45#define CR0_PE          (1 << 0)
     46#define CR0_TS          (1 << 3)
    4447#define CR0_AM          (1 << 18)
    4548#define CR0_NW          (1 << 29)
     
    4750#define CR0_PG          (1 << 31)
    4851
    49 #define CR4_OSFXSR_MASK         (1 << 9)
    50 #define CR4_OSXMMEXCPT_MASK     (1 << 10)
     52#define CR4_PSE         (1 << 4)
     53#define CR4_PAE         (1 << 5)
     54#define CR4_OSFXSR      (1 << 9)
     55#define CR4_OSXMMEXCPT  (1 << 10)
    5156
    5257#define IA32_APIC_BASE_GE       (1 << 11)
  • kernel/arch/ia32/include/arch/cpuid.h

    r811770c r57c2a87  
    4444
    4545#include <typedefs.h>
     46#include <arch/cpu.h>
    4647
    4748typedef struct {
     
    8485       
    8586        asm volatile (
    86                 "pushf\n"                    /* read flags */
     87                "pushf\n"                       /* read flags */
    8788                "popl %[ret]\n"
    8889                "movl %[ret], %[val]\n"
    8990               
    90                 "btcl $21, %[val]\n"         /* swap the ID bit */
     91                "xorl %[eflags_id], %[val]\n"   /* swap the ID bit */
    9192               
    92                 "pushl %[val]\n"             /* propagate the change into flags */
     93                "pushl %[val]\n"                /* propagate the change into flags */
    9394                "popf\n"
    9495                "pushf\n"
    9596                "popl %[val]\n"
    9697               
    97                 "andl $(1 << 21), %[ret]\n"  /* interrested only in ID bit */
    98                 "andl $(1 << 21), %[val]\n"
     98                "andl %[eflags_id], %[ret]\n"   /* interrested only in ID bit */
     99                "andl %[eflags_id], %[val]\n"
    99100                "xorl %[val], %[ret]\n"
    100101                : [ret] "=r" (ret), [val] "=r" (val)
     102                : [eflags_id] "i" (EFLAGS_ID)
    101103        );
    102104       
  • kernel/arch/ia32/src/boot/multiboot.S

    r811770c r57c2a87  
    3535#include <genarch/multiboot/multiboot.h>
    3636#include <arch/cpuid.h>
     37#include <arch/cpu.h>
    3738
    3839#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
     
    166167        /* Paging features */
    167168        movl %cr4, %ecx
    168         orl $(1 << 4), %ecx      /* PSE on */
    169         andl $(~(1 << 5)), %ecx  /* PAE off */
     169        orl $CR4_PSE, %ecx      /* PSE on */
     170        andl $~CR4_PAE, %ecx    /* PAE off */
    170171        movl %ecx, %cr4
    171172       
     
    191192       
    192193        movl %cr0, %ebx
    193         orl $(1 << 31), %ebx  /* paging on */
     194        orl $CR0_PG, %ebx       /* paging on */
    194195        movl %ebx, %cr0
    195196        ret
     
    205206        /* Paging features */
    206207        movl %cr4, %ecx
    207         andl $(~(1 << 5)), %ecx  /* PAE off */
     208        andl $~CR4_PAE, %ecx  /* PAE off */
    208209        movl %ecx, %cr4
    209210       
     
    277278               
    278279                movl %cr0, %ebx
    279                 orl $(1 << 31), %ebx  /* paging on */
     280                orl $CR0_PG, %ebx  /* paging on */
    280281                movl %ebx, %cr0
    281282               
  • kernel/arch/ia32/src/boot/vesa_real.inc

    r811770c r57c2a87  
    4949vesa_init_real:
    5050        mov %cr0, %eax
    51         and $~1, %eax
     51        and $~CR0_PE, %eax
    5252        mov %eax, %cr0
    5353       
     
    352352               
    353353                        mov %cr0, %ecx
    354                         or $1, %ecx
     354                        or $CR0_PE, %ecx
    355355                        mov %ecx, %cr0
    356356                       
  • kernel/arch/ia32/src/cpu/cpu.c

    r811770c r57c2a87  
    7272void fpu_disable(void)
    7373{
    74         asm volatile (
    75                 "mov %%cr0, %%eax\n"
    76                 "or $8, %%eax\n"
    77                 "mov %%eax, %%cr0\n"
    78                 ::: "%eax"
    79         );
     74        write_cr0(read_cr0() & ~CR0_TS);
    8075}
    8176
    8277void fpu_enable(void)
    8378{
    84         asm volatile (
    85                 "mov %%cr0, %%eax\n"
    86                 "and $0xffFFffF7, %%eax\n"
    87                 "mov %%eax,%%cr0\n"
    88                 ::: "%eax"
    89         );
     79        write_cr0(read_cr0() | CR0_TS);
    9080}
    9181
     
    115105                        "mov %[help], %%cr4\n"
    116106                        : [help] "+r" (help)
    117                         : [mask] "i" (CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK)
     107                        : [mask] "i" (CR4_OSFXSR | CR4_OSXMMEXCPT)
    118108                );
    119109        }
  • kernel/arch/ia32/src/smp/ap.S

    r811770c r57c2a87  
    3737#include <arch/mm/page.h>
    3838#include <arch/pm.h>
     39#include <arch/cpu.h>
    3940
    4041.section K_TEXT_START, "ax"
     
    6364        /* switch to protected mode */
    6465        movl %cr0, %eax
    65         orl $1, %eax
     66        orl $CR0_PE, %eax
    6667        movl %eax, %cr0
    6768        jmpl $KTEXT, $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
Note: See TracChangeset for help on using the changeset viewer.