Modestus Moon OS  R4
CS 450 project
mpx_supt.c
Go to the documentation of this file.
1 #include <core/mpx_supt.h>
2 #include <mem/heap.h>
3 
4 #include <core/pcb.h>
5 
8 void* (*student_malloc)(size_t);
9 int (*student_free)(void *);
10 
11 int sys_req( int op_code )
12 {
13  params.op_code = op_code;
14  asm volatile ("int $60");
15  return 0;
16 }
17 
18 void mpx_init(int cur_mod)
19 {
20  current_module = cur_mod;
21 }
22 
23 void sys_set_malloc(void* (*func)(size_t))
24 {
25  student_malloc = func;
26 }
27 
28 void sys_set_free(int (*func)(void *))
29 {
30  student_free = func;
31 }
32 
33 void *sys_alloc_mem(u32int size)
34 {
36  return (void *) kmalloc(size);
37  else
38  return (void *) (*student_malloc)(size);
39 }
40 
41 int sys_free_mem(void *ptr)
42 {
44  return (*student_free)(ptr);
45  // otherwise we don't free anything
46  return -1;
47 }
48 
49 void idle()
50 {
51  serial_println("\r\n\033[38;2;255;0;255mIn Idle Process\033[38;2;255;255;255m\r\n");
52  do {
53  sys_req(IDLE);
54  serial_println("\r\n\033[38;2;255;0;255mIn Idle Process\033[38;2;255;255;255m\r\n");
55  }while(readyQueue.head.next != &(readyQueue.tail));
56  serial_println("No More ready processes, IDLE is exiting");
57  sys_req(EXIT);
58 }
59 
61 
63 {
65  {
66  if(params.op_code == IDLE)
67  {
68  currentOperatingProcess->stackTop = (processStack_t*)context;
69  currentOperatingProcess->processState = READY;
71  }
72  else if(params.op_code == EXIT)
73  {
75  }
76  }
77  else
78  {
79  callerContext = context;
80  }
81  if(readyQueue.head.next != &readyQueue.tail)
82  {
83  if(removePCB(currentOperatingProcess = (pcb_t*)readyQueue.head.next->data) == SUCCESS)
84  {
85  currentOperatingProcess->processState = RUNNING;
86  return (uint32_t*)currentOperatingProcess->stackTop;
87  }
88  else
89  {
90  kpanic("Could Not remove COP from ready Queue!!!!!");
91  }
92  }
93 
94  return (uint32_t*)callerContext;
95 
96 }
97 
void *(* student_malloc)(size_t)
Definition: mpx_supt.c:8
Definition: pcb.h:47
Definition: pcb.h:47
linkedList_t readyQueue
Definition: pcb.c:3
void kpanic(const char *msg)
Definition: system.c:24
int sys_free_mem(void *ptr)
Definition: mpx_supt.c:41
u32int kmalloc(u32int size)
Definition: heap.c:52
void mpx_init(int cur_mod)
Definition: mpx_supt.c:18
uint32_t * sys_call(processContext_t *context)
sys_call
Definition: mpx_supt.c:62
pcb_t * currentOperatingProcess
Definition: pcb.c:9
The s_processContext struct defines the context that each process stores .
Definition: system.h:71
#define EXIT
Definition: mpx_supt.h:6
Definition: pcb.h:38
typedef for pcb_t struct
void insertPCB(pcb_t *pcbToInsert)
insertPCB insert the PCB into the queue represented by the process state, following each queue&#39;s rule...
Definition: pcb.c:132
e_PCB_ERROR_CODE_t freePCB(pcb_t *pcbToFree)
freePCB free all associated memory with the PCB, including the stack and other pointers ...
Definition: pcb.c:32
int op_code
Definition: mpx_supt.h:19
#define MODULE_R5
Definition: mpx_supt.h:15
uint8_t processStack_t
processStack_t a pointer to someplace in a process&#39;s stack
Definition: pcb.h:102
e_PCB_ERROR_CODE_t removePCB(pcb_t *pcbToRemove)
removePCB remove the input PCB from its associated queue
Definition: pcb.c:162
processContext_t * callerContext
Definition: mpx_supt.c:60
Definition: mpx_supt.h:18
void sys_set_free(int(*func)(void *))
Definition: mpx_supt.c:28
unsigned long uint32_t
Definition: system.h:31
int serial_println(const char *msg)
Definition: serial.c:44
int sys_req(int op_code)
Definition: mpx_supt.c:11
param params
Definition: mpx_supt.c:6
unsigned int size_t
Definition: system.h:24
int current_module
Definition: mpx_supt.c:7
unsigned long u32int
Definition: system.h:27
#define IDLE
Definition: mpx_supt.h:7
void * sys_alloc_mem(u32int size)
Definition: mpx_supt.c:33
void idle()
Definition: mpx_supt.c:49
int(* student_free)(void *)
Definition: mpx_supt.c:9
void sys_set_malloc(void *(*func)(size_t))
Definition: mpx_supt.c:23