addrspace.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _ADDRSPACE_H_
  30. #define _ADDRSPACE_H_
  31. /*
  32. * Address space structure and operations.
  33. */
  34. #include <vm.h>
  35. struct vnode;
  36. /*
  37. * Address space - data structure associated with the virtual memory
  38. * space of a process.
  39. *
  40. * You write this.
  41. */
  42. // section is 0 for code, 1 for data, 2 for stack
  43. // pageStart is the vaddr_t where this page starts
  44. // frame is the frame # this maps to
  45. struct pte
  46. {
  47. int section;
  48. vaddr_t pageStart;
  49. int frame;
  50. };
  51. struct addrspace
  52. {
  53. bool loading;
  54. int regions;
  55. struct pte * pt;
  56. int pages;
  57. };
  58. /*
  59. * Functions in addrspace.c:
  60. *
  61. * as_create - create a new empty address space. You need to make
  62. * sure this gets called in justify the means constructall the right places. You
  63. * may find you want to change the argument list. May
  64. * return NULL on out-of-memory error.
  65. *
  66. * as_copy - create a new address space that is an exact copy of
  67. * an old one. Probably calls as_create to get a new
  68. * empty address space and fill it in, but that's up to
  69. * you.
  70. *
  71. * as_activate - make curproc's address space the one currently
  72. * "seen" by the processor.
  73. *
  74. * as_deactivate - unload curproc's address space so it isn't
  75. * currently "seen" by the processor.
  76. *
  77. * as_destroy - dispose of an address space. You may need to change
  78. * the way this works if implementing user-level threads.
  79. *
  80. * as_define_region - set up a region of memory within the address
  81. * space.
  82. *
  83. * as_prepare_load - this is called before actually loading from an
  84. * executable into the address space.
  85. *
  86. * as_complete_load - this is called when loading from an executable
  87. * is complete.
  88. *
  89. * as_define_stack - set up the stack region in the address space.
  90. * (Normally called *after* as_complete_load().) Hands
  91. * back the initial stack pointer for the new process.
  92. */
  93. struct addrspace *as_create(void);
  94. int as_copy(struct addrspace *src, struct addrspace **ret);
  95. void as_activate(void);
  96. void as_deactivate(void);
  97. void as_destroy(struct addrspace *);
  98. int as_define_region(struct addrspace *as,
  99. vaddr_t vaddr, size_t sz,
  100. int readable,
  101. int writeable,
  102. int executable);
  103. int as_prepare_load(struct addrspace *as);
  104. int as_complete_load(struct addrspace *as);
  105. int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
  106. /*
  107. * Functions in loadelf.c
  108. * load_elf - load an ELF user program executable into the current
  109. * address space. Returns the entry point (initial PC)
  110. * in the space pointed to by ENTRYPOINT.
  111. */
  112. int load_elf(struct vnode *v, vaddr_t *entrypoint);
  113. #endif /* _ADDRSPACE_H_ */