3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <partition.h>
30 #include <net/socket.h>
35 unsigned char test
[80];
37 typedef void (*void_fn_void_t
)(void);
39 extern task_t task_list
;
40 extern vfs_t vfs_list
;
41 extern int cstrcmp (char *one
, char *two
);
42 extern unsigned long file_cache_id
;
43 extern task_t
*_curr_task
;
44 extern module_t
*module_load (char *modname
);
46 char *argparse (char *cmd
)
48 unsigned cmd_len
= strlen (cmd
);
62 static void wait (void)
66 for(wait
= WAIT
; wait
!= 0; wait
--)
84 if (!cstrcmp ("help", currtty
->shell
))
86 printf ("hdd Detect HDD\n");
87 printf ("help Print help\n");
88 printf ("reboot Reboot computer\n");
89 printf ("halt Shutdown computer\n");
90 printf ("tasks Print all tasks\n");
91 printf ("ps Print all process\n");
92 printf ("uptime Print uptime in seconds\n");
93 printf ("version Displays a version of system\n");
94 printf ("debug Change to developer mode\n");
95 printf ("mount Mount device to selected directory\n");
96 printf ("env Displays all env variables\n");
97 printf ("cd Change directory\n");
98 printf ("ls Displays files in current directory\n");
99 printf ("cat Displays text in selected file\n");
100 printf ("mkdir Create a directory\n");
101 printf ("exec Execute a selected program\n");
102 printf ("lsdev Displays found devices\n");
103 printf ("login Login as another user\n");
104 printf ("serialw Write data on rs232\n");
105 printf ("serialr Read data from rs232\n");
106 printf ("fdisk Partition table manipulator\n");
107 printf ("hdcat Read selected block of data from drive\n");
108 printf ("nc Clone of netcat (nc <address> <port>)\n");
109 printf ("free Display amount of free and used memory\n");
114 if (!cstrcmp ("tasks", currtty
->shell
))
116 puts ("name\tpriority\n");
119 for (task
= task_list
.next
; task
!= &task_list
; task
= task
->next
)
120 printf ("%s\t%u\n", task
->name
, task
->priority
);
125 if (!cstrcmp ("reboot", currtty
->shell
))
127 outportb (0x64, 0xFE);
132 if (!cstrcmp ("halt", currtty
->shell
))
136 puts ("\nSystem halted\nPlease press power button ..");
140 if (!cstrcmp ("uptime", currtty
->shell
))
147 if (!cstrcmp ("ls", currtty
->shell
))
149 strcpy (test
, argparse (currtty
->shell
));
156 if (!cstrcmp ("cd", currtty
->shell
))
158 strcpy (test
, argparse (currtty
->shell
));
165 if (!cstrcmp ("cat", currtty
->shell
))
167 strcpy (test
, argparse (currtty
->shell
));
168 unsigned file_len
= strlen (test
);
171 strcpy (pwd
, (char *) env_get ("PWD"));
174 for (vfs
= vfs_list
.next
; vfs
!= &vfs_list
; vfs
= vfs
->next
)
175 if (!strcmp (vfs
->mountpoint
, pwd
) &&
176 !cstrcmp (test
, vfs
->name
)) {
177 if (vfs
->attrib
& VFS_FILEATTR_DIR
) {
178 printf ("ERROR -> this is a directory, not an file\n");
182 /* check permissions */
183 if (vfs
->attrib
& VFS_FILEATTR_SYSTEM
&& strcmp ((char *) env_get ("USER"), "root")) {
184 printf ("ERROR -> only root can do that\n");
189 if (vfs
->attrib
& VFS_FILEATTR_MOUNTED
) {
190 partition_t
*p
= mount_find ((char *) env_get ("PWD"));
195 printf ("ERROR -> device not respond\n");
200 env_set ("PWD", pwd
);
205 printf ("No such file : %s\n", test
);
210 if (!cstrcmp ("mkdir", currtty
->shell
))
212 strcpy (test
, argparse (currtty
->shell
));
219 if (!cstrcmp ("hdd", currtty
->shell
))
228 outportb (0x70, 0x12);
233 printf ("/dev/hda not installed\n");
237 outportb (0x70, 0x1b);
239 outportb (0x70, 0x1c);
241 outportb (0x70, 0x1d);
243 outportb (0x70, 0x23);
245 printf ("/dev/hda installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
250 printf ("/dev/hdb not installed\n");
254 outportb (0x70, 0x24);
256 outportb (0x70, 0x25);
258 outportb (0x70, 0x26);
260 outportb (0x70, 0x2c);
262 printf ("/dev/hdb installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
268 if (!cstrcmp ("debug", currtty
->shell
))
272 DPRINT ("developer mode was enabled.");
277 DPRINT ("developer mode was disabled.");
283 /* if (!cstrcmp ("thread", currtty->shell))
287 proc_t *proc = proc_create (currtty, "thread", thread);
292 if (!strncmp ("./", currtty
->shell
, 2) || !cstrcmp ("exec", currtty
->shell
))
294 if (!strncmp ("./", currtty
->shell
, 2))
295 strcpy (test
, currtty
->shell
+2);
297 strcpy (test
, argparse (currtty
->shell
));
300 unsigned arg_len
= strlen (argparse (test
));
302 strcpy (arg
, argparse (test
));
305 unsigned test_len
= strlen (test
);
306 test
[test_len
-arg_len
] = '\0';
311 //printf ("l: %llu\n", file_cache_id);
313 unsigned char *bin
= (unsigned char *) kmalloc (sizeof (char) * file_cache_id
+ 1);
315 memcpy (bin
, file_cache
, file_cache_id
);
316 bin
[file_cache_id
] = '\0';
319 int err
= exec_elf (bin
, &entry
);
322 printf ("ERROR -> invalid ELF exec\n");
331 :: "g" (arg_len
), "b" (arg
));
333 proc_t
*proc
= proc_create (currtty
, bin
, entry
);
336 printf ("ERROR -> Invalid process: %s\n", test
);
339 /* send parameters to application */
342 // printf ("arg: '%s' - %d\n", arg, arg_len);
344 /* start application */
345 ((void_fn_void_t
) entry
) ();
347 /* free memory of app image */
353 if (!cstrcmp ("ps", currtty
->shell
))
360 if (!cstrcmp ("mount", currtty
->shell
))
363 strcpy (test
, argparse (currtty
->shell
));
367 unsigned l
= strlen (test
);
375 memcpy (devname
, test
, x
);
377 strcpy (mountpoint
, argparse (test
));
378 unsigned y
= strlen (mountpoint
);
380 if (mountpoint
[y
-1] != '/') {
382 mountpoint
[y
+1] = '\0';
386 partition_t
*p
= partition_find (devname
);
389 mount (p
, "", mountpoint
);
391 printf ("ERROR -> partition %s does not exists\n", devname
);
398 if (!cstrcmp ("env", currtty
->shell
))
405 if (!cstrcmp ("lsdev", currtty
->shell
))
412 if (!cstrcmp ("login", currtty
->shell
))
414 currtty
->user
= NULL
;
415 currtty
->logged
= false;
423 if (!cstrcmp ("version", currtty
->shell
))
430 if (!cstrcmp ("serialr", currtty
->shell
))
432 dev_t
*dev
= dev_find ("/dev/com0");
437 dev
->handler (DEV_ACT_READ
, data
, 10);
439 printf ("serialr: %s\n", data
);
445 if (!cstrcmp ("serialw", currtty
->shell
))
447 dev_t
*dev
= dev_find ("/dev/com0");
450 unsigned len
= strlen (argparse (currtty
->shell
));
452 memcpy (data
, argparse (currtty
->shell
), len
);
455 dev
->handler (DEV_ACT_WRITE
, data
, len
);
457 printf ("serialw: %s\n", data
);
463 if (!cstrcmp ("fdisk", currtty
->shell
))
469 if (!cstrcmp ("hdcat", currtty
->shell
))
471 partition_t
*p
= partition_find (argparse (currtty
->shell
));
474 dev_t
*dev
= dev_findbypartition (p
);
476 unsigned char block
[512];
478 printf ("dev: %s\n", dev
->devname
);
480 while (!key_pressed (1)) {
481 if (key_pressed (72) == 1) {
482 printf ("##block: %d\n", d
);
483 dev
->handler (DEV_ACT_READ
, p
, block
, "", d
);
485 for (c
= 0; c
< 512; c
++)
486 putch ((unsigned)block
[c
]);
493 printf ("Please specify partition, example: hdcat /dev/hda0\n");
498 /*if (!cstrcmp ("ircc", currtty->shell))
500 irc_client (argparse (currtty->shell), 6667);
504 if (!cstrcmp ("nc", currtty
->shell
))
506 strcpy (test
, argparse (currtty
->shell
));
511 unsigned l
= strlen (test
);
519 memcpy (arg1
, test
, x
);
522 strcpy (arg2
, argparse (test
));
524 nc (arg1
, atoi (arg2
));
529 if (!cstrcmp ("spk", currtty
->shell
))
531 unsigned int freq
= 20;
533 dev_t
*dev
= dev_find ("/dev/pcspk");
537 dev
->handler (DEV_ACT_PLAY
, freq
);
540 if (key_pressed (72) == 1) {
542 printf ("freq: %d\n", freq
);
545 if (key_pressed (80) == 1) {
547 printf ("freq: %d\n", freq
);
552 /* printf ("cislo: 0x%x je %d\n", 1193182UL/750, 1193182UL/750);
580 if (!cstrcmp ("killall", currtty
->shell
))
582 strcpy (test
, argparse (currtty
->shell
));
585 for (task
= task_list
.next
; task
!= &task_list
; task
= task
->next
) {
586 if (!strcmp (task
->name
, test
))
593 if (!cstrcmp ("free", currtty
->shell
))
600 if (!cstrcmp ("modprobe", currtty
->shell
))
602 unsigned arg_len
= strlen (argparse (currtty
->shell
));
604 strcpy (arg
, argparse (currtty
->shell
));
612 if (!cstrcmp ("date", currtty
->shell
))
616 printf ("%02u:%02u:%02u, %u.%u.%u\n", realtime
->tm_hour
, realtime
->tm_min
, realtime
->tm_sec
,
617 realtime
->tm_mday
, realtime
->tm_mon
, realtime
->tm_year
);
622 /* error -> command not found */
623 printf ("%s: command not found\n", currtty
->shell
);