3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <partition.h>
34 #include <net/socket.h>
48 command_t command_list
;
49 extern partition_t partition_list
;
51 unsigned char test
[80];
53 typedef void (*void_fn_void_t
)(void);
55 extern task_t task_list
;
56 extern vfs_t vfs_list
;
57 extern int cstrcmp (char *one
, char *two
);
58 extern unsigned long file_cache_id
;
59 extern task_t
*_curr_task
;
60 extern module_t
*module_load (char *modname
);
61 extern unsigned long timer_ticks
;
62 extern unsigned vgagui
;
64 char *argparse (char *cmd
)
66 unsigned cmd_len
= strlen (cmd
);
79 /*************************************************************\
81 \*************************************************************/
84 unsigned command_help (char *command
, unsigned len
)
92 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
95 printf ("\n%s : %s", ctx
->name
, ctx
->desc
);
97 if (i
>= 24 && vgagui
!= 2) {
99 printf ("\nPress enter to continue");
101 settextcolor (15, 0);
104 /* wait, until enter key is pressed */
106 if (tty
== currtty
) {
107 if (getkey () != '\n')
124 unsigned command_hdd (char *command
, unsigned len
)
139 printf ("/dev/hda not installed\n");
151 printf ("/dev/hda installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
156 printf ("/dev/hdb not installed\n");
168 printf ("/dev/hdb installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
175 unsigned command_reboot (char *command
, unsigned len
)
184 unsigned command_halt (char *command
, unsigned len
)
186 arch_cpu_shutdown ();
188 puts ("\nSystem halted\nPlease press power button ..");
197 unsigned command_tasks (char *command
, unsigned len
)
199 puts ("id\tname\tpriority\n");
202 for (task
= task_list
.next
; task
!= &task_list
; task
= task
->next
)
203 printf ("%d\t%s\t%u\n", task
->id
, task
->name
, task
->priority
);
208 unsigned command_ps (char *command
, unsigned len
)
215 unsigned command_uptime (char *command
, unsigned len
)
222 unsigned command_version (char *command
, unsigned len
)
229 unsigned command_debug (char *command
, unsigned len
)
233 DPRINT ("developer mode was enabled.");
238 DPRINT ("developer mode was disabled.");
244 unsigned command_mount (char *command
, unsigned len
)
246 strcpy (test
, argparse (command
));
250 unsigned l
= strlen (test
);
258 memcpy (devname
, test
, x
);
260 strcpy (mountpoint
, argparse (test
));
261 unsigned y
= strlen (mountpoint
);
263 if (mountpoint
[y
-1] != '/') {
265 mountpoint
[y
+1] = '\0';
269 partition_t
*p
= partition_find (devname
);
272 mount (p
, "", mountpoint
);
274 printf ("ERROR -> partition %s does not exists\n", devname
);
281 unsigned command_umount (char *command
, unsigned len
)
284 strcpy (mountpoint
, argparse (command
));
286 unsigned y
= strlen (mountpoint
);
289 if (mountpoint
[y
-1] != '/') {
291 mountpoint
[y
+1] = '\0';
295 partition_t
*partition
;
296 for (partition
= partition_list
.next
; partition
!= &partition_list
; partition
= partition
->next
) {
297 if (umount (partition
, mountpoint
))
302 printf ("ERROR -> directory %s is not mounted\n", mountpoint
);
305 printf ("WARNING -> multiple (%d) umount of %s\n", x
, mountpoint
);
312 unsigned command_env (char *command
, unsigned len
)
319 unsigned command_cd (char *command
, unsigned len
)
321 strcpy (test
, argparse (command
));
328 unsigned command_ls (char *command
, unsigned len
)
330 strcpy (test
, argparse (command
));
337 unsigned command_cat (char *command
, unsigned len
)
339 strcpy (test
, argparse (command
));
346 unsigned command_rm (char *command
, unsigned len
)
348 strcpy (test
, argparse (command
));
355 unsigned command_mkdir (char *command
, unsigned len
)
357 strcpy (test
, argparse (command
));
364 unsigned command_touch (char *command
, unsigned len
)
366 strcpy (test
, argparse (command
));
373 unsigned command_exec (char *command
, unsigned len
)
375 if (!strncmp ("./", command
, 2))
376 strcpy (test
, command
+2);
378 strcpy (test
, argparse (command
));
380 unsigned arg_len
= strlen (argparse (test
));
382 strcpy (arg
, argparse (test
));
385 unsigned test_len
= strlen (test
);
387 /* lock current tty keyboard */
390 /* if there is argument after name, rewrite space character to zero */
391 if (test
[test_len
-(arg_len
+1)] == ' ')
392 test
[test_len
-(arg_len
+1)] = '\0';
394 test
[test_len
-arg_len
] = '\0';
396 /* read file data from filesystem */
397 int ret
= vfs_read (test
, strlen (test
));
400 printf ("%s: command not found\n", test
);
401 DPRINT ("ERROR -> vfs_read () - '%s'\n", test
);
402 tty_unlock (currtty
);
406 unsigned bin_len
= file_cache_id
;
408 unsigned char *bin
= (unsigned char *) swmalloc (bin_len
);
411 printf ("ERROR -> out of memory\n");
415 /* copy image to page aligned memory */
416 memcpy (bin
, file_cache
, bin_len
);
418 bin
[file_cache_id
] = '\0';
420 unsigned entry
, code
, data
, data_off
, bss
;
421 int err
= exec_elf (bin
, &entry
, &data
, &data_off
, &bss
);
424 printf ("ERROR -> invalid ELF exec\n");
425 tty_unlock (currtty
);
430 proc_t
*proc
= proc_create (currtty
, test
, entry
);
432 /* check for & character as app parameter */
434 while (d
< arg_len
) {
436 if (proc_flag_set (proc
, PROC_FLAG_DAEMON
))
437 printf ("%s: started as daemon\n", test
);
441 if (arg_len
> 2 && arg
[d
-1] == ' ') {
454 printf ("ERROR -> Invalid process: %s\n", test
);
456 tty_unlock (currtty
);
458 /* free image of elf-bss section */
461 /* free program image */
466 /* save process information to structure for later use */
467 proc
->start
= (unsigned) bin
;
470 proc
->data_off
= data_off
;
472 proc
->end
= (unsigned) (bin
+ bin_len
);
476 /* well, set argument for out app */
477 proc_arg_set (proc
, arg
, arg_len
);
479 proc_vmem_map (proc
);
481 /* Is this process started as daemon ? */
482 /* wait here, until pid != 0*/
483 if (!(proc
->flags
& PROC_FLAG_DAEMON
))
487 /* enable interrupts */
490 /* unlock tty console - user can write in */
491 tty_unlock (currtty
);
493 _curr_task
= proc
->tty
->task
; // this is pretty needed for correct return to our tty task
495 if (!(proc
->flags
& PROC_FLAG_DAEMON
)) {
496 if (!proc_done (proc
))
497 while (1) // NOTE: heh, this is good stuff :P
500 /* free image of elf-bss section */
503 /* free program image */
504 swfree (bin
, bin_len
);
507 /* switch to next task */
513 unsigned command_lsdev (char *command
, unsigned len
)
520 unsigned command_login (char *command
, unsigned len
)
522 currtty
->user
= NULL
;
523 currtty
->logged
= false;
531 unsigned command_serialw (char *command
, unsigned len
)
533 dev_t
*dev
= dev_find ("/dev/com0");
536 unsigned len
= strlen (argparse (command
));
538 memcpy (data
, argparse (command
), len
);
541 dev
->handler (DEV_ACT_WRITE
, data
, len
);
543 printf ("serialw: %s\n", data
);
549 unsigned command_serialr (char *command
, unsigned len
)
551 dev_t
*dev
= dev_find ("/dev/com0");
556 dev
->handler (DEV_ACT_READ
, data
, 1);
558 printf ("serialr: %s\n", data
);
564 unsigned command_fdisk (char *command
, unsigned len
)
571 unsigned command_hdcat (char *command
, unsigned len
)
575 partition_t
*p
= partition_find (argparse (command
));
578 dev_t
*dev
= (dev_t
*) dev_findbypartition (p
);
580 unsigned char block
[512];
582 printf ("dev: %s\n", dev
->devname
);
584 while (!key_pressed (1)) {
585 if (key_pressed (72) == 1) {
586 printf ("##block: %d\n", d
);
587 dev
->handler (DEV_ACT_READ
, p
, block
, "", d
);
589 for (c
= 0; c
< 512; c
++)
590 putch ((unsigned)block
[c
]);
597 printf ("Please specify partition, example: hdcat /dev/hda0\n");
599 tty_unlock (currtty
);
604 unsigned command_free (char *command
, unsigned len
)
611 unsigned command_date (char *command
, unsigned len
)
615 printf ("%02u:%02u:%02u, %u.%u.%u\n", realtime
->tm_hour
, realtime
->tm_min
, realtime
->tm_sec
,
616 realtime
->tm_mday
, realtime
->tm_mon
, realtime
->tm_year
);
656 void play_tone (dev_t
*dev
, char tone
, char type
, char time
)
678 printf ("play_tone (.., %c, %d, %d);\n", tone
, t
, tt
);
682 dev
->handler (DEV_ACT_PLAY
, 131*t
);
685 dev
->handler (DEV_ACT_PLAY
, 147*t
);
688 dev
->handler (DEV_ACT_PLAY
, 165*t
);
691 dev
->handler (DEV_ACT_PLAY
, 175*t
);
694 dev
->handler (DEV_ACT_PLAY
, 196*t
);
697 dev
->handler (DEV_ACT_PLAY
, 220*t
);
700 dev
->handler (DEV_ACT_PLAY
, 247*t
);
703 dev
->handler (DEV_ACT_PLAY
, 136*t
);
706 dev
->handler (DEV_ACT_PLAY
, 188*t
);
724 printf ("end: play_tone ();\n");
726 dev
->handler (DEV_ACT_PLAY
, 0);
729 void play_song (dev_t
*dev
, char *data
)
731 printf ("play_song ();\n");
732 unsigned i
= 0, l
= strlen (data
);
736 printf ("switch ()\n");
757 play_tone (dev
, data
[i
], data
[i
+1], data
[i
+2]);
767 unsigned command_spk (char *command
, unsigned len
)
769 unsigned int freq
= 20;
771 dev_t
*dev
= dev_find ("/dev/pcspk");
775 We wish you a merry christmas v1.0
777 D2(1/8) G2(1/8) G2(1/16) A2(1/16) G2(1/16) Fis2(1/16) E2(1/8) C2(1/8) E2(1/8) A2(1/8) A2(1/16) H2(1/16) A2(1/16) G2(1/16) Fis2(1/8) D2(1/4) H2(1/8) H2(1/16) C3(1/16) H2(1/16) A2(1/16) G2(1/8) E2(1/8) D2(1/16) D2(1/16) E2(1/8) A2(1/8) Fis2(1/8) G2(1/8)
780 play_song (dev
, "d21 g21 g22 a22 g22 F22 e21 c21 e21 a21 a22 h22 a22 g22 F21 d20 h21 h22 c32 h22 a22 g21 e21 d22 d22 e21 a21 F21 g21");
785 We wish you a merry christmas v3.0
787 G2(1/8) C3(1/8) C3(1/16) D3(1/16) C3(1/16) H2(1/16) A2(1/4) D3(1/8) D3(1/16) E3(1/16) D3(1/16) C3(1/16) H2(1/4) G2(1/8) E3(1/8) E3(1/16) F3(1/16) E3(1/16) D3(1/16) C3(1/8) A2(1/8) G2(1/8) A2(1/8) D3(1/8) H2(1/8) C3(1/8)
790 play_song (dev
, "g21 c31 c32 d32 c32 h22 a20 d31 d32 e32 d32 c32 h20 g21 e31 e32 f32 e32 d32 c31 a21 g21 a21 d31 h21 c31");
796 G2(1/8) C3(1/8) P(1/16) G2(1/16) G3(1/8) C3(1/16) E3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) G3(1/16) P(1/16) G2(1/8) C3(1/8) A3(1/8) G3(1/8) E3(1/16) F3(1/16) G3(1/8) D3(1/16) E3(1/16) C3(1/8) G2(1/8) C3(1/8) E3(1/16) F3(1/16) D3(1/8) G3(1/8) G3(1/8)
798 /* play_song (dev, "g21 c31 p2 g22 g31 c32 e31 d32 e32 c31 g21 c31 a31 g31 e32 f32 g31 g32 p2 g21 c31 a31 g31 e32 f32 g31 d32 e32 c31 g21 c31 e32 f32 d31 g31 g31");*/
806 extern bool bus_pci_acthandler (unsigned act
, char *block
, unsigned block_len
);
807 extern netif_t netif_list
;
808 extern void ext2_dump ();
815 unsigned long timer_start
= timer_ticks
+ ((unsigned) 1 * 1000);
817 while (timer_start
> timer_ticks
)
822 extern unsigned start
;
824 extern bool ide_acthandler (unsigned act
, partition_t
*p
, char *block
, char *more
, int n
);
825 unsigned command_test (char *command
, unsigned len
)
829 /*partition_t *p = partition_find ("/dev/hda0");
832 mount (p, "", "/mnt/hdd/");
834 printf ("WARNING -> partition /dev/hda0 does not exists\n");
836 //char *t = (char *) 0x400000+0x1;
839 //printf ("ddd: 0x%x, 0x%x\n", start, end);
841 /* paging_disable ();
843 task_t *task = task_find (0);
847 char *t = (char *) 0x400000;
854 printf ("Start2: 0x%x\n", *t);
855 unsigned r = page_mmap (task->page_cover, (void *) 0x0, (void *) 0x1000, 1, 0);
869 printf ("Start3: 0x%x\n", *t);
875 t = (char *) 0x400000;
877 printf ("Start4: 0x%x\n", *t);
883 cd ((char *) "/mnt/floppy");
888 command_exec ("exec sh", 7);
895 /* Create virtual block device */
897 dev_t
*dev
= (dev_t
*) dev_register ("vbd", "Virtual Block Device", DEV_ATTR_BLOCK
, (dev_handler_t
*) &ide_acthandler
);
899 partition_t
*p
= partition_add (dev
, fs_supported ("znfs"));
901 znfs_init (partition_add (dev
, fs_supported ("znfs")), "192.168.1.2"); // small HACK
904 mount (p
, "", "/mnt/hdd/");
906 printf ("WARNING -> partition /dev/hda0 does not exists\n");
908 cd ((char *) "/mnt/hdd");
910 //printf ("Je to na 0x%x\n", vesafb);
914 unsigned command_test2 (char *command
, unsigned len
)
920 unsigned command_test3 (char *command
, unsigned len
)
926 unsigned command_test4 (char *command
, unsigned len
)
934 extern void ps2mouse_get_status (int *x, int *y, int *state);
935 extern unsigned ps2mouse_install ();
936 unsigned command_mouse (char *command, unsigned len)
938 printf ("PS/2 Mouse test\n");
947 ps2mouse_get_status (&x, &y, &state);
949 if (x != x2 && y != y2)
950 printf ("mys: %d %d %d\n", x, y, state);
962 unsigned command_vesa (char *command
, unsigned len
)
964 if (!init_video_vesa ())
965 printf ("vesa -> failed\n");
970 unsigned command_kill (char *command
, unsigned len
)
972 strcpy (test
, argparse (currtty
->shell
));
974 pid_t pid
= (pid_t
) atoi (test
);
976 proc_t
*proc
= proc_findbypid (pid
);
979 printf ("kill: (%s) - No such process\n", test
);
983 /* send SIGTERM to selected process */
984 if (!proc_signal (proc
, SIGTERM
))
987 /* check for daemon */
988 if (proc
->flags
& PROC_FLAG_DAEMON
)
989 if (!proc_done (proc
))
995 unsigned command_modprobe (char *command
, unsigned len
)
997 unsigned arg_len
= strlen (argparse (currtty
->shell
));
999 strcpy (arg
, argparse (currtty
->shell
));
1000 arg
[arg_len
] = '\0';
1007 unsigned command_lsmod (char *command
, unsigned len
)
1014 #ifdef CONFIG_DRV_PCI
1015 unsigned command_lspci (char *command
, unsigned len
)
1024 unsigned command_iflist (char *command
, unsigned len
)
1031 unsigned command_ifconfig (char *command
, unsigned len
)
1033 strcpy (test
, argparse (command
));
1037 unsigned l
= strlen (test
);
1045 memcpy (ifid
, test
, x
);
1048 strcpy (ip
, argparse (test
));
1049 unsigned y
= strlen (ip
);
1051 netif_t
*netif
= netif_findbyname (ifid
);
1054 printf ("ifconfig -> bad network interface name, example: eth0\n");
1060 if (ipv4
= net_proto_ip_convert (ip
)) {
1061 netif_ip_addr (netif
, ipv4
);
1063 printf ("%s: IPv4 ", ifid
);
1064 net_proto_ip_print (ipv4
);
1066 } else if (net_proto_ipv6_convert (ipv6
, ip
)) {
1067 netif_ipv6_addr (netif
, ipv6
);
1069 printf ("%s: IPv6 ", ifid
);
1070 net_proto_ipv6_print (ipv6
);
1073 printf ("ifconfig -> bad ip address format, example:\n\t\t192.168.1.1 for IPv4\n\t\tfc00:0:0:0:0:0:0:10 for IPv6\n");
1080 unsigned command_ifroute (char *command
, unsigned len
)
1082 strcpy (test
, argparse (command
));
1086 unsigned l
= strlen (test
);
1094 memcpy (ifid
, test
, x
);
1097 strcpy (ip
, argparse (test
));
1098 unsigned y
= strlen (ip
);
1100 netif_t
*netif
= netif_findbyname (ifid
);
1103 printf ("ifroute -> bad network interface name, example: eth0\n");
1128 printf ("ifroute -> bad ip address format, example: 192.168.1.254\n");
1137 printf ("%s->gw: %d.%d.%d.%d - OK\n", ifid
, a
, b
, c
, d
);
1139 return netif_gw_addr (netif
, NET_IPV4_TO_ADDR (a
, b
, c
, d
));
1142 unsigned command_dnsconfig (char *command
, unsigned len
)
1144 strcpy (test
, argparse (currtty
->shell
));
1149 unsigned l
= strlen (test
);
1152 printf ("dnsconfig -> your domain name server is: ");
1153 net_proto_ip_print (dns_addr_get ());
1159 printf ("dnsconfig: %s - OK\n", test
);
1161 net_ipv4 dns
= net_proto_ip_convert (test
);
1171 unsigned command_tunconfig (char *command
, unsigned len
)
1173 strcpy (test
, argparse (currtty
->shell
));
1178 unsigned l
= strlen (test
);
1181 printf ("tunconfig -> wrong syntax !\ntunconfig <ipv4tunnel> for enable or tunconfig 0 for disable\n");
1186 /* you can disable this service over character '0' as parameter */
1187 if (l
== 1 && test
[0] == '0') {
1190 printf ("tunconfig: disabled - OK\n");
1195 /* classical ipv4 address from tunnel server */
1196 net_ipv4 tunnel
= net_proto_ip_convert (test
);
1199 printf ("tunconfig -> wrong syntax !\nExample: tunconfig 216.66.80.30\n");
1206 printf ("tunconfig: ::%s - OK\n", test
);
1211 unsigned command_kbdmap (char *command
, unsigned len
)
1213 strcpy (test
, argparse (currtty
->shell
));
1218 unsigned ret
= keyboard_setlayout (test
);
1221 printf ("Keyboard layout was changed to '%s'\n", test
);
1226 unsigned command_mkzexfs (char *command
, unsigned len
)
1229 strcpy (test
, argparse (currtty
->shell
));
1234 partition_t
*p
= partition_find ("/dev/hda0");
1241 unsigned command_mkext2 (char *command
, unsigned len
)
1244 strcpy (test
, argparse (currtty
->shell
));
1249 partition_t
*p
= partition_find ("/dev/hda0");
1256 unsigned command_ping (char *command
, unsigned len
)
1258 strcpy (test
, argparse (currtty
->shell
));
1263 netif_t
*netif
= netif_findbyname ("eth0");
1266 printf ("ping -> network interface does not exists\n");
1277 unsigned y
= strlen (test
);
1280 printf ("ping -> wrong syntax, please specify address\n");
1287 if (test
[i
] == '.') {
1296 net_ipv4 target
= 0;
1299 strcpy (test
, argparse (currtty
->shell
));
1300 target
= dns_cache_get (test
);
1303 target
= dns_send_request (test
);
1306 printf ("ping -> bad hostname or ip address format, example: 192.168.1.1\n");
1311 b
= atoi (test
+h
[0]);
1312 c
= atoi (test
+h
[1]);
1313 d
= atoi (test
+h
[2]);
1315 target
= NET_IPV4_TO_ADDR (a
, b
, c
, d
);
1317 strcpy (test
, argparse (currtty
->shell
));
1321 net_proto_ip_convert2 (target
, address
);
1326 unsigned long time_a
= timer_ticks
;
1327 unsigned ret
= net_proto_icmp_ping (netif
, target
);
1329 printf ("ping -> %s (%s) - %ums\n", test
, address
, (timer_ticks
- time_a
));
1331 printf ("ping -> Host %s is unreachable\n", test
);
1341 unsigned command_ping6 (char *command
, unsigned len
)
1343 strcpy (test
, argparse (currtty
->shell
));
1348 netif_t
*netif
= netif_findbyname ("eth0");
1351 printf ("ping -> network interface does not exists\n");
1366 unsigned y
= strlen (test
);
1369 printf ("ping -> wrong syntax, please specify ipv6 address\n");
1376 if (test
[i
] == ':') {
1388 /*strcpy (test, argparse (currtty->shell));
1389 target = dns_cache_get (test);
1392 target = dns_send_request (test);
1395 // printf ("ping -> bad hostname or ip address format, example: 192.168.1.1\n");
1398 printf ("ping -> wrong syntax, please specify ipv6 address\n");
1403 a
= strtol (test
, &endptr
, 16);
1404 b
= strtol (test
+k
[0], &endptr
, 16);
1405 c
= strtol (test
+k
[1], &endptr
, 16);
1406 d
= strtol (test
+k
[2], &endptr
, 16);
1407 e
= strtol (test
+k
[3], &endptr
, 16);
1408 f
= strtol (test
+k
[4], &endptr
, 16);
1409 g
= strtol (test
+k
[5], &endptr
, 16);
1410 h
= strtol (test
+k
[6], &endptr
, 16);
1412 NET_IPV6_TO_ADDR (target
, a
, b
, c
, d
, e
, f
, g
, h
);
1414 //printf ("ipv6: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", a, b, c, d, e, f, g, h);
1416 strcpy (test
, argparse (currtty
->shell
));
1420 //net_proto_ipv6_convert2 (target, address);
1425 unsigned long time_a
= timer_ticks
;
1426 unsigned ret
= net_proto_icmp6_ping (netif
, target
);
1428 printf ("ping6 -> %s (%s) - %ums\n", test
, test
, (timer_ticks
- time_a
));
1430 printf ("ping6 -> Host %s is unreachable\n", test
);
1440 unsigned command_netexec (char *command
, unsigned len
)
1442 strcpy (test
, argparse (command
));
1447 if (!strlen (test
)) {
1448 printf ("Syntax:\nnetexec <ip_of_tftp> <filename> [parameters]\n");
1452 unsigned arg_len
= strlen (argparse (test
));
1453 char arg
[arg_len
+1];
1454 strcpy (arg
, argparse (test
));
1455 arg
[arg_len
] = '\0';
1457 unsigned test_len
= strlen (test
);
1458 test
[test_len
-arg_len
] = '\0';
1460 if (test
[test_len
-arg_len
-1] == ' ') {
1461 test
[test_len
-arg_len
-1] = '\0';
1465 char file
[arg_len
+1];
1466 unsigned file_len
= 0;
1467 memcpy (file
, arg
, arg_len
);
1468 while (file_len
< arg_len
) {
1469 if (file
[file_len
] == ' ') {
1470 file
[file_len
] = '\0';
1476 if (file
[arg_len
] != '\0')
1477 file
[arg_len
] = '\0';
1479 unsigned l
= file_len
;
1481 unsigned ret
= tftp_client_connect (test
, 69, file
, &l
);
1484 printf ("tftp -> something go wrong !\n");
1488 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l
);
1490 char *bin
= (unsigned char *) pmalloc (sizeof (char) * (l
+1));
1495 int ret2
= tftp_client_read (ret
, bin
, l
);
1498 printf ("tftp -> tftp_client_read () error\n");
1503 memcpy (file_cache
, bin
, l
);
1505 unsigned entry
, code
, data
, data_off
, bss
;
1506 int err
= exec_elf (bin
, &entry
, &data
, &data_off
, &bss
);
1509 printf ("ERROR -> invalid ELF exec\n");
1515 /* create process */
1516 proc_t
*proc
= proc_create (currtty
, "netexec", entry
);
1520 /* check for & character as app parameter */
1522 while (d < arg_len) {
1523 if (arg[d] == '&') {
1524 if (proc_flag_set (proc, PROC_FLAG_DAEMON))
1525 printf ("%s: started as daemon\n", test);
1529 if (arg_len > 2 && arg[d-1] == ' ') {
1542 printf ("ERROR -> Invalid process: %s\n", test
);
1548 /* save process information to structure for later use */
1549 proc
->start
= (unsigned) bin
;
1552 proc
->data_off
= data_off
;
1554 proc
->end
= (unsigned) (bin
+ l
);
1558 /* well, set argument for out app */
1559 proc_arg_set (proc
, arg
+file_len
+1, arg_len
-file_len
-1);
1563 /* Is this process started as daemon ? */
1564 /* wait here, until pid != 0*/
1565 if (!(proc
->flags
& PROC_FLAG_DAEMON
))
1571 /* enable interrupts */
1574 /* unlock tty console - user can write in */
1575 tty_unlock (proc
->tty
);
1577 _curr_task
= proc
->tty
->task
; // this is pretty needed for correct return to our tty task
1579 if (!(proc
->flags
& PROC_FLAG_DAEMON
)) {
1580 if (!proc_done (proc
))
1581 while (1) // NOTE: heh, this is good stuff :P
1584 /* free image of app */
1589 /* switch to next task */
1597 unsigned command_netcp (char *command
, unsigned len
)
1599 strcpy (test
, argparse (command
));
1604 if (!strlen (test
)) {
1605 printf ("Syntax:\nnetcp <ip_of_tftp> <tftp_file> <output_file>\n");
1609 unsigned arg_len
= strlen (argparse (test
));
1610 char arg
[arg_len
+1];
1611 strcpy (arg
, argparse (test
));
1612 arg
[arg_len
] = '\0';
1614 unsigned test_len
= strlen (test
);
1615 test
[test_len
-arg_len
] = '\0';
1617 if (test
[test_len
-arg_len
-1] == ' ') {
1618 test
[test_len
-arg_len
-1] = '\0';
1622 char file
[arg_len
+1];
1623 unsigned file_len
= 0;
1624 memcpy (file
, arg
, arg_len
);
1625 while (file_len
< arg_len
) {
1626 if (file
[file_len
] == ' ') {
1627 file
[file_len
] = '\0';
1633 if (file
[arg_len
] != '\0')
1634 file
[arg_len
] = '\0';
1636 unsigned l
= file_len
;
1638 unsigned ret
= tftp_client_connect (test
, 69, file
, &l
);
1641 printf ("tftp -> something go wrong !\n");
1645 printf ("tftp -> file length: %ubytes\t\t[OK]\n", l
);
1646 printf ("DDDDDDDD: '%s' :: '%s' :: '%s'\n", test
, file
, arg
);
1647 char *bin
= (unsigned char *) malloc (sizeof (char) * (l
+1));
1652 int ret2
= tftp_client_read (ret
, bin
, l
);
1655 printf ("tftp -> tftp_client_read () error\n");
1665 char *output
= argparse (arg
);
1669 printf ("ERROR -> output file name is empty\n");
1673 int fd
= open (output
, O_WRONLY
| O_CREAT
);
1677 printf ("ERROR -> something go wrong with %s\n", output
);
1681 ret
= write (fd
, bin
, l
);
1685 printf ("ERROR -> File '%s' could'nt be writed\n", output
);
1688 file_cache
= (unsigned char *) 0x350000;
1693 void task_savemode ()
1696 /* disable cpu for cycle */
1702 unsigned command_savemode (char *command
, unsigned len
)
1704 task_t
*task
= (task_t
*) task_create ("savemode", (unsigned) &task_savemode
, 16);
1707 printf ("ERROR -> Save mode thread was'nt created\n");
1711 printf ("Save mode was succefully started\n");
1716 unsigned command_cpuinfo (char *command
, unsigned len
)
1718 printf ("Processor info:\n");
1720 cat ("/proc/cpuinfo");
1725 unsigned command_adm (char *command
, unsigned len
)
1727 printf ("Automatic Device Mounter - init ()\n");
1734 /*************************************************************\
1736 \*************************************************************/
1738 unsigned command_parser (char *command
, unsigned len
)
1740 /* find first non-space in command */
1742 for (i
= 0; i
< len
; i
++) {
1743 if (command
[i
] != ' ')
1748 /* try to find the command */
1749 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
1750 if (!cstrcmp (ctx
->name
, command
+i
)) {
1751 ctx
->handler (command
+i
, len
-i
);
1756 printf ("%s: command not found\n", command
);
1761 void commands (int i
)
1763 // currtty->shell_len has been set to zero already
1764 command_parser (currtty
->shell
, strlen(currtty
->shell
));
1767 unsigned command_register (char *name
, char *desc
, command_handler_t
*handler
, unsigned flags
)
1770 /* we dont want commands with same name */
1771 for (c
= command_list
.next
; c
!= &command_list
; c
= c
->next
)
1772 if (!strcmp(c
->name
, name
))
1777 // alloc and init context
1778 ctx
= (command_t
*) kmalloc (sizeof (command_t
));
1783 unsigned name_len
= strlen (name
);
1784 ctx
->name
= (char *) kmalloc (sizeof (char) * name_len
+1);
1789 memcpy (ctx
->name
, name
, name_len
);
1790 ctx
->name
[name_len
] = '\0';
1792 unsigned desc_len
= strlen (desc
);
1793 ctx
->desc
= (char *) kmalloc (sizeof (char) * desc_len
+1);
1798 memcpy (ctx
->desc
, desc
, desc_len
);
1799 ctx
->desc
[desc_len
] = '\0';
1801 ctx
->handler
= handler
;
1804 ctx
->next
= &command_list
;
1805 ctx
->prev
= command_list
.prev
;
1806 ctx
->prev
->next
= ctx
;
1807 ctx
->next
->prev
= ctx
;
1812 unsigned command_unregister (char *name
)
1816 for (ctx
= command_list
.next
; ctx
!= &command_list
; ctx
= ctx
->next
) {
1817 if (!strcmp(ctx
->name
, name
)) {
1818 ctx
->next
->prev
= ctx
->prev
;
1819 ctx
->prev
->next
= ctx
->next
;
1828 /*************************************************************\
1829 | INITIALIZATION OF COMMANDS |
1830 \*************************************************************/
1832 unsigned int init_commands ()
1834 command_list
.next
= &command_list
;
1835 command_list
.prev
= &command_list
;
1838 command_register ("help", "Displays list of available commands", &command_help
, 0);
1839 command_register ("hdd", "Detect HDD", &command_hdd
, 0);
1840 command_register ("reboot", "Reboot computer", &command_reboot
, 0);
1841 command_register ("halt", "Shutdown computer", &command_halt
, 0);
1842 command_register ("tasks", "Print all tasks", &command_tasks
, 0);
1843 command_register ("ps", "Print all process", &command_ps
, 0);
1844 command_register ("uptime", "Print uptime in seconds", &command_uptime
, 0);
1845 command_register ("version", "Displays a version of system", &command_version
, 0);
1846 command_register ("debug", "Change to developer mode", &command_debug
, 0);
1847 command_register ("mount", "Mount device to selected directory", &command_mount
, 0);
1848 command_register ("umount", "Unmount mounted directory", &command_umount
, 0);
1849 command_register ("env", "Displays all env variables", &command_env
, 0);
1850 command_register ("cd", "Change directory", &command_cd
, 0);
1851 command_register ("ls", " Displays files in current directory", &command_ls
, 0);
1852 command_register ("cat", "Displays text in selected file", &command_cat
, 0);
1853 command_register ("rm", "Remove a file", &command_rm
, 0);
1854 command_register ("mkdir", "Create a directory", &command_mkdir
, 0);
1855 command_register ("touch", "Create a file", &command_touch
, 0);
1856 command_register ("exec", "Execute a selected program", &command_exec
, 0);
1857 command_register ("lsdev", "Displays found devices", &command_lsdev
, 0);
1858 command_register ("login", "Login as another user", &command_login
, 0);
1859 command_register ("fdisk", "Partition table manipulator", &command_fdisk
, 0);
1860 command_register ("hdcat", "Read selected block of data from drive", &command_hdcat
, 0);
1861 command_register ("free", "Display amount of free and used memory", &command_free
, 0);
1862 command_register ("date", "Show current date and time", &command_date
, 0);
1863 //command_register ("xmastime", "play noel on pc-speaker", &command_spk, 0);
1864 command_register ("test", "Some test", &command_test
, 0);
1865 //command_register ("testb", "Some test", &command_test2, 0);
1866 //command_register ("testc", "Some test", &command_test3, 0);
1867 //command_register ("testd", "Some test", &command_test4, 0);
1868 //command_register ("vesa", "Some test", &command_vesa, 0);
1869 command_register ("kill", "Send a signal to process", &command_kill
, 0);
1870 command_register ("modprobe", "program to add modules from the kernel", &command_modprobe
, 0);
1871 command_register ("lsmod", "program to show the status of modules", &command_lsmod
, 0);
1872 #ifdef CONFIG_DRV_PCI
1873 command_register ("lspci", "list all pci devices", &command_lspci
, 0);
1875 //command_register ("mouse", "ps2 mouse test", &command_mouse, 0);
1876 command_register ("iflist", "Show network interface", &command_iflist
, 0);
1877 command_register ("ifconfig", "Configure network interface", &command_ifconfig
, 0);
1878 command_register ("ifroute", "Configure gateway address", &command_ifroute
, 0);
1879 command_register ("dnsconfig", "Configure domain name server address", &command_dnsconfig
, 0);
1880 #ifdef CONFIG_PROTO_TUN6
1881 command_register ("tunconfig", "Configure IPv6 tunnel server address", &command_tunconfig
, 0);
1883 command_register ("kbdmap", "Change keyboard layout", &command_kbdmap
, 0);
1884 #ifdef CONFIG_DRV_ZEXFS
1885 command_register ("mkzexfs", "Create zexfs filesystem on hdd", &command_mkzexfs
, 0);
1887 #ifdef CONFIG_DRV_EXT2
1888 command_register ("mkext2", "Create ext2 filesystem on hdd", &command_mkext2
, 0);
1890 #ifdef CONFIG_PROTO_IPV4
1891 command_register ("ping", "Send ICMP echo request", &command_ping
, 0);
1893 #ifdef CONFIG_PROTO_IPV6
1894 command_register ("ping6", "Send ICMPv6 echo request", &command_ping6
, 0);
1896 command_register ("netexec", "Execute file from network", &command_netexec
, 0);
1897 command_register ("netcp", "Copy file from network to filesystem", &command_netcp
, 0);
1898 command_register ("savemode", "Make less cpu load", &command_savemode
, 0);
1899 command_register ("cpuinfo", "Show CPU info", &command_cpuinfo
, 0);
1901 command_register ("adm", "Automatic Device Mounter", &command_adm
, 0);