Removes debugging code
[akaros.git] / kern / arch / riscv / console.c
index 6ad117a..8aabab4 100644 (file)
@@ -3,98 +3,19 @@
 #include <pmap.h>
 #include <atomic.h>
 #include <smp.h>
-
-static volatile uint64_t magic_mem[MAX_NUM_CPUS][8] __attribute__((aligned(64)));
-
-static bool fesvr_busy()
-{
-       if (mfpcr(PCR_TOHOST))
-               return true;
-       
-       volatile uint64_t* mm = magic_mem[core_id()];
-       if (mfpcr(PCR_FROMHOST) && mm[6])
-       {
-               void (*func)(void*, uint64_t*) = (void*)(uintptr_t)mm[6];
-               void* farg = (void*)(uintptr_t)mm[7];
-               func(farg, (uint64_t*)mm);
-       }
-
-       return false;
-}
-
-int fesvr_syscall(long n, long a0, long a1, long a2, long a3,
-                  void (*continuation)(void*, uint64_t*), void* arg)
-{
-       int ret = -1;
-       uintptr_t irq_state = disable_irq();
-
-       if (fesvr_busy())
-               goto out;
-
-       volatile uint64_t* mm = magic_mem[core_id()];
-       mm[0] = n;
-       mm[1] = a0;
-       mm[2] = a1;
-       mm[3] = a2;
-       mm[4] = a3;
-       mm[6] = (uintptr_t)continuation;
-       mm[7] = (uintptr_t)arg;
-
-       mb();
-       mtpcr(PCR_TOHOST, PADDR(mm));
-  
-       ret = 0;
-out:
-       restore_irq(irq_state);
-       return ret;
-}
-
-void
-fesvr_die()
-{
-       while (fesvr_syscall(FESVR_SYS_exit, 0, 0, 0, 0, 0, 0) < 0);
-}
-
-static void cons_polled(void* null, uint64_t* magic_mem)
-{
-       for (int i = 0; i < (int)magic_mem[0]; i++)
-       {
-               char c = ((char*)KADDR(magic_mem[2]))[i];
-               if (c == 'G')
-                       send_kernel_message(core_id(), __run_mon, 0, 0, 0, KMSG_ROUTINE);
-               else
-                       send_kernel_message(core_id(), __cons_add_char, (long)&cons_buf,
-                                           (long)c, 0, KMSG_ROUTINE);
-       }
-}
-
-static struct alarm_waiter keyboard_waiter;
-
-static void cons_poll(struct alarm_waiter* awaiter)
-{
-       static char buf[64] __attribute__((aligned(64)));
-       fesvr_syscall(FESVR_SYS_read, 0, PADDR(buf), sizeof(buf), 0, cons_polled, 0);
-
-       set_awaiter_rel(&keyboard_waiter, 100);
-       set_alarm(&per_cpu_info[core_id()].tchain, &keyboard_waiter);
-}
-
-// emulate keyboard input with an alarm
-void keyboard_alarm_init()
-{
-       init_awaiter(&keyboard_waiter, cons_poll);
-       set_awaiter_rel(&keyboard_waiter, 1);
-       set_alarm(&per_cpu_info[core_id()].tchain, &keyboard_waiter);
-}
+#include <kmalloc.h>
+#include <monitor.h>
+#include <process.h>
 
 int cons_get_any_char(void)
 {
        assert(0);
 }
 
-void
-cons_init(void)
+void cons_init()
 {
+       mtpcr(PCR_SR, mfpcr(PCR_SR) | (1 << (IRQ_HOST+SR_IM_SHIFT)));
+       while (mtpcr(PCR_TOHOST, 0x01L << 56));
 }
 
 // `High'-level console I/O.  Used by readline and cprintf.
@@ -102,13 +23,12 @@ cons_init(void)
 void
 cputbuf(const char* str, int len)
 {
-       static char bufs[MAX_NUM_CPUS][1024] __attribute__((aligned(64)));
-       assert(len <= sizeof(bufs[0]));
+       for (int i = 0; i < len; i++)
+               cputchar(str[i]);
+}
 
-       char* buf = bufs[core_id()];
-       while (fesvr_busy());
-       memcpy(buf, str, len);
-       while (fesvr_syscall(FESVR_SYS_write, 1, PADDR(buf), len, 0, 0, 0) < 0);
+void poll_keyboard()
+{
 }
 
 // Low-level console I/O
@@ -116,8 +36,7 @@ cputbuf(const char* str, int len)
 void
 cputchar(int c)
 {
-       char ch = c;
-       cputbuf(&ch,1);
+       while (mtpcr(PCR_TOHOST, 0x0101000000000000 | (unsigned char)c));
 }
 
 int