This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: [ECOS] arguments to main
- From: Bart Veer <bartv at tymora dot demon dot co dot uk>
- To: gary at chez-thomas dot org
- Cc: andrew dot lunn at ascom dot ch, wouter at mind dot be,ecos-patches at sources dot redhat dot com
- Date: Thu, 1 Aug 2002 00:02:33 +0100 (BST)
- Subject: Re: [ECOS] arguments to main
- References: <02072602521900.01647@c1830598-a><20020730224422.GI1607@roadkill.intern.mind.be><20020731074631.GC3392@biferten.ma.tech.ascom.ch><1028117420.28587.127.camel@hermes.chez-thomas.org> <20020731174152.GJ3392@biferten.ma.tech.ascom.ch> <1028137706.28587.155.camel@hermes.chez-thomas.org>
- Reply-to: bartv at tymora dot demon dot co dot uk
>>>>> "Gary" == Gary Thomas <gary@chez-thomas.org> writes:
Gary> On Wed, 2002-07-31 at 11:41, Andrew Lunn wrote:
>> > Additionally, these variables should be exported via some HAL .h file,
>> > possibly <cyg/hal/hal.h> or maybe <cyg/hal/hal_arch.h>.
>> >
>> > Finally, there should be appropriate ChangeLog entries.
>> >
>>
>> I could not work out how to get access to the environment. I
>> can see it on the stack, but i cannot find an obvious pointer
>> to it anywhere. Does anyone know of any documentation of how
>> the linux kernel sets up the stack before handing it over to
>> the new process?
Gary> IIRC, you have to compute it. You could look at the GLIBC
Gary> code (crt0.s) to figure it out.
I believe the correct way to get hold of both arguments and the
environment vector is in the vectors.S startup, ensuring that the
right thing can be done for different architectures. The following
code should do the right thing:
------------------------------------------------------------------------
# According the SVR4/i386 ABI, most registers are undefined. However
# there is some interesting information on the stack:
# %esp argc
# %esp+4 argv[0]
# ... argv[1 onwards]
# %esp + (argc*4) NULL
# ... environ[0]
# ... ...
# ... NULL
#
# There are some other things that could be done, for example aligning
# the stack to a 16-byte boundary for SSE, but it is not clear which of
# those things are actually useful. The glibc source file
# sysdeps/i386/elf/start.S contains some relevant information.
.file "vectors.S"
.extern _linux_entry
.data
.global cyg_hal_sys_argc
cyg_hal_sys_argc:
.long 0
.global cyg_hal_sys_argv
cyg_hal_sys_argv:
.long 0
.global cyg_hal_sys_environ
cyg_hal_sys_environ:
.long 0
.text
.globl _start
_start:
popl %eax
movl %eax, cyg_hal_sys_argc
movl %esp, %ebx
movl %ebx, cyg_hal_sys_argv
inc %eax
addl %eax, %eax
addl %eax, %eax
addl %eax, %ebx
movl %ebx, cyg_hal_sys_environ
jmp _linux_entry
------------------------------------------------------------------------
This creates variables cyg_hal_sys_argc, argv and environ, to go
alongside functions like cyg_hal_sys_open(). The argc, argv and
environ variables are not touched, deliberately. It forces code
that uses argv to use a #ifdef for e.g. CYGPKG_HAL_SYNTH, or the code
won't compile for targets other than the synthetic target. Otherwise
people might start depending on being able to set eCos environment
variables, and run into strange difficulties when development switches
to a real embedded target.
Bart