Changes in kernel/generic/src/main/main.c [128359eb:f35749e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/main/main.c
r128359eb rf35749e 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2001-2004 Jakub Jermar 3 4 * All rights reserved. … … 80 81 #include <arch/arch.h> 81 82 #include <arch.h> 82 #include <arch/faddr.h>83 83 #include <ipc/ipc.h> 84 84 #include <macros.h> … … 111 111 CHECK_INT_TYPE(64); 112 112 113 task_t *kernel_task; 114 113 115 /** Global configuration structure. */ 114 116 config_t config = { … … 132 134 }; 133 135 134 context_t ctx; 135 136 /** Lowest safe stack virtual address. */ 137 uintptr_t stack_safe = 0; 136 static context_t ctx; 137 138 // NOTE: All kernel stacks must be aligned to STACK_SIZE, see CURRENT. 139 static const size_t bootstrap_stack_size = STACK_SIZE; 140 static _Alignas(STACK_SIZE) uint8_t bootstrap_stack[STACK_SIZE]; 141 142 /* Just a convenient value for some assembly code. */ 143 uint8_t *const bootstrap_stack_top = bootstrap_stack + STACK_SIZE; 138 144 139 145 /* … … 170 176 ALIGN_UP((uintptr_t) kdata_end - config.base, PAGE_SIZE); 171 177 172 /* 173 * NOTE: All kernel stacks must be aligned to STACK_SIZE, 174 * see CURRENT. 175 */ 176 177 /* Place the stack after the kernel, init and ballocs. */ 178 config.stack_base = 179 ALIGN_UP(config.base + config.kernel_size, STACK_SIZE); 180 config.stack_size = STACK_SIZE; 181 182 /* Avoid placing stack on top of init */ 183 size_t i; 184 for (i = 0; i < init.cnt; i++) { 185 uintptr_t p = init.tasks[i].paddr + init.tasks[i].size; 186 uintptr_t bottom = PA2KA(ALIGN_UP(p, STACK_SIZE)); 187 188 if (config.stack_base < bottom) 189 config.stack_base = bottom; 190 } 191 192 /* Avoid placing stack on top of boot allocations. */ 193 if (ballocs.size) { 194 uintptr_t bottom = 195 ALIGN_UP(ballocs.base + ballocs.size, STACK_SIZE); 196 if (config.stack_base < bottom) 197 config.stack_base = bottom; 198 } 199 200 if (config.stack_base < stack_safe) 201 config.stack_base = ALIGN_UP(stack_safe, STACK_SIZE); 202 203 context_save(&ctx); 204 context_set(&ctx, FADDR(main_bsp_separated_stack), 205 config.stack_base, STACK_SIZE); 178 context_create(&ctx, main_bsp_separated_stack, 179 bootstrap_stack, bootstrap_stack_size); 206 180 context_restore(&ctx); 207 181 /* not reached */ … … 220 194 version_print(); 221 195 222 LOG("\nconfig.base=%p config.kernel_size=%zu" 223 "\nconfig.stack_base=%p config.stack_size=%zu", 224 (void *) config.base, config.kernel_size, 225 (void *) config.stack_base, config.stack_size); 196 LOG("\nconfig.base=%p config.kernel_size=%zu", 197 (void *) config.base, config.kernel_size); 226 198 227 199 #ifdef CONFIG_KCONSOLE … … 304 276 panic("Cannot create kernel task."); 305 277 278 kernel_task = kernel; 279 306 280 /* 307 281 * Create the first thread. … … 311 285 if (!kinit_thread) 312 286 panic("Cannot create kinit thread."); 313 thread_ready(kinit_thread); 314 315 /* 316 * This call to scheduler() will return to kinit, 287 thread_start(kinit_thread); 288 thread_detach(kinit_thread); 289 290 /* 291 * This call to scheduler_run() will return to kinit, 317 292 * starting the thread of kernel threads. 318 293 */ 319 scheduler(); 294 current_copy(CURRENT, (current_t *) CPU_LOCAL->stack); 295 context_replace(scheduler_run, CPU_LOCAL->stack, STACK_SIZE); 320 296 /* not reached */ 321 297 } … … 357 333 ARCH_OP(post_cpu_init); 358 334 359 current_copy(CURRENT, (current_t *) CPU->stack);360 361 335 /* 362 336 * If we woke kmp up before we left the kernel stack, we could … … 364 338 * switch to this cpu's private stack prior to waking kmp up. 365 339 */ 366 context_save(&CPU->saved_context); 367 context_set(&CPU->saved_context, FADDR(main_ap_separated_stack), 368 (uintptr_t) CPU->stack, STACK_SIZE); 369 context_restore(&CPU->saved_context); 340 current_copy(CURRENT, (current_t *) CPU_LOCAL->stack); 341 context_replace(main_ap_separated_stack, CPU_LOCAL->stack, STACK_SIZE); 370 342 /* not reached */ 371 343 } … … 383 355 timeout_init(); 384 356 385 waitq_wakeup(&ap_completion_wq, WAKEUP_FIRST);386 scheduler ();357 semaphore_up(&ap_completion_semaphore); 358 scheduler_run(); 387 359 /* not reached */ 388 360 }
Note:
See TracChangeset
for help on using the changeset viewer.