Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile gcc10 & x64 environment #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions 11-kernel-crosscompiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```