Skip to content

cassamb/shark-os

Repository files navigation

Shark OS

Static Badge

This is a high-level Java program that simulates the operation of the fictional "Shark Machine" and the accompanying "SharkOS" that coordinates its function.

Methodology

By definition, the OS is responsible for controlling and coordinating the use of the hardware among the various user application programs. This level of complexity implies large amounts of code, and the best way to manage that is through the implementation of modules or functions. This separation implies increased reliability because the failure of one module does not equate to the failure of the entire system. Furthermore, in the event a module does fail, chunking allows for easier identification of errors within the code or algorithm.

There are 3 main aspects of the simulation that transfer control in the following order:

  1. Shark Machine
  2. main() Function
  3. SharkOS

The booting sequence was implemented in this way to allow the Shark Machine time to initialize its components before running the SharkOS. In this case, the main() function is treated as a small time buffer. The run_OS() function (which runs the operating system) is abstract in that it pushes the complexity to its modules and calls on those modules when needed.

Limitations

In order for a computer to function well, its operating system must have constant and transparent communication with the hardware that lies beneath it. One of the biggest issues during the development of the simulation was maintaining a consistent line of contact from the SharkOS to the Shark Machine no matter where in the program the contact was being requested. The implementation was modular; therefore, making the components of the Shark Machine global variables of the SharkOS class was a viable solution. Therefore, in this implementation, the components of the Shark Machine (e.g., the long-term queue, short-term queue, timer, END instruction, etc.) were defined as global data structures within the SharkOS class. The idea was to keep the components of the SharkOS (software) as modular as possible while maintaining a constant line of communication with the concise Shark Machine (hardware).

Design

Data

In theory, the work of the Shark Machine is executed primarily at the time of booting and the termination of the programs. On the other hand, the CPU (which the OS is responsible for) is tasked with fetching, decoding, and executing instructions. In other words, the SharkOS is burdened with more complexity than the Shark Machine. Although the Shark Machine only has a few methods and components, they are referenced constantly throughout the lifetime of the simulation. So, rather than generating additional overhead through the creation of a separate class and instantiating an object of that class for such little information, the components on the Shark Machine were declared as global.

Fetch-Decode-Execute

  1. Fetch the instructions.
  2. Decode the instruction (by assigning the data to memory).
  3. Execute the instruction using the data stored into memory.
Name Data Type Description
memory int[] Array 1024-element array used to simulate primary memory (short term memory) of the Shark Machine.
job_queue int[] Array 6-element array used to simulate long-term memory in which jobs are initially loaded at system boot up.
pcb_offset int Variable used to assist in the calculation of the first index of PCB for each specific job loaded into long-term memory.
job_offset int Variable used to assist in the calculation of the first index of PCB for each specific job loaded into long-term memory.
second int Variable used to reflect timer count; incremented by 1 every second.
timer Timer Class Object Instance of Timer class which is used to instantiate a timer for the system clock which serves as the basis of timer runout.
OS_task TimerTask Class Object Instance of TimerTask class which is used to instantiate a timer task for the system clock which serves as the basis of timer runout.
run() TimerTask Function Function that uses the timer to load jobs into main memory based on their respective arrival times. The function compares the current time to the arrival time of jobs in the long-term queue and loads the jobs into memory if they match.
jobNum int Variable that serves as the index of the current job being observed in the job_queue.

Architecture

Memory Model

This refers to the information to be received from the programs (including elements of the PCB and program instructions) are concentrated at the beginning and end of the primary memory array.

0 PCBs Program Data (Read, Write, Store) Loaded Instructions
1 - 42 43 - 826 827 - 1023

Fig. 1 Overview of primary memory distribution. The first index is 0 which serves as an “emergency register” in the event that the main memory reaches full capacity. Indices 1-42 are representative of the PCBs for at most 6 programs. Indices 43-826 are reserved for results of ALU computations. Indices 827-1023 are reserved for job instructions.

PCB
Process ID
ACC
PSIAR
SAR
SDR
TMPR
CSIAR

Fig. 2 This is a 7-element representaion of a single PCB in memory.

0 prog1 prog2 prog3 prog4 prog5 prog6
0 1 - 7 8 - 14 15 - 21 22 - 28 29 - 35 36 - 42

Fig. 3 This is a representation of each of the 6 PCBs in memory with their respective and reserved indices.

Instruction Loading Model

Each program is given 32 registers (indices) to input their instructions into memory.

0 ... prog6 prog5 prog4 prog3 prog2 prog1
0 1 - 826 827 - 859 860 - 892 893 - 925 926 - 958 959 - 991 992 - 1023

Fig. 4 This is the representation of each of the 6 programs that can be running at once in memory.

Class and Object Modules

Method Description
run_SharkOS() Function that acts as the simulation of the SharkOS; Highly abstract.
QUEUE_JOBS() Function that loads the program files into the job_queue[]
runOSTimer() Function that starts the OS timer.
CREATE_PCB() Function that declares initial values for registers in 6 PCBs with unique identifier in first index.
LOAD_JOBS(String job_file) Function that takes program file, extracts the code, decodes the instructions, loads them into memory.
CONVERT(String instruction) Function that takes an instruction, converts the string operator into its respective opcode, strips the instruction of spaces, converts the string into an integer, and returns the value back to LOAD_JOBS();

About

A high-level Java program which simulates the operation of the “Shark Machine” (the hardware component) via a rudimentary “SharkOS” (the software component) that has multitasking capabilities. It was originally commissioned by Nova Southeastern University in 2022 as part of the CSIS 3810 Operating Systems Concepts course curriculum.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages