-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.cpp
83 lines (74 loc) · 1.87 KB
/
shell.cpp
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
//
// Author: Osayamen Aimuyo
// Created: 1/29/2023.
//
#include <iostream>
#include <unistd.h>
#include <thread>
#include "computer/computer.h"
#include "computer/print.h"
#include "scheduler/scheduler.h"
#include "utility/utility.h"
#include "memory/memory.h"
#include "shell/shell.h"
bool shouldTerminate;
void shell_main(){
int command;
int sleep_time = 10000;
while(!shouldTerminate){
atomically_print_to_stdout("Enter Command>");
if(!(std::cin >> command)){
break;
}
shell_command(command);
usleep(sleep_time);
}
}
void shell_init(){
shouldTerminate = false;
std::thread shell (shell_main);
shell.detach();
}
void shell_command(int cmd){
std::string prog_file_name;
MemoryMetadata m{};
switch (cmd) {
case 0:
shouldTerminate = true;
terminateFlag = true;
break;
case 1:
atomically_print_to_stdout("Input Program File>");
std::cin >> prog_file_name;
m = load_prog(const_cast<char*>(prog_file_name.c_str()));
if(!m.isOutOfMemory){
process_submit(prog_file_name, m);
atomically_print_to_stdout("Submitted fname->"
+ prog_file_name + "}");
}
else{
atomically_print_to_stdout("OutOfMemory: Release memory and retry");
}
break;
case 2:
shell_print_registers();
break;
case 3:
shell_print_memory();
break;
case 4:
process_dump_readyQ();
break;
case 5:
process_dump_PCB();
break;
default:
break;
}
}
void shell_print_registers(){
cpu_dump_registers();
}
void shell_print_memory(){
mem_dump_secondary_memory();
}