summaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/comus/drivers/pit.h2
-rw-r--r--kernel/include/comus/fs.h4
-rw-r--r--kernel/include/comus/memory.h35
-rw-r--r--kernel/include/comus/procs.h159
-rw-r--r--kernel/include/comus/syscalls.h37
5 files changed, 105 insertions, 132 deletions
diff --git a/kernel/include/comus/drivers/pit.h b/kernel/include/comus/drivers/pit.h
index a7a111d..77f0a14 100644
--- a/kernel/include/comus/drivers/pit.h
+++ b/kernel/include/comus/drivers/pit.h
@@ -13,7 +13,7 @@
// how many time the pit has ticked
// not accurate time, good for spinning though
-extern uint64_t ticks;
+extern volatile uint64_t ticks;
uint16_t pit_read_divider(void);
void pit_set_divider(uint16_t count);
diff --git a/kernel/include/comus/fs.h b/kernel/include/comus/fs.h
index 048c7c5..e67b6fe 100644
--- a/kernel/include/comus/fs.h
+++ b/kernel/include/comus/fs.h
@@ -47,7 +47,7 @@ struct disk {
* @param buffer - the buffer to save data into
* @returns bytes read on success, negative fs error code in failure
*/
-int disk_read(struct disk *disk, size_t offset, size_t len, uint8_t *buffer);
+int disk_read(struct disk *disk, size_t offset, size_t len, void *buffer);
/**
* write data from a disk into a buffer
@@ -58,7 +58,7 @@ int disk_read(struct disk *disk, size_t offset, size_t len, uint8_t *buffer);
* @param buffer - the buffer to read from
* @returns bytes written on success, negative fs error code in failure
*/
-int disk_write(struct disk *disk, size_t offset, size_t len, uint8_t *buffer);
+int disk_write(struct disk *disk, size_t offset, size_t len, void *buffer);
enum file_type {
// regular file
diff --git a/kernel/include/comus/memory.h b/kernel/include/comus/memory.h
index 3b57324..588219e 100644
--- a/kernel/include/comus/memory.h
+++ b/kernel/include/comus/memory.h
@@ -97,11 +97,11 @@ mem_ctx_t mem_ctx_clone(mem_ctx_t ctx, bool cow);
void mem_ctx_free(mem_ctx_t ctx);
/**
- * Free a memory context
+ * Switch into a different memory context
*
- * @param ctx - pointer to the memory context
+ * @param ctx - the memory context
*/
-void free_mem_ctx(mem_ctx_t ctx);
+void mem_ctx_switch(mem_ctx_t ctx);
/**
* Allocates at least len bytes of memory starting at
@@ -126,17 +126,42 @@ void mem_unmapaddr(mem_ctx_t ctx, void *virt);
/**
* Allocate a single page of memory with the given paging structure
*
+ * @param ctx - the memory context
+ * @param lazy - if to lazy allocate pages (alloc on fault)
+ * @returns the vitural address aloocated or NULL on failure
+ */
+void *mem_alloc_page(mem_ctx_t ctx, bool lazy);
+
+/**
+ * Allocate a single page of memory at the given vitural address with the given paging structure
+ *
+ * @param ctx - the memory context
+ * @param virt - the vitural address to allocate at
+ * @param lazy - if to lazy allocate pages (alloc on fault)
* @returns the vitural address aloocated or NULL on failure
*/
-void *mem_alloc_page(mem_ctx_t ctx);
+void *mem_alloc_page_at(mem_ctx_t ctx, void *virt, bool lazy);
/**
* Allocate size_t amount of contiguous virtual pages with the given paging structure
*
+ * @param ctx - the memory context
+ * @param count - the number of pages to allocate
+ * @param lazy - if to lazy allocate pages (alloc on fault)
+ * @returns the address allocated or NULL on failure
+ */
+void *mem_alloc_pages(mem_ctx_t ctx, size_t count, bool lazy);
+
+/**
+ * Allocate size_t amount of contiguous virtual pages at a given virtural address with the given paging structure
+ *
+ * @param ctx - the memory context
* @param count - the number of pages to allocate
+ * @param virt - the vitural address to allocate at
+ * @param lazy - if to lazy allocate pages (alloc on fault)
* @returns the address allocated or NULL on failure
*/
-void *mem_alloc_pages(mem_ctx_t ctx, size_t count);
+void *mem_alloc_pages_at(mem_ctx_t ctx, size_t count, void *virt, bool lazy);
/**
* Free allocated pages with the given paging structure.
diff --git a/kernel/include/comus/procs.h b/kernel/include/comus/procs.h
index fe8cbee..80c4fe4 100644
--- a/kernel/include/comus/procs.h
+++ b/kernel/include/comus/procs.h
@@ -14,6 +14,16 @@
#include <comus/memory.h>
#include <lib.h>
+#define PCB_REG(pcb, x) ((pcb)->regs->x)
+#define PCB_RET(pcb) ((pcb)->regs->rax)
+#define PCB_ARG1(pcb) PCB_REG((pcb), rdi)
+#define PCB_ARG2(pcb) PCB_REG((pcb), rsi)
+#define PCB_ARG3(pcb) PCB_REG((pcb), rdx)
+#define PCB_ARG4(pcb) PCB_REG((pcb), rcx)
+
+/// process id
+typedef unsigned short pid_t;
+
/// process states
enum proc_state {
// pre-viable
@@ -33,71 +43,27 @@ enum proc_state {
N_PROC_STATES,
};
-/// process priority
-enum proc_priority {
- PROC_PRIO_HIGH,
- PROC_PRIO_STD,
- PROC_PRIO_LOW,
- PROC_PRIO_DEFERRED,
- // sentinel
- N_PROC_PRIOS,
-};
-
-/// process quantum length
-/// values are number of clock ticks
-enum proc_quantum {
- PROC_QUANTUM_SHORT = 1,
- PROC_QUANTUM_STANDARD = 3,
- PROC_QUANTUM_LONG = 5,
-};
-
-/// program section information
-struct proc_section {
- uint64_t length;
- uint64_t addr;
-};
-
-#define SECT_L1 0
-#define SECT_L2 1
-#define SECT_L3 2
-#define SECT_STACK 3
-#define N_SECTS 4
-#define N_LOADABLE 3
-
-/// pid type
-typedef unsigned short pid_t;
-
/// process control block
struct pcb {
- // process context
+ // metadata
+ pid_t pid;
+ struct pcb *parent;
+ enum proc_state state;
+ size_t priority;
+ size_t ticks;
+
+ // context
mem_ctx_t memctx;
struct cpu_regs *regs;
- // vm information
- struct proc_section sects[N_SECTS];
-
// queue linkage
struct pcb *next; // next PDB in queue
// process state information
- struct pcb *parent; // pointer to PCB of our parent process
- uint64_t wakeup; // wakeup time, for sleeping processes
- uint8_t exit_status; // termination status, for parent's use
-
- // process metadata
- pid_t pid; // pid of this process
- enum proc_state state; // process' current state
- enum proc_priority priority; // process priority level
- size_t ticks; // remaining ticks in this time slice
+ uint64_t wakeup;
+ uint8_t exit_status;
};
-#define PCB_REG(pcb, x) ((pcb)->regs->x)
-#define PCB_RET(pcb) ((pcb)->regs->rax)
-#define PCB_ARG(pcb, n) (((uint64_t *)(((pcb)->regs) + 1))[(n)])
-
-/// pcb queue structure
-typedef struct pcb_queue_s *pcb_queue_t;
-
/// ordering of pcb queues
enum pcb_queue_order {
O_PCB_FIFO,
@@ -108,6 +74,9 @@ enum pcb_queue_order {
N_PCB_ORDERINGS,
};
+/// pcb queue structure
+typedef struct pcb_queue_s *pcb_queue_t;
+
/// public facing pcb queues
extern pcb_queue_t pcb_freelist;
extern pcb_queue_t ready;
@@ -116,51 +85,40 @@ extern pcb_queue_t sleeping;
extern pcb_queue_t zombie;
/// pointer to the currently-running process
-extern struct pcb *current;
-
+extern struct pcb *current_pcb;
+/// pointer to the pcb for the 'init' process
+extern struct pcb *init_pcb;
/// the process table
extern struct pcb ptable[N_PROCS];
/// next avaliable pid
extern pid_t next_pid;
-/// pointer to the pcb for the 'init' process
-extern struct pcb *init_pcb;
-
-/// table of state name strings
-extern const char *proc_state_str[N_PROC_STATES];
-
-/// table of priority name strings
-extern const char *proc_prio_str[N_PROC_PRIOS];
-
-/// table of queue ordering name strings
-extern const char *pcb_ord_str[N_PCB_ORDERINGS];
-
/**
* Initialization for the process module
*/
void pcb_init(void);
/**
- * Allocate a PCB from the list of free PCBs
+ * allocate a PCB from the free list
+ *
+ * @returns 0 on success or non zero error code
*/
int pcb_alloc(struct pcb **pcb);
/**
- * Return a PCB to the list of free PCBs.
+ * free an allocted PCB back to the free list
*
- * @param pcb Pointer to the PCB to be deallocated.
+ * @param pcb - pointer to the PCB to be deallocated
*/
void pcb_free(struct pcb *pcb);
/**
- * Turn the indicated process into a Zombie. This function
- * does most of the real work for exit() and kill() calls.
- * Is also called from the scheduler and dispatcher.
+ * turn the indicated process into a zombie
*
* @param pcb - pointer to the newly-undead PCB
*/
-void pcb_zombify(register struct pcb *victim);
+void pcb_zombify(struct pcb *victim);
/**
* Reclaim a process' data structures
@@ -237,7 +195,7 @@ struct pcb *pcb_queue_peek(const pcb_queue_t queue);
* @param pcb[out] Pointer to where the PCB pointer will be saved
* @return status of the removal request
*/
-int pcb_queue_remove(pcb_queue_t queue, struct pcb **pcb);
+int pcb_queue_pop(pcb_queue_t queue, struct pcb **pcb);
/**
* Remove the specified PCB from the indicated queue.
@@ -246,7 +204,7 @@ int pcb_queue_remove(pcb_queue_t queue, struct pcb **pcb);
* @param pcb[in] Pointer to the PCB to be removed
* @return status of the removal request
*/
-int pcb_queue_remove_this(pcb_queue_t queue, struct pcb *pcb);
+int pcb_queue_remove(pcb_queue_t queue, struct pcb *pcb);
/**
* Schedule the supplied process
@@ -260,51 +218,4 @@ void schedule(struct pcb *pcb);
*/
void dispatch(void);
-/**
- * Dumps the contents of this process context to the console
- *
- * @param msg[in] An optional message to print before the dump
- * @param c[in] The context to dump out
- */
-void ctx_dump(const char *msg, register struct cpu_regs *c);
-
-/**
- * dump the process context for all active processes
- *
- * @param msg[in] Optional message to print
- */
-void ctx_dump_all(const char *msg);
-
-/**
- * Dumps the contents of this PCB to the console
- *
- * @param msg[in] An optional message to print before the dump
- * @param p[in] The PCB to dump
- * @param all[in] Dump all the contents?
- */
-void pcb_dump(const char *msg, register struct pcb *p, bool all);
-
-/**
- * Dump the contents of the specified queue to the console
- *
- * @param msg[in] An optional message to print before the dump
- * @param queue[in] The queue to dump
- * @param contents[in] Also dump (some) contents?
- */
-void pcb_queue_dump(const char *msg, pcb_queue_t queue, bool contents);
-
-/**
- * dump the contents of the "active processes" table
- *
- * @param msg[in] Optional message to print
- * @param all[in] Dump all or only part of the relevant data
- */
-void ptable_dump(const char *msg, bool all);
-
-/**
- * Prints basic information about the process table (number of
- * entries, number with each process state, etc.).
- */
-void ptable_dump_counts(void);
-
#endif /* procs.h */
diff --git a/kernel/include/comus/syscalls.h b/kernel/include/comus/syscalls.h
new file mode 100644
index 0000000..3dc128d
--- /dev/null
+++ b/kernel/include/comus/syscalls.h
@@ -0,0 +1,37 @@
+/**
+ * @file syscalls.h
+ *
+ * @author Freya Murphy <freya@freyacat.org>
+ * @author cisi 452
+ *
+ * System call declarations
+ */
+
+#ifndef SYSCALLS_H_
+#define SYSCALLS_H_
+
+#define SYS_exit 0
+#define SYS_waitpid 1
+#define SYS_fork 2
+#define SYS_exec 3
+#define SYS_open 4
+#define SYS_close 5
+#define SYS_read 6
+#define SYS_write 7
+#define SYS_getpid 8
+#define SYS_getppid 9
+#define SYS_gettime 10
+#define SYS_getprio 11
+#define SYS_setprio 12
+#define SYS_kill 13
+#define SYS_sleep 14
+#define SYS_brk 15
+#define SYS_sbrk 16
+
+// UPDATE THIS DEFINITION IF MORE SYSCALLS ARE ADDED!
+#define N_SYSCALLS 13
+
+// interrupt vector entry for system calls
+#define VEC_SYSCALL 0x80
+
+#endif /* syscalls.h */