cris-boot.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * CRIS image loading.
  3. *
  4. * Copyright (c) 2010 Edgar E. Iglesias, Axis Communications AB.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "hw.h"
  25. #include "loader.h"
  26. #include "elf.h"
  27. #include "cris-boot.h"
  28. static void main_cpu_reset(void *opaque)
  29. {
  30. CRISCPU *cpu = opaque;
  31. CPUCRISState *env = &cpu->env;
  32. struct cris_load_info *li;
  33. li = env->load_info;
  34. cpu_reset(CPU(cpu));
  35. if (!li) {
  36. /* nothing more to do. */
  37. return;
  38. }
  39. env->pc = li->entry;
  40. if (li->image_filename) {
  41. env->regs[8] = 0x56902387; /* RAM boot magic. */
  42. env->regs[9] = 0x40004000 + li->image_size;
  43. }
  44. if (li->cmdline) {
  45. /* Let the kernel know we are modifying the cmdline. */
  46. env->regs[10] = 0x87109563;
  47. env->regs[11] = 0x40000000;
  48. }
  49. }
  50. static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
  51. {
  52. return addr - 0x80000000LL;
  53. }
  54. void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
  55. {
  56. CPUCRISState *env = &cpu->env;
  57. uint64_t entry, high;
  58. int kcmdline_len;
  59. int image_size;
  60. env->load_info = li;
  61. /* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
  62. devboard SDK. */
  63. image_size = load_elf(li->image_filename, translate_kernel_address, NULL,
  64. &entry, NULL, &high, 0, ELF_MACHINE, 0);
  65. li->entry = entry;
  66. if (image_size < 0) {
  67. /* Takes a kimage from the axis devboard SDK. */
  68. image_size = load_image_targphys(li->image_filename, 0x40004000,
  69. ram_size);
  70. li->entry = 0x40004000;
  71. }
  72. if (image_size < 0) {
  73. fprintf(stderr, "qemu: could not load kernel '%s'\n",
  74. li->image_filename);
  75. exit(1);
  76. }
  77. if (li->cmdline && (kcmdline_len = strlen(li->cmdline))) {
  78. if (kcmdline_len > 256) {
  79. fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
  80. exit(1);
  81. }
  82. pstrcpy_targphys("cmdline", 0x40000000, 256, li->cmdline);
  83. }
  84. qemu_register_reset(main_cpu_reset, cpu);
  85. }