summaryrefslogtreecommitdiff
path: root/firmware/test/fat/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/fat/debug.c')
-rw-r--r--firmware/test/fat/debug.c175
1 files changed, 175 insertions, 0 deletions
diff --git a/firmware/test/fat/debug.c b/firmware/test/fat/debug.c
new file mode 100644
index 0000000000..046a67e06c
--- /dev/null
+++ b/firmware/test/fat/debug.c
@@ -0,0 +1,175 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "fat.h"
5#include "ata.h"
6#include "debug.h"
7
8void dbg_dump_sector(int sec)
9{
10 unsigned char buf[512];
11
12 ata_read_sectors(sec,1,buf);
13 printf("---< Sector %d >-----------------------------------------\n", sec);
14 dbg_dump_buffer(buf);
15}
16
17void dbg_dump_buffer(unsigned char *buf)
18{
19 int i, j;
20 unsigned char c;
21 unsigned char ascii[33];
22
23 for(i = 0;i < 512/32;i++)
24 {
25 for(j = 0;j < 32;j++)
26 {
27 c = buf[i*32+j];
28
29 printf("%02x ", c);
30 if(c < 32 || c > 127)
31 {
32 ascii[j] = '.';
33 }
34 else
35 {
36 ascii[j] = c;
37 }
38 }
39
40 ascii[j] = 0;
41 printf("%s\n", ascii);
42 }
43}
44
45void dbg_print_bpb(struct bpb *bpb)
46{
47 printf("bpb_oemname = \"%s\"\n", bpb->bs_oemname);
48 printf("bpb_bytspersec = %d\n", bpb->bpb_bytspersec);
49 printf("bpb_secperclus = %d\n", bpb->bpb_secperclus);
50 printf("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt);
51 printf("bpb_numfats = %d\n", bpb->bpb_numfats);
52 printf("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt);
53 printf("bpb_totsec16 = %d\n", bpb->bpb_totsec16);
54 printf("bpb_media = %02x\n", bpb->bpb_media);
55 printf("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16);
56 printf("bpb_secpertrk = %d\n", bpb->bpb_secpertrk);
57 printf("bpb_numheads = %d\n", bpb->bpb_numheads);
58 printf("bpb_hiddsec = %u\n", bpb->bpb_hiddsec);
59 printf("bpb_totsec32 = %u\n", bpb->bpb_totsec32);
60
61 printf("bs_drvnum = %d\n", bpb->bs_drvnum);
62 printf("bs_bootsig = %02x\n", bpb->bs_bootsig);
63 if(bpb->bs_bootsig == 0x29)
64 {
65 printf("bs_volid = %xl\n", bpb->bs_volid);
66 printf("bs_vollab = \"%s\"\n", bpb->bs_vollab);
67 printf("bs_filsystype = \"%s\"\n", bpb->bs_filsystype);
68 }
69
70 printf("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32);
71 printf("last_word = %04x\n", bpb->last_word);
72
73 switch(bpb->fat_type)
74 {
75 case FATTYPE_FAT12:
76 printf("fat_type = FAT12\n");
77 break;
78 case FATTYPE_FAT16:
79 printf("fat_type = FAT16\n");
80 break;
81 case FATTYPE_FAT32:
82 printf("fat_type = FAT32\n");
83 break;
84 default:
85 printf("fat_type = UNKNOWN (%d)\n", bpb->fat_type);
86 break;
87 }
88}
89
90void dbg_dir(struct bpb *bpb, int currdir)
91{
92 struct fat_dirent dent;
93 struct fat_direntry de;
94
95 if(fat_opendir(bpb, &dent, currdir) >= 0)
96 {
97 while(fat_getnext(bpb, &dent, &de) >= 0)
98 {
99 printf("%s\n", de.name);
100 }
101 }
102 else
103 {
104 fprintf(stderr, "Could not read dir on cluster %d\n", currdir);
105 }
106}
107
108extern char current_directory[];
109int last_secnum = 0;
110
111void dbg_prompt(void)
112{
113 printf("C:%s> ", current_directory);
114}
115
116void dbg_console(struct bpb* bpb)
117{
118 char cmd[32] = "";
119 char last_cmd[32] = "";
120 int quit = 0;
121 char *s;
122 int secnum;
123
124 while(!quit)
125 {
126 dbg_prompt();
127 if(fgets(cmd, sizeof(cmd) - 1, stdin))
128 {
129 if(strlen(cmd) == 1) /* empty command? */
130 {
131 strcpy(cmd, last_cmd);
132 }
133
134 /* Get the first token */
135 s = strtok(cmd, " \n");
136 if(s)
137 {
138 if(!strcasecmp(s, "dir"))
139 {
140 secnum = 0;
141 if((s = strtok(NULL, " \n")))
142 {
143 secnum = atoi(s);
144 }
145 dbg_dir(bpb, secnum);
146 continue;
147 }
148
149 if(!strcasecmp(s, "ds"))
150 {
151 /* Remember the command */
152 strcpy(last_cmd, s);
153
154 if((s = strtok(NULL, " \n")))
155 {
156 last_secnum = atoi(s);
157 }
158 else
159 {
160 last_secnum++;
161 }
162 printf("secnum: %d\n", last_secnum);
163 dbg_dump_sector(last_secnum);
164 continue;
165 }
166
167 if(!strcasecmp(s, "exit") ||
168 !strcasecmp(s, "x"))
169 {
170 quit = 1;
171 }
172 }
173 }
174 }
175}