Rev 1190 | Rev 1255 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1190 | Rev 1201 | ||
|---|---|---|---|
| Line 34... | Line 34... | ||
| 34 | #include <arch/context.h> /* SP_DELTA */ |
34 | #include <arch/context.h> /* SP_DELTA */ |
| 35 | #include <arch/asm.h> |
35 | #include <arch/asm.h> |
| 36 | #include <arch/debugger.h> |
36 | #include <arch/debugger.h> |
| 37 | #include <print.h> |
37 | #include <print.h> |
| 38 | #include <arch/pm.h> |
38 | #include <arch/pm.h> |
| - | 39 | #include <adt/bitmap.h> |
|
| 39 | 40 | ||
| 40 | /** Perform amd64 specific tasks needed before the new task is run. |
41 | /** Perform amd64 specific tasks needed before the new task is run. |
| 41 | * |
42 | * |
| 42 | * Interrupts are disabled. |
43 | * Interrupts are disabled. |
| 43 | */ |
44 | */ |
| 44 | void before_task_runs_arch(void) |
45 | void before_task_runs_arch(void) |
| 45 | { |
46 | { |
| 46 | size_t iomap_size; |
47 | count_t bits; |
| 47 | ptr_16_64_t cpugdtr; |
48 | ptr_16_64_t cpugdtr; |
| 48 | descriptor_t *gdt_p; |
49 | descriptor_t *gdt_p; |
| 49 | 50 | ||
| 50 | /* |
51 | /* |
| 51 | * Switch the I/O Permission Bitmap, if necessary. |
52 | * Switch the I/O Permission Bitmap, if necessary. |
| 52 | */ |
53 | */ |
| 53 | 54 | ||
| 54 | /* First, copy the I/O Permission Bitmap. */ |
55 | /* First, copy the I/O Permission Bitmap. */ |
| 55 | spinlock_lock(&TASK->lock); |
56 | spinlock_lock(&TASK->lock); |
| 56 | iomap_size = TASK->arch.iomap_size; |
57 | if ((bits = TASK->arch.iomap.bits)) { |
| 57 | if (iomap_size) { |
58 | bitmap_t iomap; |
| - | 59 | ||
| 58 | ASSERT(TASK->arch.iomap); |
60 | ASSERT(TASK->arch.iomap.map); |
| - | 61 | bitmap_initialize(&iomap, CPU->arch.tss->iomap, TSS_IOMAP_SIZE * 8); |
|
| 59 | memcpy(CPU->arch.tss->iomap, TASK->arch.iomap, iomap_size); |
62 | bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits); |
| - | 63 | /* |
|
| 60 | CPU->arch.tss->iomap[iomap_size] = 0xff; /* terminating byte */ |
64 | * It is safe to set the trailing four bits because of the extra |
| - | 65 | * convenience byte in TSS_IOMAP_SIZE. |
|
| - | 66 | */ |
|
| - | 67 | bitmap_set_range(&iomap, TASK->arch.iomap.bits, 4); |
|
| 61 | } |
68 | } |
| 62 | spinlock_unlock(&TASK->lock); |
69 | spinlock_unlock(&TASK->lock); |
| 63 | 70 | ||
| 64 | /* Second, adjust TSS segment limit. */ |
71 | /* Second, adjust TSS segment limit. */ |
| 65 | gdtr_store(&cpugdtr); |
72 | gdtr_store(&cpugdtr); |
| 66 | gdt_p = (descriptor_t *) cpugdtr.base; |
73 | gdt_p = (descriptor_t *) cpugdtr.base; |
| 67 | gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + iomap_size - 1); |
74 | gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits) - 1); |
| 68 | gdtr_load(&cpugdtr); |
75 | gdtr_load(&cpugdtr); |
| 69 | } |
76 | } |
| 70 | 77 | ||
| 71 | /** Perform amd64 specific tasks needed before the new thread is scheduled. */ |
78 | /** Perform amd64 specific tasks needed before the new thread is scheduled. */ |
| 72 | void before_thread_runs_arch(void) |
79 | void before_thread_runs_arch(void) |