~ubuntu-branches/ubuntu/trusty/grub2/trusty

« back to all changes in this revision

Viewing changes to grub-core/loader/i386/pc/freedos.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-01-16 15:18:04 UTC
  • mfrom: (17.6.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140116151804-3foouk7fpqcq3sxx
Tags: 2.02~beta2-2
* Convert patch handling to git-dpm.
* Add bi-endian support to ELF parser (Tomohiro B Berry).
* Adjust restore_mkdevicemap.patch to mark get_kfreebsd_version as static,
  to appease "gcc -Werror=missing-prototypes".
* Cherry-pick from upstream:
  - Change grub-macbless' manual page section to 8.
* Install grub-glue-efi, grub-macbless, grub-render-label, and
  grub-syslinux2cfg.
* grub-shell: Pass -no-pad to xorriso when building floppy images.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <grub/video.h>
33
33
#include <grub/mm.h>
34
34
#include <grub/cpu/relocator.h>
 
35
#include <grub/machine/chainloader.h>
35
36
 
36
37
GRUB_MOD_LICENSE ("GPLv3+");
37
38
 
40
41
static grub_uint32_t ebx = 0xffffffff;
41
42
 
42
43
#define GRUB_FREEDOS_SEGMENT         0x60
 
44
#define GRUB_FREEDOS_ADDR            (GRUB_FREEDOS_SEGMENT << 4)
43
45
#define GRUB_FREEDOS_STACK_SEGMENT         0x1fe0
44
 
#define GRUB_FREEDOS_STACK_POINTER         0x8000
 
46
#define GRUB_FREEDOS_STACK_BPB_POINTER     0x7c00
 
47
#define GRUB_FREEDOS_BPB_ADDR        ((GRUB_FREEDOS_STACK_SEGMENT << 4) \
 
48
                                       + GRUB_FREEDOS_STACK_BPB_POINTER)
 
49
 
 
50
/* FreeDOS boot.asm passes register sp as exactly this. Importantly,
 
51
   it must point below the BPB (to avoid overwriting any of it). */
 
52
#define GRUB_FREEDOS_STACK_POINTER         (GRUB_FREEDOS_STACK_BPB_POINTER \
 
53
                                             - 0x60)
 
54
 
 
55
/* In this, the additional 8192 bytes are the stack reservation; the
 
56
   remaining parts trivially give the maximum allowed size. */
 
57
#define GRUB_FREEDOS_MAX_SIZE        ((GRUB_FREEDOS_STACK_SEGMENT << 4) \
 
58
                                       + GRUB_FREEDOS_STACK_POINTER \
 
59
                                       - GRUB_FREEDOS_ADDR \
 
60
                                       - 8192)
45
61
 
46
62
static grub_err_t
47
63
grub_freedos_boot (void)
49
65
  struct grub_relocator16_state state = { 
50
66
    .cs = GRUB_FREEDOS_SEGMENT,
51
67
    .ip = 0,
52
 
    .ds = 0,
 
68
 
 
69
    .ds = GRUB_FREEDOS_STACK_SEGMENT,
53
70
    .es = 0,
54
71
    .fs = 0,
55
72
    .gs = 0,
56
73
    .ss = GRUB_FREEDOS_STACK_SEGMENT,
57
74
    .sp = GRUB_FREEDOS_STACK_POINTER,
 
75
    .ebp = GRUB_FREEDOS_STACK_BPB_POINTER,
58
76
    .ebx = ebx,
59
 
    .edx = 0,
 
77
    .edx = ebx,
60
78
    .a20 = 1
61
79
  };
62
80
  grub_video_set_mode ("text", 0, 0);
79
97
{
80
98
  grub_file_t file = 0;
81
99
  grub_err_t err;
82
 
  void *kernelsys;
 
100
  void *bs, *kernelsys;
83
101
  grub_size_t kernelsyssize;
 
102
  grub_device_t dev;
84
103
 
85
104
  if (argc == 0)
86
105
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
95
114
  if (! file)
96
115
    goto fail;
97
116
 
 
117
  {
 
118
    grub_relocator_chunk_t ch;
 
119
    err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_BPB_ADDR,
 
120
                                           GRUB_DISK_SECTOR_SIZE);
 
121
    if (err)
 
122
      goto fail;
 
123
    bs = get_virtual_current_address (ch);
 
124
  }
 
125
 
98
126
  ebx = grub_get_root_biosnumber ();
 
127
  dev = grub_device_open (0);
 
128
 
 
129
  if (dev && dev->disk)
 
130
    {
 
131
      err = grub_disk_read (dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, bs);
 
132
      if (err)
 
133
        {
 
134
          grub_device_close (dev);
 
135
          goto fail;
 
136
        }
 
137
      grub_chainloader_patch_bpb (bs, dev, ebx);
 
138
    }
 
139
 
 
140
  if (dev)
 
141
    grub_device_close (dev);
99
142
 
100
143
  kernelsyssize = grub_file_size (file);
 
144
 
 
145
  if (kernelsyssize > GRUB_FREEDOS_MAX_SIZE)
 
146
    {
 
147
      grub_error (GRUB_ERR_BAD_OS,
 
148
                  N_("the size of `%s' is too large"), argv[0]);
 
149
      goto fail;
 
150
    }
 
151
 
101
152
  {
102
153
    grub_relocator_chunk_t ch;
103
 
    err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_SEGMENT << 4,
 
154
    err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_ADDR,
104
155
                                           kernelsyssize);
105
156
    if (err)
106
157
      goto fail;