1 /* -----------------------------------------------------------------------
3 * Copyright 2010-2011 Gene Cumm
6 * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
7 * Copyright 2009 Intel Corporation; author: H. Peter Anvin
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or
14 * sell copies of the Software, and to permit persons to whom
15 * the Software is furnished to do so, subject to the following
18 * The above copyright notice and this permission notice shall
19 * be included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
30 * ----------------------------------------------------------------------- */
33 * handoff.S: MBR/VBR-like codeblock to display handoff data
35 * Displays the values of DL, DS, SI, the contents of [DS:SI] (16 bytes),
36 * the values of ES, DI, the contents of [ES:DI] (4 bytes), scans memory for
37 * $PnP then reports a boot failure.
39 * This should (hopefully) be only 8086 code
43 * Install instructions (assuming your target is /dev/dev; file or block device):
46 * dd conv=notrunc bs=440 count=1 if=handoff.bin of=/dev/dev
48 * VBR/PBR (should work for FAT12/16/32, ext[234]fs, btrfs):
49 * echo -en "\0353\0130\0220" |dd conv=notrunc bs=1 count=3 of=/dev/dev
50 * dd conv=notrunc bs=2 count=210 seek=45 if=handoff.bin of=/dev/dev
53 // #define DEBUG_MARKER1 /* Insert markers in binary */
54 // #define DEBUG_START /* Print entry addresses at start */
55 // #define DEBUG_LOADE /* movw versus pop */
56 #define DEBUG_PNP /* Scan for $PnP and show address */
57 #define DEBUG_PAK /* Press Any Key before boot fail */
58 // #define DEBUG_ENTRY_REG /* Store (manually as pusha is 80186) registers */
59 // #define DEBUG_FDT /* Print the floppy descriptor table; INT 1Eh*/
62 .macro ASCII_MARKER1 s:vararg
65 #else /* DEBUG_MARKER1 */
66 .macro ASCII_MARKER1 s:vararg
68 #endif /* DEBUG_MARKER1 */
71 .macro LOADE r:req, t:req
74 #else /* DEBUG_LOADE */
75 .macro LOADE r:req, t:req
78 #endif /* DEBUG_LOADE */
90 /* Doubtful this will be used */
103 es_beg = (e0_bot) /* Original register values from entry point */
113 int_1e_seg = (int_1e)
114 int_1e_off = (int_1e+2)
119 #ifdef DEBUG_ENTRY_REG
123 #endif /* DEBUG_ENTRY_REG */
126 #ifdef DEBUG_ENTRY_REG
128 /* pushaw */ /* 80186 */
139 #else /* DEBUG_ENTRY_REG */
141 #endif /* DEBUG_ENTRY_REG */
142 pushw %di /* es:di -> $PnP header */
154 movw $(_start),%dx /* 0x0600 mbr.ld .text address */
160 subw $(caddr - _start), %dx
164 #endif /* DEBUG_START */
204 /* ES:DI */ /* %es:0(%di) */
229 ch_pnp: es lodsw /* Check for $PnP */
235 ch_pnp_l: /* Check $PnP failed; loop to next address */
251 #endif /* DEBUG_PNP */
256 /* INT 1Eh: Floppy Parameter Table Pointer */
274 #endif /* DEBUG_FDT */
282 movb (BIOS_page), %bh
284 int $0x10 /* May destroy %bp */
358 .ascii "\r\n\r\nPress any key\r\n\0"
362 int $0x18 /* Boot failure */