Finished part 1 prototype
parent
0f52953e3d
commit
865eed3648
Binary file not shown.
|
@ -16,6 +16,8 @@ CPPFLAGS =
|
|||
CFLAGS = -O2 -B$(GCCDIR) -G 0 -Wa,-mips1 -nostdlib -ffreestanding
|
||||
LDFLAGS = -s -T script -N -warn-common -warn-constructors -warn-multiple-gp
|
||||
|
||||
PATH=$(ARCHDIR)
|
||||
|
||||
CC = $(GCCDIR)gcc
|
||||
AS = $(GCCDIR)as
|
||||
LD = $(GCCDIR)ld
|
||||
|
@ -30,7 +32,8 @@ STDLIB_O = start.o stdio.o stdlib.o
|
|||
LIB = assert atoi printf readline stdio strncmp strcat strcmp strcpy strlen memcpy memset
|
||||
NLIB = libnachos.a
|
||||
|
||||
TARGETS = halt sh matmult sort echo cat cp mv rm #chat chatserver
|
||||
#TARGETS = halt sh matmult sort echo cat cp mv rm #chat chatserver
|
||||
TARGETS = mytest1
|
||||
|
||||
.SECONDARY: $(patsubst %.c,%.o,$(wildcard *.c))
|
||||
|
||||
|
@ -39,10 +42,10 @@ all: $(patsubst %,%.coff,$(TARGETS))
|
|||
ag: grade-file.coff grade-exec.coff grade-mini.coff grade-dumb.coff
|
||||
|
||||
clean:
|
||||
rm -f strt.s *.o *.coff $(NLIB)
|
||||
/bin/rm -f strt.s *.o *.coff $(NLIB)
|
||||
|
||||
agclean: clean
|
||||
rm -f f1-* f2-*
|
||||
/bin/rm -f f1-* f2-*
|
||||
|
||||
$(NLIB): $(patsubst %,$(NLIB)(%.o),$(LIB)) start.o
|
||||
$(RANLIB) $(NLIB)
|
||||
|
@ -50,7 +53,7 @@ $(NLIB): $(patsubst %,$(NLIB)(%.o),$(LIB)) start.o
|
|||
start.o: start.s syscall.h
|
||||
$(CPP) $(CPPFLAGS) start.s > strt.s
|
||||
$(AS) $(ASFLAGS) -o start.o strt.s
|
||||
rm strt.s
|
||||
/bin/rm strt.s
|
||||
|
||||
%.o: %.c *.h
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
|
BIN
test/assert.o
BIN
test/assert.o
Binary file not shown.
BIN
test/atoi.o
BIN
test/atoi.o
Binary file not shown.
BIN
test/cat.coff
BIN
test/cat.coff
Binary file not shown.
BIN
test/cat.o
BIN
test/cat.o
Binary file not shown.
BIN
test/cp.coff
BIN
test/cp.coff
Binary file not shown.
BIN
test/echo.coff
BIN
test/echo.coff
Binary file not shown.
BIN
test/echo.o
BIN
test/echo.o
Binary file not shown.
BIN
test/halt.coff
BIN
test/halt.coff
Binary file not shown.
BIN
test/halt.o
BIN
test/halt.o
Binary file not shown.
BIN
test/libnachos.a
BIN
test/libnachos.a
Binary file not shown.
Binary file not shown.
BIN
test/matmult.o
BIN
test/matmult.o
Binary file not shown.
BIN
test/memcpy.o
BIN
test/memcpy.o
Binary file not shown.
BIN
test/memset.o
BIN
test/memset.o
Binary file not shown.
BIN
test/mv.coff
BIN
test/mv.coff
Binary file not shown.
|
@ -0,0 +1,39 @@
|
|||
#include "syscall.h"
|
||||
#include "stdio.h"
|
||||
|
||||
char buf[100];
|
||||
int main()
|
||||
{
|
||||
int ff=creat("data");
|
||||
close(ff);
|
||||
write(1,"10 200\n",strlen("10 200\n"));
|
||||
printf("%d\n",write(ff,"10 200\n",10));
|
||||
halt();
|
||||
return 0;
|
||||
|
||||
/*
|
||||
int a=0,b=0,i=0;
|
||||
int ff=open("test");
|
||||
int l=read(ff,buf,100);
|
||||
printf("%d\n",l);
|
||||
printf("%s\n",buf);
|
||||
for(;;i++)
|
||||
{
|
||||
if(buf[i]<'0'||buf[i]>'9') break;
|
||||
a=10*a+buf[i]-'0';
|
||||
}
|
||||
for(;;i++)
|
||||
{
|
||||
if(!(buf[i]<'0'||buf[i]>'9')) break;
|
||||
}
|
||||
for(;i<l;i++)
|
||||
{
|
||||
if(buf[i]<'0'||buf[i]>'9') break;
|
||||
b=10*b+buf[i]-'0';
|
||||
}
|
||||
printf("%d+%d=%d\n",a,b,a+b);
|
||||
halt();
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
BIN
test/printf.o
BIN
test/printf.o
Binary file not shown.
BIN
test/readline.o
BIN
test/readline.o
Binary file not shown.
BIN
test/rm.coff
BIN
test/rm.coff
Binary file not shown.
BIN
test/sh.coff
BIN
test/sh.coff
Binary file not shown.
BIN
test/sort.coff
BIN
test/sort.coff
Binary file not shown.
BIN
test/sort.o
BIN
test/sort.o
Binary file not shown.
BIN
test/start.o
BIN
test/start.o
Binary file not shown.
BIN
test/stdio.o
BIN
test/stdio.o
Binary file not shown.
BIN
test/strcat.o
BIN
test/strcat.o
Binary file not shown.
BIN
test/strcmp.o
BIN
test/strcmp.o
Binary file not shown.
BIN
test/strcpy.o
BIN
test/strcpy.o
Binary file not shown.
BIN
test/strlen.o
BIN
test/strlen.o
Binary file not shown.
BIN
test/strncmp.o
BIN
test/strncmp.o
Binary file not shown.
|
@ -53,6 +53,11 @@ public class UserProcess {
|
|||
return false;
|
||||
|
||||
new UThread(this).setName(name).fork();
|
||||
descs=new OpenFile[16];
|
||||
descs[0]=UserKernel.console.openForReading();
|
||||
descs[1]=UserKernel.console.openForWriting();
|
||||
for(int i=2;i<16;i++)
|
||||
descs[i]=null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -387,17 +392,91 @@ public class UserProcess {
|
|||
* @param a3 the fourth syscall argument.
|
||||
* @return the value to be returned to the user.
|
||||
*/
|
||||
public int handleSyscall(int syscall, int a0, int a1, int a2, int a3) {
|
||||
switch (syscall) {
|
||||
case syscallHalt:
|
||||
return handleHalt();
|
||||
public int handleSyscall(int syscall, int a0, int a1, int a2, int a3)
|
||||
{
|
||||
System.out.println("System Call: "+syscall);
|
||||
String fn;
|
||||
byte[] buf;
|
||||
int len;
|
||||
switch (syscall)
|
||||
{
|
||||
case syscallHalt:
|
||||
return handleHalt();
|
||||
|
||||
case syscallCreate:
|
||||
fn=readVirtualMemoryString(a0,256);
|
||||
if(fn!=null)
|
||||
{
|
||||
//System.out.println("I am going to create a file name "+fn);
|
||||
OpenFile tf=ThreadedKernel.fileSystem.open(fn,true);
|
||||
if(tf==null)
|
||||
return -1;
|
||||
for(int i=2;i<16;i++)
|
||||
if(descs[i]==null)
|
||||
{
|
||||
descs[i]=tf;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
System.out.println("Bloody hell");
|
||||
return -1;
|
||||
|
||||
default:
|
||||
Lib.debug(dbgProcess, "Unknown syscall " + syscall);
|
||||
Lib.assertNotReached("Unknown system call!");
|
||||
}
|
||||
return 0;
|
||||
case syscallOpen:
|
||||
fn=readVirtualMemoryString(a0,256);
|
||||
if(fn!=null)
|
||||
{
|
||||
//System.out.println("I am going to open a file name "+fn);
|
||||
OpenFile tf=ThreadedKernel.fileSystem.open(fn,false);
|
||||
if(tf==null)
|
||||
return -1;
|
||||
for(int i=2;i<16;i++)
|
||||
if(descs[i]==null)
|
||||
{
|
||||
descs[i]=tf;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
System.out.println("Bloody hell");
|
||||
return -1;
|
||||
|
||||
case syscallRead:
|
||||
if(descs[a0]==null)
|
||||
return -1;
|
||||
buf=new byte[a2];
|
||||
len=descs[a0].read(buf,0,a2);
|
||||
if(len<0)
|
||||
return -1;
|
||||
return writeVirtualMemory(a1,buf,0,len);
|
||||
|
||||
case syscallWrite:
|
||||
if(descs[a0]==null)
|
||||
return -1;
|
||||
buf=new byte[a2];
|
||||
len=readVirtualMemory(a1,buf,0,a2);
|
||||
return descs[a0].write(buf,0,len);
|
||||
|
||||
case syscallClose:
|
||||
if(descs[a0]!=null)
|
||||
descs[a0].close();
|
||||
descs[a0]=null;
|
||||
return 0;
|
||||
|
||||
case syscallUnlink:
|
||||
fn=readVirtualMemoryString(a0,256);
|
||||
if(fn!=null)
|
||||
{
|
||||
ThreadedKernel.fileSystem.remove(fn);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
|
||||
default:
|
||||
Lib.debug(dbgProcess, "Unknown syscall " + syscall);
|
||||
Lib.assertNotReached("Unknown system call!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -446,4 +525,5 @@ public class UserProcess {
|
|||
|
||||
private static final int pageSize = Processor.pageSize;
|
||||
private static final char dbgProcess = 'a';
|
||||
private OpenFile descs[];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue