I have code that was configured to run in FLAT mode (SMALL memory model) on a DG128A using Metrowerks CodeWarrior. I am trying to convert it to run in BANKED mode and have run into a problem. I have some legacy in-line asm code that is not tolerant to the CALL/RTC construct and associated register manipulations. Is it possible to force routines in the same PPAGE to use JSR/RTS and still allow CALL/RTC for non-same PPAGE module calls. Thanks This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us promptly by reply e-mail then delete the Message and destroy any printed copy of it. Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall be liable for the Message if altered, changed or falsified |
|
Banked Program - JSR and CALL in the same code
Started by ●January 7, 2004
Reply by ●January 8, 20042004-01-08
Steve, With the Cosmic compiler, any functions not modified by the @far qualifier are compiled using JSR/RTS. For this to work, you must make sure that there are no references to the 'near' functions outside the compile module in which they are defined. Regards, Gordon Killingsworth, Steve wrote: >I have code that was configured to run in FLAT mode (SMALL memory model) on >a DG128A using Metrowerks CodeWarrior. > >I am trying to convert it to run in BANKED mode and have run into a problem. > >I have some legacy in-line asm code that is not tolerant to the CALL/RTC >construct and associated register manipulations. > >Is it possible to force routines in the same PPAGE to use JSR/RTS and still >allow CALL/RTC for non-same PPAGE module calls. >Thanks >This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. >This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us promptly by reply e-mail then delete the Message and destroy any printed copy of it. >Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. >E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall be liable for the Message if altered, changed or falsified > >--------------------To learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu >o learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu > > -- =============================================================== Gordon Doughman Ph: 937-438-6811 Motorola Semiconductor Fax: 937-434-7457 Field Applications Engineer Pager: 800-759-8352 Pin: 1304089 Suite 175 3131 Newmark Drive Miamisburg, OH 45342 Check out my HC12 book at: http://www.rtcbooks.com/programming.php |
|
Reply by ●January 8, 20042004-01-08
Is this also true for Codewarrior version 1.0 using banked memory model and -CpPPAGE=RUNTIME? PS: Is there a performance penalty using -CpPPAGE=0xFF vs RUNTIME for the DG128A when only code is paged / not data? It seems like all calls are being dispatched as CALL/RTC in my case no matter where the caller/callee is located. The real issue is my flash programming algorithm was written for non-banked mode and used memmove to copy one of two functions written as a standalone module in HLI from ROM to a RAM buffer which is then executed at run-time. This worked great! Since turning the code into BANKED, memmove now no longer copies the code to RAM correctly. I believe that it is due to the CALL/RTC memory order differences (e.g. CALL/RTC expects/stores ADDR,PAGE) When I debug my code, memmove is seeing the last byte of the address and page value as the address of the source during the copy operation - e.g. 0xFF00,00 (start) to 0xFF3C,00 (end) instead of copying from FF00 to FF3C it tries to copy from 0000 to 3C00). See code below... if(memmove(buf, (char *)flash_clear, ((char *)flash_wrow - (char *)flash_clear))) {} // NOTE: flash_clear and flash_wrow are stored in flash one after the other ((void(*)(void))buf) (); // Execute the function flash_clear in RAM Note that the Above function call also uses the CALL/RTC convention to execute the RAM function. In an effort to fix the memmove problem I replaced the memmove call with the following code: volatile UCHAR i, *bptr=0, *eptr=0; o o [SNIP] o asm { LDY #flash_clear; STY bptr; // Load bptr with address of flash_clear code LDY #flash_wrow; STY eptr; // Load eptr with address of flash_wrow code } // Copy flash_clear machine code to RAM (buf) until start of flash_wrow code reached for(i=0;;i++) { buf[i] = *bptr++; if(bptr >= eptr) break; } // // Execute the function from RAM // Force execution via JSR to prevent CALL/RTC convention in BANKED mode // Code MUST perform an RTS implicitly so the RTC in BANKED mode will not execute // asm { ldx the_addr ; Set the Address to Write to ldy fl_data ; Point to the Data array to write jsr buf; ; Execute the code from RAM buffer "buf" } o o [SNIP] o //---------- void flash_clear(void) { // clear flash array page asm { o o [SNIP] o RTS; // Force RTS so RTC is not executed in BANKED mode } } void flash_wrow(void) { // program flash page asm { o o [SNIP] o RTS; // Force RTS so RTC is not executed in BANKED mode } } void pic_end(void) { asm { RTS; } } This seemed to work for a while however, now I read in the compiler manual that using in-line assy within a function could cause program crashes. I am experiencing crashes in some cases. So I am left with figuring out a better/correct way to copy the ROM function to RAM and executing it no matter what memory model is being used. My next strategy is to put the above "COPY/EXECUTE from RAM" code in a standalone function and coding it all in HLI including the short for loop that copies the code. IS THERE A BETTER WAY that will work in both BANKED and non-BANKED models? I am very uncomfortable with the current design - it feels like a HACK JOB, there has to be a better way! Thanks -----Original Message----- From: Gordon Doughman [mailto:] Sent: Thursday, January 08, 2004 10:03 AM To: Subject: Re: [68HC12] Banked Program - JSR and CALL in the same code Steve, With the Cosmic compiler, any functions not modified by the @far qualifier are compiled using JSR/RTS. For this to work, you must make sure that there are no references to the 'near' functions outside the compile module in which they are defined. Regards, Gordon Killingsworth, Steve wrote: >I have code that was configured to run in FLAT mode (SMALL memory model) on >a DG128A using Metrowerks CodeWarrior. > >I am trying to convert it to run in BANKED mode and have run into a problem. > >I have some legacy in-line asm code that is not tolerant to the CALL/RTC >construct and associated register manipulations. > >Is it possible to force routines in the same PPAGE to use JSR/RTS and still >allow CALL/RTC for non-same PPAGE module calls. >Thanks >This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. >This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us promptly by reply e-mail then delete the Message and destroy any printed copy of it. >Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. >E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall be liable for the Message if altered, changed or falsified > >--------------------To learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu >o learn more about Motorola Microcontrollers, please visit >http://www.motorola.com/mcu > > -- =============================================================== Gordon Doughman Ph: 937-438-6811 Motorola Semiconductor Fax: 937-434-7457 Field Applications Engineer Pager: 800-759-8352 Pin: 1304089 Suite 175 3131 Newmark Drive Miamisburg, OH 45342 Check out my HC12 book at: http://www.rtcbooks.com/programming.php --------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us promptly by reply e-mail then delete the Message and destroy any printed copy of it. Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall be liable for the Message if altered, changed or falsified |
Reply by ●January 8, 20042004-01-08
a little example with the Metrowerks compiler: For example #pragma CODE_SECTION PAGE10 static void __near test_n(void) { } static void __far test_f(void) { } void test1(void) { __asm jsr test_f; __asm call test_n; } Then place this PAGE10 section in your PRM file into one page only. Bye Daniel > -----Original Message----- > From: Gordon Doughman [mailto:] > Sent: Thursday, January 08, 2004 16:03 > To: > Subject: Re: [68HC12] Banked Program - JSR and CALL in the same code > Steve, > > With the Cosmic compiler, any functions not modified by the @far > qualifier are compiled using JSR/RTS. For this to work, you must make > sure that there are no references to the 'near' functions outside the > compile module in which they are defined. > > Regards, > Gordon > > Killingsworth, Steve wrote: > > >I have code that was configured to run in FLAT mode (SMALL memory model) on > >a DG128A using Metrowerks CodeWarrior. > > > >I am trying to convert it to run in BANKED mode and have run into a problem. > > > >I have some legacy in-line asm code that is not tolerant to the CALL/RTC > >construct and associated register manipulations. > > > >Is it possible to force routines in the same PPAGE to use JSR/RTS and still > >allow CALL/RTC for non-same PPAGE module calls. > > > > > >Thanks > > > > > >This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. > >This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us > promptly by reply e-mail then delete the Message and destroy any printed copy of it. > >Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any > part thereof is strictly prohibited. > >E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall > be liable for the Message if altered, changed or falsified > > > >--------------------To learn more about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > >o learn more about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > > > > > > > > > > > > > > > > -- > =============================================================== > Gordon Doughman Ph: 937-438-6811 > Motorola Semiconductor Fax: 937-434-7457 > Field Applications Engineer Pager: 800-759-8352 Pin: 1304089 > Suite 175 > 3131 Newmark Drive > Miamisburg, OH 45342 > > Check out my HC12 book at: > http://www.rtcbooks.com/programming.php > > > --------------------To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |
Reply by ●January 8, 20042004-01-08
Thank you Daniel, I have a few more questions: QUESTION 1: ----------- Using the __asm jsr technique, how would execution of functions with parameters be setup? e.g. test_n(uchar a, my_struct b) QUESTION 2: ----------- Based on your inputs and some quick tests, I just discovered that BANKED code access can be done in the FLAT model by using the __far modifier on modules that are linked to paged flash locations. This is a revelation to me. I was under the impression that only BANKED model could properly control compiler behavior, linkage, and memory flash programming, etc. This is very helpful in resolving my problem. In the interest of maintaining my code library compatibility with other projects is there a way to "at compile time" have a module declared __near or __far based on the dynamics of the particular project? QUESTION 3: ----------- Can the compiler resolve calls to modules in the same bank and execute a JSR automatically even if the called module is flagged as __far? e.g. (912HCDG128A) #pragma CODE_SEG PAGE1 /* Set to 18000 BANK */ static void __near test_n(void) { } static void __far test_f(void) { } void test1(void) { test_n(); // ASM generates JSR here due to __near test_f(); // ASM generates CALL here due to __far even though in same BANK } #pragma CODE_SEG DEFAULT /* Set to non-BANKED 0E000 */ void main(void) { test_n(); // ASM generates JSR here also!! Problem, the module is outside the page bounds! test_f(); // ASM generates CALL here, OK! } PRM File: SECTIONS RAM_PAGE = READ_WRITE 0x02010 TO 0x03FFF; MONITOR_BLOCK = READ_ONLY 0x0E000 TO 0x0FFFF; /* banked FLASH ROM */ FLASH_PPAGE0 = READ_ONLY 0x08000 TO 0x0BFFF; FLASH_PPAGE1 = READ_ONLY 0x18000 TO 0x19FFF; END PLACEMENT _PRESTART, STARTUP, ROM_VAR, STRINGS, NON_BANKED, DEFAULT_ROM, COPY INTO MONITOR_BLOCK; PAGE0 INTO FLASH_PPAGE0; PAGE1 INTO FLASH_PPAGE1; DEFAULT_RAM INTO RAM_PAGE; END STACKSIZE 0x100 -----Original Message----- From: Daniel Friederich [mailto:] Sent: Thursday, January 08, 2004 1:29 PM To: Subject: RE: [68HC12] Banked Program - JSR and CALL in the same code a little example with the Metrowerks compiler: For example #pragma CODE_SECTION PAGE10 static void __near test_n(void) { } static void __far test_f(void) { } void test1(void) { __asm jsr test_f; __asm call test_n; } Then place this PAGE10 section in your PRM file into one page only. Bye Daniel > -----Original Message----- > From: Gordon Doughman [mailto:] > Sent: Thursday, January 08, 2004 16:03 > To: > Subject: Re: [68HC12] Banked Program - JSR and CALL in the same code > Steve, > > With the Cosmic compiler, any functions not modified by the @far > qualifier are compiled using JSR/RTS. For this to work, you must make > sure that there are no references to the 'near' functions outside the > compile module in which they are defined. > > Regards, > Gordon > > Killingsworth, Steve wrote: > > >I have code that was configured to run in FLAT mode (SMALL memory model) on > >a DG128A using Metrowerks CodeWarrior. > > > >I am trying to convert it to run in BANKED mode and have run into a problem. > > > >I have some legacy in-line asm code that is not tolerant to the CALL/RTC > >construct and associated register manipulations. > > > >Is it possible to force routines in the same PPAGE to use JSR/RTS and still > >allow CALL/RTC for non-same PPAGE module calls. > > > > > >Thanks > > > > > >This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. > >This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us > promptly by reply e-mail then delete the Message and destroy any printed copy of it. > >Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any > part thereof is strictly prohibited. > >E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall > be liable for the Message if altered, changed or falsified > > > >--------------------To learn more about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > >o learn more about Motorola Microcontrollers, please visit > >http://www.motorola.com/mcu > > > > > > > > > > > > > > > > -- > =============================================================== > Gordon Doughman Ph: 937-438-6811 > Motorola Semiconductor Fax: 937-434-7457 > Field Applications Engineer Pager: 800-759-8352 Pin: 1304089 > Suite 175 > 3131 Newmark Drive > Miamisburg, OH 45342 > > Check out my HC12 book at: > http://www.rtcbooks.com/programming.php > > > --------------------To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu > o learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu --------------------To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu o learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu This e-mail and any files transmitted with it ( Message ) are confidential and may contain privileged information. This Message is intended solely for the addressee(s). If you have received this Message in error, please inform us promptly by reply e-mail then delete the Message and destroy any printed copy of it. Any unauthorized use, review, retransmission, dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. E-mails are susceptible to alteration. Neither Perry Slingsby Systems nor any of its subsidiaries and affiliates shall be liable for the Message if altered, changed or falsified |