-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel-3.16.asm
485 lines (380 loc) · 9.46 KB
/
kernel-3.16.asm
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
;**********************Muse version 3.16******************
;*****************start of Muse 3 kernel code*************
[org 0x000]
[bits 16]
[SEGMENT .text]
;START #####################################################
mov ax, 0x0100 ;location where kernel is loaded
mov ds, ax
mov es, ax
cli
mov ss, ax ;stack segment
mov sp, 0xFFFF ;stack pointer at 64k limit
sti
push dx
push es
xor ax, ax
mov es, ax
cli
mov word [es:0x21*4], _int0x21 ; setup interrupt service
mov [es:0x21*4+2], cs
sti
pop es
pop dx
mov si, strWelcomeMsg ; load message
mov al, 0x01 ; request sub-service 0x01
int 0x21
call _shell ; call the shell
int 0x19 ; reboot
;END #######################################################
_int0x21:
_int0x21_ser0x01: ;service 0x01
cmp al, 0x01 ;see if service 0x01 wanted
jne _int0x21_end ;goto next check (now it is end)
_int0x21_ser0x01_start:
lodsb ; load next character
or al, al ; test for NUL character
jz _int0x21_ser0x01_end
mov ah, 0x0E ; BIOS teletype
mov bh, 0x00 ; display page 0
mov bl, 0x07 ; text attribute
int 0x10 ; invoke BIOS
jmp _int0x21_ser0x01_start
_int0x21_ser0x01_end:
jmp _int0x21_end
_int0x21_end:
iret
_shell:
_shell_begin:
;move to next line
call _display_endl
;display prompt
call _display_prompt
;get user command
call _get_command
;split command into components
call _split_cmd
;check command & perform action
; empty command
_cmd_none:
mov si, strCmd0
cmp BYTE [si], 0x00
jne _cmd_chkserial ;next command
jmp _cmd_done
;****************start_custom_command*************************
; display serial port info
_cmd_chkserial:
mov si, strCmd0
mov di, cmdSerial
mov cx,4
repe cmpsb
jne _cmd_info ;next command
call _display_endl
initialize:
mov ah, 0 ;initialize opcode to zero
mov al, 0xA7 ;parameter data (initializing port - refer to PDF)
mov dx, 0 ;parameter data (initializing port - refer to PDF)
int 0x14
transmit:
mov dx, 0 ;select COM1:
mov al, 'a' ;character to transmit-could be anything
mov ah, 1 ;transmit opcode
int 0x14
cmp ah, 0x80 ;Check for communication error
jnz serialerror
jz serialpresent
serialerror:
mov si, strNo ;serial port not installed
mov al, 0x01
int 0x21
serialpresent:
mov si, strYes ;serial port installed
mov al, 0x01
int 0x21
jmp _cmd_done
;*************************************************************
; display OS info
_cmd_info:
mov si, strCmd0
mov di, cmdInfo
mov cx, 5
repe cmpsb
jne _cmd_exit
call _display_endl
call _display_endl
mov si, txtName ;display hacker info string
mov al, 0x01
int 0x21
call _display_space
mov si, strName ;display hacker name
mov al, 0x01
int 0x21
call _display_endl
mov si, strOsName ;display OS name
mov al, 0x01
int 0x21
call _display_space
mov si, txtVersion ;display OS version
mov al, 0x01
int 0x21
call _display_space
mov si, strMajorVer
mov al, 0x01
int 0x21
mov si, strMinorVer
mov al, 0x01
int 0x21
call _display_endl
jmp _cmd_done
;*********************end_custom_command************************
; exit shell
_cmd_exit:
mov si, strCmd0
mov di, cmdExit
mov cx, 5
repe cmpsb
jne _cmd_unknown ;next command
je _shell_end ;exit from shell
_cmd_unknown:
call _display_endl
mov si, msgUnknownCmd ;unknown command
mov al, 0x01
int 0x21
_cmd_done:
;call _display_endl
jmp _shell_begin
_shell_end:
int 0x19
_get_command:
;initiate count
mov BYTE [cmdChrCnt], 0x00
mov di, strUserCmd
_get_cmd_start:
mov ah, 0x10 ;get character
int 0x16
cmp al, 0x00 ;check if extended key
je _extended_key
cmp al, 0xE0 ;check if new extended key
je _extended_key
cmp al, 0x08 ;check if backspace pressed
je _backspace_key
cmp al, 0x0D ;check if Enter pressed
je _enter_key
mov bh, [cmdMaxLen] ;check if maxlen reached
mov bl, [cmdChrCnt]
cmp bh, bl
je _get_cmd_start
;add char to buffer, display it and start again
mov [di], al ;add char to buffer
inc di ;increment buffer pointer
inc BYTE [cmdChrCnt] ;inc count
mov ah, 0x0E ;display character
mov bl, 0x07
int 0x10
jmp _get_cmd_start
_extended_key: ;extended key - do nothing now
jmp _get_cmd_start
_backspace_key:
mov bh, 0x00 ;check if count = 0
mov bl, [cmdChrCnt]
cmp bh, bl
je _get_cmd_start ;yes, do nothing
dec BYTE [cmdChrCnt] ;dec count
dec di
;check if beginning of line
mov ah, 0x03 ;read cursor position
mov bh, 0x00
int 0x10
cmp dl, 0x00
jne _move_back
dec dh
mov dl, 79
mov ah, 0x02
int 0x10
mov ah, 0x09 ; display without moving cursor
mov al, ' '
mov bh, 0x00
mov bl, 0x07
mov cx, 1 ; times to display
int 0x10
jmp _get_cmd_start
_move_back:
mov ah, 0x0E ; BIOS teletype acts on backspace!
mov bh, 0x00
mov bl, 0x07
int 0x10
mov ah, 0x09 ; display without moving cursor
mov al, ' '
mov bh, 0x00
mov bl, 0x07
mov cx, 1 ; times to display
int 0x10
jmp _get_cmd_start
_enter_key:
mov BYTE [di], 0x00
ret
_split_cmd:
;adjust si/di
mov si, strUserCmd
;mov di, strCmd0
;move blanks
_split_mb0_start:
cmp BYTE [si], 0x20
je _split_mb0_nb
jmp _split_mb0_end
_split_mb0_nb:
inc si
jmp _split_mb0_start
_split_mb0_end:
mov di, strCmd0
_split_1_start: ;get first string
cmp BYTE [si], 0x20
je _split_1_end
cmp BYTE [si], 0x00
je _split_1_end
mov al, [si]
mov [di], al
inc si
inc di
jmp _split_1_start
_split_1_end:
mov BYTE [di], 0x00
;move blanks
_split_mb1_start:
cmp BYTE [si], 0x20
je _split_mb1_nb
jmp _split_mb1_end
_split_mb1_nb:
inc si
jmp _split_mb1_start
_split_mb1_end:
mov di, strCmd1
_split_2_start: ;get second string
cmp BYTE [si], 0x20
je _split_2_end
cmp BYTE [si], 0x00
je _split_2_end
mov al, [si]
mov [di], al
inc si
inc di
jmp _split_2_start
_split_2_end:
mov BYTE [di], 0x00
;move blanks
_split_mb2_start:
cmp BYTE [si], 0x20
je _split_mb2_nb
jmp _split_mb2_end
_split_mb2_nb:
inc si
jmp _split_mb2_start
_split_mb2_end:
mov di, strCmd2
_split_3_start: ;get third string
cmp BYTE [si], 0x20
je _split_3_end
cmp BYTE [si], 0x00
je _split_3_end
mov al, [si]
mov [di], al
inc si
inc di
jmp _split_3_start
_split_3_end:
mov BYTE [di], 0x00
;move blanks
_split_mb3_start:
cmp BYTE [si], 0x20
je _split_mb3_nb
jmp _split_mb3_end
_split_mb3_nb:
inc si
jmp _split_mb3_start
_split_mb3_end:
mov di, strCmd3
_split_4_start: ;get fourth string
cmp BYTE [si], 0x20
je _split_4_end
cmp BYTE [si], 0x00
je _split_4_end
mov al, [si]
mov [di], al
inc si
inc di
jmp _split_4_start
_split_4_end:
mov BYTE [di], 0x00
;move blanks
_split_mb4_start:
cmp BYTE [si], 0x20
je _split_mb4_nb
jmp _split_mb4_end
_split_mb4_nb:
inc si
jmp _split_mb4_start
_split_mb4_end:
mov di, strCmd4
_split_5_start: ;get last string
cmp BYTE [si], 0x20
je _split_5_end
cmp BYTE [si], 0x00
je _split_5_end
mov al, [si]
mov [di], al
inc si
inc di
jmp _split_5_start
_split_5_end:
mov BYTE [di], 0x00
ret
_display_space:
mov ah, 0x0E ; BIOS teletype
mov al, 0x20
mov bh, 0x00 ; display page 0
mov bl, 0x07 ; text attribute
int 0x10 ; invoke BIOS
ret
_display_endl:
mov ah, 0x0E ; BIOS teletype acts on newline!
mov al, 0x0D
mov bh, 0x00
mov bl, 0x07
int 0x10
mov ah, 0x0E ; BIOS teletype acts on linefeed!
mov al, 0x0A
mov bh, 0x00
mov bl, 0x07
int 0x10
ret
_display_prompt:
mov si, strPrompt
mov al, 0x01
int 0x21
ret
[SEGMENT .data]
strWelcomeMsg db "Welcome to Muse 3, based on JOSH ver 3.0", 0x00
strPrompt db "muse$>", 0x00
cmdMaxLen db 255 ;maximum length of commands
strName db "Gokul", 0x00
strYes db 13,10,"A serial port is present on your computer.", 0x00
strNo db 13,10,"A serial port was not found on your computer.", 0x00
strOsName db "Muse", 0x00 ;OS details
strMajorVer db "3", 0x00
strMinorVer db ".16", 0x00
cmdSerial db "chkserial", 0x00 ; internal commands
cmdVer db "ver", 0x00 ; internal commands
cmdExit db "exit", 0x00
cmdInfo db "info", 0x00
txtVersion db "Current OS version:", 0x00 ;messages and other strings
txtName db "This version of JOSH was hacked by ", 0x00
msgUnknownCmd db "Unknown command or bad filename.", 0x00
[SEGMENT .bss]
strUserCmd resb 256 ;buffer for user commands
cmdChrCnt resb 1 ;count of characters
strCmd0 resb 256 ;buffers for the command components
strCmd1 resb 256
strCmd2 resb 256
strCmd3 resb 256
strCmd4 resb 256
;********************end of Muse 3 kernel code********************