From dfd32786f9edfb244e4ece0afeb5a4ebe1e3daaa Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 8 Jan 2014 21:34:01 +0100 Subject: [PATCH] Fix bugs --- Makefile | 9 +++++---- cpp.mk | 2 +- gdb_bochsrc.txt | 5 +++++ kernel/Makefile | 2 +- kernel/src/memory.cpp | 20 +++++--------------- programs/one/a.out | Bin 941 -> 0 bytes 6 files changed, 17 insertions(+), 21 deletions(-) create mode 100644 gdb_bochsrc.txt delete mode 100755 programs/one/a.out diff --git a/Makefile b/Makefile index addd2a64..c0faf7cf 100644 --- a/Makefile +++ b/Makefile @@ -34,15 +34,16 @@ qemu: default qemu-kvm -cpu host -hda hdd.img bochs: default - echo "c" > commands - bochs -qf bochsrc.txt -rc commands - rm commands + bochs -qf bochsrc.txt debug: default echo "c" > commands bochs -qf debug_bochsrc.txt -rc commands rm commands +gdb: default + bochs -qf gdb_bochsrc.txt + force_look: true @@ -51,4 +52,4 @@ clean: cd kernel; $(MAKE) clean cd programs/one; $(MAKE) clean rm -f *.bin - rm -f *.flp \ No newline at end of file + rm -f *.flp diff --git a/cpp.mk b/cpp.mk index 489dacc3..ed2ab51f 100644 --- a/cpp.mk +++ b/cpp.mk @@ -3,7 +3,7 @@ AS=x86_64-elf-as OC=x86_64-elf-objcopy WARNING_FLAGS=-Wall -Wextra -pedantic -Wold-style-cast -Wshadow -COMMON_CPP_FLAGS=-masm=intel -Iinclude/ -nostdlib -Os -std=c++11 -fno-stack-protector -fno-exceptions -funsigned-char -fno-rtti -ffreestanding -fomit-frame-pointer -mno-red-zone -mno-3dnow -mno-mmx -fno-asynchronous-unwind-tables +COMMON_CPP_FLAGS=-masm=intel -Iinclude/ -nostdlib -g -Os -std=c++11 -fno-stack-protector -fno-exceptions -funsigned-char -fno-rtti -ffreestanding -fomit-frame-pointer -mno-red-zone -mno-3dnow -mno-mmx -fno-asynchronous-unwind-tables CPP_FLAGS_LOW=-march=i386 -m32 -fno-strict-aliasing -fno-pic -fno-toplevel-reorder -mno-sse -mno-sse2 -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 diff --git a/gdb_bochsrc.txt b/gdb_bochsrc.txt new file mode 100644 index 00000000..2a1859c3 --- /dev/null +++ b/gdb_bochsrc.txt @@ -0,0 +1,5 @@ +display_library: sdl +magic_break: enabled=1 +gdbstub: enabled=1, port=1234 +ata0-master: type=disk, path="hdd.img", mode=flat, cylinders=1000, heads=16, spt=63 +boot: disk diff --git a/kernel/Makefile b/kernel/Makefile index e74b334d..c9c25aed 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -52,7 +52,7 @@ src/stl/%.cpp.o: kernel.bin: $(LINK_O_FILES) $(CC) $(KERNEL_LINK_FLAGS) $(CPP_FLAGS_64) -o kernel.bin.o $(LINK_O_FILES) - $(OC) -R .note -R .comment -S -O binary kernel.bin.o kernel.bin + $(OC) -R .note -R .comment -O binary --set-section-flags .bss=alloc,load,contents kernel.bin.o kernel.bin debug: echo $(KERNEL_CPP_STL_FILES) diff --git a/kernel/src/memory.cpp b/kernel/src/memory.cpp index 9397ae53..8ba8bc77 100644 --- a/kernel/src/memory.cpp +++ b/kernel/src/memory.cpp @@ -10,7 +10,7 @@ #include "paging.hpp" #include "e820.hpp" -namespace { +namespace debugging { //Used to compile with malloc operations in the console //can produce a lot of output @@ -98,8 +98,8 @@ static_assert(MIN_SPLIT == aligned_size(MIN_SPLIT), "The size of minimum split m fake_head head; malloc_header_chunk* malloc_head = 0; -const e820::mmapentry* current_mmap_entry = nullptr; -uintptr_t current_mmap_entry_position; +const e820::mmapentry* current_mmap_entry = 0; +uintptr_t current_mmap_entry_position = 0; //All allocated memory is in [min_address, max_address[ uintptr_t min_address; //Address of the first block being allocated @@ -120,16 +120,10 @@ uint64_t* allocate_block(uint64_t blocks){ } } - asm volatile("xchg bx, bx"); - - if(!current_mmap_entry){ return nullptr; } - - - auto block = reinterpret_cast(current_mmap_entry_position); paging::identity_map(block, blocks); @@ -212,28 +206,24 @@ void init_head(){ } void expand_heap(malloc_header_chunk* current){ - asm volatile("xchg bx, bx"); - //Allocate a new block of memory uint64_t* block = allocate_block(MIN_BLOCKS); //Transform it into a malloc chunk auto header = reinterpret_cast(block); - asm volatile("xchg bx, bx"); - //Update the sizes header->size() = MIN_BLOCKS * BLOCK_SIZE - META_SIZE; header->footer()->size() = header->size(); - asm volatile("xchg bx, bx"); - //Insert the new block into the free list insert_after(current, header); } } //end of anonymous namespace +using namespace debugging; + void init_memory_manager(){ //Init the fake head init_head(); diff --git a/programs/one/a.out b/programs/one/a.out deleted file mode 100755 index 52437f3f14da512041100547b646d89ef84549f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcmbV~zfJ-{5XJ{M3HT?dm5GH|kf_B435l z6IfbHD0~G=9sxT$+}WEk2f0|d$?doEn{RgacK80^_%IrY0JkXY0Y+^w6!Lq3PZjx{ z0R`zXAPzC*oeAWC>R5Y}V+BYna`~ZUo*w2Pm&&~lQfpvzNByCe{2n}xjMUq>KTODR zsaV`eZl|B=Mbl2K94rV z8B!LF2c+v#u|7M+`5cy}IC`B;`567 z_p>N@56VP**_DER-sb{k_oasUkBGla%>#~g-O%k;3(SjL*0FACrro@4y7fAOyaIPu dmMPz?+p#4yE1qY1!g7Tw1+!MQge9d>g&)gjQ>Xv{