Changeset 65f3117 in mainline for kernel/generic/src/main/main.c


Ignore:
Timestamp:
2023-02-25T13:16:38Z (14 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6188fee
Parents:
4f84ee42
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-14 13:38:14)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-25 13:16:38)
Message:

Make bootstrap stack statically, rather than dynamically allocated

With aligment requirements being part of the language now, it is
simple to allocate the extra stack area in kernel data, and we
don't need to go to so much trouble with manual allocation.
It also makes it slightly more straightforward to use the stack
from assembly, without having to dig through a saved context
structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/main/main.c

    r4f84ee42 r65f3117  
    137137uintptr_t stack_safe = 0;
    138138
     139// NOTE: All kernel stacks must be aligned to STACK_SIZE, see CURRENT.
     140const size_t bootstrap_stack_size = STACK_SIZE;
     141_Alignas(STACK_SIZE) uint8_t bootstrap_stack[STACK_SIZE];
     142/* Just a convenient value for some assembly code. */
     143const uint8_t *bootstrap_stack_top = bootstrap_stack + STACK_SIZE;
     144
    139145/*
    140146 * These two functions prevent stack from underflowing during the
     
    170176            ALIGN_UP((uintptr_t) kdata_end - config.base, PAGE_SIZE);
    171177
    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 
    203178        context_save(&ctx);
    204179        context_set(&ctx, FADDR(main_bsp_separated_stack),
    205             config.stack_base, STACK_SIZE);
     180            bootstrap_stack, bootstrap_stack_size);
    206181        context_restore(&ctx);
    207182        /* not reached */
Note: See TracChangeset for help on using the changeset viewer.