···11+/*22+ * linux/arch/unicore32/include/mach/ocd.h33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+1313+#ifndef __MACH_PUV3_OCD_H__1414+#define __MACH_PUV3_OCD_H__1515+1616+#if defined(CONFIG_DEBUG_OCD)1717+static inline void ocd_putc(unsigned int c)1818+{1919+ int status, i = 0x2000000;2020+2121+ do {2222+ if (--i < 0)2323+ return;2424+2525+ asm volatile ("movc %0, p1.c0, #0" : "=r" (status));2626+ } while (status & 2);2727+2828+ asm("movc p1.c1, %0, #1" : : "r" (c));2929+}3030+3131+#define putc(ch) ocd_putc(ch)3232+#else3333+#define putc(ch)3434+#endif3535+3636+#endif
+89
arch/unicore32/kernel/debug-macro.S
···11+/*22+ * linux/arch/unicore32/kernel/debug-macro.S33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ *1212+ * Debugging macro include header1313+ */1414+#include <generated/asm-offsets.h>1515+#include <mach/hardware.h>1616+1717+ .macro put_word_ocd, rd, rx=r161818+1001: movc \rx, p1.c0, #01919+ cand.a \rx, #22020+ bne 1001b2121+ movc p1.c1, \rd, #12222+ .endm2323+2424+#ifdef CONFIG_DEBUG_OCD2525+ /* debug using UniCore On-Chip-Debugger */2626+ .macro addruart, rx2727+ .endm2828+2929+ .macro senduart, rd, rx3030+ put_word_ocd \rd, \rx3131+ .endm3232+3333+ .macro busyuart, rd, rx3434+ .endm3535+3636+ .macro waituart, rd, rx3737+ .endm3838+#else3939+#define UART_CLK_DEFAULT 3686400 * 204040+ /* Uartclk = MCLK/ 2, The MCLK on my board is 3686400 * 40 */4141+#define BAUD_RATE_DEFAULT 1152004242+ /* The baud rate of the serial port */4343+4444+#define UART_DIVISOR_DEFAULT (UART_CLK_DEFAULT \4545+ / (16 * BAUD_RATE_DEFAULT) - 1)4646+4747+ .macro addruart,rx4848+ mrc p0, #0, \rx, c1, c04949+ tst \rx, #1 @ MMU enabled?5050+ moveq \rx, #0xee000000 @ physical base address5151+ movne \rx, #0x6e000000 @ virtual address5252+5353+ @ We probe for the active serial port here5454+ @ However, now we assume UART0 is active: epip4d5555+ @ We assume r1 and r2 can be clobbered.5656+5757+ movl r2, #UART_DIVISOR_DEFAULT5858+ mov r1, #0x805959+ str r1, [\rx, #UART_LCR_OFFSET]6060+ and r1, r2, #0xff006161+ mov r1, r1, lsr #86262+ str r1, [\rx, #UART_DLH_OFFSET]6363+ and r1, r2, #0xff6464+ str r1, [\rx, #UART_DLL_OFFSET]6565+ mov r1, #0x76666+ str r1, [\rx, #UART_FCR_OFFSET]6767+ mov r1, #0x36868+ str r1, [\rx, #UART_LCR_OFFSET]6969+ mov r1, #0x07070+ str r1, [\rx, #UART_IER_OFFSET]7171+ .endm7272+7373+ .macro senduart,rd,rx7474+ str \rd, [\rx, #UART_THR_OFFSET]7575+ .endm7676+7777+ .macro waituart,rd,rx7878+1001: ldr \rd, [\rx, #UART_LSR_OFFSET]7979+ tst \rd, #UART_LSR_THRE8080+ beq 1001b8181+ .endm8282+8383+ .macro busyuart,rd,rx8484+1001: ldr \rd, [\rx, #UART_LSR_OFFSET]8585+ tst \rd, #UART_LSR_TEMT8686+ bne 1001b8787+ .endm8888+#endif8989+
+85
arch/unicore32/kernel/debug.S
···11+/*22+ * linux/arch/unicore32/kernel/debug.S33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ *1212+ * 32-bit debugging code1313+ */1414+#include <linux/linkage.h>1515+#include <asm/assembler.h>1616+1717+ .text1818+1919+/*2020+ * Some debugging routines (useful if you've got MM problems and2121+ * printk isn't working). For DEBUGGING ONLY!!! Do not leave2222+ * references to these in a production kernel!2323+ */2424+#include "debug-macro.S"2525+2626+/*2727+ * Useful debugging routines2828+ */2929+ENTRY(printhex8)3030+ mov r1, #83131+ b printhex3232+ENDPROC(printhex8)3333+3434+ENTRY(printhex4)3535+ mov r1, #43636+ b printhex3737+ENDPROC(printhex4)3838+3939+ENTRY(printhex2)4040+ mov r1, #24141+printhex: adr r2, hexbuf4242+ add r3, r2, r14343+ mov r1, #04444+ stb r1, [r3]4545+1: and r1, r0, #154646+ mov r0, r0 >> #44747+ csub.a r1, #104848+ beg 2f4949+ add r1, r1, #'0' - 'a' + 105050+2: add r1, r1, #'a' - 105151+ stb.w r1, [r3+], #-15252+ cxor.a r3, r25353+ bne 1b5454+ mov r0, r25555+ b printascii5656+ENDPROC(printhex2)5757+5858+ .ltorg5959+6060+ENTRY(printascii)6161+ addruart r36262+ b 2f6363+1: waituart r2, r36464+ senduart r1, r36565+ busyuart r2, r36666+ cxor.a r1, #'\n'6767+ cmoveq r1, #'\r'6868+ beq 1b6969+2: cxor.a r0, #07070+ beq 3f7171+ ldb.w r1, [r0]+, #17272+ cxor.a r1, #07373+ bne 1b7474+3: mov pc, lr7575+ENDPROC(printascii)7676+7777+ENTRY(printch)7878+ addruart r37979+ mov r1, r08080+ mov r0, #08181+ b 1b8282+ENDPROC(printch)8383+8484+hexbuf: .space 168585+
+59
arch/unicore32/kernel/early_printk.c
···11+/*22+ * linux/arch/unicore32/kernel/early_printk.c33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+#include <linux/console.h>1313+#include <linux/init.h>1414+#include <linux/string.h>1515+#include <mach/ocd.h>1616+1717+/* On-Chip-Debugger functions */1818+1919+static void early_ocd_write(struct console *con, const char *s, unsigned n)2020+{2121+ while (*s && n-- > 0) {2222+ if (*s == '\n')2323+ ocd_putc((int)'\r');2424+ ocd_putc((int)*s);2525+ s++;2626+ }2727+}2828+2929+static struct console early_ocd_console = {3030+ .name = "earlyocd",3131+ .write = early_ocd_write,3232+ .flags = CON_PRINTBUFFER,3333+ .index = -1,3434+};3535+3636+/* Direct interface for emergencies */3737+static struct console *early_console = &early_ocd_console;3838+3939+static int __initdata keep_early;4040+4141+static int __init setup_early_printk(char *buf)4242+{4343+ if (!buf)4444+ return 0;4545+4646+ if (strstr(buf, "keep"))4747+ keep_early = 1;4848+4949+ if (!strncmp(buf, "ocd", 3))5050+ early_console = &early_ocd_console;5151+5252+ if (keep_early)5353+ early_console->flags &= ~CON_BOOT;5454+ else5555+ early_console->flags |= CON_BOOT;5656+ register_console(early_console);5757+ return 0;5858+}5959+early_param("earlyprintk", setup_early_printk);