1/** 2 * \file 3 * \brief The world's simplest serial driver. 4 * 5 */ 6 7/* 8 * Copyright (c) 2010, ETH Zurich. 9 * All rights reserved. 10 * 11 * This file is distributed under the terms in the attached LICENSE file. 12 * If you do not find this file, copies can be found by writing to: 13 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 14 */ 15 16#include <serial.h> 17#include <kputchar.h> 18#include <global.h> 19#include <barrelfish_kpi/spinlocks_arch.h> 20 21#define KPBUFSZ 256 22static char kputbuf[KPBUFSZ]; 23static int kcount = 0; 24 25static void kflush(void) 26{ 27 for(int i=0; i<kcount; i++) { 28 serial_console_putchar(kputbuf[i]); 29 } 30 kcount = 0; 31} 32 33void kprintf_begin(void) 34{ 35 acquire_spinlock(&global->locks.print); 36 kcount = 0; 37} 38 39int kputchar(int c) 40{ 41 kputbuf[kcount++] = c; 42 if (kcount == KPBUFSZ || c == '\n') { 43 kflush(); 44 } 45 return c; 46} 47 48void kprintf_end(void) 49{ 50 kflush(); 51 release_spinlock(&global->locks.print); 52} 53 54// End 55