| File: | hw/moxie/moxiesim.c |
| Location: | line 66, column 5 |
| Description: | Value stored to 'initrd_offset' is never read |
| 1 | /* |
| 2 | * QEMU/moxiesim emulation |
| 3 | * |
| 4 | * Emulates a very simple machine model similar to the one used by the |
| 5 | * GDB moxie simulator. |
| 6 | * |
| 7 | * Copyright (c) 2008, 2009, 2010, 2013 Anthony Green |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | * of this software and associated documentation files (the "Software"), to deal |
| 11 | * in the Software without restriction, including without limitation the rights |
| 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | * copies of the Software, and to permit persons to whom the Software is |
| 14 | * furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | * THE SOFTWARE. |
| 26 | */ |
| 27 | #include "hw/sysbus.h" |
| 28 | #include "hw/hw.h" |
| 29 | #include "hw/i386/pc.h" |
| 30 | #include "hw/isa/isa.h" |
| 31 | #include "net/net.h" |
| 32 | #include "sysemu/sysemu.h" |
| 33 | #include "hw/boards.h" |
| 34 | #include "hw/loader.h" |
| 35 | #include "hw/char/serial.h" |
| 36 | #include "exec/address-spaces.h" |
| 37 | |
| 38 | #define PHYS_MEM_BASE0x80000000 0x80000000 |
| 39 | |
| 40 | typedef struct { |
| 41 | uint64_t ram_size; |
| 42 | const char *kernel_filename; |
| 43 | const char *kernel_cmdline; |
| 44 | const char *initrd_filename; |
| 45 | } LoaderParams; |
| 46 | |
| 47 | static void load_kernel(MoxieCPU *cpu, LoaderParams *loader_params) |
| 48 | { |
| 49 | uint64_t entry, kernel_low, kernel_high; |
| 50 | long kernel_size; |
| 51 | long initrd_size; |
| 52 | ram_addr_t initrd_offset; |
| 53 | |
| 54 | kernel_size = load_elf(loader_params->kernel_filename, NULL((void*)0), NULL((void*)0), |
| 55 | &entry, &kernel_low, &kernel_high, 1, |
| 56 | ELF_MACHINE0xFEED, 0); |
| 57 | |
| 58 | if (!kernel_size) { |
| 59 | fprintf(stderrstderr, "qemu: could not load kernel '%s'\n", |
| 60 | loader_params->kernel_filename); |
| 61 | exit(1); |
| 62 | } |
| 63 | |
| 64 | /* load initrd */ |
| 65 | initrd_size = 0; |
| 66 | initrd_offset = 0; |
Value stored to 'initrd_offset' is never read | |
| 67 | if (loader_params->initrd_filename) { |
| 68 | initrd_size = get_image_size(loader_params->initrd_filename); |
| 69 | if (initrd_size > 0) { |
| 70 | initrd_offset = (kernel_high + ~TARGET_PAGE_MASK~((1 << 12) - 1)) |
| 71 | & TARGET_PAGE_MASK~((1 << 12) - 1); |
| 72 | if (initrd_offset + initrd_size > loader_params->ram_size) { |
| 73 | fprintf(stderrstderr, |
| 74 | "qemu: memory too small for initial ram disk '%s'\n", |
| 75 | loader_params->initrd_filename); |
| 76 | exit(1); |
| 77 | } |
| 78 | initrd_size = load_image_targphys(loader_params->initrd_filename, |
| 79 | initrd_offset, |
| 80 | ram_size); |
| 81 | } |
| 82 | if (initrd_size == (target_ulong)-1) { |
| 83 | fprintf(stderrstderr, "qemu: could not load initial ram disk '%s'\n", |
| 84 | loader_params->initrd_filename); |
| 85 | exit(1); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | static void main_cpu_reset(void *opaque) |
| 91 | { |
| 92 | MoxieCPU *cpu = opaque; |
| 93 | |
| 94 | cpu_reset(CPU(cpu)((CPUState *)object_dynamic_cast_assert(((Object *)((cpu))), ( "cpu"), "/home/stefan/src/qemu/qemu.org/qemu/hw/moxie/moxiesim.c" , 94, __func__))); |
| 95 | } |
| 96 | |
| 97 | static inline DeviceState * |
| 98 | moxie_intc_create(hwaddr base, qemu_irq irq, int kind_of_intr) |
| 99 | { |
| 100 | DeviceState *dev; |
| 101 | |
| 102 | dev = qdev_create(NULL((void*)0), "moxie,intc"); |
| 103 | qdev_prop_set_uint32(dev, "kind-of-intr", kind_of_intr); |
| 104 | qdev_init_nofail(dev); |
| 105 | sysbus_mmio_map(SYS_BUS_DEVICE(dev)((SysBusDevice *)object_dynamic_cast_assert(((Object *)((dev) )), ("sys-bus-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/moxie/moxiesim.c" , 105, __func__)), 0, base); |
| 106 | sysbus_connect_irq(SYS_BUS_DEVICE(dev)((SysBusDevice *)object_dynamic_cast_assert(((Object *)((dev) )), ("sys-bus-device"), "/home/stefan/src/qemu/qemu.org/qemu/hw/moxie/moxiesim.c" , 106, __func__)), 0, irq); |
| 107 | return dev; |
| 108 | } |
| 109 | |
| 110 | static void moxiesim_init(QEMUMachineInitArgs *args) |
| 111 | { |
| 112 | MoxieCPU *cpu = NULL((void*)0); |
| 113 | ram_addr_t ram_size = args->ram_size; |
| 114 | const char *cpu_model = args->cpu_model; |
| 115 | const char *kernel_filename = args->kernel_filename; |
| 116 | const char *kernel_cmdline = args->kernel_cmdline; |
| 117 | const char *initrd_filename = args->initrd_filename; |
| 118 | CPUMoxieState *env; |
| 119 | MemoryRegion *address_space_mem = get_system_memory(); |
| 120 | MemoryRegion *ram = g_new(MemoryRegion, 1)((MemoryRegion *) g_malloc_n ((1), sizeof (MemoryRegion))); |
| 121 | MemoryRegion *rom = g_new(MemoryRegion, 1)((MemoryRegion *) g_malloc_n ((1), sizeof (MemoryRegion))); |
| 122 | hwaddr ram_base = 0x200000; |
| 123 | LoaderParams loader_params; |
| 124 | |
| 125 | /* Init CPUs. */ |
| 126 | if (cpu_model == NULL((void*)0)) { |
| 127 | cpu_model = "MoxieLite-moxie-cpu"; |
| 128 | } |
| 129 | cpu = cpu_moxie_init(cpu_model); |
| 130 | if (!cpu) { |
| 131 | fprintf(stderrstderr, "Unable to find CPU definition\n"); |
| 132 | exit(1); |
| 133 | } |
| 134 | env = &cpu->env; |
| 135 | |
| 136 | qemu_register_reset(main_cpu_reset, cpu); |
| 137 | |
| 138 | /* Allocate RAM. */ |
| 139 | memory_region_init_ram(ram, NULL((void*)0), "moxiesim.ram", ram_size); |
| 140 | vmstate_register_ram_global(ram); |
| 141 | memory_region_add_subregion(address_space_mem, ram_base, ram); |
| 142 | |
| 143 | memory_region_init_ram(rom, NULL((void*)0), "moxie.rom", 128*0x1000); |
| 144 | vmstate_register_ram_global(rom); |
| 145 | memory_region_add_subregion(get_system_memory(), 0x1000, rom); |
| 146 | |
| 147 | if (kernel_filename) { |
| 148 | loader_params.ram_size = ram_size; |
| 149 | loader_params.kernel_filename = kernel_filename; |
| 150 | loader_params.kernel_cmdline = kernel_cmdline; |
| 151 | loader_params.initrd_filename = initrd_filename; |
| 152 | load_kernel(cpu, &loader_params); |
| 153 | } |
| 154 | |
| 155 | /* A single 16450 sits at offset 0x3f8. */ |
| 156 | if (serial_hds[0]) { |
| 157 | serial_mm_init(address_space_mem, 0x3f8, 0, env->irq[4], |
| 158 | 8000000/16, serial_hds[0], DEVICE_LITTLE_ENDIAN); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static QEMUMachine moxiesim_machine = { |
| 163 | .name = "moxiesim", |
| 164 | .desc = "Moxie simulator platform", |
| 165 | .init = moxiesim_init, |
| 166 | .is_default = 1, |
| 167 | }; |
| 168 | |
| 169 | static void moxie_machine_init(void) |
| 170 | { |
| 171 | qemu_register_machine(&moxiesim_machine); |
| 172 | } |
| 173 | |
| 174 | machine_init(moxie_machine_init)static void __attribute__((constructor)) do_qemu_init_moxie_machine_init (void) { register_module_init(moxie_machine_init, MODULE_INIT_MACHINE ); } |