compile gcc10 & x64 environment

pull/180/head
ppw 4 years ago committed by GitHub
parent 7aff64740e
commit e867d6742d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -74,3 +74,59 @@ collisions with your system's compiler and binutils.
You may want to add the `$PATH` to your `.bashrc`. From now on, on this tutorial, we will explicitly use the prefixes when using
the cross-compiled gcc.
how to compile the project with **GCC V 10.2.0** in x64 environments
---
add CFLAGS & LDFLAGS in Makefile
```
CFLAGS = -ffreestanding -fno-stack-protector -z execstack -m32 -no-pie -fno-pic
LDFLAGS = -melf_i386
```
the Makefile in 14-17
```
C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h)
# Nice syntax for file extension replacement
OBJ = ${C_SOURCES:.c=.o}
CC = gcc
GDB = gdb
CFLAGS = -ffreestanding -fno-stack-protector -z execstack -m32 -no-pie -fno-pic
LDFLAGS= -melf_i386
os-image.bin: boot/bootsect.bin kernel.bin
cat $^ > os-image.bin
kernel.bin: boot/kernel_entry.o ${OBJ}
ld ${LDFLAGS} -o $@ -Ttext 0x1000 $^ --oformat binary
kernel.elf: boot/kernel_entry.o ${OBJ}
ld ${LDFLAGS} -o $@ -Ttext 0x1000 $^
run: os-image.bin
qemu-system-x86_64 -fda os-image.bin
debug: os-image.bin kernel.elf
qemu-system-x86_64 -s -S -fda os-image.bin &
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf" -ex "break *0x7c00" -ex "break main" -ex "c" -ex "c"
%.o: %.asm
nasm $< -f elf -o $@
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} -c $< -o $@
%.bin: %.asm
nasm $< -f bin -o $@
clean:
rm -rf *.bin *.dis *.o os-image.bin *.elf
rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o
```

Loading…
Cancel
Save