Changeset 39cea6a in mainline for arch/ia32/src


Ignore:
Timestamp:
2006-04-13T17:38:03Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e185136
Parents:
897ad60
Message:

Cleanup pm.c and pm.h code on ia32 and amd64.
Add before_task_runs() and before_task_runs_arch() for each architecture.
Add ia32 and amd64 code to ensure I/O Permission Bitmap update.

Location:
arch/ia32/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/src/cpu/cpu.c

    r897ad60 r39cea6a  
    8888}
    8989
    90 
    91 
    92 
    9390void cpu_arch_init(void)
    9491{
    95         __u32 help=0;
     92        cpuid_feature_info fi;
     93        cpuid_extended_feature_info efi;
     94        cpu_info_t info;
     95        __u32 help = 0;
    9696       
    9797        CPU->arch.tss = tss_p;
    98         CPU->fpu_owner=NULL;
     98        CPU->arch.tss->iomap_base = &CPU->arch.tss->iomap[0] - ((__u8 *) CPU->arch.tss);
    9999
    100         cpuid_feature_info fi;
    101         cpuid_extended_feature_info efi;
     100        CPU->fpu_owner = NULL;
    102101
    103         cpu_info_t info;
    104102        cpuid(1, &info);
    105103
    106         fi.word=info.cpuid_edx;
    107         efi.word=info.cpuid_ecx;
     104        fi.word = info.cpuid_edx;
     105        efi.word = info.cpuid_ecx;
    108106       
    109         if(fi.bits.fxsr)        fpu_fxsr();
    110         else fpu_fsr();
     107        if (fi.bits.fxsr)
     108                fpu_fxsr();
     109        else
     110                fpu_fsr();     
    111111       
    112         if(fi.bits.sse) asm volatile (
    113                 "mov %%cr4,%0;\n"
    114                 "or %1,%0;\n"
    115                 "mov %0,%%cr4;\n"
    116                 :"+r"(help)
    117                 :"i"(CR4_OSFXSR_MASK|(1<<10))
    118         );
    119        
     112        if (fi.bits.sse) {
     113                asm volatile (
     114                        "mov %%cr4,%0\n"
     115                        "or %1,%0\n"
     116                        "mov %0,%%cr4\n"
     117                        : "+r" (help)
     118                        : "i" (CR4_OSFXSR_MASK|(1<<10))
     119                );
     120        }
    120121}
    121 
    122122
    123123void cpu_identify(void)
  • arch/ia32/src/pm.c

    r897ad60 r39cea6a  
    5353 * structure in it's base.
    5454 */
    55 struct descriptor gdt[GDT_ITEMS] = {
     55descriptor_t gdt[GDT_ITEMS] = {
    5656        /* NULL descriptor */
    5757        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     
    6969};
    7070
    71 static struct idescriptor idt[IDT_ITEMS];
    72 
    73 static struct tss tss;
    74 
    75 struct tss *tss_p = NULL;
     71static idescriptor_t idt[IDT_ITEMS];
     72
     73static tss_t tss;
     74
     75tss_t *tss_p = NULL;
    7676
    7777/* gdtr is changed by kmp before next CPU is initialized */
    78 struct ptr_16_32 bootstrap_gdtr = { .limit = sizeof(gdt), .base = KA2PA((__address) gdt) };
    79 struct ptr_16_32 gdtr = { .limit = sizeof(gdt), .base = (__address) gdt };
    80 
    81 void gdt_setbase(struct descriptor *d, __address base)
     78ptr_16_32_t bootstrap_gdtr = { .limit = sizeof(gdt), .base = KA2PA((__address) gdt) };
     79ptr_16_32_t gdtr = { .limit = sizeof(gdt), .base = (__address) gdt };
     80
     81void gdt_setbase(descriptor_t *d, __address base)
    8282{
    8383        d->base_0_15 = base & 0xffff;
     
    8686}
    8787
    88 void gdt_setlimit(struct descriptor *d, __u32 limit)
     88void gdt_setlimit(descriptor_t *d, __u32 limit)
    8989{
    9090        d->limit_0_15 = limit & 0xffff;
     
    9292}
    9393
    94 void idt_setoffset(struct idescriptor *d, __address offset)
     94void idt_setoffset(idescriptor_t *d, __address offset)
    9595{
    9696        /*
     
    101101}
    102102
    103 void tss_initialize(struct tss *t)
     103void tss_initialize(tss_t *t)
    104104{
    105105        memsetb((__address) t, sizeof(struct tss), 0);
     
    111111void idt_init(void)
    112112{
    113         struct idescriptor *d;
     113        idescriptor_t *d;
    114114        int i;
    115115
     
    142142static void clean_IOPL_NT_flags(void)
    143143{
    144         asm
    145         (
    146                 "pushfl;"
    147                 "pop %%eax;"
    148                 "and $0xffff8fff,%%eax;"
    149                 "push %%eax;"
    150                 "popfl;"
    151                 :
    152                 :
    153                 :"%eax"
     144        __asm__ volatile (
     145                "pushfl\n"
     146                "pop %%eax\n"
     147                "and $0xffff8fff, %%eax\n"
     148                "push %%eax\n"
     149                "popfl\n"
     150                : : : "eax"
    154151        );
    155152}
     
    158155static void clean_AM_flag(void)
    159156{
    160         asm
    161         (
    162                 "mov %%cr0,%%eax;"
    163                 "and $0xFFFBFFFF,%%eax;"
    164                 "mov %%eax,%%cr0;"
    165                 :
    166                 :
    167                 :"%eax"
     157        __asm__ volatile (
     158                "mov %%cr0, %%eax\n"
     159                "and $0xfffbffff, %%eax\n"
     160                "mov %%eax, %%cr0\n"
     161                : : : "eax"
    168162        );
    169163}
     
    171165void pm_init(void)
    172166{
    173         struct descriptor *gdt_p = (struct descriptor *) gdtr.base;
    174         struct ptr_16_32 idtr;
     167        descriptor_t *gdt_p = (descriptor_t *) gdtr.base;
     168        ptr_16_32_t idtr;
    175169
    176170        /*
     
    196190        }
    197191        else {
    198                 tss_p = (struct tss *) malloc(sizeof(struct tss),FRAME_ATOMIC);
     192                tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC);
    199193                if (!tss_p)
    200194                        panic("could not allocate TSS\n");
     
    208202       
    209203        gdt_setbase(&gdt_p[TSS_DES], (__address) tss_p);
    210         gdt_setlimit(&gdt_p[TSS_DES], sizeof(struct tss) - 1);
     204        gdt_setlimit(&gdt_p[TSS_DES], sizeof(tss_t) - 1);
    211205
    212206        /*
     
    222216void set_tls_desc(__address tls)
    223217{
    224         struct ptr_16_32 cpugdtr;
    225         struct descriptor *gdt_p = (struct descriptor *) cpugdtr.base;
     218        ptr_16_32_t cpugdtr;
     219        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    226220
    227221        gdtr_store(&cpugdtr);
  • arch/ia32/src/proc/scheduler.c

    r897ad60 r39cea6a  
    2929#include <proc/scheduler.h>
    3030#include <cpu.h>
     31#include <proc/task.h>
    3132#include <proc/thread.h>
    3233#include <arch.h>
     
    3435#include <arch/debugger.h>
    3536#include <arch/pm.h>
     37#include <arch/asm.h>
    3638
     39/** Perform ia32 specific tasks needed before the new task is run. */
     40void before_task_runs_arch(void)
     41{
     42}
     43
     44/** Perform ia32 specific tasks needed before the new thread is scheduled.
     45 *
     46 * THREAD is locked and interrupts are disabled.
     47 */
    3748void before_thread_runs_arch(void)
    3849{
     50        size_t iomap_size;
     51        ptr_16_32_t cpugdtr;
     52        descriptor_t *gdt_p;
     53
    3954        CPU->arch.tss->esp0 = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
    4055        CPU->arch.tss->ss0 = selector(KDATA_DES);
     
    4257        /* Set up TLS in GS register */
    4358        set_tls_desc(THREAD->arch.tls);
     59
     60        /*
     61         * Switch the I/O Permission Bitmap, if necessary.
     62         *
     63         * First, copy the I/O Permission Bitmap.
     64         * This needs to be changed so that the
     65         * copying is avoided if the same task
     66         * was already running and the iomap did
     67         * not change.
     68         */
     69        spinlock_lock(&TASK->lock);
     70        iomap_size = TASK->arch.iomap_size;
     71        if (iomap_size) {
     72                ASSERT(TASK->arch.iomap);
     73                memcpy(CPU->arch.tss->iomap, TASK->arch.iomap, iomap_size);
     74                CPU->arch.tss->iomap[iomap_size] = 0xff;        /* terminating byte */
     75        }
     76        spinlock_unlock(&TASK->lock);   
     77
     78        /* Second, adjust TSS segment limit. */
     79        gdtr_store(&cpugdtr);
     80        gdt_p = (descriptor_t *) cpugdtr.base;
     81        gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + iomap_size - 1);
     82        gdtr_load(&cpugdtr);
    4483
    4584#ifdef CONFIG_DEBUG_AS_WATCHPOINT
Note: See TracChangeset for help on using the changeset viewer.