Skip to content

Commit e449759

Browse files
committed
openrisc: Cleanup emergency print handling
The emergency print support only works for 8250 compatible serial ports. Now that OpenRISC platforms may be configured with different serial port hardware we don't want emergency print to try to print to non-existent hardware which will cause lockups. This patch contains several fixes to get emergency print working again: - Update symbol loading to not assume the location of symbols - Split the putc print operation out to its own function to allow for different future implementations. - Update _emergency_print_nr and _emergency_print to use the putc function. - Guard serial 8250 specific sequences by CONFIG_SERIAL_8250 - Update string line feed from lf,cr to cr,lf. Signed-off-by: Stafford Horne <[email protected]>
1 parent 87e387a commit e449759

File tree

1 file changed

+85
-63
lines changed

1 file changed

+85
-63
lines changed

arch/openrisc/kernel/head.S

Lines changed: 85 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,23 @@
297297
/* temporary store r3, r9 into r1, r10 */ ;\
298298
l.addi r1,r3,0x0 ;\
299299
l.addi r10,r9,0x0 ;\
300-
/* the string referenced by r3 must be low enough */ ;\
300+
LOAD_SYMBOL_2_GPR(r9,_string_unhandled_exception) ;\
301+
tophys (r3,r9) ;\
301302
l.jal _emergency_print ;\
302-
l.ori r3,r0,lo(_string_unhandled_exception) ;\
303+
l.nop ;\
303304
l.mfspr r3,r0,SPR_NPC ;\
304305
l.jal _emergency_print_nr ;\
305-
l.andi r3,r3,0x1f00 ;\
306-
/* the string referenced by r3 must be low enough */ ;\
306+
l.andi r3,r3,0x1f00 ;\
307+
LOAD_SYMBOL_2_GPR(r9,_string_epc_prefix) ;\
308+
tophys (r3,r9) ;\
307309
l.jal _emergency_print ;\
308-
l.ori r3,r0,lo(_string_epc_prefix) ;\
310+
l.nop ;\
309311
l.jal _emergency_print_nr ;\
310-
l.mfspr r3,r0,SPR_EPCR_BASE ;\
312+
l.mfspr r3,r0,SPR_EPCR_BASE ;\
313+
LOAD_SYMBOL_2_GPR(r9,_string_nl) ;\
314+
tophys (r3,r9) ;\
311315
l.jal _emergency_print ;\
312-
l.ori r3,r0,lo(_string_nl) ;\
316+
l.nop ;\
313317
/* end of printing */ ;\
314318
l.addi r3,r1,0x0 ;\
315319
l.addi r9,r10,0x0 ;\
@@ -1530,65 +1534,99 @@ trampoline_out:
15301534
l.jr r9
15311535
l.nop
15321536

1533-
15341537
/*
1535-
* DSCR: prints a string referenced by r3.
1538+
* DESC: Prints ASCII character stored in r7
15361539
*
1537-
* PRMS: r3 - address of the first character of null
1538-
* terminated string to be printed
1540+
* PRMS: r7 - a 32-bit value with an ASCII character in the first byte
1541+
* position.
15391542
*
1540-
* PREQ: UART at UART_BASE_ADD has to be initialized
1543+
* PREQ: The UART at UART_BASE_ADD has to be initialized
15411544
*
1542-
* POST: caller should be aware that r3, r9 are changed
1545+
* POST: internally used but restores:
1546+
* r4 - to store UART_BASE_ADD
1547+
* r5 - for loading OFF_TXFULL / THRE,TEMT
1548+
* r6 - for storing bitmask (SERIAL_8250)
15431549
*/
1544-
ENTRY(_emergency_print)
1550+
ENTRY(_emergency_putc)
15451551
EMERGENCY_PRINT_STORE_GPR4
15461552
EMERGENCY_PRINT_STORE_GPR5
15471553
EMERGENCY_PRINT_STORE_GPR6
1548-
EMERGENCY_PRINT_STORE_GPR7
1549-
2:
1550-
l.lbz r7,0(r3)
1551-
l.sfeq r7,r0
1552-
l.bf 9f
1553-
l.nop
15541554

