-
Notifications
You must be signed in to change notification settings - Fork 2
/
os.hpp
115 lines (88 loc) · 2.7 KB
/
os.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* os.hpp
*
* Baker, Ballard, Jager-Kujawa
* CSC 341
* Spring 2016
*/
#include <string> // string
#include <queue> // queue
#include <iostream> // cout, cerr
#include <iomanip> // boolalpha, setw, setfill, hex, dec, endl
#include <sstream> // sstream
#include "machine.hpp"
#include "fsys.hpp"
#include "utils.hpp"
using namespace std;
#ifndef OS
#define OS
extern string systemStats;
extern FSYS fileSystem;
extern FrameTable framesInUse;
//extern FrameTable framesLocked;
#define LOCKED true
#define UNLOCKED false
// Define the user struct
enum userID {sys, u1, u2, noID};
struct User {
userID id;
int time;
User() : id(noID), time(0) {}
User(userID uid) : id(uid), time(0) {}
};
struct Process {
int pid;
string pname;
User *user;
bool running;
registers regs;
Process(string name, int id, User *uid) : pid(id), pname(name), user(uid),
running(false), regs(registers(0, 0, 0, 0, 61440, 0, 0)) {}
string toString() {
stringstream ss;
ss << (user->id == 0 ? "SYS" : ("U" + itos(user->id))) << " \"" << pname
<< "\" process with PID : " << pid << endl;
ss << "\trA: " << regs.rA << ", r1: " << regs.r1 \
<< ", r2: " << regs.r2 << ", r3: " << regs.r3 << endl;
ss << "\tIR: " << regs.IR << ", PC: " << regs.PC \
<< ", CR: " << regs.CR << endl;
ss << "\tRunning: " << boolalpha << running << endl << endl;
if (regs.PTBR) {
ss << endl << "Page Table:" << endl;
ss << regs.PTBR->toString() << endl << endl;
}
return ss.str();
}
};
extern User U1, U2, SYS;
extern Process* currentProcess;
#define READY 1
#define BLOCKED 0
// Dump contents of main memory and all registers
void dump();
// Dump everything (to be called only on STP)
void fulldump();
// Print the contents of a queue, with a header containing the queue name
//void printQueue(string queueName, queue<User> &q,int num);
// Print the contents of a queue
//void printQueue(queue<User> &q,int num);
// Print all process control blocks
void printAllProcs();
// Loads the file into a new PCB and returns a pointer to the new Process.
// Takes the user by reference, as well as the cmdline entry the user entered.
// cmdline entry is split into cmd and args on the first encountered whitespace.
Process* loader(User& currentUser, string pname);
// Round-robin scheduler, 3 ticks per user
void scheduler();
// The user interface, prompting for input
void userinterface();
// Convert a string command (run, dmp, etc) into an int that can be used
// in a switch case statement.
int cmdToInt(string);
// Initialize all values required by the OS
void init();
// Main function (starts the OS)
int main();
// Convert process queue to string
string qtos(queue<Process*>);
#endif