Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
74afa70d
Commit
74afa70d
authored
15 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
Add serial port input/output.
Delete parallel port output. Works well with qemu -nographic mode.
parent
0ca9ca0c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
console.c
+5
-23
5 additions, 23 deletions
console.c
trap.c
+5
-0
5 additions, 0 deletions
trap.c
traps.h
+1
-0
1 addition, 0 deletions
traps.h
uart.c
+76
-0
76 additions, 0 deletions
uart.c
with
87 additions
and
23 deletions
console.c
+
5
−
23
View file @
74afa70d
// Console input and output.
// Input is from the keyboard o
nly
.
// Output is written to the screen and
the printer
port.
// Input is from the keyboard o
r serial port
.
// Output is written to the screen and
serial
port.
#include
"types.h"
#include
"defs.h"
...
...
@@ -13,31 +13,13 @@
#include
"x86.h"
#define CRTPORT 0x3d4
#define LPTPORT 0x378
#define BACKSPACE 0x100
static
ushort
*
crt
=
(
ushort
*
)
0xb8000
;
// CGA memory
static
struct
spinlock
console_lock
;
int
panicked
=
0
;
int
use_console_lock
=
0
;
// Copy console output to parallel port, which you can tell
// .bochsrc to copy to the stdout:
// parport1: enabled=1, file="/dev/stdout"
static
void
lptputc
(
int
c
)
{
int
i
;
for
(
i
=
0
;
!
(
inb
(
LPTPORT
+
1
)
&
0x80
)
&&
i
<
12800
;
i
++
)
;
if
(
c
==
BACKSPACE
)
c
=
'\b'
;
outb
(
LPTPORT
+
0
,
c
);
outb
(
LPTPORT
+
2
,
0x08
|
0x04
|
0x01
);
outb
(
LPTPORT
+
2
,
0x08
);
}
volatile
int
use_console_lock
=
0
;
static
void
cgaputc
(
int
c
)
...
...
@@ -80,14 +62,14 @@ consputc(int c)
;
}
lp
tputc
(
c
);
uar
tputc
(
c
);
cgaputc
(
c
);
}
void
printint
(
int
xx
,
int
base
,
int
sgn
)
{
static
char
digits
[]
=
"0123456789
ABCDEF
"
;
static
char
digits
[]
=
"0123456789
abcdef
"
;
char
buf
[
16
];
int
i
=
0
,
neg
=
0
;
uint
x
;
...
...
This diff is collapsed.
Click to expand it.
trap.c
+
5
−
0
View file @
74afa70d
...
...
@@ -62,6 +62,11 @@ trap(struct trapframe *tf)
kbdintr
();
lapiceoi
();
break
;
case
IRQ_OFFSET
+
IRQ_COM1
:
uartintr
();
lapiceoi
();
break
;
case
IRQ_OFFSET
+
7
:
case
IRQ_OFFSET
+
IRQ_SPURIOUS
:
cprintf
(
"cpu%d: spurious interrupt at %x:%x
\n
"
,
cpu
(),
tf
->
cs
,
tf
->
eip
);
...
...
This diff is collapsed.
Click to expand it.
traps.h
+
1
−
0
View file @
74afa70d
...
...
@@ -31,6 +31,7 @@
#define IRQ_TIMER 0
#define IRQ_KBD 1
#define IRQ_COM1 4
#define IRQ_IDE 14
#define IRQ_ERROR 19
#define IRQ_SPURIOUS 31
This diff is collapsed.
Click to expand it.
uart.c
0 → 100644
+
76
−
0
View file @
74afa70d
// Intel 8250 serial port (UART).
#include
"types.h"
#include
"defs.h"
#include
"param.h"
#include
"traps.h"
#include
"spinlock.h"
#include
"dev.h"
#include
"mmu.h"
#include
"proc.h"
#include
"x86.h"
#define COM1 0x3f8
static
int
uart
;
// is there a uart?
void
uartinit
(
void
)
{
char
*
p
;
// Turn off the FIFO
outb
(
COM1
+
2
,
0
);
// 9600 baud, 8 data bits, 1 stop bit, parity off.
outb
(
COM1
+
3
,
0x80
);
// Unlock divisor
outb
(
COM1
+
0
,
115200
/
9600
);
outb
(
COM1
+
1
,
0
);
outb
(
COM1
+
3
,
0x03
);
// Lock divisor, 8 data bits.
outb
(
COM1
+
4
,
0
);
outb
(
COM1
+
1
,
0x01
);
// Enable receive interrupts.
// If status is 0xFF, no serial port.
if
(
inb
(
COM1
+
5
)
==
0xFF
)
return
;
uart
=
1
;
// Acknowledge pre-existing interrupt conditions;
// enable interrupts.
inb
(
COM1
+
2
);
inb
(
COM1
+
0
);
picenable
(
IRQ_COM1
);
ioapicenable
(
IRQ_COM1
,
0
);
// Announce that we're here.
for
(
p
=
"xv6...
\n
"
;
*
p
;
p
++
)
uartputc
(
*
p
);
}
void
uartputc
(
int
c
)
{
int
i
;
if
(
!
uart
)
return
;
for
(
i
=
0
;
i
<
128
&&
!
(
inb
(
COM1
+
5
)
&
0x20
);
i
++
)
microdelay
(
10
);
outb
(
COM1
+
0
,
c
);
}
static
int
uartgetc
(
void
)
{
if
(
!
uart
)
return
-
1
;
if
(
!
(
inb
(
COM1
+
5
)
&
0x01
))
return
-
1
;
return
inb
(
COM1
+
0
);
}
void
uartintr
(
void
)
{
consoleintr
(
uartgetc
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment