diff packages/hal/mips/tx39/current/src/hal_diag.c @ 38:e7ba79f6d3a8 ecos-sw-1999-09-23

Merge from eCos master repository on 1999-09-23-20:10:25-BST
author jlarmour
date Thu, 23 Sep 1999 19:52:27 +0000
parents d3fbcdfa1b2f
children 7a6ac9edc838
line wrap: on
line diff
--- a/packages/hal/mips/tx39/current/src/hal_diag.c
+++ b/packages/hal/mips/tx39/current/src/hal_diag.c
@@ -55,10 +55,12 @@
 /*---------------------------------------------------------------------------*/
 
 //#define CYG_KERNEL_DIAG_LCD
-#define CYG_KERNEL_DIAG_SERIAL0
+#define CYG_KERNEL_DIAG_SERIAL0 // For ROM start but see immediately below:
 
-#if defined(CYG_HAL_USE_ROM_MONITOR)
-
+#if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON)
+#undef CYG_KERNEL_DIAG_SERIAL0
+#undef CYG_KERNEL_DIAG_LCD
+#define CYG_KERNEL_DIAG_CYGMON
 #define CYG_KERNEL_DIAG_GDB
 
 #endif
@@ -85,7 +87,7 @@ void hal_diag_led(int x)
 
 /*---------------------------------------------------------------------------*/
 
-#ifdef CYG_KERNEL_DIAG_SERIAL0
+#if defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON)
 
 #define DIAG_BASE       0xfffff300
 #define DIAG_SLCR       (DIAG_BASE+0x00)
@@ -192,7 +194,11 @@ void hal_diag_read_char_serial0(char *c)
 }
 
 
+#if defined(CYG_KERNEL_DIAG_CYGMON)
+void hal_diag_dumb_write_char(char c)
+#else
 void hal_diag_write_char(char c)
+#endif
 {
 #ifdef CYG_KERNEL_DIAG_GDB    
 #if 0 //defined(CYG_HAL_USE_ROM_MONITOR)
@@ -250,8 +256,12 @@ void hal_diag_write_char(char c)
 
             if( c1 == '+' ) break;
 
-            if( cyg_hal_is_break( &c1 , 1 ) )
-                cyg_hal_user_break( NULL );    
+            {
+                extern void cyg_hal_user_break(CYG_ADDRWORD *regs);
+                extern cyg_bool cyg_hal_is_break(char *buf, int size);
+                if( cyg_hal_is_break( &c1 , 1 ) )
+                    cyg_hal_user_break( NULL );    
+            }
             
             break;
         }
@@ -272,6 +282,7 @@ void hal_diag_write_char(char c)
 #endif    
 }
 
+
 void hal_diag_read_char(char *c)
 {
     for(;;)
@@ -314,8 +325,263 @@ void hal_diag_read_char(char *c)
     }
 }
 
+#endif // defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON)
+
+
+#if defined(CYG_KERNEL_DIAG_CYGMON) // only
+
+/* This code has been imported from the BSP module. The definitions have
+ * been left as-is, even though there was scope for doing more, to avoid
+ * too much drift from the original sources
+ */
+
+struct bsp_comm_procs {
+    void *ch_data;
+    void (*__write)(void *ch_data, const char *buf, int len);
+    int  (*__read)(void *ch_data, char *buf, int len);
+    void (*__putc)(void *ch_data, char ch);
+    int  (*__getc)(void *ch_data);
+    int  (*__control)(void *ch_data, int func, ...);
+};
+
+// This is pointed to by entry BSP_NOTVEC_BSP_COMM_PROCS:
+typedef struct {
+    int  version;       /* version number for future expansion */
+    void *__ictrl_table;
+    void *__exc_table;
+    void *__dbg_vector;
+    void *__kill_vector;
+    struct bsp_comm_procs *__console_procs;
+    struct bsp_comm_procs *__debug_procs;
+    void *__flush_dcache;
+    void *__flush_icache;
+    void *__cpu_data;
+    void *__board_data;
+    void *__sysinfo;
+    int  (*__set_debug_comm)(int __comm_id);
+    int  (*__set_console_comm)(int __comm_id);
+    int  (*__set_serial_baud)(int __comm_id, int baud);
+    void *__dbg_data;
+    void (*__reset)(void);
+    int  __console_interrupt_flag;
+} bsp_shared_t;
+
+/*
+ * Core Exception vectors.
+ */
+#define BSP_EXC_INT	    0
+#define BSP_EXC_TLBMOD	    1
+#define BSP_EXC_TLBL	    2
+#define BSP_EXC_TLBS	    3
+#define BSP_EXC_ADEL	    4
+#define BSP_EXC_ADES	    5
+#define BSP_EXC_IBE         6
+#define BSP_EXC_DBE         7
+#define BSP_EXC_SYSCALL     8
+#define BSP_EXC_BREAK       9
+#define BSP_EXC_ILL        10
+#define BSP_EXC_CPU        11
+#define BSP_EXC_OV         12
+#define BSP_EXC_TRAP       13
+#define BSP_EXC_VCEI       14
+#define BSP_EXC_FPE        15
+#define BSP_EXC_RSV16      16
+#define BSP_EXC_RSV17      17
+#define BSP_EXC_RSV18      18
+#define BSP_EXC_RSV19      19
+#define BSP_EXC_RSV20      20
+#define BSP_EXC_RSV21      21
+#define BSP_EXC_RSV22      22
+#define BSP_EXC_WATCH      23
+#define BSP_EXC_RSV24      24
+#define BSP_EXC_RSV25      25
+#define BSP_EXC_RSV26      26
+#define BSP_EXC_RSV27      27
+#define BSP_EXC_RSV28      28
+#define BSP_EXC_RSV29      29
+#define BSP_EXC_RSV30      30
+#define BSP_EXC_VCED       31
+/* tx39 debug exception */
+#define BSP_EXC_DEBUG      32
+#define BSP_EXC_TLB        33
+#define BSP_EXC_NMI        34
+/*
+ * Hack for eCos on tx39 to set an async breakpoint.
+ */
+#define BSP_VEC_BP_HOOK    35
+
+#define BSP_EXC_XTLB	   36
+#define BSP_EXC_CACHE	   37
+
+#define BSP_MAX_EXCEPTIONS 38
+
+/*
+ * Another hack for tx39 eCos compatibility.
+ */
+#if defined(__CPU_R3900__)
+#define BSP_VEC_MT_DEBUG   15
+#else
+#define BSP_VEC_MT_DEBUG   38
 #endif
 