1555-
// putc:
15561555
l.movhi r4,hi(UART_BASE_ADD)
1556+
l.ori r4,r4,lo(UART_BASE_ADD)
15571557

1558+
#if defined(CONFIG_SERIAL_8250)
1559+
/* Check UART LSR THRE (hold) bit */
15581560
l.addi r6,r0,0x20
15591561
1: l.lbz r5,5(r4)
15601562
l.andi r5,r5,0x20
15611563
l.sfeq r5,r6
15621564
l.bnf 1b
1563-
l.nop
1565+
l.nop
15641566

1567+
/* Write character */
15651568
l.sb 0(r4),r7
15661569

1570+
/* Check UART LSR THRE|TEMT (hold, empty) bits */
15671571
l.addi r6,r0,0x60
15681572
1: l.lbz r5,5(r4)
15691573
l.andi r5,r5,0x60
15701574
l.sfeq r5,r6
15711575
l.bnf 1b
1572-
l.nop
1576+
l.nop
1577+
#endif
1578+
EMERGENCY_PRINT_LOAD_GPR6
1579+
EMERGENCY_PRINT_LOAD_GPR5
1580+
EMERGENCY_PRINT_LOAD_GPR4
1581+
l.jr r9
1582+
l.nop
1583+
1584+
/*
1585+
* DSCR: prints a string referenced by r3.
1586+
*
1587+
* PRMS: r3 - address of the first character of null
1588+
* terminated string to be printed
1589+
*
1590+
* PREQ: UART at UART_BASE_ADD has to be initialized
1591+
*
1592+
* POST: caller should be aware that r3, r9 are changed
1593+
*/
1594+
ENTRY(_emergency_print)
1595+
EMERGENCY_PRINT_STORE_GPR7
1596+
EMERGENCY_PRINT_STORE_GPR9
1597+
1598+
/* Load character to r7, check for null terminator */
1599+
2: l.lbz r7,0(r3)
1600+
l.sfeqi r7,0x0
1601+
l.bf 9f
1602+
l.nop
1603+
1604+
l.jal _emergency_putc
1605+
l.nop
15731606

15741607
/* next character */
15751608
l.j 2b
1576-
l.addi r3,r3,0x1
1609+
l.addi r3,r3,0x1
15771610

15781611
9:
1612+
EMERGENCY_PRINT_LOAD_GPR9
15791613
EMERGENCY_PRINT_LOAD_GPR7
1580-
EMERGENCY_PRINT_LOAD_GPR6
1581-
EMERGENCY_PRINT_LOAD_GPR5
1582-
EMERGENCY_PRINT_LOAD_GPR4
15831614
l.jr r9
1584-
l.nop
1615+
l.nop
15851616

1617+
/*
1618+
* DSCR: prints a number in r3 in hex.
1619+
*
1620+
* PRMS: r3 - a 32-bit unsigned integer
1621+
*
1622+
* PREQ: UART at UART_BASE_ADD has to be initialized
1623+
*
1624+
* POST: caller should be aware that r3, r9 are changed
1625+
*/
15861626
ENTRY(_emergency_print_nr)
1587-
EMERGENCY_PRINT_STORE_GPR4
1588-
EMERGENCY_PRINT_STORE_GPR5
1589-
EMERGENCY_PRINT_STORE_GPR6
15901627
EMERGENCY_PRINT_STORE_GPR7
15911628
EMERGENCY_PRINT_STORE_GPR8
1629+
EMERGENCY_PRINT_STORE_GPR9
15921630

15931631
l.addi r8,r0,32 // shift register
15941632

