2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
2N/A * Copyright (C) 2009 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/* Based on the code from FreeBSD originally distributed under the
2N/A following terms: */
2N/A
2N/A/*-
2N/A * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2N/A * SUCH DAMAGE.
2N/A *
2N/A * $FreeBSD$
2N/A */
2N/A
2N/A
2N/Astatic void
2N/Afill_bsd64_pagetable (grub_uint8_t *src, grub_addr_t target)
2N/A{
2N/A grub_uint64_t *pt2, *pt3, *pt4;
2N/A grub_addr_t pt2t, pt3t;
2N/A int i;
2N/A
2N/A#define PG_V 0x001
2N/A#define PG_RW 0x002
2N/A#define PG_U 0x004
2N/A#define PG_PS 0x080
2N/A
2N/A pt4 = (grub_uint64_t *) src;
2N/A pt3 = (grub_uint64_t *) (src + 4096);
2N/A pt2 = (grub_uint64_t *) (src + 8192);
2N/A
2N/A pt3t = target + 4096;
2N/A pt2t = target + 8192;
2N/A
2N/A grub_memset (src, 0, 4096 * 3);
2N/A
2N/A /*
2N/A * This is kinda brutal, but every single 1GB VM memory segment points to
2N/A * the same first 1GB of physical memory. But it is how BSD expects
2N/A * it to be.
2N/A */
2N/A for (i = 0; i < 512; i++)
2N/A {
2N/A /* Each slot of the level 4 pages points to the same level 3 page */
2N/A pt4[i] = (grub_addr_t) pt3t;
2N/A pt4[i] |= PG_V | PG_RW | PG_U;
2N/A
2N/A /* Each slot of the level 3 pages points to the same level 2 page */
2N/A pt3[i] = (grub_addr_t) pt2t;
2N/A pt3[i] |= PG_V | PG_RW | PG_U;
2N/A
2N/A /* The level 2 page slots are mapped with 2MB pages for 1GB. */
2N/A pt2[i] = i * (2 * 1024 * 1024);
2N/A pt2[i] |= PG_V | PG_RW | PG_PS | PG_U;
2N/A }
2N/A}