📄 serialstream.cxx
字号:
/* * Copyright (C) 2001, Jonathan S. Shapiro. * * This file is part of the EROS Operating System. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* This is a serial debugging stream based closely on the earlier * logic introduced by Mike Hilsdale. */#include <kerninc/kernel.hxx>#include <kerninc/KernStream.hxx>#include <kerninc/IRQ.hxx>#include <eros/i486/io.h>#include <eros/i486/fixregs.h>#include "IDT.hxx"/* This class has a singleton instance! */struct SerialStream: public KernStream { void Init(); void Put(uint8_t c);#ifdef OPTION_DDB uint8_t Get(); void SetDebugging(bool onoff); void EnableDebuggerInput();#endif};#define COMIRQ IRQ386::Serial0#define COMBASE 0x3f8struct SerialStream TheSerialStream;KernStream* KernStream::SerialStream = &TheSerialStream;voidSerialStream::Init(){ uint16_t dlab = COMBASE + 3; /* Initialize COM port */ /* Currently: 9600, 8N1 */ /* (This seemes to not be needed when using VMware * and psuedo terminal pipes, but it's here for * completeness and for real hardware.) */ /* set DLAB bit */ /* b7=1 */ old_outb(dlab, inb(dlab) ^ 0x80); /* set 16-bit divisor to 12 (0Ch = 9600 baud) */ old_outb(COMBASE, 0x0C); old_outb(COMBASE + 1, 0); /* set data bits to 8 */ /* b0=1 b1=1 */ old_outb(dlab, inb(dlab) ^ 0x03); /* set parity to None */ /* b3=0 b4=4 b5=0 */ old_outb(dlab, inb(dlab) & 0xC7); /* set stop bits to 1 */ /* b2=0 */ old_outb(dlab, inb(dlab) & 0xFB); /* unset DLAB bit */ /* b7=0 */ old_outb(COMBASE + 3, inb(COMBASE + 3) & 0x70); /* tell COM port to report INTs on received char */ old_outb(COMBASE + 1, 1);}uint8_tSerialStream::Get(){ uint8_t c; /* This is incorrect: Should be spinning waiting for a valid * character! */ c = inb(COMBASE); return c;}voidSerialStream::Put(uint8_t c){ /* This *may* be incorrect. Should *probably* be spinning waiting * for room in the output fifo! */ old_outb(COMBASE, c); return;}voidSerialStream::SetDebugging(bool onOff){ debuggerIsActive = onOff; if (debuggerIsActive == false) IRQ::Enable(COMIRQ);}static voidSerialInterrupt(fixregs_t *sa){ char c; uint32_t irq = IRQ_FROM_EXCEPTION(sa->ExceptNo); /* look at interrupt id to quell UART */ /* may want to actually do something here sometime later */ inb(COMBASE + 2); if (KernStream::debuggerIsActive) return; assert(irq == COMIRQ); c = TheSerialStream.Get(); if (c == ASCII::ETX) Debugger(); IRQ::Enable(irq);}voidSerialStream::EnableDebuggerInput(){ IRQ::SetHandler(COMIRQ, SerialInterrupt); printf("Set up keyboard (console) interrupt handler!\n");#if 0 /* Establish initial keyboard state visibly: */ UpdateKbdLeds();#endif /* FIX: This may prove a problem, as I need to check exactly where * the interrupt vectors are set up in the boot sequence... */ IRQ::Enable(COMIRQ);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -