{"id":1769,"date":"2013-09-20T19:57:34","date_gmt":"2013-09-20T14:27:34","guid":{"rendered":"http:\/\/www.e-consystems.com\/blog\/windowsce\/?p=1006"},"modified":"2024-03-18T18:11:09","modified_gmt":"2024-03-18T12:41:09","slug":"wec2013-understanding-startuptext-macro-part-2","status":"publish","type":"post","link":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wec2013-understanding-startuptext-macro-part-2\/","title":{"rendered":"WinCE2013-Understanding STARTUPTEXT macro-Part2"},"content":{"rendered":"<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">This post is the continuation of the <a href=\"https:\/\/www.e-consystems.com\/blog\/windowsce\/wec2013-understanding-startuptext-macro\/\">Windows Embedded Compact 2013 \u2013 Understanding STARTUPTEXT macro &#8211; Part 1<\/a>. Finally found a solution on how to fix the entry point at the beginning of the code in the executable. Let\u2019s make the hand dirty.<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">Instead of disturb the STARTUPTEXT macro, I define a custom macro STARTAREA in the startup.s file (which has the entry function StartUp).<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1007\" title=\"Custom macro to fix the entrypoint in StartUp \" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-001.png\" alt=\"Custom macro to fix the entrypoint in StartUp \" width=\"397\" height=\"80\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-001.png 397w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-001-307x62.png 307w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure a) Custom macro to fix the entrypoint in StartUp<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">Just replace the <strong>.text<\/strong> with .<strong>astart<\/strong> from the TEXTAREA macro in kxarm.h file. Simply using this STARTAREA macro didn\u2019t 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. \u00a0An optional parameter \u201cAreaname\u201d 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 <strong>\u201c.text<\/strong>\u201d segment as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-002.png\" alt=\"LEAF_ENTRY definition in WEC2013\" width=\"415\" height=\"357\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure b) LEAF_ENTRY definition in WEC2013<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-003.png\" alt=\"LEAF_ENTRY definition in WEC7\" width=\"453\" height=\"165\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure c) LEAF_ENTRY definition in WEC7<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">So, to place the Entry function at the beginning we must pass the AreaName in the LEAF_ENTRY as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-004.png\" alt=\"StartUp routine (Entry code)\" width=\"475\" height=\"315\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure d) StartUp routine (Entry code)<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">Hurray!!!! It worked and able to place the startup code at the beginning of the executable as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-006.jpg\" alt=\".Map file of the executable\" width=\"602\" height=\"402\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure e) .Map file of the executable<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">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 -&gt; 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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-007.png\" alt=\".lst file\" width=\"358\" height=\"163\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure f) .lst file<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-008.png\" alt=\"xldrsd.nb0 file\" width=\"482\" height=\"183\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure g) xldrsd.nb0 file<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\"><strong>Defining a custom code segment instead of .astart<\/strong><br \/>\nThere are some cases we may need to use custom code segment apart from .<strong>astart<\/strong> or .<strong>text<\/strong>. Let\u2019s see how to do that. I use the same macro STARTAREA for easy understanding and create a custom segment named as <strong>.abegin <\/strong>which is going to do that same work as <strong>.astart<\/strong> segment, only the name is ours as shown in the below figure.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-009.png\" alt=\"Custom segment name\" width=\"493\" height=\"413\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure h) Custom segment name<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">Simply adding this will create a custom segment as shown in the below figure but it won\u2019t work because it is created as a separate section and the remaining code is in a separate section which won\u2019t work.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-011.jpg\" alt=\".abegin and other code are in different section\" width=\"601\" height=\"347\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure i) <strong>.abegin<\/strong> and other code are in different section<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">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 <strong>sources<\/strong> file as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-012.png\" alt=\"Linker option -Merge\" width=\"355\" height=\"346\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure j) Linker option -Merge<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">After adding this you can get the single code section as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-013.jpg\" alt=\".abegin segment merged with other code segment\" width=\"601\" height=\"372\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure k) .<strong>abegin<\/strong> segment merged with other code segment<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">Now you will get a prober working binary. A question here\u2026 How <strong>.astart<\/strong> is merged with other code segments? <strong>Makefile.def<\/strong> available in \\WINCE800\\public\\common\\oak\\misc will answer your question. This Merge option is added by default for <strong>.astart <\/strong>section as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-014.png\" alt=\".astart is merged with .text segment in makefile.def\" width=\"371\" height=\"245\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure L) .<strong>astart<\/strong> is merged with .<strong>text<\/strong> segment in makefile.def<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">You can see this in the build.log file as shown below.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1007 size-full\" src=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2013\/09\/Wec2013-startuptext-015.jpg\" alt=\"build.log shows the linker parameters\" width=\"601\" height=\"207\" border=\"0\" \/><\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\" align=\"center\">Figure M) build.log shows the linker parameters<\/p>\n<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10pt;\">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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is the continuation of the Windows Embedded Compact 2013 \u2013 Understanding STARTUPTEXT macro&#8230;<\/p>\n","protected":false},"author":12,"featured_media":1271,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213,216],"tags":[219,264,272,280,281,300],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1769"}],"collection":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/comments?post=1769"}],"version-history":[{"count":2,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1769\/revisions"}],"predecessor-version":[{"id":2987,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/1769\/revisions\/2987"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media\/1271"}],"wp:attachment":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media?parent=1769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/categories?post=1769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/tags?post=1769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}