1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2015 Imagination Technologies
4 * Author: Paul Burton <paul.burton@mips.com>
7 #include <asm/addrspace.h>
9 #include <asm/asm-offsets.h>
10 #include <asm/mipsregs.h>
11 #include <asm/regdef.h>
12 #include <linux/serial_reg.h>
14 #define UART_TX_OFS (UART_TX << CONFIG_MIPS_CPS_NS16550_SHIFT)
15 #define UART_LSR_OFS (UART_LSR << CONFIG_MIPS_CPS_NS16550_SHIFT)
17 #if CONFIG_MIPS_CPS_NS16550_WIDTH == 1
20 #elif CONFIG_MIPS_CPS_NS16550_WIDTH == 2
23 #elif CONFIG_MIPS_CPS_NS16550_WIDTH == 4
32 * _mips_cps_putc() - write a character to the UART
33 * @a0: ASCII character to write
34 * @t9: UART base address
37 1: UART_L t0, UART_LSR_OFS(t9)
38 andi t0, t0, UART_LSR_TEMT
40 UART_S a0, UART_TX_OFS(t9)
45 * _mips_cps_puts() - write a string to the UART
46 * @a0: pointer to NULL-terminated ASCII string
47 * @t9: UART base address
49 * Write a null-terminated ASCII string to the UART.
51 NESTED(_mips_cps_puts, 0, ra)
65 * _mips_cps_putx4 - write a 4b hex value to the UART
66 * @a0: the 4b value to write to the UART
67 * @t9: UART base address
69 * Write a single hexadecimal character to the UART.
71 NESTED(_mips_cps_putx4, 0, ra)
82 * _mips_cps_putx8 - write an 8b hex value to the UART
83 * @a0: the 8b value to write to the UART
84 * @t9: UART base address
86 * Write an 8 bit value (ie. 2 hexadecimal characters) to the UART.
88 NESTED(_mips_cps_putx8, 0, ra)
99 * _mips_cps_putx16 - write a 16b hex value to the UART
100 * @a0: the 16b value to write to the UART
101 * @t9: UART base address
103 * Write a 16 bit value (ie. 4 hexadecimal characters) to the UART.
105 NESTED(_mips_cps_putx16, 0, ra)
113 END(_mips_cps_putx16)
116 * _mips_cps_putx32 - write a 32b hex value to the UART
117 * @a0: the 32b value to write to the UART
118 * @t9: UART base address
120 * Write a 32 bit value (ie. 8 hexadecimal characters) to the UART.
122 NESTED(_mips_cps_putx32, 0, ra)
130 END(_mips_cps_putx32)
135 * _mips_cps_putx64 - write a 64b hex value to the UART
136 * @a0: the 64b value to write to the UART
137 * @t9: UART base address
139 * Write a 64 bit value (ie. 16 hexadecimal characters) to the UART.
141 NESTED(_mips_cps_putx64, 0, ra)
149 END(_mips_cps_putx64)
151 #define _mips_cps_putxlong _mips_cps_putx64
153 #else /* !CONFIG_64BIT */
155 #define _mips_cps_putxlong _mips_cps_putx32
157 #endif /* !CONFIG_64BIT */
160 * mips_cps_bev_dump() - dump relevant exception state to UART
161 * @a0: pointer to NULL-terminated ASCII string naming the exception
163 * Write information that may be useful in debugging an exception to the
164 * UART configured by CONFIG_MIPS_CPS_NS16550_*. As this BEV exception
165 * will only be run if something goes horribly wrong very early during
166 * the bringup of a core and it is very likely to be unsafe to perform
167 * memory accesses at that point (cache state indeterminate, EVA may not
168 * be configured, coherence may be disabled) let alone have a stack,
169 * this is all written in assembly using only registers & unmapped
170 * uncached access to the UART registers.
172 LEAF(mips_cps_bev_dump)
176 li t9, CKSEG1ADDR(CONFIG_MIPS_CPS_NS16550_BASE)
178 PTR_LA a0, str_newline
184 PTR_LA a0, str_newline
186 PTR_LA a0, str_newline
189 #define DUMP_COP0_REG(reg, name, sz, _mfc0) \
191 jal _mips_cps_puts; \
193 jal _mips_cps_putx##sz; \
194 PTR_LA a0, str_newline; \
195 jal _mips_cps_puts; \
198 DUMP_COP0_REG(CP0_CAUSE, "Cause: 0x", 32, mfc0)
199 DUMP_COP0_REG(CP0_STATUS, "Status: 0x", 32, mfc0)
200 DUMP_COP0_REG(CP0_EBASE, "EBase: 0x", long, MFC0)
201 DUMP_COP0_REG(CP0_BADVADDR, "BadVAddr: 0x", long, MFC0)
202 DUMP_COP0_REG(CP0_BADINSTR, "BadInstr: 0x", 32, mfc0)
204 PTR_LA a0, str_newline
207 END(mips_cps_bev_dump)
210 str_bev: .asciiz "BEV Exception: "
211 str_newline: .asciiz "\r\n"