~jonathank89/burg/burg-percise

« back to all changes in this revision

Viewing changes to fs/i386/pc/fb.c

  • Committer: Bean
  • Date: 2010-06-23 15:25:02 UTC
  • Revision ID: bean123ch@gmail.com-20100623152502-9h370uiaoryb2r3v
New command time, misc fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#define FB_MAGIC        "FBBF"
31
31
#define FB_MAGIC_LONG   0x46424246
32
32
 
33
 
#define FBM_TYPE_FILE   1
 
33
#define FB_VER_MAJOR    1
 
34
#define FB_VER_MINOR    6
34
35
 
35
36
struct fb_mbr
36
37
{
37
38
  grub_uint8_t jmp_code;
38
39
  grub_uint8_t jmp_ofs;
39
 
  grub_uint8_t boot_code[0x1a9];
40
 
  grub_uint8_t max_sec;         /* 0x1ab  */
41
 
  grub_uint16_t lba;            /* 0x1ac  */
42
 
  grub_uint8_t spt;             /* 0x1ae  */
43
 
  grub_uint8_t heads;           /* 0x1af  */
44
 
  grub_uint16_t boot_base;      /* 0x1b0  */
45
 
  grub_uint16_t boot_size;      /* 0x1b2  */
 
40
  grub_uint8_t boot_code[0x1ab];
 
41
  grub_uint8_t max_sec;         /* 0x1ad  */
 
42
  grub_uint16_t lba;            /* 0x1ae  */
 
43
  grub_uint8_t spt;             /* 0x1b0  */
 
44
  grub_uint8_t heads;           /* 0x1b1  */
 
45
  grub_uint16_t boot_base;      /* 0x1b2  */
46
46
  grub_uint32_t fb_magic;       /* 0x1b4  */
47
47
  grub_uint8_t mbr_table[0x46]; /* 0x1b8  */
48
48
  grub_uint16_t end_magic;      /* 0x1fe  */
50
50
 
51
51
struct fb_data
52
52
{
53
 
  grub_uint16_t menu_ofs;       /* 0x200  */
 
53
  grub_uint16_t boot_size;      /* 0x200  */
54
54
  grub_uint16_t flags;          /* 0x202  */
55
55
  grub_uint8_t ver_major;       /* 0x204  */
56
56
  grub_uint8_t ver_minor;       /* 0x205  */
57
 
  grub_uint32_t pri_size;       /* 0x206  */
58
 
  grub_uint32_t ext_size;       /* 0x20a  */
 
57
  grub_uint16_t list_used;      /* 0x206  */
 
58
  grub_uint16_t list_size;      /* 0x208  */
 
59
  grub_uint16_t pri_size;       /* 0x20a  */
 
60
  grub_uint32_t ext_size;       /* 0x20c  */
59
61
} __attribute__((packed));
60
62
 
61
63
struct fbm_file
62
64
{
63
65
  grub_uint8_t size;
64
 
  grub_uint8_t type;
 
66
  grub_uint8_t flag;
65
67
  grub_uint32_t data_start;
66
68
  grub_uint32_t data_size;
67
69
  grub_uint32_t data_time;
68
 
  grub_uint8_t flag;
69
70
  char name[0];
70
71
} __attribute__((packed));
71
72
 
118
119
        grub_memcpy ((char *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf, nb);
119
120
 
120
121
      if ((fb_lba) ? fb_rw_lba (cmd, sector, ns) : fb_rw_chs (cmd, sector, ns))
121
 
        return 1;
 
122
        {
 
123
          if (fb_max > 7)
 
124
            {
 
125
              fb_max = 7;
 
126
              continue;
 
127
            }
 
128
          else if (fb_max > 1)
 
129
            {
 
130
              fb_max = 1;
 
131
              continue;
 
132
            }
 
133
          return 1;
 
134
        }
122
135
 
123
136
      if (buf)
124
137
        {
139
152
{
140
153
  struct fb_mbr *m;
141
154
  struct fb_data *data;
142
 
  int boot_base, boot_size, i, menu_ofs, list_size;
143
 
  char *p;
 
155
  int boot_base, boot_size, list_used, i;
 
156
  char *p1, *p2;
144
157
 
145
158
  fb_drive = grub_boot_drive;
146
159
 
147
160
  if (fb_drive == GRUB_BOOT_MACHINE_PXE_DL)
148
161
    return 0;
149
162
 
150
 
  if (! fb_rw_lba (0, 0, 1))
151
 
    fb_lba = 1;
152
 
  else if (grub_biosdisk_rw_standard (0x02, fb_drive,
153
 
                                      0, 0, 1, 1,
154
 
                                      GRUB_MEMORY_MACHINE_SCRATCH_SEG))
 
163
  fb_lba = grub_biosdisk_check_int13_extensions (fb_drive);
 
164
  if ((fb_lba) ? fb_rw_lba (0, 0, 1) :
 
165
      grub_biosdisk_rw_standard (0x02, fb_drive, 0, 0, 1, 1,
 
166
                                 GRUB_MEMORY_MACHINE_SCRATCH_SEG))
155
167
    return 0;
156
168
 
157
169
  m =  (struct fb_mbr *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
161
173
  fb_ofs = m->lba;
162
174
  fb_max = m->max_sec;
163
175
  boot_base = m->boot_base;
164
 
  boot_size = m->boot_size;
165
176
 
166
177
  if (! fb_lba)
167
178
    {
193
204
      fb_nhd = (lba - fb_ofs) / fb_spt;
194
205
    }
195
206
 
196
 
  fb_list = grub_malloc (boot_size << 9);
197
 
  if (! fb_list)
198
 
    return 0;
199
 
 
200
 
  if (fb_rw (0, fb_list, boot_base + 1, boot_size))
201
 
    return 0;
202
 
 
203
 
  data = (struct fb_data *) fb_list;
204
 
  if ((data->ver_major != 1) || (data->ver_minor < 5))
205
 
    return 0;
206
 
 
207
 
  menu_ofs = data->menu_ofs;
 
207
  data = (struct fb_data *) m;
 
208
  if (fb_rw (0, (char *) data, boot_base + 1, 1))
 
209
    return 0;
 
210
 
 
211
  if ((data->ver_major != FB_VER_MAJOR) || (data->ver_minor != FB_VER_MINOR))
 
212
    return 0;
 
213
 
 
214
  boot_size = data->boot_size;
208
215
  fb_pri_size = data->pri_size;
209
216
  fb_total_size = data->pri_size + data->ext_size;
210
 
 
211
 
  i = (menu_ofs >> 9) + 1;
212
 
  p = fb_list + (i << 9) - 2;
213
 
  for (; i < boot_size; i++)
214
 
    {
215
 
      grub_memcpy (p, fb_list + (i << 9), 510);
216
 
      p += 510;
217
 
    }
218
 
 
219
 
  list_size = p - fb_list;
220
 
 
221
 
  p = fb_list;
222
 
  while (fb_list[menu_ofs])
223
 
    {
224
 
      int len;
225
 
 
226
 
      len = fb_list[menu_ofs] + 2;
227
 
 
228
 
      if (fb_list[menu_ofs + 1] == FBM_TYPE_FILE)
229
 
        {
230
 
          grub_memcpy (p, fb_list + menu_ofs, len);
231
 
          p += len;
232
 
        }
233
 
 
234
 
      menu_ofs += len;
235
 
      if (menu_ofs >= list_size)
236
 
        return 0;
237
 
    }
238
 
  *p = 0;
 
217
  list_used = data->list_used;
 
218
 
 
219
  fb_list = grub_malloc (list_used << 9);
 
220
  if (! fb_list)
 
221
    return 0;
 
222
 
 
223
  if (fb_rw (0, fb_list, boot_base + 1 + boot_size, list_used))
 
224
    return 0;
 
225
 
 
226
  p1 = p2 = fb_list;
 
227
  for (i = 0; i < list_used - 1; i++)
 
228
    {
 
229
      p1 += 510;
 
230
      p2 += 512;
 
231
      grub_memcpy (p1, p2, 510);
 
232
    }
239
233
 
240
234
  return 1;
241
235
}