+#define BSP_VEC_STUB_ENTRY 39
+#define BSP_VEC_BSPDATA    40
+#define BSP_VEC_MAGIC      41
+#define BSP_VEC_IRQ_CHECK  42
+
+#define BSP_VEC_PAD        43
+#define NUM_VTAB_ENTRIES   44
+
+
+#define BSP_MAGIC_VAL      0x55aa4321
+
+#define SYS_interrupt 1000
+
+// These vectors should be called with:
+//
+//  k0 - Exception Number
+
+#define CYGMON_VECTOR_TABLE_BASE 0x80000100
+#define CYGMON_VECTOR_TABLE ((CYG_ADDRESS *)CYGMON_VECTOR_TABLE_BASE)
+
+#if 0 // UNUSED
+static int
+hal_bsp_set_debug_comm(int arg)
+{
+    bsp_shared_t *shared;
+
+    shared = (bsp_shared_t *)
+        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
+
+    if (0 != shared->__set_debug_comm) {
+        return (*(shared->__set_debug_comm))(arg);
+    }
+    return 0;
+}
+
+static int
+hal_bsp_set_console_comm(int arg)
+{
+    bsp_shared_t *shared;
+
+    shared = (bsp_shared_t *)
+        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
+
+    if (0 != shared->__set_console_comm) {
+        return (*(shared->__set_console_comm))(arg);
+    }
+    return 0;
+}
+#endif // 0 UNUSED
+
+static void bsp_trap(int trap_num);
+
+static int
+hal_bsp_console_write(const void *p, int len)
+{
+    bsp_shared_t *shared;
+    struct bsp_comm_procs *com;
+    int  magic;
+
+    /*hal_bsp_set_console_comm(0);*/
+
+    /* If this is not a BSP-based CygMon, return 0 */
+    magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
+    if (magic != BSP_MAGIC_VAL)
+	return 0;
+
+    shared = (bsp_shared_t *)
+        (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]);
+
+    com = shared->__console_procs;
+
+    if (0 != com) {
+	shared->__console_interrupt_flag = 0;
+        com->__write(com->ch_data, p, len);
+	if (shared->__console_interrupt_flag) {
+	    /* debug interrupt; stop here */
+	    bsp_trap(SYS_interrupt);
+	}
+
+        return 1;
+    }
+    return 0;
+}
+
+static void
+bsp_trap(int trap_num)
+{
+    asm("syscall\n");
+}
+
+
+static void
+hal_dumb_serial_write(const char *p, int len)
+{
+    int i;
+    for ( i = 0 ; i < len; i++ ) {
+	hal_diag_dumb_write_char(p[i]);
+    }
+} 
+
+void hal_diag_write_char(char c)
+{
+    static char line[100];
+    static int pos = 0;
+
+    // No need to send CRs
+    if( c == '\r' ) return;
+
+    line[pos++] = c;
+
+    if( c == '\n' || pos == sizeof(line) ) {
+        CYG_INTERRUPT_STATE old;
+
+        // Disable interrupts. This prevents GDB trying to interrupt us
+        // while we are in the middle of sending a packet. The serial
+        // receive interrupt will be seen when we re-enable interrupts
+        // later.
+        
+        HAL_DISABLE_INTERRUPTS(old);
+        
+        if ( ! hal_bsp_console_write( line, pos ) )
+            // then there is no function registered, just spew it out serial
+            hal_dumb_serial_write( line, pos );
+        
+        pos = 0;
+
+        // And re-enable interrupts
+        HAL_RESTORE_INTERRUPTS(old);
+
+    }
+}
+
+int
+hal_diag_irq_check(int vector)
+{
+    typedef int irq_check_fn(int irq_nr);
+    irq_check_fn *fn = (irq_check_fn *)(CYGMON_VECTOR_TABLE[ BSP_VEC_IRQ_CHECK ]);
+    int  magic;
+    
+
+    /* If this is not a BSP-based CygMon, return 0 */
+    magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]);
+    if (magic != BSP_MAGIC_VAL)
+	return 0;
+
+#if defined(CYGPKG_HAL_MIPS_TX3904)
+    /* convert vector to BSP irq number */
+    if (vector == 16)
+	vector = 2;
+    else
+	vector += 3;
+#endif
+
+    return fn(vector);
+}
+
+#endif // defined(CYG_KERNEL_DIAG_CYGMON) *only*
+
 /*---------------------------------------------------------------------------*/
 
 #if defined(CYGPKG_HAL_MIPS_TX39_JMR3904) && defined(CYG_KERNEL_DIAG_LCD)