Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1826486
  • 博文数量: 286
  • 博客积分: 3713
  • 博客等级: 少校
  • 技术积分: 2275
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-11 09:47
个人简介

http://blog.chinaunix.net/uid/16979052.html

文章分类

全部博文(286)

文章存档

2018年(1)

2017年(16)

2016年(9)

2015年(17)

2014年(15)

2013年(112)

2012年(116)

分类: LINUX

2012-06-27 17:14:56

#include
#include
#include

static int early_serial_base = 0x3f8;  /*ttyS0*/
#define XMTRDY 0x20
#define DLAB 0x80
#define TXR 0 /*Transmit register(WRITE)*/
#define RXR 0 /*Receive register(READ)*/
#define IER 1 /*Interrupt Enable*/
#define IIR 2 /*Interrupt ID*/
#define FCR 2 /*FIFO control*/
#define LCR 3 /*Line control*/
#define MCR 4 /*Modem control*/
#define LSR 5 /*Line Status*/
#define MSR 6 /*Modem Status*/
#define DLL 0 /*Divisor Latch Low*/
#define DLH 1 /*Divisor latch High*/
static int early_serial_putc(uint8_t ch)
{
uint16_t timeout = 0xffff;
while((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
iodelay();
outb(early_serial_base + TXR, ch);
return timeout ? 0 : -1;
}

static void early_serial_write(const char *s, uint32_t n)
{
while(*s && n-- > 0)
{
if (*s == '\n')
early_serial_putc('\r');
early_serial_putc(*s);
s++;
}
}

int __printk(const char *file, int line, const char *fmt, ...)
{
int i;
char buf[512];
va_list args;
va_start(args, fmt);
//i = vsnprintf(buf, sizeof(buf), fmt, args);
i = vsprintf(buf, fmt, args);
va_end(args);
early_serial_write(buf, strlen(buf));
return i;
}

#define DEFAULT_BAUD 9600
void early_serial_init()
{
uint32_t port = 0;
uint8_t c;
uint32_t divisor;
uint32_t baud = DEFAULT_BAUD;
static const int bases[] = { 0x3f8, 0x2f8 };
early_serial_base = bases[port];
outb(early_serial_base + LCR, 0x3); /*8n1*/
outb(early_serial_base + IER, 0); /*no intr*/
outb(early_serial_base + FCR, 0); /*no fifo*/
outb(early_serial_base + MCR, 0x3); /*DTR+RTS*/
divisor = 115200 / baud;
c = inb(early_serial_base + LCR);
outb(early_serial_base + LCR, c | DLAB);
outb(early_serial_base + DLL, divisor & 0xff);
outb(early_serial_base + DLH, (divisor >> 8) & 0xff);
outb(early_serial_base + LCR, c & ~DLAB);
}

阅读(1396) | 评论(0) | 转发(0) |
0

上一篇:多PPPOE负载均衡

下一篇:include/multiboot.h

给主人留下些什么吧!~~