Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
  2. HEADERS = $(wildcard kernel/*.h drivers/*.h)
  3. # Nice syntax for file extension replacement
  4. OBJ = ${C_SOURCES:.c=.o}
  5.  
  6. # Change this if your cross-compiler is somewhere else
  7. CC = gcc
  8. GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
  9. # -g: Use debugging symbols in gcc
  10. CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -std=gnu99
  11. # First rule is run by default
  12. os-image.bin: boot/boot.bin kernel.bin
  13. cat $^ > os-image.bin
  14.  
  15. # '--oformat binary' deletes all symbols as a collateral, so we don't need
  16. # to 'strip' them manually on this case
  17. kernel.bin: kernel/kernel.o ${OBJ}
  18. ld -melf_i386 -o $@ -T link.ld $^ --oformat binary
  19.  
  20. # Used for debugging purposes
  21. kernel.elf: kernel/kernel.o ${OBJ}
  22. ld -o $@ -Ttext 0x1000 $^
  23.  
  24. run: os-image.bin
  25. qemu-system-i386 -fda os-image.bin
  26.  
  27. # Open the connection to qemu and load our kernel-object file with symbols
  28. debug: os-image.bin kernel.elf
  29. qemu-system-i386 -s -fda os-image.bin &
  30. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
  31.  
  32. # Generic rules for wildcards
  33. # To make an object, always compile from its .c
  34. %.o: %.c ${HEADERS}
  35. ${CC} ${CFLAGS} -ffreestanding -c $< -o $@
  36.  
  37. %.o: %.asm
  38. nasm $< -f elf -o $@
  39.  
  40. %.bin: %.asm
  41. nasm $< -f bin -o $@
  42.  
  43. clean:
  44. rm -rf *.bin *.dis os-image.bin *.elf
  45. rm -rf boot/*.bin drivers/*.o boot/*.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement