Makefile:: add tags options; vmm.[ch] fix bug in find_vma Function, and update check_vma_struct Funciton from lab3-lab8
This commit is contained in:
		
							parent
							
								
									0f1770031b
								
							
						
					
					
						commit
						0c99c48257
					
				
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -3,3 +3,7 @@ obj/
 | 
				
			|||||||
bin/
 | 
					bin/
 | 
				
			||||||
.gdb.in
 | 
					.gdb.in
 | 
				
			||||||
.qemu.out
 | 
					.qemu.out
 | 
				
			||||||
 | 
					cscope.*
 | 
				
			||||||
 | 
					ncscope.*
 | 
				
			||||||
 | 
					tags
 | 
				
			||||||
 | 
					*swp
 | 
				
			||||||
 | 
				
			|||||||
@ -233,9 +233,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -248,3 +248,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -260,9 +260,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean distclean handin
 | 
					.PHONY: clean distclean handin tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	$(V)$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						$(V)$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
distclean: clean
 | 
					distclean: clean
 | 
				
			||||||
@ -273,3 +273,9 @@ handin: distclean
 | 
				
			|||||||
					| grep -v '/\.git/' | grep -v '/\.svn/' | grep -v "$(HANDIN)"` \
 | 
										| grep -v '/\.git/' | grep -v '/\.svn/' | grep -v "$(HANDIN)"` \
 | 
				
			||||||
					| $(ZIP) > $(HANDIN)
 | 
										| $(ZIP) > $(HANDIN)
 | 
				
			||||||
					
 | 
										
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -254,9 +254,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -269,3 +269,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -80,7 +80,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -181,7 +181,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -195,21 +195,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -258,9 +258,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -273,3 +273,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -81,7 +81,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -180,7 +180,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -194,21 +194,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -306,9 +306,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -321,3 +321,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -270,7 +270,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -284,21 +284,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -306,9 +306,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -321,3 +321,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -270,7 +270,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -284,21 +284,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -306,9 +306,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -321,3 +321,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -270,7 +270,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -284,21 +284,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -11,11 +11,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,10 @@
 | 
				
			|||||||
PROJ	:= 5
 | 
					PROJ	:= 8
 | 
				
			||||||
EMPTY	:=
 | 
					EMPTY	:=
 | 
				
			||||||
SPACE	:= $(EMPTY) $(EMPTY)
 | 
					SPACE	:= $(EMPTY) $(EMPTY)
 | 
				
			||||||
SLASH	:= /
 | 
					SLASH	:= /
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					V       := @
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# try to infer the correct GCCPREFX
 | 
					# try to infer the correct GCCPREFX
 | 
				
			||||||
ifndef GCCPREFIX
 | 
					ifndef GCCPREFIX
 | 
				
			||||||
