~joshrig/mipsfoo

e71eff5b4d285e7467f2e28d675882133ac434f2 — Joshua Lynch 1 year, 1 month ago 8a976f5
assembly newbie makes constants. read all about it
3 files changed, 22 insertions(+), 68 deletions(-)

M Makefile
M main.S
D main.s
M Makefile => Makefile +10 -35
@@ 5,38 5,32 @@ AS          = xc32-as
OBJCOPY     = xc32-objcopy
OBJDUMP     = xc32-objdump
SIZE        = xc32-size
BIN2HEX     = xc32-bin2hex

TARGET      = mipsfoo
OUT_ELF     = $(TARGET).elf
OUT_BIN     = $(TARGET).bin
OUT_HEX     = $(TARGET).hex
OUT_INFO    = $(TARGET).lss
OUT_MAP     = $(TARGET).map

TARGET_ARCH = 32MZ2048EFH064
ASFLAGS     = -p$(TARGET_ARCH) -mdsp -mdspr2 -mno-pdr -mfp64 \
		--no-construct-floats -mhard-float --trap --gdwarf-2
LDFLAGS     = -T$(TARGET_ARCH).ld -nostartfiles  -Map=$(OUT_MAP) \
CPPFLAGS    = -nostartfiles -ffunction-sections -fdata-sections -g -fno-common -mprocessor=32MZ2048EFH064 -Wa,-p32MZ2048EFH064,-mdsp,-mdspr2,-mno-pdr,-mfp64,--no-construct-floats,-mhard-float,--trap,--gdwarf-2 -mdfp="/opt/microchip/mplabx/v6.10/packs/Microchip/PIC32MZ-EF_DFP/1.3.58"
LDFLAGS     = -T32MZ2048EFH064.ld -Map=$(OUT_MAP) \
		--no-code-in-dinit --no-dinit-in-serial-mem

A_SRCS     := $(wildcard *.S)
C_SRCS     := $(wildcard *.c)
# A_SRCS     := $(wildcard *.S)
# OBJS        = $(C_SRCS:%.c=%.o) $(A_SRCS:%.S=%.o)
A_SRCS     := $(wildcard *.s)
OBJS        = $(C_SRCS:%.c=%.o) $(A_SRCS:%.s=%.o)
DEPS        = $(C_SRCS:%.c=%.d)

VERBOSE    := 1
OBJS        = $(A_SRCS:%.S=%.o) $(C_SRCS:%.c=%.o)


.PHONY: all
all: $(OUT_ELF) $(OUT_BIN) $(OUT_INFO)
all: $(OUT_ELF) $(OUT_BIN) $(OUT_INFO) $(OUT_HEX)


$(OUT_ELF): $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $^

$(OUT_BIN): $(OUT_ELF)
	$(OBJCOPY) -O binary $^ $@
$(OUT_HEX): $(OUT_ELF)
	$(BIN2HEX) $^

$(OUT_INFO): $(OUT_ELF)
	$(OBJDUMP) -Sh $^ > $@


@@ 44,23 38,4 @@ $(OUT_INFO): $(OUT_ELF)

.PHONY: clean
clean:
	-rm -f $(OBJS) $(DEPS) $(OUT_ELF) $(OUT_BIN) $(OUT_INFO) $(OUT_MAP) nul *.d.*


# standard commands for making a .d file
#
# %.d: %.c
# 	@echo making dependency for $<
# 	@set -e; \
# 	rm -f %@; \
# 	$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
# 	sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' < $@.$$$$ > $@; \
# 	rm -f $@.$$$$

# only include the dependency files (and thus restart make)
# if we're not running the clean or check-syntax goal
#
# ifeq (,$(filter clean,$(MAKECMDGOALS)))
#  -include $(DEPS)
# endif

	-rm -f $(OBJS) $(OUT_ELF) $(OUT_BIN) $(OUT_INFO) $(OUT_HEX) $(OUT_MAP) nul *.d.*

M main.S => main.S +12 -14
@@ 6,6 6,12 @@

        .align 2

        .equ LATB,     0xBF860130
        .equ TRISBCLR, 0xBF860114
        .equ ANSELCLR, 0xBF860104
        .equ LATBSET,  0xBF860138
        .equ LATBCLR,  0xBF860134

        .section .reset,code,keep

        .ent _reset


@@ 13,33 19,25 @@ _reset:
        di                      // disable interrupts
        ehb                     // hazard barrier

        la  t1, 0xBF860130      // LATB
        sw  zero, (t1)          // enable gpio port
        sw  zero, (LATB)        // enable gpio port

        li  t3, 0x7
        sll t3, t3, 8           // gpio mask

        la  t1, 0xBF860114      // TRISBCLR
        sw  t3, (t1)            // set output pin direction

        la  t1, 0xBF860104      // ANSELCLR
        sw  t3, (t1)            // enable digital mode

        li  t7, 4000000
        sw  t3, (TRISBCLR)      // set output pin direction
        sw  t3, (ANSELCLR)      // enable digital mode

        li  t0, 0               // load the initial counter value
        la  t4, 0xBF860134      // LATBCLR
        la  t5, 0xBF860138      // LATBSET

1:
        sw    t3, (t4)          // logic low on the gpios
        sw    t3, (LATBCLR)     // logic low on the gpios

        addiu t0, t0, 1         // increment t0, save to t1
        and   t1, t0, 0x7       // mask off the relevant gpios
        sll   t1, t1, 8         // left shift the values
        sw    t1, (t5)          // set the gpios high
        sw    t1, (LATBSET)     // set the gpios high

        move  t6, t7            // load delay
        li   t6, 4000000        // load delay
loop:
        subu t6, t6, 1          // subtract 1
        bnez t6, loop           // if t6 != 0, loop

D main.s => main.s +0 -19
@@ 1,19 0,0 @@
#include <xc.h>

        .set nomips16
        .set nomicromips
        .set noreorder

        .align 2

        .section .reset,code,keep

        .ent _reset
_reset:
        jal _reset
        nop

        .end _reset
        .globl _reset
        .size _reset, .-_reset