1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

LPC2138 and linker script

Discussion in 'Embedded' started by Stan, Dec 5, 2007.

  1. Stan

    Stan Guest


    I want to initialize global variables from ROM,

    my crt0.s is same as :

    /* select user mode */
    mrs r0, cpsr
    bic r0, r0, #0x1F /* clear mode flags */
    orr r0, r0, #0x10 /* set user mode */
    msr cpsr, r0

    /* init stack */
    ldr sp,_Lstack_end

    /* copy data */
    ldr r0, _Linit_data_start
    ldr r1, _Ldata_start
    ldr r2, _Ldata_end
    cmp r1,r2
    beq _Lzero_bss

    /* copy byte by byte if not aligned */
    tst r0, #0x3
    bne _Lcopy_bytes
    tst r1, #0x3
    bne _Lcopy_bytes
    tst r2, #0x3
    bne _Lcopy_bytes
    ldr r3, [r0], #0x4
    str r3, [r1], #0x4
    cmp r1,r2
    bne _Lcopy_words
    b _Lzero_bss
    ldr r3, [r0], #0x1
    str r3, [r1], #0x1
    cmp r1,r2
    bne _Lcopy_bytes

    /* zero bss */
    ldr r0, _Lbss_start
    ldr r1, _Lbss_end

    at present my linker script is :

    __TEXT_START__ = 0x00000400;
    __DATA_START__ = 0x40003000;
    __STACK_END__ = 0x40004000;

    /* Read-only sections, merged into text segment */

    .text0 0x0:

    .text2 __TEXT_START__ :

    PROVIDE (__etext = .);

    .rodata :

    /* append .data; it will be copied by crt0 to final __DATA_START__ */
    . = ALIGN(4);
    __INIT_DATA_START__ = .;
    .data __DATA_START__ : AT ( __INIT_DATA_START__ )
    . = ALIGN(4);
    __DATA_END__ = .;

    /* noninitialized data; will be zeroed by crt0*/
    __bss_start__ = .;
    .bss :
    . = ALIGN(4);
    . = ALIGN(4);
    __bss_end__ = . ;
    PROVIDE (end = .);
    Stan, Dec 5, 2007
    1. Advertisements

  2. Stan

    Ted Guest

    You might want to tell us whose linker this is a script for.

    Ted, Dec 5, 2007
    1. Advertisements

  3. Stan

    Stan Guest

    I use GNU ld version 2.16.1 ( arm-elf-ld ).
    Stan, Dec 5, 2007
  4. Stan

    David Brown Guest

    The easiest way to do this is to look at the standard crt0.s and linker
    files for your compiler, and base your versions on that. But the normal
    way to set up a linker file is to have memory areas defined at the top
    of the linker file, and put your .text, .data and .bss output sections
    into the ROM and RAM memory areas as appropriate. The initialised data
    section is put into "> ROM AT> RAM" (or something similar - now you have
    the hint, you can look up the exact syntax) which sets the link-time
    addresses for data items to a ram address, but puts their contents in
    rom. You need to be careful to get the init_data_start and data_start
    symbols from the correct area - again, look at the standard linker files
    for examples.

    You can also drop all the "copy byte" stuff in your startup routines -
    use . = ALIGN(4) liberally in your linker file, and everything will be
    aligned to 32-bit boundaries.
    David Brown, Dec 5, 2007
  5. What script?

    Robert Adsett, Dec 5, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.