Extending SDK

After Porting LLVM-MOS to a platform, please consider submitting your port for inclusion in the LLVM-MOS SDK. We'd like the SDK to be a nice out-of-the-box way to write code for any 6502 platform, and contributions along those lines are greatly appreciated.

This guide follows the Porting Guide above; make sure you've at least skimmed it before continuing, otherwise this guide likely won't make as much sense.

Review
Completing the porting guide produced the following artifacts:

A linker script, : A command line to build a binary:

This is enough to set up a freestanding platform in the SDK.

CMake
As mentioned previously, our SDK uses CMake to build. If you haven't done so already, check out and build the SDK sources using CMake.

Let's call our platform, for old times' sake. Make a  subdirectory under the mos-platform directory for the platform to live in. Tell CMake that the new directory exists by adding  to mos-platform/CMakeLists.txt. This will cause CMake to look for a  file in the   subdirectory, which will tell it how to build the   platform.

Platform Definition
A minimal platform  for   is just. Building and installing the SDK afterwards will then produce a  symlink that tells Clang to use the platform.

This produces an incomplete target with nothing in it. Our target should be complete though; it should be possible to produce binaries from it. So we can tell CMake that by using.

This will cause CMake to link for a  file in the   subdirectory. Placing the  file there allows the build and install to succeed and causes   to automatically use that linker script.

This still doesn't allow producing binaries though; the command line used for this was, not. Since the  platform is based off of the   platform, we need to change the platform definition to. With this,  can produce executables.

Platform Libraries
There's one remaining part of the command line to deal with:. These libraries need to be included in the platform libraries for.

For each platform, the Clang driver expects the following files to be available to the linker: has already been discussed. and  contain routines used at the beginning and end of a program. contains functionality that may or may not be included, depending on what symbols are referenced in the program, while  contains the essential scaffolding to start and end a program. contains routines used to implement compiler functionality like multiplication and division, while  contains the C standard library and support for some C++ language features.

We can't just include  and   on the command line; the above files are structured so that compiler flags like   do what they logically should. So, we need to include  and   into the appropriate platform library,.

To do so, we add to the    : The early return just makes sure the following libraries aren't compiled for the host; they're 6502 code, so they need to be compiled with llvm-mos.

The remainder of the code creates a  for   that bundles in the ,   , and   libraries from the   platform. The other libraries bleed through from the  platform, while the   for   will be used in preference to the one from

With this,  will behave like to the original command line, and the platform is now fully incorporated into the SDK.