University of Wisconsin Computer Sciences Header Map (repeated with 
textual links if page includes departmental footer) Useful Resources Research at UW-Madison CS Dept UW-Madison CS Undergraduate Program UW-Madison CS Graduate Program UW-Madison CS People Useful Information Current Seminars in the CS Department Search Our Site UW-Madison CS Computer Systems Laboratory UW-Madison Computer Sciences Department Home Page UW-Madison Home Page

Program 4

CS/ECE 354, Fall 2003

Send e-mail questions to Nitin A, nitina@cs.wisc.edu
Due Wednesday, November 19, before 5pm


This program is intended to provide understanding in the areas of I/O implementation, memory-mapped I/O, and spin wait loops (polling). You will first write a user-level program and then integrate it with a kernel that uses spin-wait loops to implement I/O instructions.

User-level Program Statement

Write a MAL program to see give the user a little typing test. The user will type the alphabet twice, with the program identifying errors (location and number) in each of the two runs. After the user is finished with each line of input, the program checks the input, makes a visual display of the errors (see sample runs), and makes a count of the number of errors. The program prints the visual display along with a message that tells the user the number of errors. The program ends after stating whether test number 1 or test number 2 had fewer errors. If the number of errors is the same for both runs, the program states that test number 1 had fewer errors.

A newline character ends each line of the user input. If the user enters more than the 26 characters, have the program read and throw away the extras, counting each extra as an error, but do not show these errors with the carrot character. (This will simplify your implementation.) If the user enters fewer than the 26 characters, count each of the missing characters as an error.

See the sample runs. User input is shown in bold. All other display is generated by the program.

Sample program run 1


Typing test:  Type the string exactly as seen,
followed by the return key when finished.
abcdefghijklmnopqrstuvwxyz
aaadefghijklmnopqrstuvwxyz
 ^^
Number of errors: 2
Repeat the test:
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz

Number of errors: 0
The better score was on test number 2

Sample program run 2


Typing test:  Type the string exactly as seen,
followed by the return key when finished.
abcdefghijklmnopqrstuvwxyz
aaaaa
 ^^^^^^^^^^^^^^^^^^^^^^^^^
Number of errors: 25
Repeat the test:
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzZZZ

Number of errors: 3
The better score was on test number 2

Integrating with the Spin-Wait Kernel

Put this MAL user-level program together with a kernel in which you implement the MAL I/O functions of getc, putc, and puts. This functionality will be implemented using memory-mapped I/O and spin wait loops.

Provided for you is a working kernel. The kernel you will use for this program is in the file:

/p/course/cs354-common/public/bin/spinwait.kernel

Copy the file (to your own directory), and modify your copy. Note that this kernel works, but it is missing the code to do the syscall functions getc, putc, and puts. You will need to add code to this kernel to make these syscall functions work.

The simulator (sim) has a default kernel of its own that it uses. In order to substitute and test your own kernel, you must use a different version of the simulator, called isim. The user interface is exactly the same as sim, but a kernel must be supplied with the user-level program. Note for users of the PC version: you will not be able to use the PC port of the simulator for this assignment. It may look the same, but it does not work the same.

Requirements

  1. Your program must follow the input/output format shown in the sample runs.
  2. Write the user-level program such that it first reads (and stores in an array) the user input. After this, the program checks the input for errors and prints its output. The program is to be organized in this way in order to simplify modifications you will make for Program 5.
  3. For any and all procedures or methods you implement, follow the register usage conventions of the last assignment as given in P3 Conventions.
  4. For the I/O instructions getc, putc, and puts within the user-level program, substitute the MAL/TAL instructions that the simulator uses. When you hand your program in, your user-level program will not have the instructions getc, putc, or puts, but will instead use syscall. The function number (which goes in register $2 before syscall) is given in the textbook on page 262.
  5. Your implementation of the MAL I/O functions of getc, putc, and puts are to be implemented within the kernel using memory-mapped I/O and spin wait loops.
  6. Use symbolic register names (examples: $a0 instead of $4, or $sp instead of $29) for register names.
  7. Your program must be well commented. Also, please include comments within the kernel that identify code you have added. Place
    #### start of added kernel code  #####
    
    before any new code you add, and place
    #### end of added kernel code  #####
    
    after any new code you add.

Recommended Approach

  1. Keep backup copies of each piece of this program.
  2. First produce a working version of the user-level program to do this assignment before going on to the next step. Test this user-level program with sim.
  3. Modify the user-level program so that it uses syscall directly instead of the MAL instructions getc, putc, and puts. Again, test this program using sim. Make and keep a separate copy of this program. (It will be needed to do Program 5.)
  4. Copy the spin wait version of the kernel. Add code to your copy of the kernel to implement getc, putc, and puts.
  5. Do not forget to have the code within the kernel echo keyboard input.
  6. Put this completed kernel together with the user-level program that uses syscall into one file. The kernel must be first within the file. A convenient Unix command to help do this is cat. Use the command as
    cat  kernelp4.s userp4.s > allp4.s
    
    where kernelp4.s is a sample name of your copy of the kernel, userp4.s is a sample name of the user-level program, and allp4.s is a sample name of the resulting file that cat produces. Test this code using isim.

Hints

  1. Our definition of the getc instruction includes keyboard echo. Besides getting a character from the keyboard, the character is also displayed. Do not forget to have getc echo the character.
  2. For Program 3, you wrote a procedure called print_integer. You will want to reuse that code in this program to print out the number of errors. If your own solution did not work, you may use the procedure as given in the posted solution. Make sure to include a proper citation. This includes the name of the person that wrote the solution and where this code was copied from.

Handing In the Program

Turn in your combined kernel and user-level MAL program by running the script:

    handinP4 program4.s

where program4.s is an example name of the file containing the program. The handinP4 script submits your program for you. No printout will be turned in.