merge mainline into net

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-10-25 13:19:10 +02:00
commit dc5aeea5b9
103 changed files with 2530 additions and 690 deletions

View file

@ -48,10 +48,15 @@ CLEANFILES += grub_script.tab.c grub_script.tab.h
grub_script.yy.h: script/yylex.l
$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $<
grub_script.yy.c: grub_script.yy.h
rs_decoder.S: $(srcdir)/lib/reed_solomon.c
$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3
kern/i386/pc/startup.S: $(builddir)/rs_decoder.S
CLEANFILES += grub_script.yy.c grub_script.yy.h
include $(srcdir)/Makefile.core.am
include $(srcdir)/Makefile.gcry.am
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h
@ -109,6 +114,8 @@ endif
if COND_i386_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pit.h
endif
@ -134,15 +141,24 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_powerpc_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_sparc64_ieee1275
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
endif
if COND_emu
@ -175,7 +191,7 @@ CLEANFILES += symlist.c
BUILT_SOURCES += symlist.c
if COND_HAVE_ASM_USCORE
ASM_PREFIX=1
ASM_PREFIX=_
else
ASM_PREFIX=
endif
@ -185,8 +201,8 @@ noinst_DATA += kernel_syms.lst
kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input
cat kernel_syms.input | grep -v '^#' | sed -n \
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined '"$(ASM_PREFIX)"'kernel \1/;p;}' \
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined '"$(ASM_PREFIX)"' kernel \1/;p;}' \
-e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
-e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \
| sort -u >$@
rm -f kernel_syms.input
CLEANFILES += kernel_syms.lst

View file

@ -92,10 +92,10 @@ kernel = {
ieee1275 = kern/ieee1275/openfw.c;
ieee1275 = term/ieee1275/ofconsole.c;
ieee1275 = term/terminfo.c;
ieee1275 = term/tparm.c;
mips = term/terminfo.c;
mips = term/tparm.c;
terminfoinkernel = term/terminfo.c;
terminfoinkernel = term/tparm.c;
terminfoinkernel = commands/extcmd.c;
terminfoinkernel = lib/arg.c;
i386 = kern/i386/dl.c;
@ -173,9 +173,7 @@ kernel = {
emu = kern/emu/mm.c;
emu = kern/emu/time.c;
videoinkernel = lib/arg.c;
videoinkernel = term/gfxterm.c;
videoinkernel = commands/extcmd.c;
videoinkernel = font/font.c;
videoinkernel = font/font_cmd.c;
videoinkernel = io/bufio.c;
@ -290,6 +288,38 @@ image = {
enable = i386_pc;
};
image = {
name = xz_decompress;
mips = boot/mips/startup_raw.S;
common = boot/decompressor/minilib.c;
common = boot/decompressor/xz.c;
common = lib/xzembed/xz_dec_bcj.c;
common = lib/xzembed/xz_dec_lzma2.c;
common = lib/xzembed/xz_dec_stream.c;
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed';
mips_cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
objcopyflags = '-O binary';
ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000';
cflags = '-static-libgcc';
enable = mips;
};
image = {
name = none_decompress;
mips = boot/mips/startup_raw.S;
common = boot/decompressor/none.c;
mips_cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1 -DGRUB_MACHINE_LINK_ADDR=0x80200000';
objcopyflags = '-O binary';
ldflags = '-lgcc -static-libgcc -Wl,-Ttext,0x80100000';
cflags = '-static-libgcc';
enable = mips;
};
image = {
name = fwstart;
mips_yeeloong = boot/mips/yeeloong/fwstart.S;
@ -510,6 +540,7 @@ module = {
name = extcmd;
common = commands/extcmd.c;
common = lib/arg.c;
enable = terminfomodule;
};
module = {
@ -1305,6 +1336,7 @@ module = {
name = terminfo;
common = term/terminfo.c;
common = term/tparm.c;
enable = terminfomodule;
};
module = {

View file

@ -0,0 +1,102 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/decompressor.h>
void *
memset (void *s, int c, grub_size_t len)
{
grub_uint8_t *ptr;
for (ptr = s; len; ptr++, len--)
*ptr = c;
return s;
}
void *
grub_memmove (void *dest, const void *src, grub_size_t n)
{
char *d = (char *) dest;
const char *s = (const char *) src;
if (d < s)
while (n--)
*d++ = *s++;
else
{
d += n;
s += n;
while (n--)
*--d = *--s;
}
return dest;
}
int
grub_memcmp (const void *s1, const void *s2, grub_size_t n)
{
const char *t1 = s1;
const char *t2 = s2;
while (n--)
{
if (*t1 != *t2)
return (int) *t1 - (int) *t2;
t1++;
t2++;
}
return 0;
}
int memcmp (const void *s1, const void *s2, grub_size_t n)
__attribute__ ((alias ("grub_memcmp")));
void *memmove (void *dest, const void *src, grub_size_t n)
__attribute__ ((alias ("grub_memmove")));
void *memcpy (void *dest, const void *src, grub_size_t n)
__attribute__ ((alias ("grub_memmove")));
void *grub_decompressor_scratch;
void
find_scratch (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize)
{
#ifdef _mips
/* Decoding from ROM. */
if (((grub_addr_t) src & 0x10000000))
{
grub_decompressor_scratch = (void *) ALIGN_UP((grub_addr_t) dst + dstsize,
256);
return;
}
#endif
if ((char *) src + srcsize > (char *) dst + dstsize)
grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) src + srcsize,
256);
else
grub_decompressor_scratch = (void *) ALIGN_UP ((grub_addr_t) dst + dstsize,
256);
return;
}

View file

@ -0,0 +1,39 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/decompressor.h>
void
grub_decompress_core (void *src, void *dest, unsigned long n,
unsigned long dstsize __attribute__ ((unused)))
{
char *d = (char *) dest;
const char *s = (const char *) src;
if (d < s)
while (n--)
*d++ = *s++;
else
{
d += n;
s += n;
while (n--)
*--d = *--s;
}
}

View file

@ -0,0 +1,60 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/decompressor.h>
#include "xz.h"
#include "xz_stream.h"
void
grub_decompress_core (void *src, void *dst, unsigned long srcsize,
unsigned long dstsize)
{
struct xz_dec *dec;
struct xz_buf buf;
find_scratch (src, dst, srcsize, dstsize);
dec = xz_dec_init (GRUB_DECOMPRESSOR_DICT_SIZE);
buf.in = src;
buf.in_pos = 0;
buf.in_size = srcsize;
buf.out = dst;
buf.out_pos = 0;
buf.out_size = dstsize;
while (buf.in_pos != buf.in_size)
{
enum xz_ret xzret;
xzret = xz_dec_run (dec, &buf);
switch (xzret)
{
case XZ_MEMLIMIT_ERROR:
case XZ_FORMAT_ERROR:
case XZ_OPTIONS_ERROR:
case XZ_DATA_ERROR:
case XZ_BUF_ERROR:
return;
default:
break;
}
}
}

View file

@ -185,7 +185,7 @@ real_code_2:
call LOCAL(move_memory)
/* Check for multiboot signature. */
cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE)
cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART)
jz 1f
movl (ramdisk_image - start), %esi

View file

@ -0,0 +1,187 @@
/* startup.S - Startup code for the MIPS. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/symbol.h>
#include <grub/offsets.h>
#include <grub/machine/memory.h>
#include <grub/offsets.h>
#define BASE_ADDR 8
.extern __bss_start
.extern _end
.globl __start, _start, start
.set noreorder
.set nomacro
__start:
_start:
start:
bal codestart
nop
base:
. = _start + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
compressed_size:
.long 0
. = _start + GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE
uncompressed_size:
.long 0
codestart:
/* Save our base. */
move $s0, $ra
/* Parse arguments. Has to be done before relocation.
So need to do it in asm. */
#ifdef GRUB_MACHINE_MIPS_YEELOONG
move $s2, $zero
move $s3, $zero
move $s4, $zero
move $s5, $zero
/* $a2 has the environment. */
addiu $t0, $a2, 1
beq $t0, $zero, argdone
nop
move $t0, $a2
argcont:
lw $t1, 0($t0)
beq $t1, $zero, argdone
nop
#define DO_PARSE(str, reg) \
addiu $t2, $s0, (str-base);\
bal parsestr;\
nop ;\
beq $v0, $zero, 1f;\
nop ;\
b 2f;\
move reg, $v0; \
1:
DO_PARSE (busclockstr, $s2)
DO_PARSE (cpuclockstr, $s3)
DO_PARSE (memsizestr, $s4)
DO_PARSE (highmemsizestr, $s5)
2:
b argcont
addiu $t0, $t0, 4
parsestr:
move $v0, $zero
move $t3, $t1
3:
lb $t4, 0($t2)
lb $t5, 0($t3)
addiu $t2, $t2, 1
addiu $t3, $t3, 1
beq $t5, $zero, 1f
nop
beq $t5, $t4, 3b
nop
bne $t4, $zero, 1f
nop
addiu $t3, $t3, 0xffff
digcont:
lb $t5, 0($t3)
/* Substract '0' from digit. */
addiu $t5, $t5, 0xffd0
bltz $t5, 1f
nop
addiu $t4, $t5, 0xfff7
bgtz $t4, 1f
nop
/* Multiply $v0 by 10 with bitshifts. */
sll $v0, $v0, 1
sll $t4, $v0, 2
addu $v0, $v0, $t4
addu $v0, $v0, $t5
addiu $t3, $t3, 1
b digcont
nop
1:
jr $ra
nop
busclockstr: .asciiz "busclock="
cpuclockstr: .asciiz "cpuclock="
memsizestr: .asciiz "memsize="
highmemsizestr: .asciiz "highmemsize="
.p2align 2
argdone:
#endif
/* Copy the decompressor. */
lui $t1, %hi(base)
addiu $t1, $t1, %lo(base)
lui $t3, %hi(__bss_start)
addiu $t3, $t3, %lo(__bss_start)
move $t2, $s0
1:
beq $t1, $t3, 2f
lb $t4, 0($t2)
sb $t4, 0($t1)
addiu $t1, $t1, 1
b 1b
addiu $t2, $t2, 1
2:
/* Clean out its BSS. */
lui $t1, %hi(__bss_start)
addiu $t1, $t1, %lo(__bss_start)
lui $t2, %hi(_end)
addiu $t2, $t2, %lo(_end)
1:
beq $t1, $t2, 2f
nop
sb $zero, 0($t1)
b 1b
addiu $t1, $t1, 1
2:
/* Decompress the payload. */
lui $a0, %hi(__bss_start)
addiu $a0, $a0, %lo(__bss_start)
lui $t0, %hi(base)
addiu $t0, $t0, %lo(base)
subu $a0, $a0, $t0
addu $a0, $a0, $s0
lui $a1, %hi(GRUB_MACHINE_LINK_ADDR)
addiu $a1, %lo(GRUB_MACHINE_LINK_ADDR)
lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0)
lw $a3, (GRUB_KERNEL_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0)
move $s1, $a1
/* $a0 contains source compressed address, $a1 is destination,
$a2 is compressed size, $a3 is uncompressed size.
*/
move $s6, $a3
lui $sp, %hi(_start - 256)
bal EXT_C(grub_decompress_core)
addiu $sp, $sp, %lo(_start - 256)
move $a0, $s1
move $a1, $s6
#include "../../kern/mips/cache_flush.S"
lui $t1, %hi(GRUB_MACHINE_LINK_ADDR)
addiu $t1, %lo(GRUB_MACHINE_LINK_ADDR)
jr $t1
nop

