2N/A/* chainloader.c - boot another boot loader */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2004,2007,2009,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/loader.h>
2N/A#include <grub/file.h>
2N/A#include <grub/err.h>
2N/A#include <grub/device.h>
2N/A#include <grub/disk.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/types.h>
2N/A#include <grub/partition.h>
2N/A#include <grub/dl.h>
2N/A#include <grub/command.h>
2N/A#include <grub/machine/biosnum.h>
2N/A#include <grub/i18n.h>
2N/A#include <grub/video.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/cpu/relocator.h>
2N/A
2N/AGRUB_MOD_LICENSE ("GPLv3+");
2N/A
2N/Astatic grub_dl_t my_mod;
2N/Astatic struct grub_relocator *rel;
2N/Astatic grub_uint32_t ebx = 0xffffffff;
2N/A
2N/A#define GRUB_FREEDOS_SEGMENT 0x60
2N/A#define GRUB_FREEDOS_STACK_SEGMENT 0x1fe0
2N/A#define GRUB_FREEDOS_STACK_POINTER 0x8000
2N/A
2N/Astatic grub_err_t
2N/Agrub_freedos_boot (void)
2N/A{
2N/A struct grub_relocator16_state state = {
2N/A .cs = GRUB_FREEDOS_SEGMENT,
2N/A .ip = 0,
2N/A .ds = 0,
2N/A .es = 0,
2N/A .fs = 0,
2N/A .gs = 0,
2N/A .ss = GRUB_FREEDOS_STACK_SEGMENT,
2N/A .sp = GRUB_FREEDOS_STACK_POINTER,
2N/A .ebx = ebx,
2N/A .edx = 0,
2N/A .a20 = 1
2N/A };
2N/A grub_video_set_mode ("text", 0, 0);
2N/A
2N/A return grub_relocator16_boot (rel, state);
2N/A}
2N/A
2N/Astatic grub_err_t
2N/Agrub_freedos_unload (void)
2N/A{
2N/A grub_relocator_unload (rel);
2N/A rel = NULL;
2N/A grub_dl_unref (my_mod);
2N/A return GRUB_ERR_NONE;
2N/A}
2N/A
2N/Astatic grub_err_t
2N/Agrub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)),
2N/A int argc, char *argv[])
2N/A{
2N/A grub_file_t file = 0;
2N/A grub_err_t err;
2N/A void *kernelsys;
2N/A grub_size_t kernelsyssize;
2N/A
2N/A if (argc == 0)
2N/A return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
2N/A
2N/A grub_dl_ref (my_mod);
2N/A
2N/A rel = grub_relocator_new ();
2N/A if (!rel)
2N/A goto fail;
2N/A
2N/A file = grub_file_open (argv[0]);
2N/A if (! file)
2N/A goto fail;
2N/A
2N/A ebx = grub_get_root_biosnumber ();
2N/A
2N/A kernelsyssize = grub_file_size (file);
2N/A {
2N/A grub_relocator_chunk_t ch;
2N/A err = grub_relocator_alloc_chunk_addr (rel, &ch, GRUB_FREEDOS_SEGMENT << 4,
2N/A kernelsyssize);
2N/A if (err)
2N/A goto fail;
2N/A kernelsys = get_virtual_current_address (ch);
2N/A }
2N/A
2N/A if (grub_file_read (file, kernelsys, kernelsyssize)
2N/A != (grub_ssize_t) kernelsyssize)
2N/A goto fail;
2N/A
2N/A grub_loader_set (grub_freedos_boot, grub_freedos_unload, 1);
2N/A return GRUB_ERR_NONE;
2N/A
2N/A fail:
2N/A
2N/A if (file)
2N/A grub_file_close (file);
2N/A
2N/A grub_freedos_unload ();
2N/A
2N/A return grub_errno;
2N/A}
2N/A
2N/Astatic grub_command_t cmd;
2N/A
2N/AGRUB_MOD_INIT(freedos)
2N/A{
2N/A cmd = grub_register_command ("freedos", grub_cmd_freedos,
2N/A 0, N_("Load FreeDOS kernel.sys."));
2N/A my_mod = mod;
2N/A}
2N/A
2N/AGRUB_MOD_FINI(freedos)
2N/A{
2N/A grub_unregister_command (cmd);
2N/A}