OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [jtag/] [jp2.c] - Blame information for rev 1259

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1246 markom
/* jp2-linux.c -- JTAG protocol via parallel port for linux
2
   Copyright(C) 2001 Marko Mlinar, markom@opencores.org
3
   Code for TCP/IP copied from gdb, by Chris Ziomkowski
4
 
5
This file is part of OpenRISC 1000 Architectural Simulator.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
 
21
/* Establishes jtag proxy server and communicates with parallel
22
 port directly.  Requires root access. */
23
 
24
#include <stdio.h>
25
#include <ctype.h>
26
#include <string.h>
27
#include <stdlib.h>
28
#include <unistd.h>
29
#include <stdarg.h>
30 1259 markom
#include <sys/stat.h>
31
#include <sys/types.h>
32 1246 markom
 
33
/* Dirty way to include inb and outb from, but they say it is
34
   a standard one.  */
35
#include <asm/io.h>
36
#include <asm/system.h>
37
#include "mc.h"
38
#include "gdb.h"
39
#include "jp2.h"
40
 
41 1259 markom
#define TC_RESET           0
42
#define TC_BRIGHT          1
43
#define TC_DIM             2
44
#define TC_UNDERLINE       3
45
#define TC_BLINK           4
46
#define TC_REVERSE         7
47
#define TC_HIDDEN          8
48
 
49
#define TC_BLACK           0
50
#define TC_RED             1
51
#define TC_GREEN           2
52
#define TC_YELLOW          3
53
#define TC_BLUE            4
54
#define TC_MAGENTA         5
55
#define TC_CYAN            6
56
#define TC_WHITE           7
57
 
58 1246 markom
static int base = 0x378; /* FIXME: We should detect the address. */
59
int err = 0;
60
int set_pc = 0;
61
int set_step = 0;
62
int waiting = 0;
63
 
64
/* Scan chain info. */
65
static int chain_addr_size[] = { 0,  32, 0,  0,  5,  32, 32};
66
static int chain_data_size[] = { 0,  32, 0,  32, 32, 32, 32};
67
static int chain_is_valid[]  = { 0,  1,  0,  1,  1,  1,   1};
68
static int chain_has_crc[]   = { 0,  1,  0,  1,  1,  1,   1};
69
static int chain_has_rw[]    = { 0,  1,  0,  0,  1,  1,   1};
70
 
71
/* Currently selected scan chain - just to prevent unnecessary
72
   transfers. */
73
static int current_chain = -1;
74
 
75
/* The chain that should be currently selected. */
76
static int dbg_chain = -1;
77
 
78
/* Crc of current read or written data.  */
79
static int crc_r, crc_w = 0;
80
 
81
/* Address of previous read */
82
static unsigned long prev_regno = 0;
83
 
84
/* Generates new crc, sending in new bit input_bit */
85
static unsigned long crc_calc(unsigned long crc, int input_bit) {
86
  unsigned long d = (input_bit&1) ? 0xfffffff : 0x0000000;
87
  unsigned long crc_32 = ((crc >> 31)&1) ? 0xfffffff : 0x0000000;
88
  crc <<= 1;
89
  return crc ^ (d ^ crc_32) & DBG_CRC_POLY;
90
}
91
 
92
/* Send a byte to parallel port. */
93
inline static void jp2_out(unsigned int value) {
94
#ifdef RTL_SIM
95
  time_t time;
96
  struct stat s;
97
  char buf[1000];
98
  FILE *fout;
99
  unsigned num_read;
100
  int r;
101
  fout = fopen(GDB_IN, "wt+");
102
  fprintf(fout, "F\n");
103
  fclose(fout);
104
  fout = fopen(GDB_OUT, "wt+");
105
  fprintf(fout, "%02X\n", value);
106
  fclose(fout);
107
error:
108
  fout = fopen(GDB_OUT, "rt");
109
  r = fscanf(fout,"%x", &num_read);
110
  fclose(fout);
111
  if(r == 0 || num_read !=(0x10 | value)) goto error;
112
#else
113
  outb(value, LPT_WRITE);
114
#endif /* RTL_SIM */
115 1259 markom
  if (!(value & TCLK_BIT)) {
116
    if (value & TMS_BIT) debug("%c[%d;%dm", 0x1b, TC_BRIGHT, TC_WHITE + 30);
117
    debug("%x",(value & TDI_BIT) != 0);
118
    debug("%c[%d;%dm", 0x1b, TC_RESET, TC_WHITE + 30);
119
  }
120 1246 markom
  flush_debug();
121
}
122
 
123
/* Receive a byte from parallel port.  */
124
inline static unsigned char jp2_in() {
125
  int data;
126
#ifndef RTL_SIM
127
  data = inb(LPT_READ);
128
#ifdef TDO_INV
129
  data =(data & TDO_BIT) != TDO_BIT;
130
#else
131
  data =(data & TDO_BIT) == TDO_BIT;
132
#endif
133
#else
134
  FILE *fin = 0;
135
  char ch;
136
  time_t time;
137
  struct stat s;
138
  while(1) {
139
    fin = fopen(GDB_IN, "rt");
140
    if(fin == 0) continue;
141
    ch = fgetc(fin);
142
    if(ch != '0' && ch != '1') {
143
      fclose(fin);
144
      continue;
145
    } else break;
146
  }
147
  fclose(fin);
148
  data = ch == '1';
149
#endif /* !RTL_SIM */
150 1259 markom
  debug("%c[%d;%dm", 0x1b, TC_BRIGHT, TC_GREEN + 30);
151
  debug("%01X", data);
152
  debug("%c[%d;%dm", 0x1b, TC_RESET, TC_WHITE + 30);
153 1246 markom
  flush_debug();
154
  return data;
155
}
156
 
