aboutsummaryrefslogtreecommitdiff
path: root/src/cpu/irq.c
blob: 1d50c7d182161eb486b5db7419a157ddbf046fc9 (plain)
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
116
#include "../cpu/irq.h"
#include "../sys/core.h"
#include "../sys/timer.h"
#include "../drivers/uart.h"
#include "../util/mutex.h"
#include "../util/time.h"

extern unsigned long cmdidx;
extern char cmd[2048];
extern void disable_irq(void);
extern void enable_irq(void);

void c_irq_handler(void) {
	//disable_irq();
	disableirq();
	unsigned long source = load32(CORE0_IRQ_SOURCE);
	if (source & (1 << 8)) {
		if(load32(IRQ_PENDING2) & (1 << 25)) {
			if(load32(UART0_MIS) & (1<<4)) {
				unsigned long data = load32(UART0_DR);
				// Ctrl+Tab to toggle timer
				if(data == 0x14) {
					unsigned long timer_status;
					asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r"(timer_status));
					if(timer_status == 0) {
						cntfrq = read_cntfrq();
						write_cntv_tval(cntfrq);
						enable_cntv();
#ifndef NOANSI
						uart_string((char*)"\033[?25l\033[s\033[4;1H\033[0KTimer: \033[92mEnabled\033[0m\033[u\033[?25h");
#else
						uart_string((char*)"\033[?25l\033[4;1H\033[0KTimer: \033[92mEnabled\033[0m\033[8;1H\033[?25h> ");
#endif
					} else {
						disable_cntv();
#ifndef NOANSI
						uart_string((char*)"\033[?25l\033[s\033[4;1H\033[0KTimer: \033[91mDisabled\033[0m\033[u\033[?25h");
#else
						uart_string((char*)"\033[?25l\033[4;1H\033[0KTimer: \033[91mDisabled\033[0m\033[8;1H\033[?25h> ");
#endif
					}
				} else {
					unsigned long off = cmdidx;
					if (off < 2048) {
						// Newline Case
						if (data == 0x0D) {
							off = 0;
							cmd[0] = 0x0;
							//uart_char(0x0a);
							uart_char(data);
							uart_string("\033[?25l> \033[0K\033[?25h");
						// Backspace Case
						} else if (data == 0x08 || data == 0x7F) {
							if (off > 0) {
								off -= 1;
							}
							cmd[off] = 0x0;
							uart_char((unsigned char)data);
							uart_char(0x20);
							uart_char((unsigned char)data);
						// Lock Case
						} else if (data == 0x6C) {
							uart_char((unsigned char)data);
							cmd[off] = (char) data;
							off += 1;
							lock_mutex(&exe_cnt_m, SCHED_PID);
						// Release Case
						} else if (data == 0x72) {
							uart_char((unsigned char)data);
							cmd[off] = (char) data;
							off += 1;
							release_mutex(&exe_cnt_m, SCHED_PID);
						// Else output
						} else {
							uart_char((unsigned char)data);
							cmd[off] = (char) data;
							off += 1;
						}
					} else if (off == 2048) {
						if (data == 0x0D) {
							off = 0;
							cmd[0] = 0x0;
							//uart_char(0x0a);
							uart_char(data);
							uart_string("\033[?25l> \033[0K\033[?25h");
						} else if (data == 0x08 || data == 0x7F) {
							if (off > 0) {
								off -= 1;
							}
							cmd[off] = 0x0;
							uart_char((unsigned char)data);
							uart_char(0x20);
							uart_char((unsigned char)data);
						}
					}
					cmdidx = off;
					//store32(off, (unsigned long*) cmdidx);
					uart_string("\033[?25l\033[9;1H\033[0K");
					uart_10(off);
					uart_string("\n\033[0K");
					uart_string(cmd);
					uart_string("\033[?25h\033[8;1H> ");
				}
				//enable_irq();
				enableirq();
				return;
			}
		}
	} else if (source & (1 << 3)) {
		c_timer();
		//enable_irq();
		enableirq();
		return;
	}
	return;
}