OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [cmds/] [atabug.c] - Blame information for rev 831

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
/*
2
    atabug.c -- ATA debugging
3
    Copyright (C) 2002 Richard Herveille, rherveille@opencores.org
4
 
5
    This file is part of OpenRISC 1000 Reference Platform Monitor (ORPmon)
6
 
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 2 of the License, or
10
    (at your option) any later version
11
 
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.
16
 
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
*/
21
 
22
#include "support.h"
23
#include "common.h"
24
#include "atabug.h"
25
#include "ata.h"
26
 
27
#include <ctype.h>
28
 
29
static int ata_num_commands;
30
static command_struct ata_command[MAX_ATA_COMMANDS];
31
 
32
/* inode struct for ata */
33
static struct inode _inode;
34
static struct inode *inode = &_inode;
35
 
36
/* file struct for ata */
37
static struct file _filp;
38
static struct file *filp = &_filp;
39
 
40
/* buffer for ata-data */
41
static unsigned char buf[512];
42
 
43
/**********************************************************************/
44
/*                                                                    */
45
/*      A T A B U G                                                   */
46
/*                                                                    */
47
/**********************************************************************/
48
/*
49
        A T A _ I N I T
50
 
51
        initializes the ATA core, and registers it with ORPmon
52
*/
53 406 julius
void module_ata_init(void)
54 2 marcus.erl
{
55 406 julius
        ata_num_commands = 0;
56 2 marcus.erl
 
57 406 julius
        register_command("atabug", "",
58
                         "ATA debugger. Type 'atabug help' for help", atabug);
59 2 marcus.erl
 
60 406 julius
        register_ata_command("help", "", "Display this help message",
61
                             atabug_help);
62
        register_ata_command("exit", "", "Exit atabug and return to ORPmon",
63
                             atabug_exit);
64
        register_ata_command("open", "<device> [<mode>]",
65
                             "Opens the requested device. Device=<0|1>, Mode=<r>eadonly|read<w>rite.",
66
                             ata_open_cmd);
67
        register_ata_command("close", "", "Closes the device.", ata_close_cmd);
68
        register_ata_command("reset", "<mode>", "Reset ata device(s).",
69
                             ata_reset_cmd);
70
        register_ata_command("enable", "",
71
                             "Enables ATA host controller, clears all resets",
72
                             ata_enable_cmd);
73
        register_ata_command("dump_dev_regs", "",
74
                             "Dump the (readable) ata device registers.",
75
                             ata_dump_device_regs_cmd);
76
        register_ata_command("dump_host_regs", "",
77
                             "Dump the ata host registers.",
78
                             ata_dump_host_regs_cmd);
79
        register_ata_command("exec_cmd", "<cmd>",
80
                             "Execute ata command <cmd> (hex)",
81
                             ata_exec_cmd_cmd);
82
        register_ata_command("identify_device", "",
83
                             "Dumps device's IDENTIFY DEVICE block.",
84
                             ata_identify_device_cmd);
85
        register_ata_command("program_timing", "<PIO mode>",
86
                             "Programs the device to the selected PIO mode.",
87
                             ata_set_piomode_cmd);
88
        register_ata_command("read_sectors", "<startsector> [<sectorcount>]",
89
                             "Reads sector", ata_read_sectors_cmd);
90
        register_ata_command("read_mbr", "<partition>",
91
                             "Reads the Master Boot Record.", ata_read_mbr_cmd);
92
        register_ata_command("read_dosboot", "<sector>",
93
                             "Reads the device's bootsector (FAT).",
94
                             ata_read_dosboot_cmd);
95
        register_ata_command("select_device", "<device_no>",
96
                             "Select ata device. device_no=<0|1>",
97
                             ata_select_device_cmd);
98 2 marcus.erl
}
99
 