157
/* Writes TCLK=0, TRST=1, TMS=bit1, TDI=bit0
158
   and    TCLK=1, TRST=1, TMS=bit1, TDI=bit0 */
159
static inline void jp2_write_JTAG(unsigned char packet) {
160
  unsigned char data = TRST_BIT;
161
  if(packet & 1) data |= TDI_BIT;
162
  if(packet & 2) data |= TMS_BIT;
163
 
164
  jp2_out(data);
165
  JTAG_WAIT();
166
  crc_w = crc_calc(crc_w, packet&1);
167
 
168
  /* rise clock */
169
  jp2_out(data | TCLK_BIT);
170
  JTAG_WAIT();
171
}
172
 
173
/* Reads TDI.  */
174
static inline int jp2_read_JTAG() {
175
  int data;
176
  data = jp2_in();
177
  crc_r = crc_calc(crc_r, data);
178
  return data;
179
}
180
 
181
/* Writes bitstream.  LS bit first if len < 0, MS bit first if len > 0.  */
182
static inline void jp2_write_stream(ULONGEST stream, int len, int set_last_bit) {
183
  int i;
184
  if (len < 0) {
185
    len = -len;
186 1259 markom
    debug("writeL%d(", len);
187 1246 markom
    for(i = 0; i < len - 1; i++)
188
      jp2_write_JTAG((stream >> i) & 1);
189
 
190
    if(set_last_bit) jp2_write_JTAG((stream >>(len - 1))& 1 | TMS);
191
    else jp2_write_JTAG((stream >>(len - 1))& 1);
192
  } else {
193 1259 markom
    debug("write%d(", len);
194 1246 markom
    for(i = 0; i < len - 1; i++)
195
      jp2_write_JTAG((stream >> (len - 1 - i)) & 1);
196
 
197
    if(set_last_bit) jp2_write_JTAG((stream >> 0) & 1 | TMS);
198
    else jp2_write_JTAG((stream >> 0)& 1);
199
  }
200
  debug(")\n");
201
}
202
 
203
/* Gets bitstream.  LS bit first if len < 0, MS bit first if len > 0.  */
204
inline static ULONGEST jp2_read_stream(unsigned long stream, int len, int set_last_bit) {
205
  int i;
206
  ULONGEST data = 0;
207
  if (len < 0) {
208 1259 markom
    debug("readL(");
209 1246 markom
    for(i = 0; i < len - 1; i++) {
210
      jp2_write_JTAG((stream >> i) & 1);   /* LSB first */
211
      data |= jp2_read_JTAG() << i; /* LSB first */
212
    }
213
 
214
    if (set_last_bit) jp2_write_JTAG((stream >> (len - 1)) & 1 | TMS);
215
    else jp2_write_JTAG((stream >> (len - 1)) & 1);
216
    data |= jp2_read_JTAG() << (len - 1);
217
  } else {
218 1259 markom
    debug("read(");
219 1246 markom
    for(i = 0; i < len - 1; i++) {
220
      jp2_write_JTAG((stream >> (len - 1 - i)) & 1);   /* MSB first */
221
      data |= jp2_read_JTAG() << (len - 1 - i); /* MSB first */
222
    }
223
 
224
    if (set_last_bit) jp2_write_JTAG((stream >> 0) & 1 | TMS);
225
    else jp2_write_JTAG((stream >> 0) & 1);
226
    data |= jp2_read_JTAG() << 0;
227
  }
228
  debug(")\n");
229
  return data;
230
}
231
 
232
/* Sets scan chain.  */
233
void jtag_set_ir(int ir) {
234
  jp2_write_JTAG(TMS); /* SELECT_DR SCAN */
235
  jp2_write_JTAG(TMS); /* SELECT_IR SCAN */
236
 
237
  jp2_write_JTAG(0); /* CAPTURE_IR */
238
  jp2_write_JTAG(0); /* SHIFT_IR */
239
 
240
  /* write data, EXIT1_IR */
241
  jp2_write_stream(ir, -JI_SIZE, 1);
242
 
243
  jp2_write_JTAG(TMS); /* UPDATE_IR */
244
  jp2_write_JTAG(0); /* IDLE */
245
  current_chain = -1;
246
}
247
 
248
/* Resets JTAG
249
   Writes TRST=0
250
   and    TRST=1 */
251
static void jp2_reset_JTAG() {
252
  int i;
253
  debug2("\nreset(");
254
  jp2_out(0);
255
  JTAG_RETRY_WAIT();
256
  /* In case we don't have TRST reset it manually */
257
  for(i = 0; i < 8; i++) jp2_write_JTAG(TMS);
258
  jp2_out(TRST_BIT);
259
  JTAG_RETRY_WAIT();
260
  jp2_write_JTAG(0);
261
  debug2(")\n");
262
}
263
 
