Problem with div (1.9.0, arm7tdmi)
Lewin A.R.W. Edwards
Mon Jul 2 18:10:00 GMT 2001
I have been experiencing a very odd bug in div() from newlib 1.9.0 on an
arm7tdmi target (using gcc 2.95.2/cygwin). The manifestation of the bug is
that subroutines will spontaneously return out of the middle of the
routine, or hang, especially on nested div calls. I eventually tracked down
the culprit and have replaced constructs like:
x = div(a,b).quot;
x = a/b;
and y = div(a,b).rem;
y = a - ((a / b) * b);
which has fixed the behavior but I am concerned that I may run into future
Is this a known bug in div(), or is it a compiler bug? Or could it be a
result of not having initalized the run-time environment correctly? My
startup code basically just initializes the hardware, sets the top of stack
and jumps to main() - which works fine for me on hppa1.1-winbond and newlib
1.something-old with gcc-something-old.
(This is not a simple stack overflow error - I moved stack 1Mb away from
the nearest RAM write :).
There is a complicating factor - this particular code lives inside a device
driver architecture, (it's a kind of object orientation I have implemented
in C), and so this code is reached through a function pointer inside a
structure, possibly through several levels of pointer dereferencing.
The system I'm working on has no real debugging support except a serial
(text) terminal and the code-loading process is slow (flash/powerup) so I'm
hoping someone has run across this one before. TIA...
-- Lewin A.R.W. Edwards
Embedded Engineer, Digi-Frame Inc.
Tel (914) 937-4090 9am-6:30pm M-F ET
Personal: http://www.larwe.com/ http://www.zws.com/
"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
More information about the Newlib