From 968211392d613c12e68baa69321e8be32f487005 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Mon, 20 Oct 2014 23:21:20 +0200 Subject: [PATCH] lesson 14 --- 14-checkpoint/Makefile | 10 +++++----- 14-checkpoint/README.md | 11 ++++++++--- 14-checkpoint/boot/bootsect.bin | Bin 0 -> 512 bytes 14-checkpoint/kernel/kernel.o | Bin 0 -> 1936 bytes 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 14-checkpoint/boot/bootsect.bin create mode 100644 14-checkpoint/kernel/kernel.o diff --git a/14-checkpoint/Makefile b/14-checkpoint/Makefile index 61497ea..2756535 100644 --- a/14-checkpoint/Makefile +++ b/14-checkpoint/Makefile @@ -12,9 +12,13 @@ CFLAGS = -g os-image.bin: boot/bootsect.bin kernel.bin cat $^ > os-image.bin -kernel.bin: kernel.elf +kernel.bin: boot/kernel_entry.o ${OBJ} 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 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 & ${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 %.o: %.c ${HEADERS} ${CC} ${CFLAGS} -ffreestanding -c $< -o $@ diff --git a/14-checkpoint/README.md b/14-checkpoint/README.md index cf31211..56c608f 100644 --- a/14-checkpoint/README.md +++ b/14-checkpoint/README.md @@ -31,8 +31,12 @@ make make install ``` -Check out the Makefile target `make debug`. We can take -advantage of this cool qemu feature. Type `make debug` and, on the gdb shell: +Check out the Makefile target `make debug`. This target uses builds `kernel.elf`, which +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` - 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' - 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 diff --git a/14-checkpoint/boot/bootsect.bin b/14-checkpoint/boot/bootsect.bin new file mode 100644 index 0000000000000000000000000000000000000000..e8d27fbfebf937aaa6263436ba130a44bd615eda GIT binary patch literal 512 zcmb_YK}#D!6n?u6rW$mY3Mo_%Lp^yYL<^;Y$6g986r~qY$mq^Wh}nV33JSYL*h`Yb zA|47Y1#cFl2Zb2aC6Kt6(z58$TXL}su8JP@km(TdANXC~``-8Xc;73fXWcrimoI`j zm#2Wg0FD%X1#u@^Nlt>@TOEjWFI3_i9A>KnJAIM9(;w-Q8~}K?346GF;8vJMVJEJYobJh%iPOytfu8V`RZb)^cHxg_v#iQk-jNz#;_yyW(r1o_8m9MK(Ox#rhuo)N?(5*6 z`X_$FZ~MFs&+!DiiBVgIk+XZ9Vk2iQqC8<1S&|kuMFmozZ1o}K JBh=5^{{et8xw-%V literal 0 HcmV?d00001 diff --git a/14-checkpoint/kernel/kernel.o b/14-checkpoint/kernel/kernel.o new file mode 100644 index 0000000000000000000000000000000000000000..c7cfa2e54c46d6deae1031809589bb0c71a2cbf0 GIT binary patch literal 1936 zcma)7OKTKC5U$?YU88H(JQSnxu!8XcW;T-eHa-&L3lS6oBFH*B+q*ktXGUgbLn4Zb z2#N>sFK+37taVG$dDk5dK%G$ zr94xq*iA#Uf#x57z5X75lW+2RkY7)JIfQnBZUb0b*C1}c@#!(QA0a2$zIWE(hLrQQ-3 zHhW-v9Gs(_7=`#z?#Gz+5#19DG74meNJ-mOEiI(khNmZ5-BvD#_(iWF!NaH%b~<6~ zR8L3Y&3d?0JsrATUj|8BZFxz%Td#)kc+yS6$a6Z?eN*FZTe=H3LoZ0E(e?f1T7s-K zOo*11)onYG-a&O`BfjGWL}zDbk5qPJ#e39(i8gXaK;qUF61V%r==yyA5n91bWM<+6 zrc>pTuR7pIEh1cJ&wtaWXEpE zdbd^cf@TO;ik*5rl8afd6FEUkuA0#C0%;~7KiO{RbNAFV*{(Gs$Ctdo|D#ca@jWW) zaK1m;kH_4x?K)0hGrFYXjWBV$VCVz?D{cZYW)A1zd~F7rjBhXWwZ;h9w}$8jgeE3)5oL1nR4ZiCVJ#Cv3|>J-l}^_)N!amRXOVaMyV zT7VovcPfyK`Cr0%?-%^{pPc%ise3BWBkrNVfpI@srVkP%-jejq+RhRm*iP-|d&F