summaryrefslogtreecommitdiff
path: root/boot/tokenizer.s
blob: b1ac11f6c19cbdaaeeceebc0ec41ca319c8b07a1 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
.global _tokenizer_initialize

.section .rodata
#
# Classes:
#
# 0x00: Invalid
# 0x01: Digit
# 0x02: Character
# 0x03: Space
.type classes, @object
.size classes, 128
classes:
	.byte 0x00 # 00 NUL
	.byte 0x00 # 01 SOH
	.byte 0x00 # 02 STX
	.byte 0x00 # 03 ETX
	.byte 0x00 # 04 EOT
	.byte 0x00 # 05 ENQ
	.byte 0x00 # 06 ACK
	.byte 0x00 # 07 BEL
	.byte 0x00 # 08 BS
	.byte 0x00 # 09 HT
	.byte 0x00 # 0A LF
	.byte 0x00 # 0B VT
	.byte 0x00 # 0C FF
	.byte 0x00 # 0D CR
	.byte 0x00 # 0E SO
	.byte 0x00 # 0F SI
	.byte 0x00 # 10 DLE
	.byte 0x00 # 11 DC1
	.byte 0x00 # 12 DC2
	.byte 0x00 # 13 DC3
	.byte 0x00 # 14 DC4
	.byte 0x00 # 15 NAK
	.byte 0x00 # 16 SYN
	.byte 0x00 # 17 ETB
	.byte 0x00 # 18 CAN
	.byte 0x00 # 19 EM
	.byte 0x00 # 1A SUB
	.byte 0x00 # 1B ESC
	.byte 0x00 # 1C FS
	.byte 0x00 # 1D GS
	.byte 0x00 # 1E RS
	.byte 0x00 # 1F US
	.byte 0x03 # 20 Space
	.byte 0x00 # 21 !
	.byte 0x00 # 22 "
	.byte 0x00 # 23 #
	.byte 0x00 # 24 $
	.byte 0x00 # 25 %
	.byte 0x00 # 26 &
	.byte 0x00 # 27 '
	.byte 0x00 # 28 (
	.byte 0x00 # 29 )
	.byte 0x00 # 2A *
	.byte 0x00 # 2B +
	.byte 0x00 # 2C ,
	.byte 0x00 # 2D -
	.byte 0x00 # 2E .
	.byte 0x00 # 2F /
	.byte 0x01 # 30 0
	.byte 0x01 # 31 1
	.byte 0x01 # 32 2
	.byte 0x01 # 33 3
	.byte 0x01 # 34 4
	.byte 0x01 # 35 5
	.byte 0x01 # 36 6
	.byte 0x01 # 37 7
	.byte 0x01 # 38 8
	.byte 0x01 # 39 9
	.byte 0x00 # 3A :
	.byte 0x00 # 3B ;
	.byte 0x00 # 3C <
	.byte 0x00 # 3D =
	.byte 0x00 # 3E >
	.byte 0x00 # 3F ?
	.byte 0x00 # 40 @
	.byte 0x02 # 41 A
	.byte 0x02 # 42 B
	.byte 0x02 # 43 C
	.byte 0x02 # 44 D
	.byte 0x02 # 45 E
	.byte 0x02 # 46 F
	.byte 0x02 # 47 G
	.byte 0x02 # 48 H
	.byte 0x02 # 49 I
	.byte 0x02 # 4A J
	.byte 0x02 # 4B K
	.byte 0x02 # 4C L
	.byte 0x02 # 4D M
	.byte 0x02 # 4E N
	.byte 0x02 # 4F O
	.byte 0x02 # 50 P
	.byte 0x02 # 51 Q
	.byte 0x02 # 52 R
	.byte 0x02 # 53 S
	.byte 0x02 # 54 T
	.byte 0x02 # 55 U
	.byte 0x02 # 56 V
	.byte 0x02 # 57 W
	.byte 0x02 # 58 X
	.byte 0x02 # 59 Y
	.byte 0x02 # 5A Z
	.byte 0x00 # 5B [
	.byte 0x00 # 5C \
	.byte 0x00 # 5D ]
	.byte 0x00 # 5E ^
	.byte 0x00 # 5F _
	.byte 0x00 # 60 `
	.byte 0x02 # 61 a
	.byte 0x02 # 62 b
	.byte 0x02 # 63 c
	.byte 0x02 # 64 d
	.byte 0x02 # 65 e
	.byte 0x02 # 66 f
	.byte 0x02 # 67 g
	.byte 0x02 # 68 h
	.byte 0x02 # 69 i
	.byte 0x02 # 6A j
	.byte 0x02 # 6B k
	.byte 0x02 # 6C l
	.byte 0x02 # 6D m
	.byte 0x02 # 6E n
	.byte 0x02 # 6F o
	.byte 0x02 # 70 p
	.byte 0x02 # 71 q
	.byte 0x02 # 72 r
	.byte 0x02 # 73 s
	.byte 0x02 # 74 t
	.byte 0x02 # 75 u
	.byte 0x02 # 76 v
	.byte 0x02 # 77 w
	.byte 0x02 # 78 x
	.byte 0x02 # 79 y
	.byte 0x02 # 7A z
	.byte 0x00 # 7B {
	.byte 0x00 # 7C |
	.byte 0x00 # 7D }
	.byte 0x00 # 7E ~
	.byte 0x00 # 7F DEL

.section .data

.section .bss
.type class_names, @object
.size class_names, 1024
class_names: .zero 1024

.section .text

# Initializes the classification table.
#
# Paramaters:
# a0 - Raw input for the classification table.
.type _initialize_classes, @function
_initialize_classes:
	# Prologue.
	addi sp, sp, -24
	sw ra, 20(sp)
	sw s0, 16(sp)
	addi s0, sp, 24

	sw s1, 12(sp) # Preserve the s1 register used for the character counter.
	li s1, 128 # 128 ASCII characters.

.Linitialize_classes_loop:
	addi s1, s1, -1

	la t0, classes
	add t0, t0, s1
	lbu t0, (t0)
	li t1, 0x01

	bne t0, t1, .Linitialize_classes_step

	/* DEBUG */
	li a0, 0x69676964
	sw a0, 8(sp) # Preserve the memory address.
	addi a0, sp, 8
	li a1, 4
	call _write_error

.Linitialize_classes_step:
	bnez s1, .Linitialize_classes_loop

	lw s1, 12(sp) # Restore the saved register.

	# Epilogue.
	lw ra, 20(sp)
	lw s0, 16(sp)
	addi sp, sp, 24
	ret

# Initializes the lookup tables.
.type _tokenizer_initialize, @function
_tokenizer_initialize:
	# Prologue.
	addi sp, sp, -8
	sw ra, 4(sp)
	sw s0, 0(sp)
	addi s0, sp, 8

	call _initialize_classes

	# Epilogue.
	lw ra, 4(sp)
	lw s0, 0(sp)
	addi sp, sp, 8
	ret