/* the new am7930 function: */ TME_ELEMENT_X_NEW_DECL(tme_ic_,am7930,am7930) { struct tme_am7930 *am7930; int arg_i; int usage; /* check our arguments: */ usage = 0; arg_i = 1; for (;;) { if (0) { } /* if we ran out of arguments: */ else if (args[arg_i] == NULL) { break; } /* otherwise this is a bad argument: */ else { tme_output_append_error(_output, "%s %s, ", args[arg_i], _("unexpected")); usage = TRUE; break; } } if (usage) { tme_output_append_error(_output, "%s %s", _("usage:"), args[0]); return (EINVAL); } /* start the am7930 structure: */ am7930 = tme_new0(struct tme_am7930, 1); am7930->tme_am7930_element = element; tme_mutex_init(&am7930->tme_am7930_mutex); /* initialize our simple bus device descriptor: */ am7930->tme_am7930_device.tme_bus_device_element = element; am7930->tme_am7930_device.tme_bus_device_tlb_fill = _tme_am7930_tlb_fill; am7930->tme_am7930_device.tme_bus_device_address_last = TME_AM7930_SIZ_REGS - 1; am7930->tme_am7930_device.tme_bus_device_signal = _tme_am7930_signal; /* fill the element: */ element->tme_element_private = am7930; element->tme_element_connections_new = _tme_am7930_connections_new; /* reset the am7930: */ _tme_am7930_reset(am7930); return (TME_OK); }
/* the new sun_obie function: */ int tme_sun_obie(struct tme_element *element, const char * const *args, char **_output) { struct tme_sun_obie *sun_obie; int arg_i; int usage; /* check our arguments: */ usage = 0; arg_i = 1; for (;;) { if (0) { } /* if we ran out of arguments: */ else if (args[arg_i] == NULL) { break; } /* otherwise this is a bad argument: */ else { tme_output_append_error(_output, "%s %s, ", args[arg_i], _("unexpected")); usage = TRUE; break; } } if (usage) { tme_output_append_error(_output, "%s %s", _("usage:"), args[0]); return (EINVAL); } /* start the sun_obie structure: */ sun_obie = tme_new0(struct tme_sun_obie, 1); sun_obie->tme_sun_obie_element = element; TME_SUN_OBIE_CSR_PUT(sun_obie, (TME_SUN_OBIE_CSR_NORESET | TME_SUN_OBIE_CSR_NOLOOP)); tme_mutex_init(&sun_obie->tme_sun_obie_mutex); tme_rwlock_init(&sun_obie->tme_sun_obie_rwlock); /* fill the element: */ element->tme_element_private = sun_obie; element->tme_element_connections_new = _tme_sun_obie_connections_new; return (TME_OK); }
/* the new serial function: */ TME_ELEMENT_SUB_NEW_DECL(tme_host_posix,serial) { struct tme_posix_serial *serial; const char *filename_in; const char *filename_out; int fd_in, fd_out; int usage; int arg_i; int saved_errno; int emulate_break; /* initialize: */ filename_in = NULL; filename_out = NULL; emulate_break = FALSE; arg_i = 1; usage = FALSE; /* loop reading our arguments: */ for (;;) { /* the device we're supposed to use for input: */ if (TME_ARG_IS(args[arg_i + 0], "device-input") && args[arg_i + 1] != NULL && filename_in == NULL) { filename_in = args[arg_i + 1]; arg_i += 2; } /* the device we're supposed to use for output: */ else if (TME_ARG_IS(args[arg_i + 0], "device-output") && args[arg_i + 1] != NULL && filename_out == NULL) { filename_out = args[arg_i + 1]; arg_i += 2; } /* the device we're supposed to use for input and output: */ else if (TME_ARG_IS(args[arg_i + 0], "device") && args[arg_i + 1] != NULL && filename_in == NULL && filename_out == NULL) { filename_in = filename_out = args[arg_i + 1]; arg_i += 2; } /* if we're supposed to emulate break: */ else if (TME_ARG_IS(args[arg_i + 0], "break-carats")) { emulate_break = TRUE; arg_i++; } /* if we've run out of arguments: */ else if (args[arg_i + 0] == NULL) { /* we must have been given input and output devices: */ if (filename_in == NULL || filename_out == NULL) { usage = TRUE; } break; } /* this is a bad argument: */ else { tme_output_append_error(_output, "%s %s", args[arg_i], _("unexpected")); usage = TRUE; break; } } if (usage) { tme_output_append_error(_output, "%s %s { device %s | { device-input %s device-output %s } } [break-carats]", _("usage:"), args[0], _("DEVICE"), _("DEVICE"), _("DEVICE")); return (EINVAL); } /* open the devices: */ fd_in = fd_out = -1; if (fd_in < 0 && !strcmp(filename_in, "-")) { fd_in = STDIN_FILENO; } if (fd_out < 0 && !strcmp(filename_out, "-")) { fd_out = STDOUT_FILENO; } if (fd_in < 0) { if (strcmp(filename_in, filename_out) == 0) { if (strcmp(filename_in, "pty") == 0) { fd_in = fd_out = posix_openpt(O_RDWR | O_NONBLOCK); if (fd_in != -1) { int serrno; if (grantpt(fd_in) == -1) { bad: serrno = errno; (void)close(fd_in); (void)close(fd_out); errno = serrno; } else { filename_in = filename_out = ptsname(fd_in); if (filename_in) { tme_output_append(_output, "Using %s as console\n", filename_in); } else { goto bad; } } } } else { fd_in = fd_out = open(filename_in, O_RDWR | O_NONBLOCK); } } else { fd_in = open(filename_in, O_RDONLY | O_NONBLOCK); } if (fd_in < 0) { tme_output_append_error(_output, "%s", filename_in); return (errno); } } if (fd_out < 0) { fd_out = open(filename_out, O_WRONLY | O_NONBLOCK); if (fd_out < 0) { saved_errno = errno; close(fd_in); tme_output_append_error(_output, "%s", filename_out); return (saved_errno); } } /* start the serial structure: */ serial = tme_new0(struct tme_posix_serial, 1); serial->tme_posix_serial_element = element; serial->tme_posix_serial_fd_in = fd_in; serial->tme_posix_serial_fd_out = fd_out; serial->tme_posix_serial_emulate_break = emulate_break; serial->tme_posix_serial_ctrl_callout = 0; serial->tme_posix_serial_ctrl_callout_last = 0; tme_serial_buffer_init(&serial->tme_posix_serial_buffer_in, TME_POSIX_SERIAL_BUFFER_SIZE); tme_serial_buffer_init(&serial->tme_posix_serial_buffer_out, TME_POSIX_SERIAL_BUFFER_SIZE); /* start the threads: */ tme_mutex_init(&serial->tme_posix_serial_mutex); tme_cond_init(&serial->tme_posix_serial_cond_writer); tme_thread_create((tme_thread_t) _tme_posix_serial_th_writer, serial); tme_thread_create((tme_thread_t) _tme_posix_serial_th_reader, serial); tme_thread_create((tme_thread_t) _tme_posix_serial_th_ctrl, serial); /* fill the element: */ element->tme_element_private = serial; element->tme_element_connections_new = _tme_posix_serial_connections_new; return (TME_OK); }