CS 503 Fall 2009

Lab 0: Getting Acquainted with XINU (110 pts)

Due: Friday 09/11/09, 11:59 PM

1. Objectives

The objectives of this introductory lab are to familiarize you with the process of compiling and running XINU, the tools involved, and the run-time environment and segment layout.

2. Readings

  1. XINU Setup handout
  2. Chapters 1, 2, 4 and 8 in the XINU book, particularly the section entitled The C Runtime Environment in Chapter 2, and Section 4.1.
  3. The Intel manuals which are available on the class web page or the main lab web page, as well as on the Intel web site.
  4. AT&T assembly information linked through the class web page or the main lab web page.
  5. Any man pages/manuals you discover that you need.
Note: The Intel document is hundreds of pages long and there is no need to print it. Please do not print it. You will be penalized if the systems staff informs us that anyone has printed the entire document. You will be asked to answer some questions from this in this lab, and you will need it in some later labs.

3. What to do [80 pts]

You have to write XINU functions that perform the following:

    1. long host2netl_asm (long param)
          Convert the parameter param from host byte order to network byte order (always Big Endian).  The code for this function should be entirely written in x86 assembly. You should not use in-line assembly (i.e., do not  use asm("...")).  You can assume that the size of long is 4 bytes and the byte order of the host machine is Little Endian.  To investigate the assembly code generated by the compiler, you can use the tool objdump -d <___.o> to disassemble an object file.  The object files reside in the /compile directory within the main Xinu directory (xinu-fall2009). You can also see some of the *.S files in the /sys directory for reference.

    2.  void printsegaddress()
          Print the address of the end of the text, data, and bss segments of the Xinu OS. Also print the 4 bytes (in hexadecimal) preceding the end of the three segment boundaries, and similarly for the 4 bytes following the segment boundaries. This function can be written in C.

    3.   void printtos()
           Print the address of the top of the run-time stack for whichever process you are currently in.  In addition, print the contents of up to five stack locations at and below the top of the stack (the five or fewer items that have been the most recently pushed, if any). Remember that stack elements are 32 bits wide, and be careful to perform pointer arithmetic correctly.  Also note that there are local variables and arguments on the stack, among other things. See the hints given for #4 below, especially on stacktrace.c and proc.h. Your function can be written entirely in C, or you can use in-line assembly if you prefer.

    4.   void printprocstks()
            For each existing process, print the stack base, stack size, stack limit, and stack pointer. Also, for each process, include the process name and the process id. An example output might look something like:

        Proc [prnull]. Pid = 0.
            Stack: Base  = 4095996
                       Len   = 0
                       Limit = 4091904
                       StkPtr  = 4095820

        Proc [main]. Pid = 49.
            Stack: Base  = 4091896
                       Len   = 4096
                       Limit = 4087804
                       StkPtr  = 4091872

        To help you do this, please look into proc.h in the h/ directory.  Note the proctab[] array that holds all processes. Also, note that the pesp member of the pentry structure holds the saved stack pointer.  Therefore, the currently executing process has a stack pointer that is different from the value of this variable.  In order to help you get the stack pointer of the currently executing process, carefully study the stacktrace.c file in the sys/directory.  The register %esp holds the current stack pointer.  You can use in-line assembly (i.e., asm("...")) to do this part.
 

    Implement this lab as a set of functions that can be called from main().  Each function should reside in a separate file in the sys directory, and should be incorporated into the Makefile.  The files should be named after the functions they are implementing with C files having the .c extension and the assembly files having the .S extension.  So, for example, the file that will hold void printsegaddress() should be named printsegaddress.c; and the file that will hold long host2netl_asm(long param) should be named host2netl_asm.S.  If you require a header file, please name it lab0.h.  Note: As you create new files, you may need to update the Makefile (located in the compile/ directory) to configure it to compile your files correctly. Just look at what is done for the existing files (e.g., main.c) to determine what you have to do.


4. Additional Questions [30 pts]

      Write your answers to the following questions in a file named Lab0Answers.txt (if simple text), Lab0Answers.ps (if Postscript, e.g., generated from LaTeX/dvips), or Lab0Answers.pdf (for PDF output). Please place this file in the sys/ directory and turn it in, along with the above programming assignment.
  1. Assuming the XINU text begins at address 0x0, draw a diagram of XINU's memory layout with addresses derived from your experimental measurements.  Include the information you uncovered from running your version of printsegaddress() and printprocstks().
  2. Draw a layout of the stack for a user process based on your measurements. Show the relative locations of local variables and arguments. If you found other information about the stack, include it in the diagram. What other items might be found on a stack that are not included in your diagram?  Include the information you uncovered from running your version of printtos().
  3. Describe the mov, push, pusha, pop, and popa instructions in x86.

Turn-in Instructions

Electronic turn-in instructions:

        i) go to the xinu-fall2009/compile directory and do "make clean".

        ii) go to the directory of which your xinu-fall2009 directory is a subdirectory (NOTE: please do not rename xinu-fall2009, or any of its subdirectories.)

                e.g., if /homes/jsr/xinu-fall2009 is your directory structure, goto /homes/jsr

        iii) type in the following command

                turnin -c cs503 -p lab0 xinu-fall2009

You can write code in main.c to test your procedures, but please note that when we test your programs we will replace the main.c file! Therefore, do not put any functionality in the main.c file.

Also, ALL debugging output should be turned off before you submit your code.


Back to the CS 503 web page