Skip to content

Instantly share code, notes, and snippets.

@bfoz
Created February 15, 2010 11:56
Show Gist options
  • Save bfoz/304594 to your computer and use it in GitHub Desktop.
Save bfoz/304594 to your computer and use it in GitHub Desktop.
Compile and link a bootloader using SDCC
.globl __start__stack
;--------------------------------------------------------
; Stack segment in internal ram
;--------------------------------------------------------
.area SSEG (DATA)
__start__stack:
.ds 1
.area VECTOR (CODE)
.globl __interrupt_vect
__interrupt_vect:
ljmp __sdcc_gsinit_startup
.globl __start__stack
.area GSINIT0 (CODE)
__sdcc_gsinit_startup::
mov sp,#__start__stack - 1
.area GSFINAL (CODE)
ljmp _bootloader
ASM= asx8051
CC= sdcc
BOOTLOADER_ADDRESS=0x3000
OUTPUT_DIR= build
.PHONY: $(OUTPUT_DIR)
.SUFFIXES:
.SUFFIXES: .asm .c .ihx .hex .rel
AFLAGS= -plosgff
INCLUDE_DIRS= -I$(TOP)
VPATH=$(TOP)
# !!! main.c must be the first file, otherwise SDCC produces bad output
SRCS= main.c
OBJS= ${SRCS:.c=.rel}
all: $(OUTPUT_DIR)
@TOP='..' $(MAKE) -e --no-print-directory -C $< --file=../Makefile main.hex
clean:
rm -rf ${OUTPUT_DIR} *.d52 *.lst *.map *.mem *.rel *.rst *.sym
$(OUTPUT_DIR):
@mkdir -p ${OUTPUT_DIR}
.asm.rel:
${ASM} ${AFLAGS} $^
mv -f $(addprefix $(basename $^), .lst .rel .sym) .
.ihx.hex:
packihx $< > $@
.c.rel:
${CC} -c ${CFLAGS} ${INCLUDE_DIRS} $^
main.ihx: $(OBJS) crtstart.rel
${CC} ${CFLAGS} -Wl-bHOME=${BOOTLOADER_ADDRESS} -o $@ $^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment