Rev 1826 | Rev 1894 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1826 | Rev 1833 | ||
|---|---|---|---|
| Line 103... | Line 103... | ||
| 103 | */ |
103 | */ |
| 104 | uintptr_t hardcoded_load_address = 0; /**< Virtual address of where the kernel is loaded. */ |
104 | uintptr_t hardcoded_load_address = 0; /**< Virtual address of where the kernel is loaded. */ |
| 105 | size_t hardcoded_ktext_size = 0; /**< Size of the kernel code in bytes. */ |
105 | size_t hardcoded_ktext_size = 0; /**< Size of the kernel code in bytes. */ |
| 106 | size_t hardcoded_kdata_size = 0; /**< Size of the kernel data in bytes. */ |
106 | size_t hardcoded_kdata_size = 0; /**< Size of the kernel data in bytes. */ |
| 107 | 107 | ||
| - | 108 | uintptr_t stack_safe = 0; /**< Lowest safe stack virtual address */ |
|
| - | 109 | ||
| 108 | void main_bsp(void); |
110 | void main_bsp(void); |
| 109 | void main_ap(void); |
111 | void main_ap(void); |
| 110 | 112 | ||
| 111 | /* |
113 | /* |
| 112 | * These two functions prevent stack from underflowing during the |
114 | * These two functions prevent stack from underflowing during the |
| Line 130... | Line 132... | ||
| 130 | * Assuming interrupts_disable(). |
132 | * Assuming interrupts_disable(). |
| 131 | * |
133 | * |
| 132 | */ |
134 | */ |
| 133 | void main_bsp(void) |
135 | void main_bsp(void) |
| 134 | { |
136 | { |
| 135 | uintptr_t stackaddr; |
- | |
| 136 | - | ||
| 137 | config.cpu_count = 1; |
137 | config.cpu_count = 1; |
| 138 | config.cpu_active = 1; |
138 | config.cpu_active = 1; |
| 139 | 139 | ||
| 140 | config.base = hardcoded_load_address; |
140 | config.base = hardcoded_load_address; |
| 141 | config.memory_size = get_memory_size(); |
141 | config.memory_size = get_memory_size(); |
| 142 | 142 | ||
| 143 | config.kernel_size = ALIGN_UP(hardcoded_ktext_size + hardcoded_kdata_size, PAGE_SIZE); |
143 | config.kernel_size = ALIGN_UP(hardcoded_ktext_size + hardcoded_kdata_size, PAGE_SIZE); |
| - | 144 | config.stack_size = CONFIG_STACK_SIZE; |
|
| - | 145 | ||
| - | 146 | /* Initialy the stack is placed just after the kernel */ |
|
| 144 | stackaddr = config.base + config.kernel_size; |
147 | config.stack_base = config.base + config.kernel_size; |
| 145 | 148 | ||
| 146 | /* Avoid placing kernel on top of init */ |
149 | /* Avoid placing stack on top of init */ |
| 147 | count_t i; |
150 | count_t i; |
| 148 | bool overlap = false; |
- | |
| 149 | for (i = 0; i < init.cnt; i++) |
151 | for (i = 0; i < init.cnt; i++) { |
| 150 | if (PA_overlaps(stackaddr, CONFIG_STACK_SIZE, init.tasks[i].addr, init.tasks[i].size)) { |
152 | if (PA_overlaps(config.stack_base, config.stack_size, init.tasks[i].addr, init.tasks[i].size)) |
| 151 | stackaddr = ALIGN_UP(init.tasks[i].addr + init.tasks[i].size, CONFIG_STACK_SIZE); |
153 | config.stack_base = ALIGN_UP(init.tasks[i].addr + init.tasks[i].size, config.stack_size); |
| 152 | init.tasks[i].size = ALIGN_UP(init.tasks[i].size, CONFIG_STACK_SIZE) + CONFIG_STACK_SIZE; |
- | |
| 153 | overlap = true; |
- | |
| 154 | } |
154 | } |
| 155 | 155 | ||
| 156 | if (!overlap) |
156 | if (config.stack_base < stack_safe) |
| 157 | config.kernel_size += CONFIG_STACK_SIZE; |
157 | config.stack_base = ALIGN_UP(stack_safe, PAGE_SIZE); |
| 158 | 158 | ||
| 159 | context_save(&ctx); |
159 | context_save(&ctx); |
| 160 | context_set(&ctx, FADDR(main_bsp_separated_stack), stackaddr, THREAD_STACK_SIZE); |
160 | context_set(&ctx, FADDR(main_bsp_separated_stack), config.stack_base, THREAD_STACK_SIZE); |
| 161 | context_restore(&ctx); |
161 | context_restore(&ctx); |
| 162 | /* not reached */ |
162 | /* not reached */ |
| 163 | } |
163 | } |
| 164 | 164 | ||
| 165 | 165 | ||
| Line 200... | Line 200... | ||
| 200 | page_init(); |
200 | page_init(); |
| 201 | tlb_init(); |
201 | tlb_init(); |
| 202 | arch_post_mm_init(); |
202 | arch_post_mm_init(); |
| 203 | 203 | ||
| 204 | version_print(); |
204 | version_print(); |
| 205 | printf("%.*p: hardcoded_ktext_size=%zdK, hardcoded_kdata_size=%zdK\n", sizeof(uintptr_t) * 2, config.base, hardcoded_ktext_size >> 10, hardcoded_kdata_size >> 10); |
205 | printf("kernel: %.*p hardcoded_ktext_size=%zdK, hardcoded_kdata_size=%zdK\n", sizeof(uintptr_t) * 2, config.base, hardcoded_ktext_size >> 10, hardcoded_kdata_size >> 10); |
| - | 206 | printf("stack: %.*p size=%zdK\n", sizeof(uintptr_t) * 2, config.stack_base, config.stack_size >> 10); |
|
| 206 | 207 | ||
| 207 | arch_pre_smp_init(); |
208 | arch_pre_smp_init(); |
| 208 | smp_init(); |
209 | smp_init(); |
| 209 | 210 | ||
| 210 | slab_enable_cpucache(); /* Slab must be initialized AFTER we know the number of processors */ |
211 | slab_enable_cpucache(); /* Slab must be initialized AFTER we know the number of processors */ |