?? tm1stuff.c
字號:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995-1998 by Philips Semiconductors. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | Philips Semiconductors. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*
*
* Module name : TM1stuff.c 1.34
*
* Last update : 11:02:48 - 98/07/10
*
* Description :
*
* This module provides functions to download and run executables on
* a TM-1000 with a Mac as host
*
* Revision :
*/
/*-----------------------------includes-------------------------------------*/
#include <stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <Files.h>
#include <Folders.h>
#include <Script.h>
#include <PCI.h>
#include <DriverServices.h>
#include <Types.h>
#include <NameRegistry.h>
#include "TMDownLoader.h"
#include "mmio.h"
#include "TM1stuff.h"
#include "tmtypes.h"
#include "OpenDll.h"
#include "TM1IF.h"
#include "TMDownLoader.h"
/*-----------------------------defines---------------------------------------*/
/* name of the preference file */
#define C_PREFERENCE_FILE "TriMedia Preferences"
#ifdef _MPW
#define NL "\n"
#else
#define NL "\r"
#endif
#define PREFERENCES "frequency=100000000" NL \
"dllpath=" NL \
"board=pci1131,1" NL
#define P_PREFERENCE_FILE "\p" C_PREFERENCE_FILE
/* number of entries in table with shared memory pointers */
#define SH_MEM_SLOTS 16
#define SET_RST_MASK 0x00000800
#define CLEAR_RST_MASK 0x00000400
#define NUM_OF_SERVERS 1
/* PCI Configuration register offsets */
#define CONFIG_COMMAND 0x04
#define CONFIG_STATUS 0x06
#define CONFIG_LATENCY 0x0D
#define CONFIG_BASE0_ADDRESS 0x10
#define CONFIG_BASE1_ADDRESS 0x14
#define MAX_STDIN_LINE_LENGTH 1024
/*-------------------------------types----------------------------------------*/
/* table with shared memory pointers */
typedef struct IdPtr {
IOPreparationID id;
void* ptr;
} IdPtr;
TriMediaInfo TMInfo[MAX_TM]; /* Info block for each TriMedia. */
UInt TM_frequency;
int NumberOfTMs = 0; /* Total TriMedia's found in system. */
int nodesLoaded; /* Number of TriMedia nodes loaded with code. */
volatile UInt32 *_MMIO_bases[MAX_TM];
/*-----------------------------GLOBALS----------------------------------------*/
/* location of the communication buffer, so far 2 4-byte pointers */
extern volatile Address *_HostCall_commvar;
char stdin_file[FILENAME_MAX]; /* stdin file. Console if empty. */
char stdout_file[FILENAME_MAX]; /* stdout file. Console if empty. */
char stderr_file[FILENAME_MAX]; /* stderr file. Console if empty. */
int stdin_fd = STDIN_HANDLE;
int stdout_fd = STDOUT_HANDLE;
int stderr_fd = STDERR_HANDLE;
/*-----------------------------globals-this-file------------------------------*/
/* _HostCall_commvar location as seen from the target (when VM is on) */
static unsigned long HostCall_commvar_target;
static IdPtr ShMemList[SH_MEM_SLOTS] = { 0 };
static Bool CommBufferClean = False;
static Endian object_endian;
/*------------------------------local-prototypes------------------------------*/
void InitEmber(RegEntryID theEntryID);
OSStatus GetBaseAddress( RegEntryID *pRegID, UInt32 *pBaseRegAddress, UInt8 offsetValue, UInt32 *pSpaceAllocated );
OSStatus GetDeviceProperty( RegEntryID *pRegID, RegPropertyName *pPropertyName, RegPropertyValue *pPropertyValue, RegPropertyValueSize *pPropertySize );
OSStatus DisposeProperty( RegPropertyValue propertyValue );
OSStatus FindPropertyWithValue(const RegPropertyName *propertyName, const void *propertyValue,
const RegPropertyValueSize propertySize, RegEntryID *foundEntry);
/*------------------------------functions-------------------------------------*/
Boolean TMRunning(void)
{
int i;
for (i = 0; i < nodesLoaded; i++)
{
if (TMInfo[i].TM_running)
return true;
}
return false;
}
//===================================================================
//===================================================================
Boolean ResetTM(Int32 node)
{
// clear and mask interrupts
MMIO_M(node,IMASK) = 0;
MMIO_M(node,ICLEAR) = 0xffffffff;
// Ensure that BIU_CTL shows that CPU is now in reset
// Writing a 0 to CR bit is a nop
MMIO_M(node,BIU_CTL) &= ~CLEAR_RST_MASK;
// reset BIU
MMIO_M(node,BIU_CTL) |= SET_RST_MASK;
MMIO_M(node,BIU_CTL) &= ~SET_RST_MASK;
// reset the peripherals
MMIO_M(node,AO_CTL) = 0x80000000;
MMIO_M(node,AO_FREQ) = 0x0;
MMIO_M(node,AI_CTL) = 0x80000000;
MMIO_M(node,AI_FREQ) = 0x0;
MMIO_M(node,VI_CTL) = 0x00080000;
MMIO_M(node,VI_CLOCK) = 0x0;
MMIO_M(node,VO_CTL) = 0x80000000;
MMIO_M(node,VO_CLOCK) = 0x0;
MMIO_M(node,SSI_CTL) = 0xc0000000;
// Roy does the following 10 times...oh, boy
MMIO_M(node,ICP_SR) = 0x80;
MMIO_M(node,IIC_CTL) = 0;
MMIO_M(node,VLD_COMMAND) = 0x00000401;
// reset JTAG
MMIO_M(node,JTAG_DATA_IN) = 0;
MMIO_M(node,JTAG_DATA_OUT) = 0;
MMIO_M(node,JTAG_CTL) = 0x4;
// reset breakpoints, I$ lock and ??
MMIO_M(node,BICTL) = 0;
MMIO_M(node,IC_LOCK_CTL) = 0;
MMIO_M(node,ARB_BW_CTL) = 0;
MMIO_M(node,ARB_RAISE) = 0;
// reset timers
MMIO_M(node,TIMER1_TCTL) = 0xfffffffe;
MMIO_M(node,TIMER2_TCTL) = 0xfffffffe;
MMIO_M(node,TIMER3_TCTL) = 0xfffffffe;
MMIO_M(node,SYSTIMER_TCTL) = 0xfffffffe;
CommBufferClean = False;
return true;
}
//===================================================================
//===================================================================
//
Boolean
InitTM( Boolean reinitialize , Int32 node)
{
OSErr theErr;
UInt16 data16;
UInt32 addr;
int i;
OSStatus osErr;
RegEntryID *pNodeID;
pNodeID = &TMInfo[node].NodeID;
if ( reinitialize ) {
osErr = ExpMgrConfigWriteByte(pNodeID, (LogicalAddress) (CONFIG_LATENCY), TMInfo[node].ConfigHeader[CONFIG_LATENCY]);
if (osErr != noErr) {
printf("** Error: Could not write to PCI configuration\n");
return false;
}
for ( i = 0; i < 8; i++ ) {
osErr = ExpMgrConfigWriteByte(pNodeID, (LogicalAddress) (CONFIG_BASE0_ADDRESS + i), TMInfo[node].ConfigHeader[CONFIG_BASE0_ADDRESS + i]);
if (osErr != noErr) {
printf("** Error: Could not write to PCI configuration\n");
return false;
}
}
osErr = ExpMgrConfigWriteByte(pNodeID, (LogicalAddress) (CONFIG_COMMAND), 0x04);
if (osErr != noErr) {
printf("** Error: Could not write to PCI configuration\n");
return false;
}
}
// first thing to do is to make sure that memory access is enabled
// this is the PCI command register
addr = CONFIG_COMMAND;
theErr = ExpMgrConfigReadWord(pNodeID, (LogicalAddress)addr, &data16);
if (theErr != noErr) {
printf("** Error: Could not read from PCI configuration (1)\n");
return false;
}
// set the memory space access enable
data16 |= 1<<1;
theErr = ExpMgrConfigWriteWord(pNodeID, (LogicalAddress)addr, (UInt16)data16);
if (theErr != noErr) {
printf("** Error: Could not write to PCI configuration\n");
return false;
}
MMIO_M(node,BIU_CTL) = 0x00000202;
MMIO_M(node,MMIO_BASE) = TMInfo[node].mmio_base;
MMIO_M(node,DRAM_BASE) = TMInfo[node].sdram_base;
MMIO_M(node,DRAM_LIMIT) = TMInfo[node].sdram_base + TMInfo[node].sdram_size;
// TMInfo[node].frequency = TM_frequency; ???
TMInfo[node].TM_running = false;
i = 0;
osErr = noErr;
while ((osErr == noErr) & (i < 64))
{
osErr = ExpMgrConfigReadByte(pNodeID, (LogicalAddress) i, &TMInfo[node].ConfigHeader[i]);
i++;
}
if (osErr != noErr)
{
printf("** Error: Could not read from PCI configuration (2)\n");
return false;
}
else
return true;
}
//===================================================================
static int exitf(UInt32 node_id, Int32 status)
{
TMInfo[node_id].Exit_Status = status;
TMInfo[node_id].TM_running = false;
if (!TMRunning())
TM1IF_term();
return 0;
}
static int my_fstat( int fildes, struct stat *buf )
{
if ( fildes == STDIN_HANDLE
|| fildes == STDOUT_HANDLE
|| fildes == STDERR_HANDLE
)
{
// for some strange reason, MW's fstat doesn't handle
// stdin, stdout & stderr, so we have to fill it out
// explicitly
buf->st_dev = 0;
buf->st_ino = fildes;
buf->st_mode = 0020000;
buf->st_nlink = 1;
buf->st_uid = getuid();
buf->st_gid = getgid();
buf->st_rdev = 0;
buf->st_size = 4096;
buf->st_atime = time(0L);
buf->st_mtime = time(0L);
buf->st_ctime = time(0L);
buf->st_blksize = 4096;
buf->st_blocks = 1;
return 0;
} else {
int result= fstat(fildes,buf);
buf->st_mode <<=4;
return result;
}
}
static int my_stat( char *name, struct stat *buf );
static int my_stat( char *name, struct stat *buf )
{
int result;
if (name == NULL)
return -1;
result = stat(name,buf);
buf->st_mode <<=4;
return result;
}
static int my_read( int fd, char* buf, int n );
static int my_read( int fd, char* buf, int n )
{
int result;
static char line[MAX_STDIN_LINE_LENGTH];
static char *linep = NULL;
if (fd == STDIN_HANDLE && stdin_fd != STDIN_HANDLE)
fd = stdin_fd;
if ( fd == STDIN_HANDLE ) {
int i;
for (i=0; i<n; i++) {
if (linep == NULL) {
char * check;
check = fgets(line, MAX_STDIN_LINE_LENGTH-1, stdin);
if (check == NULL) {
linep = NULL;
return 0;
}
linep = line;
}
if (*linep == '\n') {
buf[i] = *linep;
linep = NULL;
return i+1;
} else {
buf[i] = *linep++;
}
}
return n;
} else {
result= read(fd,buf,n);
}
return result;
}
static int my_write( int fd, char* buf, int n );
static int my_write( int fd, char* buf, int n )
{
if (fd == STDOUT_HANDLE && stdout_fd != STDOUT_HANDLE)
fd = stdout_fd;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -