Code Monkey home page Code Monkey logo

os161's People

Contributors

jcgibson38 avatar

Watchers

 avatar  avatar

Forkers

trollic

os161's Issues

Implement as_define_region()

The implementation for as_define_region() is located in kern/vm/addrspace.c. The prototype is as followed:

int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz, int readable, int writeable, int executable)

When this function is called, it will:

  1. Allocate one or more page(s) in the coremap to accommodate the size of the new memory region. The pages allocated do not need to be contiguous as they are not kernel pages.
  2. Mark page(s) as allocated, and modify any other fields necessary such as as_vbase, as_voffset, and the permission flags.
  3. Set up corresponding page table entries for each page allocated. (A page table entry contains a pointer to the previous and next entry in the linked list, and a pointer to the corresponding page in the coremap.)

Relevant files:

  • kern/include/addrspace.h
  • kern/arch/mips/vm/vm.c
  • kern/arch/mips/vm/vm.h

Write tests for open() and close()

Testing needs to be done on open() and close() system calls. The test code can be added to user/testbin/f_test/f_test.c. Specifically, we need to check that open() does what we want it to do after passing in different flags (O_APPEND, O_TRUNC, etc).

After making changes, re-compile user binaries:
$ cd src/
$ bmake
$ bmake install

TODO: Get /testbin/forktest & /testbin/fileonlytest working

Need to get /testbin/forktest && /testbin/fileonlytest running and working. Them running properly would be good indicators that stuff is working properly, and then we can move on to swapping.

In ee09d0e you can see that I commented out some code that allocated and initialized the file descriptor table -- we will need to fix that up to get fileonlytest working -- looks like we used kmalloc completely wrong there.

TODO: Mop up existing code.

Basic user program test and coremap test is passing now. Lot's of commented out code in vm.c and addrspace.c to clean up.

Implement as_prepare_load()

The implementation for as_prepare_load() is located in kern/vm/addrspace.c. The prototype is as followed:

int as_prepare_load(struct addrspace *as)

When this function is called, it will:

  1. Walk through the page table and set the permission flags on each page to writable.

This will allow data to be loaded into the address space.

Relevant files:

  • kern/include/addrspace.h
  • kern/arch/mips/vm/vm.c
  • kern/arch/mips/vm/vm.h

Implement vm_fault

The implementation for vm_fault() is located in kern/vm/vm.c. The prototype is as followed:

int vm_fault(int faulttype, vaddr_t faultaddress)

The faultaddress is the address the that the user program tried to access which generated the fault. Each faulttype code is defined below in trapframe.h:

#define EX_MOD    1    /* TLB Modify (write to read-only page) */
#define EX_TLBL   2    /* TLB miss on load */
#define EX_TLBS   3    /* TLB miss on store */

When this function is called, it will:

  1. Walk the user program's page table (curthread->t_addrspace->pages) and find correct page.
  2. Once the correct page is located, the TLB is updated with the appropriate faultaddress ----> (curthread->t_addrspace->pages->entry->page->as_vbase) mapping.

Relevant files

  • kern/arch/mips/locore/trap.c
  • kern/arch/mips/include/trapframe.h
  • kern/include/addrspace.h
  • kern/arch/mips/vm/vm.c
  • kern/arch/mips/vm/vm.h

Implement as_define_stack

The implementation for as_define_stack() is located in kern/vm/addrspace.c. The prototype is as followed:

int as_define_stack(struct addrspace *as, vaddr_t *stackptr)

When this function is called, it will:

  1. Define a new region with a size of 4KB and starting from virtual address [(USERSPACETOP-1) -USER_STACK_SIZE)].
    *Note that USER_STACK_SIZE is a pre-defined macro that will need to be defined. Linux uses 2 MB stack sizes per process by default.
    *Also note that USERSPACETOP is already defined in vm.h, and is the address immediately above the last valid user address. It's value is defined as 0x80000000.
    *Recall that the stack in MIPS starts at 0x7FFFFFFF and grows downwards.
  2. Update the address space's internal data structures which keep track of each defined region accordingly.
  3. Return a pointer to the top of the (initially empty) stack
    stackptr = USERSPACETOP-1

Relevant files:

  • kern/include/addrspace.h
  • kern/arch/mips/vm/vm.c
  • kern/arch/mips/vm/vm.h

Implement as_complete_load()

The implementation for as_complete_load() is located in kern/vm/addrspace.c. The prototype is as followed:

as_complete_load(struct addrspace *as)

When this function is called, it will:

  1. Walk through the page table and set the permission flags on each page accordingly, restoring the state of each page prior to when as_prepare_load() was called.

This will require some sort of book keeping to know whether the page belongs to which segment (data, code, heap, etc.) See comments in #3.

Relevant files:

  • kern/include/addrspace.h
  • kern/arch/mips/vm/vm.c
  • kern/arch/mips/vm/vm.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.