5.2 Loading COFF binaries

COFF (Common Object File Format) binaries contain a lot of information, but very little of it is actually relevent to Nachos programs. Further, Nachos provides a COFF loader class, nachos.machine.Coff, that abstracts away most of the details. But a few details are still important. A COFF binary is broken into one or more sections. A section is a contiguous chunk of virtual memory, all the bytes of which have similar attributes (code vs. data, read-only vs. read-write, initialized vs. uninitialized).

Nachos classes that are needed to handle user program are mostly reside in nachos.userprog. To support multi-programming, UserKernel extends ThreadedKernel. When kernel.run() is called in Autograder.run(), Nachos creates a process and execute the shell program specified by the “-x” argument or in the config file. This is done by first loading the program into the process’ address space, at some start address specified by the section (Line 2). A COFF binary also specifies an initial value for the PC register and the stack pointer. Both values will be stored within the UserProcess object. Lastly, a user thread (nachos.userprog.UThread) is created and put in the ready queue (Line 5).

1   public boolean nachos.userprog.UserProcess.execute(String name, String[] args) {
2   if (!load(name, args))
3   return false;
4  
5   new UThread(this).setName(name).fork();
6  
7   return true;
8   }