264
/* Resets JTAG, and sets DEBUG scan chain */
265
static int dbg_reset() {
266
  int err;
267
  jp2_reset_JTAG();
268
  /* select debug scan chain and stay in it forever */
269
  jtag_set_ir(JI_DEBUG);
270
  current_chain = -1;
271
  return DBG_ERR_OK;
272
}
273 1259 markom
/* counts retries and returns zero if we should abort */
274 1246 markom
/* TODO: dinamically adjust timings for jp2 */
275
static int retry_no = 0;
276
int retry_do() {
277
  int i, err;
278 1259 markom
  printf("RETRY\n");
279 1246 markom
  if (retry_no >= NUM_SOFT_RETRIES) {
280
    if ((err = dbg_reset())) return err;
281
  } else { /* quick reset */
282
    for(i = 0; i < 8; i++) jp2_write_JTAG(TMS);
283
    jp2_write_JTAG(0); /* go into IDLE state */
284
  }
285
  if (retry_no >= NUM_SOFT_RETRIES + NUM_HARD_RETRIES) {
286
    retry_no = 0;
287 1259 markom
    return 0;
288 1246 markom
  }
289
  retry_no++;
290 1259 markom
  return 1;
291 1246 markom
}
292
 
293
/* resets retry counter */
294
void retry_ok() {
295
  retry_no = 0;
296
}
297
 
298
/* Sets scan chain.  */
299
int dbg_set_chain(int chain) {
300
  int status, crc_generated, crc_read;
301
  dbg_chain = chain;
302
 
303
try_again:
304
  if (current_chain == chain) return DBG_ERR_OK;
305
  current_chain = -1;
306
  debug("\n");
307
  debug2("set_chain %i\n", chain);
308
  jp2_write_JTAG(TMS); /* SELECT_DR SCAN */
309
  jp2_write_JTAG(0); /* CAPTURE_DR */
310
  jp2_write_JTAG(0); /* SHIFT_DR */
311
 
312
  /* write data, EXIT1_DR */
313 1259 markom
  crc_w = 0xffffffff;
314 1246 markom
  jp2_write_stream((chain & 0x7 | 0x8), DC_SIZE + 1, 0);
315
  jp2_write_stream(crc_w, DBG_CRC_SIZE, 0);
316 1259 markom
  crc_r = 0xffffffff;
317 1246 markom
  status = jp2_read_stream(0, DC_STATUS_SIZE, 0);
318
  crc_generated = crc_r;
319
  crc_read = jp2_read_stream(0, DBG_CRC_SIZE, 1);
320
 
321
  /* invalid chain? */
322
  if (status == 0xf && crc_read == crc_generated) return DBG_ERR_INV_CHAIN;
323
 
324
  /* we should read 1101, otherwise retry */
325
  if (status != 0xd || crc_read != crc_generated) {
326
    if (retry_do()) goto try_again;
327
    else return DBG_ERR_CRC;
328
  }
329
 
330
  /* reset retry counter */
331
  retry_ok();
332
 
333
  jp2_write_JTAG(TMS); /* UPDATE_DR */
334
  jp2_write_JTAG(0); /* IDLE */
335
  current_chain = chain;
336
  return DBG_ERR_OK;
337
}
338
 
339
/* sends out a command with 32bit address and 16bit length, if len >= 0 */
340 1259 markom
int dbg_command(unsigned long adr, int command, int expect_status, int len) {
341 1246 markom
  int status, crc_generated, crc_read;
342
 
343
try_again:
344
  dbg_set_chain(dbg_chain);
345
  debug("\n");
346
  debug2("wb_comm %i\n", command);
347
 
348
  /***** WRITEx *****/
349
  jp2_write_JTAG(TMS); /* SELECT_DR SCAN */
350
  jp2_write_JTAG(0); /* CAPTURE_DR */
351
  jp2_write_JTAG(0); /* SHIFT_DR */
352
 
353
  /* write data, EXIT1_DR */
354 1259 markom
  crc_w = 0xffffffff;
355 1246 markom
  jp2_write_stream((command & 0x7), DC_SIZE + 1, 0);
356
  jp2_write_stream(adr, 32, 0);
357
  if (len >= 0) jp2_write_stream(len, 16, 0);
358
  jp2_write_stream(crc_w, DBG_CRC_SIZE, 0);
359 1259 markom
  crc_r = 0xffffffff;
360 1246 markom
  status = jp2_read_stream(0, DC_STATUS_SIZE, 0);
361
  crc_generated = crc_r;
362
  crc_read = jp2_read_stream(0, DBG_CRC_SIZE, 1);
363
 
364 1259 markom
  /* we should read expected status value, otherwise retry */
365
  if (status != expect_status || crc_read != crc_generated) {
366 1246 markom
    if (retry_do()) goto try_again;
367
    else return DBG_ERR_CRC;
368
  }
369
  jp2_write_JTAG(TMS); /* UPDATE_DR */
370
  jp2_write_JTAG(0); /* IDLE */
371
 
372
  /* reset retry counter */
373
  retry_ok();
374
  return DBG_ERR_OK;
375
}
376
 
