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.
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.
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
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
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.
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.
getc,
putc, and puts are to be implemented
within the kernel using memory-mapped I/O and spin wait loops.
#### start of added kernel code #####before any new code you add, and place
#### end of added kernel code #####after any new code you add.
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.)
getc, putc, and puts.
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.swhere
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.
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.
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.
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.