что за нулевая строка в скрипте линкера?
От: another_one  
Дата: 11.10.22 08:56
Оценка:
Здравствуйте!

Я пытаюсь создать линкер скрипт и Си рантайм для MIPS64 используя cygwin64 + mips-mti-elf

Вот мой скрипт:
OUTPUT_FORMAT("elf64-tradlittlemips")
SEARCH_DIR(objs)
GROUP(-lc -lgcc)
STARTUP(mcrt.o)
PROVIDE(    _vector_spacing     = 0x00000001    );
PROVIDE(    _ebase_address      = 0xB5000000    );
PROVIDE(     _stack         = 0xB503FFFF    );
PROVIDE(     text_start     = 0xB5000FA0    );
PROVIDE(     data_start     = 0xB500FA00    );
PROVIDE(     bss_start      = 0xB502EE00    );
PROVIDE(     heap_start     = 0xB5032C80    );
PROVIDE(    _RESET_ADDR                     = 0xBFC00000    );
PROVIDE(    _SRAM_ADDR_2_EX = 0xB5000000    );              
PROVIDE(    _GEN_EXCPT_ADDR                 = _ebase_address + 0x180    );

_SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
_CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
_GEN_EXCPT_ADDR                = _ebase_address + 0x180;

MEMORY
    {
        ram         (rwx) : ORIGIN = 0xB5000000, LENGTH = 0x3FFFF 
    }

ENTRY(_startup)  
SECTIONS

    . = _text_start;
    .text :
    {   
        . = ALIGN(4);
        KEEP(*(.simple_tlb_refill_vector))
        . = _CACHE_ERR_EXCPT_ADDR;
        KEEP(*(.cache_err_vector))
        . = _GEN_EXCPT_ADDR;
        KEEP(*(.gen_handler))
        _startup = .;
        KEEP(*(.init))

        KEEP(*(.text))
        *(.text)
        *(.text.*)  
    } 
    
    . = data_start;
    .data :
    {
        . = ALIGN(4);   
        _gp = . ;
        KEEP(*(.data))
        *(.data)
        *(.data.*)
    } 

    . = bss_start;
    .bss : 
    {
        . = ALIGN(4);
            KEEP(*(.bss))
        *(.bss)
        *(.bss.*)
            
    }

    . = heap_start;
    .heap :
    {
            . = ALIGN(4);
        KEEP(*(.heap))  
            *(.heap)
            *(.heap.*)
        
    } 

    __stack = ORIGIN(ram) + LENGTH(ram);
}


Вот мой Си рантайм:

#include <mips/asm.h>
#include <mips/regdef.h>
#include <mips/mips64.h>
##include <mips.h> 
#  .set nomips16 
        ##################################################################
        # Entry point of the entire application
        ##################################################################
        /* This file contains 32-bit assembly code */
        .set nomips16
        
        ##################################################################
        # Startup code
        ##################################################################
        .section .init
        .align 2
        .set noreorder
        .ent _startup
_startup: .global _startup

        ##################################################################
        # Initialize CP0 registers
        ##################################################################
        # Подготавливаем Cause Register
        mfc0     $26,  $13,  0                  
        lui      $27,  0x0080                  
        or       $26,  $26,  $27            
        mtc0     $26,  $13,   0                 

        
        mfc0     $26,  $12,   1                 
        ori      $27,  $0,   0x20              
        or       $26,  $26,  $27           
        mtc0     $26,  $12,   1                  

        
        mfc0     $26,  $15,   1                 
        lui      $27,  0x1500                   
        or       $26,  $26,  $27           
        mtc0     $27,  $15,   1                 

        
        mfc0     $26,  $12,   0                 
        lui      $27,  0x0040                  
        ori      $27,  $27, 0xFC06           
        nor      $27,  $0, $27               
        and      $26,  $26,  $27           
        mtc0     $26,  $12,   0                  


        ##################################################################
        # EBASE configure
        ##################################################################
        mfc0     $26,  $15,   1
        lui      $27,  0x1500
        or       $26,  $26,  $27
        mtc0     $26,  $15,   1
        ##################################################################
        # Initialize Stack Pointer
        #   _stack is initialized by the linker script to point to the
        #    starting location of the stack in RAM
        ##################################################################
        dla      sp,__stack

        ##################################################################
        # Initialize Global Pointer
        #   _gp is initialized by the linker script to point to "middle"
        #   of the small variables region
        ##################################################################
        dla      gp,_gp


        ##################################################################
        # Fill stack
        # TODO - handle different stack lengths:
        # mulitple of 4, 8, 16, or 32
        ##################################################################
        dla      t0,_stack_start
        dla      t1,_stack
        b       _stack_check

_stack_init:
        sw      zero,0x0(t0)
        sw      zero,0x4(t0)
        sw      zero,0x8(t0)
        sw      zero,0xc(t0)
        addu    t0,16

_stack_check:
        bltu    t0,t1,_stack_init
        nop



        ##################################################################
        # Clear uninitialized data sections
        ##################################################################
        dla      t0,_bss_begin
        dla      t1,_bss_end
        b       _bss_check
        nop

_bss_init:
        sw      zero,0x0(t0)
        sw      zero,0x4(t0)
        sw      zero,0x8(t0)
        sw      zero,0xc(t0)
        addu    t0,16
_bss_check:
        bltu    t0,t1,_bss_init
        nop

 
        ##################################################################
        #   Initializes data section
        #   Warning: _data_image_start, _data_image_end, _data_start 
        #   must be aligned to word address (check linker script)!
        ##################################################################
init_data_section:
        dla     t0, _data_image_start
        dla     t1, _data_image_end
        dla     t2, _data_start
    #init_data_loop:
    #   beq     t0, t1, init_data_done
    #   nop
    #   lw      t3, (t0)
    #   addiu   t0, 4
    #   sw      t3, (t2)
    #   b       init_data_loop
    #   addiu   t2, 4
    #init_data_done:
    #   jr      ra
    #   nop
        .end _startup   
        
        ##################################################################
        # General Exception Vector Handler
        # Jumps to _general_exception_context
        ##################################################################
        .section .gen_handler
        .set noreorder
        .ent _gen_exception
_gen_exception:
/*0:      dla      k0,_general_exception_context
        jr      k0*/
        nop

        .end _gen_exception


        ##################################################################
        # Simple TLB-Refill Exception Vector
        # Jumps to _simple_tlb_refill_exception_context
        ##################################################################
        .section .simple_tlb_refill_vector
        .set noreorder
        .ent simple_tlb_refill_vector
simple_tlb_refill_vector:
       /* dla      k0,_simple_tlb_refill_exception_context
        jr      k0*/
        nop

        .end simple_tlb_refill_vector


   ##################################################################
        # Cache-Error Exception Vector Handler
        # Jumps to _cache_err_exception_context
        ##################################################################
        .section .cache_err_vector
        .set noreorder
        .ent _cache_err_vector
_cache_err_vector:
        /*la      k0,_cache_err_exception_context
        jr      k0*/
        nop

        .end _cache_err_vector

        .section .text
        .ent _main_entry
_main_entry:


        ##################################################################
        # Call main
        ##################################################################
        jal main
        nop


        .end _main_entry


Но в процессе сборки возникают следующие предупреждения:
src/mcrt.S:162: Warning: .ent or .aent not in text section

src/mcrt.S:168: Warning: .end not in text section

src/mcrt.S:177: Warning: .ent or .aent not in text section

src/mcrt.S:183: Warning: .end not in text section

src/mcrt.S:192: Warning: .ent or .aent not in text section

src/mcrt.S:198: Warning: .end not in text section


и также одна ошибка на этапе (APP).elf: $(TOBJS) $(CC) $(LDFLAGS) $^ -o $@" мейкфайла:

c:/tmp/cygwin64/usr/local/mips-mti-elf/2017.10-08/bin/../lib/gcc/mips-mti-elf/6.3.0/../../../..

/mips-mti-elf/bin/ld.exe:script1.ld:0: syntax error

collect2.exe: error: ld returned 1 exit status

make: *** [Makefile:49: mipsoutput.elf] Error 1


Я не понимаю на какую нулевую строку ссылается линкер в моем script1.ld

И также не понимаю почему init секция не в текст секции(согласно предупрежениям), когда как я ее там сохраняю

text
{
...
"KEEP(*(.init))"
...
}

Прошу помочь разобраться

Заранее благодарен
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.