100
int atabug(int argc, char **argv)
101
{
102
 
103 406 julius
        /* take care of commandline options                                 */
104
        if (argc == 0) {
105
                /* start atabug                                                   */
106
                while (!ata_mon_command()) ;
107
        } else
108
                return execute_ata_command(argv[0], argc - 1, &argv[1]);
109 2 marcus.erl
 
110 406 julius
        return 0;
111 2 marcus.erl
}
112
 
113
int atabug_exit(int argc, char **argv)
114
{
115 406 julius
        ata_close_cmd(argc, argv);
116
        return -2;
117 2 marcus.erl
}
118
 
119
/*
120
 The next code is graceously taken from the "common.c" file
121
 and slightly modified to suit the big list of ATA commands
122
 
123
 Better would be if we could access the routines in 'common.c'
124
 directly, using our own set of commands.
125
*/
126
 
127
/* Process command-line, generate arguments */
128
int ata_mon_command(void)
129
{
130 406 julius
        char c = '\0';
131
        char str[1000];
132
        char *pstr = str;
133
        char *command_str;
134
        char *argv[20];
135
        int argc = 0;
136 2 marcus.erl
 
137 406 julius
        /* Show prompt */
138
        printf("\natabug> ");
139 2 marcus.erl
 
140 406 julius
        /* Get characters from UART */
141
        c = getc();
142
        while (c != '\r' && c != '\f' && c != '\n') {
143
                if (c == '\b')
144
                        pstr--;
145
                else
146
                        *pstr++ = c;
147
                putc(c);
148
                c = getc();
149
        }
150
        *pstr = '\0';
151
        printf("\n");
152 2 marcus.erl
 
153 406 julius
        /* Skip leading blanks */
154
        pstr = str;
155
        while (isspace(*pstr))
156
                pstr++;
157 2 marcus.erl
 
158 406 julius
        /* Get command from the string */
159
        command_str = pstr;
160 2 marcus.erl
 
161 406 julius
        while (1) {
162
                /* Go to next argument */
163
                while (isgraph(*pstr))
164
                        pstr++;
165
                if (*pstr) {
166
                        *pstr++ = '\0';
167
                        while (isspace(*pstr))
168
                                pstr++;
169
                        argv[argc++] = pstr;
170
                } else
171
                        break;
172
        }
173 2 marcus.erl
 
174 406 julius
        return execute_ata_command(command_str, argc, argv);
175 2 marcus.erl
}
176
 
177
int execute_ata_command(char *command_str, int argc, char **argv)
178
{
179 406 julius
        int i, found = 0;
180 2 marcus.erl
 
181 406 julius
        for (i = 0; i < ata_num_commands; i++)
182
                if (!strcmp(command_str, ata_command[i].name)) {
183
                        switch (ata_command[i].func(argc, argv)) {
184
                        case -1:
185
                                printf
186
                                    ("Missing/wrong parameters, usage: %s %s\n",
187
                                     ata_command[i].name,
188
                                     ata_command[i].params);
189
                                break;
190 2 marcus.erl
 
191 406 julius
                        case -2:
192
                                return -1;
193
                        }
194 2 marcus.erl
 
195 406 julius
                        found++;
196
                        break;
197
                }
198 2 marcus.erl
 
199 406 julius
        if (!found)
200
                printf("Unknown command. Type 'ata help' for help.\n");
201
 
202
        return 0;
203 2 marcus.erl
}
204
 
205 406 julius
void register_ata_command(const char *name, const char *params,
206
                          const char *help, int (*func) (int argc,
207
                                                         char *argv[]))
208 2 marcus.erl
{
209 406 julius
        if (ata_num_commands < MAX_ATA_COMMANDS) {
210
                ata_command[ata_num_commands].name = name;
211
                ata_command[ata_num_commands].params = params;
212
                ata_command[ata_num_commands].help = help;
213
                ata_command[ata_num_commands].func = func;
214
                ata_num_commands++;
215
        } else
216
                printf("ata-command '%s' ignored; MAX_COMMANDS limit reached\n",
217
                       name);
218 2 marcus.erl
}
219
 
