Changeset 6e5252a in mainline


Ignore:
Timestamp:
2018-11-13T20:22:20Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
156bae23
Parents:
2214382
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-23 21:48:41)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-13 20:22:20)
Message:

Place AP bootstrap correctly via linker script instead of manual copy

Location:
kernel/arch
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/_link.ld.in

    r2214382 r6e5252a  
    1414ENTRY(multiboot_image_start)
    1515
     16PHDRS {
     17        ap_boot PT_LOAD ;
     18        unmapped PT_LOAD ;
     19        mapped PT_LOAD ;
     20}
     21
    1622SECTIONS {
    1723        kernel_load_address = PA2KA(BOOT_OFFSET);
    1824
    19         .unmapped (BOOT_OFFSET + SIZEOF_HEADERS): AT (BOOT_OFFSET + SIZEOF_HEADERS) {
     25        .ap_bootstrap (AP_BOOT_OFFSET): AT (AP_BOOT_OFFSET) {
     26                ap_bootstrap_start = .;
     27
     28                /* Must be first. */
     29                *(.multiboot);
     30
     31                *(K_AP_TEXT_START);
     32                *(K_AP_DATA_START);
     33                ap_bootstrap_end = .;
     34        } :ap_boot
     35
     36        .unmapped (BOOT_OFFSET): AT (BOOT_OFFSET) {
    2037                unmapped_start = .;
    2138                *(K_TEXT_START);
     
    2340                *(K_INI_PTLS);
    2441                unmapped_end = .;
    25         }
     42        } :unmapped
    2643
    27         .mapped (PA2KA(BOOT_OFFSET) + SIZEOF_HEADERS + SIZEOF(.unmapped)) : AT (BOOT_OFFSET + SIZEOF_HEADERS + SIZEOF(.unmapped)) {
     44        .mapped (PA2KA(BOOT_OFFSET) + SIZEOF(.unmapped)) : AT (BOOT_OFFSET + SIZEOF(.unmapped)) {
    2845                ktext_start = .;
    2946                *(.text .text.*);
     
    4360
    4461                kdata_end = .;
    45         }
     62        } :mapped
    4663
    4764#ifdef CONFIG_LINE_DEBUG
     
    6380
    6481#ifdef CONFIG_SMP
    65         ap_boot = unmapped_ap_boot - BOOT_OFFSET + AP_BOOT_OFFSET;
    66         ap_gdtr = unmapped_ap_gdtr - BOOT_OFFSET + AP_BOOT_OFFSET;
    6782        protected_ap_gdtr = PA2KA(ap_gdtr);
    6883#endif /* CONFIG_SMP */
  • kernel/arch/amd64/include/arch/boot/boot.h

    r2214382 r6e5252a  
    4242#ifndef __ASSEMBLER__
    4343
    44 extern uint8_t unmapped_end[];
     44extern uint8_t ap_bootstrap_start[];
     45extern uint8_t ap_bootstrap_end[];
    4546
    4647#endif /* __ASSEMBLER__ */
  • kernel/arch/amd64/src/amd64.c

    r2214382 r6e5252a  
    9292        multiboot_info_parse(signature, (multiboot_info_t *) info);
    9393        multiboot2_info_parse(signature, (multiboot2_info_t *) info);
    94 
    95 #ifdef CONFIG_SMP
    96         size_t unmapped_size = (uintptr_t) unmapped_end - BOOT_OFFSET;
    97         /* Copy AP bootstrap routines below 1 MB. */
    98         memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, unmapped_size);
    99 #endif
    10094}
    10195
  • kernel/arch/amd64/src/boot/multiboot.S

    r2214382 r6e5252a  
    4646#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
    4747
    48 .section K_TEXT_START, "ax"
    49 
    50 .code32
    51 
    52 .macro pm_error msg
    53         movl \msg, %esi
    54         jmp pm_error_halt
    55 .endm
    56 
    57 .macro pm_status msg
    58 #if defined(CONFIG_EGA) && !defined(CONFIG_FB)
    59         pushl %esi
    60         movl \msg, %esi
    61         call pm_early_puts
    62         popl %esi
    63 #endif
    64 .endm
    65 
    66 .macro pm2_status msg
    67 #ifndef CONFIG_FB
    68         pm_status \msg
    69 #endif
    70 .endm
     48.section .multiboot, "a"
    7149
    7250.align 4
     
    9169        .long CONFIG_BFB_BPP
    9270#endif
     71
     72.section K_TEXT_START, "ax"
     73
     74.code32
     75
     76.macro pm_error msg
     77        movl \msg, %esi
     78        jmp pm_error_halt
     79.endm
     80
     81.macro pm_status msg
     82#if defined(CONFIG_EGA) && !defined(CONFIG_FB)
     83        pushl %esi
     84        movl \msg, %esi
     85        call pm_early_puts
     86        popl %esi
     87#endif
     88.endm
     89
     90.macro pm2_status msg
     91#ifndef CONFIG_FB
     92        pm_status \msg
     93#endif
     94.endm
    9395
    9496SYMBOL(multiboot_image_start)
  • kernel/arch/amd64/src/boot/multiboot2.S

    r2214382 r6e5252a  
    3535#include <genarch/multiboot/multiboot2.h>
    3636
    37 .section K_TEXT_START, "ax"
    38 
    39 .code32
     37.section .multiboot, "a"
    4038
    4139.align 8
  • kernel/arch/amd64/src/smp/ap.S

    r2214382 r6e5252a  
    4141#include <arch/context_struct.h>
    4242
    43 .section K_TEXT_START, "ax"
     43.section K_AP_TEXT_START, "ax"
    4444
    4545#ifdef CONFIG_SMP
     
    5050
    5151.align 4096
    52 SYMBOL(unmapped_ap_boot)
     52
     53SYMBOL(ap_boot)
    5354.code16
    5455        cli
     
    6162        orl $CR0_PE, %eax
    6263        movl %eax, %cr0     # switch to protected mode
    63         jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
     64        jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel
    6465
    6566jump_to_kernel:
     
    9495
    9596        # At this point we are in compatibility mode
    96         jmpl $GDT_SELECTOR(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
     97        jmpl $GDT_SELECTOR(KTEXT_DES), $start64
    9798
    9899.code64
     
    109110#endif /* CONFIG_SMP */
    110111
    111 .section K_DATA_START, "aw", @progbits
     112.section K_AP_DATA_START, "aw", @progbits
    112113
    113114#ifdef CONFIG_SMP
    114115
    115 SYMBOL(unmapped_ap_gdtr)
     116SYMBOL(ap_gdtr)
    116117        .word 0
    117118        .long 0
  • kernel/arch/ia32/_link.ld.in

    r2214382 r6e5252a  
    1414ENTRY(multiboot_image_start)
    1515
     16PHDRS {
     17        ap_boot PT_LOAD ;
     18        unmapped PT_LOAD ;
     19        mapped PT_LOAD ;
     20}
     21
    1622SECTIONS {
    1723        kernel_load_address = PA2KA(BOOT_OFFSET);
    1824
    19         .unmapped (BOOT_OFFSET + SIZEOF_HEADERS): AT (BOOT_OFFSET + SIZEOF_HEADERS) {
     25        .ap_bootstrap (AP_BOOT_OFFSET): AT (AP_BOOT_OFFSET) {
     26                ap_bootstrap_start = .;
     27
     28                /* Must be first. */
     29                *(.multiboot);
     30
     31                *(K_AP_TEXT_START);
     32                *(K_AP_DATA_START);
     33                ap_bootstrap_end = .;
     34        } :ap_boot
     35
     36        .unmapped (BOOT_OFFSET): AT (BOOT_OFFSET) {
    2037                unmapped_start = .;
    2138                *(K_TEXT_START);
    2239                *(K_DATA_START);
    2340                unmapped_end = .;
    24         }
     41        } :unmapped
    2542
    26         .mapped (PA2KA(BOOT_OFFSET) + SIZEOF_HEADERS + SIZEOF(.unmapped)): AT (BOOT_OFFSET + SIZEOF_HEADERS + SIZEOF(.unmapped)) {
     43        .mapped (PA2KA(BOOT_OFFSET) + SIZEOF(.unmapped)): AT (BOOT_OFFSET + SIZEOF(.unmapped)) {
    2744                ktext_start = .;
    2845                *(.text .text.*);
     
    4158                *(symtab.*);            /* Symbol table, must be LAST symbol! */
    4259                kdata_end = .;
    43         }
     60        } :mapped
    4461
    4562#ifdef CONFIG_LINE_DEBUG
     
    6178
    6279#ifdef CONFIG_SMP
    63 
    64         ap_boot = unmapped_ap_boot - BOOT_OFFSET + AP_BOOT_OFFSET;
    65         ap_gdtr = unmapped_ap_gdtr - BOOT_OFFSET + AP_BOOT_OFFSET;
    6680        protected_ap_gdtr = PA2KA(ap_gdtr);
    67 
    6881#endif /* CONFIG_SMP */
    6982
  • kernel/arch/ia32/include/arch/boot/boot.h

    r2214382 r6e5252a  
    4444#ifdef CONFIG_SMP
    4545
    46 extern uint8_t unmapped_end[];
     46extern uint8_t ap_bootstrap_start[];
     47extern uint8_t ap_bootstrap_end[];
    4748
    4849#endif /* CONFIG_SMP */
  • kernel/arch/ia32/src/boot/multiboot.S

    r2214382 r6e5252a  
    4646#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
    4747
    48 .section K_TEXT_START, "ax"
    49 
    50 .code32
    51 
    52 .macro pm_status msg
    53 #if defined(CONFIG_EGA) && !defined(CONFIG_FB)
    54         pushl %esi
    55         movl \msg, %esi
    56         call pm_early_puts
    57         popl %esi
    58 #endif
    59 .endm
    60 
    61 .macro pm2_status msg
    62         pushl \msg
    63         call early_puts
    64 .endm
     48.section .multiboot, "a"
    6549
    6650.align 4
     
    8569        .long CONFIG_BFB_BPP
    8670#endif
     71
     72.section K_TEXT_START, "ax"
     73
     74.code32
     75
     76.macro pm_status msg
     77#if defined(CONFIG_EGA) && !defined(CONFIG_FB)
     78        pushl %esi
     79        movl \msg, %esi
     80        call pm_early_puts
     81        popl %esi
     82#endif
     83.endm
     84
     85.macro pm2_status msg
     86        pushl \msg
     87        call early_puts
     88.endm
    8789
    8890SYMBOL(multiboot_image_start)
  • kernel/arch/ia32/src/boot/multiboot2.S

    r2214382 r6e5252a  
    3333#include <genarch/multiboot/multiboot2.h>
    3434
    35 .section K_TEXT_START, "ax"
    36 
    37 .code32
     35.section .multiboot, "a"
    3836
    3937.align 8
  • kernel/arch/ia32/src/ia32.c

    r2214382 r6e5252a  
    9292        multiboot_info_parse(signature, (multiboot_info_t *) info);
    9393        multiboot2_info_parse(signature, (multiboot2_info_t *) info);
    94 
    95 #ifdef CONFIG_SMP
    96         size_t unmapped_size = (uintptr_t) unmapped_end - BOOT_OFFSET;
    97         /* Copy AP bootstrap routines below 1 MB. */
    98         memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET, unmapped_size);
    99 #endif
    10094}
    10195
  • kernel/arch/ia32/src/mm/frame.c

    r2214382 r6e5252a  
    152152
    153153#ifdef CONFIG_SMP
    154                 size_t unmapped_size =
    155                     (uintptr_t) unmapped_end - BOOT_OFFSET;
    156 
    157                 minconf = max(minconf,
    158                     ADDR2PFN(AP_BOOT_OFFSET + unmapped_size));
     154                // FIXME: What is the purpose of minconf? Can we remove it?
     155                uintptr_t ap_end = ALIGN_UP((uintptr_t) ap_bootstrap_end, FRAME_SIZE);
     156                minconf = max(minconf, ADDR2PFN(ap_end));
    159157#endif
    160158
     
    165163
    166164#ifdef CONFIG_SMP
     165                // TODO: should go away implicitly with section table
     166
    167167                /* Reserve AP real mode bootstrap memory */
     168                size_t ap_size =
     169                    ALIGN_UP(ap_bootstrap_end - ap_bootstrap_start, FRAME_SIZE);
    168170                frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
    169                     unmapped_size >> FRAME_WIDTH);
     171                    ap_size >> FRAME_WIDTH);
    170172#endif
    171173        }
  • kernel/arch/ia32/src/smp/ap.S

    r2214382 r6e5252a  
    4040#include <arch/context_struct.h>
    4141
    42 .section K_TEXT_START, "ax"
     42.section K_AP_TEXT_START, "ax"
    4343
    4444#ifdef CONFIG_SMP
     
    5454
    5555.align 4096
    56 SYMBOL(unmapped_ap_boot)
     56SYMBOL(ap_boot)
    5757.code16
    5858        cli
     
    6767        orl $CR0_PE, %eax
    6868        movl %eax, %cr0
    69         jmpl $KTEXT, $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
     69        jmpl $KTEXT, $jump_to_kernel
    7070
    7171jump_to_kernel:
     
    9696
    9797
    98 .section K_DATA_START, "aw", @progbits
     98.section K_AP_DATA_START, "aw", @progbits
    9999
    100100#ifdef CONFIG_SMP
    101101
    102 SYMBOL(unmapped_ap_gdtr)
     102SYMBOL(ap_gdtr)
    103103        .word 0
    104104        .long 0
Note: See TracChangeset for help on using the changeset viewer.