Rev 897 | Rev 1187 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 897 | Rev 901 | ||
|---|---|---|---|
| Line 28... | Line 28... | ||
| 28 | 28 | ||
| 29 | #include <proc/scheduler.h> |
29 | #include <proc/scheduler.h> |
| 30 | #include <proc/thread.h> |
30 | #include <proc/thread.h> |
| 31 | #include <arch.h> |
31 | #include <arch.h> |
| 32 | #include <arch/mm/tlb.h> |
32 | #include <arch/mm/tlb.h> |
| - | 33 | #include <arch/mm/page.h> |
|
| 33 | #include <config.h> |
34 | #include <config.h> |
| 34 | #include <align.h> |
35 | #include <align.h> |
| 35 | 36 | ||
| 36 | /** Ensure that thread's kernel stack is locked in TLB. */ |
37 | /** Ensure that thread's kernel stack is locked in TLB. */ |
| 37 | void before_thread_runs_arch(void) |
38 | void before_thread_runs_arch(void) |
| 38 | { |
39 | { |
| 39 | __address base; |
40 | __address base; |
| 40 | 41 | ||
| 41 | base = ALIGN_DOWN(config.base, 4*1024*1024); |
42 | base = ALIGN_DOWN(config.base, 1<<KERNEL_PAGE_WIDTH); |
| 42 | 43 | ||
| 43 | if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + 4*1024*1024) { |
44 | if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + (1<<KERNEL_PAGE_WIDTH)) { |
| 44 | /* |
45 | /* |
| 45 | * Kernel stack of this thread is not locked in DTLB. |
46 | * Kernel stack of this thread is not locked in DTLB. |
| 46 | * First, make sure it is not mapped already. |
47 | * First, make sure it is not mapped already. |
| 47 | * If not, create a locked mapping for it. |
48 | * If not, create a locked mapping for it. |
| 48 | */ |
49 | */ |
| 49 | dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (__address) THREAD->kstack); |
50 | dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (__address) THREAD->kstack); |
| 50 | dtlb_insert_mapping((__address) THREAD->kstack, (__address) THREAD->kstack, PAGESIZE_8K, true, true); |
51 | dtlb_insert_mapping((__address) THREAD->kstack, KA2PA(THREAD->kstack), PAGESIZE_8K, true, true); |
| 51 | } |
52 | } |
| 52 | } |
53 | } |
| 53 | 54 | ||
| 54 | /** Unlock thread's stack from TLB, if necessary. */ |
55 | /** Unlock thread's stack from TLB, if necessary. */ |
| 55 | void after_thread_ran_arch(void) |
56 | void after_thread_ran_arch(void) |
| 56 | { |
57 | { |
| 57 | __address base; |
58 | __address base; |
| 58 | 59 | ||
| 59 | base = ALIGN_DOWN(config.base, 4*1024*1024); |
60 | base = ALIGN_DOWN(config.base, 1<<KERNEL_PAGE_WIDTH); |
| 60 | 61 | ||
| 61 | if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + 4*1024*1024) { |
62 | if ((__address) THREAD->kstack < base || (__address) THREAD->kstack > base + (1<<KERNEL_PAGE_WIDTH)) { |
| 62 | /* |
63 | /* |
| 63 | * Kernel stack of this thread is locked in DTLB. |
64 | * Kernel stack of this thread is locked in DTLB. |
| 64 | * Destroy the mapping. |
65 | * Destroy the mapping. |
| 65 | */ |
66 | */ |
| 66 | dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (__address) THREAD->kstack); |
67 | dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (__address) THREAD->kstack); |