Printf and _sbrk

Pierre Habraken
Tue Apr 30 09:49:00 GMT 2002


I am trying to use newlib together with gcc, gas and gdb for teaching
Arm assembly language to undergraduate students.

One software that students have to work on is a small program which
simulates the part in a kernel or OS which manages context switches.
No interrupts are available to the program, they are simulated using the
SWI instruction.

Program execution is emulated using the Gdb "sim" target.
Gcc, Binutils, Newlib and Gdb were compiled for the target arm-elf.

The main procedure of the program installs the SWI vector then
initializes 3 tasks and last starts the 1st task by mean of a call to
Afterwards, execution of each task is scheduled according to a round
robin policy : actually, as there are no timer interrupts, each task has
to relinquishes the processor at some point of its code using another
call to SWI.

The main program is started by the simulator in SVC mode.
Tasks run is USER mode.

Now, here is the problem :

- if the main program (running in SVC mode) does NOT execute any printf,
  then the first printf called by a task (running in USER mode) makes
  the whole program abort and display the message :
  _sbrk: Heap and stack collision

- if the main program DOES execute one (at least) call to printf before
  launching the 1st task, then everything runs ok until normal
  completion of all three tasks.

Did anyone already meet the same sort of behavior ?
What might cause it ?

Thanks in advance for any help !

Tél: 04 76 82 72 83 - Fax: 04 76 82 72 87

More information about the Newlib mailing list