220
int atabug_help(int argc, char **argv)
221
{
222 406 julius
        int i;
223 2 marcus.erl
 
224 406 julius
        for (i = 0; i < ata_num_commands; i++)
225
                printf("%-15s %-17s -%s\n", ata_command[i].name,
226
                       ata_command[i].params, ata_command[i].help);
227 2 marcus.erl
 
228 406 julius
        return 0;
229 2 marcus.erl
}
230
 
231
/**********************************************************************/
232
/*                                                                    */
233
/*      A T A B U G   C O M M A N D S E T                             */
234
/*                                                                    */
235
/**********************************************************************/
236
 
237
/*
238
        A T A _ C L O S E
239
 
240
        closes the ata_device
241
*/
242
int ata_close_cmd(int argc, char **argv)
243
{
244 406 julius
        inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0');
245 2 marcus.erl
 
246 406 julius
        return ata_release(inode, filp);
247 2 marcus.erl
}
248
 
249
/*
250
        A T A _ D U M P _ D E V I C E _ R E G S
251
 
252
        Dumps the (readable) ata-registers.
253
        Exception: status register is not read, this could mask an interrupt
254
*/
255
int ata_dump_device_regs_cmd(int argc, char **argv)
256
{
257 406 julius
        if (argc)
258
                printf("\nWARNING: Ignoring invalid argument(s)\n\n");
259 2 marcus.erl
 
260 406 julius
        printf("Alternate status register : 0x%02lX\n",
261
               REG32(ATA_BASE_ADDR + ATA_ASR));
262
        printf("Cylinder high register    : 0x%02lX\n",
263
               REG32(ATA_BASE_ADDR + ATA_CHR));
264
        printf("Cylinder low register     : 0x%02lX\n",
265
               REG32(ATA_BASE_ADDR + ATA_CLR));
266
        printf("Device head register      : 0x%02lX\n",
267
               REG32(ATA_BASE_ADDR + ATA_DHR));
268
        printf("Error register            : 0x%02lX\n",
269
               REG32(ATA_BASE_ADDR + ATA_ERR));
270
        printf("Sector count register     : 0x%02lX\n",
271
               REG32(ATA_BASE_ADDR + ATA_SCR));
272
        printf("Sector number register    : 0x%02lX\n",
273
               REG32(ATA_BASE_ADDR + ATA_SNR));
274
        printf("Status register (see alternate status register)\n");
275 2 marcus.erl
 
276 406 julius
        return 0;
277 2 marcus.erl
}
278
 
279
/*
280
        A T A _ D U M P _ H O S T _ R E G S
281
 
282
        Dumps the ata-host registers
283
*/
284
int ata_dump_host_regs_cmd(int argc, char **argv)
285
{
286 406 julius
        if (argc)
287
                printf("\nWARNING: Ignoring invalid argument(s)\n\n");
288 2 marcus.erl
 
289 406 julius
        printf("Control register                   CTRL : 0x%08lX\n",
290
               REG32(ATA_BASE_ADDR + ATA_CTRL));
291
        printf("Status register                    STAT : 0x%08lX\n",
292
               REG32(ATA_BASE_ADDR + ATA_STAT));
293
        printf("Pio command timing register        PCTR : 0x%08lX\n",
294
               REG32(ATA_BASE_ADDR + ATA_PCTR));
295
        printf("Pio fast timing register (device0) PFTR0: 0x%08lX\n",
296
               REG32(ATA_BASE_ADDR + ATA_PFTR0));
297
        printf("Pio fast timing register (device1) PFTR1: 0x%08lX\n",
298
               REG32(ATA_BASE_ADDR + ATA_PFTR1));
299
        printf("Dma timing register (device0)      DTR0 : 0x%08lX\n",
300
               REG32(ATA_BASE_ADDR + ATA_DTR0));
301
        printf("Dma timing register (device1)      DTR1 : 0x%08lX\n",
302
               REG32(ATA_BASE_ADDR + ATA_DTR1));
303 2 marcus.erl
 
304 406 julius
        return 0;
305 2 marcus.erl
}
306
 
