Getting started with HC12 relocatable code SECTIONS.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting started with HC12 relocatable code SECTIONS.

Jump to solution
1,663 Views
acpRobert
Contributor I
I'm new to HC12 but have used Metrowerks for years, most recently on a 56300E project in mixed and assembly.  I'm just getting acquinted with the HC12 and wanted to model a relocatable assembly project.
 
Starting with the code wizard, I have a nice little main program that calls its own subroutine.
 
Trying to take the next logical step, I've been  unable to put that subroutine in its own assembly file, or even in another section in  main.asm. 
 
I include the MySub.asm by adding the file to the Sources folder and everything compiles fine (using the appropriate XDEFs and XREFs), but the subroutine call fails, and the map shows that its entry point is at  0x388000 rather than in the Cxxx range.
 
Can you point me to a  simple relocatable project or explain what is necessary to add other code modules?  I'm assuming I don't have to change the Link PRM file since it says:
 
/* This is a linker parameter file for the MC9S12E128 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */
 
Here's my subroutine file.

 XDEF   CalcFibo2
; code section

; include derivative specific macros
           INCLUDE 'mc9s12e128.inc'

; code section
MyCode:     SECTION  ; <-----Same as in main.asm
; Function to calculate fibonacci numbers. Argument is in X.
CalcFibo2:
           NOP
            ...
           ....
           RTS                        ; result in D
 
 
I've tried searching the help files and spent some time searching this forum.  This is just such a basic question  -- what have I missed?
 
Rob
 

 
Labels (1)
Tags (1)
0 Kudos
1 Solution
692 Views
CompilerGuru
NXP Employee
NXP Employee
Well, the linker treats the root object (specified in the prm file with the INIT directive, _Startup by default) special. It gets moved together with all other code from the same section into the predefined .init section. I actually never likes this special treatment but since removing the behaviour would possibly break a lot of existing apps, the linker keeps this behaviour.

Daniel

View solution in original post

0 Kudos
2 Replies
692 Views
acpRobert
Contributor I
I've been doing some research while y'all are on vacation and have begun to understand that the problem is with my lack of understanding of the linker.  It turns out that since  the section "MyCode" was not specified in the linker prm file, it got assigned to  DEFAULT_ROM which is in PAGE_38 thus the address I saw in the link map.  Now I'm still not sure why the same named SECTION in the main module got pushed into SECTION ".init", but at least I've got a usable understanding of SECTIONs and the linking process.
 
Thanks for listening...
 
Rob
0 Kudos
693 Views
CompilerGuru
NXP Employee
NXP Employee
Well, the linker treats the root object (specified in the prm file with the INIT directive, _Startup by default) special. It gets moved together with all other code from the same section into the predefined .init section. I actually never likes this special treatment but since removing the behaviour would possibly break a lot of existing apps, the linker keeps this behaviour.

Daniel
0 Kudos