mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
lesson 14
This commit is contained in:
parent
4299cf991b
commit
968211392d
@ -12,9 +12,13 @@ CFLAGS = -g
|
|||||||
os-image.bin: boot/bootsect.bin kernel.bin
|
os-image.bin: boot/bootsect.bin kernel.bin
|
||||||
cat $^ > os-image.bin
|
cat $^ > os-image.bin
|
||||||
|
|
||||||
kernel.bin: kernel.elf
|
kernel.bin: boot/kernel_entry.o ${OBJ}
|
||||||
i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
|
i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
|
||||||
|
|
||||||
|
# Used for debugging purposes
|
||||||
|
kernel.elf: boot/kernel_entry.o ${OBJ}
|
||||||
|
i386-elf-ld -o $@ -Ttext 0x1000 $^
|
||||||
|
|
||||||
run: os-image.bin
|
run: os-image.bin
|
||||||
qemu-system-i386 -fda os-image.bin
|
qemu-system-i386 -fda os-image.bin
|
||||||
|
|
||||||
@ -22,10 +26,6 @@ debug: os-image.bin kernel.elf
|
|||||||
qemu-system-i386 -s -fda os-image.bin &
|
qemu-system-i386 -s -fda os-image.bin &
|
||||||
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
|
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
|
||||||
|
|
||||||
# To build the kernel: make all objects first
|
|
||||||
kernel.elf: boot/kernel_entry.o ${OBJ}
|
|
||||||
i386-elf-ld -o $@ -Ttext 0x1000 $^
|
|
||||||
|
|
||||||
# To make an object, always compile from its .c
|
# To make an object, always compile from its .c
|
||||||
%.o: %.c ${HEADERS}
|
%.o: %.c ${HEADERS}
|
||||||
${CC} ${CFLAGS} -ffreestanding -c $< -o $@
|
${CC} ${CFLAGS} -ffreestanding -c $< -o $@
|
||||||
|
@ -31,8 +31,12 @@ make
|
|||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
Check out the Makefile target `make debug`. We can take
|
Check out the Makefile target `make debug`. This target uses builds `kernel.elf`, which
|
||||||
advantage of this cool qemu feature. Type `make debug` and, on the gdb shell:
|
is an object file (not binary) with all the symbols we generated on the kernel, thanks to
|
||||||
|
the `-g` flag on gcc. Please examine it with `xxd` and you'll see some strings. Actually,
|
||||||
|
the correct way to examine the strings in an object file is by `strings kernel.elf`
|
||||||
|
|
||||||
|
We can take advantage of this cool qemu feature. Type `make debug` and, on the gdb shell:
|
||||||
|
|
||||||
- Set up a breakpoint in `kernel.c:main()`: `b main`
|
- Set up a breakpoint in `kernel.c:main()`: `b main`
|
||||||
- Run the OS: `continue`
|
- Run the OS: `continue`
|
||||||
@ -44,7 +48,8 @@ advantage of this cool qemu feature. Type `make debug` and, on the gdb shell:
|
|||||||
- `next` to put there our 'X'
|
- `next` to put there our 'X'
|
||||||
- Let's make sure: `print *video_memory` and look at the qemu screen. It's definitely there.
|
- Let's make sure: `print *video_memory` and look at the qemu screen. It's definitely there.
|
||||||
|
|
||||||
Now is a good time to read some tutorial on `gdb`!
|
Now is a good time to read some tutorial on `gdb` and learn super useful things like `info registers`
|
||||||
|
which will save us a lot of time in the future!
|
||||||
|
|
||||||
|
|
||||||
Strategy
|
Strategy
|
||||||
|
BIN
14-checkpoint/boot/bootsect.bin
Normal file
BIN
14-checkpoint/boot/bootsect.bin
Normal file
Binary file not shown.
BIN
14-checkpoint/kernel/kernel.o
Normal file
BIN
14-checkpoint/kernel/kernel.o
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user