This guide explores the complex process of generating a bare metal binary using MSVC tools, addressing the limitations and current capabilities of the Visual Studio environment.
---
This video is based on the question https://stackoverflow.com/q/64944350/ asked by the user 'Vincent Agriesti' ( https://stackoverflow.com/u/6316437/ ) and on the answer https://stackoverflow.com/a/64980787/ provided by the user 'Frant' ( https://stackoverflow.com/u/4017881/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: What is the process for generating a bare metal binary with MSVC tools?
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Generating a Bare Metal Binary with MSVC Tools: A Challenging Task
When working with embedded systems, especially those using ARM architecture, you may find yourself needing to create a bare metal binary. This process typically entails using a toolchain to compile source code into an executable format without the overhead of an operating system. In the GNU ecosystem, this is relatively straightforward, but how does one achieve the same with Microsoft Visual Studio's MSVC tools? In this post, we’ll dive into the process and the challenges faced when trying to generate a bare metal binary using MSVC.
The Problem
The fundamental question posed is: What is the process for generating a bare metal binary with MSVC tools? While many engineers are familiar with the GNU tooling (where you use commands like cc, as, and ld), the equivalent steps using MSVC are less clear, and this lack of clarity leads to confusion.
As an example, consider a simple ARM64 assembly file intended to load a constant value into a register. For this assembly code (startup.s), you would typically follow these steps:
Assemble the source file into an object file using armasm64.exe.
Link the object file with other source files (if necessary) to produce a final executable.
However, the situation grows complicated when linking and creating the final output.
The Assembly Code
Here’s the assembly code you might start with:
[[See Video to Reveal this Text or Code Snippet]]
This code is designed to load 0xDEADBEEF into the register and then spin in an infinite loop.
Compiling the Code
To assemble the code, the command to run is:
[[See Video to Reveal this Text or Code Snippet]]
However, the next steps in linking and producing a valid output format are where many encounter difficulties.
The Linker and Its Limitations
After assembling, you’ll need to link the object file with other necessary files. The MSVC linker for ARM64 offers only a limited set of subsystem options, including:
BOOT_APPLICATION
CONSOLE
WINDOWS
NATIVE
POSIX
EFI_APPLICATION
EFI_BOOT_SERVICE_DRIVER
EFI_ROM
EFI_RUNTIME_DRIVER
Unfortunately, there is no "BAREMETAL" subsystem, which presents a significant hurdle when developing bare metal applications.
Common Errors Encountered
Attempting to link with an incorrect base address leads to consistent failure messages from the linker, such as:
[[See Video to Reveal this Text or Code Snippet]]
This error indicates that any address chosen for the base must be above 4GB, a rule set by the ARM64 architecture.
Insights from Testing
Upon further analysis while running dumpbin.exe on the output from the linker, it was determined that the base address of successful binaries typically started at 0x0000000180000000. Still, converting these into usable formats like s-record or intel hex for use in embedded systems was not possible using MSVC.
Conclusion: Current State for MSVC and Bare Metal Developments
In conclusion, it appears that the MSVC tools alone do not currently support building ARM64 bare-metal applications effectively. This post aims to shed light on the challenges while inviting further dialogue and exploration of solutions within the developer community.
If you're venturing into bare-metal programming using MSVC, prepare for limitations and consider complementing your development with other tools or environments suited for this niche.
Final Thoughts
As the embedded systems landscape continues to evolve, so too must our tools and methodologies. Learning about these limitations helps developers make informed decisions about their toolchain and project planning. If anyone has more insights or alternatives, we encourage you t
Информация по комментариям в разработке