Reply by Daniel Friederich March 2, 20052005-03-02
Actually this has been fixed in the start12.c contained in the HCS12X
V4.0 release (which does not target HC12/HCS12 directly, but the
start12.c it contains works also for HC12 V3.1).
Let me know (off list) if I should send you the new start12.c of HCS12X
V4.0.
(you could also download the complete HCS12X V4.0 from the Metrowerks
web page, but that's a big > 100MB download just to get a 15 kB file.)

Daniel
....
LDD 2,X+ ; byte count
#ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
NextWord: CLR 1,Y+ ; clear memory byte
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D, NextWord ; dec byte count
#else
LSRD ; /2 and save bit 0 in the carry
* BEQ LoopClrW1 ; do we copy more than 1 byte?
* PSHX
LDX #0
LoopClrW: STX 2,Y+ ; Word-Clear
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D, LoopClrW
PULX
*LoopClrW1:
* BCC LastClr ; handle last byte
CLR 1,Y+
LastClr:
#endif
PULY ; restore nofZeroOuts

#ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to
the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
#else
LSRD ; /2 and save bit 0 in the carry
* BEQ Copy1 ; do we copy more than 1 byte?
*Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to
the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
*Copy1:
* BCC NextBlock ; handle last byte?
MOVB 1,X+,1,Y+ ; copy the last byte
#endif Mike wrote:

>Yes that also works ... there is an optimize for size setting in the same code area ... depending on what you have selected drops in different copy down code.
>
>Problems like this would be a nightmare for newbees.
>
>Mike. >#ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
>Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the
>data area
> __FEED_COP_IN_HLI() ; feed the COP if necessary
>/*lint !e505 !e522 asm code */
> DBNE D,Copy ; copy-byte loop
>#else >
>>>>>>>>>>>>This is where the problem is <<<<<<<<<<<<<<<<<
>>>>>>>>>>>>
>>>>>>>>>>>>
>
> LSRD ; /2 and save bit 0 in the carry
>Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to the
>data area
>
> ----- Original Message -----
> From: tonalbuilder2002
> To:
> Sent: Wednesday, March 02, 2005 2:23 PM
> Subject: [68HC12] Re: Start12.c source code problem >
> Just recently I ran into a similar problem in the same part of
> start12.c code. The problem appeared when I started tinkering with
> compiler optimization settings. In my case start12 was trying to
> initialize 0xffff bytes of RAM, including...you guessed it...the
> stack. Gave me a whole new apprecation for the simulator.
>
> In my case the fix was to back off on optimization.
>
> Bill T.
> http://www.kupercontrols.com >
>
>Yahoo! Groups Links >
>


Reply by Mike March 2, 20052005-03-02
Yes that also works ... there is an optimize for size setting in the same code area ... depending on what you have selected drops in different copy down code.

Problems like this would be a nightmare for newbees.

Mike. #ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the
data area
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
#else

>>>>>>>>>>> This is where the problem is <<<<<<<<<<<<<<<<<

LSRD ; /2 and save bit 0 in the carry
Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to the
data area

----- Original Message -----
From: tonalbuilder2002
To:
Sent: Wednesday, March 02, 2005 2:23 PM
Subject: [68HC12] Re: Start12.c source code problem
Just recently I ran into a similar problem in the same part of
start12.c code. The problem appeared when I started tinkering with
compiler optimization settings. In my case start12 was trying to
initialize 0xffff bytes of RAM, including...you guessed it...the
stack. Gave me a whole new apprecation for the simulator.

In my case the fix was to back off on optimization.

Bill T.
http://www.kupercontrols.com


Reply by tonalbuilder2002 March 2, 20052005-03-02

Just recently I ran into a similar problem in the same part of
start12.c code. The problem appeared when I started tinkering with
compiler optimization settings. In my case start12 was trying to
initialize 0xffff bytes of RAM, including...you guessed it...the
stack. Gave me a whole new apprecation for the simulator.

In my case the fix was to back off on optimization.

Bill T.
http://www.kupercontrols.com --- In , "Mike" <mikesuthy@h...> wrote:
>
> Hi all,
>
> I've been working with the 9S12E128 MCU and have found an
interesting
> problem when using metrowerks code warrior.
>
> On my program execution, an illegal breakpoint would be performed
and
> execution would stop.
> After investigating I found the following ...
>
> During execution of the CopyDown function in the code warriors
Start12.c
> code the loop counter would be set incorrectly.
>
> This would happen if the block to be copied only had one byte ...
this was
> the case with my program ... there were two blocks with the second
only
> having one byte to be copied ... thus when the code hit the LSRD
instruction
> (mark in the code below), 1 is shifted left resulting in 0 ... then
the DBNE
> decrements this to $FFFF and compares this to 0 ... this is where
the
> program morphs into a monster and over writes lots of good stuff!
>
> I simply solved this by initialising some dummy variables but later
have
> added a conditional branch down to the MOVB 1,X+,1,Y+ instruction
if D = 1
> before the LSRD instruction for a long term fix ...
>
> Just wondering if anyone else has had any problems with this or
have I
> missed out one of those all important updates ;-)
>
> Mike. >
>
> CopyDown:
> #ifdef __ELF_OBJECT_FILE_FORMAT__
> LDX _startupData.toCopyDownBeg ; load address of
copy down
> desc.
> #else
> LDX _startupData.toCopyDownBeg:2 ; load address of
copy down
> desc.
> #endif
> NextBlock:
> LDD 2,X+ ; size of init-data -> D
> BEQ funcInits ; end of copy down desc.
> #ifdef FAR_DATA
> PSHD ; save counter
> LDAB 1,X+ ; load destination page
> LDY 2,X+ ; destination address
> __PIC_JSR(_SET_PAGE) ; sets the destinations
page
> register
> PULD ; restore counter
> #else /* FAR_DATA */
> LDY 2,X+ ; load destination
address
> #endif /* FAR_DATA */
>
> #ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
> Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM
to the
> data area
> __FEED_COP_IN_HLI() ; feed the COP if
necessary
> /*lint !e505 !e522 asm code */
> DBNE D,Copy ; copy-byte loop
> #else
>
> >>>>>>>>>>> This is where the problem is <<<<<<<<<<<<<<<<<
>
> LSRD ; /2 and save bit 0 in
the carry
> Copy: MOVW 2,X+,2,Y+ ; move a word from ROM
to the
> data area
> __FEED_COP_IN_HLI() ; feed the COP if
necessary
> /*lint !e505 !e522 asm code */
> DBNE D,Copy ; copy-word loop
> BCC NextBlock ; handle last byte?
> MOVB 1,X+,1,Y+ ; copy the last byte
> #endif
> BRA NextBlock



