1ca987d46SWarner Losh /*- 2ca987d46SWarner Losh * Copyright (c) 2012 Andriy Gapon <avg@FreeBSD.org> 3ca987d46SWarner Losh * All rights reserved. 4ca987d46SWarner Losh * 5ca987d46SWarner Losh * Redistribution and use in source and binary forms are freely 6ca987d46SWarner Losh * permitted provided that the above copyright notice and this 7ca987d46SWarner Losh * paragraph and the following disclaimer are duplicated in all 8ca987d46SWarner Losh * such forms. 9ca987d46SWarner Losh * 10ca987d46SWarner Losh * This software is provided "AS IS" and without any express or 11ca987d46SWarner Losh * implied warranties, including, without limitation, the implied 12ca987d46SWarner Losh * warranties of merchantability and fitness for a particular 13ca987d46SWarner Losh * purpose. 14ca987d46SWarner Losh * 15ca987d46SWarner Losh * $FreeBSD$ 16ca987d46SWarner Losh */ 17ca987d46SWarner Losh 18ca987d46SWarner Losh #ifndef _BOOT_I386_ARGS_H_ 19ca987d46SWarner Losh #define _BOOT_I386_ARGS_H_ 20ca987d46SWarner Losh 21ca987d46SWarner Losh #define KARGS_FLAGS_CD 0x1 22ca987d46SWarner Losh #define KARGS_FLAGS_PXE 0x2 23ca987d46SWarner Losh #define KARGS_FLAGS_ZFS 0x4 24ca987d46SWarner Losh #define KARGS_FLAGS_EXTARG 0x8 /* variably sized extended argument */ 25ca987d46SWarner Losh 26ca987d46SWarner Losh #define BOOTARGS_SIZE 24 /* sizeof(struct bootargs) */ 27ca987d46SWarner Losh #define BA_BOOTFLAGS 8 /* offsetof(struct bootargs, bootflags) */ 28ca987d46SWarner Losh #define BA_BOOTINFO 20 /* offsetof(struct bootargs, bootinfo) */ 29ca987d46SWarner Losh #define BI_SIZE 48 /* offsetof(struct bootinfo, bi_size) */ 30ca987d46SWarner Losh 31ca987d46SWarner Losh /* 32ca987d46SWarner Losh * We reserve some space above BTX allocated stack for the arguments 33ca987d46SWarner Losh * and certain data that could hang off them. Currently only struct bootinfo 34ca987d46SWarner Losh * is supported in that category. The bootinfo is placed at the top 35ca987d46SWarner Losh * of the arguments area and the actual arguments are placed at ARGOFF offset 36ca987d46SWarner Losh * from the top and grow towards the top. Hopefully we have enough space 37ca987d46SWarner Losh * for bootinfo and the arguments to not run into each other. 38ca987d46SWarner Losh * Arguments area below ARGOFF is reserved for future use. 39ca987d46SWarner Losh */ 40ca987d46SWarner Losh #define ARGSPACE 0x1000 /* total size of the BTX args area */ 41ca987d46SWarner Losh #define ARGOFF 0x800 /* actual args offset within the args area */ 42ca987d46SWarner Losh #define ARGADJ (ARGSPACE - ARGOFF) 43ca987d46SWarner Losh 44ca987d46SWarner Losh #ifndef __ASSEMBLER__ 45ca987d46SWarner Losh 46b92c2c90SIan Lepore /* 47b92c2c90SIan Lepore * This struct describes the contents of the stack on entry to btxldr.S. This 48b92c2c90SIan Lepore * is the data that follows the return address, so it begins at 4(%esp). On 49b92c2c90SIan Lepore * the sending side, this data is passed as individual args to __exec(). On the 50b92c2c90SIan Lepore * receiving side, code in btxldr.S copies the data from the entry stack to a 51b92c2c90SIan Lepore * known fixed location in the new address space. Then, btxcsu.S sets the 52b92c2c90SIan Lepore * global variable __args to point to that known fixed location before calling 53b92c2c90SIan Lepore * main(), which casts __args to a struct bootargs pointer to access the data. 54b92c2c90SIan Lepore * The btxldr.S code is aware of KARGS_FLAGS_EXTARG, and if it's set, the extra 55b92c2c90SIan Lepore * args data is copied along with the other bootargs from the entry stack to the 56b92c2c90SIan Lepore * fixed location in the new address space. 57b92c2c90SIan Lepore * 58b92c2c90SIan Lepore * The bootinfo field is actually a pointer to a bootinfo struct that has been 59b92c2c90SIan Lepore * converted to uint32_t using VTOP(). On the receiving side it must be 60b92c2c90SIan Lepore * converted back to a pointer using PTOV(). Code in btxldr.S is aware of this 61b92c2c90SIan Lepore * field and if it's non-NULL it copies the data it points to into another known 62b92c2c90SIan Lepore * fixed location, and adjusts the bootinfo field to point to that new location. 63b92c2c90SIan Lepore */ 64ca987d46SWarner Losh struct bootargs 65ca987d46SWarner Losh { 66ca987d46SWarner Losh uint32_t howto; 67ca987d46SWarner Losh uint32_t bootdev; 68ca987d46SWarner Losh uint32_t bootflags; 69ca987d46SWarner Losh union { 70ca987d46SWarner Losh struct { 71ca987d46SWarner Losh uint32_t pxeinfo; 72ca987d46SWarner Losh uint32_t reserved; 73ca987d46SWarner Losh }; 74ca987d46SWarner Losh uint64_t zfspool; 75ca987d46SWarner Losh }; 76ca987d46SWarner Losh uint32_t bootinfo; 77ca987d46SWarner Losh 78ca987d46SWarner Losh /* 79ca987d46SWarner Losh * If KARGS_FLAGS_EXTARG is set in bootflags, then the above fields 80ca987d46SWarner Losh * are followed by a uint32_t field that specifies a size of the 81ca987d46SWarner Losh * extended arguments (including the size field). 82ca987d46SWarner Losh */ 83ca987d46SWarner Losh }; 84ca987d46SWarner Losh 85ca987d46SWarner Losh #ifdef LOADER_GELI_SUPPORT 86ca987d46SWarner Losh #include <crypto/intake.h> 87*df108aafSIan Lepore #include "geliboot.h" 88ca987d46SWarner Losh #endif 89ca987d46SWarner Losh 90*df108aafSIan Lepore /* 91*df108aafSIan Lepore * geli_boot_data is embedded in geli_boot_args (passed from gptboot to loader) 92*df108aafSIan Lepore * and in zfs_boot_args (passed from zfsboot and gptzfsboot to loader). 93*df108aafSIan Lepore */ 94*df108aafSIan Lepore struct geli_boot_data 95ca987d46SWarner Losh { 96ca987d46SWarner Losh union { 97ca987d46SWarner Losh char gelipw[256]; 98ca987d46SWarner Losh struct { 99ca987d46SWarner Losh char notapw; /* 100ca987d46SWarner Losh * single null byte to stop keybuf 101ca987d46SWarner Losh * being interpreted as a password 102ca987d46SWarner Losh */ 103ca987d46SWarner Losh uint32_t keybuf_sentinel; 104ca987d46SWarner Losh #ifdef LOADER_GELI_SUPPORT 105ca987d46SWarner Losh struct keybuf *keybuf; 106ca987d46SWarner Losh #else 107ca987d46SWarner Losh void *keybuf; 108ca987d46SWarner Losh #endif 109ca987d46SWarner Losh }; 110ca987d46SWarner Losh }; 111ca987d46SWarner Losh }; 112ca987d46SWarner Losh 113*df108aafSIan Lepore #ifdef LOADER_GELI_SUPPORT 114*df108aafSIan Lepore 115*df108aafSIan Lepore static inline void 116*df108aafSIan Lepore export_geli_boot_data(struct geli_boot_data *gbdata) 117*df108aafSIan Lepore { 118*df108aafSIan Lepore 119*df108aafSIan Lepore gbdata->notapw = '\0'; 120*df108aafSIan Lepore gbdata->keybuf_sentinel = KEYBUF_SENTINEL; 121*df108aafSIan Lepore gbdata->keybuf = malloc(sizeof(struct keybuf) + 122*df108aafSIan Lepore (GELI_MAX_KEYS * sizeof(struct keybuf_ent))); 123*df108aafSIan Lepore geli_export_key_buffer(gbdata->keybuf); 124*df108aafSIan Lepore } 125*df108aafSIan Lepore 126*df108aafSIan Lepore static inline void 127*df108aafSIan Lepore import_geli_boot_data(struct geli_boot_data *gbdata) 128*df108aafSIan Lepore { 129*df108aafSIan Lepore 130*df108aafSIan Lepore if (gbdata->gelipw[0] != '\0') { 131*df108aafSIan Lepore setenv("kern.geom.eli.passphrase", gbdata->gelipw, 1); 132*df108aafSIan Lepore explicit_bzero(gbdata->gelipw, sizeof(gbdata->gelipw)); 133*df108aafSIan Lepore } else if (gbdata->keybuf_sentinel == KEYBUF_SENTINEL) { 134*df108aafSIan Lepore geli_import_key_buffer(gbdata->keybuf); 135*df108aafSIan Lepore } 136*df108aafSIan Lepore } 137*df108aafSIan Lepore #endif /* LOADER_GELI_SUPPORT */ 138*df108aafSIan Lepore 139*df108aafSIan Lepore struct geli_boot_args 140*df108aafSIan Lepore { 141*df108aafSIan Lepore uint32_t size; 142*df108aafSIan Lepore struct geli_boot_data gelidata; 143*df108aafSIan Lepore }; 144*df108aafSIan Lepore 145*df108aafSIan Lepore struct zfs_boot_args 146*df108aafSIan Lepore { 147*df108aafSIan Lepore uint32_t size; 148*df108aafSIan Lepore uint32_t reserved; 149*df108aafSIan Lepore uint64_t pool; 150*df108aafSIan Lepore uint64_t root; 151*df108aafSIan Lepore uint64_t primary_pool; 152*df108aafSIan Lepore uint64_t primary_vdev; 153*df108aafSIan Lepore struct geli_boot_data gelidata; 154*df108aafSIan Lepore }; 155*df108aafSIan Lepore 156ca987d46SWarner Losh #endif /*__ASSEMBLER__*/ 157ca987d46SWarner Losh 158ca987d46SWarner Losh #endif /* !_BOOT_I386_ARGS_H_ */ 159