O.K. Now I know I added the code properly, and here goes again... This is a first stage loader. It is designed to inject code into upper memory, but it can be used to create the injected code also, as a second project. It compiles properly (but doesn't run if the xn file has the oscillator specified...dunno why!). It needs to have the stack pointer (sp) assigned to a proper location, and any suggestions are welcome. Criticisms welcome too : )
Start.xc
Code: Select all
#include <xs1.h>
#include <print.h>
#include "CopyCode.h"
// Entry point... How do I make sure this always appears first
// in the
void _start(void)
{
// This initializes the code and data segment pointers
// I suppose I will need to also initialize the stack pointer eh?
// Any good suggestions?
asm("ldap r11, _cp");
asm("set cp, r11");
asm("ldap r11, _dp");
asm("set dp, r11");
// This calls the main routine
main();
}
Main.xc
Code: Select all
#include <xs1.h>
#include <print.h>
#include "CopyCode.h"
// The following array is binary code for the XS1 and causes port
// 1L to flash. If you save this in a binary editor, you can use
// "xobjdump -D filename" to disassemble the array of bytes and
// see what it does.
unsigned short uBinArr[58] = {
0x7741,0xF000,0xD82B,0x37FB,0xF000,0xD832,0x37EB,0xD000,0x7743,0x5502,0x5541,0x5580,0x86C1,0xE801,0xB6C4,0xF000
,0x5880,0xA6DD,0xF000,0x6EC0,0x6900,0xF000,0x6D41,0xAECE,0x14E7,0x1718,0xE809,0xB708,0xAF02,0x1255,0x16D4,0xE809
,0xB708,0x770B,0xF000,0x6C02,0xE808,0xF000,0x6846,0xFED4,0x0FEC,0x77C0,0xF000,0x6C02,0xE800,0x77C0,0x2D00,0x0131
,0x5A00,0x0262,0x0B00,0x0001,0xB044,0x0001,0xB054,0x0001,0x0B00,0x0001};
int main(void)
{
// This initializes the code and data segment pointers
// I suppose I will need to also initialize the stack pointer eh?
// Any good suggestions?
asm("ldap r11, _cp");
asm("set cp, r11");
asm("ldap r11, _dp");
asm("set dp, r11");
// This calls the main routine.
// 0x1B000 is where in memory the code gets copied to and started
// 58 is the number of elements in the array
// uBinArr is an array of shorts containing the binary to be executed
CopyCode(0x1B000, 58, uBinArr);
}
CopyCode.S (make sure you have the 'S' capitalized to allow for the xc preprocessor to go through the comments, etc...)
Code: Select all
.text
.align 2
// void CopyCode(int nJumpLoc, int nCodeLen, unsigned short uBinArr[])
// r0 is the jump/copy address
// r1 is the code length
// r2 is the source array
// r3, and r11 do not need to be saved by the callee
.globl CopyCode
.align 2
.type CopyCode,@function
.set CopyCode.nstackwords,0
.globl CopyCode.nstackwords
.cc_top CopyCode.function
CopyCode:
sub r1, r1, 1
ld16s r3, r2[r1]
st16 r3, r0[r1]
bt r1, CopyCode
bau r0
retsp 0
.cc_bottom CopyCode.function
CopyCode.h
Code: Select all
#ifndef _copycode_h
#define _copycode_h
#ifdef __XC__
void CopyCode(int nJumpLoc, int nCodeLen, unsigned short uBinArr[]);
#else
void CopyCode(int nJumpLoc, int nCodeLen, unsigned short *uBinArr);
#endif
int main(void);
#endif
Makefile
Code: Select all
# The TARGET variable determines what target system the application is
# compiled for. It either refers to an XN file in the source directories
# or a valid argument for the --target option when compiling
TARGET = XS1-U8A-64-FB96-C5
# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name
APP_NAME = EnvisicONFILoader
# The USED_MODULES variable lists other module used by the application.
USED_MODULES =
# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
XCC_FLAGS_Debug = -O0 -g
XCC_FLAGS_Release = -O3 -g
# The debug version does not have the --bootable flag, since I am using
# it for testing. If someone wants to use this sample to compile the
# binary that eventually gets converted to text, use the --bootable
# flag to create and xe file with just the binary. Then use xobjdump --split myfile.xe
# to get image_n0c0.bin. Convert the bin file to a text array of shorts and
# use this as the array in the main.xc file. If one is compiling code to
# be injected, the following flags need to be added to both the debug and
# release paths (-Xmapper --image-base -Xmapper 0x0001B000). This allows
# the code to be compiled to appear at whatever upper memory location you
# desire.
XCC_MAP_FLAGS_Debug = -nostdlib -Xmapper --first -Xmapper ".\..\.build_Debug\src\start.xc.o"
XCC_MAP_FLAGS_Release = -nostdlib --bootable -Xmapper --first -Xmapper ".\..\.build_Release\src\start.xc.o"
# Our custom build rule..remember, before 'xcc' there should be a tab,
# not a space. Otherwise it will give missing separator for linux makefiles
ifeq "$(CONFIG)" "Debug"
.build_Debug/src/start.xc.o: src/start.xc
xcc $(XCC_FLAGS_Debug) -c $< -o $@
$(BIN_DIR)/$(APP_NAME)_Debug.xe: .build_Debug/src/start.xc.o
endif
ifeq "$(CONFIG)" "Release"
.build_Release/src/start.xc.o: src/start.xc
xcc $(XCC_FLAGS_Release) -c $< -o $@
$(BIN_DIR)/$(APP_NAME).xe: .build_Release/src/start.xc.o
endif
# The VERBOSE variable, if set to 1, enables verbose output from the make system.
VERBOSE = 1
XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
# The EXCLUDE_FILES is for custom make rules to avoid files being linked twice
EXCLUDE_FILES = start.xc
XS1-U8A-64-FB96-C5.xn - a stripped down version of it. For some reason, setting the Oscillator="24MHz" in the <Node Id> section kills the app produced. Any suggestions???
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
<Type>Device</Type>
<Name>XS1-U8A-64-FB96-C5 Device</Name>
<Declarations>
<Declaration>tileref tile[1]</Declaration>
</Declarations>
<Packages>
<Package id="0" Type="XS1-UnA-64-FB96">
<Nodes>
<Node Id="0" InPackageId="0" Type="XS1-L8A-64" SystemFrequency="500MHz" ReferenceFrequency="100MHz">
<Tile Number="0" Reference="tile[0]"/>
</Node>
</Nodes>
</Package>
</Packages>
<JTAGChain>
<JTAGDevice NodeId="0"/>
</JTAGChain>
</Network>