377
/* issues a burst read/write */
378 1259 markom
int dbg_go(int go_command, unsigned char *data, unsigned short len, int read, int expected_status) {
379 1246 markom
  int status, crc_generated, crc_read;
380
  int i;
381
 
382
try_again:
383
  dbg_set_chain(dbg_chain);
384
  debug("\n");
385
  debug2("go len = %d\n", len);
386
 
387
  jp2_write_JTAG(TMS); /* SELECT_DR SCAN */
388
  jp2_write_JTAG(0); /* CAPTURE_DR */
389
  jp2_write_JTAG(0); /* SHIFT_DR */
390
 
391
  /* write data, EXIT1_DR */
392 1259 markom
  crc_w = 0xffffffff;
393 1246 markom
  jp2_write_stream(go_command, DC_SIZE + 1, 0);
394 1259 markom
  if (!read) {
395
    /* reverse byte ordering, since we must send in big endian */
396
    for (i = 0; i < len; i++)
397
      jp2_write_stream(data[i], 8, 0);
398
  }
399 1246 markom
  jp2_write_stream(crc_w, DBG_CRC_SIZE, 0);
400 1259 markom
  crc_r = 0xffffffff;
401
  if (read) {
402
    /* reverse byte ordering, since we must send in big endian */
403
    for (i = 0; i < len; i++)
404
      data[i] = jp2_read_stream(data[i], 8, 0);
405
  }
406 1246 markom
  status = jp2_read_stream(0, DC_STATUS_SIZE, 0);
407
  crc_generated = crc_r;
408
  crc_read = jp2_read_stream(0, DBG_CRC_SIZE, 1);
409
 
410 1259 markom
  /* was there an bus error -- wishbone only */
411
  if (status == 0x9 && crc_read == crc_generated) return DBG_ERR_BUSERR;
412
  //printf("[status %x %x %x %x]\n", status, expected_status, crc_read, crc_generated);
413 1246 markom
 
414 1259 markom
  /* we should read expected status, otherwise retry */
415
  if (status != expected_status || crc_read != crc_generated) {
416 1246 markom
    if (retry_do()) goto try_again;
417
    else return DBG_ERR_CRC;
418
  }
419
  jp2_write_JTAG(TMS); /* UPDATE_DR */
420
  jp2_write_JTAG(0); /* IDLE */
421
 
422
  /* reset retry counter */
423
  retry_ok();
424
  return DBG_ERR_OK;
425
}
426
 
427
/* check the status */
428
int dbg_wb_status() {
429
  int status, crc_generated, crc_read;
430
  int wait_retries = 0;
431
 
432
try_again:
433
  dbg_set_chain(dbg_chain);
434
  debug("\n");
435
  debug2("status\n");
436
 
437
  jp2_write_JTAG(TMS); /* SELECT_DR SCAN */
438
  jp2_write_JTAG(0); /* CAPTURE_DR */
439
  jp2_write_JTAG(0); /* SHIFT_DR */
440
 
441
  /* write data, EXIT1_DR */
442 1259 markom
  crc_w = 0xffffffff;
443 1246 markom
  jp2_write_stream(DI_WB_STATUS, DC_SIZE + 1, 0);
444
  jp2_write_stream(crc_w, DBG_CRC_SIZE, 0);
445 1259 markom
  crc_r = 0xffffffff;
446 1246 markom
  status = jp2_read_stream(0, DC_STATUS_SIZE, 0);
447
  crc_generated = crc_r;
448
  crc_read = jp2_read_stream(0, DBG_CRC_SIZE, 1);
449
 
450
  /* is cycle still in progress */
451
  if (status == 0xc && crc_read == crc_generated) {
452
    jp2_write_JTAG(TMS); /* UPDATE_DR */
453
    jp2_write_JTAG(0); /* IDLE */
454
    JTAG_RETRY_WAIT();
455
    wait_retries++;
456
    if (wait_retries > NUM_ACCESS_RETRIES) goto try_again;
457
  }
458
 
459
  /* we should read 1000, otherwise retry */
460
  if (status != 0x8 || crc_read != crc_generated) {
461
    if (retry_do()) goto try_again;
462
    else return DBG_ERR_CRC;
463
  }
464
 
465
  jp2_write_JTAG(TMS); /* UPDATE_DR */
466
  jp2_write_JTAG(0); /* IDLE */
467
 
468
  /* reset retry counter */
469
  retry_ok();
470
  return DBG_ERR_OK;
471
}
472
 
473
/* read a block from wishbone */
474
int dbg_wb_read(unsigned long adr, int command, unsigned char *data, unsigned short len) {
475
  int err;
476
  if ((err = dbg_set_chain(DC_WISHBONE))) return err;
477 1259 markom
  if ((err = dbg_command(adr, command, 0x8, len))) return err;
478
  if ((err = dbg_go(DI_WB_GO, data, len, 1, 0x8))) return err;
479 1246 markom
  if ((err = dbg_wb_status())) return err;
480
  return DBG_ERR_OK;
481
}
482
 
483
/* write a block to wishbone */
484
int dbg_wb_write(unsigned long adr, int command, unsigned char *data, unsigned short len) {
485
  int err;
486
  if ((err = dbg_set_chain(DC_WISHBONE))) return err;
487 1259 markom
  if ((err = dbg_command(adr, command, 0x8, len))) return err;
488
  if ((err = dbg_go(DI_WB_GO, data, len, 0, 0x8))) return err;
489 1246 markom
  if ((err = dbg_wb_status())) return err;
490
  return DBG_ERR_OK;
491
}
492
 
