-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.s
292 lines (249 loc) · 4.84 KB
/
main.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/******************************************************************************
* main.s
* by Alex Chadwick
*
* A sample assembly code implementation of the input02 operating system, that
* demonstrates a command line interface.
*
* main.s contains the main operating system, and IVT code.
******************************************************************************/
/******************************************************************************
* Diego Jacobs 13160
* Ejercicio #5
******************************************************************************/
/*
* .globl is a directive to our assembler, that tells it to export this symbol
* to the elf file. Convention dictates that the symbol _start is used for the
* entry point, so this all has the net effect of setting the entry point here.
* Ultimately, this is useless as the elf itself is not used in the final
* result, and so the entry point really doesn't matter, but it aids clarity,
* allows simulators to run the elf, and also stops us getting a linker warning
* about having no entry point.
*/
.section .init
.globl _start
_start:
/*
* Branch to the actual main code.
*/
b main
/*
* This command tells the assembler to put this code with the rest.
*/
.section .text
/*
* main is what we shall call our main operating system method. It never
* returns, and takes no parameters.
* C++ Signature: void main(void)
*/
main:
/*
* Set the stack point to 0x8000.
*/
mov sp,#0x8000
/*
* Setup the screen.
*/
mov r0,#1024
mov r1,#768
mov r2,#16
bl InitialiseFrameBuffer
/*
* Check for a failed frame buffer.
*/
teq r0,#0
bne noError$
mov r0,#16
mov r1,#1
bl SetGpioFunction
mov r0,#16
mov r1,#0
bl SetGpio
error$:
b error$
noError$:
fbInfoAddr .req r4
mov fbInfoAddr,r0
/*
* Let our drawing method know where we are drawing to.
*/
bl SetGraphicsAddress
bl UsbInitialise
reset$:
mov sp,#0x8000
/*1.Limpiar pantalla*/
bl TerminalClear
/*2.Mensaje bienvenida*/
ldr r0,=welcome
mov r1,#welcomeEnd-welcome
bl Print
loop$:
/*2.Prompt*/
ldr r0,=prompt
mov r1,#promptEnd-prompt
bl Print
/*3.Leer comando ingresado*/
ldr r0,=command
mov r1,#commandEnd-command
bl ReadLine
teq r0,#0
beq loopContinue$
mov r4,r0 /*comando ingresado*/
ldr r5,=command
ldr r6,=commandTable
ldr r7,[r6,#0] /*cadena*/
ldr r9,[r6,#4] /*etiqueta*/
commandLoop$:
ldr r8,[r6,#8]
sub r1,r8,r7
/*compara si es comando valido (letra inicial)*/
cmp r1,r4
bgt commandLoopContinue$
mov r0,#0
commandName$:
/*compara letra x letra */
ldrb r2,[r5,r0]
ldrb r3,[r7,r0]
teq r2,r3
bne commandLoopContinue$
add r0,#1
teq r0,r1
bne commandName$
ldrb r2,[r5,r0]
teq r2,#0
teqne r2,#' '
bne commandLoopContinue$
mov r0,r5
mov r1,r4
mov lr,pc
mov pc,r9 /*salta a etiqueta de commandTable*/
b loopContinue$
commandLoopContinue$:
add r6,#8
mov r7,r8
ldr r9,[r6,#4]
teq r9,#0
bne commandLoop$
/*Sino es comando válido mostrar mensaje y regresar al paso 2*/
ldr r0,=commandUnknown
mov r1,#commandUnknownEnd-commandUnknown
ldr r2,=formatBuffer
ldr r3,=command
bl FormatString
mov r1,r0
ldr r0,=formatBuffer
bl Print
loopContinue$:
/*actualiza pantalla*/
bl TerminalDisplay
b loop$
echo:
cmp r1,#5
movle pc,lr
add r0,#5
sub r1,#5
b Print
ok:
teq r1,#5
beq okOn$
teq r1,#6
beq okOff$
mov pc,lr
okOn$:
ldrb r2,[r0,#3]
teq r2,#'o'
ldreqb r2,[r0,#4]
teqeq r2,#'n'
movne pc,lr
mov r1,#0
b okAct$
okOff$:
ldrb r2,[r0,#3]
teq r2,#'o'
ldreqb r2,[r0,#4]
teqeq r2,#'f'
ldreqb r2,[r0,#5]
teqeq r2,#'f'
movne pc,lr
mov r1,#1
okAct$:
mov r0,#16
b SetGpio
vocalnumero:
cmp r1,#12
movle pc,lr
add r0,#12
sub r1,#12
mov r2,#0
mov r11,#0
VN:
ldrb r10,[r0,r2]
cmp r10,#'a'
moveq r3,#'1'
beq strbeq
ldrb r10,[r0,r2]
cmp r10,#'e'
moveq r3,#'2'
beq strbeq
ldrb r10,[r0,r2]
cmp r10,#'i'
moveq r3,#'3'
beq strbeq
ldrb r10,[r0,r2]
cmp r10,#'o'
moveq r3,#'4'
beq strbeq
ldrb r10,[r0,r2]
cmp r10,#'u'
moveq r3,#'5'
beq strbeq
ciclo:
add r2,r2,#1
add r11,r11,#1
cmp r11,r1
ble VN
b Print
strbeq:
strb r3,[r0,r2]
b ciclo
.section .data
.align 2
welcome:
.ascii "Welcome to DJ's OS - Feel the power of the bytes"
welcomeEnd:
.align 2
prompt:
.ascii "\n¬ "
promptEnd:
.align 2
command:
.rept 128
.byte 0
.endr
commandEnd:
.byte 0
.align 2
commandUnknown:
.ascii "Command `%s' was not recognised.\n"
commandUnknownEnd:
.align 2
formatBuffer:
.rept 256
.byte 0
.endr
formatEnd:
.align 2
commandStringEcho: .ascii "echo"
commandStringReset: .ascii "reset"
commandStringOk: .ascii "ok"
commandStringCls: .ascii "cls"
commandStringVN: .ascii "vocalnumero"
commandStringEnd:
.align 2
commandTable:
.int commandStringEcho, echo
.int commandStringReset, reset$
.int commandStringOk, ok
.int commandStringCls, TerminalClear
.int commandStringVN, vocalnumero
.int commandStringEnd, 0