307
/*
308
        A T A _ E N A B L E
309
 
310
        clears reset bits
311
*/
312
int ata_enable_cmd(int argc, char **argv)
313
{
314 406 julius
        if (argc != 0)
315
                printf("Ignoring invalid parameters\n");
316 2 marcus.erl
 
317 406 julius
        inode->i_rdev = (ATA_BASE_ADDR >> 16);
318 2 marcus.erl
 
319 406 julius
        // clear hardware reset bit
320
        if (ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_HW_RST))
321
                return -1;
322 2 marcus.erl
 
323 406 julius
        // clear software reset bit
324
        if (ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_SW_RST))
325
                return -1;
326 2 marcus.erl
 
327 406 julius
        // enable ATA Hostcontroller core
328
        if (ata_ioctl(inode, filp, ATA_IOCTL_ENABLE_HOST, 0))
329
                return -1;
330 2 marcus.erl
 
331 406 julius
        printf("ATA host controller enabled\n");
332 2 marcus.erl
 
333 406 julius
        return 0;
334 2 marcus.erl
}
335
 
336
/*
337
        A T A _ E X E C _ C M D
338
 
339
        Executes the command; writes the command number in the command register
340
*/
341
int ata_exec_cmd_cmd(int argc, char **argv)
342
{
343 406 julius
        if (argc != 1)
344
                return -1;
345 2 marcus.erl
 
346 406 julius
        inode->i_rdev = (ATA_BASE_ADDR >> 16);
347
 
348
        ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, strtoul(*argv, argv, 16));
349
        return 0;
350 2 marcus.erl
}
351
 
352
/*
353
        A T A _ I D E N T I F Y _ D E V I C E
354
 
355
        Reads the identify_device block and dumps it to the screen
356
*/
357
int ata_identify_device_cmd(int argc, char **argv)
358
{
359 406 julius
        unsigned char checksum;
360 2 marcus.erl
 
361 406 julius
        if (argc != 0)
362
                printf("Ignoring invalid parameters\n");
363 2 marcus.erl
 
364 406 julius
        /* check for busy flag                                            */
365
        if (ata_dev_busy(ATA_BASE_ADDR))
366
                printf("Selected ata device busy, ignoring command\n");
367
        else {
368
                /* execute identify device                                    */
369
                ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE);
370 2 marcus.erl
 
371 406 julius
                /* read block from ata-device                                 */
372
                buf[0] = 0;
373
                buf[1] = 1;
374
                ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long)buf);
375 2 marcus.erl
 
376 406 julius
                /* dump data to the screen                                    */
377
                checksum = atabug_dump_data(buf, 512);
378 2 marcus.erl
 
379 406 julius
                if (buf[512] == 0xa5)
380
                        printf("Checksum = 0x%02X (%s)\n", checksum,
381
                               checksum ? "error" : "OK");
382
                else
383
                        printf("No checksum supported\n");
384
        }
385
        return 0;
386 2 marcus.erl
}
387
 
388
/*
389
        A T A _ O P E N
390
 
391
        opens the ata_device
392
*/
393
int ata_open_cmd(int argc, char **argv)
394
{
395 406 julius
        inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0');
396 2 marcus.erl
 
397 406 julius
        filp->f_mode = FMODE_READ;
398 2 marcus.erl
 
399 406 julius
        if (*argv[1] == 'w')
400
                filp->f_mode |= FMODE_WRITE;
401 2 marcus.erl
 
402 406 julius
        switch (ata_open(inode, filp)) {
403
        case EOPENIDEV:
404
                printf("Error: Invalid device (invalid MINOR %02X)\n",
405
                       MINOR(inode->i_rdev));
406
                break;
407 2 marcus.erl
 
408 406 julius
        case EOPENNODEV:
409
                printf("Error: Requested device not found\n");
410
                break;
411 2 marcus.erl
 
412 406 julius
        case EOPENIHOST:
413
                printf("Error: Invalid host (invalid MAJOR %02X)\n",
414
                       MAJOR(inode->i_rdev));
415
        default:
416
                break;
417
        }
418 2 marcus.erl
 
419 406 julius
        return 0;
420 2 marcus.erl
}
421
 
