File: pceb.c

package info (click to toggle)
pm3 1.1.13-11
  • links: PTS
  • area: main
  • in suites: potato
  • size: 174,164 kB
  • ctags: 133,819
  • sloc: ansic: 982,617; modula3: 548,483; cpp: 57,119; exp: 21,673; sh: 17,053; lisp: 13,693; makefile: 13,492; asm: 11,795; yacc: 8,575; sed: 1,100; objc: 476; csh: 254; awk: 223; pascal: 95; fortran: 5
file content (404 lines) | stat: -rw-r--r-- 11,757 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
static char _[] = "@(#)pceb.c	5.18 93/07/30 16:40:31, AMD.";
/******************************************************************************
 * Copyright 1991 Advanced Micro Devices, Inc.
 *
 * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
 * specifically  grants the user the right to modify, use and distribute this
 * software provided this notice is not removed or altered.  All other rights
 * are reserved by AMD.
 *
 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
 * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
 * USE OF THIS SOFTWARE.
 *
 * So that all may benefit from your experience, please report  any  problems
 * or  suggestions about this software to the 29K Technical Support Center at
 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
 * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
 *
 * Advanced Micro Devices, Inc.
 * 29K Support Products
 * Mail Stop 573
 * 5900 E. Ben White Blvd.
 * Austin, TX 78741
 * 800-292-9263
 *****************************************************************************
 *      Engineer: Srini Subramanian.
 *****************************************************************************
 ** 
 **       This file defines functions which initialize and access the
 **       the PCEB 29K board.
 **
 *****************************************************************************
 */


#include <stdio.h>
#include <memory.h>
#include "messages.h"
#include "pceb.h"
#include "memspcs.h"
#include "macros.h"
#include "tdfunc.h"
#include "mtip.h"

#include <dos.h>
#include <conio.h>
void  endian_cvt PARAMS((union msg_t *, int));
void  tip_convert32 PARAMS((BYTE *));


/*
** This function is used to initialize the communication
** channel.  This consists of setting the window location
** of the PCEB to the value defined by the values in
** the file PCEB.h.
*/

/*ARGSUSED*/
INT32
init_comm_pceb(PC_port_base, PC_mem_seg)
INT32	PC_port_base;
INT32	PC_mem_seg;
   {
   
   /*** check for existence of the board ***/

   /* Set up PCCNF and reset processor */
   outp((unsigned int) (PC_port_base + PCEB_PCCNF_OFFSET),
        ((int) (PC_mem_seg & 0x7000) >> 10));
   outp((unsigned int) (PC_port_base + PCEB_PC229K_OFFSET),
        (int) (PCEB_LB_END | PCEB_WINENA | PCEB_S_HALT));

   return(0);
   }


/*
** This function is used to send a message to the PCEB.
** If the message is successfully sent, a zero is
** returned.  If the message was not sendable, a -1
** is returned.
**
** Also note that this function does endian conversion on the
** returned message.  This is necessary because the Am29000
** target will be sending big-endian messages and the PC will
** be expecting little-endian.
*/

INT32
msg_send_pceb(msg_ptr, PC_port_base)
   union  msg_t  *msg_ptr;
   INT32	PC_port_base;
   {
   INT32    result;
   int    pc229k;
   INT32  message_size;
   INT32	semaphore;
   INT32	result3;

         /* Set semaphore (PCEB_RECV_BUF_PTR) to zero */
	   semaphore = (INT32) 0;
           result3 = Mini_write_memory ((INT32)   D_MEM,
                                      (ADDR32) PCEB_RECV_BUF_PTR,
                                      (INT32)  sizeof(INT32),
                                      (BYTE *) &semaphore);
   /* Get size of whole message */
   message_size = (msg_ptr->generic_msg).length + (2 * sizeof(INT32));

   /* Do endian conversion */
   if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
      endian_cvt(msg_ptr, OUTGOING_MSG);

   /* Send message */
   result = Mini_write_memory ((INT32)  D_MEM,
                              (ADDR32) PCEB_SEND_BUF,
                              (INT32)  message_size,
                              (BYTE *) msg_ptr);

   /* Interrupt target (write to pceb mailbox) */
   pc229k = (PCEB_P_REQ | PCEB_WINENA | PCEB_LB_END | PCEB_S_NORMAL);
   outp((unsigned int) (PC_port_base + PCEB_PC229K_OFFSET),
        (int) pc229k);

   /* Did everything go ok? */
   if (result != 0)
      return(-1);
      else
         return(0);

   }  /* end msg_send_pceb() */




