Finished part 1 prototype

master
ginger88895 2019-04-30 21:20:48 +08:00
parent 0f52953e3d
commit 865eed3648
39 changed files with 135 additions and 13 deletions

View File

@ -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 $<

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
test/cp.o

Binary file not shown.

0
test/data Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
test/mv.o

Binary file not shown.

39
test/mytest1.c Normal file
View File

@ -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;
}

BIN
test/mytest1.coff Normal file

Binary file not shown.

BIN
test/mytest1.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
test/rm.o

Binary file not shown.

Binary file not shown.

BIN
test/sh.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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[];
}