422
/*
423
        A T A _ S E T _ P I O M O D E
424
 
425
        Sets the device to the requested PIO mode
426
*/
427
int ata_set_piomode_cmd(int argc, char **argv)
428
{
429 406 julius
        return 0;
430 2 marcus.erl
}
431
 
432
/*
433
        A T A _ R E A D _ S E C T O R S
434
 
435
        Reads 1 sector from the device and dumps it to the screen
436
*/
437
int ata_read_sectors_cmd(int argc, char **argv)
438
{
439 406 julius
        struct request request;
440
        unsigned long sector_cnt, sector;
441 2 marcus.erl
 
442 406 julius
        sector = strtoul(argv[0], argv, 10);
443 2 marcus.erl
 
444 406 julius
        switch (argc) {
445
        case 2:
446
                sector_cnt = strtoul(argv[1], argv, 10);
447
                break;
448 2 marcus.erl
 
449 406 julius
        case 1:
450
                sector_cnt = 1;
451
                break;
452 2 marcus.erl
 
453 406 julius
        default:
454
                return -1;
455
        }
456 2 marcus.erl
 
457 406 julius
        if (!sector_cnt) {
458
                printf("Invalid number of sectors.\n");
459
                return 0;
460
        }
461 2 marcus.erl
 
462 406 julius
        /* check for busy flag                                            */
463
        if (ata_dev_busy(ATA_BASE_ADDR))
464
                printf("Selected ata device busy, ignoring command\n");
465
        else {
466
                /* fill the request structure                                 */
467
                request.cmd = READ;
468
                request.sector = sector;
469
                request.nr_sectors = sector_cnt;
470
                request.buffer = buf;
471 2 marcus.erl
 
472 406 julius
                if (ata_request(inode, filp, &request)) {
473
                        printf
474
                            ("Error while executing READ_SECTOR(S) command\n");
475
                        printf
476
                            ("Status register = 0x%02lX, error register = 0x%02lX\n",
477
                             ata_astatus(ATA_BASE_ADDR),
478
                             ata_error(ATA_BASE_ADDR));
479
                } else {
480
                        /* dump data to the screen                                    */
481
                        atabug_dump_data(buf, 512 * sector_cnt);
482
                }
483 2 marcus.erl
        }
484 406 julius
        return 0;
485 2 marcus.erl
}
486
 
