1998-02-06 10:29:22 +08:00
|
|
|
/* Copyright (C) 1998, Cygnus Solutions */
|
|
|
|
|
1998-02-19 05:26:38 +08:00
|
|
|
|
1998-03-11 19:57:55 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
#include <stdlib.h>
|
1998-02-07 08:12:14 +08:00
|
|
|
#include "sky-pke.h"
|
|
|
|
#include "sky-dma.h"
|
1998-02-14 07:29:38 +08:00
|
|
|
#include "sim-bits.h"
|
1998-02-07 08:12:14 +08:00
|
|
|
#include "sim-assert.h"
|
|
|
|
#include "sky-vu0.h"
|
|
|
|
#include "sky-vu1.h"
|
|
|
|
#include "sky-gpuif.h"
|
1998-03-07 06:46:40 +08:00
|
|
|
#include "sky-device.h"
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-03-11 19:57:55 +08:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
/* Internal function declarations */
|
|
|
|
|
|
|
|
static int pke_io_read_buffer(device*, void*, int, address_word,
|
|
|
|
unsigned, sim_cpu*, sim_cia);
|
|
|
|
static int pke_io_write_buffer(device*, const void*, int, address_word,
|
|
|
|
unsigned, sim_cpu*, sim_cia);
|
1998-03-14 09:47:06 +08:00
|
|
|
static void pke_reset(struct pke_device*);
|
1998-02-19 05:26:38 +08:00
|
|
|
static void pke_issue(SIM_DESC, struct pke_device*);
|
1998-02-07 08:12:14 +08:00
|
|
|
static void pke_pc_advance(struct pke_device*, int num_words);
|
1998-03-14 09:47:06 +08:00
|
|
|
static struct fifo_quadword* pke_pcrel_fifo(struct pke_device*, int operand_num,
|
|
|
|
unsigned_4** operand);
|
|
|
|
static unsigned_4* pke_pcrel_operand(struct pke_device*, int operand_num);
|
|
|
|
static unsigned_4 pke_pcrel_operand_bits(struct pke_device*, int bit_offset,
|
|
|
|
int bit_width, unsigned_4* sourceaddr);
|
1998-02-07 08:12:14 +08:00
|
|
|
static void pke_attach(SIM_DESC sd, struct pke_device* me);
|
1998-02-12 03:42:15 +08:00
|
|
|
enum pke_check_target { chk_vu, chk_path1, chk_path2, chk_path3 };
|
|
|
|
static int pke_check_stall(struct pke_device* me, enum pke_check_target what);
|
|
|
|
static void pke_flip_dbf(struct pke_device* me);
|
1998-03-14 09:47:06 +08:00
|
|
|
static void pke_begin_interrupt_stall(struct pke_device* me);
|
1998-02-12 03:42:15 +08:00
|
|
|
/* PKEcode handlers */
|
|
|
|
static void pke_code_nop(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_stcycl(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_offset(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_base(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_itop(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_stmod(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_mskpath3(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_pkemark(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_flushe(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_flush(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_flusha(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_pkemscal(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_pkemscnt(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_pkemscalf(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_stmask(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_strow(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_stcol(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_mpg(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_direct(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_directhl(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_unpack(struct pke_device* me, unsigned_4 pkecode);
|
|
|
|
static void pke_code_error(struct pke_device* me, unsigned_4 pkecode);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Static data */
|
|
|
|
|
|
|
|
struct pke_device pke0_device =
|
|
|
|
{
|
|
|
|
{ "pke0", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
|
|
|
|
0, 0, /* ID, flags */
|
|
|
|
{}, /* regs */
|
1998-02-14 07:29:38 +08:00
|
|
|
{}, 0, /* FIFO write buffer */
|
1998-03-14 09:47:06 +08:00
|
|
|
{ NULL, 0, 0, 0 }, /* FIFO */
|
|
|
|
NULL, /* FIFO trace file */
|
1998-03-21 06:12:06 +08:00
|
|
|
-1, -1, 0, 0, 0, /* invalid FIFO cache */
|
1998-02-07 08:12:14 +08:00
|
|
|
0, 0 /* pc */
|
1998-02-06 10:29:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct pke_device pke1_device =
|
|
|
|
{
|
|
|
|
{ "pke1", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
|
|
|
|
1, 0, /* ID, flags */
|
|
|
|
{}, /* regs */
|
1998-02-14 07:29:38 +08:00
|
|
|
{}, 0, /* FIFO write buffer */
|
1998-03-14 09:47:06 +08:00
|
|
|
{ NULL, 0, 0, 0 }, /* FIFO */
|
|
|
|
NULL, /* FIFO trace file */
|
1998-03-21 06:12:06 +08:00
|
|
|
-1, -1, 0, 0, 0, /* invalid FIFO cache */
|
1998-02-07 08:12:14 +08:00
|
|
|
0, 0 /* pc */
|
1998-02-06 10:29:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* External functions */
|
|
|
|
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* Attach PKE addresses to main memory */
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke0_attach(SIM_DESC sd)
|
|
|
|
{
|
1998-02-07 08:12:14 +08:00
|
|
|
pke_attach(sd, & pke0_device);
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_reset(& pke0_device);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
void
|
|
|
|
pke1_attach(SIM_DESC sd)
|
|
|
|
{
|
|
|
|
pke_attach(sd, & pke1_device);
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_reset(& pke1_device);
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
/* Issue a PKE instruction if possible */
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
void
|
1998-02-19 05:26:38 +08:00
|
|
|
pke0_issue(SIM_DESC sd)
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
1998-02-19 05:26:38 +08:00
|
|
|
pke_issue(sd, & pke0_device);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-19 05:26:38 +08:00
|
|
|
pke1_issue(SIM_DESC sd)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-21 07:59:10 +08:00
|
|
|
pke_issue(sd, & pke1_device);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Internal functions */
|
|
|
|
|
|
|
|
|
|
|
|
/* Attach PKE memory regions to simulator */
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_attach(SIM_DESC sd, struct pke_device* me)
|
|
|
|
{
|
|
|
|
/* register file */
|
1998-02-19 05:26:38 +08:00
|
|
|
sim_core_attach (sd, NULL, 0, access_read_write, 0,
|
1998-02-07 08:12:14 +08:00
|
|
|
(me->pke_number == 0) ? PKE0_REGISTER_WINDOW_START : PKE1_REGISTER_WINDOW_START,
|
1998-02-06 10:29:22 +08:00
|
|
|
PKE_REGISTER_WINDOW_SIZE /*nr_bytes*/,
|
|
|
|
0 /*modulo*/,
|
1998-02-19 05:26:38 +08:00
|
|
|
(device*) me,
|
1998-02-06 10:29:22 +08:00
|
|
|
NULL /*buffer*/);
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* FIFO port */
|
1998-02-19 05:26:38 +08:00
|
|
|
sim_core_attach (sd, NULL, 0, access_read_write, 0,
|
1998-02-07 08:12:14 +08:00
|
|
|
(me->pke_number == 0) ? PKE0_FIFO_ADDR : PKE1_FIFO_ADDR,
|
1998-02-06 10:29:22 +08:00
|
|
|
sizeof(quadword) /*nr_bytes*/,
|
|
|
|
0 /*modulo*/,
|
1998-02-19 05:26:38 +08:00
|
|
|
(device*) me,
|
1998-02-06 10:29:22 +08:00
|
|
|
NULL /*buffer*/);
|
|
|
|
|
1998-02-20 09:50:01 +08:00
|
|
|
/* VU MEM0 tracking table */
|
1998-02-19 05:26:38 +08:00
|
|
|
sim_core_attach (sd, NULL, 0, access_read_write, 0,
|
1998-02-20 09:50:01 +08:00
|
|
|
((me->pke_number == 0) ? VU0_MEM0_SRCADDR_START : VU1_MEM0_SRCADDR_START),
|
|
|
|
((me->pke_number == 0) ? VU0_MEM0_SIZE : VU1_MEM0_SIZE) / 2,
|
1998-02-07 08:12:14 +08:00
|
|
|
0 /*modulo*/,
|
1998-02-20 09:50:01 +08:00
|
|
|
NULL,
|
|
|
|
NULL /*buffer*/);
|
|
|
|
|
|
|
|
/* VU MEM1 tracking table */
|
|
|
|
sim_core_attach (sd, NULL, 0, access_read_write, 0,
|
|
|
|
((me->pke_number == 0) ? VU0_MEM1_SRCADDR_START : VU1_MEM1_SRCADDR_START),
|
|
|
|
((me->pke_number == 0) ? VU0_MEM1_SIZE : VU1_MEM1_SIZE) / 4,
|
|
|
|
0 /*modulo*/,
|
|
|
|
NULL,
|
|
|
|
NULL /*buffer*/);
|
|
|
|
|
1998-02-19 05:26:38 +08:00
|
|
|
|
|
|
|
/* attach to trace file if appropriate */
|
|
|
|
{
|
|
|
|
char trace_envvar[80];
|
|
|
|
char* trace_filename = NULL;
|
|
|
|
sprintf(trace_envvar, "VIF%d_TRACE_FILE", me->pke_number);
|
|
|
|
trace_filename = getenv(trace_envvar);
|
|
|
|
if(trace_filename != NULL)
|
|
|
|
{
|
|
|
|
me->fifo_trace_file = fopen(trace_filename, "w");
|
|
|
|
if(me->fifo_trace_file == NULL)
|
|
|
|
perror("VIF FIFO trace error on fopen");
|
1998-02-24 10:10:23 +08:00
|
|
|
else
|
|
|
|
setvbuf(me->fifo_trace_file, NULL, _IOLBF, 0);
|
1998-02-19 05:26:38 +08:00
|
|
|
}
|
|
|
|
}
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle a PKE read; return no. of bytes read */
|
|
|
|
|
|
|
|
int
|
|
|
|
pke_io_read_buffer(device *me_,
|
|
|
|
void *dest,
|
|
|
|
int space,
|
|
|
|
address_word addr,
|
|
|
|
unsigned nr_bytes,
|
1998-02-07 08:12:14 +08:00
|
|
|
sim_cpu *cpu,
|
1998-02-06 10:29:22 +08:00
|
|
|
sim_cia cia)
|
|
|
|
{
|
|
|
|
/* downcast to gather embedding pke_device struct */
|
|
|
|
struct pke_device* me = (struct pke_device*) me_;
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* find my address ranges */
|
|
|
|
address_word my_reg_start =
|
|
|
|
(me->pke_number == 0) ? PKE0_REGISTER_WINDOW_START : PKE1_REGISTER_WINDOW_START;
|
|
|
|
address_word my_fifo_addr =
|
|
|
|
(me->pke_number == 0) ? PKE0_FIFO_ADDR : PKE1_FIFO_ADDR;
|
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
/* enforce that an access does not span more than one quadword */
|
|
|
|
address_word low = ADDR_TRUNC_QW(addr);
|
|
|
|
address_word high = ADDR_TRUNC_QW(addr + nr_bytes - 1);
|
|
|
|
if(low != high)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* classify address & handle */
|
1998-02-07 08:12:14 +08:00
|
|
|
if((addr >= my_reg_start) && (addr < my_reg_start + PKE_REGISTER_WINDOW_SIZE))
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
|
|
|
/* register bank */
|
1998-02-07 08:12:14 +08:00
|
|
|
int reg_num = ADDR_TRUNC_QW(addr - my_reg_start) >> 4;
|
|
|
|
int reg_byte = ADDR_OFFSET_QW(addr); /* find byte-offset inside register bank */
|
1998-02-06 10:29:22 +08:00
|
|
|
int readable = 1;
|
1998-02-07 08:12:14 +08:00
|
|
|
quadword result;
|
|
|
|
|
|
|
|
/* clear result */
|
|
|
|
result[0] = result[1] = result[2] = result[3] = 0;
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* handle reads to individual registers; clear `readable' on error */
|
1998-02-06 10:29:22 +08:00
|
|
|
switch(reg_num)
|
|
|
|
{
|
1998-02-07 08:12:14 +08:00
|
|
|
/* handle common case of register reading, side-effect free */
|
|
|
|
/* PKE1-only registers*/
|
1998-02-06 10:29:22 +08:00
|
|
|
case PKE_REG_BASE:
|
|
|
|
case PKE_REG_OFST:
|
|
|
|
case PKE_REG_TOPS:
|
|
|
|
case PKE_REG_TOP:
|
|
|
|
case PKE_REG_DBF:
|
1998-02-07 08:12:14 +08:00
|
|
|
if(me->pke_number == 0)
|
1998-02-06 10:29:22 +08:00
|
|
|
readable = 0;
|
1998-02-07 08:12:14 +08:00
|
|
|
/* fall through */
|
|
|
|
/* PKE0 & PKE1 common registers*/
|
|
|
|
case PKE_REG_STAT:
|
|
|
|
case PKE_REG_ERR:
|
|
|
|
case PKE_REG_MARK:
|
|
|
|
case PKE_REG_CYCLE:
|
|
|
|
case PKE_REG_MODE:
|
|
|
|
case PKE_REG_NUM:
|
|
|
|
case PKE_REG_MASK:
|
|
|
|
case PKE_REG_CODE:
|
|
|
|
case PKE_REG_ITOPS:
|
|
|
|
case PKE_REG_ITOP:
|
|
|
|
case PKE_REG_R0:
|
|
|
|
case PKE_REG_R1:
|
|
|
|
case PKE_REG_R2:
|
|
|
|
case PKE_REG_R3:
|
|
|
|
case PKE_REG_C0:
|
|
|
|
case PKE_REG_C1:
|
|
|
|
case PKE_REG_C2:
|
|
|
|
case PKE_REG_C3:
|
1998-02-28 05:52:40 +08:00
|
|
|
result[0] = H2T_4(me->regs[reg_num][0]);
|
1998-02-07 08:12:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* handle common case of write-only registers */
|
|
|
|
case PKE_REG_FBRST:
|
|
|
|
readable = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0); /* test above should prevent this possibility */
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* perform transfer & return */
|
1998-02-06 10:29:22 +08:00
|
|
|
if(readable)
|
|
|
|
{
|
|
|
|
/* copy the bits */
|
1998-02-07 08:12:14 +08:00
|
|
|
memcpy(dest, ((unsigned_1*) &result) + reg_byte, nr_bytes);
|
1998-02-06 10:29:22 +08:00
|
|
|
/* okay */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-02-24 10:10:23 +08:00
|
|
|
/* return zero bits */
|
|
|
|
memset(dest, 0, nr_bytes);
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
return nr_bytes;
|
1998-02-06 10:29:22 +08:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
else if(addr >= my_fifo_addr &&
|
|
|
|
addr < my_fifo_addr + sizeof(quadword))
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
|
|
|
/* FIFO */
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* FIFO is not readable: return a word of zeroes */
|
|
|
|
memset(dest, 0, nr_bytes);
|
|
|
|
return nr_bytes;
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
1998-02-07 08:12:14 +08:00
|
|
|
return 0;
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle a PKE read; return no. of bytes written */
|
|
|
|
|
|
|
|
int
|
|
|
|
pke_io_write_buffer(device *me_,
|
|
|
|
const void *src,
|
|
|
|
int space,
|
|
|
|
address_word addr,
|
|
|
|
unsigned nr_bytes,
|
1998-02-07 08:12:14 +08:00
|
|
|
sim_cpu *cpu,
|
1998-02-06 10:29:22 +08:00
|
|
|
sim_cia cia)
|
|
|
|
{
|
|
|
|
/* downcast to gather embedding pke_device struct */
|
|
|
|
struct pke_device* me = (struct pke_device*) me_;
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* find my address ranges */
|
|
|
|
address_word my_reg_start =
|
|
|
|
(me->pke_number == 0) ? PKE0_REGISTER_WINDOW_START : PKE1_REGISTER_WINDOW_START;
|
|
|
|
address_word my_fifo_addr =
|
|
|
|
(me->pke_number == 0) ? PKE0_FIFO_ADDR : PKE1_FIFO_ADDR;
|
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
/* enforce that an access does not span more than one quadword */
|
|
|
|
address_word low = ADDR_TRUNC_QW(addr);
|
|
|
|
address_word high = ADDR_TRUNC_QW(addr + nr_bytes - 1);
|
|
|
|
if(low != high)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* classify address & handle */
|
1998-02-07 08:12:14 +08:00
|
|
|
if((addr >= my_reg_start) && (addr < my_reg_start + PKE_REGISTER_WINDOW_SIZE))
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
|
|
|
/* register bank */
|
1998-02-07 08:12:14 +08:00
|
|
|
int reg_num = ADDR_TRUNC_QW(addr - my_reg_start) >> 4;
|
|
|
|
int reg_byte = ADDR_OFFSET_QW(addr); /* find byte-offset inside register bank */
|
1998-02-06 10:29:22 +08:00
|
|
|
int writeable = 1;
|
1998-02-07 08:12:14 +08:00
|
|
|
quadword input;
|
|
|
|
|
|
|
|
/* clear input */
|
|
|
|
input[0] = input[1] = input[2] = input[3] = 0;
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* write user-given bytes into input */
|
|
|
|
memcpy(((unsigned_1*) &input) + reg_byte, src, nr_bytes);
|
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* make words host-endian */
|
|
|
|
input[0] = T2H_4(input[0]);
|
|
|
|
/* we may ignore other words */
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* handle writes to individual registers; clear `writeable' on error */
|
1998-02-06 10:29:22 +08:00
|
|
|
switch(reg_num)
|
|
|
|
{
|
1998-02-07 08:12:14 +08:00
|
|
|
case PKE_REG_FBRST:
|
1998-02-12 03:42:15 +08:00
|
|
|
/* Order these tests from least to most overriding, in case
|
|
|
|
multiple bits are set. */
|
1998-02-24 10:10:23 +08:00
|
|
|
if(BIT_MASK_GET(input[0], PKE_REG_FBRST_STC_B, PKE_REG_FBRST_STC_E))
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
|
|
|
/* clear a bunch of status bits */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PSS, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PFS, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PIS, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, INT, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, ER0, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, ER1, 0);
|
1998-02-14 07:29:38 +08:00
|
|
|
me->flags &= ~PKE_FLAG_PENDING_PSS;
|
1998-02-07 08:12:14 +08:00
|
|
|
/* will allow resumption of possible stalled instruction */
|
|
|
|
}
|
1998-02-24 10:10:23 +08:00
|
|
|
if(BIT_MASK_GET(input[0], PKE_REG_FBRST_STP_B, PKE_REG_FBRST_STP_E))
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-02-14 07:29:38 +08:00
|
|
|
me->flags |= PKE_FLAG_PENDING_PSS;
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-24 10:10:23 +08:00
|
|
|
if(BIT_MASK_GET(input[0], PKE_REG_FBRST_FBK_B, PKE_REG_FBRST_FBK_E))
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PFS, 1);
|
|
|
|
}
|
1998-02-24 10:10:23 +08:00
|
|
|
if(BIT_MASK_GET(input[0], PKE_REG_FBRST_RST_B, PKE_REG_FBRST_RST_E))
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_reset(me);
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_REG_ERR:
|
|
|
|
/* copy bottom three bits */
|
|
|
|
BIT_MASK_SET(me->regs[PKE_REG_ERR][0], 0, 2, BIT_MASK_GET(input[0], 0, 2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_REG_MARK:
|
|
|
|
/* copy bottom sixteen bits */
|
|
|
|
PKE_REG_MASK_SET(me, MARK, MARK, BIT_MASK_GET(input[0], 0, 15));
|
|
|
|
/* reset MRK bit in STAT */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, MRK, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* handle common case of read-only registers */
|
|
|
|
/* PKE1-only registers - not really necessary to handle separately */
|
1998-02-06 10:29:22 +08:00
|
|
|
case PKE_REG_BASE:
|
|
|
|
case PKE_REG_OFST:
|
|
|
|
case PKE_REG_TOPS:
|
|
|
|
case PKE_REG_TOP:
|
|
|
|
case PKE_REG_DBF:
|
1998-02-07 08:12:14 +08:00
|
|
|
if(me->pke_number == 0)
|
1998-02-06 10:29:22 +08:00
|
|
|
writeable = 0;
|
1998-02-07 08:12:14 +08:00
|
|
|
/* fall through */
|
|
|
|
/* PKE0 & PKE1 common registers*/
|
|
|
|
case PKE_REG_STAT:
|
|
|
|
/* ignore FDR bit for PKE1_STAT -- simulator does not implement PKE->RAM transfers */
|
|
|
|
case PKE_REG_CYCLE:
|
|
|
|
case PKE_REG_MODE:
|
|
|
|
case PKE_REG_NUM:
|
|
|
|
case PKE_REG_MASK:
|
|
|
|
case PKE_REG_CODE:
|
|
|
|
case PKE_REG_ITOPS:
|
|
|
|
case PKE_REG_ITOP:
|
|
|
|
case PKE_REG_R0:
|
|
|
|
case PKE_REG_R1:
|
|
|
|
case PKE_REG_R2:
|
|
|
|
case PKE_REG_R3:
|
|
|
|
case PKE_REG_C0:
|
|
|
|
case PKE_REG_C1:
|
|
|
|
case PKE_REG_C2:
|
|
|
|
case PKE_REG_C3:
|
|
|
|
writeable = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0); /* test above should prevent this possibility */
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* perform return */
|
1998-02-24 10:10:23 +08:00
|
|
|
if(! writeable)
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
1998-02-24 10:10:23 +08:00
|
|
|
; /* error */
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
return nr_bytes;
|
|
|
|
|
1998-02-06 10:29:22 +08:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
else if(addr >= my_fifo_addr &&
|
|
|
|
addr < my_fifo_addr + sizeof(quadword))
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
|
|
|
/* FIFO */
|
1998-02-07 08:12:14 +08:00
|
|
|
struct fifo_quadword* fqw;
|
1998-02-14 07:29:38 +08:00
|
|
|
int fifo_byte = ADDR_OFFSET_QW(addr); /* find byte-offset inside fifo quadword */
|
1998-02-19 05:26:38 +08:00
|
|
|
unsigned_4 dma_tag_present = 0;
|
1998-02-14 07:29:38 +08:00
|
|
|
int i;
|
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* collect potentially-partial quadword in write buffer; LE byte order */
|
1998-02-14 07:29:38 +08:00
|
|
|
memcpy(((unsigned_1*)& me->fifo_qw_in_progress) + fifo_byte, src, nr_bytes);
|
|
|
|
/* mark bytes written */
|
|
|
|
for(i = fifo_byte; i < fifo_byte + nr_bytes; i++)
|
|
|
|
BIT_MASK_SET(me->fifo_qw_done, i, i, 1);
|
|
|
|
|
|
|
|
/* return if quadword not quite written yet */
|
|
|
|
if(BIT_MASK_GET(me->fifo_qw_done, 0, sizeof(quadword)-1) !=
|
1998-02-19 05:26:38 +08:00
|
|
|
BIT_MASK_BTW(0, sizeof(quadword)-1))
|
1998-02-14 07:29:38 +08:00
|
|
|
return nr_bytes;
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* all done - process quadword after clearing flag */
|
|
|
|
BIT_MASK_SET(me->fifo_qw_done, 0, sizeof(quadword)-1, 0);
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* allocate required address in FIFO */
|
|
|
|
fqw = pke_fifo_fit(& me->fifo);
|
|
|
|
ASSERT(fqw != NULL);
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* fill in unclassified FIFO quadword data in host byte order */
|
1998-02-19 05:26:38 +08:00
|
|
|
fqw->word_class[0] = fqw->word_class[1] =
|
|
|
|
fqw->word_class[2] = fqw->word_class[3] = wc_unknown;
|
1998-02-28 05:52:40 +08:00
|
|
|
fqw->data[0] = T2H_4(me->fifo_qw_in_progress[0]);
|
|
|
|
fqw->data[1] = T2H_4(me->fifo_qw_in_progress[1]);
|
|
|
|
fqw->data[2] = T2H_4(me->fifo_qw_in_progress[2]);
|
|
|
|
fqw->data[3] = T2H_4(me->fifo_qw_in_progress[3]);
|
1998-03-14 09:47:06 +08:00
|
|
|
|
|
|
|
/* read DMAC-supplied indicators */
|
1998-02-19 05:26:38 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
1998-02-20 09:50:01 +08:00
|
|
|
PKE_MEM_READ(me, (me->pke_number == 0 ? DMA_D0_MADR : DMA_D1_MADR),
|
1998-02-28 05:52:40 +08:00
|
|
|
& fqw->source_address, /* converted to host-endian */
|
1998-02-19 05:26:38 +08:00
|
|
|
4);
|
1998-02-20 09:50:01 +08:00
|
|
|
PKE_MEM_READ(me, (me->pke_number == 0 ? DMA_D0_PKTFLAG : DMA_D1_PKTFLAG),
|
1998-02-19 05:26:38 +08:00
|
|
|
& dma_tag_present,
|
|
|
|
4);
|
|
|
|
|
|
|
|
if(dma_tag_present)
|
|
|
|
{
|
|
|
|
/* lower two words are DMA tags */
|
|
|
|
fqw->word_class[0] = fqw->word_class[1] = wc_dma;
|
|
|
|
}
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* set FQC to "1" as FIFO is now not empty */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, FQC, 1);
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
/* okay */
|
|
|
|
return nr_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTREACHED */
|
1998-02-07 08:12:14 +08:00
|
|
|
return 0;
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* Reset the PKE */
|
|
|
|
void
|
|
|
|
pke_reset(struct pke_device* me)
|
|
|
|
{
|
|
|
|
/* advance PC over last quadword in FIFO; keep previous FIFO history */
|
|
|
|
me->fifo_pc = pke_fifo_flush(& me->fifo);
|
|
|
|
me->qw_pc = 0;
|
|
|
|
/* clear registers, flag, other state */
|
|
|
|
memset(me->regs, 0, sizeof(me->regs));
|
|
|
|
me->fifo_qw_done = 0;
|
|
|
|
me->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* Issue & swallow next PKE opcode if possible/available */
|
1998-02-06 10:29:22 +08:00
|
|
|
|
|
|
|
void
|
1998-02-19 05:26:38 +08:00
|
|
|
pke_issue(SIM_DESC sd, struct pke_device* me)
|
1998-02-06 10:29:22 +08:00
|
|
|
{
|
1998-02-07 08:12:14 +08:00
|
|
|
struct fifo_quadword* fqw;
|
|
|
|
unsigned_4 fw;
|
1998-03-11 19:57:55 +08:00
|
|
|
unsigned_4 cmd, intr;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-07 06:46:40 +08:00
|
|
|
/* 1 -- fetch PKE instruction */
|
|
|
|
|
|
|
|
/* confirm availability of new quadword of PKE instructions */
|
1998-03-14 09:47:06 +08:00
|
|
|
fqw = pke_fifo_access(& me->fifo, me->fifo_pc);
|
|
|
|
if(fqw == NULL)
|
1998-03-07 06:46:40 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* skip over DMA tag, if present */
|
|
|
|
pke_pc_advance(me, 0);
|
1998-03-14 09:47:06 +08:00
|
|
|
/* note: this can only change qw_pc from 0 to 2 and will not
|
|
|
|
invalidate fqw */
|
1998-03-07 06:46:40 +08:00
|
|
|
|
|
|
|
/* "fetch" instruction quadword and word */
|
|
|
|
fw = fqw->data[me->qw_pc];
|
|
|
|
|
|
|
|
/* store word in PKECODE register */
|
|
|
|
me->regs[PKE_REG_CODE][0] = fw;
|
|
|
|
|
|
|
|
|
|
|
|
/* 2 -- test go / no-go for PKE execution */
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* switch on STAT:PSS if PSS-pending and in idle state */
|
|
|
|
if((PKE_REG_MASK_GET(me, STAT, PPS) == PKE_REG_STAT_PPS_IDLE) &&
|
|
|
|
(me->flags & PKE_FLAG_PENDING_PSS) != 0)
|
|
|
|
{
|
|
|
|
me->flags &= ~PKE_FLAG_PENDING_PSS;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PSS, 1);
|
|
|
|
}
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
/* check for stall/halt control bits */
|
1998-02-14 07:29:38 +08:00
|
|
|
if(PKE_REG_MASK_GET(me, STAT, PFS) ||
|
|
|
|
PKE_REG_MASK_GET(me, STAT, PSS) || /* note special treatment below */
|
1998-03-14 09:47:06 +08:00
|
|
|
/* PEW bit not a reason to keep stalling - it's just an indication, re-computed below */
|
|
|
|
/* PGW bit not a reason to keep stalling - it's just an indication, re-computed below */
|
|
|
|
/* ER0/ER1 not a reason to keep stalling - it's just an indication */
|
1998-03-07 06:46:40 +08:00
|
|
|
PKE_REG_MASK_GET(me, STAT, PIS))
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-03-07 06:46:40 +08:00
|
|
|
/* (still) stalled */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
/* try again next cycle */
|
1998-02-12 03:42:15 +08:00
|
|
|
return;
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 3 -- decode PKE instruction */
|
|
|
|
|
1998-03-07 06:46:40 +08:00
|
|
|
/* decoding */
|
|
|
|
if(PKE_REG_MASK_GET(me, STAT, PPS) == PKE_REG_STAT_PPS_IDLE)
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_DECODE);
|
|
|
|
|
|
|
|
/* Extract relevant bits from PKEcode */
|
1998-02-07 08:12:14 +08:00
|
|
|
intr = BIT_MASK_GET(fw, PKE_OPCODE_I_B, PKE_OPCODE_I_E);
|
|
|
|
cmd = BIT_MASK_GET(fw, PKE_OPCODE_CMD_B, PKE_OPCODE_CMD_E);
|
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* handle interrupts */
|
1998-02-07 08:12:14 +08:00
|
|
|
if(intr)
|
|
|
|
{
|
1998-03-07 06:46:40 +08:00
|
|
|
/* are we resuming an interrupt-stalled instruction? */
|
1998-02-26 03:34:06 +08:00
|
|
|
if(me->flags & PKE_FLAG_INT_NOLOOP)
|
|
|
|
{
|
|
|
|
/* clear loop-prevention flag */
|
|
|
|
me->flags &= ~PKE_FLAG_INT_NOLOOP;
|
1998-03-07 06:46:40 +08:00
|
|
|
|
|
|
|
/* fall through to decode & execute */
|
|
|
|
/* The pke_code_* functions should not check the MSB in the
|
|
|
|
pkecode. */
|
1998-02-26 03:34:06 +08:00
|
|
|
}
|
|
|
|
else /* new interrupt-flagged instruction */
|
|
|
|
{
|
|
|
|
/* set INT flag in STAT register */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, INT, 1);
|
|
|
|
/* set loop-prevention flag */
|
|
|
|
me->flags |= PKE_FLAG_INT_NOLOOP;
|
|
|
|
|
1998-03-07 06:46:40 +08:00
|
|
|
/* set PIS if stall not masked */
|
|
|
|
if(!PKE_REG_MASK_GET(me, ERR, MII))
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_begin_interrupt_stall(me);
|
1998-03-07 06:46:40 +08:00
|
|
|
|
|
|
|
/* suspend this instruction unless it's PKEMARK */
|
|
|
|
if(!IS_PKE_CMD(cmd, PKEMARK))
|
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
; /* fall through to decode & execute */
|
|
|
|
}
|
1998-02-26 03:34:06 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
1998-03-05 03:14:03 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* decode & execute */
|
1998-03-07 06:46:40 +08:00
|
|
|
if(IS_PKE_CMD(cmd, PKENOP))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_nop(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, STCYCL))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_stcycl(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, OFFSET))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_offset(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, BASE))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_base(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, ITOP))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_itop(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, STMOD))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_stmod(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, MSKPATH3))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_mskpath3(me, fw);
|
1998-02-07 08:12:14 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, PKEMARK))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_pkemark(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, FLUSHE))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_flushe(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, FLUSH))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_flush(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, FLUSHA))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_flusha(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, PKEMSCAL))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_pkemscal(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, PKEMSCNT))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_pkemscnt(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(me->pke_number == 1 && IS_PKE_CMD(cmd, PKEMSCALF))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_pkemscalf(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, STMASK))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_stmask(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, STROW))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_strow(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, STCOL))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_stcol(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, MPG))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_mpg(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, DIRECT))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_direct(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, DIRECTHL))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_directhl(me, fw);
|
1998-03-07 06:46:40 +08:00
|
|
|
else if(IS_PKE_CMD(cmd, UNPACK))
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_unpack(me, fw);
|
1998-02-14 07:29:38 +08:00
|
|
|
/* ... no other commands ... */
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
pke_code_error(me, fw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* Clear out contents of FIFO; act as if it was empty. Return PC
|
|
|
|
pointing to one-past-last word. */
|
|
|
|
|
|
|
|
unsigned_4
|
|
|
|
pke_fifo_flush(struct pke_fifo* fifo)
|
|
|
|
{
|
|
|
|
/* don't modify any state! */
|
|
|
|
return fifo->origin + fifo->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-03-21 06:12:06 +08:00
|
|
|
/* Clear out contents of FIFO; make it really empty. */
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_fifo_reset(struct pke_fifo* fifo)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* clear fifo quadwords */
|
|
|
|
for(i=0; i<fifo->next; i++)
|
|
|
|
{
|
|
|
|
zfree(fifo->quadwords[i]);
|
|
|
|
fifo->quadwords[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset pointers */
|
|
|
|
fifo->origin = 0;
|
|
|
|
fifo->next = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* Make space for the next quadword in the FIFO. Allocate/enlarge
|
|
|
|
FIFO pointer block if necessary. Return a pointer to it. */
|
|
|
|
|
|
|
|
struct fifo_quadword*
|
|
|
|
pke_fifo_fit(struct pke_fifo* fifo)
|
|
|
|
{
|
|
|
|
struct fifo_quadword* fqw;
|
|
|
|
|
|
|
|
/* out of space on quadword pointer array? */
|
|
|
|
if(fifo->next == fifo->length) /* also triggered before fifo->quadwords allocated */
|
|
|
|
{
|
|
|
|
struct fifo_quadword** new_qw;
|
|
|
|
unsigned_4 new_length = fifo->length + PKE_FIFO_GROW_SIZE;
|
|
|
|
|
|
|
|
/* allocate new pointer block */
|
|
|
|
new_qw = zalloc(new_length * sizeof(struct fifo_quadword*));
|
|
|
|
ASSERT(new_qw != NULL);
|
|
|
|
|
1998-03-19 03:33:33 +08:00
|
|
|
/* copy over old contents, if any */
|
|
|
|
if(fifo->quadwords != NULL)
|
|
|
|
{
|
|
|
|
/* copy over old pointers to beginning of new block */
|
|
|
|
memcpy(new_qw, fifo->quadwords,
|
|
|
|
fifo->length * sizeof(struct fifo_quadword*));
|
|
|
|
|
|
|
|
/* free old block */
|
|
|
|
zfree(fifo->quadwords);
|
|
|
|
}
|
1998-03-14 09:47:06 +08:00
|
|
|
|
|
|
|
/* replace pointers & counts */
|
|
|
|
fifo->quadwords = new_qw;
|
|
|
|
fifo->length = new_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
ASSERT(fifo->quadwords != NULL);
|
|
|
|
|
|
|
|
/* allocate new quadword from heap */
|
|
|
|
fqw = zalloc(sizeof(struct fifo_quadword));
|
|
|
|
ASSERT(fqw != NULL);
|
|
|
|
|
|
|
|
/* push quadword onto fifo */
|
|
|
|
fifo->quadwords[fifo->next] = fqw;
|
|
|
|
fifo->next++;
|
|
|
|
return fqw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return a pointer to the FIFO quadword with given absolute index, or
|
|
|
|
NULL if it is out of range */
|
|
|
|
|
|
|
|
struct fifo_quadword*
|
|
|
|
pke_fifo_access(struct pke_fifo* fifo, unsigned_4 qwnum)
|
|
|
|
{
|
|
|
|
struct fifo_quadword* fqw;
|
|
|
|
|
|
|
|
if((qwnum < fifo->origin) || /* before history */
|
|
|
|
(qwnum >= fifo->origin + fifo->next)) /* after last available quadword */
|
|
|
|
fqw = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(fifo->quadwords != NULL); /* must be allocated already */
|
|
|
|
fqw = fifo->quadwords[qwnum - fifo->origin]; /* pull out pointer from array */
|
|
|
|
ASSERT(fqw != NULL); /* must be allocated already */
|
|
|
|
}
|
|
|
|
|
|
|
|
return fqw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Authorize release of any FIFO entries older than given absolute quadword. */
|
|
|
|
void
|
|
|
|
pke_fifo_old(struct pke_fifo* fifo, unsigned_4 qwnum)
|
|
|
|
{
|
|
|
|
/* do we have any too-old FIFO elements? */
|
|
|
|
if(fifo->origin + PKE_FIFO_ARCHEOLOGY < qwnum)
|
|
|
|
{
|
|
|
|
/* count quadwords to forget */
|
|
|
|
int horizon = qwnum - (fifo->origin + PKE_FIFO_ARCHEOLOGY);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* free quadwords at indices below horizon */
|
|
|
|
for(i=0; i < horizon; i++)
|
|
|
|
zfree(fifo->quadwords[i]);
|
|
|
|
|
|
|
|
/* move surviving quadword pointers down to beginning of array */
|
|
|
|
for(i=horizon; i < fifo->next; i++)
|
|
|
|
fifo->quadwords[i-horizon] = fifo->quadwords[i];
|
|
|
|
|
|
|
|
/* clear duplicate pointers */
|
|
|
|
for(i=fifo->next - horizon; i < fifo->next; i++)
|
|
|
|
fifo->quadwords[i] = NULL;
|
|
|
|
|
|
|
|
/* adjust FIFO pointers */
|
|
|
|
fifo->origin = fifo->origin + horizon;
|
|
|
|
fifo->next = fifo->next - horizon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* advance the PC by given number of data words; update STAT/FQC
|
1998-02-19 05:26:38 +08:00
|
|
|
field; assume FIFO is filled enough; classify passed-over words;
|
|
|
|
write FIFO trace line */
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_pc_advance(struct pke_device* me, int num_words)
|
|
|
|
{
|
|
|
|
int num = num_words;
|
1998-02-19 05:26:38 +08:00
|
|
|
struct fifo_quadword* fq = NULL;
|
1998-03-14 09:47:06 +08:00
|
|
|
unsigned_4 old_fifo_pc = me->fifo_pc;
|
|
|
|
|
1998-02-19 05:26:38 +08:00
|
|
|
ASSERT(num_words >= 0);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
/* printf("pke %d pc_advance num_words %d\n", me->pke_number, num_words); */
|
|
|
|
|
|
|
|
while(1)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
/* find next quadword, if any */
|
|
|
|
fq = pke_fifo_access(& me->fifo, me->fifo_pc);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* skip over DMA tag words if present in word 0 or 1 */
|
1998-03-14 09:47:06 +08:00
|
|
|
if(fq != NULL && fq->word_class[me->qw_pc] == wc_dma)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* skip by going around loop an extra time */
|
|
|
|
num ++;
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-24 10:10:23 +08:00
|
|
|
|
|
|
|
/* nothing left to skip / no DMA tag here */
|
|
|
|
if(num == 0)
|
|
|
|
break;
|
1998-02-19 05:26:38 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* we are supposed to skip existing words */
|
|
|
|
ASSERT(fq != NULL);
|
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
/* one word skipped */
|
|
|
|
num --;
|
|
|
|
|
|
|
|
/* point to next word */
|
|
|
|
me->qw_pc ++;
|
|
|
|
if(me->qw_pc == 4)
|
1998-02-19 05:26:38 +08:00
|
|
|
{
|
1998-02-24 10:10:23 +08:00
|
|
|
me->qw_pc = 0;
|
|
|
|
me->fifo_pc ++;
|
1998-02-19 05:26:38 +08:00
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
/* trace the consumption of the FIFO quadword we just skipped over */
|
|
|
|
/* fq still points to it */
|
|
|
|
if(me->fifo_trace_file != NULL)
|
1998-02-19 05:26:38 +08:00
|
|
|
{
|
1998-02-24 10:10:23 +08:00
|
|
|
/* assert complete classification */
|
|
|
|
ASSERT(fq->word_class[3] != wc_unknown);
|
|
|
|
ASSERT(fq->word_class[2] != wc_unknown);
|
|
|
|
ASSERT(fq->word_class[1] != wc_unknown);
|
|
|
|
ASSERT(fq->word_class[0] != wc_unknown);
|
1998-02-19 05:26:38 +08:00
|
|
|
|
1998-02-24 10:10:23 +08:00
|
|
|
/* print trace record */
|
|
|
|
fprintf(me->fifo_trace_file,
|
|
|
|
"%d 0x%08x_%08x_%08x_%08x 0x%08x %c%c%c%c\n",
|
|
|
|
(me->pke_number == 0 ? 0 : 1),
|
|
|
|
(unsigned) fq->data[3], (unsigned) fq->data[2],
|
|
|
|
(unsigned) fq->data[1], (unsigned) fq->data[0],
|
|
|
|
(unsigned) fq->source_address,
|
|
|
|
fq->word_class[3], fq->word_class[2],
|
|
|
|
fq->word_class[1], fq->word_class[0]);
|
|
|
|
}
|
|
|
|
} /* next quadword */
|
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* age old entries before PC */
|
|
|
|
if(me->fifo_pc != old_fifo_pc)
|
|
|
|
{
|
|
|
|
/* we advanced the fifo-pc; authorize disposal of anything
|
|
|
|
before previous PKEcode */
|
|
|
|
pke_fifo_old(& me->fifo, old_fifo_pc);
|
|
|
|
}
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* clear FQC if FIFO is now empty */
|
1998-03-14 09:47:06 +08:00
|
|
|
fq = pke_fifo_access(& me->fifo, me->fifo_pc);
|
|
|
|
if(fq == NULL)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
PKE_REG_MASK_SET(me, STAT, FQC, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-19 05:26:38 +08:00
|
|
|
else /* annote the word where the PC lands as an PKEcode */
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
ASSERT(fq->word_class[me->qw_pc] == wc_pkecode || fq->word_class[me->qw_pc] == wc_unknown);
|
1998-02-19 05:26:38 +08:00
|
|
|
fq->word_class[me->qw_pc] = wc_pkecode;
|
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* Return pointer to FIFO quadword containing given operand# in FIFO.
|
|
|
|
`operand_num' starts at 1. Return pointer to operand word in last
|
|
|
|
argument, if non-NULL. If FIFO is not full enough, return 0.
|
|
|
|
Signal an ER0 indication upon skipping a DMA tag. */
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
struct fifo_quadword*
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_pcrel_fifo(struct pke_device* me, int operand_num, unsigned_4** operand)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-03-21 06:12:06 +08:00
|
|
|
int num;
|
1998-02-12 03:42:15 +08:00
|
|
|
int new_qw_pc, new_fifo_pc;
|
1998-02-19 05:26:38 +08:00
|
|
|
struct fifo_quadword* fq = NULL;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-21 06:12:06 +08:00
|
|
|
/* check for validity of last search results in cache */
|
|
|
|
if(me->last_fifo_pc == me->fifo_pc &&
|
|
|
|
me->last_qw_pc == me->qw_pc &&
|
|
|
|
operand_num > me->last_num)
|
|
|
|
{
|
|
|
|
/* continue search from last stop */
|
|
|
|
new_fifo_pc = me->last_new_fifo_pc;
|
|
|
|
new_qw_pc = me->last_new_qw_pc;
|
|
|
|
num = operand_num - me->last_num;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* start search from scratch */
|
|
|
|
new_fifo_pc = me->fifo_pc;
|
|
|
|
new_qw_pc = me->qw_pc;
|
|
|
|
num = operand_num;
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-21 06:12:06 +08:00
|
|
|
ASSERT(num > 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* printf("pke %d pcrel_fifo operand_num %d\n", me->pke_number, operand_num); */
|
1998-02-24 10:10:23 +08:00
|
|
|
|
1998-02-19 05:26:38 +08:00
|
|
|
do
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
/* one word skipped */
|
|
|
|
num --;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* point to next word */
|
|
|
|
new_qw_pc ++;
|
|
|
|
if(new_qw_pc == 4)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
new_qw_pc = 0;
|
|
|
|
new_fifo_pc ++;
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
fq = pke_fifo_access(& me->fifo, new_fifo_pc);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* check for FIFO underflow */
|
1998-03-14 09:47:06 +08:00
|
|
|
if(fq == NULL)
|
|
|
|
break;
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* skip over DMA tag words if present in word 0 or 1 */
|
1998-02-19 05:26:38 +08:00
|
|
|
if(fq->word_class[new_qw_pc] == wc_dma)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
/* set ER0 */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, ER0, 1);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* mismatch error! */
|
1998-03-07 06:46:40 +08:00
|
|
|
if(! PKE_REG_MASK_GET(me, ERR, ME0))
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_begin_interrupt_stall(me);
|
1998-03-07 06:46:40 +08:00
|
|
|
/* don't stall just yet -- finish this instruction */
|
|
|
|
/* the PPS_STALL state will be entered by pke_issue() next time */
|
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
/* skip by going around loop an extra time */
|
|
|
|
num ++;
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
}
|
1998-02-19 05:26:38 +08:00
|
|
|
while(num > 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* return pointer to operand word itself */
|
1998-02-19 05:26:38 +08:00
|
|
|
if(fq != NULL)
|
|
|
|
{
|
|
|
|
*operand = & fq->data[new_qw_pc];
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* annote the word where the pseudo-PC lands as an PKE operand */
|
|
|
|
ASSERT(fq->word_class[new_qw_pc] == wc_pkedata || fq->word_class[new_qw_pc] == wc_unknown);
|
1998-02-19 05:26:38 +08:00
|
|
|
fq->word_class[new_qw_pc] = wc_pkedata;
|
1998-03-21 06:12:06 +08:00
|
|
|
|
|
|
|
/* store search results in cache */
|
|
|
|
/* keys */
|
|
|
|
me->last_fifo_pc = me->fifo_pc;
|
|
|
|
me->last_qw_pc = me->qw_pc;
|
|
|
|
/* values */
|
|
|
|
me->last_num = operand_num;
|
|
|
|
me->last_new_fifo_pc = new_fifo_pc;
|
|
|
|
me->last_new_qw_pc = new_qw_pc;
|
1998-02-19 05:26:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return fq;
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* Return pointer to given operand# in FIFO. `operand_num' starts at 1.
|
|
|
|
If FIFO is not full enough, return 0. Skip over DMA tags, but mark
|
|
|
|
them as an error (ER0). */
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
unsigned_4*
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_pcrel_operand(struct pke_device* me, int operand_num)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
unsigned_4* operand = NULL;
|
|
|
|
struct fifo_quadword* fifo_operand;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
fifo_operand = pke_pcrel_fifo(me, operand_num, & operand);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
if(fifo_operand == NULL)
|
1998-03-14 09:47:06 +08:00
|
|
|
ASSERT(operand == NULL); /* pke_pcrel_fifo() ought leave it untouched */
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
return operand;
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* Return a bit-field extract of given operand# in FIFO, and its
|
|
|
|
source-addr. `bit_offset' starts at 0, referring to LSB after PKE
|
|
|
|
instruction word. Width must be >0, <=32. Assume FIFO is full
|
|
|
|
enough. Skip over DMA tags, but mark them as an error (ER0). */
|
|
|
|
|
|
|
|
unsigned_4
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_pcrel_operand_bits(struct pke_device* me, int bit_offset, int bit_width, unsigned_4* source_addr)
|
1998-02-14 07:29:38 +08:00
|
|
|
{
|
|
|
|
unsigned_4* word = NULL;
|
|
|
|
unsigned_4 value;
|
|
|
|
struct fifo_quadword* fifo_operand;
|
1998-02-20 09:50:01 +08:00
|
|
|
int wordnumber, bitnumber;
|
|
|
|
|
|
|
|
wordnumber = bit_offset/32;
|
|
|
|
bitnumber = bit_offset%32;
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* find operand word with bitfield */
|
1998-03-14 09:47:06 +08:00
|
|
|
fifo_operand = pke_pcrel_fifo(me, wordnumber + 1, &word);
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(word != NULL);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* extract bitfield from word */
|
1998-02-20 09:50:01 +08:00
|
|
|
value = BIT_MASK_GET(*word, bitnumber, bitnumber + bit_width - 1);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* extract source addr from fifo word */
|
|
|
|
*source_addr = fifo_operand->source_address;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* check for stall conditions on indicated devices (path* only on
|
|
|
|
PKE1), do not change status; return 0 iff no stall */
|
1998-02-12 03:42:15 +08:00
|
|
|
int
|
|
|
|
pke_check_stall(struct pke_device* me, enum pke_check_target what)
|
|
|
|
{
|
|
|
|
int any_stall = 0;
|
1998-02-19 05:26:38 +08:00
|
|
|
unsigned_4 cop2_stat, gpuif_stat;
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-19 05:26:38 +08:00
|
|
|
/* read status words */
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_READ(me, (GIF_REG_STAT),
|
|
|
|
& gpuif_stat,
|
|
|
|
4);
|
|
|
|
PKE_MEM_READ(me, (COP2_REG_STAT_ADDR),
|
|
|
|
& cop2_stat,
|
|
|
|
4);
|
1998-02-19 05:26:38 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* perform checks */
|
|
|
|
if(what == chk_vu)
|
|
|
|
{
|
1998-02-19 05:26:38 +08:00
|
|
|
if(me->pke_number == 0)
|
|
|
|
any_stall = BIT_MASK_GET(cop2_stat, COP2_REG_STAT_VBS0_B, COP2_REG_STAT_VBS0_E);
|
|
|
|
else /* if(me->pke_number == 1) */
|
|
|
|
any_stall = BIT_MASK_GET(cop2_stat, COP2_REG_STAT_VBS1_B, COP2_REG_STAT_VBS1_E);
|
1998-02-14 07:29:38 +08:00
|
|
|
}
|
|
|
|
else if(what == chk_path1) /* VU -> GPUIF */
|
|
|
|
{
|
|
|
|
if(BIT_MASK_GET(gpuif_stat, GPUIF_REG_STAT_APATH_B, GPUIF_REG_STAT_APATH_E) == 1)
|
1998-02-12 03:42:15 +08:00
|
|
|
any_stall = 1;
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-14 07:29:38 +08:00
|
|
|
else if(what == chk_path2) /* PKE -> GPUIF */
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-14 07:29:38 +08:00
|
|
|
if(BIT_MASK_GET(gpuif_stat, GPUIF_REG_STAT_APATH_B, GPUIF_REG_STAT_APATH_E) == 2)
|
|
|
|
any_stall = 1;
|
|
|
|
}
|
|
|
|
else if(what == chk_path3) /* DMA -> GPUIF */
|
|
|
|
{
|
|
|
|
if(BIT_MASK_GET(gpuif_stat, GPUIF_REG_STAT_APATH_B, GPUIF_REG_STAT_APATH_E) == 3)
|
1998-02-12 03:42:15 +08:00
|
|
|
any_stall = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-02-14 07:29:38 +08:00
|
|
|
/* invalid what */
|
|
|
|
ASSERT(0);
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* any stall reasons? */
|
|
|
|
return any_stall;
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* PKE1 only: flip the DBF bit; recompute TOPS, TOP */
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_flip_dbf(struct pke_device* me)
|
|
|
|
{
|
1998-03-06 04:23:59 +08:00
|
|
|
int newdf;
|
1998-02-26 03:34:06 +08:00
|
|
|
/* compute new TOP */
|
1998-02-25 07:37:20 +08:00
|
|
|
PKE_REG_MASK_SET(me, TOP, TOP,
|
|
|
|
PKE_REG_MASK_GET(me, TOPS, TOPS));
|
1998-02-12 03:42:15 +08:00
|
|
|
/* flip DBF */
|
1998-03-06 04:23:59 +08:00
|
|
|
newdf = PKE_REG_MASK_GET(me, DBF, DF) ? 0 : 1;
|
|
|
|
PKE_REG_MASK_SET(me, DBF, DF, newdf);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, DBF, newdf);
|
1998-02-12 03:42:15 +08:00
|
|
|
/* compute new TOPS */
|
|
|
|
PKE_REG_MASK_SET(me, TOPS, TOPS,
|
|
|
|
(PKE_REG_MASK_GET(me, BASE, BASE) +
|
1998-03-06 04:23:59 +08:00
|
|
|
newdf * PKE_REG_MASK_GET(me, OFST, OFFSET)));
|
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* this is equivalent to last word from okadaa (98-02-25):
|
|
|
|
1) TOP=TOPS;
|
|
|
|
2) TOPS=BASE + !DBF*OFFSET
|
|
|
|
3) DBF=!DBF */
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* set the STAT:PIS bit and send an interrupt to the 5900 */
|
|
|
|
void
|
|
|
|
pke_begin_interrupt_stall(struct pke_device* me)
|
|
|
|
{
|
|
|
|
/* set PIS */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PIS, 1);
|
|
|
|
|
|
|
|
/* XXX: send interrupt to 5900? */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* PKEcode handler functions -- responsible for checking and
|
|
|
|
confirming old stall conditions, executing pkecode, updating PC and
|
|
|
|
status registers -- may assume being run on correct PKE unit */
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_nop(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_stcycl(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
1998-02-26 03:34:06 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy immediate value into CYCLE reg */
|
1998-02-20 09:50:01 +08:00
|
|
|
PKE_REG_MASK_SET(me, CYCLE, WL, BIT_MASK_GET(imm, 8, 15));
|
|
|
|
PKE_REG_MASK_SET(me, CYCLE, CL, BIT_MASK_GET(imm, 0, 7));
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_offset(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
1998-02-26 03:34:06 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy 10 bits to OFFSET field */
|
|
|
|
PKE_REG_MASK_SET(me, OFST, OFFSET, BIT_MASK_GET(imm, 0, 9));
|
|
|
|
/* clear DBF bit */
|
|
|
|
PKE_REG_MASK_SET(me, DBF, DF, 0);
|
|
|
|
/* clear other DBF bit */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, DBF, 0);
|
|
|
|
/* set TOPS = BASE */
|
|
|
|
PKE_REG_MASK_SET(me, TOPS, TOPS, PKE_REG_MASK_GET(me, BASE, BASE));
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_base(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
1998-02-26 03:34:06 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy 10 bits to BASE field */
|
|
|
|
PKE_REG_MASK_SET(me, BASE, BASE, BIT_MASK_GET(imm, 0, 9));
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_itop(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
1998-02-26 03:34:06 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy 10 bits to ITOPS field */
|
|
|
|
PKE_REG_MASK_SET(me, ITOPS, ITOPS, BIT_MASK_GET(imm, 0, 9));
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_stmod(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
1998-02-26 03:34:06 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy 2 bits to MODE register */
|
|
|
|
PKE_REG_MASK_SET(me, MODE, MDE, BIT_MASK_GET(imm, 0, 2));
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_mskpath3(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
1998-02-24 10:10:23 +08:00
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
unsigned_4 gif_mode;
|
|
|
|
|
1998-02-25 09:13:05 +08:00
|
|
|
/* set appropriate bit */
|
1998-02-24 10:10:23 +08:00
|
|
|
if(BIT_MASK_GET(imm, PKE_REG_MSKPATH3_B, PKE_REG_MSKPATH3_E) != 0)
|
1998-02-25 09:13:05 +08:00
|
|
|
gif_mode = GIF_REG_MODE_M3R_MASK;
|
1998-02-24 10:10:23 +08:00
|
|
|
else
|
1998-02-25 09:13:05 +08:00
|
|
|
gif_mode = 0;
|
1998-02-24 10:10:23 +08:00
|
|
|
|
1998-02-25 09:13:05 +08:00
|
|
|
/* write register; patrickm code will look at M3R bit only */
|
1998-02-24 10:10:23 +08:00
|
|
|
PKE_MEM_WRITE(me, GIF_REG_MODE, & gif_mode, 4);
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_pkemark(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
/* copy 16 bits to MARK register */
|
|
|
|
PKE_REG_MASK_SET(me, MARK, MARK, BIT_MASK_GET(imm, 0, 15));
|
|
|
|
/* set MRK bit in STAT register - CPU2 v2.1 docs incorrect */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, MRK, 1);
|
|
|
|
/* done */
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_flushe(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
/* compute next PEW bit */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
|
|
|
{
|
|
|
|
/* VU busy */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
/* try again next cycle */
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* VU idle */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
1998-02-07 08:12:14 +08:00
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_flush(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int something_busy = 0;
|
|
|
|
|
|
|
|
/* compute next PEW, PGW bits */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
|
|
|
{
|
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
if(pke_check_stall(me, chk_path1) ||
|
|
|
|
pke_check_stall(me, chk_path2))
|
|
|
|
{
|
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* go or no go */
|
|
|
|
if(something_busy)
|
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* all idle */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
1998-02-12 03:42:15 +08:00
|
|
|
pke_code_flusha(struct pke_device* me, unsigned_4 pkecode)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
int something_busy = 0;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* compute next PEW, PGW bits */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
if(pke_check_stall(me, chk_path1) ||
|
|
|
|
pke_check_stall(me, chk_path2) ||
|
|
|
|
pke_check_stall(me, chk_path3))
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 1);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
if(something_busy)
|
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* all idle */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_pkemscal(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
/* compute next PEW bit */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
|
|
|
{
|
|
|
|
/* VU busy */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned_4 vu_pc;
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
|
|
|
|
/* VU idle */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
|
|
|
|
|
|
|
/* flip DBF on PKE1 */
|
|
|
|
if(me->pke_number == 1)
|
|
|
|
pke_flip_dbf(me);
|
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* compute new PC for VU (host byte-order) */
|
1998-02-14 07:29:38 +08:00
|
|
|
vu_pc = BIT_MASK_GET(imm, 0, 15);
|
1998-02-28 05:52:40 +08:00
|
|
|
vu_pc = T2H_4(vu_pc);
|
1998-02-20 09:50:01 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* write new PC; callback function gets VU running */
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_WRITE(me, (me->pke_number == 0 ? VU0_CIA : VU1_CIA),
|
|
|
|
& vu_pc,
|
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* copy ITOPS field to ITOP */
|
|
|
|
PKE_REG_MASK_SET(me, ITOP, ITOP, PKE_REG_MASK_GET(me, ITOPS, ITOPS));
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_pkemscnt(struct pke_device* me, unsigned_4 pkecode)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* compute next PEW bit */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
|
|
|
{
|
|
|
|
/* VU busy */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned_4 vu_pc;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* VU idle */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* flip DBF on PKE1 */
|
|
|
|
if(me->pke_number == 1)
|
|
|
|
pke_flip_dbf(me);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* read old PC */
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_READ(me, (me->pke_number == 0 ? VU0_CIA : VU1_CIA),
|
|
|
|
& vu_pc,
|
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* rewrite new PC; callback function gets VU running */
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_WRITE(me, (me->pke_number == 0 ? VU0_CIA : VU1_CIA),
|
|
|
|
& vu_pc,
|
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* copy ITOPS field to ITOP */
|
|
|
|
PKE_REG_MASK_SET(me, ITOP, ITOP, PKE_REG_MASK_GET(me, ITOPS, ITOPS));
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_pkemscalf(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int something_busy = 0;
|
|
|
|
|
|
|
|
/* compute next PEW, PGW bits */
|
|
|
|
if(pke_check_stall(me, chk_vu))
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 1);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PEW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
if(pke_check_stall(me, chk_path1) ||
|
|
|
|
pke_check_stall(me, chk_path2) ||
|
|
|
|
pke_check_stall(me, chk_path3))
|
|
|
|
{
|
|
|
|
something_busy = 1;
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 1);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
else
|
1998-02-12 03:42:15 +08:00
|
|
|
PKE_REG_MASK_SET(me, STAT, PGW, 0);
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* go or no go */
|
|
|
|
if(something_busy)
|
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned_4 vu_pc;
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
|
|
|
|
/* flip DBF on PKE1 */
|
|
|
|
if(me->pke_number == 1)
|
|
|
|
pke_flip_dbf(me);
|
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* compute new PC for VU (host byte-order) */
|
1998-02-14 07:29:38 +08:00
|
|
|
vu_pc = BIT_MASK_GET(imm, 0, 15);
|
1998-02-28 05:52:40 +08:00
|
|
|
vu_pc = T2H_4(vu_pc);
|
1998-02-20 09:50:01 +08:00
|
|
|
|
|
|
|
/* rewrite new PC; callback function gets VU running */
|
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_WRITE(me, (me->pke_number == 0 ? VU0_CIA : VU1_CIA),
|
|
|
|
& vu_pc,
|
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-26 03:34:06 +08:00
|
|
|
/* copy ITOPS field to ITOP */
|
|
|
|
PKE_REG_MASK_SET(me, ITOP, ITOP, PKE_REG_MASK_GET(me, ITOPS, ITOPS));
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_stmask(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
unsigned_4* mask;
|
1998-02-26 03:34:06 +08:00
|
|
|
|
|
|
|
/* check that FIFO has one more word for STMASK operand */
|
1998-03-14 09:47:06 +08:00
|
|
|
mask = pke_pcrel_operand(me, 1);
|
1998-02-12 03:42:15 +08:00
|
|
|
if(mask != NULL)
|
|
|
|
{
|
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 1);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* fill the register */
|
|
|
|
PKE_REG_MASK_SET(me, MASK, MASK, *mask);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 0);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
1998-02-19 05:26:38 +08:00
|
|
|
pke_pc_advance(me, 2);
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_strow(struct pke_device* me, unsigned_4 pkecode)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* check that FIFO has four more words for STROW operand */
|
|
|
|
unsigned_4* last_op;
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
last_op = pke_pcrel_operand(me, 4);
|
1998-02-12 03:42:15 +08:00
|
|
|
if(last_op != NULL)
|
|
|
|
{
|
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 1);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy ROW registers: must all exist if 4th operand exists */
|
1998-03-14 09:47:06 +08:00
|
|
|
me->regs[PKE_REG_R0][0] = * pke_pcrel_operand(me, 1);
|
|
|
|
me->regs[PKE_REG_R1][0] = * pke_pcrel_operand(me, 2);
|
|
|
|
me->regs[PKE_REG_R2][0] = * pke_pcrel_operand(me, 3);
|
|
|
|
me->regs[PKE_REG_R3][0] = * pke_pcrel_operand(me, 4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 0);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
}
|
1998-02-06 10:29:22 +08:00
|
|
|
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_stcol(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
/* check that FIFO has four more words for STCOL operand */
|
|
|
|
unsigned_4* last_op;
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
last_op = pke_pcrel_operand(me, 4);
|
1998-02-12 03:42:15 +08:00
|
|
|
if(last_op != NULL)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 1);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* copy COL registers: must all exist if 4th operand exists */
|
1998-03-14 09:47:06 +08:00
|
|
|
me->regs[PKE_REG_C0][0] = * pke_pcrel_operand(me, 1);
|
|
|
|
me->regs[PKE_REG_C1][0] = * pke_pcrel_operand(me, 2);
|
|
|
|
me->regs[PKE_REG_C2][0] = * pke_pcrel_operand(me, 3);
|
|
|
|
me->regs[PKE_REG_C3][0] = * pke_pcrel_operand(me, 4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, 0);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 5);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|
|
|
|
else
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* try again next cycle */
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_mpg(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
unsigned_4* last_mpg_word;
|
|
|
|
int num = BIT_MASK_GET(pkecode, PKE_OPCODE_NUM_B, PKE_OPCODE_NUM_E);
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
|
1998-02-21 07:59:10 +08:00
|
|
|
/* assert 64-bit alignment of MPG operand */
|
|
|
|
if(me->qw_pc != 3 && me->qw_pc != 1)
|
|
|
|
return pke_code_error(me, pkecode);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* map zero to max+1 */
|
|
|
|
if(num==0) num=0x100;
|
|
|
|
|
|
|
|
/* check that FIFO has a few more words for MPG operand */
|
1998-03-14 09:47:06 +08:00
|
|
|
last_mpg_word = pke_pcrel_operand(me, num*2); /* num: number of 64-bit words */
|
1998-02-12 03:42:15 +08:00
|
|
|
if(last_mpg_word != NULL)
|
|
|
|
{
|
|
|
|
/* perform implied FLUSHE */
|
1998-02-14 07:29:38 +08:00
|
|
|
if(pke_check_stall(me, chk_vu))
|
1998-02-21 07:59:10 +08:00
|
|
|
{
|
|
|
|
/* VU busy */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
/* retry this instruction next clock */
|
|
|
|
}
|
|
|
|
else
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
/* VU idle */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
|
|
|
|
1998-02-20 09:50:01 +08:00
|
|
|
/* set NUM */
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, num);
|
|
|
|
|
|
|
|
/* transfer VU instructions, one word-pair per iteration */
|
|
|
|
for(i=0; i<num; i++)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
address_word vu_addr_base, vu_addr;
|
|
|
|
address_word vutrack_addr_base, vutrack_addr;
|
1998-02-25 09:13:05 +08:00
|
|
|
address_word vu_addr_max_size;
|
1998-02-21 07:59:10 +08:00
|
|
|
unsigned_4 vu_lower_opcode, vu_upper_opcode;
|
1998-02-12 03:42:15 +08:00
|
|
|
unsigned_4* operand;
|
1998-02-20 09:50:01 +08:00
|
|
|
struct fifo_quadword* fq;
|
|
|
|
int next_num;
|
|
|
|
|
|
|
|
/* decrement NUM */
|
|
|
|
next_num = PKE_REG_MASK_GET(me, NUM, NUM) - 1;
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, next_num);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* imm: in 64-bit units for MPG instruction */
|
1998-02-12 03:42:15 +08:00
|
|
|
/* VU*_MEM0 : instruction memory */
|
|
|
|
vu_addr_base = (me->pke_number == 0) ?
|
1998-02-25 07:37:20 +08:00
|
|
|
VU0_MEM0_WINDOW_START : VU1_MEM0_WINDOW_START;
|
1998-02-25 09:13:05 +08:00
|
|
|
vu_addr_max_size = (me->pke_number == 0) ?
|
|
|
|
VU0_MEM0_SIZE : VU1_MEM0_SIZE;
|
1998-02-12 03:42:15 +08:00
|
|
|
vutrack_addr_base = (me->pke_number == 0) ?
|
|
|
|
VU0_MEM0_SRCADDR_START : VU1_MEM0_SRCADDR_START;
|
1998-02-25 09:13:05 +08:00
|
|
|
|
|
|
|
/* compute VU address for this word-pair */
|
|
|
|
vu_addr = vu_addr_base + (imm + i) * 8;
|
|
|
|
/* check for vu_addr overflow */
|
|
|
|
while(vu_addr >= vu_addr_base + vu_addr_max_size)
|
|
|
|
vu_addr -= vu_addr_max_size;
|
|
|
|
|
|
|
|
/* compute VU tracking address */
|
|
|
|
vutrack_addr = vutrack_addr_base + ((signed_8)vu_addr - (signed_8)vu_addr_base) / 2;
|
1998-02-20 09:50:01 +08:00
|
|
|
|
1998-02-21 07:59:10 +08:00
|
|
|
/* Fetch operand words; assume they are already little-endian for VU imem */
|
1998-03-14 09:47:06 +08:00
|
|
|
fq = pke_pcrel_fifo(me, i*2 + 1, & operand);
|
1998-02-21 07:59:10 +08:00
|
|
|
vu_lower_opcode = *operand;
|
1998-03-14 09:47:06 +08:00
|
|
|
vu_upper_opcode = *pke_pcrel_operand(me, i*2 + 2);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* write data into VU memory */
|
1998-02-28 05:52:40 +08:00
|
|
|
/* lower (scalar) opcode comes in first word ; macro performs H2T! */
|
1998-02-20 09:50:01 +08:00
|
|
|
PKE_MEM_WRITE(me, vu_addr,
|
1998-02-24 10:10:23 +08:00
|
|
|
& vu_lower_opcode,
|
1998-02-21 07:59:10 +08:00
|
|
|
4);
|
1998-02-28 05:52:40 +08:00
|
|
|
/* upper (vector) opcode comes in second word ; H2T */
|
1998-02-24 10:10:23 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
1998-02-21 07:59:10 +08:00
|
|
|
PKE_MEM_WRITE(me, vu_addr + 4,
|
1998-02-24 10:10:23 +08:00
|
|
|
& vu_upper_opcode,
|
1998-02-21 07:59:10 +08:00
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-21 07:59:10 +08:00
|
|
|
/* write tracking address in target byte-order */
|
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
1998-02-20 09:50:01 +08:00
|
|
|
PKE_MEM_WRITE(me, vutrack_addr,
|
1998-02-28 05:52:40 +08:00
|
|
|
& fq->source_address,
|
1998-02-20 09:50:01 +08:00
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
} /* VU xfer loop */
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* check NUM */
|
|
|
|
ASSERT(PKE_REG_MASK_GET(me, NUM, NUM) == 0);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1 + num*2);
|
|
|
|
}
|
|
|
|
} /* if FIFO full enough */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* retry this instruction next clock */
|
|
|
|
}
|
1998-02-06 10:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
void
|
|
|
|
pke_code_direct(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
/* check that FIFO has a few more words for DIRECT operand */
|
|
|
|
unsigned_4* last_direct_word;
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
|
1998-02-21 07:59:10 +08:00
|
|
|
/* assert 128-bit alignment of DIRECT operand */
|
|
|
|
if(me->qw_pc != 3)
|
|
|
|
return pke_code_error(me, pkecode);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* map zero to max+1 */
|
|
|
|
if(imm==0) imm=0x10000;
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
last_direct_word = pke_pcrel_operand(me, imm*4); /* imm: number of 128-bit words */
|
1998-02-12 03:42:15 +08:00
|
|
|
if(last_direct_word != NULL)
|
|
|
|
{
|
|
|
|
/* VU idle */
|
|
|
|
int i;
|
1998-02-28 05:52:40 +08:00
|
|
|
unsigned_16 fifo_data;
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
|
|
|
|
|
|
|
/* transfer GPUIF quadwords, one word per iteration */
|
|
|
|
for(i=0; i<imm*4; i++)
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
unsigned_4* operand = pke_pcrel_operand(me, 1+i);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* collect word into quadword */
|
1998-02-28 05:52:40 +08:00
|
|
|
*A4_16(&fifo_data, 3 - (i % 4)) = *operand;
|
1998-03-19 03:33:33 +08:00
|
|
|
|
1998-02-20 09:50:01 +08:00
|
|
|
/* write to GPUIF FIFO only with full quadword */
|
|
|
|
if(i % 4 == 3)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(fifo_data) == 16);
|
|
|
|
PKE_MEM_WRITE(me, GIF_PATH2_FIFO_ADDR,
|
1998-02-28 05:52:40 +08:00
|
|
|
& fifo_data,
|
1998-02-20 09:50:01 +08:00
|
|
|
16);
|
1998-02-12 03:42:15 +08:00
|
|
|
} /* write collected quadword */
|
|
|
|
} /* GPUIF xfer loop */
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
pke_pc_advance(me, 1 + imm*4);
|
|
|
|
} /* if FIFO full enough */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* retry this instruction next clock */
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_directhl(struct pke_device* me, unsigned_4 pkecode)
|
1998-02-07 08:12:14 +08:00
|
|
|
{
|
1998-02-12 03:42:15 +08:00
|
|
|
/* treat the same as DIRECTH */
|
|
|
|
pke_code_direct(me, pkecode);
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_unpack(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
|
|
|
int imm = BIT_MASK_GET(pkecode, PKE_OPCODE_IMM_B, PKE_OPCODE_IMM_E);
|
|
|
|
int cmd = BIT_MASK_GET(pkecode, PKE_OPCODE_CMD_B, PKE_OPCODE_CMD_E);
|
|
|
|
int num = BIT_MASK_GET(pkecode, PKE_OPCODE_NUM_B, PKE_OPCODE_NUM_E);
|
1998-03-14 09:47:06 +08:00
|
|
|
int nummx = (num == 0) ? 0x0100 : num;
|
1998-02-14 07:29:38 +08:00
|
|
|
short vn = BIT_MASK_GET(cmd, 2, 3); /* unpack shape controls */
|
1998-02-12 03:42:15 +08:00
|
|
|
short vl = BIT_MASK_GET(cmd, 0, 1);
|
|
|
|
int m = BIT_MASK_GET(cmd, 4, 4);
|
1998-02-14 07:29:38 +08:00
|
|
|
short cl = PKE_REG_MASK_GET(me, CYCLE, CL); /* cycle controls */
|
1998-02-12 03:42:15 +08:00
|
|
|
short wl = PKE_REG_MASK_GET(me, CYCLE, WL);
|
1998-03-14 09:47:06 +08:00
|
|
|
short addrwl = (wl == 0) ? 0x0100 : wl;
|
1998-02-14 07:29:38 +08:00
|
|
|
int r = BIT_MASK_GET(imm, 15, 15); /* indicator bits in imm value */
|
1998-02-21 07:59:10 +08:00
|
|
|
int usn = BIT_MASK_GET(imm, 14, 14);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
int n, num_operands;
|
1998-02-20 09:50:01 +08:00
|
|
|
unsigned_4* last_operand_word = NULL;
|
1998-03-14 09:47:06 +08:00
|
|
|
|
|
|
|
/* catch all illegal UNPACK variants */
|
|
|
|
if(vl == 3 && vn < 3)
|
|
|
|
{
|
|
|
|
pke_code_error(me, pkecode);
|
|
|
|
return;
|
|
|
|
}
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* compute PKEcode length, as given in CPU2 spec, v2.1 pg. 11 */
|
1998-03-14 09:47:06 +08:00
|
|
|
if(cl >= addrwl)
|
1998-02-12 03:42:15 +08:00
|
|
|
n = num;
|
|
|
|
else
|
1998-03-14 09:47:06 +08:00
|
|
|
n = cl * (nummx / addrwl) + PKE_LIMIT(nummx % addrwl, cl);
|
1998-03-07 06:46:40 +08:00
|
|
|
num_operands = (31 + (32 >> vl) * (vn+1) * n)/32; /* round up to next word */
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* confirm that FIFO has enough words in it */
|
1998-02-20 09:50:01 +08:00
|
|
|
if(num_operands > 0)
|
1998-03-14 09:47:06 +08:00
|
|
|
last_operand_word = pke_pcrel_operand(me, num_operands);
|
1998-02-20 09:50:01 +08:00
|
|
|
if(last_operand_word != NULL || num_operands == 0)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-02-20 09:50:01 +08:00
|
|
|
address_word vu_addr_base, vutrack_addr_base;
|
|
|
|
address_word vu_addr_max_size;
|
|
|
|
int vector_num_out, vector_num_in;
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* "transferring" operand */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_XFER);
|
|
|
|
|
|
|
|
/* don't check whether VU is idle */
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* compute VU address base */
|
1998-02-12 03:42:15 +08:00
|
|
|
if(me->pke_number == 0)
|
1998-02-20 09:50:01 +08:00
|
|
|
{
|
1998-02-26 03:34:06 +08:00
|
|
|
vu_addr_base = VU0_MEM1_WINDOW_START;
|
1998-02-20 09:50:01 +08:00
|
|
|
vu_addr_max_size = VU0_MEM1_SIZE;
|
1998-02-26 03:34:06 +08:00
|
|
|
vutrack_addr_base = VU0_MEM1_SRCADDR_START;
|
|
|
|
r = 0;
|
1998-02-20 09:50:01 +08:00
|
|
|
}
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
{
|
1998-02-26 03:34:06 +08:00
|
|
|
vu_addr_base = VU1_MEM1_WINDOW_START;
|
1998-02-20 09:50:01 +08:00
|
|
|
vu_addr_max_size = VU1_MEM1_SIZE;
|
1998-02-26 03:34:06 +08:00
|
|
|
vutrack_addr_base = VU1_MEM1_SRCADDR_START;
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* set NUM */
|
1998-03-14 09:47:06 +08:00
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, nummx);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* transfer given number of vectors */
|
1998-02-20 09:50:01 +08:00
|
|
|
vector_num_out = 0; /* output vector number being processed */
|
|
|
|
vector_num_in = 0; /* argument vector number being processed */
|
1998-02-14 07:29:38 +08:00
|
|
|
do
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
quadword vu_old_data;
|
|
|
|
quadword vu_new_data;
|
|
|
|
quadword unpacked_data;
|
|
|
|
address_word vu_addr;
|
1998-02-20 09:50:01 +08:00
|
|
|
address_word vutrack_addr;
|
1998-02-14 07:29:38 +08:00
|
|
|
unsigned_4 source_addr = 0;
|
1998-02-12 03:42:15 +08:00
|
|
|
int i;
|
1998-02-20 09:50:01 +08:00
|
|
|
int next_num;
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* decrement NUM */
|
1998-02-20 09:50:01 +08:00
|
|
|
next_num = PKE_REG_MASK_GET(me, NUM, NUM) - 1;
|
|
|
|
PKE_REG_MASK_SET(me, NUM, NUM, next_num);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* compute VU destination address, as bytes in R5900 memory */
|
|
|
|
if(cl >= wl)
|
|
|
|
{
|
|
|
|
/* map zero to max+1 */
|
1998-02-26 03:34:06 +08:00
|
|
|
vu_addr = vu_addr_base + 16 * (BIT_MASK_GET(imm, 0, 9) +
|
1998-03-07 06:46:40 +08:00
|
|
|
(vector_num_out / addrwl) * cl +
|
|
|
|
(vector_num_out % addrwl));
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
|
|
|
else
|
1998-02-26 03:34:06 +08:00
|
|
|
vu_addr = vu_addr_base + 16 * (BIT_MASK_GET(imm, 0, 9) +
|
|
|
|
vector_num_out);
|
1998-03-07 06:46:40 +08:00
|
|
|
|
|
|
|
/* handle "R" double-buffering bit */
|
|
|
|
if(r)
|
|
|
|
vu_addr += 16 * PKE_REG_MASK_GET(me, TOPS, TOPS);
|
1998-02-20 09:50:01 +08:00
|
|
|
|
|
|
|
/* check for vu_addr overflow */
|
|
|
|
while(vu_addr >= vu_addr_base + vu_addr_max_size)
|
|
|
|
vu_addr -= vu_addr_max_size;
|
|
|
|
|
|
|
|
/* compute address of tracking table entry */
|
|
|
|
vutrack_addr = vutrack_addr_base + ((signed_8)vu_addr - (signed_8)vu_addr_base) / 4;
|
1998-02-14 07:29:38 +08:00
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* read old VU data word at address; reverse words if needed */
|
|
|
|
{
|
|
|
|
unsigned_16 vu_old_badwords;
|
|
|
|
ASSERT(sizeof(vu_old_badwords) == 16);
|
|
|
|
PKE_MEM_READ(me, vu_addr,
|
|
|
|
&vu_old_badwords, 16);
|
|
|
|
vu_old_data[0] = * A4_16(& vu_old_badwords, 3);
|
|
|
|
vu_old_data[1] = * A4_16(& vu_old_badwords, 2);
|
|
|
|
vu_old_data[2] = * A4_16(& vu_old_badwords, 1);
|
|
|
|
vu_old_data[3] = * A4_16(& vu_old_badwords, 0);
|
|
|
|
}
|
1998-02-21 07:59:10 +08:00
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* For cyclic unpack, next operand quadword may come from instruction stream
|
|
|
|
or be zero. */
|
1998-03-14 09:47:06 +08:00
|
|
|
if((cl < addrwl) &&
|
|
|
|
(vector_num_out % addrwl) >= cl)
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
/* clear operand - used only in a "indeterminate" state */
|
|
|
|
for(i = 0; i < 4; i++)
|
|
|
|
unpacked_data[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-02-14 07:29:38 +08:00
|
|
|
/* compute packed vector dimensions */
|
1998-03-14 09:47:06 +08:00
|
|
|
int vectorbits = 0, unitbits = 0;
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
if(vl < 3) /* PKE_UNPACK_*_{32,16,8} */
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
1998-02-14 07:29:38 +08:00
|
|
|
unitbits = (32 >> vl);
|
|
|
|
vectorbits = unitbits * (vn+1);
|
|
|
|
}
|
|
|
|
else if(vl == 3 && vn == 3) /* PKE_UNPACK_V4_5 */
|
|
|
|
{
|
|
|
|
unitbits = 5;
|
|
|
|
vectorbits = 16;
|
|
|
|
}
|
|
|
|
else /* illegal unpack variant */
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
/* should have been caught at top of function */
|
|
|
|
ASSERT(0);
|
1998-02-14 07:29:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* loop over columns */
|
|
|
|
for(i=0; i<=vn; i++)
|
|
|
|
{
|
|
|
|
unsigned_4 operand;
|
1998-02-07 08:12:14 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* offset in bits in current operand word */
|
|
|
|
int bitoffset =
|
1998-02-20 09:50:01 +08:00
|
|
|
(vector_num_in * vectorbits) + (i * unitbits); /* # of bits from PKEcode */
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* last unit of V4_5 is only one bit wide */
|
|
|
|
if(vl == 3 && vn == 3 && i == 3) /* PKE_UNPACK_V4_5 */
|
|
|
|
unitbits = 1;
|
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* confirm we're not reading more than we said we needed */
|
|
|
|
if(vector_num_in * vectorbits >= num_operands * 32)
|
|
|
|
{
|
|
|
|
/* this condition may be triggered by illegal
|
|
|
|
PKEcode / CYCLE combinations. */
|
|
|
|
pke_code_error(me, pkecode);
|
|
|
|
/* XXX: this case needs to be better understood,
|
|
|
|
and detected at a better time. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* fetch bitfield operand */
|
1998-03-14 09:47:06 +08:00
|
|
|
operand = pke_pcrel_operand_bits(me, bitoffset, unitbits, & source_addr);
|
1998-02-14 07:29:38 +08:00
|
|
|
|
|
|
|
/* selectively sign-extend; not for V4_5 1-bit value */
|
1998-02-21 07:59:10 +08:00
|
|
|
if(usn || unitbits == 1)
|
1998-02-14 07:29:38 +08:00
|
|
|
unpacked_data[i] = operand;
|
1998-02-21 07:59:10 +08:00
|
|
|
else
|
|
|
|
unpacked_data[i] = SEXT32(operand, unitbits-1);
|
1998-02-12 03:42:15 +08:00
|
|
|
}
|
1998-02-20 09:50:01 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* set remaining top words in vector */
|
|
|
|
for(i=vn+1; i<4; i++)
|
|
|
|
{
|
|
|
|
if(vn == 0) /* S_{32,16,8}: copy lowest element */
|
|
|
|
unpacked_data[i] = unpacked_data[0];
|
|
|
|
else
|
|
|
|
unpacked_data[i] = 0;
|
|
|
|
}
|
1998-03-07 06:46:40 +08:00
|
|
|
|
1998-02-20 09:50:01 +08:00
|
|
|
/* consumed a vector from the PKE instruction stream */
|
|
|
|
vector_num_in ++;
|
1998-02-14 07:29:38 +08:00
|
|
|
} /* unpack word from instruction operand */
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* process STMOD register for accumulation operations */
|
|
|
|
switch(PKE_REG_MASK_GET(me, MODE, MDE))
|
|
|
|
{
|
|
|
|
case PKE_MODE_ADDROW: /* add row registers to output data */
|
|
|
|
for(i=0; i<4; i++)
|
|
|
|
/* exploit R0..R3 contiguity */
|
|
|
|
unpacked_data[i] += me->regs[PKE_REG_R0 + i][0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_MODE_ACCROW: /* add row registers to output data; accumulate */
|
|
|
|
for(i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
/* exploit R0..R3 contiguity */
|
|
|
|
unpacked_data[i] += me->regs[PKE_REG_R0 + i][0];
|
|
|
|
me->regs[PKE_REG_R0 + i][0] = unpacked_data[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_MODE_INPUT: /* pass data through */
|
|
|
|
default: /* specified as undefined */
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
1998-02-14 07:29:38 +08:00
|
|
|
/* compute replacement word */
|
1998-02-12 03:42:15 +08:00
|
|
|
if(m) /* use mask register? */
|
|
|
|
{
|
|
|
|
/* compute index into mask register for this word */
|
1998-02-24 10:10:23 +08:00
|
|
|
int mask_index = PKE_LIMIT(vector_num_out % addrwl, 3);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-02-20 09:50:01 +08:00
|
|
|
for(i=0; i<4; i++) /* loop over columns */
|
1998-02-12 03:42:15 +08:00
|
|
|
{
|
|
|
|
int mask_op = PKE_MASKREG_GET(me, mask_index, i);
|
|
|
|
unsigned_4* masked_value = NULL;
|
|
|
|
|
|
|
|
switch(mask_op)
|
|
|
|
{
|
|
|
|
case PKE_MASKREG_INPUT:
|
1998-03-14 09:47:06 +08:00
|
|
|
masked_value = & unpacked_data[i];
|
1998-02-12 03:42:15 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_MASKREG_ROW: /* exploit R0..R3 contiguity */
|
|
|
|
masked_value = & me->regs[PKE_REG_R0 + i][0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_MASKREG_COLUMN: /* exploit C0..C3 contiguity */
|
1998-02-20 09:50:01 +08:00
|
|
|
masked_value = & me->regs[PKE_REG_C0 + mask_index][0];
|
1998-02-12 03:42:15 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PKE_MASKREG_NOTHING:
|
|
|
|
/* "write inhibit" by re-copying old data */
|
|
|
|
masked_value = & vu_old_data[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
/* no other cases possible */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy masked value for column */
|
1998-02-14 07:29:38 +08:00
|
|
|
vu_new_data[i] = *masked_value;
|
1998-02-12 03:42:15 +08:00
|
|
|
} /* loop over columns */
|
1998-02-14 07:29:38 +08:00
|
|
|
} /* mask */
|
1998-02-12 03:42:15 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no mask - just copy over entire unpacked quadword */
|
|
|
|
memcpy(vu_new_data, unpacked_data, sizeof(unpacked_data));
|
|
|
|
}
|
|
|
|
|
1998-02-28 05:52:40 +08:00
|
|
|
/* write new VU data word at address; reverse words if needed */
|
|
|
|
{
|
|
|
|
unsigned_16 vu_new_badwords;
|
|
|
|
* A4_16(& vu_new_badwords, 3) = vu_new_data[0];
|
|
|
|
* A4_16(& vu_new_badwords, 2) = vu_new_data[1];
|
|
|
|
* A4_16(& vu_new_badwords, 1) = vu_new_data[2];
|
|
|
|
* A4_16(& vu_new_badwords, 0) = vu_new_data[3];
|
|
|
|
ASSERT(sizeof(vu_new_badwords) == 16);
|
|
|
|
PKE_MEM_WRITE(me, vu_addr,
|
|
|
|
&vu_new_badwords, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write tracking address */
|
1998-02-20 09:50:01 +08:00
|
|
|
ASSERT(sizeof(unsigned_4) == 4);
|
|
|
|
PKE_MEM_WRITE(me, vutrack_addr,
|
|
|
|
& source_addr,
|
|
|
|
4);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
|
|
|
/* next vector please */
|
1998-02-20 09:50:01 +08:00
|
|
|
vector_num_out ++;
|
1998-02-12 03:42:15 +08:00
|
|
|
} /* vector transfer loop */
|
1998-02-14 07:29:38 +08:00
|
|
|
while(PKE_REG_MASK_GET(me, NUM, NUM) > 0);
|
1998-02-12 03:42:15 +08:00
|
|
|
|
1998-03-14 09:47:06 +08:00
|
|
|
/* confirm we've written as many vectors as told */
|
|
|
|
ASSERT(nummx == vector_num_out);
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* done */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
1998-02-19 05:26:38 +08:00
|
|
|
pke_pc_advance(me, 1 + num_operands);
|
1998-02-12 03:42:15 +08:00
|
|
|
} /* PKE FIFO full enough */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* need to wait for another word */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_WAIT);
|
|
|
|
/* retry this instruction next clock */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
pke_code_error(struct pke_device* me, unsigned_4 pkecode)
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
/* set ER1 flag in STAT register */
|
|
|
|
PKE_REG_MASK_SET(me, STAT, ER1, 1);
|
|
|
|
|
1998-03-07 06:46:40 +08:00
|
|
|
if(! PKE_REG_MASK_GET(me, ERR, ME1))
|
|
|
|
{
|
1998-03-14 09:47:06 +08:00
|
|
|
pke_begin_interrupt_stall(me);
|
1998-03-07 06:46:40 +08:00
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_STALL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PKE_REG_MASK_SET(me, STAT, PPS, PKE_REG_STAT_PPS_IDLE);
|
|
|
|
}
|
|
|
|
|
1998-02-12 03:42:15 +08:00
|
|
|
/* advance over faulty word */
|
|
|
|
pke_pc_advance(me, 1);
|
1998-02-07 08:12:14 +08:00
|
|
|
}
|