View file

@ -150,7 +150,7 @@ typedef enum
#define GRUB_OHCI_RESET_CONNECT_CHANGE (1 << 16)
#define GRUB_OHCI_CTRL_EDS 256
#define GRUB_OHCI_BULK_EDS 510
#define GRUB_OHCI_TDS 256
#define GRUB_OHCI_TDS 640
#define GRUB_OHCI_ED_ADDR_MASK 0x7ff
@ -220,7 +220,6 @@ grub_ohci_pci_iter (grub_pci_device_t dev,
grub_pci_address_t addr;
struct grub_ohci *o;
grub_uint32_t revision;
int cs5536;
int j;
/* Determine IO base address. */
@ -230,7 +229,6 @@ grub_ohci_pci_iter (grub_pci_device_t dev,
{
grub_uint64_t basereg;
cs5536 = 1;
basereg = grub_cs5536_read_msr (dev, GRUB_CS5536_MSR_USB_OHCI_BASE);
if (!(basereg & GRUB_CS5536_MSR_USB_BASE_MEMORY_ENABLE))
{

View file

@ -29,6 +29,7 @@
#define GRUB_UHCI_IOMASK (0x7FF << 5)
#define N_QH 256
#define N_TD 640
typedef enum
{
@ -105,7 +106,7 @@ struct grub_uhci
/* N_QH Queue Heads. */
grub_uhci_qh_t qh;
/* 256 Transfer Descriptors. */
/* N_TD Transfer Descriptors. */
grub_uhci_td_t td;
/* Free Transfer Descriptors. */
@ -213,7 +214,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
/* The QH pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */
u->qh = (grub_uhci_qh_t) grub_memalign (4096, 4096);
u->qh = (grub_uhci_qh_t) grub_memalign (4096, sizeof(struct grub_uhci_qh)*N_QH);
if (! u->qh)
goto fail;
@ -227,7 +228,7 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
/* The TD pointer of UHCI is only 32 bits, make sure this
code works on on 64 bits architectures. */
u->td = (grub_uhci_td_t) grub_memalign (4096, 4096*2);
u->td = (grub_uhci_td_t) grub_memalign (4096, sizeof(struct grub_uhci_td)*N_TD);
if (! u->td)
goto fail;
@ -244,9 +245,9 @@ grub_uhci_pci_iter (grub_pci_device_t dev,
/* Link all Transfer Descriptors in a list of available Transfer
Descriptors. */
for (i = 0; i < 256; i++)
for (i = 0; i < N_TD; i++)
u->td[i].linkptr = (grub_uint32_t) (grub_addr_t) &u->td[i + 1];
u->td[255 - 1].linkptr = 0;
u->td[N_TD - 2].linkptr = 0;
u->tdfree = u->td;
/* Make sure UHCI is disabled! */

View file

@ -228,7 +228,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
if (dev->initialized)
{
struct grub_usb_desc_endp *endpdesc;
endpdesc = grub_usb_get_endpdescriptor (dev, 0);
endpdesc = grub_usb_get_endpdescriptor (dev, endpoint);
if (endpdesc)
max = endpdesc->maxpacket;

View file

@ -16,9 +16,28 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef GRUB_DSDT_TEST
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define grub_dprintf(cond, args...) printf ( args )
#define grub_printf printf
typedef uint64_t grub_uint64_t;
typedef uint32_t grub_uint32_t;
typedef uint16_t grub_uint16_t;
typedef uint8_t grub_uint8_t;
#endif
#include <grub/acpi.h>
#ifndef GRUB_DSDT_TEST
#include <grub/misc.h>
#include <grub/cpu/io.h>
#endif
static inline grub_uint32_t
decode_length (const grub_uint8_t *ptr, int *numlen)
@ -123,6 +142,7 @@ skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end)
return 0;
break;
case GRUB_ACPI_EXTOPCODE_FIELD_OP:
case GRUB_ACPI_EXTOPCODE_INDEX_FIELD_OP:
ptr++;
ptr += decode_length (ptr, 0);
break;
@ -136,7 +156,7 @@ skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end)
static int
get_sleep_type (grub_uint8_t *table, grub_uint8_t *end)
{
grub_uint8_t *ptr, *prev;
grub_uint8_t *ptr, *prev = table;
int sleep_type = -1;
ptr = table + sizeof (struct grub_acpi_table_header);
@ -156,11 +176,12 @@ get_sleep_type (grub_uint8_t *table, grub_uint8_t *end)
break;
case GRUB_ACPI_OPCODE_NAME:
ptr++;
if (memcmp (ptr, "_S5_", 4) == 0)
if (memcmp (ptr, "_S5_", 4) == 0 || memcmp (ptr, "\\_S5_", 4) == 0)
{
int ll;
grub_uint8_t *ptr2 = ptr;
ptr2 += 4;
grub_dprintf ("acpi", "S5 found\n");
ptr2 += skip_name_string (ptr, end);
if (*ptr2 != 0x12)
{
grub_printf ("Unknown opcode in _S5: 0x%x\n", *ptr2);
@ -208,6 +229,47 @@ get_sleep_type (grub_uint8_t *table, grub_uint8_t *end)
return sleep_type;
}
#ifdef GRUB_DSDT_TEST
int
main (int argc, char **argv)
{
FILE *f;
size_t len;
unsigned char *buf;
if (argc < 2)
printf ("Usage: %s FILE\n", argv[0]);
f = fopen (argv[1], "rb");
if (!f)
{
printf ("Couldn't open file\n");
return 1;
}
fseek (f, 0, SEEK_END);
len = ftell (f);
fseek (f, 0, SEEK_SET);
buf = malloc (len);
if (!buf)
{
printf ("Couldn't malloc buffer\n");
fclose (f);
return 2;
}
if (fread (buf, 1, len, f) != len)
{
printf ("Read failed\n");
free (buf);
fclose (f);
return 2;
}
printf ("Sleep type = %d\n", get_sleep_type (buf, buf + len));
free (buf);
fclose (f);
return 0;
}
#else
void
grub_acpi_halt (void)
{
@ -264,3 +326,4 @@ grub_acpi_halt (void)
grub_printf ("ACPI shutdown failed\n");
}
#endif

View file

@ -225,7 +225,9 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
int argc, char **args)
{
int i;
#ifdef TODO
int no_mem_option = 0;
#endif
struct grub_command *cmd;
char **cutargs;
int cutargc;
@ -235,7 +237,9 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
/* FIXME: really support this. */
if (argc >= 1 && grub_strcmp (args[0], "--no-mem-option") == 0)
{
#ifdef TODO
no_mem_option = 1;
#endif
argc--;
args++;
continue;

View file

@ -259,7 +259,7 @@ grub_lvm_scan_device (const char *name)
{
grub_err_t err;
grub_disk_t disk;
grub_uint64_t da_offset, da_size, mda_offset, mda_size;
grub_uint64_t mda_offset, mda_size;
char buf[GRUB_LVM_LABEL_SIZE];
char vg_id[GRUB_LVM_ID_STRLEN+1];
char pv_id[GRUB_LVM_ID_STRLEN+1];
@ -319,8 +319,6 @@ grub_lvm_scan_device (const char *name)
pv_id[j] = '\0';
dlocn = pvh->disk_areas_xl;
da_offset = grub_le_to_cpu64 (dlocn->offset);
da_size = grub_le_to_cpu64 (dlocn->size);
dlocn++;
/* Is it possible to have multiple data/metadata areas? I haven't

View file

@ -107,6 +107,14 @@ grub_raid_memberlist (grub_disk_t disk)
return list;
}
static const char *
grub_raid_getname (struct grub_disk *disk)
{
struct grub_raid_array *array = disk->data;
return array->driver->name;
}
#endif
static grub_err_t
@ -476,7 +484,8 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)),
static grub_err_t
insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
grub_disk_addr_t start_sector, const char *scanner_name)
grub_disk_addr_t start_sector, const char *scanner_name,
grub_raid_t raid __attribute__ ((unused)))
{
struct grub_raid_array *array = 0, *p;
@ -524,6 +533,9 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
*array = *new_array;
array->nr_devs = 0;
#ifdef GRUB_UTIL
array->driver = raid;
#endif
grub_memset (&array->device, 0, sizeof (array->device));
grub_memset (&array->start_sector, 0, sizeof (array->start_sector));
@ -662,7 +674,8 @@ grub_raid_register (grub_raid_t raid)
if ((disk->total_sectors != GRUB_ULONG_MAX) &&
(! grub_raid_list->detect (disk, &array, &start_sector)) &&
(! insert_array (disk, &array, start_sector, grub_raid_list->name)))
(! insert_array (disk, &array, start_sector, grub_raid_list->name,
grub_raid_list)))
return 0;
/* This error usually means it's not raid, no need to display
@ -706,6 +719,7 @@ static struct grub_disk_dev grub_raid_dev =
.write = grub_raid_write,
#ifdef GRUB_UTIL
.memberlist = grub_raid_memberlist,
.raidname = grub_raid_getname,
#endif
.next = 0
};

View file

@ -266,11 +266,13 @@ grub_efiemu_prepare (void)
if (prepared)
return GRUB_ERR_NONE;
err = grub_efiemu_autocore ();
if (err)
return err;
grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n",
8 * grub_efiemu_sizeof_uintn_t ());
err = grub_efiemu_autocore ();
/* Create NVRAM. */
grub_efiemu_pnvram ();

View file

@ -601,7 +601,6 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
char fpath[grub_strlen (path)];
char *name = fpath;
char *next;
unsigned int pos = 0;
struct grub_jfs_diropen *diro;
grub_strncpy (fpath, path, grub_strlen (path) + 1);
@ -664,8 +663,6 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
if (!next)
return 0;
pos = 0;
name = next;
next = grub_strchr (name, '/');
if (next)

View file

@ -436,7 +436,6 @@ grub_minix_dir (grub_device_t device, const char *path,
const struct grub_dirhook_info *info))
{
struct grub_minix_data *data = 0;
struct grub_minix_sblock *sblock;
unsigned int pos = 0;
data = grub_minix_mount (device->disk);
@ -447,8 +446,6 @@ grub_minix_dir (grub_device_t device, const char *path,
if (grub_errno)
goto fail;
sblock = &data->sblock;
grub_minix_find_file (data, path);
if (grub_errno)
goto fail;

View file

@ -149,7 +149,6 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
struct grub_sfs_btree *tree;
int i;
int next;
int prev;
treeblock = grub_malloc (data->blocksize);
if (!block)
@ -161,8 +160,6 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
/* Handle this level in the btree. */
do
{
prev = 0;
grub_disk_read (data->disk, next, 0, data->blocksize, treeblock);
if (grub_errno)
{

View file

@ -568,7 +568,6 @@ grub_ufs_dir (grub_device_t device, const char *path,
const struct grub_dirhook_info *info))
{
struct grub_ufs_data *data;
struct grub_ufs_sblock *sblock;
unsigned int pos = 0;
data = grub_ufs_mount (device->disk);
@ -579,8 +578,6 @@ grub_ufs_dir (grub_device_t device, const char *path,
if (grub_errno)
return grub_errno;
sblock = &data->sblock;
if (!path || path[0] != '/')
{
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");

View file

@ -38,10 +38,10 @@ rm -f $tmpfile $outfile
objcopy -R .modname -R .moddeps $infile $tmpfile
# Attach .modname and .moddeps sections
t1=`mktemp`
t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
printf "$modname\0" >$t1
t2=`mktemp`
t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
for dep in $deps; do printf "$dep\0" >> $t2; done
if test -n "$deps"; then

View file

@ -287,8 +287,10 @@ grub_gettext_init_ext (const char *lang)
/* Will try adding .gz as well. */
if (fd_mo == NULL)
{
grub_free (mo_file);
char *mo_file_old;
mo_file_old = mo_file;
mo_file = grub_xasprintf ("%s.gz", mo_file);
grub_free (mo_file_old);
if (!mo_file)
return;
fd_mo = grub_mofile_open (mo_file);

View file

@ -563,7 +563,6 @@ grub_gui_list_new (void)
list_impl_t self;
grub_font_t default_font;
grub_gui_color_t default_fg_color;
grub_gui_color_t default_bg_color;
self = grub_zalloc (sizeof (*self));
if (! self)
@ -576,7 +575,6 @@ grub_gui_list_new (void)
default_font = grub_font_get ("Unknown Regular 16");
default_fg_color = grub_gui_color_rgb (0, 0, 0);
default_bg_color = grub_gui_color_rgb (255, 255, 255);
self->icon_width = 32;
self->icon_height = 32;

View file

@ -309,10 +309,8 @@ redraw_menu_visit (grub_gui_component_t component,
view = userdata;
if (component->ops->is_instance (component, "list"))
{
grub_gui_list_t list;
grub_video_rect_t bounds;
list = (grub_gui_list_t) component;
component->ops->get_bounds (component, &bounds);
grub_gfxmenu_view_redraw (view, &bounds);
}

View file

@ -79,21 +79,9 @@ static void
draw (grub_gfxmenu_box_t self, int x, int y)
{
int height_n;
int height_s;
int height_e;
int height_w;
int width_n;
int width_s;
int width_e;
int width_w;
height_n = get_height (self->scaled_pixmaps[BOX_PIXMAP_N]);
height_s = get_height (self->scaled_pixmaps[BOX_PIXMAP_S]);
height_e = get_height (self->scaled_pixmaps[BOX_PIXMAP_E]);
height_w = get_height (self->scaled_pixmaps[BOX_PIXMAP_W]);
width_n = get_width (self->scaled_pixmaps[BOX_PIXMAP_N]);
width_s = get_width (self->scaled_pixmaps[BOX_PIXMAP_S]);
width_e = get_width (self->scaled_pixmaps[BOX_PIXMAP_E]);
width_w = get_width (self->scaled_pixmaps[BOX_PIXMAP_W]);
/* Draw sides. */

View file

@ -25,26 +25,13 @@
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
#define BYTES_TO_PAGES(bytes) ((bytes) >> 12)
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
#define PAGES_TO_BYTES(pages) ((pages) << 12)
/* The size of a memory map obtained from the firmware. This must be
a multiplier of 4KB. */
#define MEMORY_MAP_SIZE 0x3000
/* Maintain the list of allocated pages. */
struct allocated_page
{
grub_efi_physical_address_t addr;
grub_efi_uint64_t num_pages;
};
#define ALLOCATED_PAGES_SIZE 0x1000
#define MAX_ALLOCATED_PAGES \
(ALLOCATED_PAGES_SIZE / sizeof (struct allocated_page))
static struct allocated_page *allocated_pages = 0;
/* The minimum and maximum heap size for GRUB itself. */
#define MIN_HEAP_SIZE 0x100000
#define MAX_HEAP_SIZE (1600 * 0x100000)
@ -102,22 +89,6 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
return 0;
}
if (allocated_pages)
{
unsigned i;
for (i = 0; i < MAX_ALLOCATED_PAGES; i++)
if (allocated_pages[i].addr == 0)
{
allocated_pages[i].addr = address;
allocated_pages[i].num_pages = pages;
break;
}
if (i == MAX_ALLOCATED_PAGES)
grub_fatal ("too many page allocations");
}
return (void *) ((grub_addr_t) address);
}
@ -128,20 +99,6 @@ grub_efi_free_pages (grub_efi_physical_address_t address,
{
grub_efi_boot_services_t *b;
if (allocated_pages
&& ((grub_efi_physical_address_t) ((grub_addr_t) allocated_pages)
!= address))
{
unsigned i;
for (i = 0; i < MAX_ALLOCATED_PAGES; i++)
if (allocated_pages[i].addr == address)
{
allocated_pages[i].addr = 0;
break;
}
}
b = grub_efi_system_table->boot_services;
efi_call_2 (b->free_pages, address, pages);
}
@ -422,14 +379,6 @@ grub_efi_mm_init (void)
grub_efi_uint64_t required_pages;
int mm_status;
/* First of all, allocate pages to maintain allocations. */
allocated_pages
= grub_efi_allocate_pages (0, BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE));
if (! allocated_pages)
grub_fatal ("cannot allocate memory");
grub_memset (allocated_pages, 0, ALLOCATED_PAGES_SIZE);
/* Prepare a memory region to store two memory maps. */
memory_map = grub_efi_allocate_pages (0,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
@ -447,6 +396,9 @@ grub_efi_mm_init (void)
((grub_efi_physical_address_t) ((grub_addr_t) memory_map),
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
/* Freeing/allocating operations may increase memory map size. */
map_size += desc_size * 32;
memory_map = grub_efi_allocate_pages (0, 2 * BYTES_TO_PAGES (map_size));
if (! memory_map)
grub_fatal ("cannot allocate memory");
@ -499,24 +451,3 @@ grub_efi_mm_init (void)
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
}
void
grub_efi_mm_fini (void)
{
if (allocated_pages)
{
unsigned i;
for (i = 0; i < MAX_ALLOCATED_PAGES; i++)
{
struct allocated_page *p;
p = allocated_pages + i;
if (p->addr != 0)
grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages);
}
grub_efi_free_pages ((grub_addr_t) allocated_pages,
BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE));
}
}

View file

@ -61,9 +61,11 @@ void
grub_emu_post_init (void)
{
grub_lvm_fini ();
grub_mdraid_fini ();
grub_mdraid09_fini ();
grub_mdraid1x_fini ();
grub_raid_fini ();
grub_raid_init ();
grub_mdraid_init ();
grub_mdraid09_init ();
grub_mdraid1x_init ();
grub_lvm_init ();
}

View file

@ -189,31 +189,40 @@ find_root_device_from_libzfs (const char *dir)
{
zpool_handle_t *zpool;
libzfs_handle_t *libzfs;
nvlist_t *nvlist;
nvlist_t **nvlist_array;
nvlist_t *config, *vdev_tree;
nvlist_t **children, **path;
unsigned int nvlist_count;
unsigned int i;
libzfs = grub_get_libzfs_handle ();
if (! libzfs)
return NULL;
zpool = zpool_open (libzfs, poolname);
nvlist = zpool_get_config (zpool, NULL);
config = zpool_get_config (zpool, NULL);
if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0)
if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) != 0)
error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
if (nvlist_lookup_nvlist_array (nvlist, "children", &nvlist_array, &nvlist_count) != 0)
if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0)
error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
assert (nvlist_count > 0);
do
while (nvlist_lookup_nvlist_array (children[0], "children",
&children, &nvlist_count) == 0)
assert (nvlist_count > 0);
for (i = 0; i < nvlist_count; i++)
{
assert (nvlist_count > 0);
} while (nvlist_lookup_nvlist_array (nvlist_array[0], "children",
&nvlist_array, &nvlist_count) == 0);
if (nvlist_lookup_string (children[i], "path", &device) != 0)
error (1, errno, "nvlist_lookup_string (\"path\")");
if (nvlist_lookup_string (nvlist_array[0], "path", &device) != 0)
error (1, errno, "nvlist_lookup_string (\"path\")");
struct stat st;
if (stat (device, &st) == 0)
break;
device = NULL;
}
zpool_close (zpool);
}

View file

@ -1,7 +1,7 @@
/* hostdisk.c - emulate biosdisk */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009 Free Software Foundation, Inc.
* Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -115,6 +115,9 @@ struct hd_geometry
# include <util.h> /* getrawpartition */
# endif /* HAVE_GETRAWPARTITION */
# include <sys/fdio.h>
# ifndef FLOPPY_MAJOR
# define FLOPPY_MAJOR 2
# endif /* ! FLOPPY_MAJOR */
# ifndef RAW_FLOPPY_MAJOR
# define RAW_FLOPPY_MAJOR 9
# endif /* ! RAW_FLOPPY_MAJOR */
@ -1624,7 +1627,16 @@ grub_util_biosdisk_is_floppy (grub_disk_t disk)
return 1;
#endif
#if defined(FLOPPY_MAJOR)
if (major(st.st_rdev) == FLOPPY_MAJOR)
#else
/* Some kernels (e.g. kFreeBSD) don't have a static major number
for floppies, but they still use a "fd[0-9]" pathname. */
if (map[disk->id].device[5] == 'f'
&& map[disk->id].device[6] == 'd'
&& map[disk->id].device[7] >= '0'
&& map[disk->id].device[7] <= '9')
#endif
return 1;
return 0;

View file

@ -21,7 +21,6 @@
#include <stdlib.h>
#include <setjmp.h>
#include <sys/stat.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>

View file

@ -416,6 +416,10 @@ grub_make_system_path_relative_to_its_root (const char *path)
{
free (buf);
free (buf2);
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
if (poolfs)
return xasprintf ("/%s/@", poolfs);
#endif
return xstrdup ("");
}
else

View file

@ -77,69 +77,6 @@
#define RepLenCoder (LenCoder + kNumLenProbs)
#define Literal (RepLenCoder + kNumLenProbs)
#if 0
DbgOut:
pushf
pushl %ebp
pushl %edi
pushl %esi
pushl %edx
pushl %ecx
pushl %ebx
pushl %eax
call _DebugPrint
popl %eax
popl %ebx
popl %ecx
popl %edx
popl %esi
popl %edi
popl %ebp
popf
ret
/*
* int LzmaDecodeProperties(CLzmaProperties *propsRes,
* const unsigned char *propsData,
* int size);
*/
_LzmaDecodePropertiesA:
movb (%edx), %dl
xorl %ecx, %ecx
1:
cmpb $45, %dl
jb 2f
incl %ecx
subb $45, %dl
jmp 1b
2:
movl %ecx, 8(%eax) /* pb */
xorl %ecx, %ecx
1:
cmpb $9, %dl
jb 2f
incl %ecx
subb $9, %dl
2:
movl %ecx, 4(%eax) /* lp */
movb %dl, %cl
movl %ecx, (%eax) /* lc */
#endif
#ifndef ASM_FILE
xorl %eax, %eax
#endif
ret
#define out_size 8(%ebp)
#define now_pos -4(%ebp)

View file

@ -100,6 +100,8 @@ VARIABLE(grub_install_dos_part)
.long 0xFFFFFFFF
VARIABLE(grub_install_bsd_part)
.long 0xFFFFFFFF
reed_solomon_redundancy:
.long 0
#ifdef APPLE_CC
bss_start:
@ -107,7 +109,58 @@ bss_start:
bss_end:
.long 0
#endif
/*
* This is the area for all of the special variables.
*/
VARIABLE(grub_boot_drive)
.byte 0
/* the real mode code continues... */
LOCAL (codestart):
cli /* we're not safe here! */
/* set up %ds, %ss, and %es */
xorw %ax, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
/* set up the real mode/BIOS stack */
movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
movl %ebp, %esp
sti /* we're safe again */
/* save the boot drive */
ADDR32 movb %dl, EXT_C(grub_boot_drive)
/* reset disk system (%ah = 0) */
int $0x13
/* transition to protected mode */
DATA32 call real_to_prot
/* The ".code32" directive takes GAS out of 16-bit mode. */
.code32
incl %eax
call grub_gate_a20
movl EXT_C(grub_compressed_size), %edx
addl $(GRUB_KERNEL_MACHINE_RAW_SIZE - GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART), %edx
movl reed_solomon_redundancy, %ecx
leal _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART, %eax
testl %edx, %edx
jz post_reed_solomon
call EXT_C (grub_reed_solomon_recover)
jmp post_reed_solomon
#include <rs_decoder.S>
.text
. = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART
/*
* Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
* This uses the a.out kludge to load raw binary to the area starting at 1MB,
@ -171,38 +224,8 @@ multiboot_trampoline:
movb $0xFF, %dh
/* enter the usual booting */
call prot_to_real
.code16
/* the real mode code continues... */
LOCAL (codestart):
cli /* we're not safe here! */
/* set up %ds, %ss, and %es */
xorw %ax, %ax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
/* set up the real mode/BIOS stack */
movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
movl %ebp, %esp
sti /* we're safe again */
/* save the boot drive */
ADDR32 movb %dl, EXT_C(grub_boot_drive)
/* reset disk system (%ah = 0) */
int $0x13
/* transition to protected mode */
DATA32 call real_to_prot
/* The ".code32" directive takes GAS out of 16-bit mode. */
.code32
incl %eax
call grub_gate_a20
post_reed_solomon:
#ifdef ENABLE_LZMA
movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
@ -271,15 +294,6 @@ LOCAL (codestart):
*/
call EXT_C(grub_main)
/*
* This is the area for all of the special variables.
*/
VARIABLE(grub_boot_drive)
.byte 0
.p2align 2 /* force 4-byte alignment */
#include "../realmode.S"
/*
@ -577,7 +591,7 @@ FUNCTION(grub_console_putchar)
LOCAL(bypass_table):
.word 0x0100 | '\e',0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r'
.word 0x011b, 0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r'
.word 0x1c00 | '\n'
LOCAL(bypass_table_end):
@ -601,6 +615,7 @@ LOCAL(bypass_table_end):
FUNCTION(grub_console_getkey)
pushl %ebp
pushl %edi
call prot_to_real
.code16
@ -630,15 +645,16 @@ FUNCTION(grub_console_getkey)
jz 1f
andl %edx, %eax
cmp %eax, 0x20
ja 2f
cmpl $0x20, %eax
jae 2f
movl %edx, %eax
leal LOCAL(bypass_table), %esi
leal LOCAL(bypass_table), %edi
movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx
repne cmpsw
repne scasw
jz 3f
addl $('a' - 1 | GRUB_TERM_CTRL), %eax
andl $0xff, %eax
addl $(('a' - 1) | GRUB_TERM_CTRL), %eax
jmp 2f
3:
andl $0xff, %eax
@ -647,7 +663,8 @@ FUNCTION(grub_console_getkey)
1: movl %edx, %eax
shrl $8, %eax
orl $GRUB_TERM_EXTENDED, %eax
2:
2:
popl %edi
popl %ebp
ret
@ -803,6 +820,10 @@ FUNCTION(grub_console_setcursor)
DATA32 call real_to_prot
.code32
cmp %cl, %ch
jb 3f
movw $0x0d0e, %cx
3:
movw %cx, console_cursor_shape
1:
/* set %cx to the designated cursor shape */

View file

@ -1,6 +1,9 @@
#include <grub/symbol.h>
.set noreorder
.set nomacro
FUNCTION (grub_cpu_flush_cache)
FUNCTION (grub_arch_sync_caches)
#include "cache_flush.S"

View file

@ -9,15 +9,15 @@
subu $t1, $t3, $t2
1:
cache 1, 0($t0)
addiu $t0, $t0, 0x1
addiu $t1, $t1, 0xffff
bne $t1, $zero, 1b
addiu $t0, $t0, 0x1
sync
move $t0, $t2
subu $t1, $t3, $t2
2:
cache 0, 0($t0)
addiu $t0, $t0, 0x1
addiu $t1, $t1, 0xffff
bne $t1, $zero, 2b
addiu $t0, $t0, 0x1
sync

View file

@ -22,128 +22,23 @@
#include <grub/machine/memory.h>
#include <grub/offsets.h>
#define BASE_ADDR 8
.extern __bss_start
.extern _end
#define BASE_ADDR 8
.globl __start, _start, start
.set noreorder
.set nomacro
__start:
_start:
start:
bal codestart
base:
. = _start + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
compressed_size:
.long 0
. = _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
start:
.extern __bss_start
.extern _end
bal cont
nop
. = _start + GRUB_KERNEL_MIPS_YEELOONG_TOTAL_MODULE_SIZE
total_module_size:
.long 0
. = _start + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE
kernel_image_size:
.long 0
codestart:
/* Save our base. */
move $s0, $ra
/* Parse arguments. Has to be done before relocation.
So need to do it in asm. */
#ifdef GRUB_MACHINE_MIPS_YEELOONG
move $s2, $zero
move $s3, $zero
move $s4, $zero
move $s5, $zero
/* $a2 has the environment. */
addiu $t0, $a2, 1
beq $t0, $zero, argdone
move $t0, $a2
argcont:
lw $t1, 0($t0)
beq $t1, $zero, argdone
#define DO_PARSE(str, reg) \
addiu $t2, $s0, (str-base);\
bal parsestr;\
beq $v0, $zero, 1f;\
move reg, $v0;\
b 2f;\
1:
DO_PARSE (busclockstr, $s2)
DO_PARSE (cpuclockstr, $s3)
DO_PARSE (memsizestr, $s4)
DO_PARSE (highmemsizestr, $s5)
2:
addiu $t0, $t0, 4
b argcont
parsestr:
move $v0, $zero
move $t3, $t1
3:
lb $t4, 0($t2)
lb $t5, 0($t3)
addiu $t2, $t2, 1
addiu $t3, $t3, 1
beq $t5, $zero, 1f
beq $t5, $t4, 3b
bne $t4, $zero, 1f
addiu $t3, $t3, 0xffff
digcont:
lb $t5, 0($t3)
/* Substract '0' from digit. */
addiu $t5, $t5, 0xffd0
bltz $t5, 1f
addiu $t4, $t5, 0xfff7
bgtz $t4, 1f
/* Multiply $v0 by 10 with bitshifts. */
sll $v0, $v0, 1
sll $t4, $v0, 2
addu $v0, $v0, $t4
addu $v0, $v0, $t5
addiu $t3, $t3, 1
b digcont
1:
jr $ra
busclockstr: .asciiz "busclock="
cpuclockstr: .asciiz "cpuclock="
memsizestr: .asciiz "memsize="
highmemsizestr: .asciiz "highmemsize="
.p2align 2
argdone:
#endif
/* Decompress the payload. */
addiu $a0, $s0, GRUB_KERNEL_MACHINE_RAW_SIZE - BASE_ADDR
lui $a1, %hi(compressed)
addiu $a1, %lo(compressed)
lw $a2, (GRUB_KERNEL_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0)
move $s1, $a1
/* $a0 contains source compressed address, $a1 is destination,
$a2 is compressed size. FIXME: put LZMA here. Don't clober $s0,
$s1, $s2, $s3, $s4 and $s5.
On return $v0 contains uncompressed size.
*/
move $v0, $a2
reloccont:
lb $t4, 0($a0)
sb $t4, 0($a1)
addiu $a1,$a1,1
addiu $a0,$a0,1
addiu $a2, 0xffff
bne $a2, $0, reloccont
move $a0, $s1
move $a1, $v0
#include "cache_flush.S"
lui $t1, %hi(cont)
addiu $t1, %lo(cont)
jr $t1
. = _start + GRUB_KERNEL_MACHINE_RAW_SIZE
compressed:
. = _start + GRUB_KERNEL_MACHINE_PREFIX
VARIABLE(grub_prefix)
@ -166,6 +61,8 @@ VARIABLE (grub_arch_highmemsize)
.long 0
#endif
cont:
/* Save our base. */
move $s0, $ra
#ifdef GRUB_MACHINE_MIPS_YEELOONG
lui $t1, %hi(grub_arch_busclock)
@ -177,15 +74,13 @@ cont:
#endif
/* Move the modules out of BSS. */
lui $t1, %hi(_start)
addiu $t1, %lo(_start)
lw $t2, (GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE - BASE_ADDR)($s0)
addu $t2, $t1, $t2
lui $t2, %hi(__bss_start)
addiu $t2, %lo(__bss_start)
lui $t1, %hi(_end)
addiu $t1, %lo(_end)
addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN-1)
li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN-1)
addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
nor $t3, $t3, $0
and $t1, $t1, $t3
@ -194,33 +89,38 @@ cont:
/* Backward copy. */
add $t1, $t1, $t3
add $t2, $t2, $t3
addiu $t1, $t1, 0xffff
addiu $t2, $t2, 0xffff
addiu $t1, $t1, -1
addiu $t2, $t2, -1
/* $t2 is source. $t1 is destination. $t3 is size. */
modulesmovcont:
beq $t3, $0, modulesmovdone
nop
lb $t4, 0($t2)
sb $t4, 0($t1)
addiu $t1,$t1,0xffff
addiu $t2,$t2,0xffff
addiu $t3, 0xffff
bne $t3, $0, modulesmovcont
addiu $t2, $t2, -1
addiu $t1, $t1, -1
b modulesmovcont
addiu $t3, $t3, -1
modulesmovdone:
/* Clean BSS. */
lui $t1, %hi(__bss_start)
addiu $t1, %lo(__bss_start)
addiu $t1, $t1, %lo(__bss_start)
lui $t2, %hi(_end)
addiu $t2, %lo(_end)
addiu $t2, $t2, %lo(_end)
bsscont:
sb $0,0($t1)
addiu $t1,$t1,1
sltu $t3,$t1,$t2
addiu $t1, $t1, 1
sltu $t3, $t1, $t2
bne $t3, $0, bsscont
nop
li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH
lui $t1, %hi(grub_main)
addiu $t1, %lo(grub_main)
lui $sp, %hi(GRUB_MACHINE_MEMORY_STACK_HIGH)
jr $t1
addiu $sp, $sp, %lo(GRUB_MACHINE_MEMORY_STACK_HIGH)

View file

@ -24,6 +24,9 @@
* See <http://www.7-zip.org>, for more information about LZMA.
*/
#include <config.h>
#include <string.h>
#include <grub/lib/LzFind.h>

View file

@ -24,6 +24,8 @@
* See <http://www.7-zip.org>, for more information about LZMA.
*/
#include <config.h>
#include <stdio.h>
#include <string.h>

View file

@ -260,7 +260,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
char *option = 0;
/* No option is used. */
if ((num && GRUB_COMMAND_OPTIONS_AT_START)
if ((num && (cmd->cmd->flags & GRUB_COMMAND_OPTIONS_AT_START))
|| arg[0] != '-' || grub_strlen (arg) == 1)
{
if (add_arg (arg) != 0)

View file

@ -486,8 +486,12 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
if (legacy_commands[cmdnum].flags & FLAG_TERMINAL)
{
int dumb = 0, no_echo = 0, no_edit = 0, lines = 24;
int console = 0, serial = 0, hercules = 0;
int dumb = 0, lines = 24;
#ifdef TODO
int no_echo = 0, no_edit = 0;
int hercules = 0;
#endif
int console = 0, serial = 0;
/* Big enough for any possible resulting command. */
char outbuf[256] = "";
char *outptr;
@ -497,13 +501,13 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
" [console] [serial] [hercules]"*/
if (grub_memcmp (ptr, "--dumb", sizeof ("--dumb") - 1) == 0)
dumb = 1;
#ifdef TODO
if (grub_memcmp (ptr, "--no-echo", sizeof ("--no-echo") - 1) == 0)
no_echo = 1;
if (grub_memcmp (ptr, "--no-edit", sizeof ("--no-edit") - 1) == 0)
no_edit = 1;
#endif
if (grub_memcmp (ptr, "--lines=", sizeof ("--lines=") - 1) == 0)
{
lines = grub_strtoul (ptr + sizeof ("--lines=") - 1, 0, 0);
@ -519,10 +523,10 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
if (grub_memcmp (ptr, "serial", sizeof ("serial") - 1) == 0)
serial = 1;
#ifdef TODO
if (grub_memcmp (ptr, "hercules", sizeof ("hercules") - 1) == 0)
hercules = 1;
#endif
while (*ptr && !grub_isspace (*ptr))
ptr++;
while (*ptr && grub_isspace (*ptr))

View file

@ -20,6 +20,9 @@
.p2align 4 /* force 16-byte alignment */
.set noreorder
.set nomacro
VARIABLE (grub_relocator_forward_start)
move $a0, $9
move $a1, $10
@ -28,9 +31,9 @@ copycont1:
lb $11,0($8)
sb $11,0($9)
addiu $8, $8, 1
addiu $9, $9, 1
addiu $10, $10, -1
bne $10, $0, copycont1
addiu $9, $9, 1
#include "../../kern/mips/cache_flush.S"
@ -49,9 +52,9 @@ copycont2:
lb $11,0($8)
sb $11,0($9)
addiu $8, $8, -1
addiu $9, $9, -1
addiu $10, $10, -1
bne $10, $0, copycont2
addiu $9, $9, -1
#include "../../kern/mips/cache_flush.S"

View file

@ -0,0 +1,518 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef TEST
#include <stdio.h>
#define xmalloc malloc
#define grub_memset memset
#define grub_memcpy memcpy
#endif
#ifndef STANDALONE
#ifdef TEST
#include <string.h>
#include <stdlib.h>
typedef unsigned int grub_size_t;
typedef unsigned char grub_uint8_t;
typedef unsigned short grub_uint16_t;
#else
#include <grub/types.h>
#include <grub/reed_solomon.h>
#include <grub/util/misc.h>
#include <grub/misc.h>
#endif
#endif
#ifdef STANDALONE
#ifdef TEST
typedef unsigned int grub_size_t;
typedef unsigned char grub_uint8_t;
typedef unsigned short grub_uint16_t;
#else
#include <grub/types.h>
#endif
void
grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs);
#endif
#define GF_SIZE 8
typedef grub_uint8_t gf_single_t;
typedef grub_uint16_t gf_double_t;
#define GF_POLYNOMIAL 0x1d
#define GF_INVERT2 0x8e
#if defined (STANDALONE) && !defined (TEST)
static char *gf_invert __attribute__ ((section(".text"))) = (void *) 0x100000;
static char *scratch __attribute__ ((section(".text"))) = (void *) 0x100100;
#else
static char *scratch;
static grub_uint8_t gf_invert[256];
#endif
#define SECTOR_SIZE 512
#define MAX_BLOCK_SIZE (200 * SECTOR_SIZE)
static gf_single_t
gf_reduce (gf_double_t a)
{
int i;
for (i = GF_SIZE - 1; i >= 0; i--)
if (a & (1ULL << (i + GF_SIZE)))
a ^= (((gf_double_t) GF_POLYNOMIAL) << i);
return a & ((1ULL << GF_SIZE) - 1);
}
static gf_single_t
gf_mul (gf_single_t a, gf_single_t b)
{
gf_double_t res = 0;
int i;
for (i = 0; i < GF_SIZE; i++)
if (b & (1 << i))
res ^= ((gf_double_t) a) << i;
return gf_reduce (res);
}
static void
init_inverts (void)
{
gf_single_t a = 1, ai = 1;
do
{
a = gf_mul (a, 2);
ai = gf_mul (ai, GF_INVERT2);
gf_invert[a] = ai;
}
while (a != 1);
}
static gf_single_t
pol_evaluate (gf_single_t *pol, grub_size_t degree, gf_single_t x)
{
int i;
gf_single_t xn = 1, s = 0;
for (i = degree; i >= 0; i--)
{
s ^= gf_mul (pol[i], xn);
xn = gf_mul (x, xn);
}
return s;
}
#if !defined (STANDALONE)
static void
rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs)
{
gf_single_t *rs_polynomial, a = 1;
int i, j;
gf_single_t *m;
m = xmalloc ((s + rs) * sizeof (gf_single_t));
grub_memcpy (m, data, s * sizeof (gf_single_t));
grub_memset (m + s, 0, rs * sizeof (gf_single_t));
rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t));
grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t));
rs_polynomial[rs] = 1;
/* Multiply with X - a^r */
for (j = 0; j < rs; j++)
{
if (a & (1 << (GF_SIZE - 1)))
{
a <<= 1;
a ^= GF_POLYNOMIAL;
}
else
a <<= 1;
for (i = 0; i < rs; i++)
rs_polynomial[i] = rs_polynomial[i + 1] ^ gf_mul (a, rs_polynomial[i]);
rs_polynomial[rs] = gf_mul (a, rs_polynomial[rs]);
}
for (j = 0; j < s; j++)
if (m[j])
{
gf_single_t f = m[j];
for (i = 0; i <= rs; i++)
m[i+j] ^= gf_mul (rs_polynomial[i], f);
}
free (rs_polynomial);
grub_memcpy (data + s, m + s, rs * sizeof (gf_single_t));
free (m);
}
#endif
static void
syndroms (gf_single_t *m, grub_size_t s, grub_size_t rs,
gf_single_t *sy)
{
gf_single_t xn = 1;
unsigned i;
for (i = 0; i < rs; i++)
{
if (xn & (1 << (GF_SIZE - 1)))
{
xn <<= 1;
xn ^= GF_POLYNOMIAL;
}
else
xn <<= 1;
sy[i] = pol_evaluate (m, s + rs - 1, xn);
}
}
static void
gauss_eliminate (gf_single_t *eq, int n, int m, int *chosen)
{
int i, j;
for (i = 0 ; i < n; i++)
{
int nzidx;
int k;
gf_single_t r;
for (nzidx = 0; nzidx < m && (eq[i * (m + 1) + nzidx] == 0);
nzidx++);
if (nzidx == m)
continue;
chosen[i] = nzidx;
r = gf_invert [eq[i * (m + 1) + nzidx]];
for (j = 0; j < m + 1; j++)
eq[i * (m + 1) + j] = gf_mul (eq[i * (m + 1) + j], r);
for (j = i + 1; j < n; j++)
{
gf_single_t rr = eq[j * (m + 1) + nzidx];
for (k = 0; k < m + 1; k++)
eq[j * (m + 1) + k] ^= gf_mul (eq[i * (m + 1) + k], rr);
}
}
}
static void
gauss_solve (gf_single_t *eq, int n, int m, gf_single_t *sol)
{
int *chosen;
int i, j;
#ifndef STANDALONE
chosen = xmalloc (n * sizeof (int));
grub_memset (chosen, -1, n * sizeof (int));
#else
chosen = (void *) scratch;
scratch += n;
#endif
for (i = 0; i < m; i++)
sol[i] = 0;
gauss_eliminate (eq, n, m, chosen);
for (i = n - 1; i >= 0; i--)
{
gf_single_t s = 0;
if (chosen[i] == -1)
continue;
for (j = 0; j < m; j++)
s ^= gf_mul (eq[i * (m + 1) + j], sol[j]);
s ^= eq[i * (m + 1) + m];
sol[chosen[i]] = s;
}
#ifndef STANDALONE
free (chosen);
#else
scratch -= n;
#endif
}
static void
rs_recover (gf_single_t *m, grub_size_t s, grub_size_t rs)
{
grub_size_t rs2 = rs / 2;
gf_single_t *sigma;
gf_single_t *errpot;
int *errpos;
gf_single_t *sy;
int errnum = 0;
int i, j;
#ifndef STANDALONE
sigma = xmalloc (rs2 * sizeof (gf_single_t));
errpot = xmalloc (rs2 * sizeof (gf_single_t));
errpos = xmalloc (rs2 * sizeof (int));
sy = xmalloc (rs * sizeof (gf_single_t));
#else
sigma = (void *) scratch;
scratch += rs2 * sizeof (gf_single_t);
errpot = (void *) scratch;
scratch += rs2 * sizeof (gf_single_t);
errpos = (void *) scratch;
scratch += rs2 * sizeof (int);
sy = (void *) scratch;
scratch += rs * sizeof (gf_single_t);
#endif
syndroms (m, s, rs, sy);
{
gf_single_t *eq;
#ifndef STANDALONE
eq = xmalloc (rs2 * (rs2 + 1) * sizeof (gf_single_t));
#else
eq = (void *) scratch;
scratch += rs2 * (rs2 + 1) * sizeof (gf_single_t);
#endif
for (i = 0; i < (int) rs; i++)
if (sy[i] != 0)
break;
/* No error detected. */
if (i == (int) rs)
return;
for (i = 0; i < (int) rs2; i++)
for (j = 0; j < (int) rs2 + 1; j++)
eq[i * (rs2 + 1) + j] = sy[i+j];
for (i = 0; i < (int) rs2; i++)
sigma[i] = 0;
gauss_solve (eq, rs2, rs2, sigma);
#ifndef STANDALONE
free (eq);
#else
scratch -= rs2 * (rs2 + 1) * sizeof (gf_single_t);
#endif
}
{
gf_single_t xn = 1, yn = 1;
for (i = 0; i < (int) (rs + s); i++)
{
gf_single_t ev = (gf_mul (pol_evaluate (sigma, rs2 - 1, xn), xn) ^ 1);
if (ev == 0)
{
errpot[errnum] = yn;
errpos[errnum++] = s + rs - i - 1;
}
yn = gf_mul (yn, 2);
xn = gf_mul (xn, GF_INVERT2);
}
}
{
gf_single_t *errvals;
gf_single_t *eq;
#ifndef STANDALONE
eq = xmalloc (rs * (errnum + 1) * sizeof (gf_single_t));
errvals = xmalloc (errnum * sizeof (int));
#else
eq = (void *) scratch;
scratch += rs * (errnum + 1) * sizeof (gf_single_t);
errvals = (void *) scratch;
scratch += errnum * sizeof (int);
#endif
for (j = 0; j < errnum; j++)
eq[j] = errpot[j];
eq[errnum] = sy[0];
for (i = 1; i < (int) rs; i++)
{
for (j = 0; j < (int) errnum; j++)
eq[(errnum + 1) * i + j] = gf_mul (errpot[j],
eq[(errnum + 1) * (i - 1) + j]);
eq[(errnum + 1) * i + errnum] = sy[i];
}
gauss_solve (eq, rs, errnum, errvals);
for (i = 0; i < (int) errnum; i++)
m[errpos[i]] ^= errvals[i];
#ifndef STANDALONE
free (eq);
free (errvals);
#else
scratch -= rs * (errnum + 1) * sizeof (gf_single_t);
scratch -= errnum * sizeof (int);
#endif
}
#ifndef STANDALONE
free (sigma);
free (errpot);
free (errpos);
free (sy);
#else
scratch -= rs2 * sizeof (gf_single_t);
scratch -= rs2 * sizeof (gf_single_t);
scratch -= rs2 * sizeof (int);
scratch -= rs * sizeof (gf_single_t);
#endif
}
static void
decode_block (gf_single_t *ptr, grub_size_t s,
gf_single_t *rptr, grub_size_t rs)
{
int i, j;
for (i = 0; i < SECTOR_SIZE; i++)
{
grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
gf_single_t m[ds + rr];
for (j = 0; j < (int) ds; j++)
m[j] = ptr[SECTOR_SIZE * j + i];
for (j = 0; j < (int) rr; j++)
m[j + ds] = rptr[SECTOR_SIZE * j + i];
rs_recover (m, ds, rr);
for (j = 0; j < (int) ds; j++)
ptr[SECTOR_SIZE * j + i] = m[j];
}
}
#if !defined (STANDALONE)
static void
encode_block (gf_single_t *ptr, grub_size_t s,
gf_single_t *rptr, grub_size_t rs)
{
int i, j;
for (i = 0; i < SECTOR_SIZE; i++)
{
grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
grub_size_t rr = (rs + SECTOR_SIZE - 1 - i) / SECTOR_SIZE;
gf_single_t m[ds + rr];
for (j = 0; j < ds; j++)
m[j] = ptr[SECTOR_SIZE * j + i];
rs_encode (m, ds, rr);
for (j = 0; j < rr; j++)
rptr[SECTOR_SIZE * j + i] = m[j + ds];
}
}
#endif
#if !defined (STANDALONE)
void
grub_reed_solomon_add_redundancy (void *buffer, grub_size_t data_size,
grub_size_t redundancy)
{
grub_size_t s = data_size;
grub_size_t rs = redundancy;
gf_single_t *ptr = buffer;
gf_single_t *rptr = ptr + s;
while (s > 0)
{
grub_size_t tt;
grub_size_t cs, crs;
cs = s;
crs = rs;
tt = cs + crs;
if (tt > MAX_BLOCK_SIZE)
{
cs = (cs * MAX_BLOCK_SIZE) / tt;
crs = (crs * MAX_BLOCK_SIZE) / tt;
}
encode_block (ptr, cs, rptr, crs);
ptr += cs;
rptr += crs;
s -= cs;
rs -= crs;
}
}
#endif
void
grub_reed_solomon_recover (void *ptr_, grub_size_t s, grub_size_t rs)
{
gf_single_t *ptr = ptr_;
gf_single_t *rptr = ptr + s;
#if defined (STANDALONE)
init_inverts ();
#endif
while (s > 0)
{
grub_size_t tt;
grub_size_t cs, crs;
cs = s;
crs = rs;
tt = cs + crs;
if (tt > MAX_BLOCK_SIZE)
{
cs = cs * MAX_BLOCK_SIZE / tt;
crs = crs * MAX_BLOCK_SIZE / tt;
}
decode_block (ptr, cs, rptr, crs);
ptr += cs;
rptr += crs;
s -= cs;
rs -= crs;
}
}
#ifdef TEST
int
main (int argc, char **argv)
{
FILE *in, *out;
grub_size_t s, rs;
char *buf;
#ifdef STANDALONE
scratch = xmalloc (1048576);
#endif
#ifndef STANDALONE
init_inverts ();
#endif
in = fopen ("tst.bin", "rb");
if (!in)
return 1;
fseek (in, 0, SEEK_END);
s = ftell (in);
fseek (in, 0, SEEK_SET);
rs = 1024 * ((s + MAX_BLOCK_SIZE - 1) / (MAX_BLOCK_SIZE - 1024));
buf = xmalloc (s + rs + SECTOR_SIZE);
fread (buf, 1, s, in);
s = 0x5fbb;
rs = 0x6af9;
#if 0
grub_reed_solomon_add_redundancy (buf, s, rs);
out = fopen ("tst_rs.bin", "wb");
fwrite (buf, 1, s + rs, out);
fclose (out);
grub_memset (buf + 512 * 15, 0, 512);
out = fopen ("tst_dam.bin", "wb");
fwrite (buf, 1, s + rs, out);
fclose (out);
#endif
s = 0x5fbb;
rs = 0x6af9;
grub_reed_solomon_recover (buf, s, rs);
out = fopen ("tst_rec.bin", "wb");
fwrite (buf, 1, s, out);
fclose (out);
return 0;
}
#endif

View file

@ -40,7 +40,6 @@ struct grub_relocator_subchunk
#endif
} type;
grub_mm_region_t reg;
grub_mm_header_t head;
grub_phys_addr_t start;
grub_size_t size;
grub_size_t pre_size;
@ -355,11 +354,11 @@ free_subchunk (const struct grub_relocator_subchunk *subchu)
}
case CHUNK_TYPE_IN_REGION:
{
grub_mm_header_t h = (grub_mm_header_t) ALIGN_DOWN ((grub_addr_t) subchu->head,
grub_mm_header_t h = (grub_mm_header_t) ALIGN_DOWN ((grub_addr_t) subchu->start,
GRUB_MM_ALIGN);
h->size
= ((subchu->start + subchu->size + GRUB_MM_ALIGN - 1) / GRUB_MM_ALIGN)
- (subchu->start / GRUB_MM_ALIGN);
- (subchu->start / GRUB_MM_ALIGN) - 1;
h->next = h;
h->magic = GRUB_MM_ALLOC_MAGIC;
grub_free (h + 1);
@ -579,21 +578,17 @@ malloc_in_range (struct grub_relocator *rel,
for (ra = &base_saved, r = *ra; r; ra = &(r->next), r = *ra)
{
int pre_added = 0;
pa = r->first;
p = pa->next;
if (p->magic == GRUB_MM_ALLOC_MAGIC)
continue;
do
{
grub_dprintf ("relocator", "free block %p+0x%lx\n",
p, (unsigned long) p->size);
if (p->magic != GRUB_MM_FREE_MAGIC)
grub_fatal (__FILE__":%d free magic broken at %p (0x%x)\n",
__LINE__, p, p->magic);
if (p == (grub_mm_header_t) (r + 1))
{
pre_added = 1;
events[N].type = REG_BEG_START;
events[N].pos = grub_vtop (r) - r->pre_size;
events[N].reg = r;
@ -669,7 +664,6 @@ malloc_in_range (struct grub_relocator *rel,
const int nlefto = 0;
#endif
grub_addr_t starta = 0;
int numstarted;
for (j = from_low_priv ? 0 : N - 1; from_low_priv ? j < N : (j + 1);
from_low_priv ? j++ : j--)
{
@ -727,11 +721,8 @@ malloc_in_range (struct grub_relocator *rel,
isinsideafter = (!ncollisions && (nstarted || ((nlefto || nstartedfw)
&& !nblockfw)));
if (!isinsidebefore && isinsideafter)
{
starta = from_low_priv ? ALIGN_UP (events[j].pos, align)
: ALIGN_DOWN (events[j].pos - size, align) + size;
numstarted = j;
}
starta = from_low_priv ? ALIGN_UP (events[j].pos, align)
: ALIGN_DOWN (events[j].pos - size, align) + size;
if (isinsidebefore && !isinsideafter && from_low_priv)
{
target = starta;
@ -979,7 +970,6 @@ malloc_in_range (struct grub_relocator *rel,
|| typepre == CHUNK_TYPE_IN_REGION)
{
curschu->reg = events[last_start].reg;
curschu->head = events[last_start].head;
curschu->pre_size = alloc_start - events[j - 1].pos;
}
if (!oom && (typepre == CHUNK_TYPE_REGION_START
@ -1504,7 +1494,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr,
grub_relocator_align,
rel->relocators_size, &movers_chunk, 1, 1))
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
rels = rels0 = grub_map_memory (movers_chunk.src, movers_chunk.size);
movers_chunk.srcv = rels = rels0
= grub_map_memory (movers_chunk.src, movers_chunk.size);
if (relsize)
*relsize = rel->relocators_size;

View file

@ -520,9 +520,18 @@ enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
return s->ret;
}
#ifdef GRUB_EMBED_DECOMPRESSOR
struct xz_dec_bcj bcj;
#endif
struct xz_dec_bcj * xz_dec_bcj_create(bool single_call)
{
struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
struct xz_dec_bcj *s;
#ifdef GRUB_EMBED_DECOMPRESSOR
s = &bcj;
#else
s = kmalloc(sizeof(*s), GFP_KERNEL);
#endif
if (s != NULL)
s->single_call = single_call;

View file

@ -1100,10 +1100,16 @@ enum xz_ret xz_dec_lzma2_run(
return XZ_OK;
}
#ifdef GRUB_EMBED_DECOMPRESSOR
#include <grub/decompressor.h>
static struct xz_dec_lzma2 lzma2;
#endif
struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
{
struct xz_dec_lzma2 *s;
#ifndef GRUB_EMBED_DECOMPRESSOR
/* Maximum supported dictionary by this implementation is 3 GiB. */
if (dict_max > ((uint32_t)3 << 30))
return NULL;
@ -1120,6 +1126,11 @@ struct xz_dec_lzma2 * xz_dec_lzma2_create(uint32_t dict_max)
}
}
#else
s = &lzma2;
s->dict.buf = grub_decompressor_scratch;
#endif
s->dict.allocated = dict_max;
return s;
@ -1135,6 +1146,7 @@ enum xz_ret xz_dec_lzma2_reset(
s->dict.size = 2 + (props & 1);
s->dict.size <<= (props >> 1) + 11;
#ifndef GRUB_EMBED_DECOMPRESSOR
if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size)
{
/* enlarge dictionary buffer */
@ -1146,7 +1158,7 @@ enum xz_ret xz_dec_lzma2_reset(
s->dict.buf = newdict;
s->dict.allocated = s->dict.size;
}
#endif
s->dict.end = s->dict.size;
s->lzma.len = 0;
@ -1159,10 +1171,12 @@ enum xz_ret xz_dec_lzma2_reset(
return XZ_OK;
}
void xz_dec_lzma2_end(struct xz_dec_lzma2 *s)
void xz_dec_lzma2_end(struct xz_dec_lzma2 *s __attribute__ ((unused)))
{
#ifndef GRUB_EMBED_DECOMPRESSOR
if (s->dict.allocated > 0)
vfree(s->dict.buf);
kfree(s);
#endif
}

View file

@ -31,7 +31,9 @@
struct xz_dec_hash {
vli_type unpadded;
vli_type uncompressed;
#ifndef GRUB_EMBED_DECOMPRESSOR
uint8_t *crc32_context;
#endif
};
struct xz_dec {
@ -247,9 +249,11 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
> s->block_header.uncompressed)
return XZ_DATA_ERROR;
#ifndef GRUB_EMBED_DECOMPRESSOR
if (s->has_crc32)
GRUB_MD_CRC32->write(s->crc32_context,b->out + s->out_start,
b->out_pos - s->out_start);
#endif
if (ret == XZ_STREAM_END) {
if (s->block_header.compressed != VLI_UNKNOWN
@ -269,8 +273,10 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
s->block.hash.uncompressed += s->block.uncompressed;
#ifndef GRUB_EMBED_DECOMPRESSOR
GRUB_MD_CRC32->write(s->block.hash.crc32_context,
(const uint8_t *)&s->block.hash, 2 * sizeof(vli_type));
#endif
++s->block.count;
}
@ -283,7 +289,9 @@ static void index_update(struct xz_dec *s, const struct xz_buf *b)
{
size_t in_used = b->in_pos - s->in_start;
s->index.size += in_used;
#ifndef GRUB_EMBED_DECOMPRESSOR
GRUB_MD_CRC32->write(s->crc32_context,b->in + s->in_start, in_used);
#endif
}
/*
@ -328,8 +336,10 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
case SEQ_INDEX_UNCOMPRESSED:
s->index.hash.uncompressed += s->vli;
#ifndef GRUB_EMBED_DECOMPRESSOR
GRUB_MD_CRC32->write(s->index.hash.crc32_context,
(const uint8_t *)&s->index.hash, 2 * sizeof(vli_type));
#endif
--s->index.count;
s->index.sequence = SEQ_INDEX_UNPADDED;
@ -346,24 +356,30 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
*/
static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
{
#ifndef GRUB_EMBED_DECOMPRESSOR
if(s->crc32_temp == 0)
{
GRUB_MD_CRC32->final(s->crc32_context);
s->crc32_temp = get_unaligned_be32(GRUB_MD_CRC32->read(s->crc32_context));
}
#endif
do {
if (b->in_pos == b->in_size)
return XZ_OK;
#ifndef GRUB_EMBED_DECOMPRESSOR
if (((s->crc32_temp >> s->pos) & 0xFF) != b->in[b->in_pos++])
return XZ_DATA_ERROR;
#endif
s->pos += 8;
} while (s->pos < 32);
#ifndef GRUB_EMBED_DECOMPRESSOR
GRUB_MD_CRC32->init(s->crc32_context);
#endif
s->crc32_temp = 0;
s->pos = 0;
@ -376,6 +392,7 @@ static enum xz_ret dec_stream_header(struct xz_dec *s)
if (! memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE))
return XZ_FORMAT_ERROR;
#ifndef GRUB_EMBED_DECOMPRESSOR
uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
GRUB_MD_CRC32->init(crc32_context);
@ -387,6 +404,7 @@ static enum xz_ret dec_stream_header(struct xz_dec *s)
if(resultcrc != readcrc)
return XZ_DATA_ERROR;
#endif
/*
* Decode the Stream Flags field. Of integrity checks, we support
@ -407,6 +425,7 @@ static enum xz_ret dec_stream_footer(struct xz_dec *s)
if (! memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE))
return XZ_DATA_ERROR;
#ifndef GRUB_EMBED_DECOMPRESSOR
uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
GRUB_MD_CRC32->init(crc32_context);
@ -418,6 +437,7 @@ static enum xz_ret dec_stream_footer(struct xz_dec *s)
if(resultcrc != readcrc)
return XZ_DATA_ERROR;
#endif
/*
* Validate Backward Size. Note that we never added the size of the
@ -447,7 +467,7 @@ static enum xz_ret dec_block_header(struct xz_dec *s)
* eight bytes so this is safe.
*/
s->temp.size -= 4;
#ifndef GRUB_EMBED_DECOMPRESSOR
uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
GRUB_MD_CRC32->init(crc32_context);
@ -459,6 +479,7 @@ static enum xz_ret dec_block_header(struct xz_dec *s)
if (resultcrc != readcrc)
return XZ_DATA_ERROR;
#endif
s->temp.pos = 2;
@ -669,6 +690,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
/* Finish the CRC32 value and Index size. */
index_update(s, b);
#ifndef GRUB_EMBED_DECOMPRESSOR
/* Compare the hashes to validate the Index field. */
GRUB_MD_CRC32->final(s->block.hash.crc32_context);
GRUB_MD_CRC32->final(s->index.hash.crc32_context);
@ -681,6 +703,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
{
return XZ_DATA_ERROR;
}
#endif
s->sequence = SEQ_INDEX_CRC32;
@ -764,12 +787,22 @@ enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b)
return ret;
}
#ifdef GRUB_EMBED_DECOMPRESSOR
struct xz_dec decoder;
#endif
struct xz_dec * xz_dec_init(uint32_t dict_max)
{
struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL);
struct xz_dec *s;
#ifdef GRUB_EMBED_DECOMPRESSOR
s = &decoder;
#else
s = kmalloc(sizeof(*s), GFP_KERNEL);
if (s == NULL)
return NULL;
#endif
#ifndef GRUB_EMBED_DECOMPRESSOR
/* prepare CRC32 calculators */
if(GRUB_MD_CRC32 == NULL)
{
@ -803,10 +836,11 @@ struct xz_dec * xz_dec_init(uint32_t dict_max)
GRUB_MD_CRC32->init(s->crc32_context);
s->crc32_temp = 0;
GRUB_MD_CRC32->init(s->index.hash.crc32_context);
GRUB_MD_CRC32->init(s->block.hash.crc32_context);
#endif
s->crc32_temp = 0;
s->single_call = dict_max == 0;
@ -828,7 +862,9 @@ error_lzma2:
xz_dec_bcj_end(s->bcj);
error_bcj:
#endif
#ifndef GRUB_EMBED_DECOMPRESSOR
kfree(s);
#endif
return NULL;
}
@ -839,34 +875,45 @@ void xz_dec_reset(struct xz_dec *s)
s->pos = 0;
{
#ifndef GRUB_EMBED_DECOMPRESSOR
uint8_t *t;
t = s->block.hash.crc32_context;
#endif
memzero(&s->block, sizeof(s->block));
#ifndef GRUB_EMBED_DECOMPRESSOR
s->block.hash.crc32_context = t;
t = s->index.hash.crc32_context;
#endif
memzero(&s->index, sizeof(s->index));
#ifndef GRUB_EMBED_DECOMPRESSOR
s->index.hash.crc32_context = t;
#endif
}
s->temp.pos = 0;
s->temp.size = STREAM_HEADER_SIZE;
#ifndef GRUB_EMBED_DECOMPRESSOR
GRUB_MD_CRC32->init(s->crc32_context);
s->crc32_temp = 0;
GRUB_MD_CRC32->init(s->index.hash.crc32_context);
GRUB_MD_CRC32->init(s->block.hash.crc32_context);
#endif
s->crc32_temp = 0;
}
void xz_dec_end(struct xz_dec *s)
{
if (s != NULL) {
xz_dec_lzma2_end(s->lzma2);
#ifndef GRUB_EMBED_DECOMPRESSOR
kfree(s->index.hash.crc32_context);
kfree(s->block.hash.crc32_context);
kfree(s->crc32_context);
#endif
#ifdef XZ_DEC_BCJ
xz_dec_bcj_end(s->bcj);
#endif
#ifndef GRUB_EMBED_DECOMPRESSOR
kfree(s);
#endif
}
}

View file

@ -1559,6 +1559,9 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
grub_memset (&serial, 0, sizeof (serial));
grub_strcpy (serial.devname, "com");
serial.addr = grub_ns8250_hw_get_port (0);
serial.speed = 9600;
if (ctxt->state[NETBSD_SERIAL_ARG].arg)
{
ptr = ctxt->state[NETBSD_SERIAL_ARG].arg;
@ -1581,7 +1584,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
return grub_errno;
}
}
grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial));
}
else

View file

@ -396,10 +396,8 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator,
Elf_Shdr *s, *symsh, *strsh;
char *shdr;
unsigned symsize, strsize;
Elf_Sym *sym;
void *sym_chunk;
grub_uint8_t *curload;
const char *str;
grub_size_t chunk_size;
Elf_Ehdr *e2;
struct grub_netbsd_btinfo_symtab symtab;
@ -473,7 +471,6 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator,
if (grub_file_seek (file, symsh->sh_offset) == (grub_off_t) -1)
return grub_errno;
sym = (Elf_Sym *) curload;
if (grub_file_read (file, curload, symsize) != (grub_ssize_t) symsize)
{
if (! grub_errno)
@ -484,7 +481,6 @@ SUFFIX (grub_netbsd_load_elf_meta) (struct grub_relocator *relocator,
if (grub_file_seek (file, strsh->sh_offset) == (grub_off_t) -1)
return grub_errno;
str = (char *) curload;
if (grub_file_read (file, curload, strsize) != (grub_ssize_t) strsize)
{
if (! grub_errno)

View file

@ -53,7 +53,7 @@ static void
fill_bsd64_pagetable (grub_uint8_t *src, grub_addr_t target)
{
grub_uint64_t *pt2, *pt3, *pt4;
grub_addr_t pt2t, pt3t, pt4t;
grub_addr_t pt2t, pt3t;
int i;
#define PG_V 0x001
@ -65,7 +65,6 @@ fill_bsd64_pagetable (grub_uint8_t *src, grub_addr_t target)
pt3 = (grub_uint64_t *) (src + 4096);
pt2 = (grub_uint64_t *) (src + 8192);
pt4t = target;
pt3t = target + 4096;
pt2t = target + 8192;

View file

@ -41,7 +41,7 @@
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#define HAS_VGA_TEXT 0
#define DEFAULT_VIDEO_MODE "800x600"
#define DEFAULT_VIDEO_MODE "auto"
#elif defined (GRUB_MACHINE_IEEE1275)
#include <grub/ieee1275/ieee1275.h>
#define HAS_VGA_TEXT 0

View file

@ -188,6 +188,10 @@ grub_multiboot_load (grub_file_t file)
return err;
}
#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT
#include <grub/i386/pc/vbe.h>
#endif
static grub_size_t
grub_multiboot_get_mbi_size (void)
{
@ -200,7 +204,7 @@ grub_multiboot_get_mbi_size (void)
+ grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)
+ elf_sec_entsize * elf_sec_num
+ 256 * sizeof (struct multiboot_color)
#if GRUB_MACHINE_HAS_VBE
#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT
+ sizeof (struct grub_vbe_info_block)
+ sizeof (struct grub_vbe_mode_info_block)
#endif
@ -260,15 +264,17 @@ grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry)
grub_mmap_iterate (hook);
}
#if GRUB_MACHINE_HAS_VBE
#if GRUB_MACHINE_HAS_VBE || GRUB_MACHINE_HAS_VGA_TEXT
static grub_err_t
fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig,
grub_uint32_t ptrdest, int fill_generic)
{
grub_vbe_status_t status;
grub_uint32_t vbe_mode;
void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
struct grub_vbe_mode_info_block *mode_info;
#if GRUB_MACHINE_HAS_VBE
grub_vbe_status_t status;
void *scratch = (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
status = grub_vbe_bios_get_controller_info (scratch);
if (status != GRUB_VBE_STATUS_OK)
@ -278,11 +284,18 @@ fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig,
grub_memcpy (ptrorig, scratch, sizeof (struct grub_vbe_info_block));
ptrorig += sizeof (struct grub_vbe_info_block);
ptrdest += sizeof (struct grub_vbe_info_block);
#else
mbi->vbe_control_info = 0;
#endif
#if GRUB_MACHINE_HAS_VBE
status = grub_vbe_bios_get_mode (scratch);
vbe_mode = *(grub_uint32_t *) scratch;
if (status != GRUB_VBE_STATUS_OK)
return grub_error (GRUB_ERR_IO, "can't get VBE mode");
#else
vbe_mode = 3;
#endif
mbi->vbe_mode = vbe_mode;
mode_info = (struct grub_vbe_mode_info_block *) ptrorig;
@ -297,18 +310,22 @@ fill_vbe_info (struct multiboot_info *mbi, grub_uint8_t *ptrorig,
}
else
{
#if GRUB_MACHINE_HAS_VBE
status = grub_vbe_bios_get_mode_info (vbe_mode, scratch);
if (status != GRUB_VBE_STATUS_OK)
return grub_error (GRUB_ERR_IO, "can't get mode info");
grub_memcpy (mode_info, scratch,
sizeof (struct grub_vbe_mode_info_block));
#endif
}
ptrorig += sizeof (struct grub_vbe_mode_info_block);
ptrdest += sizeof (struct grub_vbe_mode_info_block);
#if GRUB_MACHINE_HAS_VBE
grub_vbe_bios_get_pm_interface (&mbi->vbe_interface_seg,
&mbi->vbe_interface_off,
&mbi->vbe_interface_len);
#endif
mbi->flags |= MULTIBOOT_INFO_VBE_INFO;

View file

@ -705,7 +705,7 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
}
}
#if defined (GRUB_MACHINE_EFI) && __x86_64__
#if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
{
struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi64 *) ptrorig;
tag->type = MULTIBOOT_TAG_TYPE_EFI64;
@ -715,9 +715,9 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
}
#endif
#if defined (GRUB_MACHINE_EFI) && __i386_
#if defined (GRUB_MACHINE_EFI) && defined (__i386__)
{
struct multiboot_tag_efi64 *tag = (struct multiboot_tag_efi32 *) ptrorig;
struct multiboot_tag_efi32 *tag = (struct multiboot_tag_efi32 *) ptrorig;
tag->type = MULTIBOOT_TAG_TYPE_EFI32;
tag->size = sizeof (*tag);
tag->pointer = (grub_addr_t) grub_efi_system_table;

View file

@ -201,7 +201,6 @@ grub_auth_check_authentication (const char *userlist)
{
char login[1024];
struct grub_auth_user *cur = NULL;
grub_err_t err;
static unsigned long punishment_delay = 1;
char entered[GRUB_AUTH_MAX_PASSLEN];
struct grub_auth_user *user;
@ -233,7 +232,7 @@ grub_auth_check_authentication (const char *userlist)
if (!cur || ! cur->callback)
goto access_denied;
err = cur->callback (login, entered, cur->arg);
cur->callback (login, entered, cur->arg);
if (is_authenticated (userlist))
{
punishment_delay = 1;

View file

@ -376,8 +376,8 @@ read_terminal_list (const char *prefix)
if (! cur->modname)
{
grub_errno = GRUB_ERR_NONE;
grub_free (cur);
grub_free (cur->name);
grub_free (cur);
continue;
}
cur->next = *target;

View file

@ -124,9 +124,9 @@ gpt_partition_map_iterate (grub_disk_t disk,
#ifdef GRUB_UTIL
static grub_err_t
gpt_partition_map_embed (struct grub_disk *disk, unsigned int nsectors,
gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
grub_embed_type_t embed_type,
grub_disk_addr_t *sectors)
grub_disk_addr_t **sectors)
{
grub_disk_addr_t start = 0, len = 0;
unsigned i;
@ -168,13 +168,17 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int nsectors,
"This GPT partition label has no BIOS Boot Partition;"
" embedding won't be possible!");
if (len < nsectors)
if (len < *nsectors)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Your BIOS Boot Partition is too small;"
" embedding won't be possible!");
for (i = 0; i < nsectors; i++)
sectors[i] = start + i;
*nsectors = len;
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
if (!*sectors)
return grub_errno;
for (i = 0; i < *nsectors; i++)
(*sectors)[i] = start + i;
return GRUB_ERR_NONE;
}

View file

@ -145,9 +145,9 @@ grub_partition_msdos_iterate (grub_disk_t disk,
#ifdef GRUB_UTIL
static grub_err_t
pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors,
pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
grub_embed_type_t embed_type,
grub_disk_addr_t *sectors)
grub_disk_addr_t **sectors)
{
grub_disk_addr_t end = ~0ULL;
struct grub_msdos_partition_mbr mbr;
@ -232,11 +232,15 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors,
break;
}
if (end >= nsectors + 1)
if (end >= *nsectors + 1)
{
int i;
for (i = 0; i < nsectors; i++)
sectors[i] = 1 + i;
*nsectors = end - 1;
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
if (!*sectors)
return grub_errno;
for (i = 0; i < *nsectors; i++)
(*sectors)[i] = 1 + i;
return GRUB_ERR_NONE;
}
@ -245,7 +249,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int nsectors,
"This msdos-style partition label has no "
"post-MBR gap; embedding won't be possible!");
if (nsectors > 62)
if (*nsectors > 62)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Your core.img is unusually large. "
"It won't fit in the embedding area.");

View file

@ -513,6 +513,7 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
new_scope.argv.argc = argc;
new_scope.argv.args = args;
new_scope.flags = 0;
old_scope = scope;
scope = &new_scope;

View file

@ -17,6 +17,8 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/parser.h>
#include <grub/misc.h>
#include <grub/mm.h>

View file

@ -71,6 +71,8 @@ static void copy_string (struct grub_parser_param *, const char *,
%top{
#include <config.h>
#include <sys/types.h>
typedef size_t yy_size_t;

View file

@ -24,10 +24,6 @@
#include <grub/efi/api.h>
#include <grub/efi/console.h>
static const grub_uint8_t
grub_console_standard_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_YELLOW,
GRUB_EFI_BACKGROUND_BLACK);
static grub_uint32_t
map_char (grub_uint32_t c)
{
@ -208,13 +204,14 @@ grub_console_setcolorstate (struct grub_term_output *term,
switch (state) {
case GRUB_TERM_COLOR_STANDARD:
efi_call_2 (o->set_attributes, o, grub_console_standard_color);
efi_call_2 (o->set_attributes, o, GRUB_TERM_DEFAULT_STANDARD_COLOR
& 0x7f);
break;
case GRUB_TERM_COLOR_NORMAL:
efi_call_2 (o->set_attributes, o, term->normal_color);
efi_call_2 (o->set_attributes, o, term->normal_color & 0x7f);
break;
case GRUB_TERM_COLOR_HIGHLIGHT:
efi_call_2 (o->set_attributes, o, term->highlight_color);
efi_call_2 (o->set_attributes, o, term->highlight_color & 0x7f);
break;
default:
break;
@ -266,10 +263,8 @@ static struct grub_term_output grub_console_term_output =
.cls = grub_console_cls,
.setcolorstate = grub_console_setcolorstate,
.setcursor = grub_console_setcursor,
.normal_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_LIGHTGRAY,
GRUB_EFI_BACKGROUND_BLACK),
.highlight_color = GRUB_EFI_TEXT_ATTR (GRUB_EFI_BLACK,
GRUB_EFI_BACKGROUND_LIGHTGRAY),
.normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
.highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
.flags = GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS
};

View file

@ -90,7 +90,7 @@ grub_ofconsole_dimensions (void)
if (! grub_ieee1275_get_property (options, "screen-#columns",
val, lval, 0))
grub_ofconsole_terminfo_output->width
grub_ofconsole_terminfo_output.width
= (grub_uint8_t) grub_strtoul (val, 0, 10);
}
if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval)
@ -99,16 +99,16 @@ grub_ofconsole_dimensions (void)
char val[lval];
if (! grub_ieee1275_get_property (options, "screen-#rows",
val, lval, 0))
grub_ofconsole_terminfo_output->height
grub_ofconsole_terminfo_output.height
= (grub_uint8_t) grub_strtoul (val, 0, 10);
}
}
/* Use a small console by default. */
if (! grub_ofconsole_terminfo_output->width)
grub_ofconsole_terminfo_output->width = 80;
if (! grub_ofconsole_terminfo_output->height)
grub_ofconsole_terminfo_output->height = 24;
if (! grub_ofconsole_terminfo_output.width)
grub_ofconsole_terminfo_output.width = 80;
if (! grub_ofconsole_terminfo_output.height)
grub_ofconsole_terminfo_output.height = 24;
}
static void

View file

@ -23,6 +23,7 @@
#include <grub/misc.h>
#include <grub/cpu/io.h>
#include <grub/mm.h>
#include <grub/time.h>
#ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/memory.h>
@ -90,6 +91,8 @@ do_real_config (struct grub_serial_port *port)
if (port->configured)
return;
port->broken = 0;
divisor = serial_get_divisor (port->config.speed);
/* Turn off the interrupt. */
@ -145,18 +148,30 @@ serial_hw_fetch (struct grub_serial_port *port)
static void
serial_hw_put (struct grub_serial_port *port, const int c)
{
unsigned int timeout = 100000;
grub_uint64_t endtime;
do_real_config (port);
if (port->broken > 5)
endtime = grub_get_time_ms ();
else if (port->broken > 1)
endtime = grub_get_time_ms () + 50;
else
endtime = grub_get_time_ms () + 200;
/* Wait until the transmitter holding register is empty. */
while ((grub_inb (port->port + UART_LSR) & UART_EMPTY_TRANSMITTER) == 0)
{
if (--timeout == 0)
/* There is something wrong. But what can I do? */
return;
if (grub_get_time_ms () > endtime)
{
port->broken++;
/* There is something wrong. But what can I do? */
return;
}
}
if (port->broken)
port->broken--;
grub_outb (c, port->port + UART_TX);
}