487
/*
488
        A T A _ R E A D _ M B R
489
 
490
        Reads master boot record from the device and dumps it's contents to the screen
491
*/
492
int ata_read_mbr_cmd(int argc, char **argv)
493
{
494 406 julius
        struct request request;
495
        unsigned int partition;
496 2 marcus.erl
 
497 406 julius
        // get requested partition number
498
        partition = 0;
499
        if (argc)
500
                partition = strtoul(*argv, argv, 10);
501 2 marcus.erl
 
502 406 julius
        /* check for busy flag                                            */
503
        if (ata_dev_busy(ATA_BASE_ADDR))
504
                printf("Selected ata device busy, ignoring command\n");
505
        else {
506
                /* fill the request structure                                 */
507
                request.cmd = READ;
508
                request.sector = 0;
509
                request.nr_sectors = 1;
510
                request.buffer = buf;
511 2 marcus.erl
 
512 406 julius
                if (ata_request(inode, filp, &request)) {
513
                        printf("Error while reading master boot sector.\n");
514
                        printf
515
                            ("Status register = 0x%02lX, error register = 0x%02lX\n",
516
                             ata_astatus(ATA_BASE_ADDR),
517
                             ata_error(ATA_BASE_ADDR));
518
                } else {
519
                        printf("Skipping bootloader (446bytes)\n");
520
                        printf("Partition %1d:\n", partition);
521 2 marcus.erl
 
522 406 julius
                        // abuse partitionnumber to get offset in MBR record
523
                        partition *= 16;
524
                        partition += 446;
525 2 marcus.erl
 
526 406 julius
                        printf("Bootindicator: 0x%2X (%s)\n", buf[partition],
527
                               buf[partition] ? "bootable" : "non-bootable");
528
                        printf
529
                            ("Partition start (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n",
530
                             buf[partition + 1],
531
                             (buf[partition + 2] & 0xc0) << 2 | buf[partition +
532
                                                                    3],
533
                             buf[partition + 2] & 0x3f);
534
                        printf("Systemindicator: 0x%02X (", buf[partition + 4]);
535 2 marcus.erl
 
536 406 julius
                        switch (buf[partition + 4]) {
537
                        case 0:
538
                                printf("Non DOS");
539
                                break;
540
                        case 1:
541
                                printf("DOS FAT12");
542
                                break;
543
                        case 4:
544
                                printf("DOS FAT16");
545
                                break;
546
                        case 5:
547
                                printf("DOS extended");
548
                                break;
549
                        case 6:
550
                                printf("DOS >32MByte");
551
                                break;
552 2 marcus.erl
 
553 406 julius
                        default:
554
                                printf("unkown");
555
                        };
556
                        printf(")\n");
557
                        printf
558
                            ("Partition end (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n",
559
                             buf[partition + 5],
560
                             (buf[partition + 6] & 0xc0) << 2 | buf[partition +
561
                                                                    7],
562
                             buf[partition + 6] & 0x3f);
563
                        printf("Physical Startsector: 0x%08X\n",
564
                               buf[partition + 11] << 24 | buf[partition +
565
                                                               10] << 16 |
566
                               buf[partition + 9] << 8 | buf[partition + 8]);
567
                        printf("Sector count: 0x%08X\n",
568
                               buf[partition + 15] << 24 | buf[partition +
569
                                                               14] << 16 |
570
                               buf[partition + 13] << 8 | buf[partition + 12]);
571
                }
572
        }
573
        return 0;
574 2 marcus.erl
}
575
 
576
/*
577
        A T A _ R E A D _ D O S B O O T
578
 
579
        Reads boot sector from the device and dumps it's contents to the screen
580
*/
581
int ata_read_dosboot_cmd(int argc, char **argv)
582
{
583 406 julius
        struct request request;
584
        unsigned int sector;
585
        char txt[8];
586 2 marcus.erl
 
587 406 julius
        sector = 0;
588
        if (argc)
589
                sector = strtoul(*argv, argv, 0);
590 2 marcus.erl
 
591 406 julius
        /* check for busy flag                                            */
592
        if (ata_dev_busy(ATA_BASE_ADDR))
593
                printf("Selected ata device busy, ignoring command\n");
594
        else {
595
                /* fill the request structure                                 */
596
                request.cmd = READ;
597
                request.sector = sector;
598
                request.nr_sectors = 1;
599
                request.buffer = buf;
600 2 marcus.erl
 
601 406 julius
                if (ata_request(inode, filp, &request)) {
602
                        printf("Error whilereading boot sector 0x%02X.\n",
603
                               sector);
604
                        printf
605
                            ("Status register = 0x%02lX, error register = 0x%02lX\n",
606
                             ata_astatus(ATA_BASE_ADDR),
607
                             ata_error(ATA_BASE_ADDR));
608
                } else {
609
                        printf("Reading boot sector 0x%02X\n", sector);
610
                        printf("ID number: 0x%2X%2X%2X\n", buf[0], buf[1],
611
                               buf[2]);
612 2 marcus.erl
 
613 406 julius
                        printf("OEM-name and number: ");
614
                        memcpy(txt, &buf[3], 8);
615
                        txt[8] = '\0';
616
                        printf("%s\n", txt);
617 2 marcus.erl
 
618 406 julius
                        printf("Bytes per sector: %5d\n",
619
                               (buf[12] << 8) | buf[11]);
620
                        printf("Sectors per cluster: %3d\n", buf[13]);
621
                        printf("Reserved IM-sectors: %5d\n",
622
                               (buf[15] << 8) | buf[14]);
623
                        printf("Number of FATs: %3d\n", buf[16]);
624
                        printf("Number of entries in the root-directory: %5d\n",
625
                               (buf[18] << 8) | buf[17]);
626
                        printf("Number of logical sectors: %5d\n",
627
                               (buf[20] << 8) | buf[19]);
628
                        printf("Medium descriptor byte: %02X\n", buf[21]);
629
                        printf("Sectors per FAT: %5d\n",
630
                               (buf[23] << 8) | buf[22]);
631
                        printf("Sectors per track: %5d\n",
632
                               (buf[25] << 8) | buf[24]);
633
                        printf("Number of heads: %5d\n",
634
                               (buf[27] << 8) | buf[26]);
635
                        printf("Number of hidden sectors: %5d\n",
636
                               (buf[29] << 8) | buf[28]);
637
                }
638
        }
639
        return 0;
640 2 marcus.erl
}
641
 