493
/* read a register from cpu */
494 1259 markom
int dbg_cpu_read(unsigned long adr, int command, unsigned long *data, int len) {
495 1246 markom
  int err;
496
  if ((err = dbg_set_chain(DC_CPU))) return err;
497 1259 markom
  if ((err = dbg_command(adr, command, 0xa, -1))) return err;
498
  if ((err = dbg_go(DI_CPU_GO, (unsigned char*)data, len, 1, 0xa))) return err;
499 1246 markom
  return DBG_ERR_OK;
500
}
501
 
502
/* write a cpu register */
503 1259 markom
int dbg_cpu_write(unsigned long adr, int command, unsigned long data, int len) {
504 1246 markom
  int err;
505
  if ((err = dbg_set_chain(DC_CPU))) return err;
506 1259 markom
  if ((err = dbg_command(adr, command, 0xa, -1))) return err;
507
  if ((err = dbg_go(DI_CPU_GO, (unsigned char *)&data, len, 0, 0xa))) return err;
508 1246 markom
  return DBG_ERR_OK;
509
}
510
 
511
/* read a word from wishbone */
512
int dbg_wb_read32(unsigned long adr, unsigned long *data) {
513 1259 markom
  int err = dbg_wb_read(adr, DI_WB_READ32, (unsigned char*)data, 4);
514
  *data = ntohl(*data);
515
  return err;
516 1246 markom
}
517
 
518
/* write a word to wishbone */
519
int dbg_wb_write32(unsigned long adr, unsigned long data) {
520 1259 markom
  data = ntohl(data);
521 1246 markom
  return dbg_wb_write(adr, DI_WB_WRITE32, (unsigned char*)&data, 4);
522
}
523
 
524
/* read a block from wishbone */
525 1259 markom
int dbg_wb_read_block32(unsigned long adr, unsigned long *data, int len) {
526
  int i, err;
527
  //printf("%08x %08x\n", adr, len);
528
  err = dbg_wb_read(adr, DI_WB_READ32, (unsigned char*)data, len);
529
  for (i = 0; i < len / 4; i ++) data[i] = ntohl(data[i]);
530
  //printf("%08x\n", err);
531
  return err;
532 1246 markom
}
533
 
534
/* write a block to wishbone */
535
int dbg_wb_write_block32(unsigned long adr, unsigned long *data, int len) {
536 1259 markom
  int i;
537
  for (i = 0; i < len / 4; i ++) data[i] = ntohl(data[i]);
538 1246 markom
  return dbg_wb_write(adr, DI_WB_WRITE32, (unsigned char*)data, len);
539
}
540
 
541
/* read a register from cpu */
542
int dbg_cpu_read32(unsigned long adr, unsigned long *data) {
543 1259 markom
  int err = dbg_cpu_read(adr, DI_CPU_READ32, data, 4);
544
  *data = ntohl(*data);
545
  return err;
546 1246 markom
}
547
 
548
/* read a register from cpu module */
549 1259 markom
int dbg_cpu_read_reg(unsigned long adr, unsigned char *data) {
550
  return dbg_cpu_read(adr, DI_CPU_READ_REG, (unsigned long *)data, 1);
551 1246 markom
}
552
 
553
/* write a cpu register */
554
int dbg_cpu_write32(unsigned long adr, unsigned long data) {
555 1259 markom
  data = ntohl(data);
556
  return dbg_cpu_write(adr, DI_CPU_WRITE32, data, 4);
557 1246 markom
}
558
 
559
/* write a cpu module register */
560 1259 markom
int dbg_cpu_write_reg(unsigned long adr, unsigned char data) {
561
  unsigned long l;
562
  *((unsigned char*)&l) = data;
563
  return dbg_cpu_write(adr, DI_CPU_WRITE_REG, data, 1);
564 1246 markom
}
565
 
566 1259 markom
void check(char *fn, int l, int i) {
567
  if (i != DBG_ERR_OK) {
568
    fprintf(stderr, "%s:%d: Jtag error %d occured; exiting.\n", fn, l, i);
569
    exit(1);
570
  }
571
}
572
 
