summaryrefslogtreecommitdiff
path: root/s51/s51-main.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2008-12-21 23:33:35 -0800
committerKeith Packard <keithp@keithp.com>2008-12-21 23:33:42 -0800
commite75918f3667a5c8ad294bec4acef6fe81682edf6 (patch)
tree49c4411b2becaa874693f829876df703a9191f02 /s51/s51-main.c
parentf7d49868aeae80d515b12a7e339628f1296754a6 (diff)
Add preliminary version of s51, a UI clone of the 8051 emulator.
sdcdb provides source-level debugging using the 8051 emulator, s51. By emulating that emulator a the UI level, we should be able to get source debugging right on our target platform. This is just the preliminary structure for the program with most commands not yet implemented.
Diffstat (limited to 's51/s51-main.c')
-rw-r--r--s51/s51-main.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/s51/s51-main.c b/s51/s51-main.c
new file mode 100644
index 00000000..e8bf2d7d
--- /dev/null
+++ b/s51/s51-main.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2008 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "s51.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+static int s51_port = 0;
+static char *cpu = "8051";
+static double freq = 11059200;
+char *s51_prompt = "> ";
+struct ccdbg *s51_dbg;
+
+static void
+usage(void)
+{
+ fprintf(stderr, "You're doing it wrong.\n");
+ exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+ int flags, opt;
+ FILE *console_in = stdin;
+ FILE *console_out = stdout;
+ char *endptr;
+
+ while ((opt = getopt(argc, argv, "PVvHht:X:c:Z:s:S:p:")) != -1) {
+ switch (opt) {
+ case 't':
+ cpu = optarg;
+ break;
+ case 'X':
+ freq = strtod(optarg, &endptr);
+ if (endptr == optarg)
+ usage();
+ if (endptr[0] != '\0') {
+ if (!strcmp(endptr, "k"))
+ freq *= 1000;
+ else if (!strcmp(endptr, "M") )
+ freq *= 1000000;
+ else
+ usage ();
+ }
+ break;
+ case 'c':
+ break;
+ case 'Z':
+ s51_port = strtol(optarg, &endptr, 0);
+ if (endptr == optarg || strlen(endptr) != 0)
+ usage();
+ break;
+ case 's':
+ break;
+ case 'S':
+ break;
+ case 'p':
+ s51_prompt = optarg;
+ break;
+ case 'P':
+ s51_prompt = NULL;
+ break;
+ case 'V':
+ break;
+ case 'v':
+ break;
+ case 'H':
+ exit (0);
+ break;
+ case 'h':
+ usage ();
+ break;
+ }
+ }
+ if (s51_port) {
+ int l, r, one = 1;
+ int s;
+ struct sockaddr_in in;
+
+ l = socket(AF_INET, SOCK_STREAM, 0);
+ if (l < 0) {
+ perror ("socket");
+ exit(1);
+ }
+ in.sin_family = AF_INET;
+ in.sin_port = htons(s51_port);
+ in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ r = bind(l, (struct sockaddr *) &in, sizeof (in));
+ if (r) {
+ perror("bind");
+ exit(1);
+ }
+ r = setsockopt(l, SOL_SOCKET, SO_REUSEADDR, &one, sizeof (int));
+ if (r) {
+ perror("setsockopt");
+ exit(1);
+ }
+ r = listen(l, 5);
+ if (r) {
+ perror("listen");
+ exit(1);
+ }
+ for (;;) {
+ struct sockaddr_in client_addr;
+ socklen_t client_len = sizeof (struct sockaddr_in);
+ FILE *client;
+
+ s = accept(r, (struct sockaddr *)
+ &client_addr, &client_len);
+ if (s < 0) {
+ perror("accept");
+ exit(1);
+ }
+ client = fdopen(s, "rw");
+ if (!client) {
+ perror("fdopen");
+ exit(1);
+ }
+ command_read(client, client);
+ fclose(client);
+ }
+ } else
+ command_read(console_in, console_out);
+ exit(0);
+}