WEC-2013-Logo

WinCE2013-Understanding STARTUPTEXT macro-Part2

Published on September 20, 2013

This post is the continuation of the Windows Embedded Compact 2013 – Understanding STARTUPTEXT macro – Part 1. Finally found a solution on how to fix the entry point at the beginning of the code in the executable. Let’s make the hand dirty.

Instead of disturb the STARTUPTEXT macro, I define a custom macro STARTAREA in the startup.s file (which has the entry function StartUp).

Custom macro to fix the entrypoint in StartUp

Figure a) Custom macro to fix the entrypoint in StartUp

Just replace the .text with .astart from the TEXTAREA macro in kxarm.h file. Simply using this STARTAREA macro didn’t work. I made a comparison of kxarm.h between WinCE 7 and Windows Embedded Compact 2013 and interestingly I found the difference in the LEAFENTRY Macro definition.  An optional parameter “Areaname” is included in Windows Embedded Compact 2013 and which is not available in WinCE 7. Again, if the AreaName is not passed, it is fixed to “.text” segment as shown below.

Figure b) LEAF_ENTRY definition in WEC2013

Figure c) LEAF_ENTRY definition in WEC7

So, to place the Entry function at the beginning we must pass the AreaName in the LEAF_ENTRY as shown below.

Figure d) StartUp routine (Entry code)

Hurray!!!! It worked and able to place the startup code at the beginning of the executable as shown below.

Figure e) .Map file of the executable

Now I am able to remove the jump page and directly jump to the StartUp entry which helps to reduce the size. Keep in mind that it is your responsibility to take care the ARM -> THUMB switching since the jump instruction is removed from your image. The above StartUp routine (Figure d) take care of this. Below figure shows the startup location in the binary file.

Figure f) .lst file

Figure g) xldrsd.nb0 file

Defining a custom code segment instead of .astart
There are some cases we may need to use custom code segment apart from .astart or .text. Let’s see how to do that. I use the same macro STARTAREA for easy understanding and create a custom segment named as .abegin which is going to do that same work as .astart segment, only the name is ours as shown in the below figure.

Figure h) Custom segment name

Simply adding this will create a custom segment as shown in the below figure but it won’t work because it is created as a separate section and the remaining code is in a separate section which won’t work.

Figure i) .abegin and other code are in different section

Now how to make it in a single section? There is a linker option called MERGE which helps to merge the sections. You have to define through LDEFINES in sources file as shown below.

Figure j) Linker option -Merge

After adding this you can get the single code section as shown below.

Figure k) .abegin segment merged with other code segment

Now you will get a prober working binary. A question here… How .astart is merged with other code segments? Makefile.def available in \WINCE800\public\common\oak\misc will answer your question. This Merge option is added by default for .astart section as shown below.

Figure L) .astart is merged with .text segment in makefile.def

You can see this in the build.log file as shown below.

Figure M) build.log shows the linker parameters

Hope this post shade some lights for the people who wants to fix the entry point at the beginning also to create a custom code segment.

 

 

Recently Published