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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [utils/] [amd-udi/] [montip/] [messages.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
static char _[] = "@(#)messages.c       5.20 93/08/02 13:23:58, Srini, AMD.";
2
/******************************************************************************
3
 * Copyright 1991 Advanced Micro Devices, Inc.
4
 *
5
 * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
6
 * specifically  grants the user the right to modify, use and distribute this
7
 * software provided this notice is not removed or altered.  All other rights
8
 * are reserved by AMD.
9
 *
10
 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11
 * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12
 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13
 * USE OF THIS SOFTWARE.
14
 *
15
 * So that all may benefit from your experience, please report  any  problems
16
 * or  suggestions about this software to the 29K Technical Support Center at
17
 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
18
 * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
19
 *
20
 * Advanced Micro Devices, Inc.
21
 * 29K Support Products
22
 * Mail Stop 573
23
 * 5900 E. Ben White Blvd.
24
 * Austin, TX 78741
25
 * 800-292-9263
26
 *****************************************************************************
27
 *      Engineer: Srini Subramanian.
28
 *****************************************************************************
29
 * This module contains the functions to build and unpack MiniMON29K messages.
30
 * It also defines the functions to send and receive messages from the
31
 * 29K target. An array defining the appropriate functions to use for
32
 * different targets is initialized.
33
 *****************************************************************************
34
 */
35
 
36
/*
37
 * Definitions of functions that
38
 * -initialize the Message System
39
 * -send messages to the target
40
 * -receive messages from the target
41
 */
42
 
43
#include <stdio.h>
44
#include <ctype.h>
45
#ifdef  MSDOS
46
#include <stdlib.h>
47
#endif
48
#include <string.h>
49
#include "messages.h"
50
#include "memspcs.h"
51
#include "tdfunc.h"
52
#include "mtip.h"
53
 
54
extern  FILE    *MsgFile;
55
static  int     DebugCoreVersion;
56
 
57
static  INT32   target_index = 0;        /* Default EB29K */
58
 
59
int     lpt_initialize=0;        /* global */
60
int     use_parport=0;   /* global */
61
 
62
static  union msg_t     *send_msg_buffer;
63
static  union msg_t     *recv_msg_buffer;
64
 
65
struct  target_dep_funcs {
66
 char   target_name[15];
67
 INT32  (*msg_send)PARAMS((union msg_t *, INT32));
68
 INT32  (*msg_recv)PARAMS((union msg_t *, INT32, INT32));
69
 INT32  (*init_comm)PARAMS((INT32, INT32));
70
 INT32  (*reset_comm)PARAMS((INT32, INT32));
71
 INT32  (*exit_comm)PARAMS((INT32, INT32));
72
 INT32  (*read_memory)PARAMS((INT32, ADDR32, BYTE *, INT32, INT32, INT32));
73
 INT32  (*write_memory)PARAMS((INT32, ADDR32, BYTE *, INT32, INT32, INT32));
74
 INT32  (*fill_memory)PARAMS((void));
75
 INT32  PC_port_base;
76
 INT32  PC_mem_seg;
77
 void   (*go)PARAMS((INT32, INT32));
78
} TDF[] = {
79
"pceb", msg_send_pceb, msg_recv_pceb, init_comm_pceb,
80
reset_comm_pceb, exit_comm_pceb, read_memory_pceb, write_memory_pceb,
81
fill_memory_pceb, (INT32) 0x240, (INT32) 0xd000, go_pceb,
82
 
83
#ifndef MSDOS
84
"pcserver", msg_send_serial, msg_recv_serial, init_comm_serial,
85
reset_comm_pcserver, exit_comm_serial, read_memory_serial, write_memory_serial,
86
fill_memory_serial, (INT32) -1 , (INT32) -1, go_serial,
87
#endif
88
 
89
#ifdef  MSDOS
90
"paral_1", msg_send_parport, msg_recv_serial, init_comm_serial,
91
reset_comm_serial, exit_comm_serial, read_memory_serial, write_memory_serial,
92
fill_memory_serial, (INT32) -1 , (INT32) -1, go_serial,
93
#endif
94
 
95
"serial", msg_send_serial, msg_recv_serial, init_comm_serial,
96
reset_comm_serial, exit_comm_serial, read_memory_serial, write_memory_serial,
97
fill_memory_serial, (INT32) -1 , (INT32) -1, go_serial,
98
 
99
"eb29030", msg_send_eb030, msg_recv_eb030, init_comm_eb030,
100
reset_comm_eb030, exit_comm_eb030, read_memory_eb030, write_memory_eb030,
101
fill_memory_eb030, (INT32) 0x208, (INT32) 0xd000, go_eb030,
102
 
103
"eb030", msg_send_eb030, msg_recv_eb030, init_comm_eb030,
104
reset_comm_eb030, exit_comm_eb030, read_memory_eb030, write_memory_eb030,
105
fill_memory_eb030, (INT32) 0x208, (INT32) 0xd000, go_eb030,
106
 
107
"eb29k", msg_send_eb29k, msg_recv_eb29k, init_comm_eb29k,
108
reset_comm_eb29k, exit_comm_eb29k, read_memory_eb29k, write_memory_eb29k,
109
fill_memory_eb29k, (INT32) 0x208, (INT32) 0xd000, go_eb29k,
110
 
111
"yarcrev8", msg_send_eb29k, msg_recv_eb29k, init_comm_eb29k,
112
reset_comm_eb29k, exit_comm_eb29k, read_memory_eb29k, write_memory_eb29k,
113
fill_memory_eb29k, (INT32) 0x208, (INT32) 0xd000, go_eb29k,
114
 
115
"lcb29k", msg_send_lcb29k, msg_recv_lcb29k, init_comm_lcb29k,
116
reset_comm_lcb29k, exit_comm_lcb29k, read_memory_lcb29k, write_memory_lcb29k,
117
fill_memory_lcb29k, (INT32) 0x208, (INT32) 0xd000, go_lcb29k,
118
 
119
"\0"
120
};
121
 
122
void    print_msg PARAMS((union msg_t *msgptr, FILE *file));
123
static  INT32   match_name PARAMS((char *targ_name));
124
 
125
 
126
#ifdef MSDOS
127
void    set_lpt PARAMS((void));
128
void    unset_lpt PARAMS((void));
129
 
130
void    set_lpt ()
131
{
132
  TDF[target_index].msg_send = msg_send_parport;
133
  use_parport = 1;
134
}
135
 
136
void    unset_lpt()
137
{
138
  TDF[target_index].msg_send = msg_send_serial;
139
  use_parport = 0;
140
}
141
 
142
#endif
143
/*
144
** Miscellaneous
145
*/
146
 
147
INT32 msg_length(code)
148
INT32 code;
149
{  /* for temporary compatibility between new and old r/w/copy msgs */
150
INT32 rv;
151
  if (code == WRITE_REQ)
152
      rv = MSG_LENGTH(struct write_req_msg_t);
153
  else
154
  if (code == READ_REQ)
155
      rv = MSG_LENGTH(struct read_req_msg_t);
156
  else
157
  if (code == COPY)
158
      rv = MSG_LENGTH(struct copy_msg_t);
159
  else return(-1);
160
 
161
  /* if msg version < 0x10 use old format */
162
  /* assumes config info this has been set up */
163
  if (((tip_target_config.version >> 16) & 0xff) < 0x10)
164
        rv = rv - 4;
165
  return(rv);
166
}
167
 
168
/*
169
** Target Dependent functions
170
*/
171
 
172
INT32
173
Mini_msg_init(target_name)
174
char    *target_name;
175
{
176
  INT32         temp;
177
 
178
  /* Allocate buffers */
179
  if ((send_msg_buffer = (union msg_t *) malloc (BUFFER_SIZE)) == NULL)
180
    return(FAILURE);
181
  if ((recv_msg_buffer = (union msg_t *) malloc (BUFFER_SIZE)) == NULL)
182
    return(FAILURE);
183
 
184
  /* Identify target */
185
  if (strcmp (target_name, "paral_1") == 0) {
186
    lpt_initialize = 1;
187
    use_parport = 1;
188
  }
189
 
190
  if ((temp = match_name(target_name)) == FAILURE)
191
    return(FAILURE);  /* Unrecognized target */
192
  else
193
    target_index = temp;
194
 
195
  if (tip_config.PC_port_base == (INT32) -1) /* no -port opt given */
196
     tip_config.PC_port_base = TDF[target_index].PC_port_base;
197
 
198
  if (tip_config.PC_mem_seg == (INT32) -1) /* no -seg opt given */
199
     tip_config.PC_mem_seg = TDF[target_index].PC_mem_seg;
200
 
201
  /* Initialize communication with target */
202
  return(Mini_init_comm());
203
 
204
}
205
 
206
int
207
Mini_alloc_msgbuf(size)
208
int     size;
209
{
210
  if (size > (int) BUFFER_SIZE) {
211
     (void) free(send_msg_buffer);
212
     (void) free(recv_msg_buffer);
213
 
214
     /* Re-Allocate buffers */
215
     if ((send_msg_buffer = (union msg_t *) malloc (size)) == NULL)
216
       return(FAILURE);
217
     if ((recv_msg_buffer = (union msg_t *) malloc (size)) == NULL)
218
       return(FAILURE);
219
  }
220
  return (SUCCESS);
221
}
222
 
223
void
224
Mini_msg_exit()
225
{
226
  if (send_msg_buffer)
227
    (void) free ((char *) send_msg_buffer);
228
  if (recv_msg_buffer)
229
    (void) free ((char *) recv_msg_buffer);
230
 
231
  (void) Mini_reset_comm();
232
  (void) Mini_exit_comm();
233
}
234
 
235
INT32
236
Mini_msg_send()
237
{
238
  INT32 retval;
239
 
240
  if (Msg_Logfile) {/* log the message */
241
     fprintf(MsgFile, "\nSending:");
242
     print_msg(send_msg_buffer, MsgFile);
243
     fflush(MsgFile);
244
  };
245
  retval = (*TDF[target_index].msg_send)(send_msg_buffer,
246
                                       tip_config.PC_port_base);
247
  /* retry once more */
248
  if (retval == MSGRETRY)
249
     retval = (*TDF[target_index].msg_send)(send_msg_buffer,
250
                                       tip_config.PC_port_base);
251
 
252
  return (retval);
253
}
254
 
255
INT32
256
Mini_msg_recv(RecvMode)
257
INT32   RecvMode;       /* BLOCK or NONBLOCK */
258
{
259
  INT32 retval;
260
 
261
  retval = (INT32) (*TDF[target_index].msg_recv)(recv_msg_buffer,
262
                                       tip_config.PC_port_base, RecvMode);
263
  if (RecvMode == BLOCK)  /* we are expecting a response */
264
  {
265
     if (retval == MSGRETRY) {
266
        Mini_msg_send();
267
        retval = (INT32) (*TDF[target_index].msg_recv)(recv_msg_buffer,
268
                                       tip_config.PC_port_base, RecvMode);
269
     }
270
     if (Msg_Logfile && (retval != (INT32) -1)) { /* log the message */
271
       fprintf(MsgFile, "\nReceived:");
272
       print_msg(recv_msg_buffer, MsgFile);
273
       fflush (MsgFile);
274
     };
275
     if (retval == MSGRETRY)
276
        return (FAILURE);
277
     else
278
        return (retval);
279
  }
280
  else  /* non-block mode */
281
  {
282
     if (retval == MSGRETRY) {
283
        retval = (INT32) (*TDF[target_index].msg_recv)(recv_msg_buffer,
284
                                       tip_config.PC_port_base, RecvMode);
285
        if (retval == MSGRETRY)
286
          return (FAILURE);
287
        else
288
          return (retval);
289
     } else  {
290
        if (Msg_Logfile && (retval != (INT32) -1)) { /* log the message */
291
          fprintf(MsgFile, "\nReceived:");
292
          print_msg(recv_msg_buffer, MsgFile);
293
          fflush (MsgFile);
294
        };
295
        return (retval);
296
     }
297
  }
298
}
299
 
300
INT32
301
Mini_init_comm()
302
{
303
 return((*TDF[target_index].init_comm)(tip_config.PC_port_base,
304
                                       tip_config.PC_mem_seg));
305
}
306
 
307
INT32
308
Mini_reset_comm()
309
{
310
 return((*TDF[target_index].reset_comm)(tip_config.PC_port_base,
311
                                        tip_config.PC_mem_seg));
312
}
313
 
314
INT32
315
Mini_exit_comm()
316
{
317
 return((*TDF[target_index].exit_comm)(tip_config.PC_port_base,
318
                                        tip_config.PC_mem_seg));
319
}
320
 
321
 
322
void
323
Mini_go_target()
324
{
325
 (*TDF[target_index].go)(tip_config.PC_port_base,
326
                                 tip_config.PC_mem_seg);
327
}
328
 
329
INT32
330
Mini_write_memory(m_space, address, byte_count, buffer)
331
INT32   m_space;
332
ADDR32  address;
333
INT32   byte_count;
334
BYTE    *buffer;
335
{
336
 return((*TDF[target_index].write_memory)(m_space,
337
                                          address,
338
                                          buffer,
339
                                          byte_count,
340
                                          tip_config.PC_port_base,
341
                                          tip_config.PC_mem_seg));
342
}
343
 
344
INT32
345
Mini_read_memory(m_space, address, byte_count, buffer)
346
INT32   m_space;
347
ADDR32  address;
348
INT32   byte_count;
349
BYTE    *buffer;
350
{
351
 return((*TDF[target_index].read_memory)(m_space,
352
                                          address,
353
                                          buffer,
354
                                          byte_count,
355
                                          tip_config.PC_port_base,
356
                                          tip_config.PC_mem_seg));
357
}
358
 
359
INT32
360
Mini_fill_memory()
361
{
362
 return((*TDF[target_index].fill_memory)());
363
}
364
 
365
/*
366
** Functions to build msgs
367
*/
368
 
369
void
370
Mini_build_reset_msg()
371
{
372
 send_msg_buffer->reset_msg.code = RESET;
373
 send_msg_buffer->reset_msg.length = (INT32) 0;/* Length always is zero */
374
}
375
 
376
void
377
Mini_build_config_req_msg()
378
{
379
 send_msg_buffer->config_req_msg.code = CONFIG_REQ;
380
 send_msg_buffer->config_req_msg.length = (INT32) 0; /* Always zero */
381
}
382
 
383
void
384
Mini_build_status_req_msg()
385
{
386
send_msg_buffer->status_req_msg.code = STATUS_REQ;
387
send_msg_buffer->status_req_msg.length = (INT32) 0; /* Always zero */
388
}
389
 
390
void
391
Mini_build_read_req_msg(m_space, address, count, size)
392
INT32   m_space;
393
ADDR32  address;
394
INT32   count;
395
INT32   size;
396
{
397
send_msg_buffer->read_req_msg.code = READ_REQ;
398
send_msg_buffer->read_req_msg.length = msg_length(READ_REQ);
399
send_msg_buffer->read_req_msg.memory_space = m_space;
400
if ((DebugCoreVersion >= (int) 0x13) && (m_space == (INT32) SPECIAL_REG))
401
   send_msg_buffer->read_req_msg.memory_space = (INT32) A_SPCL_REG;
402
send_msg_buffer->read_req_msg.address = address;
403
/* if msg version >= 0x10 use new format, else old */
404
if (((tip_target_config.version >> 16) & 0xff) >= 0x10) { /* new version */
405
        send_msg_buffer->read_req_msg.count = count;
406
        send_msg_buffer->read_req_msg.size = size;
407
        } else {                                        /* old version */
408
        send_msg_buffer->read_req_msg.count = count * size;
409
        }
410
}
411
 
412
void
413
Mini_build_write_req_msg(m_space, address, count, size, data)
414
INT32   m_space;
415
ADDR32  address;
416
INT32   count;
417
INT32   size;
418
BYTE    *data;
419
{
420
  BYTE          *s;
421
  INT32         i;
422
  INT32         bcnt = count * size;
423
 
424
send_msg_buffer->write_req_msg.code = WRITE_REQ;
425
send_msg_buffer->write_req_msg.length = msg_length(WRITE_REQ) + (count * size);
426
send_msg_buffer->write_req_msg.memory_space = m_space;
427
if ((DebugCoreVersion >= (int) 0x13) && (m_space == (INT32) SPECIAL_REG))
428
   send_msg_buffer->write_req_msg.memory_space = (INT32) A_SPCL_REG;
429
send_msg_buffer->write_req_msg.address = address;
430
 
431
/* if msg version >= 0x10 use new format, else old */
432
if (((tip_target_config.version >> 16) & 0xff) >= 0x10) { /* new version */
433
        send_msg_buffer->write_req_msg.count = count;
434
        send_msg_buffer->write_req_msg.size = size;
435
        s = &(send_msg_buffer->write_req_msg.data);
436
        for (i = 0; i < bcnt; i++)
437
          *s++ = *data++;
438
        } else {                                        /* old version */
439
        send_msg_buffer->write_req_msg.count = bcnt;
440
        s = (BYTE *) &(send_msg_buffer->write_req_msg.size);
441
        for (i = 0; i < bcnt; i++)
442
          *s++ = *data++;
443
        }
444
}
445
 
446
void
447
Mini_build_bkpt_set_msg(m_space, address, pass_count, type)
448
INT32   m_space, pass_count, type;
449
ADDR32  address;
450
{
451
send_msg_buffer->bkpt_set_msg.code = BKPT_SET;
452
send_msg_buffer->bkpt_set_msg.length = MSG_LENGTH (struct bkpt_set_msg_t);
453
send_msg_buffer->bkpt_set_msg.memory_space = m_space;
454
send_msg_buffer->bkpt_set_msg.bkpt_addr = address;
455
send_msg_buffer->bkpt_set_msg.pass_count = pass_count;
456
send_msg_buffer->bkpt_set_msg.bkpt_type = type;
457
}
458
 
459
void
460
Mini_build_bkpt_rm_msg(m_space, address)
461
INT32   m_space;
462
ADDR32  address;
463
{
464
send_msg_buffer->bkpt_rm_msg.code = BKPT_RM;
465
send_msg_buffer->bkpt_rm_msg.length = MSG_LENGTH (struct bkpt_rm_msg_t);
466
send_msg_buffer->bkpt_rm_msg.memory_space = m_space;
467
send_msg_buffer->bkpt_rm_msg.bkpt_addr = address;
468
}
469
 
470
void
471
Mini_build_bkpt_stat_msg(m_space, address)
472
INT32   m_space;
473
ADDR32  address;
474
{
475
send_msg_buffer->bkpt_stat_msg.code = BKPT_STAT;
476
send_msg_buffer->bkpt_stat_msg.length = MSG_LENGTH (struct bkpt_stat_msg_t);
477
send_msg_buffer->bkpt_stat_msg.memory_space = m_space;
478
send_msg_buffer->bkpt_stat_msg.bkpt_addr = address;
479
}
480
 
481
void
482
Mini_build_copy_msg(src_space, src_addr, dst_space, dst_addr, count, size)
483
INT32   src_space, dst_space;
484
ADDR32  src_addr, dst_addr;
485
INT32   count;
486
INT32   size;
487
{
488
send_msg_buffer->copy_msg.code = COPY;
489
send_msg_buffer->copy_msg.length = msg_length(COPY);
490
send_msg_buffer->copy_msg.source_space = src_space;
491
if ((DebugCoreVersion >= (int) 0x13) && (src_space == (INT32) SPECIAL_REG))
492
   send_msg_buffer->copy_msg.source_space = (INT32) A_SPCL_REG;
493
send_msg_buffer->copy_msg.source_addr = src_addr;
494
send_msg_buffer->copy_msg.dest_space = dst_space;
495
if ((DebugCoreVersion >= (int) 0x13) && (dst_space == (INT32) SPECIAL_REG))
496
   send_msg_buffer->copy_msg.dest_space = (INT32) A_SPCL_REG;
497
send_msg_buffer->copy_msg.dest_addr = dst_addr;
498
 
499
/* if msg version >= 0x10 use new format, else old */
500
if (((tip_target_config.version >> 16) & 0xff) >= 0x10) { /* new version */
501
        send_msg_buffer->copy_msg.count = count;
502
        send_msg_buffer->copy_msg.size = size;
503
        } else {                                        /* old version */
504
        send_msg_buffer->copy_msg.count = count * size;
505
        }
506
}
507
 
508
void
509
Mini_build_fill_msg(m_space, start, fill_count, byte_count, pattern)
510
INT32   m_space;
511
ADDR32  start;
512
INT32   fill_count, byte_count;
513
BYTE    *pattern;
514
{
515
send_msg_buffer->fill_msg.code = FILL;
516
send_msg_buffer->fill_msg.length = MSG_LENGTH (struct fill_msg_t) +
517
                                        byte_count;
518
send_msg_buffer->fill_msg.memory_space = m_space;
519
if ((DebugCoreVersion >= (int) 0x13) && (m_space == (INT32) SPECIAL_REG))
520
   send_msg_buffer->fill_msg.memory_space = (INT32) A_SPCL_REG;
521
send_msg_buffer->fill_msg.start_addr = start;
522
send_msg_buffer->fill_msg.fill_count = fill_count;
523
send_msg_buffer->fill_msg.byte_count = byte_count;
524
(void) strcpy ( &(send_msg_buffer->fill_msg.fill_data),pattern);
525
}
526
 
527
void
528
Mini_build_init_msg(t_start, t_end, d_start, d_end,
529
                    entry, m_stack, r_stack,
530
                    highmem, arg_start, os_ctrl)
531
ADDR32  t_start, t_end, d_start, d_end;
532
ADDR32  entry, highmem, arg_start;
533
INT32   m_stack, r_stack;
534
INT32   os_ctrl;
535
{
536
send_msg_buffer->init_msg.code = INIT;
537
/* subtract 4 to hide highmem value */
538
send_msg_buffer->init_msg.length = MSG_LENGTH (struct init_msg_t) - 4;
539
send_msg_buffer->init_msg.text_start = t_start;
540
send_msg_buffer->init_msg.text_end = t_end;
541
send_msg_buffer->init_msg.data_start = d_start;
542
send_msg_buffer->init_msg.data_end = d_end;
543
send_msg_buffer->init_msg.entry_point = entry;
544
send_msg_buffer->init_msg.mem_stack_size = m_stack;
545
send_msg_buffer->init_msg.reg_stack_size = r_stack;
546
send_msg_buffer->init_msg.arg_start = arg_start;
547
send_msg_buffer->init_msg.os_control = os_ctrl;
548
send_msg_buffer->init_msg.highmem = highmem;
549
}
550
 
551
void
552
Mini_build_go_msg()
553
{
554
send_msg_buffer->go_msg.code = GO;
555
send_msg_buffer->go_msg.length = (INT32) 0; /* Always zero */
556
}
557
 
558
void
559
Mini_build_step_msg(count)
560
INT32   count;
561
{
562
send_msg_buffer->step_msg.code = STEP;
563
send_msg_buffer->step_msg.length = sizeof(INT32);
564
send_msg_buffer->step_msg.count = count;
565
}
566
 
567
void
568
Mini_build_break_msg()
569
{
570
send_msg_buffer->break_msg.code = BREAK;
571
send_msg_buffer->break_msg.length = (INT32) 0; /* Always zero */
572
}
573
 
574
void
575
Mini_build_hif_rtn_msg(snum, gr121, gr96, gr97)
576
INT32   snum, gr121, gr96, gr97;
577
{
578
send_msg_buffer->hif_call_rtn_msg.code = HIF_CALL_RTN;
579
send_msg_buffer->hif_call_rtn_msg.length = MSG_LENGTH (struct hif_call_rtn_msg_t);
580
send_msg_buffer->hif_call_rtn_msg.service_number = snum;
581
send_msg_buffer->hif_call_rtn_msg.gr121 = gr121;
582
send_msg_buffer->hif_call_rtn_msg.gr96 = gr96;
583
send_msg_buffer->hif_call_rtn_msg.gr97 = gr97;
584
}
585
 
586
void
587
Mini_build_channel0_msg(input, count)
588
INT32   count;
589
BYTE    *input;
590
{
591
send_msg_buffer->channel0_msg.code = CHANNEL0;
592
send_msg_buffer->channel0_msg.length = count;   /* bytes to follow */
593
(void ) memcpy (&(send_msg_buffer->channel0_msg.data), input, (int) count);
594
}
595
 
596
void
597
Mini_build_channel1_ack_msg(gr96)
598
INT32   gr96;
599
{
600
send_msg_buffer->channel1_ack_msg.code = CHANNEL1_ACK;
601
        /*
602
         * The HIF kernel from MiniMON29K release 2.1 expects MONTIP
603
         * to send a HIF_CALL_RTN response for a HIF_CALL message, and
604
         * a CHANNEL1_ACK response for a CHANNEL1 message, and
605
         * a CHANNEL2_ACK response for a CHANNEL2 message, and
606
         * a CHANNEL0 message for a asynchronous input.
607
         * The HIF kernel version numbers 0x05 and above support these
608
         * features.
609
         */
610
     if ((tip_target_config.os_version & 0xf) > 4) { /* new HIF kernel */
611
        /*
612
         * The CHANNEL1_ACK for new HIF kernel includes the gr96 value
613
         * which is the number of characters succesfully printed out.
614
         */
615
       send_msg_buffer->channel1_ack_msg.length = (INT32) 4; /* return gr96 */
616
       send_msg_buffer->channel1_ack_msg.gr96 = gr96;
617
     } else { /* old HIF kernel */
618
       send_msg_buffer->channel1_ack_msg.length = (INT32) 0;
619
     }
620
}
621
 
622
void
623
Mini_build_channel2_ack_msg(gr96)
624
INT32   gr96;
625
{
626
send_msg_buffer->channel2_ack_msg.code = CHANNEL2_ACK;
627
        /*
628
         * The HIF kernel from MiniMON29K release 2.1 expects MONTIP
629
         * to send a HIF_CALL_RTN response for a HIF_CALL message, and
630
         * a CHANNEL1_ACK response for a CHANNEL1 message, and
631
         * a CHANNEL2_ACK response for a CHANNEL2 message, and
632
         * a CHANNEL0 message for a asynchronous input.
633
         * The HIF kernel version numbers 0x05 and above support these
634
         * features.
635
         */
636
     if ((tip_target_config.os_version & 0xf) > 4) { /* new HIF kernel */
637
        /*
638
         * The CHANNEL1_ACK for new HIF kernel includes the gr96 value
639
         * which is the number of characters succesfully printed out.
640
         */
641
       send_msg_buffer->channel2_ack_msg.length = (INT32) 4; /* return gr96 */
642
       send_msg_buffer->channel2_ack_msg.gr96 = gr96;
643
     } else { /* old HIF kernel */
644
       /*
645
        * The old kernels did not support this feature. They invoked the
646
        * debugger on target to get the information.
647
        */
648
     }
649
}
650
 
651
void    Mini_build_stdin_needed_ack_msg (count, data)
652
UINT32  count;
653
BYTE    *data;
654
{
655
  BYTE  *s;
656
 
657
send_msg_buffer->stdin_needed_ack_msg.code = STDIN_NEEDED_ACK;
658
send_msg_buffer->stdin_needed_ack_msg.length = (INT32) count;
659
s = &(send_msg_buffer->stdin_needed_ack_msg.data);
660
for (; count > 0; count--)
661
  *s++ = *data++;
662
}
663
 
664
void    Mini_build_stdin_mode_ack_msg (mode)
665
INT32   mode;
666
{
667
send_msg_buffer->stdin_mode_ack_msg.code = STDIN_MODE_ACK;
668
send_msg_buffer->stdin_mode_ack_msg.length = MSG_LENGTH(struct stdin_mode_ack_msg_t);
669
send_msg_buffer->stdin_mode_ack_msg.mode = mode;
670
}
671
 
672
/*
673
** Functions to unpack messages.
674
*/
675
 
676
void
677
Mini_unpack_reset_ack_msg()
678
{
679
 /* No data in this message */
680
}
681
 
682
void
683
Mini_unpack_config_msg(target_config)
684
TIP_TARGET_CONFIG       *target_config;
685
{
686
  /* received a CONFIG message */
687
  target_config->processor_id = recv_msg_buffer->config_msg.processor_id;
688
  target_config->version =  recv_msg_buffer->config_msg.version;
689
  DebugCoreVersion = (int) (target_config->version & 0xFF);
690
  target_config->I_mem_start =  recv_msg_buffer->config_msg.I_mem_start;
691
  target_config->I_mem_size =  recv_msg_buffer->config_msg.I_mem_size;
692
  target_config->D_mem_start =  recv_msg_buffer->config_msg.D_mem_start;
693
  target_config->D_mem_size =  recv_msg_buffer->config_msg.D_mem_size;
694
  target_config->ROM_start =  recv_msg_buffer->config_msg.ROM_start;
695
  target_config->ROM_size =  recv_msg_buffer->config_msg.ROM_size;
696
  target_config->max_msg_size =  recv_msg_buffer->config_msg.max_msg_size;
697
  target_config->max_bkpts =  recv_msg_buffer->config_msg.max_bkpts;
698
  target_config->coprocessor =  recv_msg_buffer->config_msg.coprocessor;
699
  target_config->os_version =  recv_msg_buffer->config_msg.os_version;
700
}
701
 
702
void
703
Mini_unpack_status_msg(target_status)
704
TIP_TARGET_STATUS       *target_status;
705
{
706
  /* received a STATUS mesages */
707
  target_status->msgs_sent = recv_msg_buffer->status_msg.msgs_sent;
708
  target_status->msgs_received = recv_msg_buffer->status_msg.msgs_received;
709
  target_status->errors = recv_msg_buffer->status_msg.errors;
710
  target_status->bkpts_hit = recv_msg_buffer->status_msg.bkpts_hit;
711
  target_status->bkpts_free = recv_msg_buffer->status_msg.bkpts_free;
712
  target_status->traps = recv_msg_buffer->status_msg.traps;
713
  target_status->fills = recv_msg_buffer->status_msg.fills;
714
  target_status->spills = recv_msg_buffer->status_msg.spills;
715
  target_status->cycles = recv_msg_buffer->status_msg.cycles;
716
}
717
 
718
void
719
Mini_unpack_read_ack_msg(mspace, address, bytecount, buffer)
720
INT32   *mspace;
721
ADDR32  *address;
722
INT32   *bytecount;
723
BYTE    *buffer;
724
{
725
 INT32          i;
726
 BYTE           *s;
727
 
728
 /* READ_ACK received */
729
 *mspace = recv_msg_buffer->read_ack_msg.memory_space;
730
 if ((DebugCoreVersion >= (int) 0x13) && (*mspace == (INT32) A_SPCL_REG))
731
   *mspace = (INT32) SPECIAL_REG;
732
 *address = recv_msg_buffer->read_ack_msg.address;
733
 *bytecount = recv_msg_buffer->read_ack_msg.byte_count;
734
  s = &(recv_msg_buffer->read_ack_msg.data);
735
  for (i = 0; i < *bytecount; i++)
736
     *buffer++ = *s++;
737
}
738
 
739
void
740
Mini_unpack_write_ack_msg(mspace, address, bytecount)
741
INT32   *mspace;
742
ADDR32  *address;
743
INT32   *bytecount;
744
{
745
  *mspace =recv_msg_buffer->write_ack_msg.memory_space;
746
  if ((DebugCoreVersion >= (int) 0x13) && (*mspace == (INT32) A_SPCL_REG))
747
     *mspace = (INT32) SPECIAL_REG;
748
  *address =recv_msg_buffer->write_ack_msg.address;
749
  *bytecount =recv_msg_buffer->write_ack_msg.byte_count;
750
}
751
 
752
void
753
Mini_unpack_bkpt_set_ack_msg(mspace, address, passcount, bkpt_type)
754
INT32   *mspace;
755
ADDR32  *address;
756
INT32   *passcount;
757
INT32   *bkpt_type;
758
{
759
  *mspace =recv_msg_buffer->bkpt_set_ack_msg.memory_space;
760
  *address =recv_msg_buffer->bkpt_set_ack_msg.address;
761
  *passcount =recv_msg_buffer->bkpt_set_ack_msg.pass_count;
762
  *bkpt_type =recv_msg_buffer->bkpt_set_ack_msg.bkpt_type;
763
}
764
 
765
void
766
Mini_unpack_bkpt_rm_ack_msg(mspace, address)
767
INT32   *mspace;
768
ADDR32  *address;
769
{
770
  *mspace = recv_msg_buffer->bkpt_rm_ack_msg.memory_space;
771
  *address = recv_msg_buffer->bkpt_rm_ack_msg.address;
772
}
773
 
774
void
775
Mini_unpack_bkpt_stat_ack_msg(mspace, address, pass_count, bkpt_type)
776
INT32   *mspace;
777
ADDR32  *address;
778
INT32   *pass_count;
779
INT32   *bkpt_type;
780
{
781
  *mspace = recv_msg_buffer->bkpt_stat_ack_msg.memory_space;
782
  *address = recv_msg_buffer->bkpt_stat_ack_msg.address;
783
  *pass_count = recv_msg_buffer->bkpt_stat_ack_msg.pass_count;
784
  *bkpt_type = recv_msg_buffer->bkpt_stat_ack_msg.bkpt_type;
785
}
786
 
787
void
788
Mini_unpack_copy_ack_msg(srcspace, srcaddr, dstspace, dstaddr, count)
789
INT32   *srcspace, *dstspace;
790
ADDR32  *srcaddr, *dstaddr;
791
INT32   *count;
792
{
793
  *srcspace = recv_msg_buffer->copy_ack_msg.source_space;
794
  if ((DebugCoreVersion >= (int) 0x13) && (*srcspace == (INT32) A_SPCL_REG))
795
   *srcspace = (INT32) SPECIAL_REG;
796
  *srcaddr = recv_msg_buffer->copy_ack_msg.source_addr;
797
  *dstspace = recv_msg_buffer->copy_ack_msg.dest_space;
798
  if ((DebugCoreVersion >= (int) 0x13) && (*dstspace == (INT32) A_SPCL_REG))
799
   *dstspace = (INT32) SPECIAL_REG;
800
  *dstaddr = recv_msg_buffer->copy_ack_msg.dest_addr;
801
  *count = recv_msg_buffer->copy_ack_msg.byte_count;
802
}
803
 
804
void
805
Mini_unpack_fill_ack_msg(mspace, startaddr, fillcount, pattern_cnt)
806
INT32   *mspace;
807
ADDR32  *startaddr;
808
INT32   *fillcount;
809
INT32   *pattern_cnt;
810
{
811
  *mspace = recv_msg_buffer->fill_ack_msg.memory_space;
812
  if ((DebugCoreVersion >= (int) 0x13) && (*mspace == (INT32) A_SPCL_REG))
813
    *mspace = (INT32) SPECIAL_REG;
814
  *startaddr = recv_msg_buffer->fill_ack_msg.start_addr;
815
  *fillcount = recv_msg_buffer->fill_ack_msg.fill_count;
816
  *pattern_cnt = recv_msg_buffer->fill_ack_msg.byte_count;
817
}
818
 
819
void
820
Mini_unpack_init_ack_msg()
821
{
822
 /* No data in this message */
823
 
824
}
825
 
826
void
827
Mini_unpack_halt_msg(mspace, pc0, pc1, trap_number)
828
INT32   *mspace;
829
ADDR32  *pc0;
830
ADDR32  *pc1;
831
INT32   *trap_number;
832
{
833
  *mspace = recv_msg_buffer->halt_msg.memory_space;
834
  *pc0 = recv_msg_buffer->halt_msg.pc0;
835
  *pc1 = recv_msg_buffer->halt_msg.pc1;
836
  *trap_number = recv_msg_buffer->halt_msg.trap_number;
837
}
838
 
839
void
840
Mini_unpack_error_msg(errcode, mspace, address)
841
INT32   *errcode;
842
INT32   *mspace;
843
ADDR32  *address;
844
{
845
  *errcode = recv_msg_buffer->error_msg.error_code;
846
  *mspace = recv_msg_buffer->error_msg.memory_space;
847
  *address = recv_msg_buffer->error_msg.address;
848
}
849
 
850
void
851
Mini_unpack_channel0_ack_msg()
852
{
853
 /* No data in this message */
854
}
855
 
856
void
857
Mini_unpack_channel2_msg(data, len)
858
BYTE    *data;
859
INT32   *len;
860
{
861
  INT32 i;
862
  BYTE  *s;
863
 
864
  *len = recv_msg_buffer->channel2_msg.length;
865
  s = &(recv_msg_buffer->channel2_msg.data);
866
  for (i = 0; i < *len; i++)
867
     *data++ = *s++;
868
}
869
 
870
void
871
Mini_unpack_channel1_msg(data, len)
872
BYTE    *data;
873
INT32   *len;
874
{
875
  INT32 i;
876
  BYTE  *s;
877
 
878
  *len = recv_msg_buffer->channel1_msg.length;
879
  s = &(recv_msg_buffer->channel1_msg.data);
880
  for (i = 0; i < *len; i++)
881
     *data++ = *s++;
882
}
883
 
884
void
885
Mini_unpack_hif_msg (gr121, lr2, lr3, lr4)
886
INT32 *gr121;
887
INT32 *lr2;
888
INT32 *lr3;
889
INT32 *lr4;
890
{
891
  *gr121 = recv_msg_buffer->hif_call_msg.service_number;
892
  *lr2 = recv_msg_buffer->hif_call_msg.lr2;
893
  *lr3 = recv_msg_buffer->hif_call_msg.lr3;
894
  *lr4 = recv_msg_buffer->hif_call_msg.lr4;
895
}
896
 
897
void    Mini_unpack_stdin_needed_msg (nbytes)
898
INT32   *nbytes;
899
{
900
  *nbytes = recv_msg_buffer->stdin_needed_msg.nbytes;
901
}
902
 
903
void    Mini_unpack_stdin_mode_msg (mode)
904
INT32   *mode;
905
{
906
  *mode = recv_msg_buffer->stdin_mode_msg.mode;
907
}
908
 
909
 
910
/* miscellaneous */
911
 
912
static
913
INT32 match_name(name)
914
char    *name;
915
{
916
 int    i;
917
 
918
 i = 0;
919
 while (TDF[i].target_name) {
920
   if (strcmp(TDF[i].target_name, name))
921
     i++;
922
   else
923
     return((INT32) i);
924
 }
925
 return(FAILURE);
926
}
927
 
928
/*
929
** This function is used to print out a message which has
930
** been received from the target.
931
*/
932
 
933
void
934
print_msg(msg, MsgFile)
935
   union msg_t *msg;
936
   FILE         *MsgFile;
937
   {
938
   INT32  i, j;
939
   INT32  length;
940
   BYTE         *s;
941
   INT32        *hex;
942
   INT32        code;
943
 
944
   hex = &(msg->generic_int32_msg.int32);
945
   s = &(msg->generic_msg.byte);
946
   length = msg->generic_msg.length;
947
 
948
   fprintf(MsgFile, "\n");
949
   code = msg->generic_msg.code;
950
   fprintf(MsgFile, "Code:    %ld ", code);
951
   switch (code) {
952
     case       RESET:
953
        fprintf(MsgFile,"(RESET)\t");
954
        break;
955
     case       CONFIG_REQ:
956
        fprintf(MsgFile,"(CONFIG_REQ)\t");
957
        break;
958
     case       STATUS_REQ:
959
        fprintf(MsgFile,"(STATUS_REQ)\t");
960
        break;
961
     case       READ_REQ:
962
        fprintf(MsgFile,"(READ_REQ)\t");
963
        break;
964
     case       WRITE_REQ:
965
        fprintf(MsgFile,"(WRITE_REQ)\t");
966
        break;
967
     case       BKPT_SET:
968
        fprintf(MsgFile,"(BKPT_SET)\t");
969
        break;
970
     case       BKPT_RM:
971
        fprintf(MsgFile,"(BKPT_RM)\t");
972
        break;
973
     case       BKPT_STAT:
974
        fprintf(MsgFile,"(BKPT_STAT)\t");
975
        break;
976
     case       COPY:
977
        fprintf(MsgFile,"(COPY)\t");
978
        break;
979
     case       FILL:
980
        fprintf(MsgFile,"(FILL)\t");
981
        break;
982
     case       INIT:
983
        fprintf(MsgFile,"(INIT)\t");
984
        break;
985
     case       GO:
986
        fprintf(MsgFile,"(GO)\t");
987
        break;
988
     case       STEP:
989
        fprintf(MsgFile,"(STEP)\t");
990
        break;
991
     case       BREAK:
992
        fprintf(MsgFile,"(BREAK)\t");
993
        break;
994
     case       HIF_CALL_RTN:
995
        fprintf(MsgFile,"(HIF_CALL_RTN)\t");
996
        break;
997
     case       CHANNEL0:
998
        fprintf(MsgFile,"(CHANNEL0)\t");
999
        break;
1000
     case       CHANNEL1_ACK:
1001
        fprintf(MsgFile,"(CHANNEL1_ACK)\t");
1002
        break;
1003
     case       CHANNEL2_ACK:
1004
        fprintf(MsgFile,"(CHANNEL2_ACK)\t");
1005
        break;
1006
     case       STDIN_NEEDED_ACK:
1007
        fprintf(MsgFile,"(STDIN_NEEDED_ACK)\t");
1008
        break;
1009
     case       STDIN_MODE_ACK:
1010
        fprintf(MsgFile,"(STDIN_MODE_ACK)\t");
1011
        break;
1012
     case       RESET_ACK:
1013
        fprintf(MsgFile,"(RESET_ACK)\t");
1014
        break;
1015
     case       CONFIG:
1016
        fprintf(MsgFile,"(CONFIG)\t");
1017
        break;
1018
     case       STATUS:
1019
        fprintf(MsgFile,"(STATUS)\t");
1020
        break;
1021
     case       READ_ACK:
1022
        fprintf(MsgFile,"(READ_ACK)\t");
1023
        break;
1024
     case       WRITE_ACK:
1025
        fprintf(MsgFile,"(WRITE_ACK)\t");
1026
        break;
1027
     case       BKPT_SET_ACK:
1028
        fprintf(MsgFile,"(BKPT_SET_ACK)\t");
1029
        break;
1030
     case       BKPT_RM_ACK:
1031
        fprintf(MsgFile,"(BKPT_RM_ACK)\t");
1032
        break;
1033
     case       BKPT_STAT_ACK:
1034
        fprintf(MsgFile,"(BKPT_STAT_ACK)\t");
1035
        break;
1036
     case       COPY_ACK:
1037
        fprintf(MsgFile,"(COPY_ACK)\t");
1038
        break;
1039
     case       FILL_ACK:
1040
        fprintf(MsgFile,"(FILL_ACK)\t");
1041
        break;
1042
     case       INIT_ACK:
1043
        fprintf(MsgFile,"(INIT_ACK)\t");
1044
        break;
1045
     case       HALT:
1046
        fprintf(MsgFile,"(HALT)\t");
1047
        break;
1048
     case       ERROR:
1049
        fprintf(MsgFile,"(ERROR)\t");
1050
        break;
1051
     case       HIF_CALL:
1052
        fprintf(MsgFile,"(HIF_CALL)\t");
1053
        break;
1054
     case       CHANNEL0_ACK:
1055
        fprintf(MsgFile,"(CHANNEL0_ACK)\t");
1056
        break;
1057
     case       CHANNEL1:
1058
        fprintf(MsgFile,"(CHANNEL1)\t");
1059
        break;
1060
     case       CHANNEL2:
1061
        fprintf(MsgFile,"(CHANNEL2)\t");
1062
        break;
1063
     case       STDIN_NEEDED_REQ:
1064
        fprintf(MsgFile,"(STDIN_NEEDED_REQ)\t");
1065
        break;
1066
     case       STDIN_MODE_REQ:
1067
        fprintf(MsgFile,"(STDIN_MODE_REQ)\t");
1068
        break;
1069
     default:
1070
        fprintf(MsgFile,"(unknown)\t");
1071
        break;
1072
   }
1073
   fprintf(MsgFile, "Length:  %ld\n", msg->generic_msg.length);
1074
   if ((code == CHANNEL1) || (code == CHANNEL2))
1075
       return;
1076
   if ((code == WRITE_REQ) || (code == FILL)) length = 20;
1077
   if (code == READ_ACK) length = 16;
1078
   if (code == STDIN_NEEDED_ACK) length = 16;
1079
   for (i=0; i<((length+sizeof(INT32)-1)/sizeof(INT32)); i=i+1) {
1080
      fprintf(MsgFile, "%08lx  (",  *hex++);
1081
      for (j=0; j<sizeof(INT32); j=j+1)
1082
         if (isprint(*s))
1083
            fprintf(MsgFile, "%d", *s++);
1084
               else
1085
                  s++, fprintf(MsgFile, ".");
1086
      fprintf(MsgFile, ")\n");
1087
      }
1088
 
1089
   }  /* end print_msg() */
1090
 
1091
 
1092
 
1093
 
1094
void
1095
CopyMsgToTarg(source)
1096
union msg_t     *source;
1097
{
1098
  INT32         msglen;
1099
  INT32         count;
1100
  char          *to, *from;
1101
 
1102
  send_msg_buffer->generic_msg.code = source->generic_msg.code;
1103
  send_msg_buffer->generic_msg.length = source->generic_msg.length;
1104
  msglen = source->generic_msg.length;
1105
  to = (char *) &(send_msg_buffer->generic_msg.byte);
1106
  from = (char *) &(source->generic_msg.byte);
1107
  for (count = (INT32) 0; count < msglen; count++)
1108
     *to++ = *from++;
1109
 
1110
}
1111
 
1112
void
1113
CopyMsgFromTarg(dest)
1114
union msg_t     *dest;
1115
{
1116
  INT32         msglen;
1117
  INT32         count;
1118
  char          *to, *from;
1119
 
1120
  dest->generic_msg.code = recv_msg_buffer->generic_msg.code;
1121
  dest->generic_msg.length = recv_msg_buffer->generic_msg.length;
1122
  msglen = recv_msg_buffer->generic_msg.length;
1123
  to = (char *) &(dest->generic_msg.byte);
1124
  from = (char *) &(recv_msg_buffer->generic_msg.byte);
1125
  for (count = (INT32) 0; count < msglen; count++)
1126
     *to++ = *from++;
1127
 
1128
}
1129
 
1130
void
1131
print_recv_bytes()
1132
{
1133
  printf("Bytes received: \n");
1134
  printf("0x%lx \n", (long) recv_msg_buffer->generic_msg.code);
1135
  printf("0x%lx \n", (long) recv_msg_buffer->generic_msg.length);
1136
}
1137
 

powered by: WebSVN 2.1.0

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