Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2927379
  • 博文数量: 401
  • 博客积分: 12926
  • 博客等级: 上将
  • 技术积分: 4588
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 14:51
文章分类

全部博文(401)

文章存档

2015年(16)

2014年(4)

2013年(12)

2012年(82)

2011年(98)

2010年(112)

2009年(77)

分类: LINUX

2010-01-06 11:10:16

printk输出的log到串口上,配置串口用的是bootloader传过来的参数,例如console=ttyS0。
printascii是独立于printk的打印log的方法。printascii是汇编实现的,直接往uart发送寄存器里扔数据。所以在kernel开始,解析参数之前的log,就可以用printascii去看log.
为了支持 printascii()函数,需要在Kernel裁减中(make menuconfig)添加Kernel hacking-? [*]Kernel low-level debugging functions的支持。

arch/arm/kernel/debug.S

ENTRY(printascii)
addruart r3
b 2f
1: waituart r2, r3
senduart r1, r3
busyuart r2, r3
teq r1, #'\n'
moveq r1, #'\r'
beq 1b
2: teq r0, #0
ldrneb r1, [r0], #1
teqne r1, #0
bne 1b
mov pc, lr

可以看到addruart就是uart寄存器的地址base。所以只需要配置addruart的宏定义就可以了。

arch/arm/mach-pxa/include/mach/debug-macro.S

.macro addruart,rx
mrc p15, 0, \rx, c1, c0
tst \rx, #1 @ MMU enabled?
moveq \rx, #0x40000000 @ physical
movne \rx, #io_p2v(0x40000000) @ virtual
orr \rx, \rx, #CONFIG_DEBUG_UART_OFFSET
.endm

0x40000000是寄存器base, CONFIG_DEBUG_UART_OFFSET就是UART的寄存器偏移。
实际寄存器地址为:
#define STRBR      (volatile unsigned long *)( 0x40700000 )  // Receive Buffer Register (read only)
#define STTHR      (volatile unsigned long *)( 0x40700000 )  // Transmit Holding Register (write only)
#define STIER      (volatile unsigned long *)( 0x40700004 )  // Interrupt Enable Register (read/write)
#define STIIR      (volatile unsigned long *)( 0x40700008 )  // Interrupt ID Register (read only)
#define STFCR      (volatile unsigned long *)( 0x40700008 )  // FIFO Control Register (write only)
#define STLCR      (volatile unsigned long *)( 0x4070000C )  // Line Control Register (read/write)
#define STMCR      (volatile unsigned long *)( 0x40700010 )  // Modem Control Register (read/write)
#define STLSR      (volatile unsigned long *)( 0x40700014 )  // Line Status Register (read only)
#define STMSR      (volatile unsigned long *)( 0x40700018 )  // Modem Status Register (read only)
#define STSPR      (volatile unsigned long *)( 0x4070001C )  // Scratch Pad Register (read/write)
#define STISR      (volatile unsigned long *)( 0x40700020 )  // slow Infrared Select Register (read/write)
#define STFOR      (volatile unsigned long *)( 0x40700024 )  // Receive FIFO Occupancy Register (read/write)
#define STDLL      (volatile unsigned long *)( 0x40700000 )  // baud divisor lower byte (read/write)
#define STDLH      (volatile unsigned long *)( 0x40700004 )

只要配好了这些,就printacsii就可以打印到STUART上了。

阅读(3353) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~