573 1246 markom
void dbg_test() {
574
  int i;
575
  unsigned long npc, ppc, r1, insn, result;
576 1259 markom
  unsigned char stalled;
577
#if 1
578
#define MC_BASE_ADDR     0x93000000
579
#define FLASH_BASE_ADDR  0xf0000000
580
#define FLASH_BAR_VAL    FLASH_BASE_ADDR
581
#define FLASH_AMR_VAL    0xf0000000
582
#define FLASH_WTR_VAL    0x00011009
583
#define FLASH_RTR_VAL    0x01002009
584
#define SDRAM_BASE_ADDR  0x00000000
585
#define SDRAM_BAR_VAL    SDRAM_BASE_ADDR
586
#define SDRAM_SIZE       0x02000000
587
#define SDRAM_AMR_VAL    (~(SDRAM_SIZE -1))
588
#define SDRAM_RATR_VAL   0x00000006
589
#define SDRAM_RCDR_VAL   0x00000002
590
#define SDRAM_RCTR_VAL   0x00000006
591
#define SDRAM_REFCTR_VAL 0x00000006
592
#define SDRAM_PTR_VAL    0x00000001
593
#define SDRAM_RRDR_VAL   0x00000000
594
#define SDRAM_RIR_VAL    0x000000C0
595 1246 markom
 
596 1259 markom
#define MC_BAR_0         0x00
597
#define MC_AMR_0         0x04
598
#define MC_WTR_0         0x30
599
#define MC_RTR_0         0x34
600
#define MC_OSR           0xe8
601
#define MC_BAR_4         0x80
602
#define MC_AMR_4         0x84
603
#define MC_CCR_4         0xa0
604
#define MC_RATR          0xb0
605
#define MC_RCDR          0xc8
606
#define MC_RCTR          0xb4
607
#define MC_REFCTR        0xc4
608
#define MC_PTR           0xbc
609
#define MC_RRDR          0xb8
610
#define MC_RIR           0xcc
611
#define MC_ORR           0xe4
612
 
613
  CHECK(dbg_cpu_write_reg(0, 0x01));
614 1246 markom
 
615 1259 markom
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_BAR_0, FLASH_BAR_VAL & 0xffff0000));
616
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_AMR_0, FLASH_AMR_VAL & 0xffff0000));
617
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_WTR_0, FLASH_WTR_VAL));
618
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RTR_0, FLASH_RTR_VAL));
619
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_OSR, 0x40000000));
620
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_BAR_4, SDRAM_BAR_VAL & 0xffff0000));
621
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_AMR_4, SDRAM_AMR_VAL & 0xffff0000));
622
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_CCR_4, 0x00ef0004));
623
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RATR, SDRAM_RATR_VAL));
624
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RCDR, SDRAM_RCDR_VAL));
625
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RCTR, SDRAM_RCTR_VAL));
626
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_REFCTR, SDRAM_REFCTR_VAL));
627
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_PTR, SDRAM_PTR_VAL));
628
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RRDR, SDRAM_RRDR_VAL));
629
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_RIR, SDRAM_RIR_VAL));
630
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_OSR, 0x5e000000));
631
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x5e000000));
632
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_OSR, 0x6e000000));
633
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
634
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
635
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
636
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
637
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
638
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
639
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
640
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x6e000000));
641
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_OSR, 0x7e000033));
642
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_ORR, 0x7e000033));
643
  CHECK(dbg_wb_write32(MC_BASE_ADDR + MC_CCR_4, 0xc0ef0004));
644
 
645
  CHECK(dbg_wb_read32(MC_BASE_ADDR+MC_CCR_4, &insn));
646
  printf("expected %x, read %x\n", 0xc0be0004, insn);
647
#endif
648 1246 markom
 
649 1259 markom
#if 1
650
#define CPU_OP_ADR  0
651
#define CPU_SEL_ADR 1
652
#define RAM_BASE 0x00000000
653 1246 markom
 
654 1259 markom
  /* Select cpu 0 */
655
  CHECK(dbg_cpu_write_reg(CPU_SEL_ADR, 0x01));
656
  /* Stall all cpus and selected cpu 0 */
657
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x05));
658 1246 markom
 
659 1259 markom
  /* unstall the or1200 in highland_sys */
660
  CHECK(dbg_wb_write32(0xb8070000, 2));
661 1246 markom
 
662 1259 markom
  usleep(1000);
663
  CHECK(dbg_wb_write32(RAM_BASE+0x00, 0x12345678));
664
  CHECK(dbg_wb_read32(RAM_BASE+0x00, &insn));
665
  printf("expected %x, read %x\n", 0x12345678, insn);
666
  if (insn != 0x12345678) exit(1);
667 1246 markom
 
668 1259 markom
  CHECK(dbg_wb_write32(RAM_BASE+0x0000, 0x11112222));
669
  CHECK(dbg_wb_read32(RAM_BASE+0x0000, &insn));
670
  printf("expected %x, read %x\n", 0x11112222, insn);
671
 
672
  CHECK(dbg_wb_write32(RAM_BASE+0x0004, 0x33334444));
673
  CHECK(dbg_wb_write32(RAM_BASE+0x0008, 0x55556666));
674
  CHECK(dbg_wb_write32(RAM_BASE+0x000c, 0x77778888));
675
  CHECK(dbg_wb_write32(RAM_BASE+0x0010, 0x9999aaaa));
676
  CHECK(dbg_wb_write32(RAM_BASE+0x0014, 0xbbbbcccc));
677
  CHECK(dbg_wb_write32(RAM_BASE+0x0018, 0xddddeeee));
678
  CHECK(dbg_wb_write32(RAM_BASE+0x001c, 0xffff0000));
679
  CHECK(dbg_wb_write32(RAM_BASE+0x0020, 0xdeadbeaf));
680
 
681
  CHECK(dbg_wb_read32(RAM_BASE+0x0004, &insn));
682
  printf("expected %x, read %x\n", 0x33334444, insn);
683
  CHECK(dbg_wb_read32(RAM_BASE+0x0000, &insn));
684
  printf("expected %x, read %x\n", 0x11112222, insn);
685
  CHECK(dbg_wb_read32(RAM_BASE+0x0008, &insn));
686
  printf("expected %x, read %x\n", 0x55556666, insn);