642
/*
643
        A T A _ R E S E T
644
 
645
        resets the ATA device, using the select method
646
*/
647
int ata_reset_cmd(int argc, char **argv)
648
{
649 406 julius
        if (argc != 1)
650
                return -1;
651 2 marcus.erl
 
652 406 julius
        return ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, SET | (**argv - '0'));
653 2 marcus.erl
}
654
 
655
/*
656
        A T A _ S E L E C T _ D E V I C E
657
 
658
        selects the ATA device; sets the DEV bit in the device/head register
659
*/
660
int ata_select_device_cmd(int argc, char **argv)
661
{
662 406 julius
        if (argc != 1)
663
                return -1;
664 2 marcus.erl
 
665 406 julius
        inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0');
666 2 marcus.erl
 
667 406 julius
        ata_ioctl(inode, filp, ATA_IOCTL_SELECT_DEVICE, **argv - '0');
668 2 marcus.erl
 
669 406 julius
        printf("Ata device %1d selected.\n",
670
               REG32(ATA_BASE_ADDR + ATA_DHR) & ATA_DHR_DEV ? 1 : 0);
671
        return 0;
672 2 marcus.erl
}
673
 
674
/**********************************************************************/
675
/*                                                                    */
676
/*      A T A B U G   T O O L S                                       */
677
/*                                                                    */
678
/**********************************************************************/
679
 
680
/*
681
 D U M P _ D A T A
682
 
683
 dumps byte-data in a buffer of type short to the screen
684
 and returns the byte-checksum
685
 
686
 *buffer = pointer to (short)buffer
687
 cnt     = number of bytes to display
688
*/
689
unsigned char atabug_dump_data(unsigned char *buffer, int cnt)
690
{
691 406 julius
        int i, n, bytes_per_line = 16;
692
        unsigned char c, checksum;
693
        unsigned char *buf_ptr;
694 2 marcus.erl
 
695 406 julius
        /* prepare stored data for display & calculate checksum           */
696
        checksum = 0;
697
        buf_ptr = buffer;
698 2 marcus.erl
 
699 406 julius
        /* display data                                                   */
700
        for (i = 0; i < cnt; i += bytes_per_line) {
701
                printf("%3X ", i);
702 2 marcus.erl
 
703 406 julius
                /* print hexadecimal notation                                   */
704
                for (n = 0; n < bytes_per_line; n++)
705
                        printf("%02X ", *buf_ptr++);
706 2 marcus.erl
 
707 406 julius
                buf_ptr -= bytes_per_line;      /* back to the start (of this block) */
708 2 marcus.erl
 
709 406 julius
                /* print ASCII notation & calculate checksum                    */
710
                for (n = 0; n < bytes_per_line; n++) {
711
                        c = *buf_ptr++;
712
                        printf("%c", isprint(c) ? c : '.');
713
                        checksum += c;
714
                }
715
                printf("\n");
716
        }
717 2 marcus.erl
 
718 406 julius
        return checksum;
719 2 marcus.erl
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.