This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ECOS] arguments to main


>>>>> "Andrew" == Andrew Lunn <andrew.lunn@ascom.ch> writes:

    >> 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:

    Andrew> OK. Could you please commit this to CVS, along with the appropriate
    Andrew> ChangeLog etc :-)

I have committed the changes below.

Bart

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/ChangeLog,v
retrieving revision 1.6
diff -u -u -r1.6 ChangeLog
--- ChangeLog	23 May 2002 23:05:24 -0000	1.6
+++ ChangeLog	4 Aug 2002 23:17:07 -0000
@@ -1,3 +1,7 @@
+2002-08-04  Bart Veer  <bartv@tymora.demon.co.uk>
+
+	* include/hal_io.h: added argv/argv/environ definitions
+
 2002-05-23  Jesper Skov  <jskov@redhat.com>
 
 	* cdl/hal_synth.cdl: Don't run cache tests.
Index: hal_io.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/include/hal_io.h,v
retrieving revision 1.5
diff -u -u -r1.5 hal_io.h
--- hal_io.h	23 May 2002 23:05:27 -0000	1.5
+++ hal_io.h	4 Aug 2002 23:17:21 -0000
@@ -409,6 +409,11 @@
 // mmap on the "host" system - this may be unportable.
 externC int             cyg_hal_sys_mmap(struct cyg_hal_sys_mmap_args *);
 
+// Access to environmental data
+extern int              cyg_hal_sys_argc;
+extern const char**     cyg_hal_sys_argv;
+extern const char**     cyg_hal_sys_environ;
+
 // ----------------------------------------------------------------------------
 // Interaction between the application and the auxiliary.
 // Not yet available, but there is a hardware-initialization routine.

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/i386linux/current/ChangeLog,v
retrieving revision 1.6
diff -u -u -r1.6 ChangeLog
--- ChangeLog	23 May 2002 23:05:28 -0000	1.6
+++ ChangeLog	4 Aug 2002 23:17:33 -0000
@@ -1,3 +1,8 @@
+2002-08-04  Bart Veer  <bartv@tymora.demon.co.uk>
+
+	* src/vectors.S (_start):
+	Store argv and environ in cyg_hal_sys_... variables
+
 2002-04-29  Jonathan Larmour  <jlarmour@redhat.com>
 
 	* src/vectors.S:
Index: vectors.S
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/i386linux/current/src/vectors.S,v
retrieving revision 1.3
diff -u -u -r1.3 vectors.S
--- vectors.S	23 May 2002 23:05:31 -0000	1.3
+++ vectors.S	4 Aug 2002 23:17:51 -0000
@@ -47,20 +47,56 @@
 ## Description: When running on real hardware vectors.S contains
 ##	        initialization code and usually the low-level interrupt and
 ##              exception support. On the synthetic target the latter is
-##              handled by C code. The only initialization that is needed is
+##              handled by C code. The main initialization that is needed is
 ##              to jump into the C startup.        
 ##
 ######DESCRIPTIONEND####
 ##
 ##=============================================================================
 
+# 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"
+        .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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]