This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to pass arguments to user application

Hi there,

I am currently developing an os for the beagleboard r4 and try to pass arguments to the user's applications main(). I tried to push some values to register R0, R1, R2, R3 but argc and argv are never set. I put the --args option to my app's linker script but still no success.

it seems that the __ti_auto_init() or __args_main() do not use my pushed values. where do I have to set them for my new user application?

thanks in advance and best regards,

matthias schmid

my application's .cmd file and the boot.asm file:

////////////////////////////////////////////////////////
//
// Linker command file for a Task for the Ottos-Kernel
//
-c
--args=1024

-stack           0x00002000
-heap            0x00002000

MEMORY
{

   virtual_memory:     ORIGIN 0x00020000 LENGTH = 0x01000000
   stack_memory:       ORIGIN 0x10000000 LENGTH = 0x00002000
   sysmem_memory:      ORIGIN 0x10002000 LENGTH = 0x00002000

}

SECTIONS
{
   ORDER
   .text       > virtual_memory  {
      boot.obj
      *(.text)
   }
   .bss        > virtual_memory
   .const      > virtual_memory
   .cinit      > virtual_memory
   .pinit      > virtual_memory
   .cio        > virtual_memory
   .switch     > virtual_memory
   .far        > virtual_memory
   .data       > virtual_memory
   .switch     > virtual_memory
   .init_array > virtual_memory

   .stack      > stack_memory  {
      systemStack = .;
   }

   .sysmem     > sysmem_memory {
      sysmem = .;
   }

}

// ***************************
// boot.asm


    ;PUSH {A1-A4}

    .armfunc _c_int00
    .global  _c_int00

;***************************************************************
;* TI includes
;***************************************************************

    .asg    __args_main,   ARGS_MAIN_RTN
    .global ARGS_MAIN_RTN
    .global __TI_auto_init

;***************************************************************
;* Included addresses from the linker
;***************************************************************

    .global systemStack

;***************************************************************
;* CONSTANTS USED BY THIS MODULE
;***************************************************************

c_r13_system    .long    systemStack

;***************************************************************
;* FUNCTION DEF: _c_int00
;***************************************************************

_c_int00: .asmfunc


    ; Perform all the required initilizations:
    ;  - Process BINIT Table
    ;  - Perform C auto initialization
    ;  - Call global constructors)

    BL    __TI_auto_init
    ;POP {A1-A4}
    ; CALL APPLICATION
    BL    ARGS_MAIN_RTN
.end


  • The compiler tools do have some hooks to aid in the process of handling command line arguments.  However, these hooks are not documented.  At present, such hooks are only used by other tooling supplied by TI, including CCS and BIOS.  

    Unfortunately, then, the best I can do is give you some rough guidelines to help you get started.

    See how the linker option --arg_size works in the Assembly Language Tools Book.  That's where you'll learn how the linker reserves a block of memory which starts with the symbol __c_args__.   Then extract the file args_main.c from the rtssrc.zip file in the \lib directory of the compiler distribution.  There you can see C code which processes the contents of the memory at __c_args__ so that, when main is called, the command line arguments are in the familiar argc/argv format.  From that code you can determine how the loader in your OS has to initialize the __c_args__ block of memory.

    Thanks and regards,

    -George