12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192 |
- /*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 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/loader.h>
- #include <grub/i386/bsd.h>
- #include <grub/i386/cpuid.h>
- #include <grub/memory.h>
- #include <grub/i386/memory.h>
- #include <grub/file.h>
- #include <grub/err.h>
- #include <grub/dl.h>
- #include <grub/mm.h>
- #include <grub/elfload.h>
- #include <grub/env.h>
- #include <grub/misc.h>
- #include <grub/aout.h>
- #include <grub/command.h>
- #include <grub/extcmd.h>
- #include <grub/i18n.h>
- #include <grub/ns8250.h>
- #include <grub/bsdlabel.h>
- #include <grub/crypto.h>
- #include <grub/safemath.h>
- #include <grub/verify.h>
- #ifdef GRUB_MACHINE_PCBIOS
- #include <grub/machine/int.h>
- #endif
- GRUB_MOD_LICENSE ("GPLv3+");
- #include <grub/video.h>
- #ifdef GRUB_MACHINE_PCBIOS
- #include <grub/machine/biosnum.h>
- #endif
- #ifdef GRUB_MACHINE_EFI
- #include <grub/efi/efi.h>
- #define NETBSD_DEFAULT_VIDEO_MODE "800x600"
- #else
- #define NETBSD_DEFAULT_VIDEO_MODE "text"
- #include <grub/i386/pc/vbe.h>
- #endif
- #include <grub/video.h>
- #include <grub/disk.h>
- #include <grub/device.h>
- #include <grub/partition.h>
- #include <grub/relocator.h>
- #include <grub/i386/relocator.h>
- #define ALIGN_DWORD(a) ALIGN_UP (a, 4)
- #define ALIGN_QWORD(a) ALIGN_UP (a, 8)
- #define ALIGN_VAR(a) ((is_64bit) ? (ALIGN_QWORD(a)) : (ALIGN_DWORD(a)))
- #define ALIGN_PAGE(a) ALIGN_UP (a, 4096)
- static int kernel_type = KERNEL_TYPE_NONE;
- static grub_dl_t my_mod;
- static grub_addr_t entry, entry_hi, kern_start, kern_end;
- static void *kern_chunk_src;
- static grub_uint32_t bootflags;
- static int is_elf_kernel, is_64bit;
- static grub_uint32_t openbsd_root;
- static struct grub_relocator *relocator = NULL;
- static struct grub_openbsd_ramdisk_descriptor openbsd_ramdisk;
- struct bsd_tag
- {
- struct bsd_tag *next;
- grub_size_t len;
- grub_uint32_t type;
- union {
- grub_uint8_t a;
- grub_uint16_t b;
- grub_uint32_t c;
- } data[0];
- };
- static struct bsd_tag *tags, *tags_last;
- struct netbsd_module
- {
- struct netbsd_module *next;
- struct grub_netbsd_btinfo_module mod;
- };
- static struct netbsd_module *netbsd_mods, *netbsd_mods_last;
- static const struct grub_arg_option freebsd_opts[] =
- {
- {"dual", 'D', 0, N_("Display output on all consoles."), 0, 0},
- {"serial", 'h', 0, N_("Use serial console."), 0, 0},
- {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
- {"cdrom", 'C', 0, N_("Use CD-ROM as root."), 0, 0},
- {"config", 'c', 0, N_("Invoke user configuration routing."), 0, 0},
- {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
- {"gdb", 'g', 0, N_("Use GDB remote debugger instead of DDB."), 0, 0},
- {"mute", 'm', 0, N_("Disable all boot output."), 0, 0},
- {"nointr", 'n', 0, "", 0, 0},
- {"pause", 'p', 0, N_("Wait for keypress after every line of output."), 0, 0},
- {"quiet", 'q', 0, "", 0, 0},
- {"dfltroot", 'r', 0, N_("Use compiled-in root device."), 0, 0},
- {"single", 's', 0, N_("Boot into single mode."), 0, 0},
- {"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0},
- {0, 0, 0, 0, 0, 0}
- };
- static const grub_uint32_t freebsd_flags[] =
- {
- FREEBSD_RB_DUAL, FREEBSD_RB_SERIAL, FREEBSD_RB_ASKNAME,
- FREEBSD_RB_CDROM, FREEBSD_RB_CONFIG, FREEBSD_RB_KDB,
- FREEBSD_RB_GDB, FREEBSD_RB_MUTE, FREEBSD_RB_NOINTR,
- FREEBSD_RB_PAUSE, FREEBSD_RB_QUIET, FREEBSD_RB_DFLTROOT,
- FREEBSD_RB_SINGLE, FREEBSD_RB_VERBOSE, 0
- };
- static const struct grub_arg_option openbsd_opts[] =
- {
- {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
- {"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0},
- {"config", 'c', 0, N_("Change configured devices."), 0, 0},
- {"single", 's', 0, N_("Boot into single mode."), 0, 0},
- {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
- {"root", 'r', 0, N_("Set root device."), "wdXY", ARG_TYPE_STRING},
- {"serial", 'h', GRUB_ARG_OPTION_OPTIONAL,
- N_("Use serial console."),
- /* TRANSLATORS: "com" is static and not to be translated. It refers to
- serial ports e.g. com1.
- */
- N_("comUNIT[,SPEED]"), ARG_TYPE_STRING},
- {0, 0, 0, 0, 0, 0}
- };
- static const grub_uint32_t openbsd_flags[] =
- {
- OPENBSD_RB_ASKNAME, OPENBSD_RB_HALT, OPENBSD_RB_CONFIG,
- OPENBSD_RB_SINGLE, OPENBSD_RB_KDB, 0
- };
- #define OPENBSD_ROOT_ARG (ARRAY_SIZE (openbsd_flags) - 1)
- #define OPENBSD_SERIAL_ARG (ARRAY_SIZE (openbsd_flags))
- static const struct grub_arg_option netbsd_opts[] =
- {
- {"no-smp", '1', 0, N_("Disable SMP."), 0, 0},
- {"no-acpi", '2', 0, N_("Disable ACPI."), 0, 0},
- {"askname", 'a', 0, N_("Ask for file name to reboot from."), 0, 0},
- {"halt", 'b', 0, N_("Don't reboot, just halt."), 0, 0},
- {"config", 'c', 0, N_("Change configured devices."), 0, 0},
- {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
- {"miniroot", 'm', 0, "", 0, 0},
- {"quiet", 'q', 0, N_("Don't display boot diagnostic messages."), 0, 0},
- {"single", 's', 0, N_("Boot into single mode."), 0, 0},
- {"verbose", 'v', 0, N_("Boot with verbose messages."), 0, 0},
- {"debug", 'x', 0, N_("Boot with debug messages."), 0, 0},
- {"silent", 'z', 0, N_("Suppress normal output (warnings remain)."), 0, 0},
- {"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING},
- {"serial", 'h', GRUB_ARG_OPTION_OPTIONAL,
- N_("Use serial console."),
- /* TRANSLATORS: "com" is static and not to be translated. It refers to
- serial ports e.g. com1.
- */
- N_("[ADDR|comUNIT][,SPEED]"), ARG_TYPE_STRING},
- {0, 0, 0, 0, 0, 0}
- };
- static const grub_uint32_t netbsd_flags[] =
- {
- NETBSD_AB_NOSMP, NETBSD_AB_NOACPI, NETBSD_RB_ASKNAME,
- NETBSD_RB_HALT, NETBSD_RB_USERCONFIG, NETBSD_RB_KDB,
- NETBSD_RB_MINIROOT, NETBSD_AB_QUIET, NETBSD_RB_SINGLE,
- NETBSD_AB_VERBOSE, NETBSD_AB_DEBUG, NETBSD_AB_SILENT, 0
- };
- #define NETBSD_ROOT_ARG (ARRAY_SIZE (netbsd_flags) - 1)
- #define NETBSD_SERIAL_ARG (ARRAY_SIZE (netbsd_flags))
- static void
- grub_bsd_get_device (grub_uint32_t * biosdev,
- grub_uint32_t * unit,
- grub_uint32_t * slice, grub_uint32_t * part)
- {
- grub_device_t dev;
- #ifdef GRUB_MACHINE_PCBIOS
- *biosdev = grub_get_root_biosnumber () & 0xff;
- #else
- *biosdev = 0xff;
- #endif
- *unit = (*biosdev & 0x7f);
- *slice = 0xff;
- *part = 0xff;
- dev = grub_device_open (0);
- if (dev && dev->disk && dev->disk->partition)
- {
- if (dev->disk->partition->parent)
- {
- *part = dev->disk->partition->number;
- *slice = dev->disk->partition->parent->number + 1;
- }
- else
- *slice = dev->disk->partition->number + 1;
- }
- if (dev)
- grub_device_close (dev);
- }
- static grub_err_t
- grub_bsd_add_meta_ptr (grub_uint32_t type, void **ptr, grub_uint32_t len)
- {
- struct bsd_tag *newtag;
- newtag = grub_malloc (len + sizeof (struct bsd_tag));
- if (!newtag)
- return grub_errno;
- newtag->len = len;
- newtag->type = type;
- newtag->next = NULL;
- *ptr = newtag->data;
- if (kernel_type == KERNEL_TYPE_FREEBSD
- && type == (FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_SMAP))
- {
- struct bsd_tag *p;
- for (p = tags;
- p && p->type != (FREEBSD_MODINFO_METADATA
- | FREEBSD_MODINFOMD_KERNEND);
- p = p->next);
- if (p)
- {
- newtag->next = p->next;
- p->next = newtag;
- if (newtag->next == NULL)
- tags_last = newtag;
- return GRUB_ERR_NONE;
- }
- }
- if (tags_last)
- tags_last->next = newtag;
- else
- tags = newtag;
- tags_last = newtag;
- return GRUB_ERR_NONE;
- }
- grub_err_t
- grub_bsd_add_meta (grub_uint32_t type, const void *data, grub_uint32_t len)
- {
- grub_err_t err;
- void *ptr = NULL;
- err = grub_bsd_add_meta_ptr (type, &ptr, len);
- if (err)
- return err;
- if (len)
- grub_memcpy (ptr, data, len);
- return GRUB_ERR_NONE;
- }
- struct grub_e820_mmap
- {
- grub_uint64_t addr;
- grub_uint64_t size;
- grub_uint32_t type;
- } GRUB_PACKED;
- #define GRUB_E820_RAM 1
- #define GRUB_E820_RESERVED 2
- #define GRUB_E820_ACPI 3
- #define GRUB_E820_NVS 4
- #define GRUB_E820_BADRAM 5
- #define GRUB_E820_COREBOOT_TABLES 0x10
- /* Context for generate_e820_mmap. */
- struct generate_e820_mmap_ctx
- {
- int count;
- struct grub_e820_mmap *mmap;
- struct grub_e820_mmap prev, cur;
- };
- /* Helper for generate_e820_mmap. */
- static int
- generate_e820_mmap_iter (grub_uint64_t addr, grub_uint64_t size,
- grub_memory_type_t type, void *data)
- {
- struct generate_e820_mmap_ctx *ctx = data;
- ctx->cur.addr = addr;
- ctx->cur.size = size;
- if (type == GRUB_MEMORY_COREBOOT_TABLES
- && addr == 0)
- /* Nowadays the tables at 0 don't contain anything important but
- *BSD needs the memory at 0 for own needs.
- */
- type = GRUB_E820_RAM;
- ctx->cur.type = type;
- /* Merge regions if possible. */
- if (ctx->count && ctx->cur.type == ctx->prev.type
- && ctx->cur.addr == ctx->prev.addr + ctx->prev.size)
- {
- ctx->prev.size += ctx->cur.size;
- if (ctx->mmap)
- ctx->mmap[-1] = ctx->prev;
- }
- else
- {
- if (ctx->mmap)
- *ctx->mmap++ = ctx->cur;
- ctx->prev = ctx->cur;
- ctx->count++;
- }
- if (kernel_type == KERNEL_TYPE_OPENBSD && ctx->prev.addr < 0x100000
- && ctx->prev.addr + ctx->prev.size > 0x100000)
- {
- ctx->cur.addr = 0x100000;
- ctx->cur.size = ctx->prev.addr + ctx->prev.size - 0x100000;
- ctx->cur.type = ctx->prev.type;
- ctx->prev.size = 0x100000 - ctx->prev.addr;
- if (ctx->mmap)
- {
- ctx->mmap[-1] = ctx->prev;
- ctx->mmap[0] = ctx->cur;
- ctx->mmap++;
- }
- ctx->prev = ctx->cur;
- ctx->count++;
- }
- return 0;
- }
- static void
- generate_e820_mmap (grub_size_t *len, grub_size_t *cnt, void *buf)
- {
- struct generate_e820_mmap_ctx ctx = {
- .count = 0,
- .mmap = buf
- };
- grub_mmap_iterate (generate_e820_mmap_iter, &ctx);
- if (len)
- *len = ctx.count * sizeof (struct grub_e820_mmap);
- *cnt = ctx.count;
- return;
- }
- static grub_err_t
- grub_bsd_add_mmap (void)
- {
- grub_size_t len, cnt;
- void *buf = NULL, *buf0;
- generate_e820_mmap (&len, &cnt, buf);
- if (kernel_type == KERNEL_TYPE_NETBSD)
- len += sizeof (grub_uint32_t);
- if (kernel_type == KERNEL_TYPE_OPENBSD)
- len += sizeof (struct grub_e820_mmap);
- buf = grub_malloc (len);
- if (!buf)
- return grub_errno;
- buf0 = buf;
- if (kernel_type == KERNEL_TYPE_NETBSD)
- {
- *(grub_uint32_t *) buf = cnt;
- buf = ((grub_uint32_t *) buf + 1);
- }
- generate_e820_mmap (NULL, &cnt, buf);
- if (kernel_type == KERNEL_TYPE_OPENBSD)
- grub_memset ((grub_uint8_t *) buf + len - sizeof (struct grub_e820_mmap), 0,
- sizeof (struct grub_e820_mmap));
- grub_dprintf ("bsd", "%u entries in smap\n", (unsigned) cnt);
- if (kernel_type == KERNEL_TYPE_NETBSD)
- grub_bsd_add_meta (NETBSD_BTINFO_MEMMAP, buf0, len);
- else if (kernel_type == KERNEL_TYPE_OPENBSD)
- grub_bsd_add_meta (OPENBSD_BOOTARG_MMAP, buf0, len);
- else
- grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
- FREEBSD_MODINFOMD_SMAP, buf0, len);
- grub_free (buf0);
- return grub_errno;
- }
- grub_err_t
- grub_freebsd_add_meta_module (const char *filename, const char *type,
- int argc, char **argv,
- grub_addr_t addr, grub_uint32_t size)
- {
- const char *name;
- grub_err_t err;
- name = grub_strrchr (filename, '/');
- if (name)
- name++;
- else
- name = filename;
- if (grub_strcmp (type, "/boot/zfs/zpool.cache") == 0)
- name = "/boot/zfs/zpool.cache";
- if (grub_bsd_add_meta (FREEBSD_MODINFO_NAME, name, grub_strlen (name) + 1))
- return grub_errno;
- if (is_64bit)
- {
- grub_uint64_t addr64 = addr, size64 = size;
- if (grub_bsd_add_meta (FREEBSD_MODINFO_TYPE, type, grub_strlen (type) + 1)
- || grub_bsd_add_meta (FREEBSD_MODINFO_ADDR, &addr64, sizeof (addr64))
- || grub_bsd_add_meta (FREEBSD_MODINFO_SIZE, &size64, sizeof (size64)))
- return grub_errno;
- }
- else
- {
- if (grub_bsd_add_meta (FREEBSD_MODINFO_TYPE, type, grub_strlen (type) + 1)
- || grub_bsd_add_meta (FREEBSD_MODINFO_ADDR, &addr, sizeof (addr))
- || grub_bsd_add_meta (FREEBSD_MODINFO_SIZE, &size, sizeof (size)))
- return grub_errno;
- }
- if (argc)
- {
- int i, n;
- n = 0;
- for (i = 0; i < argc; i++)
- {
- n += grub_strlen (argv[i]) + 1;
- }
- if (n)
- {
- void *cmdline;
- char *p;
- if (grub_bsd_add_meta_ptr (FREEBSD_MODINFO_ARGS, &cmdline, n))
- return grub_errno;
- p = cmdline;
- for (i = 0; i < argc; i++)
- {
- grub_strcpy (p, argv[i]);
- p += grub_strlen (argv[i]);
- *(p++) = ' ';
- }
- *p = 0;
- err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE);
- if (err)
- return err;
- }
- }
- return GRUB_ERR_NONE;
- }
- static void
- grub_freebsd_list_modules (void)
- {
- struct bsd_tag *tag;
- grub_printf (" %-18s %-18s%14s%14s\n", _("name"), _("type"), _("addr"),
- _("size"));
- for (tag = tags; tag; tag = tag->next)
- {
- switch (tag->type)
- {
- case FREEBSD_MODINFO_NAME:
- case FREEBSD_MODINFO_TYPE:
- grub_printf (" %-18s", (char *) tag->data);
- break;
- case FREEBSD_MODINFO_ADDR:
- {
- grub_uint32_t addr;
- addr = *((grub_uint32_t *) tag->data);
- grub_printf (" 0x%08x", addr);
- break;
- }
- case FREEBSD_MODINFO_SIZE:
- {
- grub_uint32_t len;
- len = *((grub_uint32_t *) tag->data);
- grub_printf (" 0x%08x\n", len);
- }
- }
- }
- }
- static grub_err_t
- grub_netbsd_add_meta_module (char *filename, grub_uint32_t type,
- grub_addr_t addr, grub_uint32_t size)
- {
- char *name;
- struct netbsd_module *mod;
- name = grub_strrchr (filename, '/');
- if (name)
- name++;
- else
- name = filename;
- mod = grub_zalloc (sizeof (*mod));
- if (!mod)
- return grub_errno;
- grub_strncpy (mod->mod.name, name, sizeof (mod->mod.name) - 1);
- mod->mod.addr = addr;
- mod->mod.type = type;
- mod->mod.size = size;
- if (netbsd_mods_last)
- netbsd_mods_last->next = mod;
- else
- netbsd_mods = mod;
- netbsd_mods_last = mod;
- return GRUB_ERR_NONE;
- }
- static void
- grub_netbsd_list_modules (void)
- {
- struct netbsd_module *mod;
- grub_printf (" %-18s%14s%14s%14s\n", _("name"), _("type"), _("addr"),
- _("size"));
- for (mod = netbsd_mods; mod; mod = mod->next)
- grub_printf (" %-18s 0x%08x 0x%08x 0x%08x", mod->mod.name,
- mod->mod.type, mod->mod.addr, mod->mod.size);
- }
- /* This function would be here but it's under different license. */
- #include "bsd_pagetable.c"
- static grub_uint32_t freebsd_bootdev, freebsd_biosdev;
- static grub_uint64_t freebsd_zfsguid;
- static void
- freebsd_get_zfs (void)
- {
- grub_device_t dev;
- grub_fs_t fs;
- char *uuid;
- grub_err_t err;
- dev = grub_device_open (0);
- if (!dev)
- return;
- fs = grub_fs_probe (dev);
- if (!fs)
- return;
- if (!fs->fs_uuid || grub_strcmp (fs->name, "zfs") != 0)
- return;
- err = fs->fs_uuid (dev, &uuid);
- if (err)
- return;
- if (!uuid)
- return;
- freebsd_zfsguid = grub_strtoull (uuid, 0, 16);
- grub_free (uuid);
- }
- static grub_err_t
- grub_freebsd_boot (void)
- {
- struct grub_freebsd_bootinfo bi;
- grub_uint8_t *p, *p0;
- grub_addr_t p_target;
- grub_size_t p_size = 0;
- grub_err_t err;
- grub_size_t tag_buf_len = 0;
- struct grub_env_var *var;
- grub_memset (&bi, 0, sizeof (bi));
- bi.version = FREEBSD_BOOTINFO_VERSION;
- bi.length = sizeof (bi);
- bi.boot_device = freebsd_biosdev;
- p_size = 0;
- FOR_SORTED_ENV (var)
- if ((grub_memcmp (var->name, "kFreeBSD.", sizeof("kFreeBSD.") - 1) == 0) && (var->name[sizeof("kFreeBSD.") - 1]))
- {
- p_size += grub_strlen (&var->name[sizeof("kFreeBSD.") - 1]);
- p_size++;
- p_size += grub_strlen (var->value) + 1;
- }
- if (p_size)
- p_size = ALIGN_PAGE (kern_end + p_size + 1) - kern_end;
- if (is_elf_kernel)
- {
- struct bsd_tag *tag;
- err = grub_bsd_add_mmap ();
- if (err)
- return err;
- err = grub_bsd_add_meta (FREEBSD_MODINFO_END, 0, 0);
- if (err)
- return err;
- tag_buf_len = 0;
- for (tag = tags; tag; tag = tag->next)
- tag_buf_len = ALIGN_VAR (tag_buf_len
- + sizeof (struct freebsd_tag_header)
- + tag->len);
- p_size = ALIGN_PAGE (kern_end + p_size + tag_buf_len) - kern_end;
- }
- if (is_64bit)
- p_size += 4096 * 3;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch,
- kern_end, p_size);
- if (err)
- return err;
- p = get_virtual_current_address (ch);
- }
- p_target = kern_end;
- p0 = p;
- kern_end += p_size;
- FOR_SORTED_ENV (var)
- if ((grub_memcmp (var->name, "kFreeBSD.", sizeof("kFreeBSD.") - 1) == 0) && (var->name[sizeof("kFreeBSD.") - 1]))
- {
- grub_strcpy ((char *) p, &var->name[sizeof("kFreeBSD.") - 1]);
- p += grub_strlen ((char *) p);
- *(p++) = '=';
- grub_strcpy ((char *) p, var->value);
- p += grub_strlen ((char *) p) + 1;
- }
- if (p != p0)
- {
- *(p++) = 0;
- bi.environment = p_target;
- }
- if (is_elf_kernel)
- {
- grub_uint8_t *p_tag = p;
- struct bsd_tag *tag;
- for (tag = tags; tag; tag = tag->next)
- {
- struct freebsd_tag_header *head
- = (struct freebsd_tag_header *) p_tag;
- head->type = tag->type;
- head->len = tag->len;
- p_tag += sizeof (struct freebsd_tag_header);
- switch (tag->type)
- {
- case FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_HOWTO:
- if (is_64bit)
- *(grub_uint64_t *) p_tag = bootflags;
- else
- *(grub_uint32_t *) p_tag = bootflags;
- break;
- case FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_ENVP:
- if (is_64bit)
- *(grub_uint64_t *) p_tag = bi.environment;
- else
- *(grub_uint32_t *) p_tag = bi.environment;
- break;
- case FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_KERNEND:
- if (is_64bit)
- *(grub_uint64_t *) p_tag = kern_end;
- else
- *(grub_uint32_t *) p_tag = kern_end;
- break;
- default:
- grub_memcpy (p_tag, tag->data, tag->len);
- break;
- }
- p_tag += tag->len;
- p_tag = ALIGN_VAR (p_tag - p) + p;
- }
- bi.tags = (p - p0) + p_target;
- p = (ALIGN_PAGE ((p_tag - p0) + p_target) - p_target) + p0;
- }
- bi.kern_end = kern_end;
- grub_video_set_mode ("text", 0, 0);
- if (is_64bit)
- {
- struct grub_relocator64_state state = {0};
- grub_uint8_t *pagetable;
- grub_uint32_t *stack;
- grub_addr_t stack_target;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_align (relocator, &ch,
- 0x10000, 0x90000,
- 3 * sizeof (grub_uint32_t)
- + sizeof (bi), 4,
- GRUB_RELOCATOR_PREFERENCE_NONE,
- 0);
- if (err)
- return err;
- stack = get_virtual_current_address (ch);
- stack_target = get_physical_target_address (ch);
- }
- #ifdef GRUB_MACHINE_EFI
- err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
- if (err)
- return err;
- #endif
- pagetable = p;
- fill_bsd64_pagetable (pagetable, (pagetable - p0) + p_target);
- state.cr3 = (pagetable - p0) + p_target;
- state.rsp = stack_target;
- state.rip = (((grub_uint64_t) entry_hi) << 32) | entry;
- stack[0] = entry;
- stack[1] = bi.tags;
- stack[2] = kern_end;
- return grub_relocator64_boot (relocator, state, 0, 0x40000000);
- }
- else
- {
- struct grub_relocator32_state state = {0};
- grub_uint32_t *stack;
- grub_addr_t stack_target;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_align (relocator, &ch,
- 0x10000, 0x90000,
- 9 * sizeof (grub_uint32_t)
- + sizeof (bi), 4,
- GRUB_RELOCATOR_PREFERENCE_NONE,
- 0);
- if (err)
- return err;
- stack = get_virtual_current_address (ch);
- stack_target = get_physical_target_address (ch);
- }
- #ifdef GRUB_MACHINE_EFI
- err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
- if (err)
- return err;
- #endif
- grub_memcpy (&stack[9], &bi, sizeof (bi));
- state.eip = entry;
- state.esp = stack_target;
- state.ebp = stack_target;
- stack[0] = entry; /* "Return" address. */
- stack[1] = bootflags | FREEBSD_RB_BOOTINFO;
- stack[2] = freebsd_bootdev;
- stack[3] = freebsd_zfsguid ? 4 : 0;
- stack[4] = freebsd_zfsguid;
- stack[5] = freebsd_zfsguid >> 32;
- stack[6] = stack_target + 9 * sizeof (grub_uint32_t);
- stack[7] = bi.tags;
- stack[8] = kern_end;
- return grub_relocator32_boot (relocator, state, 0);
- }
- /* Not reached. */
- return GRUB_ERR_NONE;
- }
- static grub_err_t
- grub_openbsd_boot (void)
- {
- grub_uint32_t *stack;
- struct grub_relocator32_state state;
- void *curarg, *buf0, *arg0;
- grub_addr_t buf_target;
- grub_err_t err;
- grub_size_t tag_buf_len;
- err = grub_bsd_add_mmap ();
- if (err)
- return err;
- #ifdef GRUB_MACHINE_PCBIOS
- {
- struct grub_bios_int_registers regs;
- regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
- regs.ebx = 0;
- regs.ecx = 0;
- regs.eax = 0xb101;
- regs.es = 0;
- regs.edi = 0;
- regs.edx = 0;
- grub_bios_interrupt (0x1a, ®s);
- if (regs.edx == 0x20494350)
- {
- struct grub_openbsd_bootarg_pcibios pcibios;
- pcibios.characteristics = regs.eax & 0xff;
- pcibios.revision = regs.ebx & 0xffff;
- pcibios.pm_entry = regs.edi;
- pcibios.last_bus = regs.ecx & 0xff;
- grub_bsd_add_meta (OPENBSD_BOOTARG_PCIBIOS, &pcibios,
- sizeof (pcibios));
- }
- }
- #endif
- {
- struct bsd_tag *tag;
- tag_buf_len = 0;
- for (tag = tags; tag; tag = tag->next)
- tag_buf_len = ALIGN_VAR (tag_buf_len
- + sizeof (struct grub_openbsd_bootargs)
- + tag->len);
- }
- buf_target = GRUB_BSD_TEMP_BUFFER - 9 * sizeof (grub_uint32_t);
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch, buf_target,
- tag_buf_len
- + sizeof (struct grub_openbsd_bootargs)
- + 9 * sizeof (grub_uint32_t));
- if (err)
- return err;
- buf0 = get_virtual_current_address (ch);
- }
- stack = (grub_uint32_t *) buf0;
- arg0 = curarg = stack + 9;
- {
- struct bsd_tag *tag;
- struct grub_openbsd_bootargs *head;
- for (tag = tags; tag; tag = tag->next)
- {
- head = curarg;
- head->ba_type = tag->type;
- head->ba_size = tag->len + sizeof (*head);
- curarg = head + 1;
- grub_memcpy (curarg, tag->data, tag->len);
- curarg = (grub_uint8_t *) curarg + tag->len;
- head->ba_next = (grub_uint8_t *) curarg - (grub_uint8_t *) buf0
- + buf_target;
- }
- head = curarg;
- head->ba_type = OPENBSD_BOOTARG_END;
- head->ba_size = 0;
- head->ba_next = 0;
- }
- grub_video_set_mode ("text", 0, 0);
- #ifdef GRUB_MACHINE_EFI
- err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
- if (err)
- return err;
- #endif
- state.eip = entry;
- state.ebp = state.esp
- = ((grub_uint8_t *) stack - (grub_uint8_t *) buf0) + buf_target;
- stack[0] = entry;
- stack[1] = bootflags;
- stack[2] = openbsd_root;
- stack[3] = OPENBSD_BOOTARG_APIVER;
- stack[4] = 0;
- stack[5] = grub_mmap_get_upper () >> 10;
- stack[6] = grub_mmap_get_lower () >> 10;
- stack[7] = (grub_uint8_t *) curarg - (grub_uint8_t *) arg0;
- stack[8] = ((grub_uint8_t *) arg0 - (grub_uint8_t *) buf0) + buf_target;
- return grub_relocator32_boot (relocator, state, 0);
- }
- static grub_err_t
- grub_netbsd_setup_video (void)
- {
- struct grub_video_mode_info mode_info;
- void *framebuffer;
- const char *modevar;
- struct grub_netbsd_btinfo_framebuf params = {0};
- grub_err_t err;
- grub_video_driver_id_t driv_id;
- modevar = grub_env_get ("gfxpayload");
- /* Now all graphical modes are acceptable.
- May change in future if we have modes without framebuffer. */
- if (modevar && *modevar != 0)
- {
- char *tmp;
- tmp = grub_xasprintf ("%s;" NETBSD_DEFAULT_VIDEO_MODE, modevar);
- if (! tmp)
- return grub_errno;
- err = grub_video_set_mode (tmp, 0, 0);
- grub_free (tmp);
- }
- else
- err = grub_video_set_mode (NETBSD_DEFAULT_VIDEO_MODE, 0, 0);
- if (err)
- return err;
- driv_id = grub_video_get_driver_id ();
- if (driv_id == GRUB_VIDEO_DRIVER_NONE)
- return GRUB_ERR_NONE;
- err = grub_video_get_info_and_fini (&mode_info, &framebuffer);
- if (err)
- return err;
- params.width = mode_info.width;
- params.height = mode_info.height;
- params.bpp = mode_info.bpp;
- params.pitch = mode_info.pitch;
- params.flags = 0;
- params.fbaddr = (grub_addr_t) framebuffer;
- params.red_mask_size = mode_info.red_mask_size;
- params.red_field_pos = mode_info.red_field_pos;
- params.green_mask_size = mode_info.green_mask_size;
- params.green_field_pos = mode_info.green_field_pos;
- params.blue_mask_size = mode_info.blue_mask_size;
- params.blue_field_pos = mode_info.blue_field_pos;
- #ifdef GRUB_MACHINE_PCBIOS
- /* VESA packed modes may come with zeroed mask sizes, which need
- to be set here according to DAC Palette width. If we don't,
- this results in Linux displaying a black screen. */
- if (mode_info.bpp <= 8 && driv_id == GRUB_VIDEO_DRIVER_VBE)
- {
- struct grub_vbe_info_block controller_info;
- int status;
- int width = 8;
- status = grub_vbe_bios_get_controller_info (&controller_info);
- if (status == GRUB_VBE_STATUS_OK &&
- (controller_info.capabilities & GRUB_VBE_CAPABILITY_DACWIDTH))
- status = grub_vbe_bios_set_dac_palette_width (&width);
- if (status != GRUB_VBE_STATUS_OK)
- /* 6 is default after mode reset. */
- width = 6;
- params.red_mask_size = params.green_mask_size
- = params.blue_mask_size = width;
- }
- #endif
- err = grub_bsd_add_meta (NETBSD_BTINFO_FRAMEBUF, ¶ms, sizeof (params));
- return err;
- }
- static grub_err_t
- grub_netbsd_add_modules (void)
- {
- struct netbsd_module *mod;
- unsigned modcnt = 0;
- struct grub_netbsd_btinfo_modules *mods;
- unsigned i;
- grub_err_t err;
- grub_size_t sz;
- for (mod = netbsd_mods; mod; mod = mod->next)
- modcnt++;
- if (grub_mul (modcnt, sizeof (mods->mods[0]), &sz) ||
- grub_add (sz, sizeof (*mods), &sz))
- return GRUB_ERR_OUT_OF_RANGE;
- mods = grub_malloc (sz);
- if (!mods)
- return grub_errno;
- mods->num = modcnt;
- mods->last_addr = kern_end;
- for (mod = netbsd_mods, i = 0; mod; i++, mod = mod->next)
- mods->mods[i] = mod->mod;
- err = grub_bsd_add_meta (NETBSD_BTINFO_MODULES, mods,
- sizeof (*mods) + sizeof (mods->mods[0]) * modcnt);
- grub_free (mods);
- return err;
- }
- /*
- * Adds NetBSD bootinfo bootdisk and bootwedge. The partition identified
- * in these bootinfo fields is the root device.
- */
- static void
- grub_netbsd_add_boot_disk_and_wedge (void)
- {
- grub_device_t dev;
- grub_disk_t disk;
- grub_partition_t part;
- grub_uint32_t biosdev;
- grub_uint32_t partmapsector;
- union {
- grub_uint64_t raw[GRUB_DISK_SECTOR_SIZE / 8];
- struct grub_partition_bsd_disk_label label;
- } buf;
- if (GRUB_MD_MD5->mdlen > GRUB_CRYPTO_MAX_MDLEN)
- {
- grub_error (GRUB_ERR_BUG, "mdlen too long");
- return;
- }
- dev = grub_device_open (0);
- if (! (dev && dev->disk && dev->disk->partition))
- goto fail;
- disk = dev->disk;
- part = disk->partition;
- if (disk->dev && disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID)
- biosdev = (grub_uint32_t) disk->id & 0xff;
- else
- biosdev = 0xff;
- /* Absolute sector of the partition map describing this partition. */
- partmapsector = grub_partition_get_start (part->parent) + part->offset;
- disk->partition = part->parent;
- if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf.raw)
- != GRUB_ERR_NONE)
- goto fail;
- disk->partition = part;
- /* Fill bootwedge. */
- {
- struct grub_netbsd_btinfo_bootwedge biw;
- grub_uint8_t hash[GRUB_CRYPTO_MAX_MDLEN];
- grub_memset (&biw, 0, sizeof (biw));
- biw.biosdev = biosdev;
- biw.startblk = grub_partition_get_start (part);
- biw.nblks = part->len;
- biw.matchblk = partmapsector;
- biw.matchnblks = 1;
- grub_crypto_hash (GRUB_MD_MD5, hash,
- buf.raw, GRUB_DISK_SECTOR_SIZE);
- grub_memcpy (biw.matchhash, hash, 16);
- grub_bsd_add_meta (NETBSD_BTINFO_BOOTWEDGE, &biw, sizeof (biw));
- }
- /* Fill bootdisk. */
- {
- struct grub_netbsd_btinfo_bootdisk bid;
- grub_memset (&bid, 0, sizeof (bid));
- /* Check for a NetBSD disk label. */
- if (part->partmap != NULL &&
- (grub_strcmp (part->partmap->name, "netbsd") == 0 ||
- (part->parent == NULL && grub_strcmp (part->partmap->name, "bsd") == 0)))
- {
- bid.labelsector = partmapsector;
- bid.label.type = buf.label.type;
- bid.label.checksum = buf.label.checksum;
- grub_memcpy (bid.label.packname, buf.label.packname, 16);
- }
- else
- {
- bid.labelsector = -1;
- }
- bid.biosdev = biosdev;
- bid.partition = part->number;
- grub_bsd_add_meta (NETBSD_BTINFO_BOOTDISK, &bid, sizeof (bid));
- }
- fail:
- if (dev)
- grub_device_close (dev);
- }
- static grub_err_t
- grub_netbsd_boot (void)
- {
- struct grub_netbsd_bootinfo *bootinfo;
- void *curarg, *arg0;
- grub_addr_t arg_target, stack_target;
- grub_uint32_t *stack;
- grub_err_t err;
- struct grub_relocator32_state state;
- grub_size_t tag_buf_len = 0;
- int tag_count = 0;
- err = grub_bsd_add_mmap ();
- if (err)
- return err;
- err = grub_netbsd_setup_video ();
- if (err)
- {
- grub_print_error ();
- grub_puts_ (N_("Booting in blind mode"));
- grub_errno = GRUB_ERR_NONE;
- }
- err = grub_netbsd_add_modules ();
- if (err)
- return err;
- #ifdef GRUB_MACHINE_EFI
- err = grub_bsd_add_meta (NETBSD_BTINFO_EFI,
- &grub_efi_system_table,
- sizeof (grub_efi_system_table));
- if (err)
- return err;
- #endif
- {
- struct bsd_tag *tag;
- tag_buf_len = 0;
- for (tag = tags; tag; tag = tag->next)
- {
- tag_buf_len = ALIGN_VAR (tag_buf_len
- + sizeof (struct grub_netbsd_btinfo_common)
- + tag->len);
- tag_count++;
- }
- }
- arg_target = kern_end;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch,
- arg_target, tag_buf_len
- + sizeof (struct grub_netbsd_bootinfo)
- + tag_count * sizeof (grub_uint32_t));
- if (err)
- return err;
- curarg = get_virtual_current_address (ch);
- }
- arg0 = curarg;
- bootinfo = (void *) ((grub_uint8_t *) arg0 + tag_buf_len);
- {
- struct bsd_tag *tag;
- unsigned i;
- bootinfo->bi_count = tag_count;
- for (tag = tags, i = 0; tag; i++, tag = tag->next)
- {
- struct grub_netbsd_btinfo_common *head = curarg;
- bootinfo->bi_data[i] = ((grub_uint8_t *) curarg - (grub_uint8_t *) arg0)
- + arg_target;
- head->type = tag->type;
- head->len = tag->len + sizeof (*head);
- curarg = head + 1;
- grub_memcpy (curarg, tag->data, tag->len);
- curarg = (grub_uint8_t *) curarg + tag->len;
- }
- }
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x10000, 0x90000,
- 7 * sizeof (grub_uint32_t), 4,
- GRUB_RELOCATOR_PREFERENCE_NONE,
- 0);
- if (err)
- return err;
- stack = get_virtual_current_address (ch);
- stack_target = get_physical_target_address (ch);
- }
- #ifdef GRUB_MACHINE_EFI
- err = grub_efi_finish_boot_services (NULL, NULL, NULL, NULL, NULL);
- if (err)
- return err;
- #endif
- state.eip = entry;
- state.esp = stack_target;
- state.ebp = stack_target;
- stack[0] = entry;
- stack[1] = bootflags;
- stack[2] = 0;
- stack[3] = ((grub_uint8_t *) bootinfo - (grub_uint8_t *) arg0) + arg_target;
- stack[4] = 0;
- stack[5] = grub_mmap_get_upper () >> 10;
- stack[6] = grub_mmap_get_lower () >> 10;
- return grub_relocator32_boot (relocator, state, 0);
- }
- static grub_err_t
- grub_bsd_unload (void)
- {
- struct bsd_tag *tag, *next;
- for (tag = tags; tag; tag = next)
- {
- next = tag->next;
- grub_free (tag);
- }
- tags = NULL;
- tags_last = NULL;
- kernel_type = KERNEL_TYPE_NONE;
- grub_dl_unref (my_mod);
- grub_relocator_unload (relocator);
- relocator = NULL;
- return GRUB_ERR_NONE;
- }
- static grub_err_t
- grub_bsd_load_aout (grub_file_t file, const char *filename)
- {
- grub_addr_t load_addr, load_end;
- int ofs, align_page;
- union grub_aout_header ah;
- grub_err_t err;
- grub_size_t bss_size;
- if ((grub_file_seek (file, 0)) == (grub_off_t) - 1)
- return grub_errno;
- if (grub_file_read (file, &ah, sizeof (ah)) != sizeof (ah))
- {
- if (!grub_errno)
- grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
- filename);
- return grub_errno;
- }
- if (grub_aout_get_type (&ah) != AOUT_TYPE_AOUT32)
- return grub_error (GRUB_ERR_BAD_OS, "invalid a.out header");
- entry = ah.aout32.a_entry & 0xFFFFFF;
- if (AOUT_GETMAGIC (ah.aout32) == AOUT32_ZMAGIC)
- {
- load_addr = entry;
- ofs = 0x1000;
- align_page = 0;
- }
- else
- {
- load_addr = entry & 0xF00000;
- ofs = sizeof (struct grub_aout32_header);
- align_page = 1;
- }
- if (load_addr < 0x100000)
- return grub_error (GRUB_ERR_BAD_OS, "load address below 1M");
- kern_start = load_addr;
- load_end = kern_end = load_addr + ah.aout32.a_text + ah.aout32.a_data;
- if (align_page)
- kern_end = ALIGN_PAGE (kern_end);
- if (ah.aout32.a_bss)
- {
- kern_end += ah.aout32.a_bss;
- if (align_page)
- kern_end = ALIGN_PAGE (kern_end);
- bss_size = kern_end - load_end;
- }
- else
- bss_size = 0;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch,
- kern_start, kern_end - kern_start);
- if (err)
- return err;
- kern_chunk_src = get_virtual_current_address (ch);
- }
- return grub_aout_load (file, ofs, kern_chunk_src,
- ah.aout32.a_text + ah.aout32.a_data,
- bss_size);
- }
- static grub_err_t
- grub_bsd_load_elf (grub_elf_t elf, const char *filename)
- {
- grub_err_t err;
- kern_end = 0;
- kern_start = ~0;
- if (grub_elf_is_elf32 (elf))
- {
- grub_relocator_chunk_t ch;
- Elf32_Phdr *phdr;
- entry = elf->ehdr.ehdr32.e_entry & 0xFFFFFFF;
- FOR_ELF32_PHDRS (elf, phdr)
- {
- Elf32_Addr paddr;
- if (phdr->p_type != PT_LOAD
- && phdr->p_type != PT_DYNAMIC)
- continue;
- paddr = phdr->p_paddr & 0xFFFFFFF;
- if (paddr < kern_start)
- kern_start = paddr;
- if (paddr + phdr->p_memsz > kern_end)
- kern_end = paddr + phdr->p_memsz;
- }
- if (grub_errno)
- return grub_errno;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch,
- kern_start, kern_end - kern_start);
- if (err)
- return err;
- kern_chunk_src = get_virtual_current_address (ch);
- err = grub_elf32_load (elf, filename, (grub_uint8_t *) kern_chunk_src - kern_start, GRUB_ELF_LOAD_FLAGS_LOAD_PT_DYNAMIC | GRUB_ELF_LOAD_FLAGS_28BITS, 0, 0);
- if (err)
- return err;
- if (kernel_type != KERNEL_TYPE_OPENBSD)
- return GRUB_ERR_NONE;
- return grub_openbsd_find_ramdisk32 (elf->file, filename, kern_start,
- kern_chunk_src, &openbsd_ramdisk);
- }
- else if (grub_elf_is_elf64 (elf))
- {
- Elf64_Phdr *phdr;
- is_64bit = 1;
- if (! grub_cpuid_has_longmode)
- return grub_error (GRUB_ERR_BAD_OS, "your CPU does not implement AMD64 architecture");
- /* FreeBSD has 64-bit entry point. */
- if (kernel_type == KERNEL_TYPE_FREEBSD)
- {
- entry = elf->ehdr.ehdr64.e_entry & 0xffffffff;
- entry_hi = (elf->ehdr.ehdr64.e_entry >> 32) & 0xffffffff;
- }
- else
- {
- entry = elf->ehdr.ehdr64.e_entry & 0x0fffffff;
- entry_hi = 0;
- }
- FOR_ELF64_PHDRS (elf, phdr)
- {
- Elf64_Addr paddr;
- if (phdr->p_type != PT_LOAD
- && phdr->p_type != PT_DYNAMIC)
- continue;
- paddr = phdr->p_paddr & 0xFFFFFFF;
- if (paddr < kern_start)
- kern_start = paddr;
- if (paddr + phdr->p_memsz > kern_end)
- kern_end = paddr + phdr->p_memsz;
- }
- if (grub_errno)
- return grub_errno;
- grub_dprintf ("bsd", "kern_start = %lx, kern_end = %lx\n",
- (unsigned long) kern_start, (unsigned long) kern_end);
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_start,
- kern_end - kern_start);
- if (err)
- return err;
- kern_chunk_src = get_virtual_current_address (ch);
- }
- err = grub_elf64_load (elf, filename,
- (grub_uint8_t *) kern_chunk_src - kern_start, GRUB_ELF_LOAD_FLAGS_LOAD_PT_DYNAMIC | GRUB_ELF_LOAD_FLAGS_28BITS, 0, 0);
- if (err)
- return err;
- if (kernel_type != KERNEL_TYPE_OPENBSD)
- return GRUB_ERR_NONE;
- return grub_openbsd_find_ramdisk64 (elf->file, filename, kern_start,
- kern_chunk_src, &openbsd_ramdisk);
- }
- else
- return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
- }
- static grub_err_t
- grub_bsd_load (int argc, char *argv[])
- {
- grub_file_t file;
- grub_elf_t elf;
- grub_dl_ref (my_mod);
- grub_loader_unset ();
- grub_memset (&openbsd_ramdisk, 0, sizeof (openbsd_ramdisk));
- if (argc == 0)
- {
- grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
- goto fail;
- }
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
- if (!file)
- goto fail;
- relocator = grub_relocator_new ();
- if (!relocator)
- {
- grub_file_close (file);
- goto fail;
- }
- elf = grub_elf_file (file, argv[0]);
- if (elf)
- {
- is_elf_kernel = 1;
- grub_bsd_load_elf (elf, argv[0]);
- grub_elf_close (elf);
- }
- else
- {
- is_elf_kernel = 0;
- grub_errno = 0;
- grub_bsd_load_aout (file, argv[0]);
- grub_file_close (file);
- }
- kern_end = ALIGN_PAGE (kern_end);
- fail:
- if (grub_errno != GRUB_ERR_NONE)
- grub_dl_unref (my_mod);
- return grub_errno;
- }
- static grub_uint32_t
- grub_bsd_parse_flags (const struct grub_arg_list *state,
- const grub_uint32_t * flags)
- {
- grub_uint32_t result = 0;
- unsigned i;
- for (i = 0; flags[i]; i++)
- if (state[i].set)
- result |= flags[i];
- return result;
- }
- static grub_err_t
- grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
- {
- kernel_type = KERNEL_TYPE_FREEBSD;
- bootflags = grub_bsd_parse_flags (ctxt->state, freebsd_flags);
- if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE)
- {
- grub_uint32_t unit, slice, part;
- kern_end = ALIGN_PAGE (kern_end);
- if (is_elf_kernel)
- {
- grub_err_t err;
- grub_uint64_t data = 0;
- grub_file_t file;
- int len = is_64bit ? 8 : 4;
- err = grub_freebsd_add_meta_module (argv[0], is_64bit
- ? FREEBSD_MODTYPE_KERNEL64
- : FREEBSD_MODTYPE_KERNEL,
- argc - 1, argv + 1,
- kern_start,
- kern_end - kern_start);
- if (err)
- return err;
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
- if (! file)
- return grub_errno;
- if (is_64bit)
- err = grub_freebsd_load_elf_meta64 (relocator, file, argv[0],
- &kern_end);
- else
- err = grub_freebsd_load_elf_meta32 (relocator, file, argv[0],
- &kern_end);
- if (err)
- return err;
- err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
- FREEBSD_MODINFOMD_HOWTO, &data, 4);
- if (err)
- return err;
- err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
- FREEBSD_MODINFOMD_ENVP, &data, len);
- if (err)
- return err;
- err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
- FREEBSD_MODINFOMD_KERNEND, &data, len);
- if (err)
- return err;
- }
- grub_bsd_get_device (&freebsd_biosdev, &unit, &slice, &part);
- freebsd_zfsguid = 0;
- if (!is_64bit)
- freebsd_get_zfs ();
- grub_print_error ();
- freebsd_bootdev = (FREEBSD_B_DEVMAGIC + ((slice + 1) << FREEBSD_B_SLICESHIFT) +
- (unit << FREEBSD_B_UNITSHIFT) + (part << FREEBSD_B_PARTSHIFT));
- grub_loader_set (grub_freebsd_boot, grub_bsd_unload, 0);
- }
- return grub_errno;
- }
- static const char *types[] = {
- [0] = "wd",
- [2] = "fd",
- [4] = "sd",
- [6] = "cd",
- [14] = "vnd",
- [17] = "rd"
- };
- static grub_err_t
- grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
- {
- grub_uint32_t bootdev;
- kernel_type = KERNEL_TYPE_OPENBSD;
- bootflags = grub_bsd_parse_flags (ctxt->state, openbsd_flags);
- if (ctxt->state[OPENBSD_ROOT_ARG].set && ctxt->state[OPENBSD_ROOT_ARG].arg != NULL)
- {
- const char *arg = ctxt->state[OPENBSD_ROOT_ARG].arg;
- unsigned type, unit, part;
- for (type = 0; type < ARRAY_SIZE (types); type++)
- if (types[type]
- && grub_strncmp (arg, types[type],
- grub_strlen (types[type])) == 0)
- {
- arg += grub_strlen (types[type]);
- break;
- }
- if (type == ARRAY_SIZE (types))
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "unknown disk type name");
- unit = grub_strtoul (arg, &arg, 10);
- if (! (*arg >= 'a' && *arg <= 'z'))
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only device specifications of form "
- "<type><number><lowercase letter> are supported");
- part = *arg - 'a';
- bootdev = (OPENBSD_B_DEVMAGIC | (type << OPENBSD_B_TYPESHIFT)
- | (unit << OPENBSD_B_UNITSHIFT)
- | (part << OPENBSD_B_PARTSHIFT));
- }
- else
- bootdev = 0;
- if (ctxt->state[OPENBSD_SERIAL_ARG].set)
- {
- struct grub_openbsd_bootarg_console serial;
- const char *ptr;
- unsigned port = 0;
- unsigned speed = 9600;
- grub_memset (&serial, 0, sizeof (serial));
- if (ctxt->state[OPENBSD_SERIAL_ARG].arg)
- {
- ptr = ctxt->state[OPENBSD_SERIAL_ARG].arg;
- if (grub_memcmp (ptr, "com", sizeof ("com") - 1) != 0)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only com0-com3 are supported");
- ptr += sizeof ("com") - 1;
- port = grub_strtoul (ptr, &ptr, 0);
- if (port >= 4)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only com0-com3 are supported");
- if (*ptr == ',')
- {
- ptr++;
- speed = grub_strtoul (ptr, &ptr, 0);
- if (grub_errno)
- return grub_errno;
- }
- }
- serial.device = (GRUB_OPENBSD_COM_MAJOR << 8) | port;
- serial.speed = speed;
- serial.addr = grub_ns8250_hw_get_port (port);
- grub_bsd_add_meta (OPENBSD_BOOTARG_CONSOLE, &serial, sizeof (serial));
- bootflags |= OPENBSD_RB_SERCONS;
- }
- else
- {
- struct grub_openbsd_bootarg_console serial;
- grub_memset (&serial, 0, sizeof (serial));
- serial.device = (GRUB_OPENBSD_VGA_MAJOR << 8);
- serial.addr = 0xffffffff;
- grub_bsd_add_meta (OPENBSD_BOOTARG_CONSOLE, &serial, sizeof (serial));
- bootflags &= ~OPENBSD_RB_SERCONS;
- }
- if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE)
- {
- grub_loader_set (grub_openbsd_boot, grub_bsd_unload, 0);
- openbsd_root = bootdev;
- }
- return grub_errno;
- }
- static grub_err_t
- grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
- {
- grub_err_t err;
- kernel_type = KERNEL_TYPE_NETBSD;
- bootflags = grub_bsd_parse_flags (ctxt->state, netbsd_flags);
- if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE)
- {
- if (is_elf_kernel)
- {
- grub_file_t file;
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
- if (! file)
- return grub_errno;
- if (is_64bit)
- err = grub_netbsd_load_elf_meta64 (relocator, file, argv[0], &kern_end);
- else
- err = grub_netbsd_load_elf_meta32 (relocator, file, argv[0], &kern_end);
- if (err)
- return err;
- }
- {
- char bootpath[GRUB_NETBSD_MAX_BOOTPATH_LEN];
- char *name;
- name = grub_strrchr (argv[0], '/');
- if (name)
- name++;
- else
- name = argv[0];
- grub_memset (bootpath, 0, sizeof (bootpath));
- grub_strncpy (bootpath, name, sizeof (bootpath) - 1);
- grub_bsd_add_meta (NETBSD_BTINFO_BOOTPATH, bootpath, sizeof (bootpath));
- }
- if (ctxt->state[NETBSD_ROOT_ARG].set)
- {
- char root[GRUB_NETBSD_MAX_ROOTDEVICE_LEN];
- grub_memset (root, 0, sizeof (root));
- grub_strncpy (root, ctxt->state[NETBSD_ROOT_ARG].arg,
- sizeof (root) - 1);
- grub_bsd_add_meta (NETBSD_BTINFO_ROOTDEVICE, root, sizeof (root));
- }
- if (ctxt->state[NETBSD_SERIAL_ARG].set)
- {
- struct grub_netbsd_btinfo_serial serial;
- const char *ptr;
- grub_memset (&serial, 0, sizeof (serial));
- grub_strcpy (serial.devname, "com");
- serial.addr = grub_ns8250_hw_get_port (0);
- serial.speed = 9600;
- if (ctxt->state[NETBSD_SERIAL_ARG].arg)
- {
- ptr = ctxt->state[NETBSD_SERIAL_ARG].arg;
- if (grub_memcmp (ptr, "com", sizeof ("com") - 1) == 0)
- {
- ptr += sizeof ("com") - 1;
- serial.addr
- = grub_ns8250_hw_get_port (grub_strtoul (ptr, &ptr, 0));
- }
- else
- serial.addr = grub_strtoul (ptr, &ptr, 0);
- if (grub_errno)
- return grub_errno;
- if (*ptr == ',')
- {
- ptr++;
- serial.speed = grub_strtoul (ptr, &ptr, 0);
- if (grub_errno)
- return grub_errno;
- }
- }
- grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial));
- }
- else
- {
- struct grub_netbsd_btinfo_serial cons;
- grub_memset (&cons, 0, sizeof (cons));
- grub_strcpy (cons.devname, "pc");
- grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &cons, sizeof (cons));
- }
- grub_netbsd_add_boot_disk_and_wedge ();
- grub_loader_set (grub_netbsd_boot, grub_bsd_unload, 0);
- }
- return grub_errno;
- }
- static grub_err_t
- grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
- {
- grub_file_t file = 0;
- char *buf = 0, *curr, *next;
- int len;
- if (! grub_loader_is_loaded ())
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the kernel first"));
- if (kernel_type != KERNEL_TYPE_FREEBSD)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only FreeBSD supports environment");
- if (argc == 0)
- {
- grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
- goto fail;
- }
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV);
- if ((!file) || (!file->size))
- goto fail;
- len = file->size;
- buf = grub_malloc (len + 1);
- if (!buf)
- goto fail;
- if (grub_file_read (file, buf, len) != len)
- goto fail;
- buf[len] = 0;
- next = buf;
- while (next)
- {
- char *p;
- curr = next;
- next = grub_strchr (curr, '\n');
- if (next)
- {
- p = next - 1;
- while (p > curr)
- {
- if ((*p != '\r') && (*p != ' ') && (*p != '\t'))
- break;
- p--;
- }
- if ((p > curr) && (*p == '"'))
- p--;
- *(p + 1) = 0;
- next++;
- }
- if (*curr == '#')
- continue;
- p = grub_strchr (curr, '=');
- if (!p)
- continue;
- *(p++) = 0;
- if (*curr)
- {
- char *name;
- if (*p == '"')
- p++;
- name = grub_xasprintf ("kFreeBSD.%s", curr);
- if (!name)
- goto fail;
- if (grub_env_set (name, p))
- {
- grub_free (name);
- goto fail;
- }
- grub_free (name);
- }
- }
- fail:
- grub_free (buf);
- if (file)
- grub_file_close (file);
- return grub_errno;
- }
- static grub_err_t
- grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
- {
- grub_file_t file = 0;
- int modargc;
- char **modargv;
- const char *type;
- grub_err_t err;
- void *src;
- if (! grub_loader_is_loaded ())
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the kernel first"));
- if (kernel_type != KERNEL_TYPE_FREEBSD)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "no FreeBSD loaded");
- if (!is_elf_kernel)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only ELF kernel supports module");
- /* List the current modules if no parameter. */
- if (!argc)
- {
- grub_freebsd_list_modules ();
- return 0;
- }
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE);
- if ((!file) || (!file->size))
- goto fail;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_end,
- file->size);
- if (err)
- goto fail;
- src = get_virtual_current_address (ch);
- }
- grub_file_read (file, src, file->size);
- if (grub_errno)
- goto fail;
- modargc = argc - 1;
- modargv = argv + 1;
- if (modargc && (! grub_memcmp (modargv[0], "type=", 5)))
- {
- type = &modargv[0][5];
- modargc--;
- modargv++;
- }
- else
- type = FREEBSD_MODTYPE_RAW;
- err = grub_freebsd_add_meta_module (argv[0], type, modargc, modargv,
- kern_end, file->size);
- if (err)
- goto fail;
- kern_end = ALIGN_PAGE (kern_end + file->size);
- fail:
- if (file)
- grub_file_close (file);
- return grub_errno;
- }
- static grub_err_t
- grub_netbsd_module_load (char *filename, grub_uint32_t type)
- {
- grub_file_t file = 0;
- void *src;
- grub_err_t err;
- file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE);
- if ((!file) || (!file->size))
- goto fail;
- {
- grub_relocator_chunk_t ch;
- err = grub_relocator_alloc_chunk_addr (relocator, &ch, kern_end,
- file->size);
- if (err)
- goto fail;
- src = get_virtual_current_address (ch);
- }
- grub_file_read (file, src, file->size);
- if (grub_errno)
- goto fail;
- err = grub_netbsd_add_meta_module (filename, type, kern_end, file->size);
- if (err)
- goto fail;
- kern_end = ALIGN_PAGE (kern_end + file->size);
- fail:
- if (file)
- grub_file_close (file);
- return grub_errno;
- }
- static grub_err_t
- grub_cmd_netbsd_module (grub_command_t cmd,
- int argc, char *argv[])
- {
- grub_uint32_t type;
- if (! grub_loader_is_loaded ())
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the kernel first"));
- if (kernel_type != KERNEL_TYPE_NETBSD)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "no NetBSD loaded");
- if (!is_elf_kernel)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only ELF kernel supports module");
- /* List the current modules if no parameter. */
- if (!argc)
- {
- grub_netbsd_list_modules ();
- return 0;
- }
- if (grub_strcmp (cmd->name, "knetbsd_module_elf") == 0)
- type = GRUB_NETBSD_MODULE_ELF;
- else
- type = GRUB_NETBSD_MODULE_RAW;
- return grub_netbsd_module_load (argv[0], type);
- }
- static grub_err_t
- grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
- {
- grub_file_t file = 0;
- grub_err_t err;
- if (! grub_loader_is_loaded ())
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the kernel first"));
- if (kernel_type != KERNEL_TYPE_FREEBSD)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only FreeBSD supports module");
- if (! is_elf_kernel)
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- "only ELF kernel supports module");
- /* List the current modules if no parameter. */
- if (! argc)
- {
- grub_freebsd_list_modules ();
- return 0;
- }
- file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF);
- if (!file)
- return grub_errno;
- if (!file->size)
- {
- grub_file_close (file);
- return grub_errno;
- }
- if (is_64bit)
- err = grub_freebsd_load_elfmodule_obj64 (relocator, file,
- argc, argv, &kern_end);
- else
- err = grub_freebsd_load_elfmodule32 (relocator, file,
- argc, argv, &kern_end);
- grub_file_close (file);
- return err;
- }
- static grub_err_t
- grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *args[])
- {
- grub_file_t file;
- grub_size_t size;
- if (argc != 1)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
- if (! grub_loader_is_loaded ())
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("you need to load the kernel first"));
- if (kernel_type != KERNEL_TYPE_OPENBSD)
- return grub_error (GRUB_ERR_BAD_OS, "no kOpenBSD loaded");
- if (!openbsd_ramdisk.max_size)
- return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk");
- file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK);
- if (! file)
- return grub_errno;
- size = grub_file_size (file);
- if (size > openbsd_ramdisk.max_size)
- {
- grub_file_close (file);
- return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD supports ramdisk only"
- " up to %" PRIuGRUB_SIZE " bytes, however you supplied"
- " a %" PRIuGRUB_SIZE " bytes one",
- openbsd_ramdisk.max_size, size);
- }
- if (grub_file_read (file, openbsd_ramdisk.target, size)
- != (grub_ssize_t) (size))
- {
- grub_file_close (file);
- if (!grub_errno)
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
- return grub_errno;
- }
- grub_memset (openbsd_ramdisk.target + size, 0,
- openbsd_ramdisk.max_size - size);
- *openbsd_ramdisk.size = ALIGN_UP (size, 512);
- return GRUB_ERR_NONE;
- }
- static grub_extcmd_t cmd_freebsd, cmd_openbsd, cmd_netbsd;
- static grub_command_t cmd_freebsd_loadenv, cmd_freebsd_module;
- static grub_command_t cmd_netbsd_module, cmd_freebsd_module_elf;
- static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk;
- GRUB_MOD_INIT (bsd)
- {
- /* Net and OpenBSD kernels are often compressed. */
- grub_dl_load ("gzio");
- cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd, 0,
- N_("FILE"), N_("Load kernel of FreeBSD."),
- freebsd_opts);
- cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd, 0,
- N_("FILE"), N_("Load kernel of OpenBSD."),
- openbsd_opts);
- cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd, 0,
- N_("FILE"), N_("Load kernel of NetBSD."),
- netbsd_opts);
- cmd_freebsd_loadenv =
- grub_register_command ("kfreebsd_loadenv", grub_cmd_freebsd_loadenv,
- 0, N_("Load FreeBSD env."));
- cmd_freebsd_module =
- grub_register_command ("kfreebsd_module", grub_cmd_freebsd_module,
- 0, N_("Load FreeBSD kernel module."));
- cmd_netbsd_module =
- grub_register_command ("knetbsd_module", grub_cmd_netbsd_module,
- 0, N_("Load NetBSD kernel module."));
- cmd_netbsd_module_elf =
- grub_register_command ("knetbsd_module_elf", grub_cmd_netbsd_module,
- 0, N_("Load NetBSD kernel module (ELF)."));
- cmd_freebsd_module_elf =
- grub_register_command ("kfreebsd_module_elf", grub_cmd_freebsd_module_elf,
- 0, N_("Load FreeBSD kernel module (ELF)."));
- cmd_openbsd_ramdisk = grub_register_command ("kopenbsd_ramdisk",
- grub_cmd_openbsd_ramdisk, 0,
- /* TRANSLATORS: ramdisk isn't identifier,
- it can be translated. */
- N_("Load kOpenBSD ramdisk."));
- my_mod = mod;
- }
- GRUB_MOD_FINI (bsd)
- {
- grub_unregister_extcmd (cmd_freebsd);
- grub_unregister_extcmd (cmd_openbsd);
- grub_unregister_extcmd (cmd_netbsd);
- grub_unregister_command (cmd_freebsd_loadenv);
- grub_unregister_command (cmd_freebsd_module);
- grub_unregister_command (cmd_netbsd_module);
- grub_unregister_command (cmd_freebsd_module_elf);
- grub_unregister_command (cmd_netbsd_module_elf);
- grub_unregister_command (cmd_openbsd_ramdisk);
- grub_bsd_unload ();
- }
|