6 #include "kernel/kernel.h"
7 #include "libopenbios/bindings.h"
8 #include "libopenbios/fcode_load.h"
9 #include "libopenbios/sys_info.h"
10 #include "libc/diskio.h"
17 is_fcode(unsigned char *fcode)
19 return (fcode[0] == 0xf0 // start0
20 || fcode[0] == 0xf1 // start1
21 || fcode[0] == 0xf2 // start2
22 || fcode[0] == 0xf3 // start4
23 || fcode[0] == 0xfd); // version1
27 fcode_load(ihandle_t dev)
30 uint8_t fcode_header[8];
31 unsigned long start, size;
34 /* Mark the saved-program-state as invalid */
35 feval("0 state-valid !");
42 for (offset = 0; offset < 16 * 512; offset += 512) {
44 if (read_io(fd, &fcode_header, sizeof(fcode_header))
45 != sizeof(fcode_header)) {
46 debug("Can't read FCode header from ihandle " FMT_ucellx "\n", dev);
47 retval = LOADER_NOT_SUPPORT;
51 if (is_fcode(fcode_header))
55 debug("Not a bootable FCode image\n");
56 retval = LOADER_NOT_SUPPORT;
60 size = (fcode_header[4] << 24) | (fcode_header[5] << 16) |
61 (fcode_header[6] << 8) | fcode_header[7];
66 printf("\nLoading FCode image...\n");
70 if ((size_t)read_io(fd, (void *)start, size) != size) {
71 printf("Can't read file (size 0x%lx)\n", size);
75 debug("Loaded %lu bytes\n", size);
76 debug("entry point is %#lx\n", start);
78 // Initialise saved-program-state
80 feval("saved-program-state >sps.entry !");
82 feval("saved-program-state >sps.file-size !");
83 feval("fcode saved-program-state >sps.file-type !");
85 feval("-1 state-valid !");
93 fcode_init_program(void)
95 /* If the payload is Fcode then we execute it immediately */
101 if (!is_fcode((unsigned char *)address)) {
102 debug("Not a valid Fcode memory image\n");