Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. MAKEFLAGS += -R -r
  2. SUBDIRS := include test roms fatfs/source
  3. CROSS = ../tools/gnu/bin/riscv32-unknown-elf-
  4. CC = $(CROSS)gcc
  5. LD = $(CROSS)ld
  6. OBJCOPY = $(CROSS)objcopy
  7. AR = $(CROSS)ar
  8. NM = $(CROSS)nm
  9. PERL = perl
  10. INCLUDE = -I. -I./include -I./fatfs/source
  11. include ../riscv-opts.mk
  12. CPPFLAGS = $(INCLUDE) $(riscv_flags)
  13. CFLAGS = $(CPPFLAGS) -W -Wextra
  14. SFLAGS = $(CPPFLAGS) -D__ASSEMBLY__
  15. LDSCRIPT = max80.ild
  16. LDFLAGS = $(CFLAGS) \
  17. -Wl,-Map=$*.map \
  18. -Wl,--gc-sections \
  19. -Wl,--sort-section=alignment \
  20. -Wl,-T,$(LDSCRIPT) \
  21. -Wl,-z,common-page-size=16 \
  22. -Wl,-z,max-page-size=16
  23. gendeps = -MD -MF $(@D)/.$(@F).d -MT $@
  24. # Delete output files on error
  25. .DELETE_ON_ERROR:
  26. # Don't delete intermediate files
  27. .SECONDARY:
  28. genhdrs = iodevs.h irqtable.h
  29. gensrcs =
  30. all: boot.mif dram.hex
  31. # Generate MIF file for 8Kx32 RAM
  32. boot_depth := 8192
  33. boot_width := 32
  34. boot_stride := 1
  35. ROMS := $(wildcard roms/*.rom)
  36. ROMOBJS = $(ROMS:.rom=.o)
  37. max80.elf: head.o dummy.o die.o main.o system.o \
  38. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  39. console.o rtc.o romcopy.o \
  40. sdcard.o diskcache.o \
  41. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  42. memset.o memcpy.o \
  43. runtest.o start_test.o \
  44. $(ROMOBJS) \
  45. testimg.o \
  46. fatfs.a
  47. testimg.elf: head.o dummy.o die.o test/main.o test/system.o \
  48. ioregsa.o irqasm.o irqtable.o spurious_irq.o sbrk.o \
  49. console.o rtc.o romcopy.o \
  50. sdcard.o diskcache.o \
  51. abcmem.o abcio.o abcdisk.o abcrtc.o abcpun80.o \
  52. memset.o memcpy.o \
  53. testdata.o $(ROMOBJS) \
  54. fatfs.a
  55. FATFS_C = $(wildcard fatfs/source/*.c)
  56. FATFS_O = $(FATFS_C:.c=.o)
  57. fatfs.a: $(FATFS_O)
  58. rm -f $@
  59. $(AR) cq $@ $(FATFS_O)
  60. CFLAGS_memset.c := -O2
  61. %.mif: %.bin bin2mif.pl
  62. $(PERL) bin2mif.pl $< $@ $($*_depth) $($*_width) $($*_stride)
  63. %.hex: %.elf
  64. $(OBJCOPY) -O ihex $< $@
  65. %.mem: %.bin
  66. $(BIN2MEM) $< > $@
  67. boot.bin: max80.elf
  68. $(OBJCOPY) -O binary -R '.dram*' $< $@
  69. dram.bin: max80.elf
  70. $(OBJCOPY) -O binary -j '.dram*' $< $@
  71. dram_init.bin: dram.bin max80.elf
  72. dd if=$@ of=$< count=1 bs=
  73. checksum.h: dram.bin checksum.pl
  74. $(PERL) checksum.pl $< $@ \
  75. $$(($$($(NM) -n max80.elf --radix=decimal | \
  76. grep ' R __dram_init_end$$' | \
  77. awk '{ print $$1; }') - (1 << 30)))
  78. testimg.bin: testimg.elf
  79. $(OBJCOPY) -O binary $< $@
  80. testimg.o: testimg.S testimg.bin
  81. %.hex: %.bin
  82. $(OBJCOPY) -I binary -O ihex $< $@
  83. %.elf: $(LDSCRIPT)
  84. $(CC) $(LDFLAGS) -o $@ $(filter-out $(LDSCRIPT),$^)
  85. %.o: %.c | $(genhdrs)
  86. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -c -o $@ $<
  87. %.s: %.c | $(genhdrs)
  88. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -S -o $@ $<
  89. %.i: %.c | $(genhdrs)
  90. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) -E -o $@ $<
  91. %.o: %.S | $(genhdrs)
  92. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -c -o $@ $<
  93. %.s: %.S | $(genhdrs)
  94. $(CC) $(SFLAGS) $(SFLAGS_$<) $(gendeps) -E -o $@ $<
  95. ioregsa.S: ioregs.h ioregsa.pl | $(genhdrs)
  96. $(PERL) ioregsa.pl $< $@
  97. roms/%.o: roms/%.rom rom.S
  98. $(CC) $(SFLAGS) $(SFLAGS_$(F<)) -DNAME='rom_$*' -DFILE='"$<"' \
  99. -c -o $@ rom.S
  100. %.ild: %.ld | $(genhdrs)
  101. $(CC) $(CFLAGS) $(CFLAGS_$<) $(gendeps) \
  102. -x assembler-with-cpp \
  103. -fdollars-in-identifiers \
  104. -C -P -E $< | $(PERL) -pe 's:^(#.*)$$:/* $$1 */:' > $@
  105. iodevs.h: ../iodevs.conf ../tools/iodevs.pl
  106. $(PERL) ../tools/iodevs.pl h $< $@
  107. irqtable.h: ../iodevs.conf ../tools/iodevs.pl
  108. $(PERL) ../tools/iodevs.pl irqh $< $@
  109. clean:
  110. for d in . $(SUBDIRS); do \
  111. rm -f $$d/*.o $$d/*.i $$d/*.s $$d/*.elf $$d/*.bin \
  112. $$d/.*.d $$d/*.ild $$d/*.map; \
  113. done
  114. rm -f $(genhdrs) $(gensrcs)
  115. spotless: clean
  116. rm -f *.mem *.hex *.mif
  117. -include $(patsubst %,%/.*.d,. $(SUBDIRS))