POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/ppc/prep/cons.c
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #include <errno.h>
00019 
00020 #include "ioports.h"
00021 #include <libc.h>
00022 #include <core/debug.h>
00023 #include <core/cons.h>
00024 #include "cons.h"
00025 
00026 #if defined (POK_NEEDS_CONSOLE) || defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_INSTRUMENTATION) || defined (POK_NEEDS_COVERAGE_INFOS)
00027 
00028 #define  COM1      0x3F8
00029 
00030 static int is_transmit_empty(void)
00031 {
00032    return inb(COM1 + 5) & 0x20;
00033 }
00034 
00035 static void write_serial(char a)
00036 {
00037    while (is_transmit_empty() == 0)
00038      ;
00039 
00040    outb(COM1,a);
00041 }
00042 
00043 pok_bool_t pok_cons_write (const char *s, size_t length)
00044 {
00045    for (; length > 0; length--)
00046       write_serial (*s++);
00047    return 0;
00048 }
00049 
00050 
00051 int pok_cons_init (void)
00052 {
00053    outb(COM1 + 1, 0x00);    // Disable all interrupts
00054    outb(COM1 + 3, 0x80);    // Enable DLAB (set baud rate divisor)
00055    outb(COM1 + 0, 0x03);    // Set divisor to 3 (lo byte) 38400 baud
00056    outb(COM1 + 1, 0x00);    //                  (hi byte)
00057    outb(COM1 + 3, 0x03);    // 8 bits, no parity, one stop bit
00058    outb(COM1 + 2, 0xC7);    // Enable FIFO, clear them, with 14-byte threshold
00059    outb(COM1 + 4, 0x0B);    // IRQs enabled, RTS/DSR set
00060 
00061    pok_print_init (write_serial, NULL);
00062 
00063    return 0;
00064 
00065 
00066 }
00067 #else
00068 int pok_cons_init (void)
00069 {
00070    return 0;
00071 }
00072 #endif
00073 
00074