mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-05 14:32:15 +00:00
Minor tweaks to support compilation of ether.cpp within MacOS. i.e. mostly
migrate the Ethernet driver to the MacOS side. This is enabled for DIRECT_ADDRESSING cases. I didn't want to alter much of ether.cpp (as it would have required to support that mode). Of course, in REAL_ADDRESSING mode (the default) and for debugging purposes, the old driver is still available.
This commit is contained in:
parent
9c16ab1514
commit
97726bd1e7
@ -89,6 +89,11 @@
|
||||
#define REAL_ADDRESSING 1
|
||||
#endif
|
||||
|
||||
// Always use the complete non-stubs Ethernet driver
|
||||
#if DIRECT_ADDRESSING
|
||||
#define USE_ETHER_FULL_DRIVER 1
|
||||
#endif
|
||||
|
||||
#define POWERPC_ROM 1
|
||||
|
||||
#if EMULATED_PPC
|
||||
|
@ -31,16 +31,10 @@
|
||||
#include "ether.h"
|
||||
#include "ether_defs.h"
|
||||
#include "macos_util.h"
|
||||
#include "emul_op.h"
|
||||
#include "main.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#if DIRECT_ADDRESSING
|
||||
#warning "This code is not direct addressing clean"
|
||||
#endif
|
||||
|
||||
// Packet types
|
||||
enum {
|
||||
kPktDIX = 0,
|
||||
@ -183,7 +177,7 @@ typedef mblk_t *(*allocb_ptr)(size_t size, int pri);
|
||||
static uint32 allocb_tvect = 0;
|
||||
mblk_t *allocb(size_t arg1, int arg2)
|
||||
{
|
||||
return (mblk_t *)Mac2HostAddr(CallMacOS2(allocb_ptr, allocb_tvect, arg1, arg2));
|
||||
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS2(allocb_ptr, allocb_tvect, arg1, arg2));
|
||||
}
|
||||
typedef void (*freeb_ptr)(mblk_t *);
|
||||
static uint32 freeb_tvect = 0;
|
||||
@ -201,19 +195,19 @@ typedef mblk_t *(*copyb_ptr)(mblk_t *);
|
||||
static uint32 copyb_tvect = 0;
|
||||
static inline mblk_t *copyb(mblk_t *arg1)
|
||||
{
|
||||
return (mblk_t *)Mac2HostAddr(CallMacOS1(copyb_ptr, copyb_tvect, arg1));
|
||||
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(copyb_ptr, copyb_tvect, arg1));
|
||||
}
|
||||
typedef mblk_t *(*dupmsg_ptr)(mblk_t *);
|
||||
static uint32 dupmsg_tvect = 0;
|
||||
static inline mblk_t *dupmsg(mblk_t *arg1)
|
||||
{
|
||||
return (mblk_t *)Mac2HostAddr(CallMacOS1(dupmsg_ptr, dupmsg_tvect, arg1));
|
||||
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(dupmsg_ptr, dupmsg_tvect, arg1));
|
||||
}
|
||||
typedef mblk_t *(*getq_ptr)(queue_t *);
|
||||
static uint32 getq_tvect = 0;
|
||||
static inline mblk_t *getq(queue_t *arg1)
|
||||
{
|
||||
return (mblk_t *)Mac2HostAddr(CallMacOS1(getq_ptr, getq_tvect, arg1));
|
||||
return (mblk_t *)Mac2HostAddr((uint32)CallMacOS1(getq_ptr, getq_tvect, arg1));
|
||||
}
|
||||
typedef int (*putq_ptr)(queue_t *, mblk_t *);
|
||||
static uint32 putq_tvect = 0;
|
||||
@ -285,9 +279,12 @@ typedef DLPIStream *(*mi_next_ptr_ptr)(DLPIStream *);
|
||||
static uint32 mi_next_ptr_tvect = 0;
|
||||
static inline DLPIStream *mi_next_ptr(DLPIStream *arg1)
|
||||
{
|
||||
return (DLPIStream *)Mac2HostAddr(CallMacOS1(mi_next_ptr_ptr, mi_next_ptr_tvect, arg1));
|
||||
return (DLPIStream *)Mac2HostAddr((uint32)CallMacOS1(mi_next_ptr_ptr, mi_next_ptr_tvect, arg1));
|
||||
}
|
||||
|
||||
#ifdef USE_ETHER_FULL_DRIVER
|
||||
typedef void (*ether_dispatch_packet_ptr)(uint32 p, uint32 size);
|
||||
static uint32 ether_dispatch_packet_tvect = 0;
|
||||
#endif
|
||||
|
||||
// Prototypes
|
||||
static void ether_ioctl(DLPIStream *the_stream, queue_t* q, mblk_t* mp);
|
||||
@ -311,7 +308,7 @@ static void DLPI_unit_data(DLPIStream *the_stream, queue_t *q, mblk_t *mp);
|
||||
* Initialize ethernet stream module
|
||||
*/
|
||||
|
||||
uint8 InitStreamModule(void *theID)
|
||||
static uint8 InitStreamModuleImpl(void *theID)
|
||||
{
|
||||
D(bug("InitStreamModule\n"));
|
||||
|
||||
@ -394,34 +391,73 @@ uint8 InitStreamModule(void *theID)
|
||||
if (mi_next_ptr_tvect == 0)
|
||||
return false;
|
||||
|
||||
#ifndef USE_ETHER_FULL_DRIVER
|
||||
// Initialize stream list (which might be leftover)
|
||||
dlpi_stream_list = NULL;
|
||||
|
||||
// Ask add-on for ethernet hardware address
|
||||
AO_get_ethernet_address(Host2MacAddr(hardware_address));
|
||||
#endif
|
||||
|
||||
// Yes, we're open
|
||||
ether_driver_opened = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8 InitStreamModule(void *theID)
|
||||
{
|
||||
// Common initialization code
|
||||
bool net_open = InitStreamModuleImpl(theID);
|
||||
|
||||
// Call InitStreamModule() in native side
|
||||
#ifdef BUILD_ETHER_FULL_DRIVER
|
||||
extern bool NativeInitStreamModule(void *);
|
||||
if (!NativeInitStreamModule((void *)ether_dispatch_packet))
|
||||
net_open = false;
|
||||
#endif
|
||||
|
||||
// Import functions from the Ethernet driver
|
||||
#ifdef USE_ETHER_FULL_DRIVER
|
||||
ether_dispatch_packet_tvect = (uintptr)theID;
|
||||
D(bug("ether_dispatch_packet TVECT at %08lx\n", ether_dispatch_packet_tvect));
|
||||
if (ether_dispatch_packet_tvect == 0)
|
||||
net_open = false;
|
||||
#endif
|
||||
|
||||
return net_open;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Terminate ethernet stream module
|
||||
*/
|
||||
|
||||
void TerminateStreamModule(void)
|
||||
static void TerminateStreamModuleImpl(void)
|
||||
{
|
||||
D(bug("TerminateStreamModule\n"));
|
||||
|
||||
#ifndef USE_ETHER_FULL_DRIVER
|
||||
// This happens sometimes. I don't know why.
|
||||
if (dlpi_stream_list != NULL)
|
||||
printf("FATAL: TerminateStreamModule() called, but streams still open\n");
|
||||
#endif
|
||||
|
||||
// Sorry, we're closed
|
||||
ether_driver_opened = false;
|
||||
}
|
||||
|
||||
void TerminateStreamModule(void)
|
||||
{
|
||||
// Common termination code
|
||||
TerminateStreamModuleImpl();
|
||||
|
||||
// Call TerminateStreamModule() in native side
|
||||
#ifdef BUILD_ETHER_FULL_DRIVER
|
||||
extern void NativeTerminateStreamModule(void);
|
||||
NativeTerminateStreamModule();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Open new stream
|
||||
@ -1103,6 +1139,12 @@ type_found:
|
||||
|
||||
void ether_dispatch_packet(uint32 p, uint32 size)
|
||||
{
|
||||
#ifdef USE_ETHER_FULL_DRIVER
|
||||
// Call handler from the Ethernet driver
|
||||
D(bug("ether_dispatch_packet\n"));
|
||||
D(bug(" packet data at %p, %d bytes\n", p, size));
|
||||
CallMacOS2(ether_dispatch_packet_ptr, ether_dispatch_packet_tvect, p, size);
|
||||
#else
|
||||
// Wrap packet in message block
|
||||
num_rx_packets++;
|
||||
mblk_t *mp;
|
||||
@ -1115,6 +1157,7 @@ void ether_dispatch_packet(uint32 p, uint32 size)
|
||||
D(bug("WARNING: Cannot allocate mblk for received packet\n"));
|
||||
num_rx_no_mem++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,10 @@ enum {
|
||||
NATIVE_VIDEO_INSTALL_ACCEL,
|
||||
NATIVE_VIDEO_VBL,
|
||||
NATIVE_VIDEO_DO_DRIVER_IO,
|
||||
NATIVE_ETHER_AO_GET_HWADDR,
|
||||
NATIVE_ETHER_AO_ADD_MULTI,
|
||||
NATIVE_ETHER_AO_DEL_MULTI,
|
||||
NATIVE_ETHER_AO_SEND_PACKET,
|
||||
NATIVE_ETHER_IRQ,
|
||||
NATIVE_ETHER_INIT,
|
||||
NATIVE_ETHER_TERM,
|
||||
|
@ -49,6 +49,10 @@
|
||||
#define XLM_ZERO_PAGE 0x2850 // Pointer to read-only page with all bits set to 0
|
||||
#define XLM_R13 0x2854 // Pointer to .sdata section (Linux)
|
||||
|
||||
#define XLM_ETHER_AO_GET_HWADDR 0x28b0 // Pointer to ethernet A0_get_ethernet_address() function
|
||||
#define XLM_ETHER_AO_ADD_MULTI 0x28b4 // Pointer to ethernet A0_enable_multicast() function
|
||||
#define XLM_ETHER_AO_DEL_MULTI 0x28b8 // Pointer to ethernet A0_disable_multicast() function
|
||||
#define XLM_ETHER_AO_SEND_PACKET 0x28bc // Pointer to ethernet A0_transmit_packet() function
|
||||
#define XLM_ETHER_INIT 0x28c0 // Pointer to ethernet InitStreamModule() function
|
||||
#define XLM_ETHER_TERM 0x28c4 // Pointer to ethernet TerminateStreamModule() function
|
||||
#define XLM_ETHER_OPEN 0x28c8 // Pointer to ethernet ether_open() function
|
||||
|
@ -1039,6 +1039,18 @@ void sheepshaver_cpu::execute_native_op(uint32 selector)
|
||||
case NATIVE_VIDEO_DO_DRIVER_IO:
|
||||
gpr(3) = (int32)(int16)VideoDoDriverIO(gpr(3), gpr(4), gpr(5), gpr(6), gpr(7));
|
||||
break;
|
||||
case NATIVE_ETHER_AO_GET_HWADDR:
|
||||
AO_get_ethernet_address(gpr(3));
|
||||
break;
|
||||
case NATIVE_ETHER_AO_ADD_MULTI:
|
||||
AO_enable_multicast(gpr(3));
|
||||
break;
|
||||
case NATIVE_ETHER_AO_DEL_MULTI:
|
||||
AO_disable_multicast(gpr(3));
|
||||
break;
|
||||
case NATIVE_ETHER_AO_SEND_PACKET:
|
||||
AO_transmit_packet(gpr(3));
|
||||
break;
|
||||
case NATIVE_ETHER_IRQ:
|
||||
EtherIRQ();
|
||||
break;
|
||||
|
@ -239,6 +239,12 @@ bool InitAll(void)
|
||||
WriteMacInt32(XLM_R13, (uint32)R13); // TLS register
|
||||
#endif
|
||||
#endif
|
||||
|
||||
WriteMacInt32(XLM_ETHER_AO_GET_HWADDR, NativeFunction(NATIVE_ETHER_AO_GET_HWADDR)); // Low level ethernet driver functions
|
||||
WriteMacInt32(XLM_ETHER_AO_ADD_MULTI, NativeFunction(NATIVE_ETHER_AO_ADD_MULTI));
|
||||
WriteMacInt32(XLM_ETHER_AO_DEL_MULTI, NativeFunction(NATIVE_ETHER_AO_DEL_MULTI));
|
||||
WriteMacInt32(XLM_ETHER_AO_SEND_PACKET, NativeFunction(NATIVE_ETHER_AO_SEND_PACKET));
|
||||
|
||||
WriteMacInt32(XLM_ETHER_INIT, NativeFunction(NATIVE_ETHER_INIT)); // DLPI ethernet driver functions
|
||||
WriteMacInt32(XLM_ETHER_TERM, NativeFunction(NATIVE_ETHER_TERM));
|
||||
WriteMacInt32(XLM_ETHER_OPEN, NativeFunction(NATIVE_ETHER_OPEN));
|
||||
|
@ -60,7 +60,11 @@ static const uint8 video_driver[] = {
|
||||
|
||||
// Ethernet driver stub
|
||||
static const uint8 ethernet_driver[] = {
|
||||
#ifdef USE_ETHER_FULL_DRIVER
|
||||
#include "EthernetDriverFull.i"
|
||||
#else
|
||||
#include "EthernetDriverStub.i"
|
||||
#endif
|
||||
};
|
||||
|
||||
// Helper for RegEntryID
|
||||
@ -333,8 +337,6 @@ void DoPatchNameRegistry(void)
|
||||
}
|
||||
|
||||
// Create "ethernet"
|
||||
// XXX the current ethernet driver is not direct addressing clean
|
||||
#if REAL_ADDRESSING
|
||||
SheepRegEntryID ethernet;
|
||||
if (!RegistryCStrEntryCreate(device_tree.addr(), "ethernet", ethernet.addr())) {
|
||||
RegistryPropertyCreateStr(ethernet.addr(), "AAPL,connector", "ethernet");
|
||||
@ -345,7 +347,6 @@ void DoPatchNameRegistry(void)
|
||||
// local-mac-address
|
||||
// max-frame-size 2048
|
||||
}
|
||||
#endif
|
||||
}
|
||||
D(bug("done.\n"));
|
||||
}
|
||||
|
@ -62,6 +62,10 @@ uint32 NativeOpcode(int selector)
|
||||
case NATIVE_VIDEO_INSTALL_ACCEL:
|
||||
case NATIVE_VIDEO_VBL:
|
||||
case NATIVE_VIDEO_DO_DRIVER_IO:
|
||||
case NATIVE_ETHER_AO_GET_HWADDR:
|
||||
case NATIVE_ETHER_AO_ADD_MULTI:
|
||||
case NATIVE_ETHER_AO_DEL_MULTI:
|
||||
case NATIVE_ETHER_AO_SEND_PACKET:
|
||||
case NATIVE_ETHER_IRQ:
|
||||
case NATIVE_ETHER_INIT:
|
||||
case NATIVE_ETHER_TERM:
|
||||
@ -236,6 +240,10 @@ bool ThunksInit(void)
|
||||
DEFINE_NATIVE_OP(NATIVE_VIDEO_INSTALL_ACCEL, VideoInstallAccel);
|
||||
DEFINE_NATIVE_OP(NATIVE_VIDEO_VBL, VideoVBL);
|
||||
DEFINE_NATIVE_OP(NATIVE_VIDEO_DO_DRIVER_IO, VideoDoDriverIO);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_GET_HWADDR, AO_get_ethernet_address);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_ADD_MULTI, AO_enable_multicast);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_DEL_MULTI, AO_disable_multicast);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_AO_SENDPACKET, AO_transmit_packet);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_IRQ, EtherIRQ);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_INIT, InitStreamModule);
|
||||
DEFINE_NATIVE_OP(NATIVE_ETHER_TERM, TerminateStreamModule);
|
||||
|
Loading…
Reference in New Issue
Block a user