Reply by Mike March 1, 20052005-03-01

Hi all,

I've been working with the 9S12E128 MCU and have found an interesting
problem when using metrowerks code warrior.

On my program execution, an illegal breakpoint would be performed and
execution would stop.
After investigating I found the following ...

During execution of the CopyDown function in the code warriors Start12.c
code the loop counter would be set incorrectly.

This would happen if the block to be copied only had one byte ... this was
the case with my program ... there were two blocks with the second only
having one byte to be copied ... thus when the code hit the LSRD instruction
(mark in the code below), 1 is shifted left resulting in 0 ... then the DBNE
decrements this to $FFFF and compares this to 0 ... this is where the
program morphs into a monster and over writes lots of good stuff!

I simply solved this by initialising some dummy variables but later have
added a conditional branch down to the MOVB 1,X+,1,Y+ instruction if D = 1
before the LSRD instruction for a long term fix ...

Just wondering if anyone else has had any problems with this or have I
missed out one of those all important updates ;-)

Mike.

CopyDown:
#ifdef __ELF_OBJECT_FILE_FORMAT__
LDX _startupData.toCopyDownBeg ; load address of copy down
desc.
#else
LDX _startupData.toCopyDownBeg:2 ; load address of copy down
desc.
#endif
NextBlock:
LDD 2,X+ ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
#ifdef FAR_DATA
PSHD ; save counter
LDAB 1,X+ ; load destination page
LDY 2,X+ ; destination address
__PIC_JSR(_SET_PAGE) ; sets the destinations page
register
PULD ; restore counter
#else /* FAR_DATA */
LDY 2,X+ ; load destination address
#endif /* FAR_DATA */

#ifdef __OPTIMIZE_FOR_SIZE__ /* -os, default */
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the
data area
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
#else

>>>>>>>>>>> This is where the problem is <<<<<<<<<<<<<<<<<

LSRD ; /2 and save bit 0 in the carry
Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to the
data area
__FEED_COP_IN_HLI() ; feed the COP if necessary
/*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
BCC NextBlock ; handle last byte?
MOVB 1,X+,1,Y+ ; copy the last byte
#endif
BRA NextBlock