Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Comp.Arch.Embedded | va_args (va_start, va_end, va_list ) souce?

There are 16 messages in this thread.

You are currently looking at messages 0 to 10.

va_args (va_start, va_end, va_list ) souce? - Not Really Me - 2009-11-07 12:52:00

I'm trying to make a simplified printf that does not rely on stdarg.h and 
its accompanying baggage, so I need the source to the va_args functions. 
Including stdarg.h tends to pull in all sorts of extraneous library 
functions.

The source for libgcc was my first guess, but good gravy, it could take a 
year to unravel that stuff.

Does anyone have a clean va_args source to share, i.e., va_start, va_end, 
va_list in source that would be compiler independent?

Scott



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4581 (20091107) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com







Re: va_args (va_start, va_end, va_list ) souce? - Boudewijn Dijkstra - 2009-11-07 12:57:00

Op Sat, 07 Nov 2009 18:52:20 +0100 schreef Not Really Me  
<s...@validatedqwertysoftware.xyzzy.com>:
> I'm trying to make a simplified printf that does not rely on stdarg.h and
> its accompanying baggage, so I need the source to the va_args functions.

These are CPU dependent.  Some arguments might be in registers, some might  
be on the stack.



-- 
Gemaakt met Opera's revolutionaire e-mailprogramma:  
http://www.opera.com/mail/
(remove the obvious prefix to reply by mail)

Re: va_args (va_start, va_end, va_list ) souce? - Jon Kirwan - 2009-11-07 16:19:00

On Sat, 07 Nov 2009 18:57:28 +0100, "Boudewijn Dijkstra"
<s...@indes.com> wrote:

>Op Sat, 07 Nov 2009 18:52:20 +0100 schreef Not Really Me  
><s...@validatedqwertysoftware.xyzzy.com>:
>> I'm trying to make a simplified printf that does not rely on stdarg.h and
>> its accompanying baggage, so I need the source to the va_args functions.
>
>These are CPU dependent.  Some arguments might be in registers, some might  
>be on the stack.

Worse, this can also depend upon #pragma, extended keywords not
explicitly part of the c standard, and compile options, as well.  For
example, parameters may be placed in an XRAM parameter stack on the
8051.  Or passed in fixed static memory locations assigned and reused.
Also, parameters can be _spilled_ out of registers by the compiler if
their address is taken in the routine.

As you imply, the OP needs to disclose the compiler toolset and target
before getting closer to a meaningful answer.

Jon

Re: va_args (va_start, va_end, va_list ) souce? - =?ISO-8859-1?Q?Hans-Bernhard_Br=F6ker?= - 2009-11-08 09:12:00

Not Really Me wrote:
> I'm trying to make a simplified printf that does not rely on stdarg.h and 
> its accompanying baggage, so I need the source to the va_args functions. 

No can do.  For starters, the va_args functionality consists of macros, 
not functions.  I.e. the bulk of it is _in_ <stdarg.h>.  Trying to 
implement a variadic function without it would be quite exactly like 
trying to make omelettes without a pan.

> Including stdarg.h tends to pull in all sorts of extraneous library 
> functions.

If so, that'll be because it has to.

Variable argument lists are pretty much by definition totally 
system-specific.  They depend on the compiler, the switches it was 
invoked with, the operating system ABI, and all sorts of other things.

Re: va_args (va_start, va_end, va_list ) souce? - Not Really Me - 2009-11-09 10:03:00

Jon Kirwan wrote:
> On Sat, 07 Nov 2009 18:57:28 +0100, "Boudewijn Dijkstra"
> <s...@indes.com> wrote:
>
>> Op Sat, 07 Nov 2009 18:52:20 +0100 schreef Not Really Me
>> <s...@validatedqwertysoftware.xyzzy.com>:
>>> I'm trying to make a simplified printf that does not rely on
>>> stdarg.h and its accompanying baggage, so I need the source to the
>>> va_args functions.
>>
>> These are CPU dependent.  Some arguments might be in registers, some
>> might be on the stack.
>
> Worse, this can also depend upon #pragma, extended keywords not
> explicitly part of the c standard, and compile options, as well.  For
> example, parameters may be placed in an XRAM parameter stack on the
> 8051.  Or passed in fixed static memory locations assigned and reused.
> Also, parameters can be _spilled_ out of registers by the compiler if
> their address is taken in the routine.
>
> As you imply, the OP needs to disclose the compiler toolset and target
> before getting closer to a meaningful answer.
>
> Jon


grumble, grumble.  I suppose you are both right.  It really does have to be 
processor/compiler specific.  Sometimes it is only clear when someone else 
points it out.

Thanks,
Scott 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4588 (20091109) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





Re: va_args (va_start, va_end, va_list ) souce? - Nobody - 2009-11-09 17:34:00

