mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-29 00:41:15 +00:00
experimental support for loongson mips64el uefi
This commit is contained in:
507
GRUB2/MOD_SRC/grub-2.04/grub-core/Makefile.am
Normal file
507
GRUB2/MOD_SRC/grub-2.04/grub-core/Makefile.am
Normal file
@@ -0,0 +1,507 @@
|
||||
AUTOMAKE_OPTIONS = subdir-objects -Wno-portability
|
||||
|
||||
DEPDIR=.deps-core
|
||||
|
||||
include $(top_srcdir)/conf/Makefile.common
|
||||
|
||||
CC=$(TARGET_CC)
|
||||
CPP=$(TARGET_CC)
|
||||
CCAS=$(TARGET_CC)
|
||||
RANLIB=$(TARGET_RANLIB)
|
||||
STRIP=$(TARGET_STRIP)
|
||||
|
||||
MACHO2IMG=$(top_builddir)/grub-macho2img
|
||||
|
||||
AM_CFLAGS = $(TARGET_CFLAGS)
|
||||
AM_LDFLAGS = $(TARGET_LDFLAGS)
|
||||
AM_CPPFLAGS = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT)
|
||||
AM_CCASFLAGS = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT)
|
||||
|
||||
CFLAGS_PROGRAM += $(CFLAGS_PLATFORM)
|
||||
LDFLAGS_PROGRAM += $(LDFLAGS_PLATFORM)
|
||||
CPPFLAGS_PROGRAM += $(CPPFLAGS_PLATFORM)
|
||||
CCASFLAGS_PROGRAM += $(CCASFLAGS_PLATFORM)
|
||||
|
||||
CFLAGS_LIBRARY += $(CFLAGS_PLATFORM) -fno-builtin
|
||||
CPPFLAGS_LIBRARY += $(CPPFLAGS_PLATFORM)
|
||||
CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM)
|
||||
|
||||
build-grub-pep2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=64 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pep2elf\" $^
|
||||
CLEANFILES += build-grub-pep2elf$(BUILD_EXEEXT)
|
||||
|
||||
build-grub-pe2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=32 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pe2elf\" $^
|
||||
CLEANFILES += build-grub-pe2elf$(BUILD_EXEEXT)
|
||||
|
||||
# gentrigtables
|
||||
gentrigtables$(BUILD_EXEEXT): gentrigtables.c
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $< $(BUILD_LIBM)
|
||||
CLEANFILES += gentrigtables$(BUILD_EXEEXT)
|
||||
|
||||
build-grub-module-verifier$(BUILD_EXEEXT): $(top_srcdir)/util/grub-module-verifier.c $(top_srcdir)/util/grub-module-verifier32.c $(top_srcdir)/util/grub-module-verifier64.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c
|
||||
$(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-module-verifier\" $^
|
||||
CLEANFILES += build-grub-module-verifier$(BUILD_EXEEXT)
|
||||
|
||||
# trigtables.c
|
||||
trigtables.c: gentrigtables$(BUILD_EXEEXT) gentrigtables.c $(top_srcdir)/configure.ac
|
||||
./gentrigtables$(BUILD_EXEEXT) > $@
|
||||
CLEANFILES += trigtables.c
|
||||
|
||||
# XXX Use Automake's LEX & YACC support
|
||||
grub_script.tab.h: script/parser.y
|
||||
$(YACC) -d -p grub_script_yy -b grub_script $<
|
||||
grub_script.tab.c: grub_script.tab.h
|
||||
CLEANFILES += grub_script.tab.c grub_script.tab.h
|
||||
|
||||
# For the lexer.
|
||||
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.h: $(srcdir)/lib/reed_solomon.c
|
||||
$(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 -ffreestanding
|
||||
|
||||
CLEANFILES += grub_script.yy.c grub_script.yy.h
|
||||
|
||||
include $(srcdir)/Makefile.core.am
|
||||
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h
|
||||
if COND_emu
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h
|
||||
else
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h
|
||||
endif
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
|
||||
|
||||
if COND_i386_pc
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
endif
|
||||
|
||||
if COND_i386_xen_pvh
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.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/loader.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h
|
||||
endif
|
||||
|
||||
if COND_i386_efi
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
|
||||
endif
|
||||
|
||||
if COND_i386_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_i386_multiboot
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_i386_qemu
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
endif
|
||||
|
||||
if COND_i386_ieee1275
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
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/tsc.h
|
||||
endif
|
||||
|
||||
if COND_i386_xen
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.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/loader.h
|
||||
endif
|
||||
|
||||
if COND_x86_64_xen
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/x86_64/xen/hypercall.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/loader.h
|
||||
endif
|
||||
|
||||
if COND_x86_64_efi
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
|
||||
endif
|
||||
|
||||
if COND_ia64_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h
|
||||
endif
|
||||
|
||||
if COND_mips_arc
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h
|
||||
endif
|
||||
|
||||
if COND_mips_qemu_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.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_mips_loongson
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
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_mips_qemu_mips
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
|
||||
endif
|
||||
|
||||
if COND_mips64_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loongson.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_arm_uboot
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/uboot.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/disk.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/arm/system.h
|
||||
endif
|
||||
|
||||
if COND_arm_coreboot
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h
|
||||
endif
|
||||
|
||||
if COND_arm_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_arm64_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_riscv32_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_riscv64_efi
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
|
||||
endif
|
||||
|
||||
if COND_emu
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h
|
||||
if COND_GRUB_EMU_SDL
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h
|
||||
endif
|
||||
if COND_GRUB_EMU_PCI
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libpciaccess.h
|
||||
endif
|
||||
endif
|
||||
|
||||
symlist.h: $(top_builddir)/config.h $(KERNEL_HEADER_FILES)
|
||||
@list='$^'; \
|
||||
for p in $$list; do \
|
||||
echo "#include <$$p>" >> $@ || (rm -f $@; exit 1); \
|
||||
done
|
||||
CLEANFILES += symlist.h
|
||||
BUILT_SOURCES += symlist.h
|
||||
|
||||
symlist.c: symlist.h gensymlist.sh
|
||||
$(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1)
|
||||
cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1)
|
||||
rm -f symlist.p
|
||||
CLEANFILES += symlist.c
|
||||
BUILT_SOURCES += symlist.c
|
||||
|
||||
if COND_HAVE_ASM_USCORE
|
||||
ASM_PREFIX=_
|
||||
else
|
||||
ASM_PREFIX=
|
||||
endif
|
||||
|
||||
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 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
|
||||
|
||||
if COND_emu
|
||||
kern/emu/grub_emu-main.$(OBJEXT):grub_emu_init.h
|
||||
grub_emu-grub_emu_init.$(OBJEXT):grub_emu_init.h
|
||||
kern/emu/grub_emu_dyn-main.$(OBJEXT):grub_emu_init.h
|
||||
grub_emu_dyn-grub_emu_init.$(OBJEXT):grub_emu_init.h
|
||||
|
||||
grub_emu_init.h: genemuinitheader.sh $(MODULE_FILES)
|
||||
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinitheader.sh $(TARGET_NM) > $@
|
||||
CLEANFILES += grub_emu_init.h
|
||||
|
||||
grub_emu_init.c: grub_emu_init.h genemuinit.sh $(MODULE_FILES)
|
||||
rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinit.sh $(TARGET_NM) > $@
|
||||
CLEANFILES += grub_emu_init.c
|
||||
endif
|
||||
|
||||
# List files
|
||||
|
||||
fs.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
if grep 'FS_LIST_MARKER' $$pp >/dev/null 2>&1; then \
|
||||
echo $$b; \
|
||||
fi; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += fs.lst
|
||||
CLEANFILES += fs.lst
|
||||
|
||||
command.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
|
||||
-e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \
|
||||
-e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += command.lst
|
||||
CLEANFILES += command.lst
|
||||
|
||||
partmap.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
if grep 'PARTMAP_LIST_MARKER' $$pp >/dev/null 2>&1; then \
|
||||
echo $$b; \
|
||||
fi; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += partmap.lst
|
||||
CLEANFILES += partmap.lst
|
||||
|
||||
terminal.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/INPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
|
||||
-e "/OUTPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += terminal.lst
|
||||
CLEANFILES += terminal.lst
|
||||
|
||||
fdt.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \
|
||||
-e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += fdt.lst
|
||||
CLEANFILES += fdt.lst
|
||||
|
||||
parttool.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
sed -n \
|
||||
-e "/PARTTOOL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += parttool.lst
|
||||
CLEANFILES += parttool.lst
|
||||
|
||||
video.lst: $(MARKER_FILES)
|
||||
(for pp in $^; do \
|
||||
b=`basename $$pp .marker`; \
|
||||
if grep 'VIDEO_LIST_MARKER' $$pp >/dev/null 2>&1; then \
|
||||
echo $$b; \
|
||||
fi; \
|
||||
done) | sort -u > $@
|
||||
platform_DATA += video.lst
|
||||
CLEANFILES += video.lst
|
||||
|
||||
# but, crypto.lst is simply copied
|
||||
crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst
|
||||
cp $^ $@
|
||||
platform_DATA += crypto.lst
|
||||
CLEANFILES += crypto.lst
|
||||
|
||||
syminfo.lst: gensyminfo.sh kernel_syms.lst $(MODULE_FILES)
|
||||
cat kernel_syms.lst > $@.new
|
||||
for m in $(MODULE_FILES); do \
|
||||
sh $< $$m >> $@.new || exit 1; \
|
||||
done
|
||||
mv $@.new $@
|
||||
|
||||
# generate global module dependencies list
|
||||
moddep.lst: syminfo.lst genmoddep.awk video.lst
|
||||
cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1)
|
||||
platform_DATA += moddep.lst
|
||||
CLEANFILES += config.log syminfo.lst moddep.lst
|
||||
|
||||
$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT)
|
||||
TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@
|
||||
platform_DATA += $(MOD_FILES)
|
||||
platform_DATA += modinfo.sh
|
||||
CLEANFILES += $(MOD_FILES)
|
||||
|
||||
if COND_ENABLE_EFIEMU
|
||||
efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF)
|
||||
-rm -f $@
|
||||
-rm -f $@.bin
|
||||
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m32 -Wall -Werror -nostdlib -static -O2 -c -o $@.bin $<
|
||||
if test "x$(TARGET_APPLE_LINKER)" = x1; then \
|
||||
$(TARGET_OBJCONV) -felf32 -nu -nd $@.bin $@ || exit 1; \
|
||||
rm -f $@.bin ; \
|
||||
elif test ! -z "$(TARGET_OBJ2ELF)"; then \
|
||||
$(TARGET_OBJ2ELF) $@.bin || (rm -f $@.bin; exit 1); \
|
||||
mv $@.bin $@ ; \
|
||||
else \
|
||||
mv $@.bin $@ ; \
|
||||
fi
|
||||
|
||||
# Link format -arch,x86_64 means Apple linker
|
||||
efiemu64_c.o: efiemu/runtime/efiemu.c
|
||||
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -nostdlib -Wall -Werror -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
|
||||
|
||||
efiemu64_s.o: efiemu/runtime/efiemu.S
|
||||
$(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -Wall -Werror -nostdlib -O2 -mcmodel=large -mno-red-zone -c -o $@ $<
|
||||
|
||||
efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELEF)
|
||||
-rm -f $@
|
||||
-rm -f $@.bin
|
||||
$(TARGET_CC) -m64 $(EFIEMU64_LINK_FORMAT) -nostdlib -static -Wl,-r -o $@.bin $^
|
||||
if test "x$(EFIEMU64_LINK_FORMAT)" = x-arch,x86_64; then \
|
||||
$(TARGET_OBJCONV) -felf64 -nu -nd $@.bin $@ || exit 1; \
|
||||
rm -f $@.bin; \
|
||||
else \
|
||||
mv $@.bin $@ ; \
|
||||
fi
|
||||
|
||||
platform_DATA += efiemu32.o efiemu64.o
|
||||
CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
|
||||
endif
|
||||
|
||||
windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows
|
||||
windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA)
|
||||
test -d $(windowsdir)/$(target_cpu)-$(platform) || mkdir $(windowsdir)/$(target_cpu)-$(platform)
|
||||
for x in $(platform_DATA); do \
|
||||
cp -fp $$x $(windowsdir)/$(target_cpu)-$(platform)/$$x; \
|
||||
done
|
@@ -100,6 +100,10 @@ kernel = {
|
||||
emu_cppflags = '$(CPPFLAGS_GNULIB)';
|
||||
arm_uboot_ldflags = '-Wl,-r,-d';
|
||||
arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
|
||||
|
||||
mips64_efi_ldflags = '-Wl,-r,-d';
|
||||
mips64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame -R .MIPS.abiflags';
|
||||
|
||||
arm_coreboot_ldflags = '-Wl,-r,-d';
|
||||
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
|
||||
|
||||
@@ -114,6 +118,7 @@ kernel = {
|
||||
i386_coreboot_startup = kern/i386/coreboot/startup.S;
|
||||
i386_multiboot_startup = kern/i386/coreboot/startup.S;
|
||||
mips_startup = kern/mips/startup.S;
|
||||
mips64_efi_startup = kern/mips64/efi/startup.S;
|
||||
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
|
||||
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
|
||||
arm_uboot_startup = kern/arm/startup.S;
|
||||
@@ -310,6 +315,15 @@ kernel = {
|
||||
extra_dist = video/sis315_init.c;
|
||||
mips_loongson = commands/keylayouts.c;
|
||||
|
||||
mips64 = kern/mips64/init.c;
|
||||
mips64 = kern/mips64/dl.c;
|
||||
mips64 = kern/mips64/cache.S;
|
||||
mips64 = kern/generic/rtc_get_time_ms.c;
|
||||
mips64_efi = kern/mips64/efi/init.c;
|
||||
mips64_efi = kern/mips64/efi/loongson.c;
|
||||
mips64_efi = lib/mips64/efi/loongson.c;
|
||||
mips64_efi = lib/mips64/efi/loongson_asm.S;
|
||||
|
||||
powerpc_ieee1275 = kern/powerpc/cache.S;
|
||||
powerpc_ieee1275 = kern/powerpc/dl.c;
|
||||
powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
|
||||
@@ -828,6 +842,7 @@ module = {
|
||||
enable = sparc64_ieee1275;
|
||||
enable = powerpc_ieee1275;
|
||||
enable = mips_arc;
|
||||
enable = mips64_efi;
|
||||
enable = ia64_efi;
|
||||
enable = arm_efi;
|
||||
enable = arm64_efi;
|
||||
@@ -1667,6 +1682,8 @@ module = {
|
||||
efi = lib/efi/relocator.c;
|
||||
mips = lib/mips/relocator_asm.S;
|
||||
mips = lib/mips/relocator.c;
|
||||
mips64 = lib/mips64/relocator_asm.S;
|
||||
mips64 = lib/mips64/relocator.c;
|
||||
powerpc = lib/powerpc/relocator_asm.S;
|
||||
powerpc = lib/powerpc/relocator.c;
|
||||
xen = lib/xen/relocator.c;
|
||||
@@ -1679,6 +1696,7 @@ module = {
|
||||
extra_dist = kern/powerpc/cache_flush.S;
|
||||
|
||||
enable = mips;
|
||||
enable = mips64;
|
||||
enable = powerpc;
|
||||
enable = x86;
|
||||
enable = i386_xen_pvh;
|
||||
@@ -1809,6 +1827,7 @@ module = {
|
||||
i386_pc = lib/i386/pc/vesa_modes_table.c;
|
||||
i386_xen_pvh = lib/i386/pc/vesa_modes_table.c;
|
||||
mips = loader/mips/linux.c;
|
||||
mips64 = loader/mips64/linux.c;
|
||||
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
|
||||
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
|
||||
ia64_efi = loader/ia64/efi/linux.c;
|
||||
@@ -1915,6 +1934,7 @@ module = {
|
||||
enable = riscv32_efi;
|
||||
enable = riscv64_efi;
|
||||
enable = mips;
|
||||
enable = mips64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
672
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/efi/mm.c
Normal file
672
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/efi/mm.c
Normal file
@@ -0,0 +1,672 @@
|
||||
/* mm.c - generic EFI memory management */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2006,2007,2008,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/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/cpu/efi/memory.h>
|
||||
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
#include <grub/pci.h>
|
||||
#endif
|
||||
|
||||
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
|
||||
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
|
||||
|
||||
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
||||
#define BYTES_TO_PAGES_DOWN(bytes) ((bytes) >> 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
|
||||
|
||||
/* The minimum and maximum heap size for GRUB itself. */
|
||||
#define MIN_HEAP_SIZE 0x100000
|
||||
#define MAX_HEAP_SIZE (1600 * 0x100000)
|
||||
|
||||
static void *finish_mmap_buf = 0;
|
||||
static grub_efi_uintn_t finish_mmap_size = 0;
|
||||
static grub_efi_uintn_t finish_key = 0;
|
||||
static grub_efi_uintn_t finish_desc_size;
|
||||
static grub_efi_uint32_t finish_desc_version;
|
||||
int grub_efi_is_finished = 0;
|
||||
|
||||
/*
|
||||
* We need to roll back EFI allocations on exit. Remember allocations that
|
||||
* we'll free on exit.
|
||||
*/
|
||||
struct efi_allocation;
|
||||
struct efi_allocation {
|
||||
grub_efi_physical_address_t address;
|
||||
grub_efi_uint64_t pages;
|
||||
struct efi_allocation *next;
|
||||
};
|
||||
static struct efi_allocation *efi_allocated_memory;
|
||||
|
||||
static void
|
||||
grub_efi_store_alloc (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages)
|
||||
{
|
||||
grub_efi_boot_services_t *b;
|
||||
struct efi_allocation *alloc;
|
||||
grub_efi_status_t status;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
|
||||
sizeof(*alloc), (void**)&alloc);
|
||||
|
||||
if (status == GRUB_EFI_SUCCESS)
|
||||
{
|
||||
alloc->next = efi_allocated_memory;
|
||||
alloc->address = address;
|
||||
alloc->pages = pages;
|
||||
efi_allocated_memory = alloc;
|
||||
}
|
||||
else
|
||||
grub_printf ("Could not malloc memory to remember EFI allocation. "
|
||||
"Exiting GRUB won't free all memory.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_drop_alloc (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages)
|
||||
{
|
||||
struct efi_allocation *ea, *eap;
|
||||
grub_efi_boot_services_t *b;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
|
||||
for (eap = NULL, ea = efi_allocated_memory; ea; eap = ea, ea = ea->next)
|
||||
{
|
||||
if (ea->address != address || ea->pages != pages)
|
||||
continue;
|
||||
|
||||
/* Remove the current entry from the list. */
|
||||
if (eap)
|
||||
eap->next = ea->next;
|
||||
else
|
||||
efi_allocated_memory = ea->next;
|
||||
|
||||
/* Then free the memory backing it. */
|
||||
efi_call_1 (b->free_pool, ea);
|
||||
|
||||
/* And leave, we're done. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate pages. Return the pointer to the first of allocated pages. */
|
||||
void *
|
||||
grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages,
|
||||
grub_efi_allocate_type_t alloctype,
|
||||
grub_efi_memory_type_t memtype)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_boot_services_t *b;
|
||||
|
||||
/* Limit the memory access to less than 4GB for 32-bit platforms. */
|
||||
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
|
||||
return 0;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return 0;
|
||||
|
||||
if (address == 0)
|
||||
{
|
||||
/* Uggh, the address 0 was allocated... This is too annoying,
|
||||
so reallocate another one. */
|
||||
address = GRUB_EFI_MAX_USABLE_ADDRESS;
|
||||
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
||||
grub_efi_free_pages (0, pages);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_efi_store_alloc (address, pages);
|
||||
|
||||
return (void *) ((grub_addr_t) address);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_efi_allocate_any_pages (grub_efi_uintn_t pages)
|
||||
{
|
||||
return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS,
|
||||
pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS,
|
||||
GRUB_EFI_LOADER_DATA);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_efi_allocate_fixed (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages)
|
||||
{
|
||||
return grub_efi_allocate_pages_real (address, pages,
|
||||
GRUB_EFI_ALLOCATE_ADDRESS,
|
||||
GRUB_EFI_LOADER_DATA);
|
||||
}
|
||||
|
||||
/* Free pages starting from ADDRESS. */
|
||||
void
|
||||
grub_efi_free_pages (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages)
|
||||
{
|
||||
grub_efi_boot_services_t *b;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
efi_call_2 (b->free_pages, address, pages);
|
||||
|
||||
grub_efi_drop_alloc (address, pages);
|
||||
}
|
||||
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
|
||||
/* Helper for stop_broadcom. */
|
||||
static int
|
||||
find_card (grub_pci_device_t dev, grub_pci_id_t pciid,
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_uint8_t cap;
|
||||
grub_uint16_t pm_state;
|
||||
|
||||
if ((pciid & 0xffff) != GRUB_PCI_VENDOR_BROADCOM)
|
||||
return 0;
|
||||
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
if (grub_pci_read (addr) >> 24 != GRUB_PCI_CLASS_NETWORK)
|
||||
return 0;
|
||||
cap = grub_pci_find_capability (dev, GRUB_PCI_CAP_POWER_MANAGEMENT);
|
||||
if (!cap)
|
||||
return 0;
|
||||
addr = grub_pci_make_address (dev, cap + 4);
|
||||
pm_state = grub_pci_read_word (addr);
|
||||
pm_state = pm_state | 0x03;
|
||||
grub_pci_write_word (addr, pm_state);
|
||||
grub_pci_read_word (addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
stop_broadcom (void)
|
||||
{
|
||||
grub_pci_iterate (find_card, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
grub_err_t
|
||||
grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
|
||||
grub_efi_uintn_t *map_key,
|
||||
grub_efi_uintn_t *efi_desc_size,
|
||||
grub_efi_uint32_t *efi_desc_version)
|
||||
{
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_efi_status_t status;
|
||||
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
const grub_uint16_t apple[] = { 'A', 'p', 'p', 'l', 'e' };
|
||||
int is_apple;
|
||||
|
||||
is_apple = (grub_memcmp (grub_efi_system_table->firmware_vendor,
|
||||
apple, sizeof (apple)) == 0);
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
|
||||
&finish_desc_size, &finish_desc_version) < 0)
|
||||
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
|
||||
|
||||
if (outbuf && *outbuf_size < finish_mmap_size)
|
||||
return grub_error (GRUB_ERR_IO, "memory map buffer is too small");
|
||||
|
||||
finish_mmap_buf = grub_malloc (finish_mmap_size);
|
||||
if (!finish_mmap_buf)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_efi_get_memory_map (&finish_mmap_size, finish_mmap_buf, &finish_key,
|
||||
&finish_desc_size, &finish_desc_version) <= 0)
|
||||
{
|
||||
grub_free (finish_mmap_buf);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't retrieve memory map");
|
||||
}
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
|
||||
finish_key);
|
||||
if (status == GRUB_EFI_SUCCESS)
|
||||
break;
|
||||
|
||||
if (status != GRUB_EFI_INVALID_PARAMETER)
|
||||
{
|
||||
grub_free (finish_mmap_buf);
|
||||
return grub_error (GRUB_ERR_IO, "couldn't terminate EFI services");
|
||||
}
|
||||
|
||||
grub_free (finish_mmap_buf);
|
||||
grub_printf ("Trying to terminate EFI services again\n");
|
||||
}
|
||||
grub_efi_is_finished = 1;
|
||||
if (outbuf_size)
|
||||
*outbuf_size = finish_mmap_size;
|
||||
if (outbuf)
|
||||
grub_memcpy (outbuf, finish_mmap_buf, finish_mmap_size);
|
||||
if (map_key)
|
||||
*map_key = finish_key;
|
||||
if (efi_desc_size)
|
||||
*efi_desc_size = finish_desc_size;
|
||||
if (efi_desc_version)
|
||||
*efi_desc_version = finish_desc_version;
|
||||
|
||||
#if defined (__i386__) || defined (__x86_64__)
|
||||
if (is_apple)
|
||||
stop_broadcom ();
|
||||
#endif
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* To obtain the UEFI memory map, we must pass a buffer of sufficient size
|
||||
* to hold the entire map. This function returns a sane start value for
|
||||
* buffer size.
|
||||
*/
|
||||
grub_efi_uintn_t
|
||||
grub_efi_find_mmap_size (void)
|
||||
{
|
||||
grub_efi_uintn_t mmap_size = 0;
|
||||
grub_efi_uintn_t desc_size;
|
||||
|
||||
if (grub_efi_get_memory_map (&mmap_size, NULL, NULL, &desc_size, 0) < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_IO, "cannot get EFI memory map size");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an extra page, since UEFI can alter the memory map itself on
|
||||
* callbacks or explicit calls, including console output.
|
||||
*/
|
||||
return ALIGN_UP (mmap_size + GRUB_EFI_PAGE_SIZE, GRUB_EFI_PAGE_SIZE);
|
||||
}
|
||||
|
||||
/* Get the memory map as defined in the EFI spec. Return 1 if successful,
|
||||
return 0 if partial, or return -1 if an error occurs. */
|
||||
int
|
||||
grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size,
|
||||
grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_uintn_t *map_key,
|
||||
grub_efi_uintn_t *descriptor_size,
|
||||
grub_efi_uint32_t *descriptor_version)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_efi_uintn_t key;
|
||||
grub_efi_uint32_t version;
|
||||
grub_efi_uintn_t size;
|
||||
|
||||
if (grub_efi_is_finished)
|
||||
{
|
||||
int ret = 1;
|
||||
if (*memory_map_size < finish_mmap_size)
|
||||
{
|
||||
grub_memcpy (memory_map, finish_mmap_buf, *memory_map_size);
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_memcpy (memory_map, finish_mmap_buf, finish_mmap_size);
|
||||
ret = 1;
|
||||
}
|
||||
*memory_map_size = finish_mmap_size;
|
||||
if (map_key)
|
||||
*map_key = finish_key;
|
||||
if (descriptor_size)
|
||||
*descriptor_size = finish_desc_size;
|
||||
if (descriptor_version)
|
||||
*descriptor_version = finish_desc_version;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allow some parameters to be missing. */
|
||||
if (! map_key)
|
||||
map_key = &key;
|
||||
if (! descriptor_version)
|
||||
descriptor_version = &version;
|
||||
if (! descriptor_size)
|
||||
descriptor_size = &size;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_5 (b->get_memory_map, memory_map_size, memory_map, map_key,
|
||||
descriptor_size, descriptor_version);
|
||||
if (*descriptor_size == 0)
|
||||
*descriptor_size = sizeof (grub_efi_memory_descriptor_t);
|
||||
if (status == GRUB_EFI_SUCCESS)
|
||||
return 1;
|
||||
else if (status == GRUB_EFI_BUFFER_TOO_SMALL)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Sort the memory map in place. */
|
||||
static void
|
||||
sort_memory_map (grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_uintn_t desc_size,
|
||||
grub_efi_memory_descriptor_t *memory_map_end)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *d1;
|
||||
grub_efi_memory_descriptor_t *d2;
|
||||
|
||||
for (d1 = memory_map;
|
||||
d1 < memory_map_end;
|
||||
d1 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size))
|
||||
{
|
||||
grub_efi_memory_descriptor_t *max_desc = d1;
|
||||
|
||||
for (d2 = NEXT_MEMORY_DESCRIPTOR (d1, desc_size);
|
||||
d2 < memory_map_end;
|
||||
d2 = NEXT_MEMORY_DESCRIPTOR (d2, desc_size))
|
||||
{
|
||||
if (max_desc->num_pages < d2->num_pages)
|
||||
max_desc = d2;
|
||||
}
|
||||
|
||||
if (max_desc != d1)
|
||||
{
|
||||
grub_efi_memory_descriptor_t tmp;
|
||||
|
||||
tmp = *d1;
|
||||
*d1 = *max_desc;
|
||||
*max_desc = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Filter the descriptors. GRUB needs only available memory. */
|
||||
static grub_efi_memory_descriptor_t *
|
||||
filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_memory_descriptor_t *filtered_memory_map,
|
||||
grub_efi_uintn_t desc_size,
|
||||
grub_efi_memory_descriptor_t *memory_map_end)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
grub_efi_memory_descriptor_t *filtered_desc;
|
||||
|
||||
for (desc = memory_map, filtered_desc = filtered_memory_map;
|
||||
desc < memory_map_end;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY
|
||||
#if 1
|
||||
&& desc->physical_start <= GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
#endif
|
||||
&& desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
|
||||
&& desc->num_pages != 0)
|
||||
{
|
||||
grub_memcpy (filtered_desc, desc, desc_size);
|
||||
|
||||
/* Avoid less than 1MB, because some loaders seem to be confused. */
|
||||
if (desc->physical_start < 0x100000)
|
||||
{
|
||||
desc->num_pages -= BYTES_TO_PAGES (0x100000
|
||||
- desc->physical_start);
|
||||
desc->physical_start = 0x100000;
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (BYTES_TO_PAGES (filtered_desc->physical_start)
|
||||
+ filtered_desc->num_pages
|
||||
> BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS))
|
||||
filtered_desc->num_pages
|
||||
= (BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS)
|
||||
- BYTES_TO_PAGES (filtered_desc->physical_start));
|
||||
#endif
|
||||
|
||||
if (filtered_desc->num_pages == 0)
|
||||
continue;
|
||||
|
||||
filtered_desc = NEXT_MEMORY_DESCRIPTOR (filtered_desc, desc_size);
|
||||
}
|
||||
}
|
||||
|
||||
return filtered_desc;
|
||||
}
|
||||
|
||||
/* Return the total number of pages. */
|
||||
static grub_efi_uint64_t
|
||||
get_total_pages (grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_uintn_t desc_size,
|
||||
grub_efi_memory_descriptor_t *memory_map_end)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
grub_efi_uint64_t total = 0;
|
||||
|
||||
for (desc = memory_map;
|
||||
desc < memory_map_end;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
total += desc->num_pages;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/* Add memory regions. */
|
||||
static void
|
||||
add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_uintn_t desc_size,
|
||||
grub_efi_memory_descriptor_t *memory_map_end,
|
||||
grub_efi_uint64_t required_pages)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
|
||||
for (desc = memory_map;
|
||||
desc < memory_map_end;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
grub_efi_uint64_t pages;
|
||||
grub_efi_physical_address_t start;
|
||||
void *addr;
|
||||
|
||||
start = desc->physical_start;
|
||||
pages = desc->num_pages;
|
||||
if (pages > required_pages)
|
||||
{
|
||||
start += PAGES_TO_BYTES (pages - required_pages);
|
||||
pages = required_pages;
|
||||
}
|
||||
|
||||
addr = grub_efi_allocate_pages_real (start, pages,
|
||||
GRUB_EFI_ALLOCATE_ADDRESS,
|
||||
GRUB_EFI_LOADER_CODE);
|
||||
if (! addr)
|
||||
grub_fatal ("cannot allocate conventional memory %p with %u pages",
|
||||
(void *) ((grub_addr_t) start),
|
||||
(unsigned) pages);
|
||||
|
||||
grub_mm_init_region (addr, PAGES_TO_BYTES (pages));
|
||||
|
||||
required_pages -= pages;
|
||||
if (required_pages == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (required_pages > 0)
|
||||
grub_fatal ("too little memory");
|
||||
}
|
||||
|
||||
void
|
||||
grub_efi_memory_fini (void)
|
||||
{
|
||||
/*
|
||||
* Free all stale allocations. grub_efi_free_pages() will remove
|
||||
* the found entry from the list and it will always find the first
|
||||
* list entry (efi_allocated_memory is the list start). Hence we
|
||||
* remove all entries from the list until none is left altogether.
|
||||
*/
|
||||
while (efi_allocated_memory)
|
||||
grub_efi_free_pages (efi_allocated_memory->address,
|
||||
efi_allocated_memory->pages);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Print the memory map. */
|
||||
static void
|
||||
print_memory_map (grub_efi_memory_descriptor_t *memory_map,
|
||||
grub_efi_uintn_t desc_size,
|
||||
grub_efi_memory_descriptor_t *memory_map_end)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
int i;
|
||||
|
||||
for (desc = memory_map, i = 0;
|
||||
desc < memory_map_end;
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size), i++)
|
||||
{
|
||||
grub_printf ("MD: t=%x, p=%llx, v=%llx, n=%llx, a=%llx\n",
|
||||
desc->type, desc->physical_start, desc->virtual_start,
|
||||
desc->num_pages, desc->attribute);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_efi_mm_init (void)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *memory_map;
|
||||
grub_efi_memory_descriptor_t *memory_map_end;
|
||||
grub_efi_memory_descriptor_t *filtered_memory_map;
|
||||
grub_efi_memory_descriptor_t *filtered_memory_map_end;
|
||||
grub_efi_uintn_t map_size;
|
||||
grub_efi_uintn_t desc_size;
|
||||
grub_efi_uint64_t total_pages;
|
||||
grub_efi_uint64_t required_pages;
|
||||
int mm_status;
|
||||
|
||||
/* Prepare a memory region to store two memory maps. */
|
||||
memory_map = grub_efi_allocate_any_pages (2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
|
||||
if (! memory_map)
|
||||
grub_fatal ("cannot allocate memory");
|
||||
|
||||
/* Obtain descriptors for available memory. */
|
||||
map_size = MEMORY_MAP_SIZE;
|
||||
|
||||
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0);
|
||||
|
||||
if (mm_status == 0)
|
||||
{
|
||||
grub_efi_free_pages
|
||||
((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_any_pages (2 * BYTES_TO_PAGES (map_size));
|
||||
if (! memory_map)
|
||||
grub_fatal ("cannot allocate memory");
|
||||
|
||||
mm_status = grub_efi_get_memory_map (&map_size, memory_map, 0,
|
||||
&desc_size, 0);
|
||||
}
|
||||
|
||||
if (mm_status < 0)
|
||||
grub_fatal ("cannot get memory map");
|
||||
|
||||
memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size);
|
||||
|
||||
filtered_memory_map = memory_map_end;
|
||||
|
||||
filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
|
||||
desc_size, memory_map_end);
|
||||
|
||||
/* By default, request a quarter of the available memory. */
|
||||
total_pages = get_total_pages (filtered_memory_map, desc_size,
|
||||
filtered_memory_map_end);
|
||||
|
||||
#if defined (__mips__) && (_MIPS_SIM == _ABI64)
|
||||
required_pages = (total_pages > 4096) ? (total_pages - 4096) : (total_pages >> 1);
|
||||
#else
|
||||
required_pages = (total_pages >> 2);
|
||||
#endif
|
||||
|
||||
if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
|
||||
required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
|
||||
else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
|
||||
required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
|
||||
|
||||
/* Sort the filtered descriptors, so that GRUB can allocate pages
|
||||
from smaller regions. */
|
||||
sort_memory_map (filtered_memory_map, desc_size, filtered_memory_map_end);
|
||||
|
||||
/* Allocate memory regions for GRUB's memory management. */
|
||||
add_memory_regions (filtered_memory_map, desc_size,
|
||||
filtered_memory_map_end, required_pages);
|
||||
|
||||
#if 0
|
||||
/* For debug. */
|
||||
map_size = MEMORY_MAP_SIZE;
|
||||
|
||||
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0)
|
||||
grub_fatal ("cannot get memory map");
|
||||
|
||||
grub_printf ("printing memory map\n");
|
||||
print_memory_map (memory_map, desc_size,
|
||||
NEXT_MEMORY_DESCRIPTOR (memory_map, map_size));
|
||||
grub_fatal ("Debug. ");
|
||||
#endif
|
||||
|
||||
/* Release the memory maps. */
|
||||
grub_efi_free_pages ((grub_addr_t) memory_map,
|
||||
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
|
||||
}
|
||||
|
||||
#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
|
||||
grub_err_t
|
||||
grub_efi_get_ram_base(grub_addr_t *base_addr)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *memory_map, *desc;
|
||||
grub_efi_uintn_t memory_map_size, desc_size;
|
||||
int ret;
|
||||
|
||||
memory_map_size = grub_efi_find_mmap_size();
|
||||
|
||||
memory_map = grub_malloc (memory_map_size);
|
||||
if (! memory_map)
|
||||
return GRUB_ERR_OUT_OF_MEMORY;
|
||||
ret = grub_efi_get_memory_map (&memory_map_size, memory_map, NULL,
|
||||
&desc_size, NULL);
|
||||
|
||||
if (ret < 1)
|
||||
return GRUB_ERR_BUG;
|
||||
|
||||
for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS;
|
||||
(grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size);
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
if (desc->attribute & GRUB_EFI_MEMORY_WB)
|
||||
*base_addr = grub_min (*base_addr, desc->physical_start);
|
||||
|
||||
grub_free(memory_map);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#endif
|
23
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/cache.S
Normal file
23
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/cache.S
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2017 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>
|
||||
|
||||
FUNCTION (grub_arch_sync_caches)
|
||||
jr.hb $ra
|
||||
|
150
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/dl.c
Normal file
150
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/dl.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/* dl-mips64.c - arch-dependent part of loadable module support */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2005,2007,2009,2017 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/dl.h>
|
||||
#include <grub/elf.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/cpu/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
/* Check if EHDR is a valid ELF header. */
|
||||
grub_err_t
|
||||
grub_arch_dl_check_header (void *ehdr)
|
||||
{
|
||||
Elf_Ehdr *e = ehdr;
|
||||
|
||||
/* Check the magic numbers. */
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
if (e->e_ident[EI_CLASS] != ELFCLASS64
|
||||
|| e->e_ident[EI_DATA] != ELFDATA2MSB
|
||||
|| e->e_machine != EM_MIPS)
|
||||
#else
|
||||
if (e->e_ident[EI_CLASS] != ELFCLASS64
|
||||
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|
||||
|| e->e_machine != EM_MIPS)
|
||||
#endif
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
grub_err_t
|
||||
grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
|
||||
grub_size_t *tramp, grub_size_t *got)
|
||||
{
|
||||
*tramp = 0;
|
||||
*got = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Relocate symbols. */
|
||||
grub_err_t
|
||||
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
|
||||
Elf_Shdr *s, grub_dl_segment_t seg)
|
||||
{
|
||||
Elf_Ehdr *e = ehdr;
|
||||
Elf_Rel *rel, *max;
|
||||
|
||||
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
|
||||
max = (Elf_Rel *) ((char *) rel + s->sh_size);
|
||||
rel < max;
|
||||
rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
|
||||
{
|
||||
grub_uint8_t *addr;
|
||||
Elf_Sym *sym;
|
||||
Elf_Addr r_info;
|
||||
grub_uint64_t sym_value;
|
||||
|
||||
if (seg->size < rel->r_offset)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"reloc offset is out of the segment");
|
||||
|
||||
r_info = ((grub_uint64_t) rel->r_info << 32) |
|
||||
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
|
||||
|
||||
addr = (grub_uint8_t *) ((char *) seg->addr + rel->r_offset);
|
||||
sym = (Elf_Sym *) ((char *) mod->symtab
|
||||
+ mod->symsize * ELF_R_SYM (r_info));
|
||||
sym_value = sym->st_value;
|
||||
if (s->sh_type == SHT_RELA)
|
||||
{
|
||||
sym_value += ((Elf_Rela *) rel)->r_addend;
|
||||
}
|
||||
switch (ELF_R_TYPE (r_info))
|
||||
{
|
||||
case R_MIPS_64:
|
||||
*(grub_uint64_t *) addr += sym_value;
|
||||
break;
|
||||
case R_MIPS_32:
|
||||
*(grub_uint32_t *) addr += sym_value;
|
||||
break;
|
||||
case R_MIPS_26:
|
||||
{
|
||||
grub_uint32_t value;
|
||||
grub_uint32_t raw;
|
||||
raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
|
||||
value = raw << 2;
|
||||
value += sym_value;
|
||||
raw = (value >> 2) & 0x3ffffff;
|
||||
|
||||
*(grub_uint32_t *) addr =
|
||||
raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
|
||||
}
|
||||
break;
|
||||
case R_MIPS_LO16:
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
addr += 2;
|
||||
#endif
|
||||
*(grub_uint16_t *) addr = (grub_int16_t) sym_value;
|
||||
break;
|
||||
case R_MIPS_HI16:
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
addr += 2;
|
||||
#endif
|
||||
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x8000UL) >> 16);
|
||||
break;
|
||||
case R_MIPS_HIGHER:
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
addr += 2;
|
||||
#endif
|
||||
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x80008000UL) >> 32);
|
||||
break;
|
||||
case R_MIPS_HIGHEST:
|
||||
#ifdef GRUB_CPU_WORDS_BIGENDIAN
|
||||
addr += 2;
|
||||
#endif
|
||||
*(grub_uint16_t *) addr = (grub_uint16_t) ((sym_value + 0x800080008000UL) >> 48);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
N_("relocation 0x%x is not implemented yet"),
|
||||
ELF_R_TYPE (r_info));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
85
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/init.c
Normal file
85
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/init.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* init.c - initialize an arm-based EFI system */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 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/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/cpu/time.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/machine/loongson.h>
|
||||
|
||||
static grub_uint64_t tmr;
|
||||
static grub_efi_event_t tmr_evt;
|
||||
|
||||
static grub_uint64_t
|
||||
grub_efi_get_time_ms (void)
|
||||
{
|
||||
return tmr;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_loongson_increment_timer (grub_efi_event_t event __attribute__ ((unused)),
|
||||
void *context __attribute__ ((unused)))
|
||||
{
|
||||
tmr += 10;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
grub_machine_init (void)
|
||||
{
|
||||
grub_efi_boot_services_t *b;
|
||||
|
||||
grub_efi_init ();
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
|
||||
GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
|
||||
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
|
||||
|
||||
grub_install_get_time_ms (grub_efi_get_time_ms);
|
||||
|
||||
if (grub_efi_is_loongson ())
|
||||
grub_efi_loongson_init ();
|
||||
else
|
||||
/* FIXME: Get cpuclock from EFI. */
|
||||
grub_timer_init (1000000000U);
|
||||
}
|
||||
|
||||
void
|
||||
grub_machine_fini (int flags)
|
||||
{
|
||||
grub_efi_boot_services_t *b;
|
||||
|
||||
if (!(flags & GRUB_LOADER_FLAG_NORETURN))
|
||||
return;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
|
||||
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
|
||||
efi_call_1 (b->close_event, tmr_evt);
|
||||
|
||||
if (grub_efi_is_loongson ())
|
||||
grub_efi_loongson_fini ();
|
||||
grub_efi_fini ();
|
||||
}
|
33
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/loongson.c
Normal file
33
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/loongson.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2017 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/efi/efi.h>
|
||||
#include <grub/cpu/time.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/machine/loongson.h>
|
||||
|
||||
void
|
||||
grub_efi_loongson_init (void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
grub_efi_loongson_fini (void)
|
||||
{
|
||||
}
|
||||
|
47
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/startup.S
Normal file
47
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/efi/startup.S
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 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>
|
||||
|
||||
.file "startup.S"
|
||||
.text
|
||||
|
||||
.set push
|
||||
.align 4
|
||||
|
||||
FUNCTION(_start)
|
||||
/*
|
||||
* EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0.
|
||||
*/
|
||||
daddiu $sp, -16
|
||||
sd $ra, ($sp)
|
||||
|
||||
dla $a2, grub_efi_image_handle
|
||||
sd $a0, ($a2)
|
||||
dla $a2, grub_efi_system_table
|
||||
sd $a1, ($a2)
|
||||
|
||||
jal grub_main
|
||||
|
||||
1:
|
||||
ld $ra, ($sp)
|
||||
daddiu $sp, 16
|
||||
jr $ra
|
||||
|
||||
.set pop
|
||||
|
47
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/init.c
Normal file
47
GRUB2/MOD_SRC/grub-2.04/grub-core/kern/mips64/init.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2017 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/kernel.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/cpu/mips.h>
|
||||
|
||||
grub_uint32_t grub_arch_cpuclock;
|
||||
|
||||
/* FIXME: use interrupt to count high. */
|
||||
grub_uint64_t
|
||||
grub_get_rtc (void)
|
||||
{
|
||||
static grub_uint32_t high = 0;
|
||||
static grub_uint32_t last = 0;
|
||||
grub_uint32_t low;
|
||||
|
||||
asm volatile ("mfc0 %0, " GRUB_CPU_MIPS_COP0_TIMER_COUNT : "=r" (low));
|
||||
if (low < last)
|
||||
high++;
|
||||
last = low;
|
||||
|
||||
return (((grub_uint64_t) high) << 32) | low;
|
||||
}
|
||||
|
||||
void
|
||||
grub_timer_init (grub_uint32_t cpuclock)
|
||||
{
|
||||
grub_arch_cpuclock = cpuclock;
|
||||
grub_install_get_time_ms (grub_rtc_get_time_ms);
|
||||
}
|
40
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/efi/halt.c
Normal file
40
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/efi/halt.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* efi.c - generic EFI support */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 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
|
||||
* 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/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/acpi.h>
|
||||
#include <grub/loader.h>
|
||||
|
||||
void
|
||||
grub_halt (void)
|
||||
{
|
||||
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
|
||||
#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__mips__) &&\
|
||||
!defined(__riscv)
|
||||
grub_acpi_halt ();
|
||||
#endif
|
||||
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
|
||||
GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);
|
||||
|
||||
while (1);
|
||||
}
|
495
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/efi/loongson.c
Normal file
495
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/efi/loongson.c
Normal file
@@ -0,0 +1,495 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2017 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/mm.h>
|
||||
#include <grub/cache.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/cpu/efi/memory.h>
|
||||
#include <grub/cpu/memory.h>
|
||||
#include <grub/machine/loongson.h>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
#define loongson_params (&loongson_boot_params->boot_params.efi.smbios.lp)
|
||||
#define loongson_boot_params_size ALIGN_UP (sizeof (*loongson_boot_params), 8)
|
||||
#define loongson_reset_code_size (&grub_efi_loongson_reset_end - &grub_efi_loongson_reset_start)
|
||||
|
||||
extern grub_uint8_t grub_efi_loongson_reset_start;
|
||||
extern grub_uint8_t grub_efi_loongson_reset_end;
|
||||
|
||||
static struct
|
||||
{
|
||||
grub_efi_loongson_boot_params boot_params;
|
||||
grub_efi_loongson_memory_map memory_map;
|
||||
grub_efi_loongson_cpu_info cpu_info;
|
||||
grub_efi_loongson_system_info system_info;
|
||||
grub_efi_loongson_irq_src_routing_table irq_src_routing_table;
|
||||
grub_efi_loongson_interface_info interface_info;
|
||||
grub_efi_loongson_special_attribute special_attribute;
|
||||
grub_efi_loongson_board_devices board_devices;
|
||||
} GRUB_PACKED
|
||||
* loongson_boot_params;
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_reset_system (void)
|
||||
{
|
||||
grub_efi_loongson_boot_params *boot_params;
|
||||
grub_uint8_t *reset_code_addr = (grub_uint8_t *) loongson_boot_params +
|
||||
loongson_boot_params_size;
|
||||
|
||||
boot_params = &loongson_boot_params->boot_params;
|
||||
grub_efi_loongson_reset_system_addr =
|
||||
(grub_uint64_t) grub_efi_system_table->runtime_services->reset_system;
|
||||
grub_memcpy (reset_code_addr, &grub_efi_loongson_reset_start, loongson_reset_code_size);
|
||||
grub_arch_sync_caches (reset_code_addr, loongson_reset_code_size);
|
||||
|
||||
boot_params->reset_system.reset_cold = (grub_uint64_t) reset_code_addr +
|
||||
((grub_uint64_t) &grub_efi_loongson_reset_cold -
|
||||
(grub_uint64_t) &grub_efi_loongson_reset_start);
|
||||
boot_params->reset_system.reset_warm = (grub_uint64_t) reset_code_addr +
|
||||
((grub_uint64_t) &grub_efi_loongson_reset_warm -
|
||||
(grub_uint64_t) &grub_efi_loongson_reset_start);
|
||||
boot_params->reset_system.shutdown = (grub_uint64_t) reset_code_addr +
|
||||
((grub_uint64_t) &grub_efi_loongson_reset_shutdown -
|
||||
(grub_uint64_t) &grub_efi_loongson_reset_start);
|
||||
boot_params->reset_system.do_suspend = (grub_uint64_t) reset_code_addr +
|
||||
((grub_uint64_t) &grub_efi_loongson_reset_suspend -
|
||||
(grub_uint64_t) &grub_efi_loongson_reset_start);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_smbios (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_smbios_table *dst = &loongson_boot_params->boot_params.efi.smbios;
|
||||
|
||||
dst->vers = smbios_table->vers;
|
||||
dst->vga_bios = smbios_table->vga_bios;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_cpu_info (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_cpu_info *src = (void *) smbios_table->lp.cpu_offset;
|
||||
grub_efi_loongson_cpu_info *dst = &loongson_boot_params->cpu_info;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_cpu_info));
|
||||
loongson_params->cpu_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_system_info (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_system_info *src = (void *) smbios_table->lp.system_offset;
|
||||
grub_efi_loongson_system_info *dst = &loongson_boot_params->system_info;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_system_info));
|
||||
loongson_params->system_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_irq_src_routing_table (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_irq_src_routing_table *src = (void *) smbios_table->lp.irq_offset;
|
||||
grub_efi_loongson_irq_src_routing_table *dst = &loongson_boot_params->irq_src_routing_table;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_irq_src_routing_table));
|
||||
loongson_params->irq_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_interface_info (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_interface_info *src = (void *) smbios_table->lp.interface_offset;
|
||||
grub_efi_loongson_interface_info *dst = &loongson_boot_params->interface_info;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_interface_info));
|
||||
loongson_params->interface_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_special_attribute (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_special_attribute *src = (void *) smbios_table->lp.special_offset;
|
||||
grub_efi_loongson_special_attribute *dst = &loongson_boot_params->special_attribute;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_special_attribute));
|
||||
loongson_params->special_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_board_devices (grub_efi_loongson_smbios_table *smbios_table)
|
||||
{
|
||||
grub_efi_loongson_board_devices *src = (void *) smbios_table->lp.boarddev_table_offset;
|
||||
grub_efi_loongson_board_devices *dst = &loongson_boot_params->board_devices;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
grub_memcpy (dst, src, sizeof (grub_efi_loongson_board_devices));
|
||||
loongson_params->boarddev_table_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
}
|
||||
|
||||
#define ADD_MEMORY_DESCRIPTOR(desc, size) \
|
||||
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
|
||||
|
||||
static void
|
||||
grub_efi_loongson_init_memory_map (grub_efi_loongson_smbios_table *smbios_table,
|
||||
grub_efi_memory_descriptor_t *mmap_buf,
|
||||
grub_efi_uintn_t mmap_size,
|
||||
grub_efi_uintn_t desc_size)
|
||||
{
|
||||
grub_efi_loongson_memory_map *src = (void *) smbios_table->lp.memory_offset;
|
||||
grub_efi_loongson_memory_map *dst = &loongson_boot_params->memory_map;
|
||||
grub_efi_memory_descriptor_t *mmap_end;
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
grub_efi_memory_descriptor_t *desc_next;
|
||||
grub_efi_uint32_t mem_types_reserved[] =
|
||||
{
|
||||
1, // GRUB_EFI_RESERVED_MEMORY_TYPE
|
||||
0, // GRUB_EFI_LOADER_CODE
|
||||
0, // GRUB_EFI_LOADER_DATA
|
||||
0, // GRUB_EFI_BOOT_SERVICES_CODE
|
||||
0, // GRUB_EFI_BOOT_SERVICES_DATA
|
||||
1, // GRUB_EFI_RUNTIME_SERVICES_CODE
|
||||
1, // GRUB_EFI_RUNTIME_SERVICES_DATA
|
||||
0, // GRUB_EFI_CONVENTIONAL_MEMORY
|
||||
1, // GRUB_EFI_UNUSABLE_MEMORY
|
||||
0, // GRUB_EFI_ACPI_RECLAIM_MEMORY
|
||||
0, // GRUB_EFI_ACPI_MEMORY_NVS
|
||||
1, // GRUB_EFI_MEMORY_MAPPED_IO
|
||||
1, // GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE
|
||||
1, // GRUB_EFI_PAL_CODE
|
||||
1, // GRUB_EFI_PERSISTENT_MEMORY
|
||||
};
|
||||
grub_uint32_t need_sort = 1;
|
||||
|
||||
if (!src)
|
||||
return;
|
||||
|
||||
dst->vers = src->vers;
|
||||
dst->nr_map = 0;
|
||||
dst->mem_freq = src->mem_freq;
|
||||
loongson_params->memory_offset = (grub_uint64_t) dst - (grub_uint64_t) loongson_params;
|
||||
|
||||
if (!mmap_buf || !mmap_size || !desc_size)
|
||||
return;
|
||||
|
||||
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
|
||||
|
||||
/* drop reserved */
|
||||
for (desc = mmap_buf,
|
||||
desc_next = desc;
|
||||
desc < mmap_end;
|
||||
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
desc->type = mem_types_reserved[desc->type];
|
||||
if (desc->type)
|
||||
continue;
|
||||
|
||||
if (desc != desc_next)
|
||||
*desc_next = *desc;
|
||||
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size);
|
||||
}
|
||||
mmap_end = desc_next;
|
||||
|
||||
/* sort: low->high */
|
||||
while (need_sort)
|
||||
{
|
||||
need_sort = 0;
|
||||
|
||||
for (desc = mmap_buf,
|
||||
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
|
||||
(desc < mmap_end) && (desc_next < mmap_end);
|
||||
desc = desc_next,
|
||||
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
grub_efi_memory_descriptor_t tmp;
|
||||
|
||||
if (desc->physical_start <= desc_next->physical_start)
|
||||
continue;
|
||||
|
||||
tmp = *desc;
|
||||
*desc = *desc_next;
|
||||
*desc_next = tmp;
|
||||
need_sort = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* combine continuous memory map */
|
||||
for (desc = mmap_buf,
|
||||
desc_next = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
|
||||
desc_next < mmap_end;
|
||||
desc_next = ADD_MEMORY_DESCRIPTOR (desc_next, desc_size))
|
||||
{
|
||||
grub_efi_physical_address_t prev_end = desc->physical_start + (desc->num_pages << 12);
|
||||
|
||||
if (prev_end == desc_next->physical_start)
|
||||
{
|
||||
desc->num_pages += desc_next->num_pages;
|
||||
continue;
|
||||
}
|
||||
|
||||
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
|
||||
grub_memcpy (desc, desc_next, desc_size);
|
||||
}
|
||||
mmap_end = ADD_MEMORY_DESCRIPTOR (desc, desc_size);
|
||||
|
||||
/* write to loongson memory map */
|
||||
for (desc = mmap_buf;
|
||||
desc < mmap_end;
|
||||
desc = ADD_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
grub_efi_physical_address_t physical_start = grub_vtop ((void *) desc->physical_start);
|
||||
grub_efi_physical_address_t physical_end = physical_start + (desc->num_pages << 12);
|
||||
|
||||
physical_start = ALIGN_UP (physical_start, 0x100000);
|
||||
physical_end = ALIGN_DOWN (physical_end, 0x100000);
|
||||
|
||||
if (physical_start >= physical_end || (physical_end - physical_start) < 0x100000)
|
||||
continue;
|
||||
|
||||
dst->map[dst->nr_map].node_id = (desc->physical_start >> 44) & 0xf;
|
||||
dst->map[dst->nr_map].mem_type = (physical_end <= 0x10000000) ?
|
||||
GRUB_EFI_LOONGSON_SYSTEM_RAM_LOW :
|
||||
GRUB_EFI_LOONGSON_SYSTEM_RAM_HIGH;
|
||||
dst->map[dst->nr_map].mem_start = physical_start;
|
||||
dst->map[dst->nr_map].mem_size = (physical_end - physical_start) >> 20;
|
||||
|
||||
grub_dprintf ("loongson", "memory map %03u: 0x%016lx 0x%016lx @ %u\n",
|
||||
dst->nr_map, physical_start, physical_end - physical_start,
|
||||
dst->map[dst->nr_map].node_id);
|
||||
|
||||
dst->nr_map ++;
|
||||
}
|
||||
}
|
||||
|
||||
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
||||
#define SUB_MEMORY_DESCRIPTOR(desc, size) \
|
||||
((grub_efi_memory_descriptor_t *) ((char *) (desc) - (size)))
|
||||
|
||||
void
|
||||
grub_efi_loongson_alloc_boot_params (void)
|
||||
{
|
||||
grub_efi_memory_descriptor_t *mmap_buf;
|
||||
grub_efi_memory_descriptor_t *mmap_end;
|
||||
grub_efi_memory_descriptor_t *desc;
|
||||
grub_efi_uintn_t mmap_size;
|
||||
grub_efi_uintn_t desc_size;
|
||||
grub_efi_physical_address_t address;
|
||||
grub_efi_allocate_type_t type;
|
||||
grub_efi_uintn_t pages;
|
||||
grub_efi_status_t status;
|
||||
grub_efi_boot_services_t *b;
|
||||
int mm_status;
|
||||
|
||||
type = GRUB_EFI_ALLOCATE_ADDRESS;
|
||||
pages = BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size);
|
||||
|
||||
mmap_size = (1 << 12);
|
||||
mmap_buf = grub_malloc (mmap_size);
|
||||
if (!mmap_buf)
|
||||
grub_fatal ("out of memory!");
|
||||
|
||||
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
|
||||
if (mm_status == 0)
|
||||
{
|
||||
grub_free (mmap_buf);
|
||||
mmap_size += desc_size * 32;
|
||||
|
||||
mmap_buf = grub_malloc (mmap_size);
|
||||
if (!mmap_buf)
|
||||
grub_fatal ("out of memory!");
|
||||
|
||||
mm_status = grub_efi_get_memory_map (&mmap_size, mmap_buf, 0, &desc_size, 0);
|
||||
}
|
||||
|
||||
if (mm_status < 0)
|
||||
grub_fatal ("cannot get memory map!");
|
||||
|
||||
mmap_end = ADD_MEMORY_DESCRIPTOR (mmap_buf, mmap_size);
|
||||
|
||||
for (desc = SUB_MEMORY_DESCRIPTOR (mmap_end, desc_size);
|
||||
desc >= mmap_buf;
|
||||
desc = SUB_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
{
|
||||
if (desc->type != GRUB_EFI_CONVENTIONAL_MEMORY)
|
||||
continue;
|
||||
if (desc->physical_start >= GRUB_EFI_MAX_USABLE_ADDRESS)
|
||||
continue;
|
||||
if (desc->num_pages < pages)
|
||||
continue;
|
||||
|
||||
address = desc->physical_start;
|
||||
break;
|
||||
}
|
||||
|
||||
grub_free (mmap_buf);
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_RUNTIME_SERVICES_DATA, pages, &address);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
grub_fatal ("cannot allocate Loongson boot parameters!");
|
||||
|
||||
loongson_boot_params = (void *) ((grub_addr_t) address);
|
||||
}
|
||||
|
||||
void
|
||||
grub_efi_loongson_free_boot_params (void)
|
||||
{
|
||||
grub_efi_free_pages ((grub_addr_t) loongson_boot_params,
|
||||
BYTES_TO_PAGES (loongson_boot_params_size + loongson_reset_code_size));
|
||||
}
|
||||
|
||||
void *
|
||||
grub_efi_loongson_get_smbios_table (void)
|
||||
{
|
||||
static grub_efi_loongson_smbios_table *smbios_table;
|
||||
grub_efi_loongson_boot_params *old_boot_params;
|
||||
struct bootparamsinterface* boot_params;
|
||||
void * tmp_boot_params = NULL;
|
||||
char * p = NULL;
|
||||
if(smbios_table)
|
||||
return smbios_table;
|
||||
|
||||
tmp_boot_params = grub_efi_loongson_get_boot_params();
|
||||
if(tmp_boot_params == NULL)
|
||||
{
|
||||
grub_dprintf("loongson", "tmp_boot_params is NULL\n");
|
||||
return tmp_boot_params;
|
||||
}
|
||||
|
||||
boot_params = (struct bootparamsinterface *)tmp_boot_params;
|
||||
p = (char *)&(boot_params->signature);
|
||||
if(grub_strncmp(p, "BPI", 3) == 0)
|
||||
{
|
||||
grub_dprintf("loongson", "find new bpi\n");
|
||||
return boot_params ? boot_params : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
old_boot_params = (grub_efi_loongson_boot_params *)tmp_boot_params;
|
||||
return old_boot_params ? &old_boot_params->efi.smbios : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
grub_efi_is_loongson (void)
|
||||
{
|
||||
return grub_efi_loongson_get_smbios_table () ? 1 : 0;
|
||||
}
|
||||
|
||||
void *
|
||||
grub_efi_loongson_get_boot_params (void)
|
||||
{
|
||||
static void * boot_params = NULL;
|
||||
grub_efi_configuration_table_t *tables;
|
||||
grub_efi_guid_t smbios_guid = GRUB_EFI_LOONGSON_SMBIOS_TABLE_GUID;
|
||||
unsigned int i;
|
||||
|
||||
if (boot_params)
|
||||
return boot_params;
|
||||
|
||||
/* Look for Loongson SMBIOS in UEFI config tables. */
|
||||
tables = grub_efi_system_table->configuration_table;
|
||||
|
||||
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
|
||||
if (grub_memcmp (&tables[i].vendor_guid, &smbios_guid, sizeof (smbios_guid)) == 0)
|
||||
{
|
||||
boot_params= tables[i].vendor_table;
|
||||
grub_dprintf ("loongson", "found registered SMBIOS @ %p\n", boot_params);
|
||||
break;
|
||||
}
|
||||
return boot_params;
|
||||
}
|
||||
|
||||
grub_uint8_t
|
||||
grub_efi_loongson_calculatesum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
|
||||
{
|
||||
grub_uint8_t sum;
|
||||
grub_efi_uintn_t count;
|
||||
|
||||
for (sum = 0, count = 0; count < length; count++)
|
||||
{
|
||||
sum = (grub_uint8_t) (sum + *(buffer + count));
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
grub_uint8_t
|
||||
grub_efi_loongson_grub_calculatechecksum8 (const grub_uint8_t *buffer, grub_efi_uintn_t length)
|
||||
{
|
||||
grub_uint8_t checksum;
|
||||
|
||||
checksum = grub_efi_loongson_calculatesum8(buffer, length);
|
||||
|
||||
return (grub_uint8_t) (0x100 - checksum);
|
||||
}
|
||||
|
||||
|
||||
grub_uint32_t
|
||||
grub_efi_loongson_memmap_sort(struct memmap array[], grub_uint32_t length, mem_map * bpmem, grub_uint32_t index, grub_uint32_t memtype)
|
||||
{
|
||||
grub_uint64_t tempmemsize = 0;
|
||||
grub_uint32_t j = 0;
|
||||
grub_uint32_t t = 0;
|
||||
|
||||
for(j = 0; j < length;)
|
||||
{
|
||||
tempmemsize = array[j].memsize;
|
||||
for(t = j + 1; t < length; t++)
|
||||
{
|
||||
if(array[j].memstart + tempmemsize == array[t].memstart)
|
||||
{
|
||||
tempmemsize += array[t].memsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
bpmem->map[index].memtype = memtype;
|
||||
bpmem->map[index].memstart = array[j].memstart;
|
||||
bpmem->map[index].memsize = tempmemsize;
|
||||
grub_dprintf("loongson", "map[%d]:type %x, start 0x%llx, end 0x%llx\n",
|
||||
index,
|
||||
bpmem->map[index].memtype,
|
||||
(unsigned long long)bpmem->map[index].memstart,
|
||||
(unsigned long long)bpmem->map[index].memstart+ bpmem->map[index].memsize
|
||||
);
|
||||
j = t;
|
||||
index++;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2017 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>
|
||||
|
||||
.file "loongson.S"
|
||||
.text
|
||||
|
||||
.set push
|
||||
.set noreorder
|
||||
.align 4
|
||||
|
||||
VARIABLE (grub_efi_loongson_reset_start)
|
||||
|
||||
VARIABLE (grub_efi_loongson_reset_system_addr)
|
||||
.dword 0
|
||||
|
||||
reset_system:
|
||||
bal 1f
|
||||
move $a1, $zero
|
||||
1:
|
||||
ld $t9, -16($ra)
|
||||
move $a2, $zero
|
||||
jalr $t9
|
||||
move $a3, $zero
|
||||
|
||||
FUNCTION(grub_efi_loongson_reset_cold)
|
||||
b reset_system
|
||||
li $a0, 0
|
||||
|
||||
FUNCTION(grub_efi_loongson_reset_warm)
|
||||
b reset_system
|
||||
li $a0, 1
|
||||
|
||||
FUNCTION(grub_efi_loongson_reset_shutdown)
|
||||
b reset_system
|
||||
li $a0, 2
|
||||
|
||||
FUNCTION(grub_efi_loongson_reset_suspend)
|
||||
b reset_system
|
||||
li $a0, 3
|
||||
|
||||
VARIABLE (grub_efi_loongson_reset_end)
|
||||
|
||||
.set pop
|
||||
|
169
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/relocator.c
Normal file
169
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/relocator.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2017 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/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/cache.h>
|
||||
|
||||
#include <grub/mips64/relocator.h>
|
||||
#include <grub/relocator_private.h>
|
||||
|
||||
extern grub_uint8_t grub_relocator_forward_start;
|
||||
extern grub_uint8_t grub_relocator_forward_end;
|
||||
extern grub_uint8_t grub_relocator_backward_start;
|
||||
extern grub_uint8_t grub_relocator_backward_end;
|
||||
|
||||
#define REGW_SIZEOF (6 * sizeof (grub_uint32_t))
|
||||
#define JUMP_SIZEOF (2 * sizeof (grub_uint32_t))
|
||||
|
||||
#define RELOCATOR_SRC_SIZEOF(x) (&grub_relocator_##x##_end \
|
||||
- &grub_relocator_##x##_start)
|
||||
#define RELOCATOR_SIZEOF(x) (RELOCATOR_SRC_SIZEOF(x) \
|
||||
+ REGW_SIZEOF * 3)
|
||||
grub_size_t grub_relocator_align = sizeof (grub_uint64_t);
|
||||
grub_size_t grub_relocator_forward_size;
|
||||
grub_size_t grub_relocator_backward_size;
|
||||
grub_size_t grub_relocator_jumper_size = JUMP_SIZEOF + REGW_SIZEOF;
|
||||
|
||||
void
|
||||
grub_cpu_relocator_init (void)
|
||||
{
|
||||
grub_relocator_forward_size = RELOCATOR_SIZEOF(forward);
|
||||
grub_relocator_backward_size = RELOCATOR_SIZEOF(backward);
|
||||
}
|
||||
|
||||
static void
|
||||
write_reg (int regn, grub_uint64_t val, void **target)
|
||||
{
|
||||
grub_uint32_t lui;
|
||||
grub_uint32_t ori;
|
||||
grub_uint32_t dsll;
|
||||
|
||||
/* lui $r, 0 */
|
||||
lui = (0x3c00 | regn) << 16;
|
||||
/* ori $r, $r, 0 */
|
||||
ori = (0x3400 | (regn << 5) | regn) << 16;
|
||||
/* dsll $r, $r, 16 */
|
||||
dsll = (regn << 16) | (regn << 11) | (16 << 6) | 56;
|
||||
|
||||
/* lui $r, val[63:48]. */
|
||||
*(grub_uint32_t *) *target = lui | (grub_uint16_t) (val >> 48);
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* ori $r, val[47:32]. */
|
||||
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 32);
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* dsll $r, $r, 16 */
|
||||
*(grub_uint32_t *) *target = dsll;
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* ori $r, val[31:16]. */
|
||||
*(grub_uint32_t *) *target = ori | (grub_uint16_t) (val >> 16);
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* dsll $r, $r, 16 */
|
||||
*(grub_uint32_t *) *target = dsll;
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* ori $r, val[15:0]. */
|
||||
*(grub_uint32_t *) *target = ori | (grub_uint16_t) val;
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
}
|
||||
|
||||
static void
|
||||
write_jump (int regn, void **target)
|
||||
{
|
||||
/* j $r. */
|
||||
*(grub_uint32_t *) *target = (regn << 21) | 0x8;
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
/* nop. */
|
||||
*(grub_uint32_t *) *target = 0;
|
||||
*target = ((grub_uint32_t *) *target) + 1;
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
|
||||
{
|
||||
write_reg (1, addr, &rels);
|
||||
write_jump (1, &rels);
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_backward (void *ptr0, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
void *ptr = ptr0;
|
||||
write_reg (8, (grub_uint64_t) src, &ptr);
|
||||
write_reg (9, (grub_uint64_t) dest, &ptr);
|
||||
write_reg (10, (grub_uint64_t) size, &ptr);
|
||||
grub_memcpy (ptr, &grub_relocator_backward_start,
|
||||
RELOCATOR_SRC_SIZEOF (backward));
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_forward (void *ptr0, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
void *ptr = ptr0;
|
||||
write_reg (8, (grub_uint64_t) src, &ptr);
|
||||
write_reg (9, (grub_uint64_t) dest, &ptr);
|
||||
write_reg (10, (grub_uint64_t) size, &ptr);
|
||||
grub_memcpy (ptr, &grub_relocator_forward_start,
|
||||
RELOCATOR_SRC_SIZEOF (forward));
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_relocator64_boot (struct grub_relocator *rel,
|
||||
struct grub_relocator64_state state)
|
||||
{
|
||||
grub_relocator_chunk_t ch;
|
||||
void *ptr;
|
||||
grub_err_t err;
|
||||
void *relst;
|
||||
grub_size_t relsize;
|
||||
grub_size_t stateset_size = 31 * REGW_SIZEOF + JUMP_SIZEOF;
|
||||
unsigned i;
|
||||
grub_addr_t vtarget;
|
||||
|
||||
err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
|
||||
(0xffffffff - stateset_size)
|
||||
+ 1, stateset_size,
|
||||
grub_relocator_align,
|
||||
GRUB_RELOCATOR_PREFERENCE_NONE, 0);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
ptr = get_virtual_current_address (ch);
|
||||
for (i = 1; i < 32; i++)
|
||||
write_reg (i, state.gpr[i], &ptr);
|
||||
write_jump (state.jumpreg, &ptr);
|
||||
|
||||
vtarget = (grub_addr_t) grub_map_memory (get_physical_target_address (ch),
|
||||
stateset_size);
|
||||
|
||||
err = grub_relocator_prepare_relocs (rel, vtarget, &relst, &relsize);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_arch_sync_caches ((void *) relst, relsize);
|
||||
|
||||
((void (*) (void)) relst) ();
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
56
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/relocator_asm.S
Normal file
56
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/relocator_asm.S
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2017 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>
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
.set push
|
||||
.set noreorder
|
||||
.set nomacro
|
||||
|
||||
VARIABLE (grub_relocator_forward_start)
|
||||
|
||||
copycont1:
|
||||
ld $11,0($8)
|
||||
sd $11,0($9)
|
||||
daddiu $8, $8, 8
|
||||
daddiu $10, $10, -8
|
||||
bne $10, $0, copycont1
|
||||
daddiu $9, $9, 8
|
||||
|
||||
VARIABLE (grub_relocator_forward_end)
|
||||
|
||||
VARIABLE (grub_relocator_backward_start)
|
||||
|
||||
daddu $9, $9, $10
|
||||
daddu $8, $8, $10
|
||||
/* Backward movsl is implicitly off-by-one. compensate that. */
|
||||
daddiu $9, $9, -8
|
||||
daddiu $8, $8, -8
|
||||
copycont2:
|
||||
ld $11,0($8)
|
||||
sd $11,0($9)
|
||||
daddiu $8, $8, -8
|
||||
daddiu $10, $10, -8
|
||||
bne $10, $0, copycont2
|
||||
daddiu $9, $9, -8
|
||||
|
||||
VARIABLE (grub_relocator_backward_end)
|
||||
|
||||
.set pop
|
69
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/setjmp.S
Normal file
69
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/mips64/setjmp.S
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003,2007,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/dl.h>
|
||||
#include <grub/mips64/asm.h>
|
||||
|
||||
.file "setjmp.S"
|
||||
|
||||
GRUB_MOD_LICENSE "GPLv3+"
|
||||
|
||||
.text
|
||||
|
||||
/*
|
||||
* int grub_setjmp (grub_jmp_buf env)
|
||||
*/
|
||||
FUNCTION(grub_setjmp)
|
||||
GRUB_ASM_REG_S $s0, 0($a0)
|
||||
GRUB_ASM_REG_S $s1, 8($a0)
|
||||
GRUB_ASM_REG_S $s2, 16($a0)
|
||||
GRUB_ASM_REG_S $s3, 24($a0)
|
||||
GRUB_ASM_REG_S $s4, 32($a0)
|
||||
GRUB_ASM_REG_S $s5, 40($a0)
|
||||
GRUB_ASM_REG_S $s6, 48($a0)
|
||||
GRUB_ASM_REG_S $s7, 56($a0)
|
||||
GRUB_ASM_REG_S $s8, 64($a0)
|
||||
GRUB_ASM_REG_S $gp, 72($a0)
|
||||
GRUB_ASM_REG_S $sp, 80($a0)
|
||||
GRUB_ASM_REG_S $ra, 88($a0)
|
||||
move $v0, $zero
|
||||
move $v1, $zero
|
||||
jr $ra
|
||||
nop
|
||||
/*
|
||||
* int grub_longjmp (grub_jmp_buf env, int val)
|
||||
*/
|
||||
FUNCTION(grub_longjmp)
|
||||
GRUB_ASM_REG_L $s0, 0($a0)
|
||||
GRUB_ASM_REG_L $s1, 8($a0)
|
||||
GRUB_ASM_REG_L $s2, 16($a0)
|
||||
GRUB_ASM_REG_L $s3, 24($a0)
|
||||
GRUB_ASM_REG_L $s4, 32($a0)
|
||||
GRUB_ASM_REG_L $s5, 40($a0)
|
||||
GRUB_ASM_REG_L $s6, 48($a0)
|
||||
GRUB_ASM_REG_L $s7, 56($a0)
|
||||
GRUB_ASM_REG_L $s8, 64($a0)
|
||||
GRUB_ASM_REG_L $gp, 72($a0)
|
||||
GRUB_ASM_REG_L $sp, 80($a0)
|
||||
GRUB_ASM_REG_L $ra, 88($a0)
|
||||
addiu $v0, $zero, 1
|
||||
movn $v0, $a1, $a1
|
||||
move $v1, $zero
|
||||
jr $ra
|
||||
nop
|
1660
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/relocator.c
Normal file
1660
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/relocator.c
Normal file
File diff suppressed because it is too large
Load Diff
26
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/setjmp.S
Normal file
26
GRUB2/MOD_SRC/grub-2.04/grub-core/lib/setjmp.S
Normal file
@@ -0,0 +1,26 @@
|
||||
#if defined(__i386__)
|
||||
#include "./i386/setjmp.S"
|
||||
#elif defined(__x86_64__)
|
||||
#include "./x86_64/setjmp.S"
|
||||
#elif defined(__sparc__)
|
||||
#include "./sparc64/setjmp.S"
|
||||
#elif defined(__mips__)
|
||||
#if _MIPS_SIM == _ABI64
|
||||
#include "./mips64/setjmp.S"
|
||||
#else
|
||||
#include "./mips/setjmp.S"
|
||||
#endif
|
||||
#elif defined(__powerpc__) || defined(__PPC__)
|
||||
#include "./powerpc/setjmp.S"
|
||||
#elif defined(__ia64__)
|
||||
#include "./ia64/setjmp.S"
|
||||
#include "./ia64/longjmp.S"
|
||||
#elif defined(__arm__)
|
||||
#include "./arm/setjmp.S"
|
||||
#elif defined(__aarch64__)
|
||||
#include "./arm64/setjmp.S"
|
||||
#elif defined(__riscv)
|
||||
#include "./riscv/setjmp.S"
|
||||
#else
|
||||
#error "Unknown target cpu type"
|
||||
#endif
|
1023
GRUB2/MOD_SRC/grub-2.04/grub-core/loader/mips64/linux.c
Normal file
1023
GRUB2/MOD_SRC/grub-2.04/grub-core/loader/mips64/linux.c
Normal file
File diff suppressed because it is too large
Load Diff
463
GRUB2/MOD_SRC/grub-2.04/grub-core/term/serial.c
Normal file
463
GRUB2/MOD_SRC/grub-2.04/grub-core/term/serial.c
Normal file
@@ -0,0 +1,463 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2000,2001,2002,2003,2004,2005,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
|
||||
* 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/serial.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/terminfo.h>
|
||||
#if !defined (GRUB_MACHINE_EMU) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
|
||||
#include <grub/cpu/io.h>
|
||||
#endif
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/list.h>
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
#include <grub/machine/kernel.h>
|
||||
#endif
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
#include <grub/ieee1275/console.h>
|
||||
#endif
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports))
|
||||
|
||||
enum
|
||||
{
|
||||
OPTION_UNIT,
|
||||
OPTION_PORT,
|
||||
OPTION_SPEED,
|
||||
OPTION_WORD,
|
||||
OPTION_PARITY,
|
||||
OPTION_STOP,
|
||||
OPTION_BASE_CLOCK,
|
||||
OPTION_RTSCTS
|
||||
};
|
||||
|
||||
/* Argument options. */
|
||||
static const struct grub_arg_option options[] =
|
||||
{
|
||||
{"unit", 'u', 0, N_("Set the serial unit."), 0, ARG_TYPE_INT},
|
||||
{"port", 'p', 0, N_("Set the serial port address."), 0, ARG_TYPE_STRING},
|
||||
{"speed", 's', 0, N_("Set the serial port speed."), 0, ARG_TYPE_INT},
|
||||
{"word", 'w', 0, N_("Set the serial port word length."), 0, ARG_TYPE_INT},
|
||||
{"parity", 'r', 0, N_("Set the serial port parity."), 0, ARG_TYPE_STRING},
|
||||
{"stop", 't', 0, N_("Set the serial port stop bits."), 0, ARG_TYPE_INT},
|
||||
{"base-clock", 'b', 0, N_("Set the base frequency."), 0, ARG_TYPE_STRING},
|
||||
{"rtscts", 'f', 0, N_("Enable/disable RTS/CTS."), "on|off", ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static struct grub_serial_port *grub_serial_ports;
|
||||
|
||||
struct grub_serial_output_state
|
||||
{
|
||||
struct grub_terminfo_output_state tinfo;
|
||||
struct grub_serial_port *port;
|
||||
};
|
||||
|
||||
struct grub_serial_input_state
|
||||
{
|
||||
struct grub_terminfo_input_state tinfo;
|
||||
struct grub_serial_port *port;
|
||||
};
|
||||
|
||||
static void
|
||||
serial_put (grub_term_output_t term, const int c)
|
||||
{
|
||||
struct grub_serial_output_state *data = term->data;
|
||||
data->port->driver->put (data->port, c);
|
||||
}
|
||||
|
||||
static int
|
||||
serial_fetch (grub_term_input_t term)
|
||||
{
|
||||
struct grub_serial_input_state *data = term->data;
|
||||
return data->port->driver->fetch (data->port);
|
||||
}
|
||||
|
||||
static const struct grub_serial_input_state grub_serial_terminfo_input_template =
|
||||
{
|
||||
.tinfo =
|
||||
{
|
||||
.readkey = serial_fetch
|
||||
}
|
||||
};
|
||||
|
||||
static const struct grub_serial_output_state grub_serial_terminfo_output_template =
|
||||
{
|
||||
.tinfo =
|
||||
{
|
||||
.put = serial_put,
|
||||
.size = { 80, 24 }
|
||||
}
|
||||
};
|
||||
|
||||
static struct grub_serial_input_state grub_serial_terminfo_input;
|
||||
|
||||
static struct grub_serial_output_state grub_serial_terminfo_output;
|
||||
|
||||
static int registered = 0;
|
||||
|
||||
static struct grub_term_input grub_serial_term_input =
|
||||
{
|
||||
.name = "serial",
|
||||
.init = grub_terminfo_input_init,
|
||||
.getkey = grub_terminfo_getkey,
|
||||
.data = &grub_serial_terminfo_input
|
||||
};
|
||||
|
||||
static struct grub_term_output grub_serial_term_output =
|
||||
{
|
||||
.name = "serial",
|
||||
.init = grub_terminfo_output_init,
|
||||
.putchar = grub_terminfo_putchar,
|
||||
.getwh = grub_terminfo_getwh,
|
||||
.getxy = grub_terminfo_getxy,
|
||||
.gotoxy = grub_terminfo_gotoxy,
|
||||
.cls = grub_terminfo_cls,
|
||||
.setcolorstate = grub_terminfo_setcolorstate,
|
||||
.setcursor = grub_terminfo_setcursor,
|
||||
.flags = GRUB_TERM_CODE_TYPE_ASCII,
|
||||
.data = &grub_serial_terminfo_output,
|
||||
.progress_update_divisor = GRUB_PROGRESS_SLOW
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct grub_serial_port *
|
||||
grub_serial_find (const char *name)
|
||||
{
|
||||
struct grub_serial_port *port;
|
||||
|
||||
FOR_SERIAL_PORTS (port)
|
||||
if (grub_strcmp (port->name, name) == 0)
|
||||
break;
|
||||
|
||||
#if ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__)) && !defined(GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC)
|
||||
if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) == 0
|
||||
&& grub_isxdigit (name [sizeof ("port") - 1]))
|
||||
{
|
||||
name = grub_serial_ns8250_add_port (grub_strtoul (&name[sizeof ("port") - 1],
|
||||
0, 16));
|
||||
if (!name)
|
||||
return NULL;
|
||||
|
||||
FOR_SERIAL_PORTS (port)
|
||||
if (grub_strcmp (port->name, name) == 0)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
|
||||
{
|
||||
name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
|
||||
if (!name)
|
||||
return NULL;
|
||||
|
||||
FOR_SERIAL_PORTS (port)
|
||||
if (grub_strcmp (port->name, name) == 0)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
struct grub_arg_list *state = ctxt->state;
|
||||
char pname[40];
|
||||
const char *name = NULL;
|
||||
struct grub_serial_port *port;
|
||||
struct grub_serial_config config;
|
||||
grub_err_t err;
|
||||
|
||||
if (state[OPTION_UNIT].set)
|
||||
{
|
||||
grub_snprintf (pname, sizeof (pname), "com%ld",
|
||||
grub_strtoul (state[0].arg, 0, 0));
|
||||
name = pname;
|
||||
}
|
||||
|
||||
if (state[OPTION_PORT].set)
|
||||
{
|
||||
grub_snprintf (pname, sizeof (pname), "port%lx",
|
||||
grub_strtoul (state[1].arg, 0, 0));
|
||||
name = pname;
|
||||
}
|
||||
|
||||
if (argc >= 1)
|
||||
name = args[0];
|
||||
|
||||
if (!name)
|
||||
name = "com0";
|
||||
|
||||
port = grub_serial_find (name);
|
||||
if (!port)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("serial port `%s' isn't found"),
|
||||
name);
|
||||
|
||||
config = port->config;
|
||||
|
||||
if (state[OPTION_SPEED].set) {
|
||||
config.speed = grub_strtoul (state[OPTION_SPEED].arg, 0, 0);
|
||||
if (config.speed == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("unsupported serial port parity"));
|
||||
}
|
||||
|
||||
if (state[OPTION_WORD].set)
|
||||
config.word_len = grub_strtoul (state[OPTION_WORD].arg, 0, 0);
|
||||
|
||||
if (state[OPTION_PARITY].set)
|
||||
{
|
||||
if (! grub_strcmp (state[OPTION_PARITY].arg, "no"))
|
||||
config.parity = GRUB_SERIAL_PARITY_NONE;
|
||||
else if (! grub_strcmp (state[OPTION_PARITY].arg, "odd"))
|
||||
config.parity = GRUB_SERIAL_PARITY_ODD;
|
||||
else if (! grub_strcmp (state[OPTION_PARITY].arg, "even"))
|
||||
config.parity = GRUB_SERIAL_PARITY_EVEN;
|
||||
else
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("unsupported serial port parity"));
|
||||
}
|
||||
|
||||
if (state[OPTION_RTSCTS].set)
|
||||
{
|
||||
if (grub_strcmp (state[OPTION_RTSCTS].arg, "on") == 0)
|
||||
config.rtscts = 1;
|
||||
else if (grub_strcmp (state[OPTION_RTSCTS].arg, "off") == 0)
|
||||
config.rtscts = 0;
|
||||
else
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("unsupported serial port flow control"));
|
||||
}
|
||||
|
||||
if (state[OPTION_STOP].set)
|
||||
{
|
||||
if (! grub_strcmp (state[OPTION_STOP].arg, "1"))
|
||||
config.stop_bits = GRUB_SERIAL_STOP_BITS_1;
|
||||
else if (! grub_strcmp (state[OPTION_STOP].arg, "2"))
|
||||
config.stop_bits = GRUB_SERIAL_STOP_BITS_2;
|
||||
else if (! grub_strcmp (state[OPTION_STOP].arg, "1.5"))
|
||||
config.stop_bits = GRUB_SERIAL_STOP_BITS_1_5;
|
||||
else
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("unsupported serial port stop bits number"));
|
||||
}
|
||||
|
||||
if (state[OPTION_BASE_CLOCK].set)
|
||||
{
|
||||
char *ptr;
|
||||
config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
if (ptr && *ptr == 'M')
|
||||
config.base_clock *= 1000000;
|
||||
if (ptr && (*ptr == 'k' || *ptr == 'K'))
|
||||
config.base_clock *= 1000;
|
||||
}
|
||||
|
||||
if (config.speed == 0)
|
||||
config.speed = 9600;
|
||||
|
||||
/* Initialize with new settings. */
|
||||
err = port->driver->configure (port, &config);
|
||||
if (err)
|
||||
return err;
|
||||
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
|
||||
|
||||
/* Compatibility kludge. */
|
||||
if (port->driver == &grub_ns8250_driver)
|
||||
{
|
||||
if (!registered)
|
||||
{
|
||||
grub_terminfo_output_register (&grub_serial_term_output, "vt100");
|
||||
|
||||
grub_term_register_input ("serial", &grub_serial_term_input);
|
||||
grub_term_register_output ("serial", &grub_serial_term_output);
|
||||
}
|
||||
grub_serial_terminfo_output.port = port;
|
||||
grub_serial_terminfo_input.port = port;
|
||||
registered = 1;
|
||||
}
|
||||
#endif
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
const char loongson_defserial[][6] =
|
||||
{
|
||||
[GRUB_ARCH_MACHINE_YEELOONG] = "com0",
|
||||
[GRUB_ARCH_MACHINE_FULOONG2F] = "com2",
|
||||
[GRUB_ARCH_MACHINE_FULOONG2E] = "com1"
|
||||
};
|
||||
#endif
|
||||
|
||||
grub_err_t
|
||||
grub_serial_register (struct grub_serial_port *port)
|
||||
{
|
||||
struct grub_term_input *in;
|
||||
struct grub_term_output *out;
|
||||
struct grub_serial_input_state *indata;
|
||||
struct grub_serial_output_state *outdata;
|
||||
|
||||
in = grub_malloc (sizeof (*in));
|
||||
if (!in)
|
||||
return grub_errno;
|
||||
|
||||
indata = grub_malloc (sizeof (*indata));
|
||||
if (!indata)
|
||||
{
|
||||
grub_free (in);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_memcpy (in, &grub_serial_term_input, sizeof (*in));
|
||||
in->data = indata;
|
||||
in->name = grub_xasprintf ("serial_%s", port->name);
|
||||
grub_memcpy (indata, &grub_serial_terminfo_input, sizeof (*indata));
|
||||
|
||||
if (!in->name)
|
||||
{
|
||||
grub_free (in);
|
||||
grub_free (indata);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
out = grub_zalloc (sizeof (*out));
|
||||
if (!out)
|
||||
{
|
||||
grub_free (indata);
|
||||
grub_free ((char *) in->name);
|
||||
grub_free (in);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
outdata = grub_malloc (sizeof (*outdata));
|
||||
if (!outdata)
|
||||
{
|
||||
grub_free (indata);
|
||||
grub_free ((char *) in->name);
|
||||
grub_free (out);
|
||||
grub_free (in);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_memcpy (out, &grub_serial_term_output, sizeof (*out));
|
||||
out->data = outdata;
|
||||
out->name = in->name;
|
||||
grub_memcpy (outdata, &grub_serial_terminfo_output, sizeof (*outdata));
|
||||
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_serial_ports), GRUB_AS_LIST (port));
|
||||
((struct grub_serial_input_state *) in->data)->port = port;
|
||||
((struct grub_serial_output_state *) out->data)->port = port;
|
||||
port->term_in = in;
|
||||
port->term_out = out;
|
||||
grub_terminfo_output_register (out, "vt100");
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
if (grub_strcmp (port->name, loongson_defserial[grub_arch_machine]) == 0)
|
||||
{
|
||||
grub_term_register_input_active ("serial_*", in);
|
||||
grub_term_register_output_active ("serial_*", out);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_term_register_input_inactive ("serial_*", in);
|
||||
grub_term_register_output_inactive ("serial_*", out);
|
||||
}
|
||||
#else
|
||||
grub_term_register_input ("serial_*", in);
|
||||
grub_term_register_output ("serial_*", out);
|
||||
#endif
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
grub_serial_unregister (struct grub_serial_port *port)
|
||||
{
|
||||
if (port->driver->fini)
|
||||
port->driver->fini (port);
|
||||
|
||||
if (port->term_in)
|
||||
grub_term_unregister_input (port->term_in);
|
||||
if (port->term_out)
|
||||
grub_term_unregister_output (port->term_out);
|
||||
|
||||
grub_list_remove (GRUB_AS_LIST (port));
|
||||
}
|
||||
|
||||
void
|
||||
grub_serial_unregister_driver (struct grub_serial_driver *driver)
|
||||
{
|
||||
struct grub_serial_port *port, *next;
|
||||
for (port = grub_serial_ports; port; port = next)
|
||||
{
|
||||
next = port->next;
|
||||
if (port->driver == driver)
|
||||
grub_serial_unregister (port);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_extcmd_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(serial)
|
||||
{
|
||||
cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0,
|
||||
N_("[OPTIONS...]"),
|
||||
N_("Configure serial port."), options);
|
||||
grub_memcpy (&grub_serial_terminfo_output,
|
||||
&grub_serial_terminfo_output_template,
|
||||
sizeof (grub_serial_terminfo_output));
|
||||
|
||||
grub_memcpy (&grub_serial_terminfo_input,
|
||||
&grub_serial_terminfo_input_template,
|
||||
sizeof (grub_serial_terminfo_input));
|
||||
|
||||
#if !defined (GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) && ((defined(__mips__) && _MIPS_SIM != _ABI64) || defined (__i386__) || defined (__x86_64__))
|
||||
grub_ns8250_init ();
|
||||
#endif
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
grub_ofserial_init ();
|
||||
#endif
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
grub_efiserial_init ();
|
||||
#endif
|
||||
#ifdef GRUB_MACHINE_ARC
|
||||
grub_arcserial_init ();
|
||||
#endif
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(serial)
|
||||
{
|
||||
while (grub_serial_ports)
|
||||
grub_serial_unregister (grub_serial_ports);
|
||||
if (registered)
|
||||
{
|
||||
grub_term_unregister_input (&grub_serial_term_input);
|
||||
grub_term_unregister_output (&grub_serial_term_output);
|
||||
}
|
||||
grub_unregister_extcmd (cmd);
|
||||
}
|
@@ -1427,6 +1427,11 @@ static int ventoy_arch_mode_init(void)
|
||||
g_ventoy_plat_data = VTOY_PLAT_ARM64_UEFI;
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "aa64");
|
||||
}
|
||||
else if (grub_strcmp(GRUB_TARGET_CPU, "mips64el") == 0)
|
||||
{
|
||||
g_ventoy_plat_data = VTOY_PLAT_MIPS_UEFI;
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "mips");
|
||||
}
|
||||
else
|
||||
{
|
||||
g_ventoy_plat_data = VTOY_PLAT_X86_64_UEFI;
|
||||
|
@@ -56,6 +56,16 @@
|
||||
#define VTOY_PLAT_ARM64_UEFI 0x41413634
|
||||
#define VTOY_PLAT_X86_64_UEFI 0x55454649
|
||||
#define VTOY_PLAT_X86_LEGACY 0x42494f53
|
||||
#define VTOY_PLAT_MIPS_UEFI 0x4D495053
|
||||
|
||||
#define VTOY_COMM_CPIO "ventoy.cpio"
|
||||
#if defined(__arm__) || defined(__aarch64__)
|
||||
#define VTOY_ARCH_CPIO "ventoy_arm64.cpio"
|
||||
#elif defined(__mips__)
|
||||
#define VTOY_ARCH_CPIO "ventoy_mips64.cpio"
|
||||
#else
|
||||
#define VTOY_ARCH_CPIO "ventoy_x86.cpio"
|
||||
#endif
|
||||
|
||||
#define VTOY_PWD_CORRUPTED(err) \
|
||||
{\
|
||||
|
@@ -1124,6 +1124,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
grub_uint32_t injection_size = 0;
|
||||
grub_uint32_t dud_size = 0;
|
||||
grub_file_t file;
|
||||
grub_file_t archfile;
|
||||
grub_file_t tmpfile;
|
||||
ventoy_img_chunk_list chunk_list;
|
||||
|
||||
@@ -1142,12 +1143,21 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
|
||||
img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_COMM_CPIO);
|
||||
if (!file)
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_COMM_CPIO);
|
||||
}
|
||||
|
||||
archfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/%s", args[0], VTOY_ARCH_CPIO);
|
||||
if (!archfile)
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], VTOY_ARCH_CPIO);
|
||||
grub_file_close(file);
|
||||
}
|
||||
|
||||
debug("load %s %s success\n", VTOY_COMM_CPIO, VTOY_ARCH_CPIO);
|
||||
|
||||
if (g_ventoy_cpio_buf)
|
||||
{
|
||||
grub_free(g_ventoy_cpio_buf);
|
||||
@@ -1234,22 +1244,29 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
debug("dud not configed %s\n", args[1]);
|
||||
}
|
||||
|
||||
g_ventoy_cpio_buf = grub_malloc(file->size + 40960 + template_size +
|
||||
g_ventoy_cpio_buf = grub_malloc(file->size + archfile->size + 40960 + template_size +
|
||||
persistent_size + injection_size + dud_size + img_chunk_size);
|
||||
if (NULL == g_ventoy_cpio_buf)
|
||||
{
|
||||
grub_file_close(file);
|
||||
grub_file_close(archfile);
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size);
|
||||
}
|
||||
|
||||
grub_file_read(file, g_ventoy_cpio_buf, file->size);
|
||||
|
||||
buf = (grub_uint8_t *)(g_ventoy_cpio_buf + file->size - 4);
|
||||
while (*((grub_uint32_t *)buf) != 0x37303730)
|
||||
{
|
||||
buf -= 4;
|
||||
}
|
||||
|
||||
grub_file_read(archfile, buf, archfile->size);
|
||||
buf += (archfile->size - 4);
|
||||
while (*((grub_uint32_t *)buf) != 0x37303730)
|
||||
{
|
||||
buf -= 4;
|
||||
}
|
||||
|
||||
/* get initrd head len */
|
||||
initrd_head_len = ventoy_cpio_newc_fill_head(buf, 0, NULL, "initrd000.xx");
|
||||
|
||||
@@ -1313,6 +1330,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
ventoy_cpio_newc_fill_head(g_ventoy_initrd_head, 0, NULL, "initrd000.xx");
|
||||
|
||||
grub_file_close(file);
|
||||
grub_file_close(archfile);
|
||||
|
||||
if (grub_strcmp(args[3], "busybox=64") == 0)
|
||||
{
|
||||
@@ -1324,6 +1342,11 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
debug("cpio busybox proc %s\n", args[3]);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "a64");
|
||||
}
|
||||
else if (grub_strcmp(args[3], "busybox=m64") == 0)
|
||||
{
|
||||
debug("cpio busybox proc %s\n", args[3]);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "m64");
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user