/*
** This function is used to receive a message to the PCEB.
** If the message is waiting in the buffer, the message Code is
** returned and the buffer pointed to by msg_ptr is filled
** in.  If no message was available, a -1 is returned.
**
** Note that this function does endian conversion on the
** returned message.  This is necessary because the Am29000
** target will be sending big-endian messages and the PC will
** be expecting little-endian.
*/

INT32
msg_recv_pceb(msg_ptr, PC_port_base, Mode)
   union  msg_t  *msg_ptr;
   INT32  PC_port_base;
   INT32	Mode;
   {
   INT32    result1;
   INT32    result2;
   INT32    result3;
   ADDR32 recv_buf_addr;
   INT32  parms_length;
   INT32  header_size;
   INT32  semaphore;

   /* Get receive buffer address */
   result1 = Mini_read_memory ((INT32)  D_MEM,
                              (ADDR32) PCEB_RECV_BUF_PTR,
                              (INT32)  sizeof(ADDR32),
                              (BYTE *) &recv_buf_addr);

   /* Change endian of recv_buf_addr */
   if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
      tip_convert32((BYTE *) &recv_buf_addr);

   /* Return if there is no message */
   if (recv_buf_addr == 0) {
      return(-1);
      } else {
         /* Get message header */
         header_size = (INT32) (2 * sizeof(INT32));
         result1 = Mini_read_memory ((INT32)  D_MEM,
                                    (ADDR32) recv_buf_addr,
                                    (INT32)  header_size,
                                    (BYTE *) msg_ptr);

         /* Get rest of message */
         parms_length = (msg_ptr->generic_msg).length;
         if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
            tip_convert32((BYTE *) &parms_length);
         result2 = Mini_read_memory ((INT32)  D_MEM,
                                    (ADDR32) (recv_buf_addr + header_size),
                                    (INT32)  parms_length,
                                    (BYTE *) &(msg_ptr->generic_msg.byte));

         /* Do endian conversion */
         if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
            endian_cvt(msg_ptr, INCOMING_MSG);

         /* Set semaphore (PCEB_RECV_BUF_PTR) to zero */
	   semaphore = (INT32) 0;
           result3 = Mini_write_memory ((INT32)   D_MEM,
                                      (ADDR32) PCEB_RECV_BUF_PTR,
                                      (INT32)  sizeof(INT32),
                                      (BYTE *) &semaphore);
      }

   /* Did everything go ok? */
   if ((result1 != (INT32) 0) ||
       (result2 != (INT32) 0) ||
       (result3 != (INT32) 0))
         return(-1);
      else
         return(msg_ptr->generic_msg.code);

   }  /* end msg_recv_pceb() */




/*
** This function is used to close the communication
** channel.  This is used when resyncing the host and
** target and when exiting the monitor.
*/

INT32
exit_comm_pceb(PC_port_base, PC_mem_seg)
INT32	PC_port_base;
INT32	PC_mem_seg;
   {
     return (0);
   }

INT32
reset_comm_pceb(PC_port_base, PC_mem_seg)
INT32	PC_port_base;
INT32	PC_mem_seg;
   {

   return(0);

   }  /* end reset_comm_pceb() */



/*
** This function is used to "kick" the PCEB.  This
** amounts to yanking the *RESET line low.  Code
** will begin execution at ROM address 0.
*/

void
go_pceb(PC_port_base, PC_mem_seg)
INT32	PC_port_base;
INT32	PC_mem_seg;
   {
   int  setup;

   /* Reset processor */
   setup = (PCEB_LB_END | PCEB_WINENA);

   outp((unsigned int) (PC_port_base + PCEB_PC229K_OFFSET),
        (int) (setup | PCEB_S_RESET | PCEB_S_HALT));

   outp((unsigned int) (PC_port_base + PCEB_PC229K_OFFSET),
        (int) (setup | PCEB_S_RESET | PCEB_S_NORMAL));

   outp((unsigned int) (PC_port_base + PCEB_PC229K_OFFSET),
        (int ) (setup | PCEB_S_NORMAL));

   }  /* end go_pceb() */