On Sat, 07 Nov 2009 10:52:20 -0700, Not Really Me wrote:

> I'm trying to make a simplified printf that does not rely on stdarg.h and 
> its accompanying baggage, so I need the source to the va_args functions. 

They're macros, not functions. The fact that the second argument to
va_arg() is a type should be a clue (you can't pass a type as a function
argument).

> Including stdarg.h tends to pull in all sorts of extraneous library 
> functions.
> 
> The source for libgcc was my first guess,

Nope; try the source for gcc itself.

gcc's stdarg.h (it's part of gcc, not libc) defines them as:

	#define va_start(v,l)	__builtin_va_start(v,l)
	#define va_end(v)	__builtin_va_end(v)
	#define va_arg(v,l)	__builtin_va_arg(v,l)

the __builtin_* "functions" are rather like what Lisp calls "special
forms": neither functions nor macros, but constructs which the compiler
recognises and handles specially.

If you want to write equivalents, you need to know the details of the
platform's calling convention, i.e. which arguments will be in which
registers, which will be on the stack (and where).

If you're lucky, the compiler will just push all of the unspecified
arguments onto the stack in right-to-left order, so va_arg() is just
essentially "(*((type *)(ap))++)"; most x86 platforms behave like this. If
you're not so lucky, you will have to enumerate all of the possible
combinations of argument types until the registers have been exhausted
(after which, the rest will be on the stack).

Also, some platforms use a different calling convention for variadic
functions (e.g. Windows uses "cdecl" rather than "stdcall"), in which case
the convention for variadic functions is often simpler (e.g. pushing all
unspecified arguments onto the stack rather than using registers).


Re: va_args (va_start, va_end, va_list ) souce? - Chris Giese - 2009-11-10 18:42:00

"Not Really Me" <s...@validatedQWERTYsoftware.XYZZY.com> wrote:

>I'm trying to make a simplified printf that does not rely on stdarg.h and 
>its accompanying baggage, so I need the source to the va_args functions. 
>Including stdarg.h tends to pull in all sorts of extraneous library 
>functions.

http://my.execpc.com/~geezer/code/printf.c

This code assumes arguments on the stack. There are STDARG.H macro
definitions in there, but be sure to check the assumptions I made
with those.


Re: va_args (va_start, va_end, va_list ) souce? - John Devereux - 2009-11-11 03:00:00

N...@execpc.com (Chris Giese) writes:

> "Not Really Me" <s...@validatedQWERTYsoftware.XYZZY.com> wrote:
>
>>I'm trying to make a simplified printf that does not rely on stdarg.h and 
>>its accompanying baggage, so I need the source to the va_args functions. 
>>Including stdarg.h tends to pull in all sorts of extraneous library 
>>functions.
>
> http://my.execpc.com/~geezer/code/printf.c
>
> This code assumes arguments on the stack. There are STDARG.H macro
> definitions in there, but be sure to check the assumptions I made
> with those.

Hi Chris,

Hey, that's the code I used in a lot of my own projects (after I dumped
newlib for small systems).

Thanks for making it available!

-- 

John Devereux

Re: va_args (va_start, va_end, va_list ) souce? - Not Really Me - 2009-11-11 09:42:00

Chris Giese wrote:
> "Not Really Me" <s...@validatedQWERTYsoftware.XYZZY.com> wrote:
>
>> I'm trying to make a simplified printf that does not rely on
>> stdarg.h and its accompanying baggage, so I need the source to the
>> va_args functions. Including stdarg.h tends to pull in all sorts of
>> extraneous library functions.
>
> http://my.execpc.com/~geezer/code/printf.c
>
> This code assumes arguments on the stack. There are STDARG.H macro
> definitions in there, but be sure to check the assumptions I made
> with those.

Thanks.  It could be real useful in the future.  My current project is using 
Wind River Compiler for PPC and it uses registers for the first seven 
arguments.

As others so helpfully pointed out, that is the reason the _va macros are 
compiler specific.

Scott 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4595 (20091111) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





Re: va_args (va_start, va_end, va_list ) souce? - vladitx - 2009-11-11 18:28:00

On Nov 11, 4:42=A0pm, "Not Really Me"
<sc...@validatedQWERTYsoftware.XYZZY.com> wrote:

> Thanks. =A0It could be real useful in the future. =A0My current project i=
s using
> Wind River Compiler for PPC and it uses registers for the first seven
> arguments.
>
> As others so helpfully pointed out, that is the reason the _va macros are
> compiler specific.

Functions with variable number of arguments receive all their variable
arguments through stack. The <stdarg.h> macros dealing with accessing
the arguments on the stack are compiler (and possibly OS, because of
calling conventions) specific, but their purpose is simple enough -
walk through a stack frame.

| 1 | 2 | next