stty -echo -icanon min 1
stty echo icanon
cebrun
in the distribution does that for you. To invoke it, type ./cebrun
app-name
in the cygwin shell (while in the directory
containing the cebrun
script. If app-name is
"quicksort", cebrun
will try to run
quicksort/quicksort.exe. Otherwise, it will try to run tests/app-name.exe.
If the simulator terminates abnormally, you might find that your Cygwin shell seems to have died - what you type doesn't show up. Everything's fine, you just need to type the second command above.
To run with the OS, you need to link your application program
with iolib-os.o
and prologue.o
. To run with the OS you need to build a disk image.
The Cebollita documentation
gives an overview, except that the names of some files have changed. Look in the file Makefile
in directory os
for the slightly modified steps you need.
makefile
's provided. Type make
. That will also launch the Cebollita simulator
with the OS and shell. (You can modify the makefile to change that behavior.)
bootloader.s
is the boot loader. When the machine (or simulator) is powered on,
the hardware loads the first block (512 bytes) of the disk into memory at location 0. The bootloader is
those first bytes on the disk. It (a) moves itself to a higher memory address, and then (b) loads the remainder of the
OS from the disk into memory, starting at location 0 (which is why it has to move itself). The boot loader is not linked
with the OS -- it's a stand-alone program that sets things up to the get the OS going.
The OS is in files trap-handler.s
and os.c
. The former is a small set of routines that need
to be written in assembler. For example, there is a routine to save all the registers on entry into the OS, and another
one to restore them on return from the OS.
os.c
is the bulk of the OS. Once it gets going, it's entered at exceptionHandler()
. Entries into
the OS are not procedure calls -- the OS doesn't do a "return" to go back to the application. Instead,
the trap handler has saved the application's registers on entry. dispatch()
restores them, and sets the PC to
the EPC. Voila, you're back in the application.
The OS has a $gp and $sp, just like anyone else. To preserve them across dispatches of applications, it saves them in memory locations 0 and 4. When control comes back to the OS, the trap handler retrieves them from there, and then the OS can run as normal C code again.
On boot, the OS initializes itself and then launches the first program, a shell. This shell is very primitive. You type a disk
block number and it tries to launch a new process, assuming that the block you gave was the first block of an executable
stored on disk.
(The block numbers are printed in your Cygwin window when you, or the makefile, does a java sim.DiskMake
.)
The makefile loads the disk with three applications: the shell, a helloworld application, and a quicksort application.
(Yes, you can launch a shell process from the shell.) You can terminate a shell's execution by giving a negative number
for the disk block. If it is the original shell, well, the OS crashes. That's intentional.
What you type into the shell is not echo'ed back to you. Ever.