62
The Minimal Instruction Set Computer (MISC) in Java: Demonstration of Operating System Concepts Kirk Scott Computer Science The University of Alaska Anchorage 1

The Minimal Instruction Set Computer (MISC) in Java: Demonstration of Operating System Concepts

Embed Size (px)

DESCRIPTION

The Minimal Instruction Set Computer (MISC) in Java: Demonstration of Operating System Concepts. Kirk Scott Computer Science The University of Alaska Anchorage. Overall Plan of Overheads. These overheads fall into 3 sections: 1. An explanation of MISC in general - PowerPoint PPT Presentation

Citation preview

Page 1: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

1

The Minimal Instruction Set Computer (MISC) in Java:

Demonstration of Operating System Concepts

Kirk ScottComputer Science

The University of Alaska Anchorage

Page 2: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

2

These overheads fall into 3 sections: 1. An explanation of MISC in general 2. Modifications to MISC 3. What is the Point of This?

Overall Plan of Overheads

Page 3: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

3

1. An explanation of MISC in general

Page 4: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

4

MISC is a Java simulation of a simple CPU The simulation includes a simple machine

language Machine programs can be written in this

language

An Introduction to MISC

Page 5: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

5

MISC contains a simple operating system The operating system functions are

written in Java as part of the simulation In MISC, absolute machine code is loaded

at memory address 0 and executed there Program loading and execution in MISC

can be modified in several ways

Page 6: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

6

Bytes and registers Bytes, words, and memory General remarks on machine instruction

execution Fetch, decode, and execute The machine language instruction set

The Basic Structure of MISC

Page 7: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

7

General remarks on the form of machine language

An example program The Java methods comprising the simulation The command line interface A summary of the structure of the Java

simulation by class, constructor, and method

The Basic Structure, Continued

Page 8: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

8

The MISC architecture makes use of 4 byte words

The contents of a register are modeled by an object containing a character array of 8 bytes

Bytes and Registers

Page 9: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

9

Each bit is modeled by the presence of the character ‘1’ or the character ‘0’ in a position in an 8 byte array

The registers are packaged together in an array named “reg”

The index of the array identifies the particular register

Page 10: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

10

Registers:

register name decimal index binary code identification in reg array of index   unused reg[0] "00000000"   general purpose   A reg[1] "00000001" B reg[2] "00000010" C reg[3] "00000011" D reg[4] "00000100"  

Page 11: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

11

Registers, cont’d.:

register name decimal index binary code identification in reg array of index

memory offsets   codeoffsetreg[5] "00000101" dataoffset reg[6] "00000110" unused1 reg[7] "00000111" unused2 reg[8] "00001000" unused3 reg[9] "00001001"   flag reg[10] "00001010"  

Page 12: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

12

Registers, cont’d.:

register name decimal index binary code identification in reg array of index

control unit registers   instruction reg[11] "00001011" operand1 reg[12] "00001100" operand2 reg[13] "00001101" extrareg[14] "00001110"

ALU registers   aluinreg1 reg[15] "00001111" aluinreg2 reg[16] "00010000" aluoutreg reg[17] "00010001"

Page 13: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

13

A word in MISC consists of 4 bytes Memory is implemented as an array of

words The index of the array is the word offset into

memory   Memory: array name memory[]

Bytes, Words, and Memory

Page 14: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

14

These are the general rules for move and arithmetic instructions◦ A register or a memory variable can be a

destination◦ A constant, a register, or a memory variable can

be a source◦ Memory to memory operations are not allowed

General Remarks on Machine Instruction Execution

Page 15: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

15

A program is loaded to memory location 0 by default

The machine takes control of execution The machine steps through the program

code until it encounters an empty (“00000000”) instruction byte

Fetch, Decode, and Execute

Page 16: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

16

Execution starts with the value 0 in the code offset register

The next 4 contiguous bytes of code memory are put into the instruction, operand1, operand2, and extra registers

After the retrieval of each instruction the code offset is incremented for the next retrieval

Page 17: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

17

The MOVE Instruction assembly instruction method in simulation machine instruction MOVE register, register void moveDestRegSrcReg() “10000001” MOVE memory, register void moveToMemFromReg() “10000010” MOVE register, memory void movetoregfrommem() “10000011” MOVE memory, constant void movetomemfromconst() “10000100” MOVE register, constant void movetoregfromconst() “10000101”

The Machine Language Instruction Set

Page 18: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

18

The ADD Instruction assembly instruction method in simulation machine instruction   ADD register, register void addDestRegSrcReg() “10000110” ADD memory, register void addToMemFromReg() “10000111” ADD register, memory void addToRegFromMem() “10001000” ADD memory, constant void addToMemFromConst() “10001001” ADD register, constant void addToRegFromConst() “10001010”

Page 19: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

19

The SUB Instruction assembly instruction method in simulation machine instruction SUB register, register void subDestRegSrcReg() “10001011” SUB memory, register void subFromMemSrcReg() “10001100” SUB register, memory void subFromRegSrcMem() “10001101” SUB memory, constant void subFromMemSrcConst() “10001110” SUB register, constant void subFromRegSrcConst() “10001111”

Page 20: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

20

The JUMP Instruction assembly instruction method in simulation machine instruction JMP unsigned integer void jumpUnconditional() “10010000” JPOS unsigned integer void jumpOnPositive() “10010001” JNEG unsigned integer void jumpOnNegative() “10010010” JZERO unsigned integer void jumpOnZero() “10010011” JOVER unsigned integer void jumpOnOverflow() “10010100”

Page 21: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

21

The data declarations come first, then the program code

The program will be loaded at offset 0 Words 0-7 are reserved for data variables

and will be filled with 0’s if there are not that many variables

No program, including data, can be longer than 31 lines

The source file signals termination with a row of asterisks

General Remarks on the Form of Machine Language

Page 22: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

22

Data Declaration Line Byte 1: value Bytes 2-4: unused Line of Code Byte 1: instruction Byte 2: operand 1 Byte 3: operand 2 Byte 4: unused

Page 23: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

23

The example is a machine language program that sums the first 10 integers

The machine language alone with artificial line breaks and segment labels follows

The *’s are used on input to detect the end of the program.

An Example Machine Language Program

Page 24: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

24

data segment   00001011000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000

Page 25: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

25

code segment   10000101000001000000000100000000 10000111000000010000010000000000 10001010000001000000000100000000 10000011000000110000000000000000 10001011000000110000010000000000 10010001000010010000000000000000 ********************************

Page 26: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

26

/.DATA///

00001011 00000000 00000000 00000000   /LOOPLIM/X0B// loop limit offset 0, value 11   00000000 00000000 00000000 00000000 /ACCUM/X00// accumulator offset 1, value 0

The Example Program Data Segment with Assembly Language Guide

Page 27: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

27

/.CODE///

10000101 00000100 00000001 00000000   /MOVE/D/X01/ move reg D, const 1 movetoregfromconst 4, 1   /.LABEL/LOOPTOP//   10000111 00000001 00000100 00000000 /ADD/ACCUM/D/ (LABEL) add data offset 1, reg D addtomemfromreg 1, 4

The Example Program Code Segment with Assembly Language Guide

Page 28: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

28

10001010 00000100 00000001 00000000 /ADD/D/X01/ add reg D, 1 addtoregfromconst 4, 1   10000011 00000011 00000000 00000000 /MOVE/C/LOOPLIM/ move reg C, data offset 0 movetoregfrommem 3, 0

Page 29: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

29

10001011 00000011 00000100 00000000 /SUB/C/D/ sub reg C, reg D subtractdestregsrcreg 3, 4

10010001 00001001 00000000 00000000   /JPOS/LOOPTOP// Since space is reserved for 8 variables, the first instruction

comes at word 8. jump on positive to “LABEL” jumponpositive 9   ******** ******** ******** ******** /.END///

Page 30: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

30

The simulation consists of 4 java files:◦ MachineWord.java◦ Machine.java◦ Osystem.java◦ MachineOSProgram.java

MachineOSProgram contains main()

The Java Files Comprising the Simulation

Page 31: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

31

MISC presents these 3 command prompts: rpf (run program file) dmc (dump memory contents) exit

The Command Line Interface

Page 32: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

32

rpf = run program file This prompts the user for the machine

language program to run Machine language programs should be text

files

rpf

Page 33: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

33

dmc = dump machine contents This prompts the user for the name of the

output file to create This should be a text file MISC has no I/O capabilities You know what a program did by looking at

the dmc file

dmc

Page 34: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

34

exit = quit the simulation

exit

Page 35: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

35

MachineByte.java MachineWord.java

Machine.java This is the heart of the simulation It contains these critical methods:

◦ totalReset()◦ resetOffsets()◦ takeControl()

A Summary of the Structure of the Java Simulation by Class, Constructor, and Method

Page 36: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

36

Osystem.java This has a constructor in which a copy of

the Machine is constructed It contains these critical methods:

◦ runProgramFile()◦ dumpMemoryContents()

Page 37: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

37

MachineOSProgram.java This contains the main() method It is the simulation driver In it a copy of the Osystem is constructed It loops, checking for user input from the

command prompt

Page 38: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

38

MyTerminalIO This presents the command prompt in a

graphical user interface

Page 39: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

39

MISC can be modified to illustrate these operating system concepts:◦ Memory allocation◦ Absolute code◦ Relative code◦ Concurrency and scheduling

2. Modifications to MISC

Page 40: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

40

By default, programs in MISC are loaded and executed at address 0 in memory

The following overhead shows a dmc file after running the example program

Page 41: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

41

memory contents 00001011000000000000000000000000 00110111000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 10000101000001000000000100000000 10000111000000010000010000000000 10001010000001000000000100000000 10000011000000110000000000000000 10001011000000110000010000000000 10010001000010010000000000000000 00000000000000000000000000000000 …