@@ -1600,58 +1638,39 @@ ENTRY(_emergency_print_nr)
16001638
/* don't skip the last zero if number == 0x0 */
16011639
l.sfeqi r8,0x4
16021640
l.bf 2f
1603-
l.nop
1641+
l.nop
16041642

16051643
l.sfeq r7,r0
16061644
l.bf 1b
1607-
l.nop
1645+
l.nop
16081646

16091647
2:
16101648
l.srl r7,r3,r8
16111649

16121650
l.andi r7,r7,0xf
16131651
l.sflts r8,r0
1614-
l.bf 9f
1652+
l.bf 9f
16151653

1654+
/* Numbers greater than 9 translate to a-f */
16161655
l.sfgtui r7,0x9
16171656
l.bnf 8f
1618-
l.nop
1657+
l.nop
16191658
l.addi r7,r7,0x27
16201659

1621-
8:
1622-
l.addi r7,r7,0x30
1623-
// putc:
1624-
l.movhi r4,hi(UART_BASE_ADD)
1625-
1626-
l.addi r6,r0,0x20
1627-
1: l.lbz r5,5(r4)
1628-
l.andi r5,r5,0x20
1629-
l.sfeq r5,r6
1630-
l.bnf 1b
1631-
l.nop
1632-
1633-
l.sb 0(r4),r7
1634-
1635-
l.addi r6,r0,0x60
1636-
1: l.lbz r5,5(r4)
1637-
l.andi r5,r5,0x60
1638-
l.sfeq r5,r6
1639-
l.bnf 1b
1640-
l.nop
1660+
/* Convert to ascii and output character */
1661+
8: l.jal _emergency_putc
1662+
l.addi r7,r7,0x30
16411663

16421664
/* next character */
16431665
l.j 2b
16441666
l.addi r8,r8,-0x4
16451667

16461668
9:
1669+
EMERGENCY_PRINT_LOAD_GPR9
16471670
EMERGENCY_PRINT_LOAD_GPR8
16481671
EMERGENCY_PRINT_LOAD_GPR7
1649-
EMERGENCY_PRINT_LOAD_GPR6
1650-
EMERGENCY_PRINT_LOAD_GPR5
1651-
EMERGENCY_PRINT_LOAD_GPR4
16521672
l.jr r9
1653-
l.nop
1654-
1673+
l.nop
16551674

16561675
/*
16571676
* This should be used for debugging only.
@@ -1676,7 +1695,9 @@ ENTRY(_emergency_print_nr)
16761695

16771696
ENTRY(_early_uart_init)
16781697
l.movhi r3,hi(UART_BASE_ADD)
1698+
l.ori r3,r3,lo(UART_BASE_ADD)
16791699

1700+
#if defined(CONFIG_SERIAL_8250)
16801701
l.addi r4,r0,0x7
16811702
l.sb 0x2(r3),r4
16821703

@@ -1694,9 +1715,10 @@ ENTRY(_early_uart_init)
16941715
l.addi r4,r0,((UART_DIVISOR) & 0x000000ff)
16951716
l.sb UART_DLL(r3),r4
16961717
l.sb 0x3(r3),r5
1718+
#endif
16971719

16981720
l.jr r9
1699-
l.nop
1721+
l.nop
17001722

17011723
.align 0x1000
17021724
.global _secondary_evbar
@@ -1711,13 +1733,13 @@ _secondary_evbar:
17111733

17121734
.section .rodata
17131735
_string_unhandled_exception:
1714-
.string "\n\rRunarunaround: Unhandled exception 0x\0"
1736+
.string "\r\nRunarunaround: Unhandled exception 0x\0"
17151737

17161738
_string_epc_prefix:
17171739
.string ": EPC=0x\0"
17181740

17191741
_string_nl:
1720-
.string "\n\r\0"
1742+
.string "\r\n\0"
17211743

17221744

17231745
/* ========================================[ page aligned structures ]=== */

0 commit comments

Comments
 (0)