You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

  1. #
  2. # This file is part of the Rufus project.
  3. #
  4. # Copyright (c) 2012-2022 Pete Batard <pete@akeo.ie>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation, either version 3 of
  9. # the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. #
  19. TEST_TARGET = msg
  20. ASM = gcc
  21. CC = gcc
  22. LD = ld
  23. OBJDUMP = objdump
  24. OBJCOPY = objcopy
  25. CFLAGS = -m32 -nostartfiles -nodefaultlibs
  26. BOCHS = "C:/Program Files/Bochs/bochsdbg.exe"
  27. .PHONY: all clean
  28. all: mbr.bin msg.bin
  29. clean:
  30. @-rm -f -v *.o *.out *.map *.bin *.img *.ini
  31. %.o: %.c Makefile
  32. @echo "[CC] $@"
  33. @$(CC) -c -o $*.o $(CFLAGS) $<
  34. %.o: %.S Makefile
  35. @echo "[AS] $<"
  36. @$(ASM) -c -o $*.o $(CFLAGS) $<
  37. # Produce a disassembly dump, for verification purposes
  38. dis: $(TEST_TARGET).out
  39. @echo "[DIS] $<"
  40. @$(OBJCOPY) -O binary -j .main --set-section-flags .main=alloc,load,readonly,code $< main.bin
  41. @$(OBJDUMP) -D -bbinary -mi8086 -Mintel main.bin | less
  42. @-rm -f main.bin
  43. # Run the MBR in a Bochs environment (append msg.txt in subsequent blocks)
  44. test: $(TEST_TARGET).bin
  45. @test -s $(BOCHS) || { echo "Error: $(BOCHS) was not found on this system"; exit 1; }
  46. @cp $(TEST_TARGET).bin disk.img
  47. @truncate -c -s 17K disk.img
  48. @cat msg.txt >> disk.img
  49. @truncate -c -s 10M disk.img
  50. @-$(BOCHS) -f bochsrc.bxrc -q
  51. %.out: %.o mbr.ld
  52. @echo "[LD] $@"
  53. @$(LD) $(LDFLAGS) -Tmbr.ld -o $@ $< -Map $*.map
  54. %.bin: %.out
  55. @echo "[MBR] $@"
  56. @# Note: -j only works for sections that have the 'ALLOC' flag set
  57. @$(OBJCOPY) -O binary -j .main --gap-fill=0x00 $< $@
  58. @-rm -f $< $*.map