Changeset 99d6fd0 in mainline for kernel/arch/amd64


Ignore:
Timestamp:
2009-03-13T12:57:15Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
421c833
Parents:
0160b1c8
Message:

cleanup pm.h and related stuff (no change in functionality)

Location:
kernel/arch/amd64
Files:
5 edited

Legend:

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

    r0160b1c8 r99d6fd0  
    343343 *
    344344 */
    345 static inline void gdtr_load(struct ptr_16_64 *gdtr_reg)
     345static inline void gdtr_load(ptr_16_64_t *gdtr_reg)
    346346{
    347347        asm volatile (
     
    356356 *
    357357 */
    358 static inline void gdtr_store(struct ptr_16_64 *gdtr_reg)
     358static inline void gdtr_store(ptr_16_64_t *gdtr_reg)
    359359{
    360360        asm volatile (
     
    369369 *
    370370 */
    371 static inline void idtr_load(struct ptr_16_64 *idtr_reg)
     371static inline void idtr_load(ptr_16_64_t *idtr_reg)
    372372{
    373373        asm volatile (
  • kernel/arch/amd64/include/cpu.h

    r0160b1c8 r99d6fd0  
    3636#define KERN_amd64_CPU_H_
    3737
    38 #define RFLAGS_IF       (1 << 9)
    39 #define RFLAGS_DF       (1 << 10)
    40 #define RFLAGS_RF       (1 << 16)
     38#define RFLAGS_IF  (1 << 9)
     39#define RFLAGS_DF  (1 << 10)
     40#define RFLAGS_RF  (1 << 16)
    4141
    4242#define EFER_MSR_NUM    0xc0000080
     
    6363        int model;
    6464        int stepping;
    65         struct tss *tss;
     65        tss_t *tss;
    6666       
    67         count_t iomapver_copy;  /** Copy of TASK's I/O Permission bitmap generation count. */
     67        count_t iomapver_copy;  /** Copy of TASK's I/O Permission bitmap generation count. */
    6868} cpu_arch_t;
    6969
    7070struct star_msr {
    71        
    7271};
    7372
    7473struct lstar_msr {
    75        
    7674};
    7775
  • kernel/arch/amd64/include/pm.h

    r0160b1c8 r99d6fd0  
    2727 */
    2828
    29 /** @addtogroup amd64   
     29/** @addtogroup amd64
    3030 * @{
    3131 */
     
    3737
    3838#ifndef __ASM__
    39 #       include <arch/types.h>
    40 #       include <arch/context.h>
     39        #include <arch/types.h>
     40        #include <arch/context.h>
    4141#endif
    4242
    43 #define IDT_ITEMS 64
    44 #define GDT_ITEMS 8
     43#define IDT_ITEMS  64
     44#define GDT_ITEMS  8
    4545
    4646
    47 #define NULL_DES        0
    48 /* Warning: Do not reorder next items, unless you look into syscall.c!!! */
    49 #define KTEXT_DES       1
    50 #define KDATA_DES       2
    51 #define UDATA_DES       3
    52 #define UTEXT_DES       4
    53 #define KTEXT32_DES     5
    54 /* EndOfWarning */
    55 #define TSS_DES         6
    56 
    57 
     47#define NULL_DES     0
     48/* Warning: Do not reorder the following items, unless you look into syscall.c! */
     49#define KTEXT_DES    1
     50#define KDATA_DES    2
     51#define UDATA_DES    3
     52#define UTEXT_DES    4
     53#define KTEXT32_DES  5
     54/* End of warning */
     55#define TSS_DES      6
    5856
    5957#ifdef CONFIG_FB
    6058
    61 #define VESA_INIT_DES           8
    62 #define VESA_INIT_SEGMENT 0x8000
    63 #undef GDT_ITEMS
    64 #define GDT_ITEMS 9
     59#define VESA_INIT_DES      8
     60#define VESA_INIT_SEGMENT  0x8000
    6561
    66 #endif /*CONFIG_FB*/
     62#undef GDT_ITEMS
     63#define GDT_ITEMS  9
    6764
     65#endif /* CONFIG_FB */
    6866
     67#define gdtselector(des)  ((des) << 3)
     68#define idtselector(des)  ((des) << 4)
    6969
    70 #define gdtselector(des)        ((des) << 3)
    71 #define idtselector(des)        ((des) << 4)
     70#define PL_KERNEL  0
     71#define PL_USER    3
    7272
    73 #define PL_KERNEL       0
    74 #define PL_USER         3
     73#define AR_PRESENT   ( 1 << 7)
     74#define AR_DATA       (2 << 3)
     75#define AR_CODE       (3 << 3)
     76#define AR_WRITABLE   (1 << 1)
     77#define AR_READABLE   (1 << 1)
     78#define AR_TSS        (0x09)
     79#define AR_INTERRUPT  (0x0e)
     80#define AR_TRAP       (0x0f)
    7581
    76 #define AR_PRESENT      (1<<7)
    77 #define AR_DATA         (2<<3)
    78 #define AR_CODE         (3<<3)
    79 #define AR_WRITABLE     (1<<1)
    80 #define AR_READABLE     (1<<1)
    81 #define AR_TSS          (0x9)
    82 #define AR_INTERRUPT    (0xe)
    83 #define AR_TRAP         (0xf)
     82#define DPL_KERNEL  (PL_KERNEL << 5)
     83#define DPL_USER    (PL_USER << 5)
    8484
    85 #define DPL_KERNEL      (PL_KERNEL<<5)
    86 #define DPL_USER        (PL_USER<<5)
     85#define TSS_BASIC_SIZE  104
     86#define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
    8787
    88 #define TSS_BASIC_SIZE  104
    89 #define TSS_IOMAP_SIZE  (16*1024+1)     /* 16K for bitmap + 1 terminating byte for convenience */
    90 
    91 #define IO_PORTS        (64*1024)
     88#define IO_PORTS  (64 * 1024)
    9289
    9390#ifndef __ASM__
    9491
    95 struct descriptor {
     92typedef struct {
    9693        unsigned limit_0_15: 16;
    9794        unsigned base_0_15: 16;
     
    104101        unsigned granularity : 1;
    105102        unsigned base_24_31: 8;
    106 } __attribute__ ((packed));
    107 typedef struct descriptor descriptor_t;
     103} __attribute__ ((packed)) descriptor_t;
    108104
    109 struct tss_descriptor {
     105typedef struct {
    110106        unsigned limit_0_15: 16;
    111107        unsigned base_0_15: 16;
     
    122118        unsigned base_32_63 : 32;
    123119        unsigned  : 32;
    124 } __attribute__ ((packed));
    125 typedef struct tss_descriptor tss_descriptor_t;
     120} __attribute__ ((packed)) tss_descriptor_t;
    126121
    127 struct idescriptor {
     122typedef struct {
    128123        unsigned offset_0_15: 16;
    129124        unsigned selector: 16;
     
    136131        unsigned offset_32_63: 32;
    137132        unsigned  : 32;
    138 } __attribute__ ((packed));
    139 typedef struct idescriptor idescriptor_t;
     133} __attribute__ ((packed)) idescriptor_t;
    140134
    141 struct ptr_16_64 {
     135typedef struct {
    142136        uint16_t limit;
    143137        uint64_t base;
    144 } __attribute__ ((packed));
    145 typedef struct ptr_16_64 ptr_16_64_t;
     138} __attribute__ ((packed)) ptr_16_64_t;
    146139
    147 struct ptr_16_32 {
     140typedef struct {
    148141        uint16_t limit;
    149142        uint32_t base;
    150 } __attribute__ ((packed));
    151 typedef struct ptr_16_32 ptr_16_32_t;
     143} __attribute__ ((packed)) ptr_16_32_t;
    152144
    153 struct tss {
     145typedef struct {
    154146        uint32_t reserve1;
    155147        uint64_t rsp0;
     
    168160        uint16_t iomap_base;
    169161        uint8_t iomap[TSS_IOMAP_SIZE];
    170 } __attribute__ ((packed));
    171 typedef struct tss tss_t;
     162} __attribute__ ((packed)) tss_t;
    172163
    173164extern tss_t *tss_p;
  • kernel/arch/amd64/src/ddi/ddi.c

    r0160b1c8 r99d6fd0  
    5858{
    5959        count_t bits;
    60 
     60       
    6161        bits = ioaddr + size;
    6262        if (bits > IO_PORTS)
    6363                return ENOENT;
    64 
     64       
    6565        if (task->arch.iomap.bits < bits) {
    6666                bitmap_t oldiomap;
    6767                uint8_t *newmap;
    68        
     68               
    6969                /*
    7070                 * The I/O permission bitmap is too small and needs to be grown.
     
    7878                    task->arch.iomap.bits);
    7979                bitmap_initialize(&task->arch.iomap, newmap, bits);
    80 
     80               
    8181                /*
    8282                 * Mark the new range inaccessible.
     
    8484                bitmap_set_range(&task->arch.iomap, oldiomap.bits,
    8585                    bits - oldiomap.bits);
    86 
     86               
    8787                /*
    8888                 * In case there really existed smaller iomap,
    8989                 * copy its contents and deallocate it.
    90                  */             
     90                 */
    9191                if (oldiomap.bits) {
    9292                        bitmap_copy(&task->arch.iomap, &oldiomap,
     
    9595                }
    9696        }
    97 
     97       
    9898        /*
    9999         * Enable the range and we are done.
    100100         */
    101101        bitmap_clear_range(&task->arch.iomap, (index_t) ioaddr, (count_t) size);
    102 
     102       
    103103        /*
    104104         * Increment I/O Permission bitmap generation counter.
    105105         */
    106106        task->arch.iomapver++;
    107 
     107       
    108108        return 0;
    109109}
     
    123123        tss_descriptor_t *tss_desc;
    124124        count_t ver;
    125 
     125       
    126126        /* First, copy the I/O Permission Bitmap. */
    127127        spinlock_lock(&TASK->lock);
     
    141141        }
    142142        spinlock_unlock(&TASK->lock);
    143 
     143       
    144144        /*
    145145         * Second, adjust TSS segment limit.
     
    152152       
    153153        /*
    154         * Before we load new TSS limit, the current TSS descriptor
    155         * type must be changed to describe inactive TSS.
    156         */
    157         tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
     154        * Before we load new TSS limit, the current TSS descriptor
     155        * type must be changed to describe inactive TSS.
     156        */
     157        tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
    158158        tss_desc->type = AR_TSS;
    159159        tr_load(gdtselector(TSS_DES));
  • kernel/arch/amd64/src/pm.c

    r0160b1c8 r99d6fd0  
    138138void gdt_tss_setlimit(descriptor_t *d, uint32_t limit)
    139139{
    140         struct tss_descriptor *td = (tss_descriptor_t *) d;
    141 
     140        tss_descriptor_t *td = (tss_descriptor_t *) d;
     141       
    142142        td->limit_0_15 = limit & 0xffff;
    143143        td->limit_16_19 = (limit >> 16) & 0xf;
     
    186186void pm_init(void)
    187187{
    188         descriptor_t *gdt_p = (struct descriptor *) gdtr.base;
     188        descriptor_t *gdt_p = (descriptor_t *) gdtr.base;
    189189        tss_descriptor_t *tss_desc;
    190 
     190       
    191191        /*
    192192         * Each CPU has its private GDT and TSS.
    193193         * All CPUs share one IDT.
    194194         */
    195 
     195       
    196196        if (config.cpu_active == 1) {
    197197                idt_init();
     
    201201                 */
    202202                tss_p = &tss;
    203         }
    204         else {
     203        } else {
    205204                /* We are going to use malloc, which may return
    206205                 * non boot-mapped pointer, initialize the CR3 register
    207206                 * ahead of page_init */
    208207                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    209 
    210                 tss_p = (struct tss *) malloc(sizeof(tss_t), FRAME_ATOMIC);
     208               
     209                tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC);
    211210                if (!tss_p)
    212211                        panic("Cannot allocate TSS.");
    213212        }
    214 
     213       
    215214        tss_initialize(tss_p);
    216 
     215       
    217216        tss_desc = (tss_descriptor_t *) (&gdt_p[TSS_DES]);
    218217        tss_desc->present = 1;
     
    222221        gdt_tss_setbase(&gdt_p[TSS_DES], (uintptr_t) tss_p);
    223222        gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE - 1);
    224 
     223       
    225224        gdtr_load(&gdtr);
    226225        idtr_load(&idtr);
Note: See TracChangeset for help on using the changeset viewer.