-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest8250.s
113 lines (98 loc) · 1.93 KB
/
test8250.s
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
108
109
110
111
112
113
# 8250 UART test
.def REG0 136
.def REG1 137
.def REG3 139
.def REG5 141
.def CLKDIVIDE 1 # 115200 / 1 = 115200 baud
ld sp, 0x8000
# lol:
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push CLKDIVIDE
call init8250
push 65
call write8250
push 66
call write8250
push 67
call write8250
# write letters
loop:
call read8250
ld x, r0
push x
call write8250
push 65
call write8250
push 66
call write8250
push 67
call write8250
jmp loop
# usage: init8250(CLKDIVIDE)
init8250:
# select divisor latches:
# write 0x80 to line control register
ld x, 0x80
out REG3, x
# set high byte of divisor latch = 0
ld x, 0
out REG1, x
# set low byte of divisor latch = CLKDIVIDE
pop x
out REG0, x
# select data register instead of divisor latches, and set 8-bit words, no parity, 1 stop:
# write 0x03 to line control register (addr 3)
ld x, 0x03
out REG3, x
ret
# usage: write8250(char)
write8250:
ld r253, r254 # stash return address
# spin until writable
write8250_loop:
call writable8250
test r0
jz write8250_loop
pop x
out REG0, x
jmp r253
# return 1 if ready to write, 0 otherwise
writable8250:
# read Line Status Register
in x, REG5
# bit 5 of Line Status Register is 1 when transmitter holding register is empty
and x, 32
jz ret0
ld r0, 1
ret
ret0:
ret
# usage: char = read8250()
read8250:
ld r253, r254 # stash return address
# spin until writable
read8250_loop:
call readable8250
test r0
jz read8250_loop
in r0, REG0
jmp r253
# return 1 if ready to read, 0 otherwise
readable8250:
# read Line Status Register
in x, REG5
# lsb of Line Status Register is 1 when data is ready
and x, 1
ld r0, x
ret