=====================================
 LC3-project-3.html
=====================================
=====================================
 LC3 micro-OS Project, Part 3
=====================================

DESCRIPTION

Debug a more-or-less complete LC3 micro-OS. You are provided with two
source files: os-2.c and asm-utils-2.asm (and asm-utils.h).
The input trap, TRAP x20 (input_trap), has been implemented, as have
assembly routines for calling a user program and the user program
exit trap, TRAP x25. There is also a shutdown() routine.

With traps x20 (input_trap), x21 (printc_trap), and x22 (prints_trap)
implemented, the main OS can be written using printf() and scanf().
These are standard input/output C library routines. (They are in
lcc-1.3/lc3lib). The main program for the OS has a command loop that 
uses printf() and scanf(). 

User programs can also use standard I/O, and do not need to be written
in assembly at all. The user program, prog.c, just prints "Hello World"
using printf().

WHAT TO DO

You will find that the assembly routines input_trap, call_user, and 
exit_trap have bugs. Read the source code to see what the
OS does. Look at the assembly code for the buggy routines, but do
not attempt to fix them until you have used PennSim to see how they
act now.

Use the C-linking/Makefile to build os.obj and prog.obj. You will
want to either rewrite the Makefile so it uses the new sources,
os-2.c and asm-utils-2.asm, or rename these files. After building
the object files, load them into PennSim.

Provide an input file, e.g., in.txt, which contains characters for
the command loop to read. There are three commands defined: "r",
run user program, "h", print a help message, and "q", shutdown
the machine. Any other characters will be "unknown commands".
Scanf() echoes the input, as well as consuming any context characters
shown in its format argument. This may be confusing. If so, you
can replace scanf() and printf() and use do_input_trap() and
do_prints_trap() instead.

Put a breakpoint on the code line for the label "lc3_printf". It
is pretty far down. Click on a memory line and use your down-arrow
to scroll down. Do not put a breakpoint on the line for the label
"printf". That is a pointer variable in the global data area. 

Type "input" into PennSim's command window (just under the "NEXT"
button). Follow that with the name of your text input file.

Use the "CONTINUE" button to step through the program. You can add
breakpoints at other places as you zero in on what the bugs are.

WARNINGS

The compiler, lcc and the assembler, lc3as, have problems, I've
found. They can be very confusing if you stray from the formats
I've given you. For that reason, I had not given you much to do
in terms of writing your own code. However, it is interesting to
watch the stack grow without bound because of a bug in allocating
and popping call frames. You can see this as it overwrites the
memory-mapped video area above xFE00. It appears in the large
blackened window in PennSim as colored pixels as values get written
to the video memory.

WHAT TO TURN IN

Turn in a cover sheet, as usual. Check in your work as you modify
the source codes. Report your findings, problems, difficulties,
obstacles, and so forth, whether or not you were able to solve
them.