summaryrefslogtreecommitdiff
path: root/src/pc80/serial.inc
blob: 7b80697c85dbb2694bdec555685f6c2ca8f874d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <part/fallback_boot.h>


/* Base Address */
#ifndef TTYS0_BASE
#define TTYS0_BASE	0x3f8
#endif

/* Baud Rate */
#ifndef TTYS0_BAUD
#define TTYS0_BAUD 115200
#endif

#if ((115200%TTYS0_BAUD) != 0)
#error Bad ttys0 baud rate
#endif

/* Baud Rate Divisor */
#define TTYS0_DIV	(115200/TTYS0_BAUD)
#define TTYS0_DIV_LO	(TTYS0_DIV&0xFF)
#define TTYS0_DIV_HI	((TTYS0_DIV >> 8)&0xFF)

/* Line Control Settings */
#ifndef TTYS0_LCS
/* Set 8bit, 1 stop bit, no parity */
#define TTYS0_LCS	0x3
#endif

/* Data */
#define TTYS0_RBR (TTYS0_BASE+0x00)

/* Control */
#define TTYS0_TBR TTYS0_RBR
#define TTYS0_IER (TTYS0_BASE+0x01)
#define TTYS0_IIR (TTYS0_BASE+0x02)
#define TTYS0_FCR TTYS0_IIR
#define TTYS0_LCR (TTYS0_BASE+0x03)
#define TTYS0_MCR (TTYS0_BASE+0x04)
#define TTYS0_DLL TTYS0_RBR
#define TTYS0_DLM TTYS0_IER

/* Status */
#define TTYS0_LSR (TTYS0_BASE+0x05)
#define TTYS0_MSR (TTYS0_BASE+0x06)
#define TTYS0_SCR (TTYS0_BASE+0x07)

#if USE_OPTION_TABLE == 1
.section ".rom.data"
	.type	 div,@object
	.size	 div,8
div:
.byte 1,2,3,6,12,24,48,96

.previous
#endif

	jmp	serial0

	/* uses:	ax, dx */
#define TTYS0_TX_AL		\
	mov	%al, %ah	; \
9:	mov	$TTYS0_LSR, %dx	; \
	inb	%dx, %al	; \
	test	$0x20, %al	; \
	je	9b		; \
	mov	$TTYS0_TBR, %dx	; \
	mov	%ah, %al	; \
	outb	%al, %dx

serial_init:
	/* Set 115.2Kbps,8n1 */
	/* Set 8bit, 1 stop bit, no parity, DLAB */
	mov	$TTYS0_LCR, %dx
	mov	$(TTYS0_LCS | 0x80), %al
	out	%al, %dx

	/* set Baud Rate Divisor to 1 ==> 115200 Buad */
#if USE_OPTION_TABLE == 1

	movb	$(RTC_BOOT_BYTE+1), %al
	outb	%al, $0x70
	xorl	%edx,%edx
	inb	$0x71, %al
	andb	$7,%al
	movb	%al,%dl
	movb	div(%edx),%al
	mov	$TTYS0_DLL, %dx
	out	%al, %dx
	mov	$TTYS0_DLM, %dx
	xorb	%al,%al
	out	%al, %dx
#else
	mov	$TTYS0_DLL, %dx
	mov	$TTYS0_DIV_LO, %al
	out	%al, %dx
	mov	$TTYS0_DLM, %dx
	mov	$TTYS0_DIV_HI, %al
	out	%al, %dx
#endif
	/* Disable DLAB */
	mov	$TTYS0_LCR, %dx
	mov	$(TTYS0_LCS & 0x7f), %al
	out	%al, %dx
	RETSP

serial0:
	CALLSP(serial_init)