Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. protected boolean loadSections() {
  2. if (numPages > Machine.processor().getNumPhysPages()) {
  3. coff.close();
  4. Lib.debug(dbgProcess, "\tinsufficient physical memory");
  5. return false;
  6. }
  7.  
  8. // load sections
  9. for (int s=0; s<coff.getNumSections(); s++) {
  10. CoffSection section = coff.getSection(s);
  11.  
  12. Lib.debug(dbgProcess, "\tinitializing " + section.getName()
  13. + " section (" + section.getLength() + " pages)");
  14.  
  15. for (int i=0; i<section.getLength(); i++) {
  16. int vpn = section.getFirstVPN()+i;
  17.  
  18. // for now, just assume virtual addresses=physical addresses
  19. section.loadPage(i, vpn);
  20. }
  21. }
  22.  
  23. return true;
  24. }
  25.  
  26. /**
  27. * Release any resources allocated by <tt>loadSections()</tt>.
  28. */
  29. protected void unloadSections() {
  30. }
  31.  
  32. /**
  33. * Initialize the processor's registers in preparation for running the
  34. * program loaded into this process. Set the PC register to point at the
  35. * start function, set the stack pointer register to point at the top of
  36. * the stack, set the A0 and A1 registers to argc and argv, respectively,
  37. * and initialize all other registers to 0.
  38. */
  39. public void initRegisters() {
  40. Processor processor = Machine.processor();
  41.  
  42. // by default, everything's 0
  43. for (int i=0; i<processor.numUserRegisters; i++)
  44. processor.writeRegister(i, 0);
  45.  
  46. // initialize PC and SP according
  47. processor.writeRegister(Processor.regPC, initialPC);
  48. processor.writeRegister(Processor.regSP, initialSP);
  49.  
  50. // initialize the first two argument registers to argc and argv
  51. processor.writeRegister(Processor.regA0, argc);
  52. processor.writeRegister(Processor.regA1, argv);
  53. }
  54.  
  55. /**
  56. * Handle the halt() system call.
  57. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement