{"id":34,"date":"2019-01-05T18:43:47","date_gmt":"2019-01-05T18:43:47","guid":{"rendered":"https:\/\/wordpress-courses1819.wolfware.ncsu.edu\/csc501-sprg-2019-y5pdbfc\/?page_id=34"},"modified":"2023-04-04T02:41:30","modified_gmt":"2023-04-04T02:41:30","slug":"pa0","status":"publish","type":"page","link":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/pa0\/","title":{"rendered":"PA0"},"content":{"rendered":"<h2 align=\"center\">CSC 501 Spring 2023<\/h2>\n<h2 align=\"center\">PA 0: Getting Acquainted with XINU<\/h2>\n<h2 align=\"center\">Due: Tuesday January 24, 2023, 11:59 pm<\/h2>\n<h2>1. Objective<\/h2>\n<p>The objective of this introductory lab is to familiarize you with the process of compiling and running XINU, the tools involved, and the run-time environment and segment layout.<\/p>\n<h2>2. Lab Setup Guide<\/h2>\n<p>XINU is a small Unix-like operating system originally developed by Douglas Comer for instructional purposes at Purdue University. It is small enough so that we can understand it entirely within one semester. As part of lab assignment, we will re-implement or improve some apsects of XINU.<\/p>\n<p>Step 1: Setting environment variables for lab assignments:<\/p>\n<p>Get access to a customized VCL image &#8212; X<i>INU+QEMU (CSC501)&nbsp;<\/i>&#8212; through the&nbsp;<a href=\"http:\/\/vcl.ncsu.edu\/\" target=\"_blank\" rel=\"noopener noreferrer\">VCL&nbsp;<\/a>facility<\/p>\n<p>Step 2: Untar the XINU source files as follows:<\/p>\n<ol>\n<li>Change to your home directory, if you are not already in it.<\/li>\n<\/ol>\n<pre><b>cd<\/b><\/pre>\n<p>2. Untar the XINU source by typing the following:<\/p>\n<p>The <strong>csc501-lab0.tgz&nbsp;<\/strong>file is available is available on <a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/mod\/assign\/view.php?id=819783\">moodle<\/a>.<\/p>\n<pre><b>tar xzvf csc501-lab0.tgz<\/b><\/pre>\n<p>In your home directory, you will now have a directory named csc501-lab0. The subdirectories under this directory contain source code, header files, etc, for XINU. NOTE: the tar file name may be different from the above depending on the lab you are working on. Please refer to the lab handouts for the location of the tar file for the current lab.<\/p>\n<p>Step 3: Building XINU<\/p>\n<p>To compile the XINU kernel which will be downloaded and run on the backend machines, run &#8220;make&#8221; in the compile directory as follows:<\/p>\n<pre><b>cd csc501-lab0\/compile\nmake depend<\/b><\/pre>\n<p>e entirely written in x86 assembly. You should not use inline assembly, (i.e., do not use asm(???)). To investigate the assembly code generated by the compiler, you can use the tool objdump -d &lt;___.o&gt; to disassemble an object file. The object files reside in the \/compiledirectory within the main Xinu directory. You can also see some of the *.S files in the \/sys directory for reference.<\/p>\n<pre><b>\nmake\n<\/b>This creates an OS image called 'xinu.elf'.<\/pre>\n<p>If you get a permission denied issue, please go to the <strong>config<\/strong> directory and change permission of <strong>config file<\/strong>, and then compile using the previous commands.<\/p>\n<pre><b>chmod 755 config<\/b><\/pre>\n<p>Step 4: Running and debugging XINU<\/p>\n<p>The XINU image runs on the QEMU emulator machines. To boot up the image, type:<\/p>\n<pre><b>make run<\/b><\/pre>\n<p>XINU should start running and print a message &#8220;Hello World, Xinu lives.&#8221;Typing (&#8220;control-a&#8221;, then &#8220;c&#8221;) will always bring you to &#8216;(qemu)&#8217; prompt. From there, you can quit by typing &#8216;<b>q<\/b>&#8216;<\/p>\n<p>To debug XINU, run the image in the debug mode by:<\/p>\n<pre><b>make debug<\/b><\/pre>\n<p>Then execute GDB in another ssh session:<\/p>\n<pre><b>gdb xinu.elf<\/b><\/pre>\n<p>In the (gdb) console, connect to the remote server by:<\/p>\n<pre><b>target remote localhost:1234<\/b><\/pre>\n<p>You can use many debugging features provided by GDB, e.g., adding a break point at the main function:<\/p>\n<pre><b>b main<\/b><\/pre>\n<p>To run to the next breakpoint, type:<\/p>\n<pre><b>c<\/b><\/pre>\n<p>The detailed document for GDB can be found <a style=\"background-color: #ffffff\" href=\"https:\/\/www.sourceware.org\/gdb\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/p>\n<h2>3. Readings<\/h2>\n<ol>\n<li>The Intel manuals (Volume 1,&nbsp;Volume 2,&nbsp;Volume 3) are available <a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/mod\/assign\/view.php?id=819783\">here<\/a><\/li>\n<li>A brief&nbsp;<a href=\"http:\/\/www.delorie.com\/djgpp\/doc\/ug\/asm\/about-386.html\" target=\"_blank\" rel=\"noopener noreferrer\">guide on the 80386 architecture<\/a>.<\/li>\n<li>AT&amp;T assembly information specific to the gnu assembler is available&nbsp;<a href=\"http:\/\/en.wikibooks.org\/wiki\/X86_Assembly\/GAS_Syntax\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>&nbsp;as a wikibook.<\/li>\n<li>Any man pages\/manuals you discover that you need.<\/li>\n<\/ol>\n<p>Note: The Intel document is hundreds of pages long and there is no need to print it. Please do not print it!<\/p>\n<h2>4. Tasks<\/h2>\n<p>You will be using the&nbsp;<tt>csc501-lab0.tgz<\/tt>&nbsp;you have downloaded and compiled by following the lab setup guide. And you are asked to write several XINU functions that perform the following tasks:<\/p>\n<p>1.&nbsp;<b><tt>long zfunction(long param)<\/tt><\/b><\/p>\n<p>Clear from the 10th to 18th bits (counting left to right, the left most bit is the 0th bit), shift the parameter param by 4 bits to the left, and then fill the right most bits with 0. For example, the input parameter <tt>0xaabbccdd<\/tt>&nbsp;should generate a return value of&nbsp;<tt>0xa800cdd0<\/tt>. You can assume that the size of long is 4 bytes. The code for this function should be entirely written in x86 assembly. You should not use inline assembly, (i.e., do not use&nbsp;<tt>asm(???)<\/tt>). To investigate the assembly code generated by the compiler, you can use the tool&nbsp;<tt>objdump -d &lt;___.o&gt;<\/tt>&nbsp;to disassemble an object file. The object files reside in the&nbsp;<tt>\/compile <\/tt>directory within the main Xinu directory. You can also see some of the *.S files in the&nbsp;<tt>\/sys<\/tt>&nbsp;directory for reference.<\/p>\n<p>(Tips: please check out the 2nd and the 3rd readings above before doing this question.)<\/p>\n<p>2.&nbsp;<b><tt>void printsegaddress()<\/tt><\/b><\/p>\n<p>Print the addresses indicating the end of the text, data, and BSS segments of the Xinu OS. Also print the 4-byte contents (in hexadecimal) preceding and after those addresses. This function can be written in C.<\/p>\n<p>3.&nbsp;<b><tt>void printtos()<\/tt><\/b><\/p>\n<p>Print the address of the top of the run-time stack for whichever process you are currently in, right before and right after you get into the&nbsp;<tt>printtos()<\/tt>&nbsp;function call. In addition, print the contents of upto four stack locations below the top of the stack (the four 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.<\/p>\n<p>4.&nbsp;<b><tt>void printprocstks(int priority)<\/tt><\/b><\/p>\n<p>For each existing process with larger priority than the parameter, print the stack base, stack size, stacklimit, and stack pointer. Also, for each process, include the process name, the process id and the process priority.<\/p>\n<p>To help you do this, please look into&nbsp;<tt>proc.h<\/tt>&nbsp;in the&nbsp;<tt>h\/<\/tt>&nbsp;directory. Note the&nbsp;<tt>proctab[]<\/tt>&nbsp;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&nbsp;<tt>stacktrace.c<\/tt>&nbsp;file in the&nbsp;<tt>sys\/<\/tt>&nbsp;directory. The register&nbsp;<tt>%esp<\/tt>&nbsp;holds the current stack pointer. You can use in-line assembly(i.e.,&nbsp;<tt>asm(\"...\")<\/tt>) to do this part.<\/p>\n<p>5.&nbsp;<b><tt>void printsyscallsummary()<\/tt><\/b><\/p>\n<p>Print the summary of the system calls which have been invoked for each process. This task is loosely based on the functionality of&nbsp;<a href=\"http:\/\/lttng.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">LTTng&nbsp;<\/a>. There are 43 system calls declared. Please look into&nbsp;<tt>kernel.h<\/tt>&nbsp;in the&nbsp;<tt>h\/<\/tt>&nbsp;directory to see all declared system calls. However, only 27 system calls are implemented in this XINU version. The implementation of these 27 system calls are in the&nbsp;<tt>sys\/<\/tt>&nbsp;directory. You are asked to print the frequency (how many times each system call type is invoked) and the average execution time (how long it takes to execute each system call type in average) of these 27 system calls for each process. In order to do this, you will need to modify the implementation of these 27 types of system calls to trace them whenever they are invoked. To measure the time, XINU provides a global variable named&nbsp;<tt>ctr1000<\/tt>&nbsp;to track the time (in milliseconds) passed by since the system starts. Please look into&nbsp;<tt>sys\/clkinit.c<\/tt>&nbsp;and&nbsp;<tt>sys\/clkint.S<\/tt>&nbsp;to see the details.<br \/>\nYou will also need to implement two other functions:<br \/>\n<b><tt>void syscallsummary_start()<\/tt><\/b>: to start tracing the system calls. All the system calls are invoked after calling this function (and before calling&nbsp;<tt>syscallsummary_stop()<\/tt>) will be presented in the system call summary.<br \/>\n<b><tt>void syscallsummary_stop()<\/tt><\/b>: to stop tracing the system calls.<br \/>\nIn other words, these two functions determine the duration in which the system calls are traced.<br \/>\nTo help you complete this task, we provide two files,&nbsp;<a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/pluginfile.php\/1237267\/mod_assign\/introattachment\/0\/syscalls.txt?forcedownload=1\" target=\"_blank\" rel=\"noopener noreferrer\">syscalls.txt<\/a>&nbsp;lists all the system calls you will need to trace, and&nbsp;<a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/pluginfile.php\/1237267\/mod_assign\/introattachment\/0\/test.c?forcedownload=1\" target=\"_blank\" rel=\"noopener noreferrer\">test.c<\/a>&nbsp;demonstrates the usage of the functions you will implement (note that this is only the test file and will not be used for grading).<\/p>\n<p>Implement this lab as a set of functions that can be called from&nbsp;<tt>main()<\/tt>. 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. For example, the file that will hold&nbsp;<tt>void printsegaddress()<\/tt>&nbsp;should be named&nbsp;<tt>printsegaddress.c<\/tt>; and the file that will hold&nbsp;<tt>long zfunction(long param)<\/tt>&nbsp;should be named&nbsp;<tt>zfunction.S<\/tt>. You should put&nbsp;<tt>syscallsummary_start, syscallsummary_stop&nbsp;<\/tt>functions in the same file as&nbsp;<tt>printsyscallsummary&nbsp;<\/tt>function and name it as&nbsp;<tt>printsyscallsummary.c&nbsp;<\/tt>. If you require a header file, please name it&nbsp;<tt>lab0.h<\/tt>. Note: as you create new files, you may need to update the&nbsp;<tt>Makefile<\/tt>&nbsp;(located in the&nbsp;<tt>compile\/<\/tt>directory) to configure it to compile your files correctly. Just look at what is done for the existing files (e.g.,&nbsp;<tt>main.c<\/tt>) to see what you have to do.<\/p>\n<h2>5. Additional Questions<\/h2>\n<p>Write your answers to the following questions in a file named Lab0Answers.txt (in simple text).<\/p>\n<p>Please place this file in the sys\/ directory and turn it in, along with the above programming assignment.<\/p>\n<ol>\n<li>Assuming the XINU text begins at address&nbsp;<tt>0x0<\/tt>, draw a rough diagram of XINU&#8217;s memory layout with addresses derived from your experimental measurements. Include the information you uncovered from running your version of&nbsp;<tt>printsegaddress()<\/tt>&nbsp;and&nbsp;<tt>printprocstks()<\/tt>.<\/li>\n<li>What is the difference in stack top address before and after calling&nbsp;<tt>printtos()<\/tt>&nbsp;? Draw a diagram to illustrate what are the contents of the items pushed into the stack between these two time points.<\/li>\n<li>Which byte order is adopted in the host machine that we are using ? How did you find out ?<\/li>\n<li>Briefly describe the&nbsp;<tt>mov, push, pusha, pop,<\/tt>&nbsp;and&nbsp;<tt>popa<\/tt>&nbsp;instructions in the x86.<\/li>\n<li>In a stack frame, local variables are stored below the top of the stack. In task 3, does your result show all the local variables declared in your&nbsp;<b>printtos<\/b>&nbsp;function? If not, can you explain that? (hint: try to disable the compiler optimization by specifying -O0 in your Makefile)<\/li>\n<\/ol>\n<h2>Turn-in Instructions<\/h2>\n<p>Electronic turn-in instructions:<\/p>\n<ol>\n<li>make sure your output follows the&nbsp;<a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/pluginfile.php\/1237267\/mod_assign\/introattachment\/0\/output_template.txt?forcedownload=1\" target=\"_blank\" rel=\"noopener noreferrer\">output template<\/a>, as mush as possible<\/li>\n<li>go to the&nbsp;<tt>csc501-lab0\/compile<\/tt>&nbsp;directory and do&nbsp;<tt>make clean<\/tt>.<\/li>\n<li>go to the directory of which your&nbsp;<tt>csc501-lab0<\/tt>&nbsp;directory is a subdirectory (NOTE: please do not rename&nbsp;<tt>csc501-lab0<\/tt>, or any of its subdirectories.)e.g., if&nbsp;<tt>\/home\/uid\/csc501-lab0<\/tt>&nbsp;is your directory structure, goto&nbsp;<tt>\/home\/uid\/<\/tt><\/li>\n<li>create a subdirectory TMP (under the directory&nbsp;<tt>csc501-lab0<\/tt>) and copy all the files you have modified\/written, both .c files and .h files into the directory.<\/li>\n<li>compress the&nbsp;<tt>csc501-lab0<\/tt>&nbsp;directory into a tgz file and submit on <a href=\"https:\/\/moodle-courses2223.wolfware.ncsu.edu\/mod\/assign\/view.php?id=819783\">Moodle PA 0<\/a>. Please only upload one tgz file: <tt>tar czf csc501-lab0.tgz csc501-lab0<\/tt><\/li>\n<\/ol>\n<p>You can write code in main.c to test your procedures, but please note that when we test your programs we will replace the&nbsp;<tt>main.c<\/tt>&nbsp;file! Therefore, do not put any functionality in the&nbsp;<tt>main.c<\/tt>&nbsp;file.<\/p>\n<p>Also, ALL debugging output&nbsp;<b>MUST&nbsp;<\/b>be turned off before you submit your code.<\/p>\n<h2>Grading Policy<\/h2>\n<ul>\n<li>(10%) Source code can be compiled and the generated image is bootable. Please note that you will also get 0 point for the second part if your source code can not be compiled or can not generate a bootable image.<\/li>\n<li>(75%) Each task rewards 15 points (losing points on minor problems)<\/li>\n<li>(15%) Each additional question earns 3 points<\/li>\n<\/ul>\n<p><a href=\"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/index\/\" target=\"_blank\" rel=\"noopener noreferrer\">Back to the CSC501 web page<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSC 501 Spring 2023 PA 0: Getting Acquainted with XINU Due: Tuesday January 24, 2023, 11:59 pm 1. Objective The objective of this introductory lab is to familiarize you with the process of compiling and running XINU, the tools involved, and the run-time environment and segment layout. 2. Lab Setup Guide XINU is a small [&hellip;]<\/p>\n","protected":false},"author":2882,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"acf":[],"_links":{"self":[{"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/pages\/34"}],"collection":[{"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/users\/2882"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":11,"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/pages\/34\/revisions"}],"predecessor-version":[{"id":398,"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/pages\/34\/revisions\/398"}],"wp:attachment":[{"href":"https:\/\/wordpress-courses2223.wolfware.ncsu.edu\/csc-501-002-sprg-2023\/wp-json\/wp\/v2\/media?parent=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}