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>
29 unsigned char test
[10];
31 typedef void (*void_fn_void_t
)(void);
33 extern task_t task_list
;
35 char *argparse (char *cmd
)
37 unsigned cmd_len
= strlen (cmd
);
51 static void wait (void)
55 for(wait
= WAIT
; wait
!= 0; wait
--)
73 if (!cstrcmp ("help", currtty
->shell
))
75 //printf("fda [sector] Read sector from floppy drive A\n");
76 //printf("fda Read all sectors on floppy drive A\n");
77 printf ("hdd Detect HDD\n");
78 printf ("help Print help\n");
79 printf ("reboot Reboot computer\n");
80 printf ("tasks Print all tasks\n");
81 printf ("ps Print all process\n");
82 printf ("uptime Print uptime in seconds\n");
83 printf ("version Displays a version of system\n");
84 printf ("debug Change to developer mode\n");
85 printf ("mount Mount device to selected directory\n");
86 printf ("env Displays all env variables\n");
87 printf ("cd Change directory\n");
88 printf ("ls Displays files in current directory\n");
89 printf ("cat Displays text in selected file\n");
90 printf ("mkdir Create a directory\n");
91 printf ("exec Execute a selected program\n");
92 printf ("lsdev Displays found devices\n");
93 printf ("login Login as another user\n");
94 printf ("serialw Write data on rs232\n");
95 printf ("serialr Read data from rs232\n");
96 printf ("fdisk Partition table manipulator\n");
97 printf ("hdcat Read selected block of data from drive\n");
102 if (!cstrcmp ("tasks", currtty
->shell
))
104 puts ("name\tpriority\n");
107 for (task
= task_list
.next
; task
!= &task_list
; task
= task
->next
)
108 printf ("%s\t%u\n", task
->name
, task
->priority
);
113 if (!cstrcmp ("reboot", currtty
->shell
))
115 outportb (0x64, 0xFE);
120 if (!cstrcmp ("uptime", currtty
->shell
))
127 if (!cstrcmp ("ls", currtty
->shell
))
129 strcpy (test
, argparse (currtty
->shell
));
136 if (!cstrcmp ("cd", currtty
->shell
))
138 strcpy (test
, argparse (currtty
->shell
));
145 if (!cstrcmp ("cat", currtty
->shell
))
147 strcpy (test
, argparse (currtty
->shell
));
154 if (!cstrcmp ("mkdir", currtty
->shell
))
156 strcpy (test
, argparse (currtty
->shell
));
163 if (!cstrcmp ("hdd", currtty
->shell
))
172 outportb (0x70, 0x12);
177 printf ("/dev/hda not installed\n");
181 outportb (0x70, 0x1b);
183 outportb (0x70, 0x1c);
185 outportb (0x70, 0x1d);
187 outportb (0x70, 0x23);
189 printf ("/dev/hda installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
194 printf ("/dev/hdb not installed\n");
198 outportb (0x70, 0x24);
200 outportb (0x70, 0x25);
202 outportb (0x70, 0x26);
204 outportb (0x70, 0x2c);
206 printf ("/dev/hdb installed - CHS=%d-%d:%d:%d\n", c
, c2
, h
, s
);
212 if (!cstrcmp ("debug", currtty
->shell
))
216 DPRINT ("developer mode was enabled.");
221 DPRINT ("developer mode was disabled.");
227 /* if (!cstrcmp ("thread", currtty->shell))
231 proc_t *proc = proc_create (currtty, "thread", thread);
236 if (!strncmp ("./", currtty
->shell
, 2) || !cstrcmp ("exec", currtty
->shell
))
238 if (!strncmp ("./", currtty
->shell
, 2))
239 strcpy (test
, currtty
->shell
+2);
241 strcpy (test
, argparse (currtty
->shell
));
247 int err
= exec_elf (file_cache
, &entry
);
250 printf ("ERROR -> invalid ELF exec\n");
256 proc_t
*proc
= proc_create (currtty
, test
, entry
);
260 if (!proc_find (proc->task))
265 ((void_fn_void_t
) entry
)();
274 if (!cstrcmp ("ps", currtty
->shell
))
281 if (!cstrcmp ("mount", currtty
->shell
))
284 strcpy (test
, argparse (currtty
->shell
));
288 unsigned l
= strlen (test
);
296 memcpy (devname
, test
, x
);
298 strcpy (mountpoint
, argparse (test
));
299 unsigned y
= strlen (mountpoint
);
301 if (mountpoint
[y
-1] != '/') {
303 mountpoint
[y
+1] = '\0';
307 partition_t
*p
= partition_find (devname
);
310 mount (p
, "", mountpoint
);
312 printf ("ERROR -> partition %s does not exists\n", devname
);
319 if (!cstrcmp ("env", currtty
->shell
))
326 if (!cstrcmp ("lsdev", currtty
->shell
))
333 if (!cstrcmp ("login", currtty
->shell
))
335 currtty
->user
= NULL
;
336 currtty
->logged
= false;
344 if (!cstrcmp ("version", currtty
->shell
))
351 if (!cstrcmp ("serialr", currtty
->shell
))
353 dev_t
*dev
= dev_find ("/dev/com0");
358 dev
->handler (DEV_ACT_READ
, data
, 10);
360 printf ("serialr: %s\n", data
);
366 if (!cstrcmp ("serialw", currtty
->shell
))
368 dev_t
*dev
= dev_find ("/dev/com0");
371 unsigned len
= strlen (argparse (currtty
->shell
));
373 memcpy (data
, argparse (currtty
->shell
), len
);
376 dev
->handler (DEV_ACT_WRITE
, data
, len
);
378 printf ("serialw: %s\n", data
);
384 if (!cstrcmp ("fdisk", currtty
->shell
))
390 if (!cstrcmp ("hdcat", currtty
->shell
))
392 partition_t
*p
= partition_find (argparse (currtty
->shell
));
395 dev_t
*dev
= dev_findbypartition (p
);
397 unsigned char block
[512];
399 while (!key_pressed (1)) {
400 if (key_pressed (72) == 1) {
401 printf ("##block: %d\n", d
);
402 dev
->handler (DEV_ACT_READ
, p
, block
, "", d
);
404 for (c
= 0; c
< 512; c
++)
405 putch ((unsigned)block
[c
]);
412 printf ("Please specify partition, example: hdcat /dev/hda0\n");
417 /* error -> command not found */
418 printf ("%s: command not found\n", currtty
->shell
);