GCCPREFIX := $(shell if i386-ucore-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
 | 
					GCCPREFIX := $(shell if i386-ucore-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
 | 
				
			||||||
@ -353,9 +355,9 @@ touch:
 | 
				
			|||||||
print-%:
 | 
					print-%:
 | 
				
			||||||
	@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
						@echo $($(shell echo $(patsubst print-%,%,$@) | $(TR) [a-z] [A-Z]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean dist-clean handin packall
 | 
					.PHONY: clean dist-clean handin packall tags
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
	$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)  $(SFSBINS)
 | 
						$(V)$(RM) $(GRADE_GDB_IN) $(GRADE_QEMU_OUT)  $(SFSBINS) cscope* tags
 | 
				
			||||||
	-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
						-$(RM) -r $(OBJDIR) $(BINDIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean: clean
 | 
					dist-clean: clean
 | 
				
			||||||
@ -368,3 +370,9 @@ packall: clean
 | 
				
			|||||||
	@$(RM) -f $(HANDIN)
 | 
						@$(RM) -f $(HANDIN)
 | 
				
			||||||
	@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
						@tar -czf $(HANDIN) `find . -type f -o -type d | grep -v '^\.*$$' | grep -vF '$(HANDIN)'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
						@echo TAGS ALL
 | 
				
			||||||
 | 
						$(V)rm -f cscope.files cscope.in.out cscope.out cscope.po.out tags
 | 
				
			||||||
 | 
						$(V)find . -type f -name "*.[chS]" >cscope.files
 | 
				
			||||||
 | 
						$(V)cscope -bq 
 | 
				
			||||||
 | 
						$(V)ctags -L cscope.files
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ find_vma(struct mm_struct *mm, uintptr_t addr) {
 | 
				
			|||||||
                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
					                list_entry_t *list = &(mm->mmap_list), *le = list;
 | 
				
			||||||
                while ((le = list_next(le)) != list) {
 | 
					                while ((le = list_next(le)) != list) {
 | 
				
			||||||
                    vma = le2vma(le, list_link);
 | 
					                    vma = le2vma(le, list_link);
 | 
				
			||||||
                    if (addr < vma->vm_end) {
 | 
					                    if (vma->vm_start<=addr && addr < vma->vm_end) {
 | 
				
			||||||
                        found = 1;
 | 
					                        found = 1;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -270,7 +270,7 @@ check_vma_struct(void) {
 | 
				
			|||||||
    int step1 = 10, step2 = step1 * 10;
 | 
					    int step1 = 10, step2 = step1 * 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    for (i = step1; i >= 0; i --) {
 | 
					    for (i = step1; i >= 1; i --) {
 | 
				
			||||||
        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
					        struct vma_struct *vma = vma_create(i * 5, i * 5 + 2, 0);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma != NULL);
 | 
				
			||||||
        insert_vma_struct(mm, vma);
 | 
					        insert_vma_struct(mm, vma);
 | 
				
			||||||
@ -284,21 +284,35 @@ check_vma_struct(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
					    list_entry_t *le = list_next(&(mm->mmap_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i <= step2; i ++) {
 | 
					    for (i = 1; i <= step2; i ++) {
 | 
				
			||||||
        assert(le != &(mm->mmap_list));
 | 
					        assert(le != &(mm->mmap_list));
 | 
				
			||||||
        struct vma_struct *mmap = le2vma(le, list_link);
 | 
					        struct vma_struct *mmap = le2vma(le, list_link);
 | 
				
			||||||
        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
					        assert(mmap->vm_start == i * 5 && mmap->vm_end == i * 5 + 2);
 | 
				
			||||||
        le = list_next(le);
 | 
					        le = list_next(le);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; i < 5 * step2 + 2; i ++) {
 | 
					    for (i = 5; i <= 5 * step2; i +=5) {
 | 
				
			||||||
        struct vma_struct *vma = find_vma(mm, i);
 | 
					        struct vma_struct *vma1 = find_vma(mm, i);
 | 
				
			||||||
        assert(vma != NULL);
 | 
					        assert(vma1 != NULL);
 | 
				
			||||||
        int j = i / 5;
 | 
					        struct vma_struct *vma2 = find_vma(mm, i+1);
 | 
				
			||||||
        if (i >= 5 * j + 2) {
 | 
					        assert(vma2 != NULL);
 | 
				
			||||||
            j ++;
 | 
					        struct vma_struct *vma3 = find_vma(mm, i+2);
 | 
				
			||||||
 | 
					        assert(vma3 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma4 = find_vma(mm, i+3);
 | 
				
			||||||
 | 
					        assert(vma4 == NULL);
 | 
				
			||||||
 | 
					        struct vma_struct *vma5 = find_vma(mm, i+4);
 | 
				
			||||||
 | 
					        assert(vma5 == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert(vma1->vm_start == i  && vma1->vm_end == i  + 2);
 | 
				
			||||||
 | 
					        assert(vma2->vm_start == i  && vma2->vm_end == i  + 2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i =4; i>=0; i--) {
 | 
				
			||||||
 | 
					        struct vma_struct *vma_below_5= find_vma(mm,i);
 | 
				
			||||||
 | 
					        if (vma_below_5 != NULL ) {
 | 
				
			||||||
 | 
					           cprintf("vma_below_5: i %x, start %x, end %x\n",i, vma_below_5->vm_start, vma_below_5->vm_end); 
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        assert(vma->vm_start == j * 5 && vma->vm_end == j * 5 + 2);
 | 
					        assert(vma_below_5 == NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mm_destroy(mm);
 | 
					    mm_destroy(mm);
 | 
				
			||||||
 | 
				
			|||||||
@ -11,11 +11,12 @@
 | 
				
			|||||||
//pre define
 | 
					//pre define
 | 
				
			||||||
struct mm_struct;
 | 
					struct mm_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// the virtual continuous memory area(vma)
 | 
					// the virtual continuous memory area(vma), [vm_start, vm_end), 
 | 
				
			||||||
 | 
					// addr belong to a vma means  vma.vm_start<= addr <vma.vm_end 
 | 
				
			||||||
struct vma_struct {
 | 
					struct vma_struct {
 | 
				
			||||||
    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
					    struct mm_struct *vm_mm; // the set of vma using the same PDT 
 | 
				
			||||||
    uintptr_t vm_start;      //    start addr of vma    
 | 
					    uintptr_t vm_start;      // start addr of vma      
 | 
				
			||||||
    uintptr_t vm_end;        // end addr of vma
 | 
					    uintptr_t vm_end;        // end addr of vma, not include the vm_end itself
 | 
				
			||||||
    uint32_t vm_flags;       // flags of vma
 | 
					    uint32_t vm_flags;       // flags of vma
 | 
				
			||||||
    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
					    list_entry_t list_link;  // linear list link which sorted by start addr of vma
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user