Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:27:58+00:00 2026-06-15T10:27:58+00:00

I have a simple code that I am trying to compile with lm32-rtems4.11-gcc. I

  • 0

I have a simple code that I am trying to compile with lm32-rtems4.11-gcc.

I have the code, the compile command and the lst below. When I compile I see a bunch of code added on the top instead of the startup code that I want in there. The code I want the processor to start with after reset is at location 3f4 instead of 0. What I wanted help on is to figure out how the rest of the code got in and find a way to remove it or move all that code to addresses after my code. I appreciate the help.
Thanks

The code:

 //FILE: crt.S

.globl _start

.text
_start:
 xor r0, r0, r0
 mvhi sp, hi(_fstack)
 ori sp, sp, lo(_fstack)
 mv fp,r0
 mvhi r1, hi(_fbss)
 ori r1, r1, lo(_fbss)
 mvhi r2, hi(_ebss)
 ori r2, r2, lo(_ebss)
 1:
 bge r1, r2, 2f
 sw (r1+0), r0
 addi r1, r1, 4
 bi 1b
 2:
 calli main
 mvhi r1, 0xdead
 ori r2, r0, 0xbeef
 sw (r1+0), r2

 //FILE: hello_world.c

 void putc(char c)
 {
    char *tx = (char*)0xff000000;
    *tx = c;
 }

 void puts(char *s)
 {
    while (*s) putc(*s++);
 }

 void main(void)
 {
    puts("Hello World\n");
 }

 //FILE: linker.ld

OUTPUT_FORMAT("elf32-lm32")
ENTRY(_start)

__DYNAMIC = 0;

MEMORY {
    pmem : ORIGIN = 0x00000000, LENGTH = 0x8000
    dmem : ORIGIN = 0x00008000, LENGTH = 0x8000
}

SECTIONS
{
    .text :
    {
            _ftext = .;
            *(.text .stub .text.* .gnu.linkonce.t.*)
            _etext = .;
    } > pmem

    .rodata :
    {
            . = ALIGN(4);
            _frodata = .;
             *(.rodata .rodata.* .gnu.linkonce.r.*)
            *(.rodata1)
            _erodata = .;
    } > dmem

    .data :
    {
            . = ALIGN(4);
            _fdata = .;
            *(.data .data.* .gnu.linkonce.d.*)
            *(.data1)
            _gp = ALIGN(16);
            *(.sdata .sdata.* .gnu.linkonce.s.*)
            _edata = .;
    } > dmem

    .bss :
    {
            . = ALIGN(4);
            _fbss = .;
            *(.dynsbss)
            *(.sbss .sbss.* .gnu.linkonce.sb.*)
            *(.scommon)
            *(.dynbss)
            *(.bss .bss.* .gnu.linkonce.b.*)
            *(COMMON)
            . = ALIGN(4);
            _ebss = .;
            _end = .;
    } > dmem
}

The compile command

lm32-rtems4.11-gcc -Tlinker.ld -fno-builtin -o hello_world.elf crt.S hello_world.c
lm32-rtems4.11-objdump -DS hello_world.lst hello_world.elf

The lst file

00000000 <rtems_provides_crt0>:
#include <signal.h> /* sigset_t */
#include <time.h> /* struct timespec */
#include <unistd.h> /* isatty */

void rtems_provides_crt0( void ) {}  /* dummy symbol so file always has one */
0:   c3 a0 00 00     ret

00000004 <rtems_stub_malloc>:
#define RTEMS_STUB(ret, func, body) \
ret rtems_stub_##func body; \
ret func body

/* RTEMS provides some of its own routines including a Malloc family */
RTEMS_STUB(void *,malloc(size_t s), { return 0; })
4:   34 01 00 00     mvi r1,0
8:   c3 a0 00 00     ret

0000000c <malloc>:
c:   34 01 00 00     mvi r1,0
10:   c3 a0 00 00     ret
.
.
.
//omitting other such unrelated code that was inserted into the code and going to the 
//code at 3f4 that is the code I wanted at 0

000003f0 <__assert_func>:
3f0:   c3 a0 00 00     ret

000003f4 <_start>:
3f4:   98 00 00 00     xor r0,r0,r0
3f8:   78 1c 00 00     mvhi sp,0x0
3fc:   3b 9c ff fc     ori sp,sp,0xfffc
400:   b8 00 d8 00     mv fp,r0
404:   78 01 00 00     mvhi r1,0x0
408:   38 21 84 48     ori r1,r1,0x8448
40c:   78 02 00 00     mvhi r2,0x0
410:   38 42 84 48     ori r2,r2,0x8448
414:   4c 22 00 04     bge r1,r2,424 <_start+0x30>
418:   58 20 00 00     sw (r1+0),r0
41c:   34 21 00 04     addi r1,r1,4
420:   e3 ff ff fd     bi 414 <_start+0x20>
424:   f8 00 00 28     calli 4c4 <main>
428:   78 01 de ad     mvhi r1,0xdead
42c:   38 02 be ef     mvu r2,0xbeef
430:   58 22 00 00     sw (r1+0),r2
.
.
.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:27:59+00:00Added an answer on June 15, 2026 at 10:27 am

    So I could not figure out why the compiler does not move the .start label to 0 when the linker.ld clearly tells it to do so. But I did figure a work around.

    I created a section name for the startup code as shown in BOLD below. I then created a section in memory starting at 0 which I reserved only for this start up code. That seemed to do the trick. I ran the code and got a hello world 🙂 . All the changes I made are in BOLD and also commented //Change 1 //Change 2 and //Change 3.

    //FILE: crt.S
    

    .section .init// Change 1

    .globl _start
    
    .text
    _start:
    xor r0, r0, r0
    mvhi sp, hi(_fstack)
    ori sp, sp, lo(_fstack)
    mv fp,r0
    mvhi r1, hi(_fbss)
    ori r1, r1, lo(_fbss)
    .
    .
    
    //linker.ld
    OUTPUT_FORMAT("elf32-lm32")
    ENTRY(_start)
    
    __DYNAMIC = 0;
    
    MEMORY {
    

    init : ORIGIN = 0x00000000, LENGTH = 0x40 //Change 2

        pmem : ORIGIN = 0x00000040, LENGTH = 0x8000
        dmem : ORIGIN = 0x00008000, LENGTH = 0x8000
    }
    
    SECTIONS
    {
    

    .init : {*(.init)}>init //Change 3

        .text :
        {
                _ftext = .;
                *(.text .stub .text.* .gnu.linkonce.t.*)
                _etext = .;
        } > pmem
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plot (sample code pasted below) that I am trying to add
I have a simple DLL that I am trying to compile in VS2010 Express.
I have a very simple example program that I am trying to compile, but
Trying to get comfortable with jQuery and I have encountered some sample code that
I have the following code sample that im trying to wrap my head around
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I am building a PhoneGap/Cordova app and have a simple code that uses http://ricostacruz.com/jquery.transit/
I have a simple java code that reads text csv file that contains sentences
I have a simple jQuery code that runs on a web page that has
I have a simple script of code that reads a PHP file and when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.