Page 42: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

42

Here are three possible modifications to MISC:

1. Load machine programs at addresses other than 0◦ Modify relative code to absolute code for a non-

zero address 2. Load machine programs at addresses

other than 0 with dynamic address checking◦ Load relative code and modify the simulation to

check memory accesses

Modifications to MISC Which Illustrate Operating System Concepts

Page 43: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

43

3. Load and run more than one machine program at a time◦ This builds on modification 2◦ Memory accesses for each loaded program have

to be correctly handled◦ Execution of multiple programs also involves

scheduling

Page 44: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

44

Support program loading at an address other than 0

Alter the machine program code at load time Memory address references are changed to

correspond with the load address The loaded program is absolute code for the

new address The following overhead shows a dmc file after

running the example program with these modifications

Modification 1

Page 45: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

45

memory contents 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 … 00001011000000000000000000000000 00110111000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 10000101000001000000000100000000 10000111001000010000010000000000 10001010000001000000000100000000 10000011000000110010000000000000 10001011000000110000010000000000 10010001001010010000000000000000 00000000000000000000000000000000 …

Page 46: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

46

Support program loading at an address other than 0

Do not alter the machine program code at load time

A machine language program is loaded to an address other than 0

The machine code is relative code

Modification 2

Page 47: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

47

Each time the running machine program wants to do a memory access, it returns the relative address in the machine code to the operating system

The operating system checks to see if it’s within range

Page 48: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

48

The operating system adds the memory access to the base address where the program was loaded

The operating system passes this absolute address back to the machine for program memory access

The following overhead shows a dmc file after running the example program with these modifications

It looks no different from the previous modification

Page 49: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

49

memory contents 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 … 00001011000000000000000000000000 00110111000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 10000101000001000000000100000000 10000111001000010000010000000000 10001010000001000000000100000000 10000011000000110010000000000000 10001011000000110000010000000000 10010001001010010000000000000000 00000000000000000000000000000000 …

Page 50: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

50

Modify MISC to load and run more than one machine language program concurrently

Round robin scheduling can be implemented Instead of time-slicing, use instruction counts Switch between from one machine program

to another when it has executed a fixed number of instructions

Note that threading of command prompt input is necessary to accomplish this

Modification 3

Page 51: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

51

The following overhead shows a dmc file taken midstream while two copies of the machine language program are running

It illustrates that concurrency is taking place Look at the second data variable, the

accumulator Both programs have non-zero totals Neither program has yet reached the final

value of 00110111

Page 52: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

52

memory contents 00001011000000000000000000000000 00011100000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 10000101000001000000000100000000 10000111000000010000010000000000 10001010000001000000000100000000 10000011000000110000000000000000 10001011000000110000010000000000 10010001000010010000000000000000 00000000000000000000000000000000 … 00000000000000000000000000000000 00001011000000000000000000000000 00001010000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 10000101000001000000000100000000 10000111000000010000010000000000 10001010000001000000000100000000 10000011000000110000000000000000 10001011000000110000010000000000 10010001000010010000000000000000 00000000000000000000000000000000 …

Page 53: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

53

MISC and the modifications given are used as part of a course on operating systems

Students are given the original version of MISC and do the modifications as assignments

Because MISC is written in Java, the students program their solutions by writing Java code

Students can work on operating system concepts without having to work with kernel code of a live operating system

3. What is the Point of This?

Page 54: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

54

MISC as is, or expanded and modified, could be used in other areas of computer science◦ Machine language coding◦ Other operating system concepts◦ Language translation◦ Machine level operating system implementation◦ Security exercises

Page 55: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

55

MISC could also be modified for additional purposes

Its machine language could be expanded It could then be used as a testbed for

machine language coding

Machine Language Coding

Page 56: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

56

MISC could be extended to cover other operating system concepts

For example, different scheduling algorithms could be implemented

Other Operating System Concepts

Page 57: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

57

MISC and its machine language could be used as part of an exercise in language translation

It would be possible to write an assembler for MISC

It would be possible to define a simple high-level language for MISC and write a compiler for it

Language Translation

Page 58: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

58

The MISC machine language could be extended

It could include memory operations It could include all operations needed in

order to support operating system functionality

Machine Level Operating System Implementation

Page 59: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

59

If this were done, a big conceptual jump would be possible

The operating system of MISC would not be Java code, Osystem

A complete operating system in MISC machine language could be written

Running the MISC simulation would consist of loading and running this machine language program

Page 60: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

60

If the previous step were taken, MISC would closely resemble a real operating system environment

It would then become possible to write malware for that environment

For example, it would become possible to write code which caused buffer overflows in the MISC operating system

Security Exercises

Page 61: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

61

The overall idea is this: A basic version of MISC exists The three basic modifications have been

developed MISC has potential for further development

in other areas

Conclusion

Page 62: The Minimal Instruction Set Computer (MISC) in  Java: Demonstration of Operating System Concepts

62

The End