This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
RE: Why use pointer?
- To: John <john at imining dot com dot tw>
- Subject: RE: [ECOS] Why use pointer?
- From: Gary Thomas <gthomas at cambridge dot redhat dot com>
- Date: Tue, 03 Apr 2001 05:15:05 -0600 (MDT)
- Cc: ecos-discuss <ecos-discuss at sources dot redhat dot com>
- Organization: Red Hat, Inc.
On 03-Apr-2001 John wrote:
> Hi all,
>
> I'm new to ecos.
> I see the following code in vectors.S of arm platform.
> It uses PTR(init_flag) to make a pointer.
> And then uses
> ldr r0,.init_flag
> ldr r1,[r0]
> to load data at address init_flag.
> Why not use
> ldr r1,init_flag
> like init_done below?
> Is the pointer for some special purpose or some reason?
> Thanks in advance.
>
>
> .globl start
> start:
>
> LED 5
>
>#if defined(CYG_HAL_STARTUP_RAM) && \
> !defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
> // If we get restarted, hang here to avoid corrupting memory
> ldr r0,.init_flag
> ldr r1,[r0]
> 1: cmp r1,#0
> bne 1b
> ldr r1,init_done
> str r1,[r0]
This is necessary because the 'init_flag' variable is in a different
section (data, not text) which is most likely too far away to be addressed
directly. The variable 'init_done' is in the same segment and close
by, thus no indirect addressing is required.