Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
temp_build/build/
temp_build/s-mode/
temp_build/u-mode/
29 changes: 29 additions & 0 deletions temp_build/common/pt_interrupt.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

/*
.align 4
.global vector_table
.option push
.option norvc
vector_table:
j exception_handler // exceptions jump to cause 0
j ssip_handler // 1
j unreachable_handler // 2
j msip_handler // 3

j unreachable_handler // 4
j stip_handler // 5
j unreachable_handler // 6
j mtip_handler // 7

j unreachable_handler // 8
j seip_handler // 9
j unreachable_handler // 10
j meip_handler // 11

j unreachable_handler // 12
j lcofip_handler // 13
j unreachable_handler // 14
j unreachable_handler // 15
// end of standard interrupts
.option pop
*/
30 changes: 30 additions & 0 deletions temp_build/interrupts-exceptions/proc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* proc.h */

#ifndef _PROC_H_
#define _PROC_H_

#define NPROC 64 /* max number of processes */

/* Process states */
#define PR_FREE 0
#define PR_READY 1
#define PR_CURR 2
#define PR_SLEEP 3

struct procent {
uint16 prstate;
pri16 prprio; //process priority
char *prstkptr; //stack pointer
char *prstkbase; //base of runtime stack
uint32 prstklen; //stack length in bytes
//char prname[PNMLEN] //process name
sid32 prsem; //semaphore for process
pid32 prparent; //ID of creating process
//umsg prmsg; //message sent to this process
//bool8 prhasmsg; //Nonzero iff msg is valid
//int16 prdesc[NDESC]; //device descriptors for process
};

extern struct procent proctab[NPROC];

#endif
61 changes: 61 additions & 0 deletions temp_build/interrupts-exceptions/process_table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

#include <stdint.h>
#include "csr.h"
#include "utility.h"
#include "format.h"

#define QUANTUM 2;

int queue[5] = {1, 2, 3, 4, 5};
int index = 0;
uint64_t volatile time_remaining = QUANTUM;

void reschedule_function() {
index++;
time_remaining = QUANTUM;
print("Index increments. Index at %d. ", index);
}

void set_timer(uint64_t value) {
*MTIMECMP = *MTIME + value;
}

void meip_handler() {
print("meip handling....");
*EXT_CLEAR = 0x1; // writing anything simulates clearing interrupt
CSRW("mie", 0x088);
//index++;
print("Handled. ");
}

void mtip_handler() {
print("mtip handling....");
time_remaining -= 1;
if (time_remaining <= 0) {
reschedule_function();
}
set_timer(1000);
print("Handled. ");
}

void msip_handler() {
print("msip handling....");
*MSIP = 0x0; // writing 0 clears this
//index++;
print("Handled. ", index);
}

int main() {
*MTIMECMPH = 0x00;
*MTIMECMP = 0xFF;

setup_interrupt_m_vectored(vector_table, IE_MTIE | IE_MSIE | IE_MEIE);
enable_interrupts_m();

*MSIP = 1;
*EXT_SET = 1;

while (*MTIME < 0xFFFF);

return 0;
}
103 changes: 0 additions & 103 deletions temp_build/s-mode/csr.c

This file was deleted.

89 changes: 0 additions & 89 deletions temp_build/s-mode/s-mode.c

This file was deleted.

72 changes: 0 additions & 72 deletions temp_build/s-mode/tvm_tw_tsr.c

This file was deleted.

Loading