Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / ppc / qemu / main.c
1 /*
2  *   Creation Date: <2002/10/02 22:24:24 samuel>
3  *   Time-stamp: <2004/03/27 01:57:55 samuel>
4  *
5  *      <main.c>
6  *
7  *
8  *
9  *   Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10  *
11  *   This program is free software; you can redistribute it and/or
12  *   modify it under the terms of the GNU General Public License
13  *   as published by the Free Software Foundation
14  *
15  */
16
17 #include "config.h"
18 #include "libopenbios/bindings.h"
19 #include "libopenbios/elf_load.h"
20 #include "arch/common/nvram.h"
21 #include "packages/nvram.h"
22 #include "libc/diskio.h"
23 #include "libc/vsprintf.h"
24 #include "kernel.h"
25 #include "drivers/drivers.h"
26 #include "libopenbios/ofmem.h"
27 #define NO_QEMU_PROTOS
28 #include "arch/common/fw_cfg.h"
29
30 //#define DEBUG_QEMU
31
32 #ifdef DEBUG_QEMU
33 #define SUBSYS_DPRINTF(subsys, fmt, args...) \
34     do { printk("%s - %s: " fmt, subsys, __func__ , ##args); } while (0)
35 #else
36 #define SUBSYS_DPRINTF(subsys, fmt, args...) \
37     do { } while (0)
38 #endif
39 #define CHRP_DPRINTF(fmt, args...) SUBSYS_DPRINTF("CHRP", fmt, ##args)
40 #define ELF_DPRINTF(fmt, args...) SUBSYS_DPRINTF("ELF", fmt, ##args)
41 #define NEWWORLD_DPRINTF(fmt, args...) SUBSYS_DPRINTF("NEWWORLD", fmt, ##args)
42
43 static void check_preloaded_kernel(void)
44 {
45     unsigned long kernel_image, kernel_size;
46     unsigned long initrd_image, initrd_size;
47     const char * kernel_cmdline;
48
49     kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE);
50     if (kernel_size) {
51         kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR);
52         kernel_cmdline = (const char *)(uintptr_t) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE);
53         initrd_image = fw_cfg_read_i32(FW_CFG_INITRD_ADDR);
54         initrd_size = fw_cfg_read_i32(FW_CFG_INITRD_SIZE);
55         printk("[ppc] Kernel already loaded (0x%8.8lx + 0x%8.8lx) "
56                "(initrd 0x%8.8lx + 0x%8.8lx)\n",
57                kernel_image, kernel_size, initrd_image, initrd_size);
58         if (kernel_cmdline) {
59                phandle_t ph;
60                printk("[ppc] Kernel command line: %s\n", kernel_cmdline);
61                ph = find_dev("/chosen");
62                set_property(ph, "bootargs", strdup(kernel_cmdline), strlen(kernel_cmdline) + 1);
63         }
64         call_elf(initrd_image, initrd_size, kernel_image);
65     }
66 }
67
68 /************************************************************************/
69 /*      entry                                                           */
70 /************************************************************************/
71
72 void
73 boot( void )
74 {
75         uint16_t boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
76
77         fword("update-chosen");
78         if (boot_device == 'm') {
79                 check_preloaded_kernel();
80         }
81
82         if (is_apple()) {
83                 update_nvram();
84         }
85 }