Machine Problem 6, due Dec. 8

Part of the homework for CS:2630 (22C:60), Fall 2014
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Background: The Sparrowhawk architecture is a subset of the Hawk architecture; see Section 16 of the Hawk manual for the official details of the subset. All programs that run correctly on the Sparrowhawk run identically on the Hawk, but because the Sparrowhawk does not support any 32-bit instructions, many Hawk programs will give Instruction Trap errors when run on the Sparrowhawk.

A version of the Hawk monitor exists for the Sparrowhawk. If you would have used these commands to link and run a Hawk program under the Hawk monitor:

[yourname@serv15]$ link main.o subroutine.o
[yourname@serv15]$ hawk link.o

you can use these commands to link the same code under the Sparrowhawk monitor and run it on the Sparrowhawk:

[yourname@serv15]$ link -m sparrowmon.o main.o subroutine.o
[yourname@serv15]$ sparrowhawk link.o

Of course, if the code you link contains any 32-bit instructions such as LIL or ADDI, the code will give an Instruction Trap error.

One approach to nearly complete compatibility with the Hawk is a special handler for instruction traps that emulates, in software, the missing instructions. The combination of a physical Sparrowhawk CPU plus a handler that does this creates a virtual Hawk CPU. Such a handler is said to implement the virtual machine. Programs assembled for the Hawk will run correctly on a sparrowhawk that has a virtualizing Hawk instructin trap handler.

The code distributed for mp6.a is a working virtual Hawk trap handler for the Sparrowhawk, except for the part indicated by the comment reading

	; ---- FEWER THAN 100 LINES OF CODE HAVE BEEN DELETED HERE ----

What remains, after the deletions, is a complete working body of code to virtualize the LIL instruction, along with the complete body of code needed to save the complete state of the user program, decode the primary opcode field of the instruction, and restore the state of the user program. For the undefined opcodes that are not virtualized, there is also code to output an appropriate error message.

Assuming you have assembled mp6.a to make mp6.o, and assuming that you have Hawk code in files main.o and subroutine.o, you can link and run that Hawk code with on a Sparrowhawk CPU with:

[yourname@serv15]$ link -m sparrowmon.o mp6.o main.o subroutine.o
[yourname@serv15]$ sparrowhawk link.o

Of course, unless you replace the deleted lines of code, you will get an Instruction Trap error for any 32-bit memory reference instructions.

The Problem: Your job is to write the code to virtualize the memory reference instructions, replacing the comment about deleted code with code to do that job.

Suggestion: All of the 32-bit memory reference instructions on the Hawk begin by computing an effective address. Your code can therefore compute the effective address before it bothers to look at the op1 field of the instruction register (bits 12 to 15) that distinguishes the various memory reference instructions from each other.

Furthermore, individual bits of the instruction register distinguish different instructions by category. This is most obvious if you inspect Appendix B.1.2 of the Hawk manual. For example, bit 15 of the instruction register distinguishes long and short memory reference instructions. Among long instructions, bit 14 distinguishes load instructions, on the one hand, from STORE and JSR. Among load instructions, bit 13 determines whether the instruction will load the effective address or load from memory, and bit 12 determines whether the instruction should change the condition codes. Using this, you can write one relatively compact chunk of code to emulate all of the memory reference instructions instead of having to write separate code to emulate each of them.

Submission: As with MP1, use the on-line Online Coursework Submission tool provided by the Liberal Arts Linux server cluster. Your macros must be in a file named mp6.a (the name is case-sensitive). This is the name you will type in response to the File/directory name prompt. When the submission tool prompts for Course type c_060. Select the assignment directory mp6.

Grading: We will use your code to run a test program that tries all of the different memory reference instructions.

Of course, the format of the solution will be evaluated. Your comments and indenting should match the style of the code for the original, and of course, you must you must take credit for your work in the title and opening comments of the file. Penalties will be assessed for ugly indenting and for sprawling or poorly organized code. Disturbance to code that already works should be minimized. Changes outside the program header and the location of the deleted lines should be avoided.