Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/kozeris/RVM.git

  • Loading branch information...
commit e661da65190a5eaa1705449c4fb967e9b44800f6 2 parents 7964cd8 + ff97723
ernestas authored
View
8 nbproject/private/private.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
- <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
-</project-private>
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
View
91 src/Tests/SWAPTest.java
@@ -0,0 +1,91 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package Tests;
+
+import com.sun.corba.se.impl.orbutil.closure.Constant;
+import java.io.*;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import rvm.*;
+
+/**
+ *
+ * @author lukas
+ */
+public class SWAPTest {
+
+ public static void main(String[] args) {
+
+ Word w = new Word("op");
+ Word ubaba = null;
+ ObjectOutputStream outputStream;
+ try {
+ outputStream = new ObjectOutputStream(new FileOutputStream("src/test.t"));
+ outputStream.writeObject(w);
+ outputStream.flush();
+ outputStream.close();
+ } catch (IOException ex) {
+ Logger.getLogger(SWAPTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ try {
+ ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("src/test.t"));
+ ubaba = (Word) inputStream.readObject();
+ inputStream.close();
+ } catch (IOException |
+ ClassNotFoundException ex) {
+ Logger.getLogger(SWAPTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ System.out.println(ubaba);
+
+ Memory mem = new ExternalMemory(0xFFF);
+ int blocks = 5;
+ int memSize = blocks * Constants.BLOCK_SIZE;
+ ExternalMemory exMem = new ExternalMemory(0xFFFF);
+ VirtualMemorySWAP vm = new VirtualMemorySWAP(new Word(0xFF), mem, exMem);
+ vm.setSize(memSize);
+ mem.writeWord(0xFF, new Word(0x0));
+ for (int i = 0; i < blocks; i++) {
+ if (i > 3) {
+ i = i + 5;
+ }
+ int val = i + 0x10;
+ exMem.writeWord((i > 3) ? i - 5 : i, new Word(val));
+ for (int j = val * 0x10; j < val * 0x10 + Constants.BLOCK_SIZE; j++) {
+ exMem.writeWord(j, new Word(0x555));
+ }
+ }
+ //print(exMem);
+ /*
+ * for (int i = 0; i < memSize; i++){ vm.writeWord(i, new Word(0x200));
+ * }
+ */
+ for (int i = 0; i < memSize; i++) {
+ System.out.print(Integer.toHexString(i) + " " + Integer.toHexString(vm.readWord(i).toInt()) + " ");
+ if (i % 0x10 == 0) {
+ System.out.println();
+ }
+ }
+ System.out.println("*********************************************************************");
+ System.out.println("*******************Real mem******************************************");
+ System.out.println("*********************************************************************");
+ print(exMem);
+ }
+
+ public static void print(ExternalMemory mem) {
+ for (int i = 0x00; i < 0xFF; i++) {
+ System.out.print(Integer.toHexString(i).toUpperCase() + "_: ");
+ for (int j = 0x0; j <= 0xF; j++) {
+ System.out.print(Integer.toHexString(mem.readWord(i * 0x10 + j).toInt()) + " ");
+ }
+ System.out.println();
+ }
+ /*
+ * for (int i=0x000; i< MEMORY_SIZE-1; i++) {
+ * System.out.println(Integer.toHexString(i).toUpperCase() + " " +
+ * mem.readWord(i)); }
+ */
+ }
+}
View
BIN  src/memory.mem
Binary file not shown
View
58 src/rvm/ExternalMemory.java
@@ -1,10 +1,6 @@
package rvm;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
+import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -19,21 +15,57 @@
public ExternalMemory() {
super();
+ readExternalMemory();
+ }
+
+ public ExternalMemory(int size) {
+ super(size);
+ writeExternalMemory();
+ }
+
+ @Override
+ public Word readWord(int absAddress) {
+ readExternalMemory();
+ return super.readWord(absAddress);
+ }
+
+ @Override
+ public void writeWord(int absAddress, Word data) {
+ super.writeWord(absAddress, data);
+ writeExternalMemory();
+ }
+
+ private void setInputStream() throws IOException {
+ inputStream = new ObjectInputStream(new FileInputStream("src/memory.mem"));
+ }
+
+ private void setOutputStream() throws FileNotFoundException, IOException {
+ outputStream = new ObjectOutputStream(new FileOutputStream("src/memory.mem"));
+ }
+
+ private void closeInputStream() throws IOException {
+ inputStream.close();
+ }
+
+ private void closeOutputStream() throws IOException {
+ outputStream.close();
+ }
+
+ private void readExternalMemory() {
try {
- memory = (Word[])inputStream.readObject();
- } catch (IOException ex) {
- Logger.getLogger(ExternalMemory.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
+ setInputStream();
+ memory = (Word[]) inputStream.readObject();
+ closeInputStream();
+ } catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(ExternalMemory.class.getName()).log(Level.SEVERE, null, ex);
}
}
- public ExternalMemory(int size) {
- super(size);
+ private void writeExternalMemory() {
try {
- outputStream = new ObjectOutputStream(new FileOutputStream("src/momory.mem"));
+ setOutputStream();
outputStream.writeObject(memory);
- outputStream.close();
+ outputStream.flush();
} catch (IOException ex) {
Logger.getLogger(ExternalMemory.class.getName()).log(Level.SEVERE, null, ex);
}
View
3  src/rvm/Memory.java
@@ -62,7 +62,6 @@ public int getSize() {
public Word readWord(int absAddress) {
// FIXME uzejimas uz ribu
if (memory[absAddress] == null) {
- //testinimui
return new Word(0);
}
return memory[absAddress];
@@ -95,7 +94,7 @@ public void writeWord(int absAddress, Word data) {
* @param data irasomas zodis
*/
public void writeWord(Word absAddress, Word data) {
- memory[absAddress.toInt()] = data;
+ writeWord(absAddress.toInt(), data);
}
/**
View
12 src/rvm/VirtualMemorySWAP.java
@@ -16,7 +16,7 @@ public VirtualMemorySWAP(Word PTR, Memory rMemory, Memory eMemory) {
@Override
public Word readWord(int track, int word) {
if (pageTableAddress.toInt() > PT_SIZE){
- return new Word(0);
+ return new Word(externalMemory.readWord(getExternalAbsoluteAddress(track, word)).toString());
}else{
return super.readWord(track, word);
}
@@ -30,9 +30,17 @@ public Word readWord(int track, int word) {
@Override
public void writeWord(int track, int word, Word data) {
if (pageTableAddress.toInt() > PT_SIZE){
- //įrašo į išorinę atmintį
+ externalMemory.writeWord(getExternalAbsoluteAddress(track, word), data);
}else{
super.writeWord(track, word, data);
}
}
+
+ private int getExternalAbsoluteAddress(int track, int word) {
+ Word externalPageTableAddress = realMemory.readWord(pageTableAddress);
+ Word absoluteTrack = externalMemory.readWord(externalPageTableAddress.toInt() + track);
+ int absoluteAddress = absoluteTrack.toInt()*0x10 + word;
+ return absoluteAddress;
+ }
+
}
View
22 src/rvm/Word.java
@@ -1,6 +1,6 @@
package rvm;
-import java.io.Serializable;
+import java.io.*;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import static rvm.Constants.*;
@@ -12,12 +12,11 @@
* @author Ernestas Prisakaru
* @author Lukas Ignatavicius
*
- *
- * Word.java
- * Word objektas saugo 4 baitu ilgio ByteBuffer'i (tarkim masyva)
+ *
+ * Word.java Word objektas saugo 4 baitu ilgio ByteBuffer'i (tarkim masyva)
* Klase suteikia konversijos i ivairius tipus galimybes.
*/
-public class Word implements Serializable{
+public class Word implements Serializable {
private ByteBuffer word;
@@ -116,4 +115,17 @@ public int toInt() {
public String toString() {
return new String(this.toByteArray());
}
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.writeObject(this.toByteArray());
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ Object ob = ois.readObject();
+ if (ob != null) {
+ byte[] bytes = (byte[]) ob;
+ word = ByteBuffer.allocateDirect(WORD_SIZE);
+ this.word.put(bytes);
+ }
+ }
}
View
BIN  src/test.t
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.