emul_bugapi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _EMUL_BUGAPI_C_
  15. #define _EMUL_BUGAPI_C_
  16. /* Note: this module is called via a table. There is no benefit in
  17. making it inline */
  18. #include "emul_generic.h"
  19. #include "emul_bugapi.h"
  20. #ifdef HAVE_UNISTD_H
  21. #include <unistd.h>
  22. #endif
  23. #include <stdlib.h>
  24. #include <string.h>
  25. /* EMULATION
  26. BUG - Motorola's embeded firmware BUG interface
  27. DESCRIPTION
  28. */
  29. /* from PowerPCBug Debugging Package User's Manual, part 2 of 2 and also bug.S - Dale Rahn */
  30. #define _INCHR 0x000 /* Input character */
  31. #define _INSTAT 0x001 /* Input serial port status */
  32. #define _INLN 0x002 /* Input line (pointer / pointer format) */
  33. #define _READSTR 0x003 /* Input string (pointer / count format) */
  34. #define _READLN 0x004 /* Input line (pointer / count format) */
  35. #define _CHKBRK 0x005 /* Check for break */
  36. #define _DSKRD 0x010 /* Disk read */
  37. #define _DSKWR 0x011 /* Disk write */
  38. #define _DSKCFIG 0x012 /* Disk configure */
  39. #define _DSKFMT 0x014 /* Disk format */
  40. #define _DSKCTRL 0x015 /* Disk control */
  41. #define _NETRD 0x018 /* Read from host */
  42. #define _NETWR 0x019 /* Write to host */
  43. #define _NETCFIG 0x01a /* Configure network parameters */
  44. #define _NETOPN 0x01b /* Open file for reading */
  45. #define _NETFRD 0x01c /* Retreive specified file blocks */
  46. #define _NETCTRL 0x01d /* Implement special control functions */
  47. #define _OUTCHR 0x020 /* Output character (pointer / pointer format) */
  48. #define _OUTSTR 0x021 /* Output string (pointer / pointer format) */
  49. #define _OUTLN 0x022 /* Output line (pointer / pointer format) */
  50. #define _WRITE 0x023 /* Output string (pointer / count format) */
  51. #define _WRITELN 0x024 /* Output line (pointer / count format) */
  52. #define _WRITDLN 0x025 /* Output line with data (pointer / count format) */
  53. #define _PCRLF 0x026 /* Output carriage return and line feed */
  54. #define _ERASLN 0x027 /* Erase line */
  55. #define _WRITD 0x028 /* Output string with data (pointer / count format) */
  56. #define _SNDBRK 0x029 /* Send break */
  57. #define _DELAY 0x043 /* Timer delay */
  58. #define _RTC_TM 0x050 /* Time initialization for RTC */
  59. #define _RTC_DT 0x051 /* Date initialization for RTC */
  60. #define _RTC_DSP 0x052 /* Display RTC time and date */
  61. #define _RTC_RD 0x053 /* Read the RTC registers */
  62. #define _REDIR 0x060 /* Redirect I/O of a system call function */
  63. #define _REDIR_I 0x061 /* Redirect input */
  64. #define _REDIR_O 0x062 /* Redirect output */
  65. #define _RETURN 0x063 /* Return to PPCbug */
  66. #define _BINDEC 0x064 /* Convert binary to binary coded decimal (BCD) */
  67. #define _CHANGEV 0x067 /* Parse value */
  68. #define _STRCMP 0x068 /* Compare two strings (pointer / count format) */
  69. #define _MULU32 0x069 /* Multiply two 32-bit unsigned integers */
  70. #define _DIVU32 0x06a /* Divide two 32-bit unsigned integers */
  71. #define _CHK_SUM 0x06b /* Generate checksum */
  72. #define _BRD_ID 0x070 /* Return pointer to board ID packet */
  73. #define _ENVIRON 0x071 /* Access boot environment parameters */
  74. #define _DIAGFCN 0x074 /* Diagnostic function(s) */
  75. #define _SIOPEPS 0x090 /* Retrieve SCSI pointers */
  76. #define _IOINQ 0x120 /* Port inquire */
  77. #define _IOINFORM 0x124 /* Port inform */
  78. #define _IOCONFIG 0x128 /* Port configure */
  79. #define _IODELETE 0x12c /* Port delete */
  80. #define _SYMBOLTA 0x130 /* Attach symbol table */
  81. #define _SYMBOLDA 0x131 /* Detach symbol table */
  82. struct bug_map {
  83. int value;
  84. const char *info;
  85. };
  86. static const struct bug_map bug_mapping[] = {
  87. { _INCHR, ".INCHR -- Input character" },
  88. { _INSTAT, ".INSTAT -- Input serial port status" },
  89. { _INLN, ".INLN -- Input line (pointer / pointer format)" },
  90. { _READSTR, ".READSTR -- Input string (pointer / count format)" },
  91. { _READLN, ".READLN -- Input line (pointer / count format)" },
  92. { _CHKBRK, ".CHKBRK -- Check for break" },
  93. { _DSKRD, ".DSKRD -- Disk read" },
  94. { _DSKWR, ".DSKWR -- Disk write" },
  95. { _DSKCFIG, ".DSKCFIG -- Disk configure" },
  96. { _DSKFMT, ".DSKFMT -- Disk format" },
  97. { _DSKCTRL, ".DSKCTRL -- Disk control" },
  98. { _NETRD, ".NETRD -- Read from host" },
  99. { _NETWR, ".NETWR -- Write to host" },
  100. { _NETCFIG, ".NETCFIG -- Configure network parameters" },
  101. { _NETOPN, ".NETOPN -- Open file for reading" },
  102. { _NETFRD, ".NETFRD -- Retreive specified file blocks" },
  103. { _NETCTRL, ".NETCTRL -- Implement special control functions" },
  104. { _OUTCHR, ".OUTCHR -- Output character" },
  105. { _OUTSTR, ".OUTSTR -- Output string (pointer / pointer format)" },
  106. { _OUTLN, ".OUTLN -- Output line (pointer / pointer format)" },
  107. { _WRITE, ".WRITE -- Output string (pointer / count format)" },
  108. { _WRITELN, ".WRITELN -- Output line (pointer / count format)" },
  109. { _WRITDLN, ".WRITDLN -- Output line with data (pointer / count format)" },
  110. { _PCRLF, ".PCRLF -- Output carriage return and line feed" },
  111. { _ERASLN, ".ERASLN -- Erase line" },
  112. { _WRITD, ".WRITD -- Output string with data (pointer / count format)" },
  113. { _SNDBRK, ".SNDBRK -- Send break" },
  114. { _DELAY, ".DELAY -- Timer delay" },
  115. { _RTC_TM, ".RTC_TM -- Time initialization for RTC" },
  116. { _RTC_DT, ".RTC_DT -- Date initialization for RTC" },
  117. { _RTC_DSP, ".RTC_DSP -- Display RTC time and date" },
  118. { _RTC_RD, ".RTC_RD -- Read the RTC registers" },
  119. { _REDIR, ".REDIR -- Redirect I/O of a system call function" },
  120. { _REDIR, ".REDIR -- Redirect input" },
  121. { _REDIR, ".REDIR -- Redirect output" },
  122. { _RETURN, ".RETURN -- Return to PPCbug" },
  123. { _BINDEC, ".BINDEC -- Convert binary to binary coded decimal (BCD)" },
  124. { _CHANGEV, ".CHANGEV -- Parse value" },
  125. { _STRCMP, ".STRCMP -- Compare two strings (pointer / count format)" },
  126. { _MULU32, ".MULU32 -- Multiply two 32-bit unsigned integers" },
  127. { _DIVU32, ".DIVU32 -- Divide two 32-bit unsigned integers" },
  128. { _CHK_SUM, ".CHK_SUM -- Generate checksum" },
  129. { _BRD_ID, ".BRD_ID -- Return pointer to board ID packet" },
  130. { _ENVIRON, ".ENVIRON -- Access boot environment parameters" },
  131. { _DIAGFCN, ".DIAGFCN -- Diagnostic function(s)" },
  132. { _SIOPEPS, ".SIOPEPS -- Retrieve SCSI pointers" },
  133. { _IOINQ, ".IOINQ -- Port inquire" },
  134. { _IOINFORM, ".IOINFORM -- Port inform" },
  135. { _IOCONFIG, ".IOCONFIG -- Port configure" },
  136. { _IODELETE, ".IODELETE -- Port delete" },
  137. { _SYMBOLTA, ".SYMBOLTA -- Attach symbol table" },
  138. { _SYMBOLDA, ".SYMBOLDA -- Detach symbol table" },
  139. };
  140. #ifndef BUGAPI_END_ADDRESS
  141. #define BUGAPI_END_ADDRESS 0x100000
  142. #endif
  143. enum {
  144. nr_bugapi_disks = 2,
  145. };
  146. struct _os_emul_data {
  147. device *root;
  148. unsigned_word memory_size;
  149. unsigned_word top_of_stack;
  150. int interrupt_prefix;
  151. unsigned_word interrupt_vector_address;
  152. unsigned_word system_call_address;
  153. unsigned_word stall_cpu_loop_address;
  154. int little_endian;
  155. int floating_point_available;
  156. /* I/O devices */
  157. device_instance *output;
  158. device_instance *input;
  159. device_instance *(disk[nr_bugapi_disks]);
  160. };
  161. static os_emul_data *
  162. emul_bugapi_create(device *root,
  163. bfd *image,
  164. const char *name)
  165. {
  166. device *node;
  167. os_emul_data *bugapi;
  168. char *filename;
  169. /* check it really is for us */
  170. if (name != NULL
  171. && strcmp(name, "bugapi") != 0
  172. && strcmp(name, "bug") != 0)
  173. return NULL;
  174. if (image != NULL
  175. && name == NULL
  176. && bfd_get_start_address(image) >= BUGAPI_END_ADDRESS)
  177. return NULL;
  178. bugapi = ZALLOC(os_emul_data);
  179. /* options */
  180. emul_add_tree_options(root, image, "bug", "oea",
  181. 1 /*oea-interrupt-prefix*/);
  182. /* add some real hardware, include eeprom memory for the eeprom trap
  183. addresses */
  184. emul_add_tree_hardware(root);
  185. node = tree_parse(root, "/openprom/memory@0xfff00000");
  186. tree_parse(node, "./psim,description \"eeprom trap addresses");
  187. tree_parse(node, "./reg 0xfff00000 0x3000");
  188. bugapi->root = root;
  189. bugapi->memory_size
  190. = tree_find_integer_property(root, "/openprom/options/oea-memory-size");
  191. bugapi->interrupt_prefix =
  192. tree_find_integer_property(root, "/openprom/options/oea-interrupt-prefix");
  193. bugapi->interrupt_vector_address = (bugapi->interrupt_prefix
  194. ? MASK(0, 43)
  195. : 0);
  196. bugapi->system_call_address = (bugapi->interrupt_vector_address + 0x00c00);
  197. bugapi->stall_cpu_loop_address = (bugapi->system_call_address + 0x000f0);
  198. bugapi->top_of_stack = bugapi->memory_size - 0x1000;
  199. bugapi->little_endian
  200. = tree_find_boolean_property(root, "/options/little-endian?");
  201. bugapi->floating_point_available
  202. = tree_find_boolean_property(root, "/openprom/options/floating-point?");
  203. bugapi->input = NULL;
  204. bugapi->output = NULL;
  205. /* initialization */
  206. if (image != NULL)
  207. tree_parse(root, "/openprom/init/register/0.pc 0x%lx",
  208. (unsigned long)bfd_get_start_address(image));
  209. tree_parse(root, "/openprom/init/register/pc 0x%lx",
  210. (unsigned long)bugapi->stall_cpu_loop_address);
  211. tree_parse(root, "/openprom/init/register/sp 0x%lx",
  212. (unsigned long)(bugapi->top_of_stack - 16));
  213. tree_parse(root, "/openprom/init/register/msr 0x%x",
  214. (msr_recoverable_interrupt
  215. | (bugapi->little_endian
  216. ? (msr_little_endian_mode
  217. | msr_interrupt_little_endian_mode)
  218. : 0)
  219. | (bugapi->floating_point_available
  220. ? msr_floating_point_available
  221. : 0)
  222. | (bugapi->interrupt_prefix
  223. ? msr_interrupt_prefix
  224. : 0)
  225. ));
  226. /* patch the system call instruction to call this emulation and then
  227. do an rfi */
  228. node = tree_parse(root, "/openprom/init/data@0x%lx",
  229. (unsigned long)bugapi->system_call_address);
  230. tree_parse(node, "./psim,description \"system-call trap instruction");
  231. tree_parse(node, "./real-address 0x%lx",
  232. (unsigned long)bugapi->system_call_address);
  233. tree_parse(node, "./data 0x%x", emul_call_instruction);
  234. node = tree_parse(root, "/openprom/init/data@0x%lx",
  235. (unsigned long)bugapi->system_call_address + 4);
  236. tree_parse(node, "./psim,description \"return from interrupt instruction");
  237. tree_parse(node, "./real-address 0x%lx",
  238. (unsigned long)bugapi->system_call_address + 4);
  239. tree_parse(node, "./data 0x%x",
  240. emul_rfi_instruction);
  241. /* patch the end of the system call instruction so that it contains
  242. a loop to self instruction and point all the cpu's at this */
  243. node = tree_parse(root, "/openprom/init/data@0x%lx",
  244. (unsigned long)bugapi->stall_cpu_loop_address);
  245. tree_parse(node, "./psim,description \"cpu-loop instruction");
  246. tree_parse(node, "./real-address 0x%lx",
  247. (unsigned long)bugapi->stall_cpu_loop_address);
  248. tree_parse(node, "./data 0x%lx",
  249. (unsigned long)emul_loop_instruction);
  250. if (image != NULL)
  251. tree_parse(root, "/openprom/init/stack/stack-type %s",
  252. (image->xvec->flavour == bfd_target_elf_flavour
  253. ? "ppc-elf"
  254. : "ppc-xcoff"));
  255. if (image != NULL)
  256. {
  257. filename = tree_quote_property (bfd_get_filename(image));
  258. tree_parse(root, "/openprom/init/load-binary/file-name %s",
  259. filename);
  260. free (filename);
  261. }
  262. return bugapi;
  263. }
  264. static void
  265. emul_bugapi_init(os_emul_data *bugapi,
  266. int nr_cpus)
  267. {
  268. int i;
  269. /* get the current input/output devices that were created during
  270. device tree initialization */
  271. bugapi->input = tree_find_ihandle_property(bugapi->root, "/chosen/stdin");
  272. bugapi->output = tree_find_ihandle_property(bugapi->root, "/chosen/stdout");
  273. /* if present, extract the selected disk devices */
  274. for (i = 0; i < nr_bugapi_disks; i++) {
  275. char disk[32];
  276. char *chp;
  277. strcpy(disk, "/chosen/disk0");
  278. ASSERT(sizeof(disk) > strlen(disk));
  279. chp = strchr(disk, '0');
  280. *chp = *chp + i;
  281. if (tree_find_property(bugapi->root, disk) != NULL)
  282. bugapi->disk[i] = tree_find_ihandle_property(bugapi->root, disk);
  283. }
  284. }
  285. static const char *
  286. emul_bugapi_instruction_name(int call_id)
  287. {
  288. static char buffer[40];
  289. int i;
  290. for (i = 0; i < ARRAY_SIZE (bug_mapping); i++)
  291. {
  292. if (bug_mapping[i].value == call_id)
  293. return bug_mapping[i].info;
  294. }
  295. (void) sprintf (buffer, "Unknown bug call 0x%x", call_id);
  296. return buffer;
  297. }
  298. static int
  299. emul_bugapi_do_read(os_emul_data *bugapi,
  300. cpu *processor,
  301. unsigned_word cia,
  302. unsigned_word buf,
  303. int nbytes)
  304. {
  305. unsigned char *scratch_buffer;
  306. int status;
  307. /* get a tempoary bufer */
  308. scratch_buffer = (unsigned char *) zalloc(nbytes);
  309. /* check if buffer exists by reading it */
  310. emul_read_buffer((void *)scratch_buffer, buf, nbytes, processor, cia);
  311. /* read */
  312. status = device_instance_read(bugapi->input,
  313. (void *)scratch_buffer, nbytes);
  314. /* -1 = error, -2 = nothing available - see "serial" [IEEE1275] */
  315. if (status < 0) {
  316. status = 0;
  317. }
  318. if (status > 0) {
  319. emul_write_buffer((void *)scratch_buffer, buf, status, processor, cia);
  320. /* Bugapi chops off the trailing n, but leaves it in the buffer */
  321. if (scratch_buffer[status-1] == '\n' || scratch_buffer[status-1] == '\r')
  322. status--;
  323. }
  324. free(scratch_buffer);
  325. return status;
  326. }
  327. static void
  328. emul_bugapi_do_diskio(os_emul_data *bugapi,
  329. cpu *processor,
  330. unsigned_word cia,
  331. unsigned_word descriptor_addr,
  332. int call_id)
  333. {
  334. struct dskio_descriptor {
  335. unsigned_1 ctrl_lun;
  336. unsigned_1 dev_lun;
  337. unsigned_2 status;
  338. unsigned_word pbuffer;
  339. unsigned_4 blk_num;
  340. unsigned_2 blk_cnt;
  341. unsigned_1 flag;
  342. #define BUG_FILE_MARK 0x80
  343. #define IGNORE_FILENUM 0x02
  344. #define END_OF_FILE 0x01
  345. unsigned_1 addr_mod;
  346. } descriptor;
  347. int block;
  348. emul_read_buffer(&descriptor, descriptor_addr, sizeof(descriptor),
  349. processor, cia);
  350. T2H(descriptor.ctrl_lun);
  351. T2H(descriptor.dev_lun);
  352. T2H(descriptor.status);
  353. T2H(descriptor.pbuffer);
  354. T2H(descriptor.blk_num);
  355. T2H(descriptor.blk_cnt);
  356. T2H(descriptor.flag);
  357. T2H(descriptor.addr_mod);
  358. if (descriptor.dev_lun >= nr_bugapi_disks
  359. || bugapi->disk[descriptor.dev_lun] == NULL) {
  360. error("emul_bugapi_do_diskio: attempt to access unconfigured disk /chosen/disk%d",
  361. descriptor.dev_lun);
  362. }
  363. else {
  364. for (block = 0; block < descriptor.blk_cnt; block++) {
  365. device_instance *disk = bugapi->disk[descriptor.dev_lun];
  366. unsigned_1 buf[512]; /*????*/
  367. unsigned_word block_nr = descriptor.blk_num + block;
  368. unsigned_word byte_nr = block_nr * sizeof(buf);
  369. unsigned_word block_addr = descriptor.pbuffer + block*sizeof(buf);
  370. if (device_instance_seek(disk, 0, byte_nr) < 0)
  371. error("emul_bugapi_do_diskio: bad seek\n");
  372. switch (call_id) {
  373. case _DSKRD:
  374. if (device_instance_read(disk, buf, sizeof(buf)) != sizeof(buf))
  375. error("emul_`bugapi_do_diskio: bad read\n");
  376. emul_write_buffer(buf, block_addr, sizeof(buf), processor, cia);
  377. break;
  378. case _DSKWR:
  379. emul_read_buffer(buf, block_addr, sizeof(buf), processor, cia);
  380. if (device_instance_write(disk, buf, sizeof(buf)) != sizeof(buf))
  381. error("emul_bugapi_do_diskio: bad write\n");
  382. break;
  383. default:
  384. error("emul_bugapi_do_diskio: bad switch\n");
  385. }
  386. }
  387. }
  388. }
  389. static void
  390. emul_bugapi_do_write(os_emul_data *bugapi,
  391. cpu *processor,
  392. unsigned_word cia,
  393. unsigned_word buf,
  394. int nbytes,
  395. const char *suffix)
  396. {
  397. void *scratch_buffer = NULL;
  398. /* get a tempoary bufer */
  399. if (nbytes > 0)
  400. {
  401. scratch_buffer = zalloc(nbytes);
  402. /* copy in */
  403. emul_read_buffer(scratch_buffer, buf, nbytes,
  404. processor, cia);
  405. /* write */
  406. device_instance_write(bugapi->output, scratch_buffer, nbytes);
  407. free(scratch_buffer);
  408. }
  409. if (suffix)
  410. device_instance_write(bugapi->output, suffix, strlen(suffix));
  411. flush_stdoutput ();
  412. }
  413. static int
  414. emul_bugapi_instruction_call(cpu *processor,
  415. unsigned_word cia,
  416. unsigned_word ra,
  417. os_emul_data *bugapi)
  418. {
  419. const int call_id = cpu_registers(processor)->gpr[10];
  420. unsigned char uc;
  421. #define MY_INDEX itable_instruction_call
  422. ITRACE (trace_os_emul,
  423. (" 0x%x %s, r3 = 0x%lx, r4 = 0x%lx\n",
  424. call_id, emul_bugapi_instruction_name (call_id),
  425. (long)cpu_registers(processor)->gpr[3],
  426. (long)cpu_registers(processor)->gpr[4]));;
  427. /* check that this isn't an invalid instruction */
  428. if (cia != bugapi->system_call_address)
  429. return 0;
  430. switch (call_id) {
  431. default:
  432. error("emul-bugapi: unimplemented bugapi %s from address 0x%lx\n",
  433. emul_bugapi_instruction_name (call_id), SRR0);
  434. break;
  435. /* read a single character, output r3 = byte */
  436. /* FIXME: Add support to unbuffer input */
  437. case _INCHR:
  438. if (device_instance_read(bugapi->input, (void *)&uc, 1) <= 0)
  439. uc = 0;
  440. cpu_registers(processor)->gpr[3] = uc;
  441. break;
  442. /* read a line of at most 256 bytes, r3 = ptr to 1st byte, output r3 = ptr to last byte+1 */
  443. case _INLN:
  444. cpu_registers(processor)->gpr[3] += emul_bugapi_do_read(bugapi,
  445. processor, cia,
  446. cpu_registers(processor)->gpr[3],
  447. 256);
  448. break;
  449. /* output a character, r3 = character */
  450. case _OUTCHR:
  451. {
  452. char out = (char)cpu_registers(processor)->gpr[3];
  453. device_instance_write(bugapi->output, &out, 1);
  454. break;
  455. }
  456. /* output a string, r3 = ptr to 1st byte, r4 = ptr to last byte+1 */
  457. case _OUTSTR:
  458. emul_bugapi_do_write(bugapi,
  459. processor, cia,
  460. cpu_registers(processor)->gpr[3],
  461. cpu_registers(processor)->gpr[4] - cpu_registers(processor)->gpr[3],
  462. (const char *)0);
  463. break;
  464. /* output a string followed by \r\n, r3 = ptr to 1st byte, r4 = ptr to last byte+1 */
  465. case _OUTLN:
  466. emul_bugapi_do_write(bugapi,
  467. processor, cia,
  468. cpu_registers(processor)->gpr[3],
  469. cpu_registers(processor)->gpr[4] - cpu_registers(processor)->gpr[3],
  470. "\n");
  471. break;
  472. /* output a \r\n */
  473. case _PCRLF:
  474. device_instance_write(bugapi->output, "\n", 1);
  475. break;
  476. /* read/write blocks of data to/from the disk */
  477. case _DSKWR:
  478. case _DSKRD:
  479. emul_bugapi_do_diskio(bugapi, processor, cia,
  480. cpu_registers(processor)->gpr[3],
  481. call_id);
  482. break;
  483. /* return to ppcbug monitor (exiting with gpr[3] as status is not
  484. part of the bug monitor) */
  485. case _RETURN:
  486. cpu_halt(processor, cia, was_exited, cpu_registers(processor)->gpr[3]);
  487. break;
  488. }
  489. return 1;
  490. /* the instruction following this one is a RFI. Thus by just
  491. continuing the return from system call is performed */
  492. }
  493. const os_emul emul_bugapi = {
  494. "bugapi",
  495. emul_bugapi_create,
  496. emul_bugapi_init,
  497. 0, /*system_call*/
  498. emul_bugapi_instruction_call,
  499. 0 /*data*/
  500. };
  501. #endif