浏览代码

Patched various issues for system construction kernel exercise

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7009 8c9fc860-2736-0410-a75d-ab315db34111
felixf 8 年之前
父节点
当前提交
3a9f875db8
共有 6 个文件被更改,包括 58 次插入78 次删除
  1. 2 71
      source/GenericLoader.Mod
  2. 1 1
      source/Release.Tool
  3. 8 5
      source/StaticLinker.Mod
  4. 21 1
      source/StdIOShell.Mod
  5. 24 0
      source/SystemTools.Mod
  6. 2 0
      source/Traps.Mod

+ 2 - 71
source/GenericLoader.Mod

@@ -373,7 +373,7 @@ TYPE
 		
 		
 			(* stupid implementation: just search for fp in all exports *)
 			(* stupid implementation: just search for fp in all exports *)
 			PROCEDURE CheckScope(CONST scope: Modules.ExportDesc; level: LONGINT): LONGINT;
 			PROCEDURE CheckScope(CONST scope: Modules.ExportDesc; level: LONGINT): LONGINT;
-			VAR adr,i,lo,hi,m,res: LONGINT;
+			VAR adr,lo,hi,m,res: LONGINT;
 			BEGIN
 			BEGIN
 				adr := 0;
 				adr := 0;
 				(* export names are sorted, binary search: *)
 				(* export names are sorted, binary search: *)
@@ -499,7 +499,7 @@ VAR
 	END DoPreallocate;
 	END DoPreallocate;
 
 
 	PROCEDURE DoAllocate(CONST section: ObjectFile.Section; VAR data: Data): GenericLinker.Address;
 	PROCEDURE DoAllocate(CONST section: ObjectFile.Section; VAR data: Data): GenericLinker.Address;