687
  CHECK(dbg_wb_read32(RAM_BASE+0x000c, &insn));
688
  printf("expected %x, read %x\n", 0x77778888, insn);
689
  CHECK(dbg_wb_read32(RAM_BASE+0x0010, &insn));
690
  printf("expected %x, read %x\n", 0x9999aaaa, insn);
691
  CHECK(dbg_wb_read32(RAM_BASE+0x0014, &insn));
692
  printf("expected %x, read %x\n", 0xbbbbcccc, insn);
693
  CHECK(dbg_wb_read32(RAM_BASE+0x0018, &insn));
694
  printf("expected %x, read %x\n", 0xddddeeee, insn);
695
 
696
  CHECK(dbg_wb_read32(RAM_BASE+0x001c, &insn));
697
  printf("expected %x, read %x\n", 0xffff0000, insn);
698 1246 markom
 
699 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE+0x0020, &insn));
700
  printf("expected %x, read %x\n", 0xdeadbeaf, insn);
701
 
702
  if (insn != 0xdeadbeaf) exit(1);
703 1246 markom
 
704 1259 markom
  CHECK(dbg_wb_write32(RAM_BASE+0x00, 0xe0000005));   /* l.xor   r0,r0,r0   */
705
  CHECK(dbg_wb_write32(RAM_BASE+0x04, 0x9c200000));   /* l.addi  r1,r0,0x0  */
706
  CHECK(dbg_wb_write32(RAM_BASE+0x08, 0x18400000));   /* l.movhi r2,0x4000  */
707
  CHECK(dbg_wb_write32(RAM_BASE+0x0c, 0xa8420030));   /* l.ori   r2,r2,0x30 */
708
  CHECK(dbg_wb_write32(RAM_BASE+0x10, 0x9c210001));   /* l.addi  r1,r1,1    */
709
  CHECK(dbg_wb_write32(RAM_BASE+0x14, 0x9c210001));   /* l.addi  r1,r1,1    */
710
  CHECK(dbg_wb_write32(RAM_BASE+0x18, 0xd4020800));   /* l.sw    0(r2),r1   */
711
  CHECK(dbg_wb_write32(RAM_BASE+0x1c, 0x9c210001));   /* l.addi  r1,r1,1    */
712
  CHECK(dbg_wb_write32(RAM_BASE+0x20, 0x84620000));   /* l.lwz   r3,0(r2)   */
713
  CHECK(dbg_wb_write32(RAM_BASE+0x24, 0x03fffffb));   /* l.j     loop2      */
714
  CHECK(dbg_wb_write32(RAM_BASE+0x28, 0xe0211800));   /* l.add   r1,r1,r3   */
715
 
716
  CHECK(dbg_cpu_write32((0 << 11) + 17, 0x01));  /* Enable exceptions */
717
  CHECK(dbg_cpu_write32((6 << 11) + 20, 0x2000));  /* Trap causes stall */
718
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE));  /* Set PC */
719
  CHECK(dbg_cpu_write32((6 << 11) + 16, 1 << 22));  /* Set step bit */
720
  for(i = 0; i < 11; i++) {
721
    CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* 11x Unstall */
722
    do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
723
  }
724
 
725
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
726
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
727
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
728 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
729 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000010, 0x00000028, 5);
730 1246 markom
  result = npc + ppc + r1;
731
 
732 1259 markom
  CHECK(dbg_cpu_write32((6 << 11) + 16, 0));  /* Reset step bit */
733
  CHECK(dbg_wb_read32(RAM_BASE + 0x28, &insn));  /* Set trap insn in delay slot */
734
  CHECK(dbg_wb_write32(RAM_BASE + 0x28, 0x21000001));
735
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
736
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
737
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
738
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
739
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
740
  CHECK(dbg_wb_write32(RAM_BASE + 0x28, insn));  /* Set back original insn */
741 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
742 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000010, 0x00000028, 8);
743 1246 markom
  result = npc + ppc + r1 + result;
744
 
745 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE + 0x24, &insn));  /* Set trap insn in place of branch insn */
746
  CHECK(dbg_wb_write32(RAM_BASE + 0x24, 0x21000001));
747
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x10));  /* Set PC */
748
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
749
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
750
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
751
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
752
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
753
  CHECK(dbg_wb_write32(RAM_BASE + 0x24, insn));  /* Set back original insn */
754 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
755 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000028, 0x00000024, 11);
756 1246 markom
  result = npc + ppc + r1 + result;
757
 
758 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE + 0x20, &insn));  /* Set trap insn before branch insn */
759
  CHECK(dbg_wb_write32(RAM_BASE + 0x20, 0x21000001));
760
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x24));  /* Set PC */
761
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
762
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
763
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
764
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
765
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
766
  CHECK(dbg_wb_write32(RAM_BASE + 0x20, insn));  /* Set back original insn */
767 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
768 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000024, 0x00000020, 24);
769 1246 markom
  result = npc + ppc + r1 + result;
770
 
771 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE + 0x1c, &insn));  /* Set trap insn behind lsu insn */
772
  CHECK(dbg_wb_write32(RAM_BASE + 0x1c, 0x21000001));
773
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x20));  /* Set PC */
774
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
775
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
776
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
777
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
778
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
779
  CHECK(dbg_wb_write32(RAM_BASE + 0x1c, insn));  /* Set back original insn */
