Changeset 65f3117 in mainline


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.

Location:
kernel
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/smp/ap.S

    r4f84ee42 r65f3117  
    9898.code64
    9999start64:
    100         movabsq $ctx, %rsp
    101         movq CONTEXT_OFFSET_SP(%rsp), %rsp
     100        movabsq $bootstrap_stack_top, %rsp
     101        movq (%rsp), %rsp
    102102
     103        pushq $0
    103104        pushq $0
    104105        movq %rsp, %rbp
  • kernel/arch/ia32/src/smp/ap.S

    r4f84ee42 r65f3117  
    7575        movw %ax, %es
    7676        movw %ax, %ss
    77         movl $KA2PA(ctx), %eax          /* KA2PA((uintptr_t) &ctx) */
    78         movl CONTEXT_OFFSET_SP(%eax), %esp
     77        movl $KA2PA(bootstrap_stack_top), %eax   /* KA2PA((uintptr_t) &bootstrap_stack_top) */
     78        movl (%eax), %esp
    7979        leal KA2PA(0)(%esp), %esp       /* KA2PA(ctx.sp) */
    8080
  • kernel/arch/mips32/src/mm/frame.c

    r4f84ee42 r65f3117  
    111111        if (overlaps(frame << ZERO_PAGE_WIDTH, ZERO_PAGE_SIZE,
    112112            KA2PA(config.base), config.kernel_size))
    113                 return false;
    114 
    115         /* Kernel stack */
    116         if (overlaps(frame << ZERO_PAGE_WIDTH, ZERO_PAGE_SIZE,
    117             KA2PA(config.stack_base), config.stack_size))
    118113                return false;
    119114
  • kernel/arch/sparc64/src/sun4u/start.S

    r4f84ee42 r65f3117  
    356356         * in the ctx global variable.
    357357         */
    358         set ctx, %g1
    359         add %g1, CONTEXT_OFFSET_SP, %g1
     358        set bootstrap_stack_top, %g1
    360359        ldx [%g1], %o6
    361360
  • kernel/generic/include/config.h

    r4f84ee42 r65f3117  
    8787        size_t kernel_size;
    8888
    89         /** Base adddress of initial stack. */
    90         uintptr_t stack_base;
    91         /** Size of initial stack. */
    92         size_t stack_size;
    93 
    9489        bool identity_configured;
    9590        /** Base address of the kernel identity mapped memory. */
  • 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 */
  • kernel/generic/src/mm/frame.c

    r4f84ee42 r65f3117  
    752752                                        continue;
    753753
    754                                 if (overlaps(addr, PFN2ADDR(confcount),
    755                                     KA2PA(config.stack_base), config.stack_size))
    756                                         continue;
    757 
    758754                                bool overlap = false;
    759755                                for (size_t i = 0; i < init.cnt; i++) {
     
    11211117                frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
    11221118                    SIZE2FRAMES(config.kernel_size));
    1123                 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)),
    1124                     SIZE2FRAMES(config.stack_size));
    11251119
    11261120                for (size_t i = 0; i < init.cnt; i++)
Note: See TracChangeset for help on using the changeset viewer.