/*
** This function is used to write a string of bytes to
** the Am29000 memory on the PCEB board.
**
** For more information on the PCEB interface, see
** Chapter 5 of the "PCEB User's Manual".
**
** Note:  This function aligns all 16 1K byte windows to make
** a single 16K byte window on a 1K boundary.
*/

INT32
write_memory_pceb(memory_space, address, data, byte_count, PC_port_base,
		  PC_mem_seg)
   INT32    memory_space;
   ADDR32   address;
   BYTE    *data;
   INT32    byte_count;
   INT32	PC_port_base;
   INT32	PC_mem_seg;
   {
   INT32  i;
   ADDR32 temp_address;
   INT32  bytes_in_window;
   INT32  copy_count;

   while (byte_count > 0) {

      /* Set up a single, contiguous 16K window (on a 1K boundary) */
      temp_address = address;
      for (i=0; i<16; i=i+1) {
         /* Write out low PCEB addr bits */
         outp((unsigned int) (PC_port_base+(INT32) (2*i)),
              (int) ((temp_address >> 10) & 0xff));

         /* Write out high PCEB addr bits */
         outp((unsigned int) (PC_port_base+(INT32) (2*i)+(INT32) 1),
              (int) ((temp_address >> 18) & 0x1f));
         temp_address = temp_address + (ADDR32) 0x400;
         }  /* end for */

      bytes_in_window = (INT32) 0x4000 - (address & 0x3ff);
      copy_count = (byte_count < bytes_in_window) ? byte_count : bytes_in_window;

      (void) movedata((unsigned int) FP_SEG(data),
                      (unsigned int) FP_OFF(data),
                      (unsigned int) PC_mem_seg,
                      (unsigned int) (address & 0x3ff),
                      (int) copy_count);

      data = data + copy_count;
      address = address + copy_count;
      byte_count = byte_count - copy_count;

      }  /* end while loop */

   return(0);

   }  /* End write_memory_pceb() */




/*
** This function is used to read a string of bytes from
** the Am29000 memory on the PCEB board.   A zero is
** returned if the data is read successfully, otherwise
** a -1 is returned.
**
** For more information on the PCEB interface, see
** Chapter 5 of the "PCEB User's Manual".
**
** Note:  This function aligns all 16 1K byte windows to make
** a single 16K byte window on a 1K boundary.
*/

INT32
read_memory_pceb(memory_space, address, data, byte_count, PC_port_base,
		 PC_mem_seg)
   INT32    memory_space;
   ADDR32   address;
   BYTE    *data;
   INT32    byte_count;
   INT32	PC_port_base;
   INT32	PC_mem_seg;
   {
   INT32  i;
   ADDR32 temp_address;
   INT32  bytes_in_window;
   INT32  copy_count;

   while (byte_count > 0) {

      /* Set up a single, contiguous 16K window (on a 1K boundary) */
      temp_address = address;
      for (i=0; i<16; i=i+1) {
         /* Write out low PCEB addr bits */
         outp((unsigned int) (PC_port_base+(2*i)),
              (int) ((temp_address >> 10) & 0xff));

         /* Write out high PCEB addr bits */
         outp((unsigned int) (PC_port_base+(2*i)+(INT32) 1),
              (int) ((temp_address >> 18) & 0x1f));
         temp_address = temp_address + (ADDR32) 0x400;
         }  /* end for */

      bytes_in_window = (INT32) 0x4000 - (address & 0x3ff);
      copy_count = (byte_count < bytes_in_window) ? byte_count : bytes_in_window;

      (void) movedata((unsigned int) PC_mem_seg,
                      (unsigned int) (address & 0x3ff),
                      (unsigned int) FP_SEG(data),
                      (unsigned int) FP_OFF(data),
                      (int) copy_count);

      data = data + copy_count;
      address = address + copy_count;
      byte_count = byte_count - copy_count;

      }  /* end while loop */

   return(0);

   }  /* End read_memory_pceb() */

INT32
fill_memory_pceb()
{
  return(0);
}