780 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
781 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000020, 0x0000001c, 49);
782 1246 markom
  result = npc + ppc + r1 + result;
783
 
784 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE + 0x20, &insn));  /* Set trap insn very near previous one */
785
  CHECK(dbg_wb_write32(RAM_BASE + 0x20, 0x21000001));
786
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x1c));  /* Set PC */
787
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
788
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
789
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
790
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
791
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
792
  CHECK(dbg_wb_write32(RAM_BASE + 0x20, insn));  /* Set back original insn */
793 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
794 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000024, 0x00000020, 50);
795 1246 markom
  result = npc + ppc + r1 + result;
796
 
797 1259 markom
  CHECK(dbg_wb_read32(RAM_BASE + 0x10, &insn));  /* Set trap insn to the start */
798
  CHECK(dbg_wb_write32(RAM_BASE + 0x10, 0x21000001));
799
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x20)  /* Set PC */);
800
  CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
801
  do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
802
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
803
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
804
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
805
  CHECK(dbg_wb_write32(RAM_BASE + 0x10, insn));  /* Set back original insn */
806 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
807 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000014, 0x00000010, 99);
808 1246 markom
  result = npc + ppc + r1 + result;
809
 
810 1259 markom
  CHECK(dbg_cpu_write32((6 << 11) + 16, 1 << 22));  /* Set step bit */
811
  for(i = 0; i < 5; i++) {
812
    CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
813
    do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
814
  }
815
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
816
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
817
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
818 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
819 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000028, 0x00000024, 101);
820 1246 markom
  result = npc + ppc + r1 + result;
821
 
822 1259 markom
  CHECK(dbg_cpu_write32((0 << 11) + 16, RAM_BASE + 0x24));  /* Set PC */
823
  for(i = 0; i < 2; i++) {
824
    CHECK(dbg_cpu_write_reg(CPU_OP_ADR, 0x00));  /* Unstall */
825
    do CHECK(dbg_cpu_read_reg(CPU_OP_ADR, &stalled)); while (!(stalled & 1));
826
  }
827
  CHECK(dbg_cpu_read32((0 << 11) + 16, &npc));  /* Read NPC */
828
  CHECK(dbg_cpu_read32((0 << 11) + 18, &ppc));  /* Read PPC */
829
  CHECK(dbg_cpu_read32(0x401, &r1));  /* Read R1 */
830 1246 markom
  printf("Read      npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
831 1259 markom
  printf("Expected  npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x00000010, 0x00000028, 201);
832 1246 markom
  result = npc + ppc + r1 + result;
833
 
834 1259 markom
  printf("result = %.8lx\n", result ^ 0xdeaddae1);
835 1246 markom
#endif
836
}
837
 
838
int main(int argc,  char *argv[]) {
839
  char *redirstr;
840
  int trace_fd = 0;
841
  char *s;
842
  int err = DBG_ERR_OK;
843
 
844
  srand(getpid());
845
  if(argc != 2) {
846
    printf("JTAG protocol via parallel port for linux.\n");
847
    printf("Copyright(C) 2001 Marko Mlinar, markom@opencores.org\n\n");
848
    printf("Usage: %s JTAG port_number\n", argv[0]);
849
    return -1;
850
  }
851
 
852
#ifndef RTL_SIM
853
  if(ioperm(LPT_BASE, 3, 1)) {
854
    fprintf(stderr, "Couldn't get the port at %x\n", LPT_BASE);
855
    perror("Root privileges are required.\n");
856
    return -1;
857
  }
858
  printf("Using parallel port at %x\n", LPT_BASE);
859
#else
860
  {
861
    FILE *fin = fopen(GDB_IN, "wt+");
862
    if(fin == 0) {
863
      fprintf(stderr, "Can not open %s\n", GDB_IN);
864
      exit(1);
865
    }
866
    fclose(fin);
867
 
868
  }
869
#endif
870
#ifndef RTL_SIM
871
  /* Get rid of root privileges.  */
872
  setreuid(getuid(), getuid());
873
#endif
874
 
875
  /* Initialize a new connection to the or1k board, and make sure we are
876
     really connected.  */
877
  current_chain = -1;
878
  if ((err = dbg_reset())) goto error;
879
 
880
  /* Test the connection.  */
881
  dbg_test();
882
 
883
  /* We have a connection.  Establish server.  */
884
  argv++; argc--;
885
  printf("Dropping root privileges.\n");
886
  serverPort = strtol(*(argv),&s,10);
887
  if(*s) return -1;
888
  argv++; argc--;
889
 
890
  if(server_fd = GetServerSocket("or1ksim","tcp", serverPort)) {
891
    printf("JTAG Proxy server started on port %d\n", serverPort);
892
    printf("Press CTRL+c to exit.\n");
893
  } else {
894
    fprintf(stderr,"Cannot start JTAG Proxy server on port %d\n", serverPort);
895
    exit(-1);
896
  }
897
 
898
  /* Do endless loop of checking and handle GDB requests.  Ctrl-c exits.  */
899
  HandleServerSocket(true);
900
  return 0;
901
error:
902
  fprintf(stderr,"Connection with jtag via parallel port failed (err = %d).\n", err);
903
  exit(-1);
904
}
905
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.