ppc_prep.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /*
  2. * QEMU PPC PREP hardware System Emulator
  3. *
  4. * Copyright (c) 2003-2007 Jocelyn Mayer
  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 "nvram.h"
  26. #include "pc.h"
  27. #include "fdc.h"
  28. #include "net.h"
  29. #include "sysemu.h"
  30. #include "isa.h"
  31. #include "pci.h"
  32. #include "ppc.h"
  33. #include "boards.h"
  34. #include "qemu-log.h"
  35. //#define HARD_DEBUG_PPC_IO
  36. //#define DEBUG_PPC_IO
  37. /* SMP is not enabled, for now */
  38. #define MAX_CPUS 1
  39. #define MAX_IDE_BUS 2
  40. #define BIOS_FILENAME "ppc_rom.bin"
  41. #define KERNEL_LOAD_ADDR 0x01000000
  42. #define INITRD_LOAD_ADDR 0x01800000
  43. #if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO)
  44. #define DEBUG_PPC_IO
  45. #endif
  46. #if defined (HARD_DEBUG_PPC_IO)
  47. #define PPC_IO_DPRINTF(fmt, args...) \
  48. do { \
  49. if (qemu_loglevel_mask(CPU_LOG_IOPORT)) { \
  50. qemu_log("%s: " fmt, __func__ , ##args); \
  51. } else { \
  52. printf("%s : " fmt, __func__ , ##args); \
  53. } \
  54. } while (0)
  55. #elif defined (DEBUG_PPC_IO)
  56. #define PPC_IO_DPRINTF(fmt, args...) qemu_log_mask(CPU_LOG_IOPORT, ## __VA_ARGS__)
  57. #else
  58. #define PPC_IO_DPRINTF(fmt, args...) do { } while (0)
  59. #endif
  60. /* Constants for devices init */
  61. static const int ide_iobase[2] = { 0x1f0, 0x170 };
  62. static const int ide_iobase2[2] = { 0x3f6, 0x376 };
  63. static const int ide_irq[2] = { 13, 13 };
  64. #define NE2000_NB_MAX 6
  65. static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
  66. static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
  67. //static PITState *pit;
  68. /* ISA IO ports bridge */
  69. #define PPC_IO_BASE 0x80000000
  70. #if 0
  71. /* Speaker port 0x61 */
  72. static int speaker_data_on;
  73. static int dummy_refresh_clock;
  74. #endif
  75. static void speaker_ioport_write (void *opaque, uint32_t addr, uint32_t val)
  76. {
  77. #if 0
  78. speaker_data_on = (val >> 1) & 1;
  79. pit_set_gate(pit, 2, val & 1);
  80. #endif
  81. }
  82. static uint32_t speaker_ioport_read (void *opaque, uint32_t addr)
  83. {
  84. #if 0
  85. int out;
  86. out = pit_get_out(pit, 2, qemu_get_clock(vm_clock));
  87. dummy_refresh_clock ^= 1;
  88. return (speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) |
  89. (dummy_refresh_clock << 4);
  90. #endif
  91. return 0;
  92. }
  93. /* PCI intack register */
  94. /* Read-only register (?) */
  95. static void _PPC_intack_write (void *opaque,
  96. target_phys_addr_t addr, uint32_t value)
  97. {
  98. // printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
  99. }
  100. static always_inline uint32_t _PPC_intack_read (target_phys_addr_t addr)
  101. {
  102. uint32_t retval = 0;
  103. if ((addr & 0xf) == 0)
  104. retval = pic_intack_read(isa_pic);
  105. // printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
  106. return retval;
  107. }
  108. static uint32_t PPC_intack_readb (void *opaque, target_phys_addr_t addr)
  109. {
  110. return _PPC_intack_read(addr);
  111. }
  112. static uint32_t PPC_intack_readw (void *opaque, target_phys_addr_t addr)
  113. {
  114. #ifdef TARGET_WORDS_BIGENDIAN
  115. return bswap16(_PPC_intack_read(addr));
  116. #else
  117. return _PPC_intack_read(addr);
  118. #endif
  119. }
  120. static uint32_t PPC_intack_readl (void *opaque, target_phys_addr_t addr)
  121. {
  122. #ifdef TARGET_WORDS_BIGENDIAN
  123. return bswap32(_PPC_intack_read(addr));
  124. #else
  125. return _PPC_intack_read(addr);
  126. #endif
  127. }
  128. static CPUWriteMemoryFunc *PPC_intack_write[] = {
  129. &_PPC_intack_write,
  130. &_PPC_intack_write,
  131. &_PPC_intack_write,
  132. };
  133. static CPUReadMemoryFunc *PPC_intack_read[] = {
  134. &PPC_intack_readb,
  135. &PPC_intack_readw,
  136. &PPC_intack_readl,
  137. };
  138. /* PowerPC control and status registers */
  139. #if 0 // Not used
  140. static struct {
  141. /* IDs */
  142. uint32_t veni_devi;
  143. uint32_t revi;
  144. /* Control and status */
  145. uint32_t gcsr;
  146. uint32_t xcfr;
  147. uint32_t ct32;
  148. uint32_t mcsr;
  149. /* General purpose registers */
  150. uint32_t gprg[6];
  151. /* Exceptions */
  152. uint32_t feen;
  153. uint32_t fest;
  154. uint32_t fema;
  155. uint32_t fecl;
  156. uint32_t eeen;
  157. uint32_t eest;
  158. uint32_t eecl;
  159. uint32_t eeint;
  160. uint32_t eemck0;
  161. uint32_t eemck1;
  162. /* Error diagnostic */
  163. } XCSR;
  164. static void PPC_XCSR_writeb (void *opaque,
  165. target_phys_addr_t addr, uint32_t value)
  166. {
  167. printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
  168. }
  169. static void PPC_XCSR_writew (void *opaque,
  170. target_phys_addr_t addr, uint32_t value)
  171. {
  172. #ifdef TARGET_WORDS_BIGENDIAN
  173. value = bswap16(value);
  174. #endif
  175. printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
  176. }
  177. static void PPC_XCSR_writel (void *opaque,
  178. target_phys_addr_t addr, uint32_t value)
  179. {
  180. #ifdef TARGET_WORDS_BIGENDIAN
  181. value = bswap32(value);
  182. #endif
  183. printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
  184. }
  185. static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
  186. {
  187. uint32_t retval = 0;
  188. printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
  189. return retval;
  190. }
  191. static uint32_t PPC_XCSR_readw (void *opaque, target_phys_addr_t addr)
  192. {
  193. uint32_t retval = 0;
  194. printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
  195. #ifdef TARGET_WORDS_BIGENDIAN
  196. retval = bswap16(retval);
  197. #endif
  198. return retval;
  199. }
  200. static uint32_t PPC_XCSR_readl (void *opaque, target_phys_addr_t addr)
  201. {
  202. uint32_t retval = 0;
  203. printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
  204. #ifdef TARGET_WORDS_BIGENDIAN
  205. retval = bswap32(retval);
  206. #endif
  207. return retval;
  208. }
  209. static CPUWriteMemoryFunc *PPC_XCSR_write[] = {
  210. &PPC_XCSR_writeb,
  211. &PPC_XCSR_writew,
  212. &PPC_XCSR_writel,
  213. };
  214. static CPUReadMemoryFunc *PPC_XCSR_read[] = {
  215. &PPC_XCSR_readb,
  216. &PPC_XCSR_readw,
  217. &PPC_XCSR_readl,
  218. };
  219. #endif
  220. /* Fake super-io ports for PREP platform (Intel 82378ZB) */
  221. typedef struct sysctrl_t {
  222. qemu_irq reset_irq;
  223. m48t59_t *nvram;
  224. uint8_t state;
  225. uint8_t syscontrol;
  226. uint8_t fake_io[2];
  227. int contiguous_map;
  228. int endian;
  229. } sysctrl_t;
  230. enum {
  231. STATE_HARDFILE = 0x01,
  232. };
  233. static sysctrl_t *sysctrl;
  234. static void PREP_io_write (void *opaque, uint32_t addr, uint32_t val)
  235. {
  236. sysctrl_t *sysctrl = opaque;
  237. PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
  238. val);
  239. sysctrl->fake_io[addr - 0x0398] = val;
  240. }
  241. static uint32_t PREP_io_read (void *opaque, uint32_t addr)
  242. {
  243. sysctrl_t *sysctrl = opaque;
  244. PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
  245. sysctrl->fake_io[addr - 0x0398]);
  246. return sysctrl->fake_io[addr - 0x0398];
  247. }
  248. static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val)
  249. {
  250. sysctrl_t *sysctrl = opaque;
  251. PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n",
  252. addr - PPC_IO_BASE, val);
  253. switch (addr) {
  254. case 0x0092:
  255. /* Special port 92 */
  256. /* Check soft reset asked */
  257. if (val & 0x01) {
  258. qemu_irq_raise(sysctrl->reset_irq);
  259. } else {
  260. qemu_irq_lower(sysctrl->reset_irq);
  261. }
  262. /* Check LE mode */
  263. if (val & 0x02) {
  264. sysctrl->endian = 1;
  265. } else {
  266. sysctrl->endian = 0;
  267. }
  268. break;
  269. case 0x0800:
  270. /* Motorola CPU configuration register : read-only */
  271. break;
  272. case 0x0802:
  273. /* Motorola base module feature register : read-only */
  274. break;
  275. case 0x0803:
  276. /* Motorola base module status register : read-only */
  277. break;
  278. case 0x0808:
  279. /* Hardfile light register */
  280. if (val & 1)
  281. sysctrl->state |= STATE_HARDFILE;
  282. else
  283. sysctrl->state &= ~STATE_HARDFILE;
  284. break;
  285. case 0x0810:
  286. /* Password protect 1 register */
  287. if (sysctrl->nvram != NULL)
  288. m48t59_toggle_lock(sysctrl->nvram, 1);
  289. break;
  290. case 0x0812:
  291. /* Password protect 2 register */
  292. if (sysctrl->nvram != NULL)
  293. m48t59_toggle_lock(sysctrl->nvram, 2);
  294. break;
  295. case 0x0814:
  296. /* L2 invalidate register */
  297. // tlb_flush(first_cpu, 1);
  298. break;
  299. case 0x081C:
  300. /* system control register */
  301. sysctrl->syscontrol = val & 0x0F;
  302. break;
  303. case 0x0850:
  304. /* I/O map type register */
  305. sysctrl->contiguous_map = val & 0x01;
  306. break;
  307. default:
  308. printf("ERROR: unaffected IO port write: %04" PRIx32
  309. " => %02" PRIx32"\n", addr, val);
  310. break;
  311. }
  312. }
  313. static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)
  314. {
  315. sysctrl_t *sysctrl = opaque;
  316. uint32_t retval = 0xFF;
  317. switch (addr) {
  318. case 0x0092:
  319. /* Special port 92 */
  320. retval = 0x00;
  321. break;
  322. case 0x0800:
  323. /* Motorola CPU configuration register */
  324. retval = 0xEF; /* MPC750 */
  325. break;
  326. case 0x0802:
  327. /* Motorola Base module feature register */
  328. retval = 0xAD; /* No ESCC, PMC slot neither ethernet */
  329. break;
  330. case 0x0803:
  331. /* Motorola base module status register */
  332. retval = 0xE0; /* Standard MPC750 */
  333. break;
  334. case 0x080C:
  335. /* Equipment present register:
  336. * no L2 cache
  337. * no upgrade processor
  338. * no cards in PCI slots
  339. * SCSI fuse is bad
  340. */
  341. retval = 0x3C;
  342. break;
  343. case 0x0810:
  344. /* Motorola base module extended feature register */
  345. retval = 0x39; /* No USB, CF and PCI bridge. NVRAM present */
  346. break;
  347. case 0x0814:
  348. /* L2 invalidate: don't care */
  349. break;
  350. case 0x0818:
  351. /* Keylock */
  352. retval = 0x00;
  353. break;
  354. case 0x081C:
  355. /* system control register
  356. * 7 - 6 / 1 - 0: L2 cache enable
  357. */
  358. retval = sysctrl->syscontrol;
  359. break;
  360. case 0x0823:
  361. /* */
  362. retval = 0x03; /* no L2 cache */
  363. break;
  364. case 0x0850:
  365. /* I/O map type register */
  366. retval = sysctrl->contiguous_map;
  367. break;
  368. default:
  369. printf("ERROR: unaffected IO port: %04" PRIx32 " read\n", addr);
  370. break;
  371. }
  372. PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n",
  373. addr - PPC_IO_BASE, retval);
  374. return retval;
  375. }
  376. static always_inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
  377. target_phys_addr_t
  378. addr)
  379. {
  380. if (sysctrl->contiguous_map == 0) {
  381. /* 64 KB contiguous space for IOs */
  382. addr &= 0xFFFF;
  383. } else {
  384. /* 8 MB non-contiguous space for IOs */
  385. addr = (addr & 0x1F) | ((addr & 0x007FFF000) >> 7);
  386. }
  387. return addr;
  388. }
  389. static void PPC_prep_io_writeb (void *opaque, target_phys_addr_t addr,
  390. uint32_t value)
  391. {
  392. sysctrl_t *sysctrl = opaque;
  393. addr = prep_IO_address(sysctrl, addr);
  394. cpu_outb(NULL, addr, value);
  395. }
  396. static uint32_t PPC_prep_io_readb (void *opaque, target_phys_addr_t addr)
  397. {
  398. sysctrl_t *sysctrl = opaque;
  399. uint32_t ret;
  400. addr = prep_IO_address(sysctrl, addr);
  401. ret = cpu_inb(NULL, addr);
  402. return ret;
  403. }
  404. static void PPC_prep_io_writew (void *opaque, target_phys_addr_t addr,
  405. uint32_t value)
  406. {
  407. sysctrl_t *sysctrl = opaque;
  408. addr = prep_IO_address(sysctrl, addr);
  409. #ifdef TARGET_WORDS_BIGENDIAN
  410. value = bswap16(value);
  411. #endif
  412. PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
  413. cpu_outw(NULL, addr, value);
  414. }
  415. static uint32_t PPC_prep_io_readw (void *opaque, target_phys_addr_t addr)
  416. {
  417. sysctrl_t *sysctrl = opaque;
  418. uint32_t ret;
  419. addr = prep_IO_address(sysctrl, addr);
  420. ret = cpu_inw(NULL, addr);
  421. #ifdef TARGET_WORDS_BIGENDIAN
  422. ret = bswap16(ret);
  423. #endif
  424. PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
  425. return ret;
  426. }
  427. static void PPC_prep_io_writel (void *opaque, target_phys_addr_t addr,
  428. uint32_t value)
  429. {
  430. sysctrl_t *sysctrl = opaque;
  431. addr = prep_IO_address(sysctrl, addr);
  432. #ifdef TARGET_WORDS_BIGENDIAN
  433. value = bswap32(value);
  434. #endif
  435. PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
  436. cpu_outl(NULL, addr, value);
  437. }
  438. static uint32_t PPC_prep_io_readl (void *opaque, target_phys_addr_t addr)
  439. {
  440. sysctrl_t *sysctrl = opaque;
  441. uint32_t ret;
  442. addr = prep_IO_address(sysctrl, addr);
  443. ret = cpu_inl(NULL, addr);
  444. #ifdef TARGET_WORDS_BIGENDIAN
  445. ret = bswap32(ret);
  446. #endif
  447. PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
  448. return ret;
  449. }
  450. static CPUWriteMemoryFunc *PPC_prep_io_write[] = {
  451. &PPC_prep_io_writeb,
  452. &PPC_prep_io_writew,
  453. &PPC_prep_io_writel,
  454. };
  455. static CPUReadMemoryFunc *PPC_prep_io_read[] = {
  456. &PPC_prep_io_readb,
  457. &PPC_prep_io_readw,
  458. &PPC_prep_io_readl,
  459. };
  460. #define NVRAM_SIZE 0x2000
  461. /* PowerPC PREP hardware initialisation */
  462. static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size,
  463. const char *boot_device,
  464. const char *kernel_filename,
  465. const char *kernel_cmdline,
  466. const char *initrd_filename,
  467. const char *cpu_model)
  468. {
  469. CPUState *env = NULL, *envs[MAX_CPUS];
  470. char buf[1024];
  471. nvram_t nvram;
  472. m48t59_t *m48t59;
  473. int PPC_io_memory;
  474. int linux_boot, i, nb_nics1, bios_size;
  475. ram_addr_t ram_offset, vga_ram_offset, bios_offset;
  476. uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
  477. PCIBus *pci_bus;
  478. qemu_irq *i8259;
  479. int ppc_boot_device;
  480. int index;
  481. BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
  482. BlockDriverState *fd[MAX_FD];
  483. sysctrl = qemu_mallocz(sizeof(sysctrl_t));
  484. linux_boot = (kernel_filename != NULL);
  485. /* init CPUs */
  486. if (cpu_model == NULL)
  487. cpu_model = "default";
  488. for (i = 0; i < smp_cpus; i++) {
  489. env = cpu_init(cpu_model);
  490. if (!env) {
  491. fprintf(stderr, "Unable to find PowerPC CPU definition\n");
  492. exit(1);
  493. }
  494. if (env->flags & POWERPC_FLAG_RTC_CLK) {
  495. /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
  496. cpu_ppc_tb_init(env, 7812500UL);
  497. } else {
  498. /* Set time-base frequency to 100 Mhz */
  499. cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
  500. }
  501. qemu_register_reset(&cpu_ppc_reset, env);
  502. envs[i] = env;
  503. }
  504. /* allocate RAM */
  505. ram_offset = qemu_ram_alloc(ram_size);
  506. cpu_register_physical_memory(0, ram_size, ram_offset);
  507. /* allocate VGA RAM */
  508. vga_ram_offset = qemu_ram_alloc(vga_ram_size);
  509. /* allocate and load BIOS */
  510. bios_offset = qemu_ram_alloc(BIOS_SIZE);
  511. if (bios_name == NULL)
  512. bios_name = BIOS_FILENAME;
  513. snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
  514. bios_size = load_image(buf, phys_ram_base + bios_offset);
  515. if (bios_size < 0 || bios_size > BIOS_SIZE) {
  516. cpu_abort(env, "qemu: could not load PPC PREP bios '%s'\n", buf);
  517. exit(1);
  518. }
  519. if (env->nip < 0xFFF80000 && bios_size < 0x00100000) {
  520. cpu_abort(env, "PowerPC 601 / 620 / 970 need a 1MB BIOS\n");
  521. }
  522. bios_size = (bios_size + 0xfff) & ~0xfff;
  523. cpu_register_physical_memory((uint32_t)(-bios_size),
  524. bios_size, bios_offset | IO_MEM_ROM);
  525. if (linux_boot) {
  526. kernel_base = KERNEL_LOAD_ADDR;
  527. /* now we can load the kernel */
  528. kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
  529. if (kernel_size < 0) {
  530. cpu_abort(env, "qemu: could not load kernel '%s'\n",
  531. kernel_filename);
  532. exit(1);
  533. }
  534. /* load initrd */
  535. if (initrd_filename) {
  536. initrd_base = INITRD_LOAD_ADDR;
  537. initrd_size = load_image(initrd_filename,
  538. phys_ram_base + initrd_base);
  539. if (initrd_size < 0) {
  540. cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
  541. initrd_filename);
  542. exit(1);
  543. }
  544. } else {
  545. initrd_base = 0;
  546. initrd_size = 0;
  547. }
  548. ppc_boot_device = 'm';
  549. } else {
  550. kernel_base = 0;
  551. kernel_size = 0;
  552. initrd_base = 0;
  553. initrd_size = 0;
  554. ppc_boot_device = '\0';
  555. /* For now, OHW cannot boot from the network. */
  556. for (i = 0; boot_device[i] != '\0'; i++) {
  557. if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
  558. ppc_boot_device = boot_device[i];
  559. break;
  560. }
  561. }
  562. if (ppc_boot_device == '\0') {
  563. fprintf(stderr, "No valid boot device for Mac99 machine\n");
  564. exit(1);
  565. }
  566. }
  567. isa_mem_base = 0xc0000000;
  568. if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
  569. cpu_abort(env, "Only 6xx bus is supported on PREP machine\n");
  570. exit(1);
  571. }
  572. i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
  573. pci_bus = pci_prep_init(i8259);
  574. // pci_bus = i440fx_init();
  575. /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
  576. PPC_io_memory = cpu_register_io_memory(0, PPC_prep_io_read,
  577. PPC_prep_io_write, sysctrl);
  578. cpu_register_physical_memory(0x80000000, 0x00800000, PPC_io_memory);
  579. /* init basic PC hardware */
  580. pci_vga_init(pci_bus, phys_ram_base + vga_ram_offset,
  581. vga_ram_offset, vga_ram_size, 0, 0);
  582. // openpic = openpic_init(0x00000000, 0xF0000000, 1);
  583. // pit = pit_init(0x40, i8259[0]);
  584. rtc_init(0x70, i8259[8], 2000);
  585. serial_init(0x3f8, i8259[4], 115200, serial_hds[0]);
  586. nb_nics1 = nb_nics;
  587. if (nb_nics1 > NE2000_NB_MAX)
  588. nb_nics1 = NE2000_NB_MAX;
  589. for(i = 0; i < nb_nics1; i++) {
  590. if (nd_table[i].model == NULL) {
  591. nd_table[i].model = "ne2k_isa";
  592. }
  593. if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
  594. isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
  595. } else {
  596. pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
  597. }
  598. }
  599. if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
  600. fprintf(stderr, "qemu: too many IDE bus\n");
  601. exit(1);
  602. }
  603. for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
  604. index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
  605. if (index != -1)
  606. hd[i] = drives_table[index].bdrv;
  607. else
  608. hd[i] = NULL;
  609. }
  610. for(i = 0; i < MAX_IDE_BUS; i++) {
  611. isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
  612. hd[2 * i],
  613. hd[2 * i + 1]);
  614. }
  615. i8042_init(i8259[1], i8259[12], 0x60);
  616. DMA_init(1);
  617. // AUD_init();
  618. // SB16_init();
  619. for(i = 0; i < MAX_FD; i++) {
  620. index = drive_get_index(IF_FLOPPY, 0, i);
  621. if (index != -1)
  622. fd[i] = drives_table[index].bdrv;
  623. else
  624. fd[i] = NULL;
  625. }
  626. fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
  627. /* Register speaker port */
  628. register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
  629. register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL);
  630. /* Register fake IO ports for PREP */
  631. sysctrl->reset_irq = first_cpu->irq_inputs[PPC6xx_INPUT_HRESET];
  632. register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl);
  633. register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl);
  634. /* System control ports */
  635. register_ioport_read(0x0092, 0x01, 1, &PREP_io_800_readb, sysctrl);
  636. register_ioport_write(0x0092, 0x01, 1, &PREP_io_800_writeb, sysctrl);
  637. register_ioport_read(0x0800, 0x52, 1, &PREP_io_800_readb, sysctrl);
  638. register_ioport_write(0x0800, 0x52, 1, &PREP_io_800_writeb, sysctrl);
  639. /* PCI intack location */
  640. PPC_io_memory = cpu_register_io_memory(0, PPC_intack_read,
  641. PPC_intack_write, NULL);
  642. cpu_register_physical_memory(0xBFFFFFF0, 0x4, PPC_io_memory);
  643. /* PowerPC control and status register group */
  644. #if 0
  645. PPC_io_memory = cpu_register_io_memory(0, PPC_XCSR_read, PPC_XCSR_write,
  646. NULL);
  647. cpu_register_physical_memory(0xFEFF0000, 0x1000, PPC_io_memory);
  648. #endif
  649. if (usb_enabled) {
  650. usb_ohci_init_pci(pci_bus, 3, -1);
  651. }
  652. m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
  653. if (m48t59 == NULL)
  654. return;
  655. sysctrl->nvram = m48t59;
  656. /* Initialise NVRAM */
  657. nvram.opaque = m48t59;
  658. nvram.read_fn = &m48t59_read;
  659. nvram.write_fn = &m48t59_write;
  660. PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
  661. kernel_base, kernel_size,
  662. kernel_cmdline,
  663. initrd_base, initrd_size,
  664. /* XXX: need an option to load a NVRAM image */
  665. 0,
  666. graphic_width, graphic_height, graphic_depth);
  667. /* Special port to get debug messages from Open-Firmware */
  668. register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
  669. }
  670. QEMUMachine prep_machine = {
  671. .name = "prep",
  672. .desc = "PowerPC PREP platform",
  673. .init = ppc_prep_init,
  674. .ram_require = BIOS_SIZE + VGA_RAM_SIZE,
  675. .max_cpus = MAX_CPUS,
  676. };