emul_bugapi.c 19 KB

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