stackcheck example bugs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

stackcheck example bugs?

Rolf Freitag

Hi,

in the example stackcheck there are some confusing comments:
Due to the line

extern unsigned short _end;  ///<Last used byte of the last segment in RAM (defined by the linker)

_end is an uint16_t but the comment says byte = unsigned char (=uint8_t).
Is this a bug in the comment?

In function stackProtectionInit the writing starts at _end:

unsigned short *address = &_end;
...
(*address++) = STACK_GUARD_INIT;

due to the comment that means that the last used word in RAM gets overwritten.
Is this a bug in the comment?

Regards,

Rolf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: stackcheck example bugs?

Chris Liechti
[hidden email] wrote:
> in the example stackcheck there are some confusing comments:
> Due to the line
>
> extern unsigned short _end;  ///<Last used byte of the last segment in RAM (defined by the linker)
>
> _end is an uint16_t but the comment says byte = unsigned char (=uint8_t).
> Is this a bug in the comment?

_end is an address (and thus 16 bits wide on an msp), that points to the
first free byte (or after the last used byte) in RAM.
as i want to write a 16 bit "stack marker", i declare a short variable
and not a pointer. this also assumes that _end points to an even address
(which is usualy the case wih mspgcc).

chris


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: stackcheck example bugs?

Rolf Freitag
In reply to this post by Rolf Freitag

Hi,

> > in the example stackcheck there are some confusing comments:
> > Due to the line
> >
> > extern unsigned short _end;  ///<Last used byte of the last segment in RAM (defined by the linker)
> >
> > _end is an uint16_t but the comment says byte = unsigned char (=uint8_t).
> > Is this a bug in the comment?
>
> _end is an address (and thus 16 bits wide on an msp), that points to the
> first free byte (or after the last used byte) in RAM.
> as i want to write a 16 bit "stack marker", i declare a short variable
> and not a pointer. this also assumes that _end points to an even address
> (which is usualy the case wih mspgcc).

ok, but that's not safe because sometimes that address is odd:

> msp430-gcc -mmcu=msp430x168 -o aout.elf flag.o i2c.o main.o rand.o rs232.o signal.o temp.o times.o stackcheck.o -lm
stackcheck.o(.text+0x4): In function `stackCheck':
/home/nobody/c/mspgcc/par/stackcheck.c:70: internal error: unsupported relocation error
stackcheck.o(.text+0x12): In function `stackProtectionInit':
/home/nobody/c/mspgcc/par/stackcheck.c:46: internal error: unsupported relocation error
msp430-objcopy -O ihex aout.elf aout.a43
msp430-objdump -dSt aout.elf >aout.lst

With

    void * ptr_void = &_end;
    unsigned short * address = (unsigned short *)(ptr_void +(((int)ptr_void) bitand 1));

it always works.

Regards,

Rolf





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users