2 * Raw bootcode loader (CHRP/Apple %BOOT)
3 * Written by Mark Cave-Ayland 2013
7 #include "kernel/kernel.h"
8 #include "libopenbios/bindings.h"
9 #include "libopenbios/bootcode_load.h"
10 #include "libc/diskio.h"
11 #include "drivers/drivers.h"
17 bootcode_load(ihandle_t dev)
19 int retval = -1, count = 0, fd;
20 unsigned long bootcode, loadbase, entry, size, offset;
21 ihandle_t bootcode_info;
23 /* Mark the saved-program-state as invalid */
24 feval("0 state-valid !");
31 /* If we don't have the get-bootcode-info word then we don't support
32 loading bootcode via %BOOT */
33 bootcode_info = find_ih_method("get-bootcode-info", dev);
38 /* Default to loading at load-base */
46 * Apple OF does not honor load-base and instead uses pmBootLoad
47 * value from the boot partition descriptor.
50 * a debian image with QUIK installed
51 * a debian image with iQUIK installed (https://github.com/andreiw/quik)
52 * an IQUIK boot floppy
53 * a NetBSD boot floppy (boots stage 2)
69 if (seek_io(fd, offset) == -1)
71 count = read_io(fd, (void *)bootcode, 512);
76 /* If we didn't read anything then exit */
81 /* Use proper file size if we got it from bootcode info */
86 /* Initialise saved-program-state */
88 feval("saved-program-state >sps.entry !");
90 feval("saved-program-state >sps.file-size !");
91 feval("bootcode saved-program-state >sps.file-type !");
93 feval("-1 state-valid !");