init: init nachos hw01, should pass jenkins os_group_20_hw job but fail on os_group_20_ta job
This commit is contained in:
BIN
code/test/DISK_0
Normal file
BIN
code/test/DISK_0
Normal file
Binary file not shown.
203
code/test/Makefile
Normal file
203
code/test/Makefile
Normal file
@@ -0,0 +1,203 @@
|
||||
#
|
||||
# Makefile for building user programs to run on top of Nachos
|
||||
#
|
||||
# Use "make" to build the test executable(s)
|
||||
# Use "make clean" to remove .o files and .coff files
|
||||
# Use "make distclean" to remove all files produced by make, including
|
||||
# the test executables
|
||||
#
|
||||
# This is a GNU Makefile. It must be used with the GNU make program.
|
||||
# At UW, the GNU make program is /software/gnu/bin/make.
|
||||
# In many other places it is known as "gmake".
|
||||
# You may wish to include /software/gnu/bin/ early in your command
|
||||
# search path, so that you will be using GNU make when you type "make".
|
||||
#
|
||||
# Several things to be aware of:
|
||||
#
|
||||
# It should not be necessary to build the test executables for
|
||||
# every type of host machine on which Nachos runs. You should
|
||||
# be able to build them once, and then use them regardless of
|
||||
# the host machine type. That is because the test executables
|
||||
# run on the simulated MIPS machine, and not on the host.
|
||||
#
|
||||
# However:
|
||||
# (1) if you are experiencing problems with the test executables,
|
||||
# it would be prudent to rebuild them on the host machine
|
||||
# on which you are currently running Nachos. To do this,
|
||||
# just type "make distclean", and then "make"
|
||||
#
|
||||
# (2) the procedure used to build the test executables does
|
||||
# depend on the host machine you are on. All of the machine
|
||||
# dependencies are isolated in the Makefile.dep file.
|
||||
# It should be possible to build the test executables on
|
||||
# any MFCF machine. In the MFCF environment, this makefile
|
||||
# should automatically figure out what type of host you are
|
||||
# on, and should use the appropriate procedure.
|
||||
# However, if you are working outside the MFCF environment,
|
||||
# you will need to build a cross-compiler, build coff2noff,
|
||||
# and edit Makefile.dep in this directory before you
|
||||
# can build the test programs.
|
||||
#
|
||||
# Nachos assumes that the location of the program startup routine (the
|
||||
# location the kernel jumps to when the program initially starts up)
|
||||
# is at location 0. This means: start.o must be the first .o passed
|
||||
# to ld, in order for the routine "Start" to be loaded at location 0
|
||||
#
|
||||
# When you make the test programs, you will see messages like these:
|
||||
# numsections 3
|
||||
# Loading 3 sections:
|
||||
# ".text", filepos 0xd0, mempos 0x0, size 0x440
|
||||
# ".data", filepos 0x510, mempos 0x440, size 0x0
|
||||
# ".bss", filepos 0x0, mempos 0x440, size 0x12c0
|
||||
# These messages are normal. They come from the coff2noff program.
|
||||
# They are useful in that they tell you how big the various parts of your
|
||||
# compiled user program are, and where in the address space
|
||||
# coff2noff is going to place them. This information is also
|
||||
# recorded in the header of the executable file that coff2noff
|
||||
# creates. See the method AddrSpace::Load (in userprog/addrspace.cc)
|
||||
# for an example of how this header is used by the Nachos OS to set up the
|
||||
# address space for a new process that will run the executable.
|
||||
#
|
||||
#
|
||||
# Adding New Test Programs:
|
||||
#
|
||||
# You are free to write new test programs, and to modify the
|
||||
# existing programs. If you write a new program, you will
|
||||
# need to modify this makefile so that the new program will
|
||||
# get built.
|
||||
# You will need to make the following changes for each program
|
||||
# you add:
|
||||
# (1) add the program's name to PROGRAMS variable definition
|
||||
# (2) add dependencies and build commands for the new
|
||||
# program. The easiest way to do this is to
|
||||
# copy the dependencies and commands for an
|
||||
# existing program, and then change the names.
|
||||
#
|
||||
# For example, if you write a test program in foo.c, for which
|
||||
# the executable is to be called foo, you should do the following:
|
||||
#
|
||||
# change the PROGRAMS definition to look like this:
|
||||
#
|
||||
# PROGRAMS = halt shell matmult sort foo
|
||||
#
|
||||
# add these dependencies/commands:
|
||||
#
|
||||
# foo.o: foo.c
|
||||
# $(CC) $(CFLAGS) -c foo.c
|
||||
# foo: foo.o start.o
|
||||
# $(LD) $(LDFLAGS) start.o foo.o -o foo.coff
|
||||
# $(COFF2NOFF) foo.coff foo
|
||||
#
|
||||
# Be careful when you copy the commands! The commands
|
||||
# must be indented with a *TAB*, not a bunch of spaces.
|
||||
#
|
||||
#
|
||||
#############################################################################
|
||||
# Makefile.dep contains all machine-dependent definitions
|
||||
# If you are trying to build coff2noff somewhere outside
|
||||
# of the MFCF environment, you will almost certainly want
|
||||
# to visit and edit Makefile.dep before doing so
|
||||
#############################################################################
|
||||
|
||||
include Makefile.dep
|
||||
|
||||
CC = $(GCCDIR)gcc
|
||||
AS = $(GCCDIR)as
|
||||
LD = $(GCCDIR)ld
|
||||
|
||||
INCDIR =-I../userprog -I../lib
|
||||
CFLAGS = -G 0 -c $(INCDIR) -B../../usr/local/nachos/lib/gcc-lib/decstation-ultrix/2.95.2/ -B../../usr/local/nachos/decstation-ultrix/bin/
|
||||
|
||||
ifeq ($(hosttype),unknown)
|
||||
PROGRAMS = unknownhost
|
||||
else
|
||||
# change this if you create a new test program!
|
||||
# PROGRAMS = add halt consoleIO_test1 consoleIO_test2 fileIO_test1 fileIO_test2
|
||||
PROGRAMS = halt
|
||||
endif
|
||||
|
||||
all: $(PROGRAMS)
|
||||
|
||||
start.o: start.S ../userprog/syscall.h
|
||||
$(CC) $(CFLAGS) $(ASFLAGS) -c start.S
|
||||
|
||||
halt.o: halt.c
|
||||
$(CC) $(CFLAGS) -c halt.c
|
||||
halt: halt.o start.o
|
||||
$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
|
||||
$(COFF2NOFF) halt.coff halt
|
||||
|
||||
add.o: add.c
|
||||
$(CC) $(CFLAGS) -c add.c
|
||||
|
||||
add: add.o start.o
|
||||
$(LD) $(LDFLAGS) start.o add.o -o add.coff
|
||||
$(COFF2NOFF) add.coff add
|
||||
|
||||
shell.o: shell.c
|
||||
$(CC) $(CFLAGS) -c shell.c
|
||||
shell: shell.o start.o
|
||||
$(LD) $(LDFLAGS) start.o shell.o -o shell.coff
|
||||
$(COFF2NOFF) shell.coff shell
|
||||
|
||||
sort.o: sort.c
|
||||
$(CC) $(CFLAGS) -c sort.c
|
||||
sort: sort.o start.o
|
||||
$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
|
||||
$(COFF2NOFF) sort.coff sort
|
||||
|
||||
segments.o: segments.c
|
||||
$(CC) $(CFLAGS) -c segments.c
|
||||
segments: segments.o start.o
|
||||
$(LD) $(LDFLAGS) start.o segments.o -o segments.coff
|
||||
$(COFF2NOFF) segments.coff segments
|
||||
|
||||
matmult.o: matmult.c
|
||||
$(CC) $(CFLAGS) -c matmult.c
|
||||
matmult: matmult.o start.o
|
||||
$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
|
||||
$(COFF2NOFF) matmult.coff matmult
|
||||
|
||||
consoleIO_test1.o: consoleIO_test1.c
|
||||
$(CC) $(CFLAGS) -c consoleIO_test1.c
|
||||
consoleIO_test1: consoleIO_test1.o start.o
|
||||
$(LD) $(LDFLAGS) start.o consoleIO_test1.o -o consoleIO_test1.coff
|
||||
$(COFF2NOFF) consoleIO_test1.coff consoleIO_test1
|
||||
|
||||
consoleIO_test2.o: consoleIO_test2.c
|
||||
$(CC) $(CFLAGS) -c consoleIO_test2.c
|
||||
consoleIO_test2: consoleIO_test2.o start.o
|
||||
$(LD) $(LDFLAGS) start.o consoleIO_test2.o -o consoleIO_test2.coff
|
||||
$(COFF2NOFF) consoleIO_test2.coff consoleIO_test2
|
||||
|
||||
fileIO_test1.o: fileIO_test1.c
|
||||
$(CC) $(CFLAGS) -c fileIO_test1.c
|
||||
fileIO_test1: fileIO_test1.o start.o
|
||||
$(LD) $(LDFLAGS) start.o fileIO_test1.o -o fileIO_test1.coff
|
||||
$(COFF2NOFF) fileIO_test1.coff fileIO_test1
|
||||
|
||||
fileIO_test2.o: fileIO_test2.c
|
||||
$(CC) $(CFLAGS) -c fileIO_test2.c
|
||||
fileIO_test2: fileIO_test2.o start.o
|
||||
$(LD) $(LDFLAGS) start.o fileIO_test2.o -o fileIO_test2.coff
|
||||
$(COFF2NOFF) fileIO_test2.coff fileIO_test2
|
||||
|
||||
fileIO_test3.o: fileIO_test3.c
|
||||
$(CC) $(CFLAGS) -c fileIO_test3.c
|
||||
fileIO_test3: fileIO_test3.o start.o
|
||||
$(LD) $(LDFLAGS) start.o fileIO_test3.o -o fileIO_test3.coff
|
||||
$(COFF2NOFF) fileIO_test3.coff fileIO_test3
|
||||
|
||||
|
||||
clean:
|
||||
$(RM) -f *.o *.ii
|
||||
$(RM) -f *.coff
|
||||
|
||||
distclean: clean
|
||||
$(RM) -f $(PROGRAMS)
|
||||
|
||||
unknownhost:
|
||||
@echo Host type could not be determined.
|
||||
@echo make is terminating.
|
||||
@echo If you are on an MFCF machine, contact the instructor to report this problem
|
||||
@echo Otherwise, edit Makefile.dep and try again.
|
||||
63
code/test/Makefile.dep
Normal file
63
code/test/Makefile.dep
Normal file
@@ -0,0 +1,63 @@
|
||||
#############################################################################
|
||||
# Machine-specific definitions
|
||||
#
|
||||
# If you are not in the MFCF environment, you can either add a new
|
||||
# automatic test for your machine/OS type, or you should set the
|
||||
# necessary variables "manually" here
|
||||
#############################################################################
|
||||
|
||||
# unfortunately, command line arguments to uname are not
|
||||
# very consistent across UNIX flavours. However, the following
|
||||
# seem to work almost everywhere in MFCF land
|
||||
|
||||
osname = $(shell uname -s)
|
||||
osrelease = $(shell uname -r)
|
||||
|
||||
hosttype = unknown
|
||||
|
||||
# Test for x86 Linux
|
||||
# !!! COMMENT THE FOLLOWING LINES OUT IF BUILDING FOR SOLARIS HOST !!!
|
||||
# !!! ADD PATH TO CPP and CROSS COMPILER
|
||||
|
||||
ifeq ($(osname),Linux)
|
||||
# full path name of your cpp program i.e.:
|
||||
CPP = ../../usr/local/nachos/lib/gcc-lib/decstation-ultrix/2.95.2/cpp
|
||||
# directory in which your gcc cross-compiler lives i.e.:
|
||||
GCCDIR = ../../usr/local/nachos/bin/decstation-ultrix-
|
||||
LDFLAGS = -T script -N
|
||||
ASFLAGS = -mips2
|
||||
CPPFLAGS = $(INCDIR)
|
||||
COFF2NOFF = ../../coff2noff/coff2noff.x86Linux
|
||||
hosttype = x86Linux
|
||||
endif
|
||||
|
||||
ifeq ($(osname),Windows)
|
||||
CPP = /usr/local/nachosxdev/lib/gcc-lib/decstation-ultrix/2.95.3/cpp0
|
||||
# directory in which your gcc cross-compiler lives i.e.:
|
||||
GCCDIR = /usr/local/nachosxdev/bin/decstation-ultrix-
|
||||
LDFLAGS = -T script -N
|
||||
ASFLAGS = -mips2
|
||||
CPPFLAGS = $(INCDIR)
|
||||
COFF2NOFF = ../../coff2noff/coff2noff.Windows
|
||||
hosttype = Windows
|
||||
endif
|
||||
|
||||
# Note:
|
||||
# If you are trying to build on MacOS X
|
||||
# try something like this, substituting whatever
|
||||
# uname -s returns on your machine for the XXX
|
||||
#
|
||||
#ifeq ($(osname),XXX)
|
||||
#CPP = full path name of your cpp program
|
||||
#GCCDIR = directory in which your gcc cross-compiler lives
|
||||
#LDFLAGS = -T script -N
|
||||
#ASFLAGS = -mips2
|
||||
#CPPFLAGS = $(INCDIR)
|
||||
#COFF2NOFF = full pathname of your coff2noff program
|
||||
# Note: it has been moved to part of the Nachos distribution
|
||||
# COFF2NOFF = ../../coff2noff.mipsUltrix
|
||||
#hosttype = MacOS
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
BIN
code/test/a
Normal file
BIN
code/test/a
Normal file
Binary file not shown.
BIN
code/test/add
Normal file
BIN
code/test/add
Normal file
Binary file not shown.
20
code/test/add.c
Normal file
20
code/test/add.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* add.c
|
||||
* Simple program to test whether the systemcall interface works.
|
||||
*
|
||||
* Just do a add syscall that adds two values and returns the result.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = Add(42, 23);
|
||||
PrintInt(result);
|
||||
// printf("result is %d\n", result);
|
||||
Halt();
|
||||
/* not reached */
|
||||
}
|
||||
BIN
code/test/consoleIO_test1
Normal file
BIN
code/test/consoleIO_test1
Normal file
Binary file not shown.
12
code/test/consoleIO_test1.c
Normal file
12
code/test/consoleIO_test1.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int n;
|
||||
for (n=9;n>5;n--) {
|
||||
PrintInt(n);
|
||||
}
|
||||
Halt();
|
||||
}
|
||||
|
||||
BIN
code/test/consoleIO_test2
Normal file
BIN
code/test/consoleIO_test2
Normal file
Binary file not shown.
13
code/test/consoleIO_test2.c
Normal file
13
code/test/consoleIO_test2.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int n;
|
||||
for (n=15;n<=19;n++){
|
||||
|
||||
PrintInt(n);
|
||||
}
|
||||
Halt();
|
||||
}
|
||||
|
||||
BIN
code/test/fileIO_test1
Normal file
BIN
code/test/fileIO_test1
Normal file
Binary file not shown.
20
code/test/fileIO_test1.c
Normal file
20
code/test/fileIO_test1.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char test[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
int success = Create("file1.test");
|
||||
OpenFileId fid;
|
||||
int i;
|
||||
if (success != 1) MSG("Failed on creating file");
|
||||
fid = Open("file1.test");
|
||||
if (fid == -1) MSG("Failed on opening file");
|
||||
for (i = 0; i < 26; ++i) {
|
||||
int count = Write(test + i, 1, fid);
|
||||
if (count != 1) MSG("Failed on writing file");
|
||||
}
|
||||
success = Close(fid);
|
||||
if (success != 1) MSG("Failed on closing file");
|
||||
Halt();
|
||||
}
|
||||
|
||||
BIN
code/test/fileIO_test2
Normal file
BIN
code/test/fileIO_test2
Normal file
Binary file not shown.
22
code/test/fileIO_test2.c
Normal file
22
code/test/fileIO_test2.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// you should run fileIO_test1 first before running this one
|
||||
char test[26];
|
||||
char check[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
OpenFileId fid;
|
||||
int count, success, i;
|
||||
fid = Open("file1.test");
|
||||
if (fid == -1) MSG("Failed on opening file");
|
||||
count = Read(test, 26, fid);
|
||||
if (count != 26) MSG("Failed on reading file");
|
||||
success = Close(fid);
|
||||
if (success != 1) MSG("Failed on closing file");
|
||||
for (i = 0; i < 26; ++i) {
|
||||
if (test[i] != check[i]) MSG("Failed: reading wrong result");
|
||||
}
|
||||
MSG("Passed! ^_^");
|
||||
Halt();
|
||||
}
|
||||
|
||||
BIN
code/test/halt
Normal file
BIN
code/test/halt
Normal file
Binary file not shown.
20
code/test/halt.c
Normal file
20
code/test/halt.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* halt.c
|
||||
* Simple program to test whether running a user program works.
|
||||
*
|
||||
* Just do a "syscall" that shuts down the OS.
|
||||
*
|
||||
* NOTE: for some reason, user programs with global data structures
|
||||
* sometimes haven't worked in the Nachos environment. So be careful
|
||||
* out there! One option is to allocate data structures as
|
||||
* automatics within a procedure, but if you do this, you have to
|
||||
* be careful to allocate a big enough stack to hold the automatics!
|
||||
*/
|
||||
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Halt();
|
||||
/* not reached */
|
||||
}
|
||||
38
code/test/matmult.c
Normal file
38
code/test/matmult.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* matmult.c
|
||||
* Test program to do matrix multiplication on large arrays.
|
||||
*
|
||||
* Intended to stress virtual memory system.
|
||||
*
|
||||
* Ideally, we could read the matrices off of the file system,
|
||||
* and store the result back to the file system!
|
||||
*/
|
||||
|
||||
#include "syscall.h"
|
||||
|
||||
#define Dim 20 /* sum total of the arrays doesn't fit in
|
||||
* physical memory
|
||||
*/
|
||||
|
||||
int A[Dim][Dim];
|
||||
int B[Dim][Dim];
|
||||
int C[Dim][Dim];
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < Dim; i++) /* first initialize the matrices */
|
||||
for (j = 0; j < Dim; j++) {
|
||||
A[i][j] = i;
|
||||
B[i][j] = j;
|
||||
C[i][j] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < Dim; i++) /* then multiply them together */
|
||||
for (j = 0; j < Dim; j++)
|
||||
for (k = 0; k < Dim; k++)
|
||||
C[i][j] += A[i][k] * B[k][j];
|
||||
|
||||
Exit(C[Dim-1][Dim-1]); /* and then we're done */
|
||||
}
|
||||
3
code/test/os_students.sh
Normal file
3
code/test/os_students.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
make clean
|
||||
make
|
||||
../build.linux/nachos -e halt
|
||||
36
code/test/script
Normal file
36
code/test/script
Normal file
@@ -0,0 +1,36 @@
|
||||
OUTPUT_FORMAT("ecoff-littlemips")
|
||||
ENTRY(__start)
|
||||
SECTIONS
|
||||
{
|
||||
.text 0 : {
|
||||
_ftext = . ;
|
||||
*(.init)
|
||||
eprol = .;
|
||||
*(.text)
|
||||
*(.fini)
|
||||
etext = .;
|
||||
_etext = .;
|
||||
}
|
||||
.rdata . : {
|
||||
*(.rdata)
|
||||
}
|
||||
_fdata = .;
|
||||
.data . : {
|
||||
*(.data)
|
||||
CONSTRUCTORS
|
||||
}
|
||||
edata = .;
|
||||
_edata = .;
|
||||
_fbss = .;
|
||||
.sbss . : {
|
||||
*(.sbss)
|
||||
*(.scommon)
|
||||
}
|
||||
.bss . : {
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
}
|
||||
end = .;
|
||||
_end = .;
|
||||
}
|
||||
|
||||
41
code/test/segments.c
Normal file
41
code/test/segments.c
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
/* segments.c
|
||||
* Simple program to illustrate different segments and to show
|
||||
* how parameters are passed and the syscall is generated.
|
||||
*
|
||||
* objdump below refers to:
|
||||
* /software/gcc_nachos/bin/decstation-ultrix-objdump
|
||||
*
|
||||
* Compile this "gmake segments"
|
||||
* Then use objdump to examine output.
|
||||
* objdump -d segments.coff - to disassemble
|
||||
* objdump -s segments.coff - to see contents of segments
|
||||
* objdump -x segments.coff - to see symbol table information
|
||||
* nachos -d m -s -x segments
|
||||
*/
|
||||
|
||||
#define N (5) /* N is replaced by the preprocessor */
|
||||
|
||||
unsigned int initdata1 = 0xdeadbeef; /* initialized data put in .data segment */
|
||||
int initdata2 = 0xbb; /* same as above */
|
||||
const int blah = 0xff; /* into .rdata segment */
|
||||
int uninitdata[N]; /* allocate space in .bss segment */
|
||||
|
||||
main()
|
||||
{
|
||||
/* automatic variable stored on stack or in register */
|
||||
int i;
|
||||
int stack1 = 0xaa;
|
||||
int stack2;
|
||||
const int stack3 = 0xee; /* in reg or on stack not .rdata */
|
||||
char *str = "Hello World .rdata segment\n";
|
||||
|
||||
/* str is stored on the stack or in a register
|
||||
* but text that is initialized is stored in .rdata
|
||||
*/
|
||||
|
||||
for (i=0; i<N; i++) {
|
||||
uninitdata[i] = i;
|
||||
}
|
||||
Halt();
|
||||
}
|
||||
35
code/test/shell.c
Normal file
35
code/test/shell.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
SpaceId newProc;
|
||||
OpenFileId input = ConsoleInput;
|
||||
OpenFileId output = ConsoleOutput;
|
||||
char prompt[2], ch, buffer[60];
|
||||
int i;
|
||||
|
||||
prompt[0] = '-';
|
||||
prompt[1] = '-';
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
Write(prompt, 2, output);
|
||||
|
||||
i = 0;
|
||||
|
||||
do {
|
||||
|
||||
Read(&buffer[i], 1, input);
|
||||
|
||||
} while( buffer[i++] != '\n' );
|
||||
|
||||
buffer[--i] = '\0';
|
||||
|
||||
if( i > 0 ) {
|
||||
newProc = Exec(buffer);
|
||||
Join(newProc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
code/test/sort
Normal file
BIN
code/test/sort
Normal file
Binary file not shown.
69
code/test/sort.c
Normal file
69
code/test/sort.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* sort.c
|
||||
* Test program to sort a large number of integers.
|
||||
*
|
||||
* Intention is to stress virtual memory system.
|
||||
*
|
||||
* Ideally, we could read the unsorted array off of the file system,
|
||||
* and store the result back to the file system!
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
#define UNIX
|
||||
#define UNIX_DEBUG
|
||||
*/
|
||||
|
||||
#ifdef UNIX
|
||||
#include <stdio.h>
|
||||
#define Exit exit
|
||||
#else
|
||||
#include "syscall.h"
|
||||
#endif /* UNIX */
|
||||
|
||||
#define SIZE (1024)
|
||||
|
||||
int A[SIZE]; /* size of physical memory; with code, we'll run out of space!*/
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int i, j, tmp;
|
||||
|
||||
/* first initialize the array, in reverse sorted order */
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
A[i] = (SIZE-1) - i;
|
||||
}
|
||||
|
||||
/* then sort! */
|
||||
for (i = 0; i < SIZE; i++) {
|
||||
for (j = 0; j < (SIZE-1); j++) {
|
||||
if (A[j] > A[j + 1]) { /* out of order -> need to swap ! */
|
||||
tmp = A[j];
|
||||
A[j] = A[j + 1];
|
||||
A[j + 1] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UNIX_DEBUG
|
||||
for (i=0; i<SIZE; i++) {
|
||||
printf("%4d ", A[i]);
|
||||
if (((i+1) % 15) == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
if (A[i] != i) {
|
||||
fprintf(stderr, "Out of order A[%d] = %d\n", i, A[i]);
|
||||
Exit(1);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
#endif /* UNIX_DEBUG */
|
||||
|
||||
for (i=0; i<SIZE; i++) {
|
||||
if (A[i] != i) {
|
||||
Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Exit(0);
|
||||
}
|
||||
196
code/test/start.S
Normal file
196
code/test/start.S
Normal file
@@ -0,0 +1,196 @@
|
||||
/* Start.s
|
||||
* Assembly language assist for user programs running on top of Nachos.
|
||||
*
|
||||
* Since we don't want to pull in the entire C library, we define
|
||||
* what we need for a user program here, namely Start and the system
|
||||
* calls.
|
||||
*/
|
||||
|
||||
#define IN_ASM
|
||||
#include "syscall.h"
|
||||
|
||||
.text
|
||||
.align 2
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
* __start
|
||||
* Initialize running a C program, by calling "main".
|
||||
*
|
||||
* NOTE: This has to be first, so that it gets loaded at location 0.
|
||||
* The Nachos kernel always starts a program by jumping to location 0.
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
.globl __start
|
||||
.ent __start
|
||||
__start:
|
||||
jal main
|
||||
move $4,$0
|
||||
jal Exit /* if we return from main, exit(0) */
|
||||
.end __start
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
* System call stubs:
|
||||
* Assembly language assist to make system calls to the Nachos kernel.
|
||||
* There is one stub per system call, that places the code for the
|
||||
* system call into register r2, and leaves the arguments to the
|
||||
* system call alone (in other words, arg1 is in r4, arg2 is
|
||||
* in r5, arg3 is in r6, arg4 is in r7)
|
||||
*
|
||||
* The return value is in r2. This follows the standard C calling
|
||||
* convention on the MIPS.
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
.globl Halt
|
||||
.ent Halt
|
||||
Halt:
|
||||
addiu $2,$0,SC_Halt
|
||||
syscall
|
||||
j $31
|
||||
.end Halt
|
||||
|
||||
.globl MSG
|
||||
.ent MSG
|
||||
MSG:
|
||||
addiu $2,$0,SC_MSG
|
||||
syscall
|
||||
j $31
|
||||
.end MSG
|
||||
|
||||
.globl Add
|
||||
.ent Add
|
||||
Add:
|
||||
addiu $2,$0,SC_Add
|
||||
syscall
|
||||
j $31
|
||||
.end Add
|
||||
|
||||
.globl Exit
|
||||
.ent Exit
|
||||
Exit:
|
||||
addiu $2,$0,SC_Exit
|
||||
syscall
|
||||
j $31
|
||||
.end Exit
|
||||
|
||||
.globl Exec
|
||||
.ent Exec
|
||||
Exec:
|
||||
addiu $2,$0,SC_Exec
|
||||
syscall
|
||||
j $31
|
||||
.end Exec
|
||||
|
||||
.globl ExecV
|
||||
.ent ExecV
|
||||
ExecV:
|
||||
addiu $2,$0,SC_ExecV
|
||||
syscall
|
||||
j $31
|
||||
.end ExecV
|
||||
|
||||
.globl Join
|
||||
.ent Join
|
||||
Join:
|
||||
addiu $2,$0,SC_Join
|
||||
syscall
|
||||
j $31
|
||||
.end Join
|
||||
|
||||
.globl Create
|
||||
.ent Create
|
||||
Create:
|
||||
addiu $2,$0,SC_Create
|
||||
syscall
|
||||
j $31
|
||||
.end Create
|
||||
|
||||
.globl Remove
|
||||
.ent Remove
|
||||
Remove:
|
||||
addiu $2,$0,SC_Remove
|
||||
syscall
|
||||
j $31
|
||||
.end Remove
|
||||
|
||||
.globl Open
|
||||
.ent Open
|
||||
Open:
|
||||
addiu $2,$0,SC_Open
|
||||
syscall
|
||||
j $31
|
||||
.end Open
|
||||
|
||||
.globl Read
|
||||
.ent Read
|
||||
Read:
|
||||
addiu $2,$0,SC_Read
|
||||
syscall
|
||||
j $31
|
||||
.end Read
|
||||
|
||||
.globl Write
|
||||
.ent Write
|
||||
Write:
|
||||
addiu $2,$0,SC_Write
|
||||
syscall
|
||||
j $31
|
||||
.end Write
|
||||
|
||||
.globl Close
|
||||
.ent Close
|
||||
Close:
|
||||
addiu $2,$0,SC_Close
|
||||
syscall
|
||||
j $31
|
||||
.end Close
|
||||
|
||||
.globl Seek
|
||||
.ent Seek
|
||||
Seek:
|
||||
addiu $2,$0,SC_Seek
|
||||
syscall
|
||||
j $31
|
||||
.end Seek
|
||||
|
||||
.globl ThreadFork
|
||||
.ent ThreadFork
|
||||
ThreadFork:
|
||||
addiu $2,$0,SC_ThreadFork
|
||||
syscall
|
||||
j $31
|
||||
.end ThreadFork
|
||||
|
||||
.globl ThreadYield
|
||||
.ent ThreadYield
|
||||
ThreadYield:
|
||||
addiu $2,$0,SC_ThreadYield
|
||||
syscall
|
||||
j $31
|
||||
.end ThreadYield
|
||||
|
||||
.globl ThreadExit
|
||||
.ent ThreadExit
|
||||
ThreadExit:
|
||||
addiu $2, $0, SC_ThreadExit
|
||||
syscall
|
||||
j $31
|
||||
.end ThreadExit
|
||||
|
||||
.globl ThreadJoin
|
||||
.ent ThreadJoin
|
||||
ThreadJoin:
|
||||
addiu $2, $0, SC_ThreadJoin
|
||||
syscall
|
||||
j $31
|
||||
.end ThreadJoin
|
||||
|
||||
|
||||
/* dummy function to keep gcc happy */
|
||||
.globl __main
|
||||
.ent __main
|
||||
__main:
|
||||
j $31
|
||||
.end __main
|
||||
|
||||
Reference in New Issue
Block a user