-	VAR address: ObjectFile.Bits; bitPos, size, value: LONGINT;
+	VAR address: ObjectFile.Bits; size: SIZE;
 	BEGIN
 	BEGIN
 		IF (data.bytes = NIL) OR (LEN(data.bytes) # data.size) THEN NEW(data.bytes, data.size) END;
 		IF (data.bytes = NIL) OR (LEN(data.bytes) # data.size) THEN NEW(data.bytes, data.size) END;
 
 
@@ -521,75 +521,6 @@ VAR
 		IF data.firstAddress = 0 THEN data.firstAddress := address END;
 		IF data.firstAddress = 0 THEN data.firstAddress := address END;
 		RETURN address
 		RETURN address
 	END DoAllocate;
 	END DoAllocate;
-
-	(*
-	PROCEDURE SortProcTable(m: Modules.Module);
-		VAR i, j, min : LONGINT;
-
-		PROCEDURE Max(a,b: LONGINT): LONGINT;
-		BEGIN
-			IF a > b THEN RETURN a ELSE RETURN b END;
-		END Max;
-
-
-		PROCEDURE SwapProcTableEntries(p, q : LONGINT);
-		VAR procentry : Modules.ProcTableEntry;
-			k, i, basep, baseq: LONGINT; ptr: SIZE;
-		BEGIN
-			k := Max(m.procTable[p].noPtr, m.procTable[q].noPtr);
-			IF k > 0 THEN (* swap entries in ptrTable first *)
-				basep := p * m.maxPtrs; baseq := q * m.maxPtrs;
-				FOR i := 0 TO k - 1 DO
-					ptr := m.ptrTable[basep + i];
-					m.ptrTable[basep + i] := m.ptrTable[baseq + i];
-					m.ptrTable[baseq + i] := ptr
-				END
-			END;
-			procentry := m.procTable[p];
-			m.procTable[p] := m.procTable[q];
-			m.procTable[q] := procentry
-		END SwapProcTableEntries;
-
-		PROCEDURE NormalizePointerArray;
-		VAR ptrTable: Modules.PtrTable; i,j,k: LONGINT;
-		BEGIN
-			NEW(ptrTable, m.maxPtrs*m.noProcs);
-			k := 0;
-			FOR i := 0 TO LEN(m.procTable)-1 DO
-				FOR j := 0 TO m.procTable[i].noPtr-1 DO
-					ptrTable[i*m.maxPtrs+j] := m.ptrTable[k];
-					INC(k);
-				END;
-			END;
-			m.ptrTable := ptrTable;
-		END NormalizePointerArray;
-
-
-	BEGIN
-		NormalizePointerArray;
-		FOR i := 0 TO m.noProcs - 2 DO
-			min := i;
-			FOR j := i + 1 TO m.noProcs - 1 DO
-				IF m.procTable[j].pcFrom < m.procTable[min].pcFrom THEN min:= j END
-			END;
-			IF min # i THEN SwapProcTableEntries(i, min) END
-		END
-	END SortProcTable;
-	*) 
-	PROCEDURE SelectionSort(exTable: Modules.ExceptionTable);
-	VAR
-		p, q, min: LONGINT;
-		entry: Modules.ExceptionTableEntry;
-	BEGIN
-		FOR p := 0 TO LEN(exTable) - 2 DO
-			min := p;
-			FOR q := p + 1 TO LEN(exTable) - 1 DO
-				IF exTable[min].pcFrom > exTable[q].pcFrom THEN min := q END;
-				entry := exTable[min]; exTable[min] := exTable[p]; exTable[p] := entry;
-			END
-		END
-	END SelectionSort;
-	
 	
 	
 	PROCEDURE LoadObj*(CONST name, fileName: ARRAY OF CHAR;  VAR res: LONGINT; VAR msg: ARRAY OF CHAR): Modules.Module;
 	PROCEDURE LoadObj*(CONST name, fileName: ARRAY OF CHAR;  VAR res: LONGINT; VAR msg: ARRAY OF CHAR): Modules.Module;
 	TYPE Body=PROCEDURE;
 	TYPE Body=PROCEDURE;

+ 1 - 1
source/Release.Tool

@@ -478,7 +478,7 @@ PACKAGE System ARCHIVE "System.zip" SOURCE "SystemSrc.zip" DESCRIPTION "System"
 	NATIVE,WIN,UNIX { RelativeFileSystem.Mod } # file system relative to path
 	NATIVE,WIN,UNIX { RelativeFileSystem.Mod } # file system relative to path
 
 
 	NATIVEORIG,WINORIG,UNIX { Loader.Mod }
 	NATIVEORIG,WINORIG,UNIX { Loader.Mod }
-	NATIVEGEN, WINGEN, COOP {BitSets.Mod Diagnostics.Mod StringPool.Mod ObjectFile.Mod GenericLinker.Mod GenericLoader.Mod }
+	NATIVEGEN, WINGEN, COOP, UNIXG {BitSets.Mod Diagnostics.Mod StringPool.Mod ObjectFile.Mod GenericLinker.Mod GenericLoader.Mod }
 
 
 	# binding modules
 	# binding modules
 	NATIVE,WIN { BootConsole.Mod }
 	NATIVE,WIN { BootConsole.Mod }

+ 8 - 5
source/StaticLinker.Mod

@@ -205,9 +205,10 @@ BEGIN
 	Files.OpenReader (reader, file, 0);
 	Files.OpenReader (reader, file, 0);
 	
 	
 	GenericLinker.OffersRequires(reader, offers, requires);
 	GenericLinker.OffersRequires(reader, offers, requires);
-	reader.SetPos(0);
-	FOR i := 0 TO LEN(offers)-1 DO
-		moduleList.Put(offers[i],processing);
+	IF (moduleList # NIL) & (offers # NIL) THEN
+		FOR i := 0 TO LEN(offers)-1 DO
+			moduleList.Put(offers[i],processing);
+		END;
 	END;
 	END;
 	
 	
 	IF (moduleList # NIL) & (requires # NIL) THEN
 	IF (moduleList # NIL) & (requires # NIL) THEN
@@ -226,8 +227,10 @@ BEGIN
 		END;
 		END;
 	END;
 	END;
 	linker.Information (moduleName, "processing");
 	linker.Information (moduleName, "processing");
+	
+	reader.SetPos(0);
 	GenericLinker.Process (reader, linker);
 	GenericLinker.Process (reader, linker);
-	IF moduleList # NIL THEN
+	IF (moduleList # NIL) & (offers # NIL) THEN
 		FOR i := 0 TO LEN(offers)-1 DO
 		FOR i := 0 TO LEN(offers)-1 DO
 			moduleList.Put(offers[i],finished);
 			moduleList.Put(offers[i],finished);
 		END;
 		END;
@@ -1061,7 +1064,7 @@ BEGIN
 	defaults.Add("Win32C","--fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H");
 	defaults.Add("Win32C","--fileFormat=PE32CUI --fileName=oberon.exe --extension=GofW --displacement=401000H");
 	defaults.Add("Linux32G","--fileFormat=Raw --fileName=oberon --extension=.GofU --displacement=08048000H");
 	defaults.Add("Linux32G","--fileFormat=Raw --fileName=oberon --extension=.GofU --displacement=08048000H");
 	defaults.Add("RPI","--fileName=kernel.img --extension=.Goa --displacement=8000H -sa ");
 	defaults.Add("RPI","--fileName=kernel.img --extension=.Goa --displacement=8000H -sa ");
-	
+	defaults.Add("A2G","--fileName=kernel.img --extension=.GofG --displacement=0100000H");
 END StaticLinker.
 END StaticLinker.
 
 
 StaticLinker.Link --fileName=test.exe --fileFormat=PE32 --displacement=401000H Test ~
 StaticLinker.Link --fileName=test.exe --fileFormat=PE32 --displacement=401000H Test ~

+ 21 - 1
source/StdIOShell.Mod

@@ -16,6 +16,7 @@ BEGIN
 	IF str = "compile" THEN str := "Compiler.Compile"
 	IF str = "compile" THEN str := "Compiler.Compile"
 	ELSIF str="link" THEN str := "StaticLinker.Link"
 	ELSIF str="link" THEN str := "StaticLinker.Link"
 	ELSIF (str="i") OR (str = "interpreter") THEN str := "InterpreterShell.Start"
 	ELSIF (str="i") OR (str = "interpreter") THEN str := "InterpreterShell.Start"
+	ELSIF (str = "run") OR (str="r") THEN str := "SystemTools.DoFile"
 	END;
 	END;
 
 
 	Commands.Activate(str, context, {Commands.Wait}, res, msg);
 	Commands.Activate(str, context, {Commands.Wait}, res, msg);
@@ -27,8 +28,27 @@ BEGIN
 	Modules.Shutdown(Modules.PowerDown);
 	Modules.Shutdown(Modules.PowerDown);
 	LOOP END;
 	LOOP END;
 END StdIOShell.
 END StdIOShell.
+SystemTools.Free StaticLinker ~
 
 
-
+	StaticLinker.Link -p=Linux32G
+		Runtime  Traps UnixFiles RelativeFileSystem GenericLoader
+		WMDefaultFont
+		StdIOShell
+		Compiler
+		StaticLinker
+		FoxOberonFrontend
+		FoxAMDBackend
+		FoxGenericObjectFile
+		InterpreterShell
+		SystemTools
+		FSTools
+		PCAAMD64
+		BootManager
+		VirtualDisks
+		DiskFS
+		Partitions
+		~
+		FSTools.CloseFiles oberon ~
 TODOS:
 TODOS:
 	- check linux file system (new files dot not work)
 	- check linux file system (new files dot not work)
 	- add interpreter to linked image
 	- add interpreter to linked image

+ 24 - 0
source/SystemTools.Mod

@@ -402,6 +402,30 @@ BEGIN
 	RETURN (ch = " ") OR (ch = CR) OR (ch = LF) OR (ch = TAB) OR (ch = ";") OR (ch = 0X);
 	RETURN (ch = " ") OR (ch = CR) OR (ch = LF) OR (ch = TAB) OR (ch = ";") OR (ch = 0X);
 END IsDelimiter;
 END IsDelimiter;
 
 
+PROCEDURE DoFile*(context: Commands.Context);
+VAR 
+	newContext: Commands.Context;
+	file: Files.File; 
+	r: Streams.Reader;
+	filename: Files.FileName;
+	res: LONGINT;
+	msg: ARRAY 256 OF CHAR;
+BEGIN
+	IF context.arg.GetString(filename) THEN
+		file := Files.Old(filename); 
+		IF file # NIL THEN
+			r := NEW Files.Reader(file, 0);
+			NEW(newContext, context.in, r, context.out, context.error, context.caller);
+			Commands.Activate("SystemTools.DoCommands", newContext, {Commands.Wait}, res, msg);
+		ELSE
+			context.error.String("Error: no such file: "); context.error.String(filename); context.error.Ln;
+		END;
+	ELSE
+		context.error.String("Error: mo filename provided."); context.error.String(filename); context.error.Ln;
+	END;
+END DoFile;
+
+
 (** Sequentially execute a list of commands .
 (** Sequentially execute a list of commands .
 IMPORTANT: This command is specially handled by command interpreters that support it. It is the only command
 IMPORTANT: This command is specially handled by command interpreters that support it. It is the only command
 in the system for which two tilde characters (only separated by whitespace) are used to delimit the parameter string.
 in the system for which two tilde characters (only separated by whitespace) are used to delimit the parameter string.

+ 2 - 0
source/Traps.Mod

@@ -65,6 +65,8 @@ VAR
 				-14:	(* page fault *)
 				-14:	(* page fault *)
 					IF (int.CS MOD 4 > Machine.KernelLevel) & (exc.pf+4 = int.SP) THEN
 					IF (int.CS MOD 4 > Machine.KernelLevel) & (exc.pf+4 = int.SP) THEN
 						w.String("stack overflow"); overflow := TRUE
 						w.String("stack overflow"); overflow := TRUE
+					ELSE
+						w.String("memory access violation (page fault)");
 					END
 					END
 				|0: w.String("division error")
 				|0: w.String("division error")
 				|1: w.String("WITH guard failed")
 				|1: w.String("WITH guard failed")