Changeset cfdeedc in mainline for kernel


Ignore:
Timestamp:
2018-10-21T23:12:23Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf05c74
Parents:
d59718e
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-21 22:53:48)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-21 23:12:23)
Message:

Keep kernel in ELF format

By keeping kernel in an ELF file (instead of converting it to
a flat binary), we can use the information it contains, like
symbol table and debug info.

We can also later implement more advanced functionality, like
loading kernel at multiple discontiguous blocks, or loading
a position-independent kernel at a randomized address.

Currently the functionality is quite restricted, to keep changes
to a minimum. Code in boot/generic/src/kernel.c validates that
the kernel image was built with the same addresses as the boot
loader uses, giving an extra level of sanity checking compared
to a flat binary.

Location:
kernel
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    rd59718e rcfdeedc  
    4949
    5050AUTOCHECK = $(realpath $(ROOT_PATH)/tools/autocheck.awk)
    51 RAW = kernel.raw
    52 BIN = kernel.bin
     51KERNEL = kernel.elf
    5352MAP = kernel.map
    5453JOB = kernel.job
     
    7574.DELETE_ON_ERROR:
    7675
    77 all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(BIN) $(DISASM)
     76all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(KERNEL) $(DISASM)
    7877
    7978clean: autogen_clean
    80         rm -f $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* arch/*/_link.ld arch/*/include/arch/common.h
     79        rm -f $(KERNEL) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* arch/*/_link.ld arch/*/include/arch/common.h
    8180        find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm '{}' \;
    8281        find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.d' -follow -exec rm '{}' \;
     
    370369endif
    371370
    372 $(BIN): $(RAW)
    373         $(OBJCOPY) -O $(BFD) $< $@
    374 
    375 $(DISASM): $(RAW)
     371$(DISASM): $(KERNEL)
    376372ifeq ($(CONFIG_LINE_DEBUG),y)
    377373        $(OBJDUMP) -d -S $< > $@
     
    380376endif
    381377
    382 $(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
     378$(KERNEL): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
    383379        $(CC) $(DEFS) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
    384380
  • kernel/arch/abs32le/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD = binary
    3029
    3130ifeq ($(COMPILER),gcc_cross)
  • kernel/arch/amd64/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf64-x86-64
    30 BFD_ARCH = i386:x86-64
    31 BFD = binary
    3229
    3330FPU_NO_CFLAGS = -mno-sse -mno-sse2
  • kernel/arch/amd64/_link.ld.in

    rd59718e rcfdeedc  
    3333                *(COMMON);      /* global variables */
    3434
     35                /* XXX: bss can't be omitted from the ELF image. */
     36                *(.bss);        /* uninitialized static variables */
     37
    3538                . = ALIGN(8);
    3639                symbol_table = .;
    3740                *(symtab.*);    /* Symbol table, must be LAST symbol!*/
    38 
    39                 *(.bss);        /* uninitialized static variables */
    4041
    4142                kdata_end = .;
  • kernel/arch/arm32/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf32-littlearm
    30 BFD_ARCH = arm
    31 BFD = binary
    3229
    3330ATSIGN = %
  • kernel/arch/arm32/_link.ld.in

    rd59718e rcfdeedc  
    2525        . = KERNEL_LOAD_ADDRESS;
    2626        kernel_load_address = .;
     27        . = . + SIZEOF_HEADERS;
    2728        .text : {
    2829                ktext_start = .;
  • kernel/arch/ia32/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf32-i386
    30 BFD_ARCH = i386
    31 BFD = binary
    3229
    3330BITS = 32
  • kernel/arch/ia32/_link.ld.in

    rd59718e rcfdeedc  
    3131                *(.rodata .rodata.*);   /* string literals */
    3232                *(COMMON);              /* global variables */
     33
     34                /* XXX: bss can't be omitted from the ELF image. */
     35                *(.bss);                /* uninitialized static variables */
     36
    3337                . = ALIGN(8);
    3438                symbol_table = .;
    3539                *(symtab.*);            /* Symbol table, must be LAST symbol! */
    36                 *(.bss);                /* uninitialized static variables */
    3740                kdata_end = .;
    3841        }
  • kernel/arch/ia64/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf64-little
    30 BFD_ARCH = ia64-elf64
    3129
    3230COMMON_CFLAGS += -mconstant-gp -fno-unwind-tables -mfixed-range=f32-f127
     
    6563ifeq ($(MACHINE),ski)
    6664        ARCH_SOURCES += arch/$(KARCH)/src/drivers/ski.c
    67         BFD = binary
    6865endif
    6966
    7067ifeq ($(MACHINE),i460GX)
    7168        DEFS += -DI460GX
    72         BFD = binary
    7369endif
    7470
  • kernel/arch/ia64/_link.ld.in

    rd59718e rcfdeedc  
    1515        kernel_load_address = LOAD_ADDRESS_V;
    1616
    17         .image LOAD_ADDRESS_V: AT (LOAD_ADDRESS_P) {
     17        .image (LOAD_ADDRESS_V + SIZEOF_HEADERS): AT (LOAD_ADDRESS_P + SIZEOF_HEADERS) {
     18                . = ALIGN(16);
    1819                ktext_start = .;
    1920                *(K_TEXT_START);
  • kernel/arch/mips32/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_ARCH = mips
    30 BFD = binary
    3129COMMON_CFLAGS += -msoft-float -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mabi=32
    3230AS_PROLOG = .module softfloat;
     
    3836
    3937ifeq ($(MACHINE),msim)
    40         BFD_NAME = elf32-tradlittlemips
    4138        ENDIANESS = LE
    4239        COMMON_CFLAGS += -march=r4000
    4340endif
    4441ifeq ($(MACHINE),bmalta)
    45         BFD_NAME = elf32-tradbigmips
    4642        ENDIANESS = BE
    4743        COMMON_CFLAGS += -D__BE__ -march=4kc
    4844endif
    4945ifeq ($(MACHINE),lmalta)
    50         BFD_NAME = elf32-tradlittlemips
    5146        ENDIANESS = LE
    5247        COMMON_CFLAGS += -march=4kc
  • kernel/arch/mips32/_link.ld.in

    rd59718e rcfdeedc  
    2424        . = KERNEL_LOAD_ADDRESS;
    2525        kernel_load_address = .;
     26        . = . + SIZEOF_HEADERS;
    2627
    2728        .text : {
  • kernel/arch/ppc32/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf32-powerpc
    30 BFD_ARCH = powerpc:common
    31 BFD = binary
    3229
    3330COMMON_CFLAGS += -mcpu=powerpc -msoft-float -m32
  • kernel/arch/ppc32/_link.ld.in

    rd59718e rcfdeedc  
    2020        kernel_load_address = PA2KA(0);
    2121
    22         .unmapped 0: AT (0) {
     22        .unmapped (SIZEOF_HEADERS): AT (SIZEOF_HEADERS) {
     23                . = ALIGN(0x100);
    2324                *(K_UNMAPPED_TEXT_START);
    2425        }
     
    4647                kdata_end = .;
    4748        }
     49
     50        /DISCARD/ : {
     51                *(*);
     52        }
    4853}
  • kernel/arch/ppc32/src/exception.S

    rd59718e rcfdeedc  
    126126.endm
    127127
    128 .org 0x100
     128// XXX: K_UNMAPPED_TEXT_START section starts at 0x100,
     129// so all the following .org directives are relative to that.
     130#define ABSOLUTE(x) ((x) - 0x100)
     131
     132.org ABSOLUTE(0x100)
    129133SYMBOL(exc_system_reset)
    130134        CONTEXT_STORE
     
    133137        b jump_to_kernel
    134138
    135 .org 0x200
     139.org ABSOLUTE(0x200)
    136140SYMBOL(exc_machine_check)
    137141        CONTEXT_STORE
     
    140144        b jump_to_kernel
    141145
    142 .org 0x300
     146.org ABSOLUTE(0x300)
    143147SYMBOL(exc_data_storage)
    144148        CONTEXT_STORE
     
    147151        b jump_to_kernel
    148152
    149 .org 0x400
     153.org ABSOLUTE(0x400)
    150154SYMBOL(exc_instruction_storage)
    151155        CONTEXT_STORE
     
    154158        b jump_to_kernel
    155159
    156 .org 0x500
     160.org ABSOLUTE(0x500)
    157161SYMBOL(exc_external)
    158162        CONTEXT_STORE
     
    161165        b jump_to_kernel
    162166
    163 .org 0x600
     167.org ABSOLUTE(0x600)
    164168SYMBOL(exc_alignment)
    165169        CONTEXT_STORE
     
    168172        b jump_to_kernel
    169173
    170 .org 0x700
     174.org ABSOLUTE(0x700)
    171175SYMBOL(exc_program)
    172176        CONTEXT_STORE
     
    175179        b jump_to_kernel
    176180
    177 .org 0x800
     181.org ABSOLUTE(0x800)
    178182SYMBOL(exc_fp_unavailable)
    179183        CONTEXT_STORE
     
    182186        b jump_to_kernel
    183187
    184 .org 0x900
     188.org ABSOLUTE(0x900)
    185189SYMBOL(exc_decrementer)
    186190        CONTEXT_STORE
     
    189193        b jump_to_kernel
    190194
    191 .org 0xa00
     195.org ABSOLUTE(0xa00)
    192196SYMBOL(exc_reserved0)
    193197        CONTEXT_STORE
     
    196200        b jump_to_kernel
    197201
    198 .org 0xb00
     202.org ABSOLUTE(0xb00)
    199203SYMBOL(exc_reserved1)
    200204        CONTEXT_STORE
     
    203207        b jump_to_kernel
    204208
    205 .org 0xc00
     209.org ABSOLUTE(0xc00)
    206210SYMBOL(exc_syscall)
    207211        CONTEXT_STORE
     
    209213        b jump_to_kernel_syscall
    210214
    211 .org 0xd00
     215.org ABSOLUTE(0xd00)
    212216SYMBOL(exc_trace)
    213217        CONTEXT_STORE
     
    216220        b jump_to_kernel
    217221
    218 .org 0x1000
     222.org ABSOLUTE(0x1000)
    219223SYMBOL(exc_itlb_miss)
    220224        CONTEXT_STORE
     
    223227        b jump_to_kernel
    224228
    225 .org 0x1100
     229.org ABSOLUTE(0x1100)
    226230SYMBOL(exc_dtlb_miss_load)
    227231        CONTEXT_STORE
     
    230234        b jump_to_kernel
    231235
    232 .org 0x1200
     236.org ABSOLUTE(0x1200)
    233237SYMBOL(exc_dtlb_miss_store)
    234238        CONTEXT_STORE
     
    237241        b jump_to_kernel
    238242
    239 .org 0x4000
     243.org ABSOLUTE(0x4000)
    240244jump_to_kernel:
    241245        mfsrr1 r5
     
    289293        addis sp, sp, 0x8000
    290294        rfi
     295
     296/* Rest is for stack. */
     297
     298.org ABSOLUTE(0x8000)
  • kernel/arch/riscv64/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf64-littleriscv
    30 BFD_ARCH = riscv
    31 BFD = binary
    3229
    3330COMMON_CFLAGS += -mcmodel=medany
  • kernel/arch/riscv64/_link.ld.in

    rd59718e rcfdeedc  
    1616        kernel_load_address = PA2KA(BOOT_OFFSET);
    1717
    18         .image (PA2KA(BOOT_OFFSET)) : AT (0) {
     18        .image (PA2KA(BOOT_OFFSET) + SIZEOF_HEADERS) : AT (SIZEOF_HEADERS) {
    1919                ktext_start = .;
    2020                *(K_TEXT_START);
  • kernel/arch/sparc64/Makefile.inc

    rd59718e rcfdeedc  
    2727#
    2828
    29 BFD_NAME = elf64-sparc
    30 BFD_ARCH = sparc
    31 BFD = binary
    3229
    3330COMMON_CFLAGS += -m64 -mcpu=ultrasparc -mcmodel=medlow -mno-fpu
  • kernel/arch/sparc64/_link.ld.in

    rd59718e rcfdeedc  
    1212
    1313SECTIONS {
    14         .image VMA: AT (LMA) {
    15                 kernel_load_address = .;
     14        kernel_load_address = VMA;
    1615
     16        .image (VMA + SIZEOF_HEADERS): AT (LMA + SIZEOF_HEADERS) {
    1717                ktext_start = .;
    1818                *(K_TEXT_START)
Note: See TracChangeset for help on using the changeset viewer.