diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/QemuMacDrivers/shared | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/QemuMacDrivers/shared')
-rw-r--r-- | roms/QemuMacDrivers/shared/LinuxOSI.h | 92 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/LinuxOSI.s | 370 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/LinuxOSIDefs.s | 76 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/MacDriverUtils.c | 1 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/MacDriverUtils.h | 1 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/MakeFunction.s | 29 | ||||
-rw-r--r-- | roms/QemuMacDrivers/shared/logger.h | 32 | ||||
-rwxr-xr-x | roms/QemuMacDrivers/shared/vsprintf.c | 343 |
8 files changed, 944 insertions, 0 deletions
diff --git a/roms/QemuMacDrivers/shared/LinuxOSI.h b/roms/QemuMacDrivers/shared/LinuxOSI.h new file mode 100644 index 000000000..628ab7145 --- /dev/null +++ b/roms/QemuMacDrivers/shared/LinuxOSI.h @@ -0,0 +1,92 @@ +/* + * <LinuxOSI.h> + * + * Copyright (C) 1999, 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _LINUX_OSI_H +#define _LINUX_OSI_H + +#include <Types.h> + +#define MOL_GESTALT_SELECTOR 'MOL-' +//#define MOL_GESTALT_VALUE '-MOL' /* old value, osi_interrupts used */ +#define MOL_GESTALT_VALUE '1MOL' + +extern int OSI_IRQTest( int cmd, int param ); + +/* Misc */ +extern int MOLIsRunning( void ); +extern void OSI_Debugger( int debugnum ); + +extern UInt32 OSI_GetTime( void ); +extern void OSI_PutC( char ch ); +extern void OSI_CMountDrvVol( void ); + +/* Mouse Driver */ +struct osi_mouse; +extern int OSI_GetMouse( struct osi_mouse *pb ); +extern int OSI_MouseCntrl( int cmd ); +extern int OSI_MouseCntrl1( int cmd, int param ); +extern int OSI_MouseAckIRQ( void ); + +/* Video Driver */ +extern int OSI_SetVMode_( int modeID, int depthMode ); +extern int OSI_GetVModeInfo_( int modeID, int depthMode, void *ret ); +extern int OSI_SetVPowerState( int powerState ); + +extern int OSI_GetColor( int index ); +extern int OSI_SetColor( int index, int col ); +extern int OSI_VideoAckIRQ( int *events ); +extern int OSI_VideoCntrl( int cmd ); +extern int OSI_VideoCntrl1( int cmd, int param ); + +/* Ethernet Driver */ +extern int OSI_EnetOpen( UInt32 osi_id ); +extern void OSI_EnetClose( UInt32 id ); +extern UInt32 OSI_EnetGetEthAddress( UInt32 id, UInt32 eth_address_phys_ptr ); +extern UInt32 OSI_EnetGetStatus( UInt32 id ); +extern UInt32 OSI_EnetControl( UInt32 id, UInt32 command ); +extern UInt32 OSI_EnetControl1( UInt32 id, UInt32 command, UInt32 param ); +extern int OSI_EnetGetPacket( UInt32 id, UInt32 packet ); +extern int OSI_EnetSendPacket( UInt32 id, UInt32 packet, UInt32 size ); +extern UInt32 OSI_EnetAddMulticast( UInt32 id, UInt32 eth_address_phys_ptr ); +extern UInt32 OSI_EnetDelMulticast( UInt32 id, UInt32 eth_address_phys_ptr ); + +/* Sound Driver */ +extern int OSI_SoundWrite( UInt32 phys_buf, int count, int resume ); +extern long OSI_SoundSetVolume( long hwVol, long speakerVol, int hwMute ); +extern int OSI_SoundIrqAck( void ); +extern int OSI_SoundCntl2( int cmd, int parm, int param2 ); +extern int OSI_SoundCntl1( int cmd, int parm ); +extern int OSI_SoundCntl( int cmd ); + +/* Interrupt management */ +extern UInt32 OSI_RegisterIRQ( UInt32 reg_word, UInt32 appl_int ); +extern void OSI_UnregisterIRQ( UInt32 irq_cookie ); +extern int OSI_PollIRQ( UInt32 irq_cookie ); +extern int OSI_AckIRQ( UInt32 irq_cookie ); +extern int OSI_EnableIRQ( UInt32 irq_cookie, int enable ); + +/* ABlk driver */ +struct ablk_disk_info; +extern int OSI_ABlkRingSetup( int channel, UInt32 mphys, int nel ); +extern int OSI_ABlkDiskInfo( int channel, int index, struct ablk_disk_info *info ); +extern int OSI_ABlkIRQAck( int channel, int *req_cnt, int *active, int *events ); +extern int OSI_ABlkCntrl( int channel, int cmd ); +extern int OSI_ABlkCntrl1( int channel, int cmd, int arg ); +extern int OSI_ABlkKick( int channel ); +extern int OSI_ABlkSyncRead( int channel, int unit, int blk, UInt32 physbuf, int size ); +extern int OSI_ABlkSyncWrite( int channel, int unit, int blk, UInt32 physbuf, int size ); + +/* SCSI */ +extern int OSI_SCSISubmit( int req_mphys ); +extern int OSI_SCSIAck( void ); +extern int OSI_SCSIControl( int cmd, int param ); + +#endif diff --git a/roms/QemuMacDrivers/shared/LinuxOSI.s b/roms/QemuMacDrivers/shared/LinuxOSI.s new file mode 100644 index 000000000..487683416 --- /dev/null +++ b/roms/QemuMacDrivers/shared/LinuxOSI.s @@ -0,0 +1,370 @@ +;####################################################### +;# +;# Linux Interace Stub +;# +;####################################################### + + INCLUDE 'MakeFunction.s' + INCLUDE 'LinuxOSIDefs.s' + + +;####################################################### +; int OSI_IRQTest( int cmd, int param ) +;####################################################### + + MakeFunction OSI_IRQTest + mr r6,r3 + mr r7,r4 + osi_call OSI_IRQTEST + blr + + +;####################################################### +; void OSI_PutC( char ch ) +;####################################################### + + MakeFunction OSI_PutC + mr r6,r3 + OSI_CALL( OSI_LOG_PUTC ) + blr + +;####################################################### +; void OSI_Debugger( int debugnum ) +;####################################################### + + MakeFunction OSI_Debugger + mr r6,r3 + osi_call OSI_DEBUGGER + blr + +;####################################################### +; ulong OSI_GetTime( void ) +;####################################################### + + MakeFunction OSI_GetTime + osi_call OSI_GET_DATE + blr + +;####################################################### +; void OSI_CMountDrvVol( void ) +;####################################################### + + MakeFunction OSI_CMountDrvVol + osi_call OSI_CMOUNT_DRV_VOL + blr + + +;####################################################### +; int OSI_ABlkDiskInfo( int channel, int unit, ablk_disk_info_t *ret ) +; int OSI_ABlkRingSetup( int channel, ulong mphys, int num_el ) +; int OSI_ABlkCntrl( int channel, int cmd ) +; int OSI_ABlkCntrl( int channel, int cmd, int param ) +; int OSI_ABlkKick( int channel ) +; int OSI_ABlkIRQAck( int channel, int *req_count, int *active, int *event ) +; int OSI_ABlkSyncRead( int channel, int unit, int blk, ulong mphys, int size ) +; int OSI_ABlkSyncWrite( int channel, int unit, int blk, ulong mphys, int size ) +;####################################################### + + MakeFunction OSI_ABlkDiskInfo + mr r6,r3 + mr r7,r4 + mr r10,r5 ; save pointer in r10 + osi_call OSI_ABLK_DISK_INFO + stw r4,0(r10) ; 16 byte return info + stw r5,4(r10) + stw r6,8(r10) + stw r7,12(r10) + blr + + MakeFunction OSI_ABlkRingSetup + mr r6,r3 + mr r7,r4 + mr r8,r5 + osi_call OSI_ABLK_RING_SETUP + blr + + MakeFunction OSI_ABlkCntrl + mr r6,r3 + mr r7,r4 + osi_call OSI_ABLK_CNTRL + blr + + MakeFunction OSI_ABlkCntrl1 + mr r6,r3 + mr r7,r4 + mr r8,r5 + osi_call OSI_ABLK_CNTRL + blr + + MakeFunction OSI_ABlkKick + + mr r6,r3 + osi_call OSI_ABLK_KICK + blr + + MakeFunction OSI_ABlkIRQAck + mr r8,r4 ; save r4 in r8 + mr r9,r5 ; save r5 in r9 + mr r10,r6 ; save r6 in r10 + mr r6,r3 + osi_call OSI_ABLK_IRQ_ACK + stw r4,0(r8) ; return req_count + stw r5,0(r9) ; return active + stw r6,0(r10) ; return event + blr + + MakeFunction OSI_ABlkSyncRead + mr r10,r7 + mr r9,r6 + mr r8,r5 + mr r7,r4 + mr r6,r3 + osi_call OSI_ABLK_SYNC_READ + blr + + MakeFunction OSI_ABlkSyncWrite + mr r10,r7 + mr r9,r6 + mr r8,r5 + mr r7,r4 + mr r6,r3 + osi_call OSI_ABLK_SYNC_WRITE + blr + + +;####################################################### +; int OSI_MouseAckIRQ( void ) +; int OSI_GetMouse( osi_mouse_t *pb ) +; int OSI_MouseCntrl( int cmd ) +; int OSI_MouseCntrl1( int cmd, int param ) +;####################################################### + + MakeFunction OSI_MouseAckIRQ + osi_call OSI_MOUSE_ACK_IRQ + blr + + MakeFunction OSI_GetMouse + mr r10,r3 + osi_call OSI_GET_MOUSE + stw r4,0(r10) + stw r5,4(r10) + stw r6,8(r10) + stw r7,12(r10) + stw r8,16(r10) + blr + + MakeFunction OSI_MouseCntrl + mr r6,r3 + osi_call OSI_MOUSE_CNTRL + blr + + MakeFunction OSI_MouseCntrl1 + mr r6,r3 + mr r7,r4 + osi_call OSI_MOUSE_CNTRL + blr + + +;####################################################### +; int OSI_SetVMode_( int modeID, int depthMode ) +; int OSI_GetVModeInfo_( int modeID, int depthMode, osi_get_vmode_info_t *ret ) +; int OSI_SetVPowerState( int powerState ) +; int OSI_GetColor( int index ) +; int OSI_SetColor( int index, int color ) +; int OSI_VideoAckIRQ( int *events ) +; int OSI_VideoCntrl( int cmd ) +; int OSI_VideoCntrl1( int cmd, int param ) +;####################################################### + + MakeFunction OSI_SetVMode_ + mr r6,r3 + mr r7,r4 + osi_call OSI_SET_VMODE + blr + + MakeFunction OSI_GetVModeInfo_ + mr r6,r3 + mr r7,r4 + mr r10,r5 + osi_call OSI_GET_VMODE_INFO + stw r4,0(r10) + stw r5,4(r10) + stw r6,8(r10) + stw r7,12(r10) + stw r8,16(r10) + stw r9,20(r10) + blr + + MakeFunction OSI_SetVPowerState + mr r6,r3 + osi_call OSI_SET_VIDEO_POWER + blr + + MakeFunction OSI_GetColor + mr r6,r3 + osi_call OSI_GET_COLOR + blr + + MakeFunction OSI_SetColor + mr r6,r3 + mr r7,r4 + osi_call OSI_SET_COLOR + blr + + MakeFunction OSI_VideoAckIRQ + mr r10,r3 ; save pointer in r10 + osi_call OSI_VIDEO_ACK_IRQ + stw r4,0(r10) ; events return in r4 + blr + + MakeFunction OSI_VideoCntrl + mr r6,r3 + osi_call OSI_VIDEO_CNTRL + blr + + MakeFunction OSI_VideoCntrl1 + mr r6,r3 + mr r7,r4 + osi_call OSI_VIDEO_CNTRL + blr + + +;####################################################### +; void OSI_EnetClose( UInt32 id ) +; UInt32 OSI_EnetOpen( UInt32 interruptNumber ) +; UInt32 OSI_EnetGetEthAddress( UInt32 id, UInt32 eth_address_phys_ptr ) +; UInt32 OSI_EnetGetStatus( UInt32 id ) +; UInt32 OSI_EnetControl1( UInt32 id, UInt32 command, int param ) +; UInt32 OSI_EnetControl( UInt32 id, UInt32 command ) +; int OSI_EnetGetPacket( UInt32 id, UInt32 packet ) +; int OSI_EnetSendPacket( UInt32 id, UInt32 packet, UInt32 size ) +; UInt32 OSI_EnetAddMulticast( UInt32 id, UInt32 eth_address_phys_ptr ) +; UInt32 OSI_EnetDelMulticast( UInt32 id, UInt32 eth_address_phys_ptr ) +;####################################################### + + MakeFunction OSI_EnetOpen + mr r6,r3 + osi_call OSI_ENET_OPEN + blr + + MakeFunction OSI_EnetClose + mr r6,r3 + osi_call OSI_ENET_CLOSE + blr + + MakeFunction OSI_EnetGetEthAddress + mr r6,r3 + mr r7,r4 + osi_call OSI_ENET_GET_ADDR + blr + + MakeFunction OSI_EnetGetStatus + mr r6,r3 + osi_call OSI_ENET_GET_STATUS + blr + + MakeFunction OSI_EnetControl + mr r6,r3 + mr r7,r4 + osi_call OSI_ENET_CONTROL + blr + + MakeFunction OSI_EnetControl1 + mr r6,r3 + mr r7,r4 + mr r8,r5 + osi_call OSI_ENET_CONTROL + blr + + MakeFunction OSI_EnetGetPacket + mr r6,r3 + mr r7,r4 + osi_call OSI_ENET_GET_PACKET + blr + + MakeFunction OSI_EnetSendPacket + mr r6,r3 + mr r7,r4 + mr r8,r5 + osi_call OSI_ENET_SEND_PACKET + blr + + MakeFunction OSI_EnetAddMulticast + mr r6,r3 + mr r7,r4 + osi_call OSI_ENET_ADD_MULTI + blr + + MakeFunction OSI_EnetDelMulticast + mr r6,r3 + mr r7,r4 + osi_call OSI_ENET_DEL_MULTI + blr + + +;####################################################### +; int OSI_SoundWrite( UInt32 phys_buf, int size, int restart ) +; int OSI_SoundCntl2( int cmd, int param, int param2 ) +; int OSI_SoundCntl1( int cmd, int param ) +; int OSI_SoundCntl( int cmd ) +; int OSI_SoundSetVolume( int hwVol, int speakerVol, int hwMute ) +; int OSI_SoundIrqAck( void ) +;####################################################### + + MakeFunction OSI_SoundWrite + mr r6,r3 + mr r7,r4 + mr r8,r5 + OSI_CALL( OSI_SOUND_WRITE ) + blr + + MakeFunction OSI_SoundCntl2 + mr r8,r5 + mr r7,r4 + mr r6,r3 + OSI_CALL( OSI_SOUND_CNTL ) + blr + + MakeFunction OSI_SoundCntl1 + mr r7,r4 + mr r6,r3 + OSI_CALL( OSI_SOUND_CNTL ) + blr + + MakeFunction OSI_SoundCntl + mr r6,r3 + OSI_CALL( OSI_SOUND_CNTL ) + blr + + MakeFunction OSI_SoundSetVolume + mr r6,r3 + mr r7,r4 + mr r8,r5 + OSI_CALL( OSI_SOUND_SET_VOLUME ) + blr + + MakeFunction OSI_SoundIrqAck + OSI_CALL( OSI_SOUND_IRQ_ACK ) + blr + + +;####################################################### +; int OSI_SCSIControl( int sel, int param ) +; int OSI_SCSISubmit( int req_mphys ) +; int OSI_SCSIAck( void ) +;####################################################### + + MakeFunction OSI_SCSIControl + mr r7,r4 + mr r6,r3 + OSI_CALL( OSI_SCSI_CNTRL ) + blr + + MakeFunction OSI_SCSISubmit + mr r6,r3 + OSI_CALL( OSI_SCSI_SUBMIT ) + blr + + MakeFunction OSI_SCSIAck + OSI_CALL( OSI_SCSI_ACK ) + blr diff --git a/roms/QemuMacDrivers/shared/LinuxOSIDefs.s b/roms/QemuMacDrivers/shared/LinuxOSIDefs.s new file mode 100644 index 000000000..d39d1954a --- /dev/null +++ b/roms/QemuMacDrivers/shared/LinuxOSIDefs.s @@ -0,0 +1,76 @@ +; +; Linux interface magic +; + +OSI_SC_MAGIC_R3: set 0x113724FA +OSI_SC_MAGIC_R4: set 0x77810F9B + + MACRO + osi_call &selector + li r3,0x24FA + addis r3,r3,0x1137 + li r4,0x0F9B + addis r4,r4,0x7781 + li r5,&selector + sc + ENDM + +; +; Selectors +; + +OSI_DEBUGGER set 1 +OSI_CMOUNT_DRV_VOL set 4 + +OSI_MOUSE_CNTRL set 8 +OSI_GET_DATE set 9 + +OSI_ENET_OPEN set 10 +OSI_ENET_CLOSE set 11 +OSI_ENET_GET_ADDR set 12 +OSI_ENET_GET_STATUS set 13 +OSI_ENET_CONTROL set 14 +OSI_ENET_ADD_MULTI set 16 +OSI_ENET_DEL_MULTI set 17 +OSI_ENET_GET_PACKET set 18 +OSI_ENET_SEND_PACKET set 19 + +OSI_SCSI_CNTRL set 23 +OSI_SCSI_SUBMIT set 24 +OSI_SCSI_ACK set 25 + +OSI_GET_MOUSE set 26 ; void -- r4-r7 mouse data, r3 status +OSI_MOUSE_ACK_IRQ set 27 + +OSI_SET_VMODE set 28 ; vmode, depthmode -- err +OSI_GET_VMODE_INFO set 29 ; int modeID -- r3-status, r4-r7 osi_get_next_vmode_t +OSI_GET_MOUSE_DPI set 30 ; -- mouse dpi + +OSI_SET_VIDEO_POWER set 31 ; set VESA DPMS (Energy Star) state on console-video + +OSI_SOUND_WRITE set 33 +OSI_SOUND_SET_VOLUME set 35 +OSI_SOUND_CNTL set 36 + +OSI_VIDEO_ACK_IRQ set 38 +OSI_VIDEO_CNTRL set 39 + +OSI_SOUND_IRQ_ACK set 40 +OSI_SOUND_START_STOP set 41 + +OSI_REGISTER_IRQ set 42 ; first_word_of_reg_property -- irq_cookie + +OSI_LOG_PUTC set 47 + +OSI_SET_COLOR set 59 +OSI_GET_COLOR set 64 + +OSI_IRQTEST set 65 + +OSI_ABLK_RING_SETUP set 79 +OSI_ABLK_CNTRL set 80 +OSI_ABLK_DISK_INFO set 81 +OSI_ABLK_KICK set 82 +OSI_ABLK_IRQ_ACK set 83 +OSI_ABLK_SYNC_READ set 84 +OSI_ABLK_SYNC_WRITE set 85 diff --git a/roms/QemuMacDrivers/shared/MacDriverUtils.c b/roms/QemuMacDrivers/shared/MacDriverUtils.c new file mode 100644 index 000000000..3537dad0d --- /dev/null +++ b/roms/QemuMacDrivers/shared/MacDriverUtils.c @@ -0,0 +1 @@ +/*
* Various utilities for writing a MacOS "ndrv" driver, such as device-tree
* helpers. These replace the various Apple sample codes whose licences
* are dubious and probably not suitable for GPL code
*/
//#include "VideoDriverPrivate.h"
//#include "VideoDriverPrototypes.h"
#include "logger.h"
#include "MacDriverUtils.h"
/* Simplified DT properties accessors */
void *DTGetProp(RegEntryIDPtr dtNode,
RegPropertyNamePtr name,
RegPropertyValueSize *outSize)
{
OSStatus err;
RegPropertyValue *v;
if (!outSize)
return NULL;
/* Grab size so we can allocate some memory */
err = RegistryPropertyGetSize(dtNode, name, outSize);
if (err)
return NULL;
/* Allocate */
v = PoolAllocateResident(*outSize, FALSE);
if (!v)
return NULL;
err = RegistryPropertyGet(dtNode, name, v, outSize);
if (err)
return NULL;
return v;
}
void DTFreeProp(void *v)
{
if (v)
PoolDeallocate(v);
}
/* Find a BAR logical address and size */
LogicalAddress GetDeviceBARAddress(RegEntryIDPtr dtNode,
PCIRegisterNumber barOffset,
ByteCount *size,
Boolean *isIO)
{
RegPropertyValueSize aasize, lasize;
LogicalAddress *las = NULL;
PCIAssignedAddress *aas = NULL;
LogicalAddress result = 0;
UInt32 i;
/* First grab assigned-addresses to find the BAR */
aas = DTGetProp(dtNode, kPCIAssignedAddressProperty, &aasize);
if (!aas)
return NULL;
aasize /= sizeof(*aas);
/* Then grab AAPL,addresses to get the corresponding logical addresses */
las = DTGetProp(dtNode, kAAPLDeviceLogicalAddress, &lasize);
if (!las)
goto bail;
lasize /= sizeof(LogicalAddress);
/* Lookup BAR */
for (i = 0; i < aasize; i++) {
struct PCIAssignedAddress *aa = aas + i;
/* Skip config space */
if (GetPCIAddressSpaceType(aa) == kPCIConfigSpace)
continue;
/* Check BAR offset */
if (GetPCIRegisterNumber(aa) != barOffset)
continue;
/* Found it, check that it was assigned */
if (aa->size.hi == 0 && aa->size.lo == 0) {
lprintf("BAR %02x not assigned !\n");
goto bail;
}
/* Check we have a logical for it */
if (i >= lasize) {
lprintf("BAR %02x missing AAPL,address property !\n");
goto bail;
}
/* We don't do 64-bit, sorry... */
if (aa->size.hi) {
lprintf("BAR %02x too big !\n");
goto bail;
}
/* Gotcha ! */
if (size)
*size = aa->size.lo;
if (isIO)
*isIO = GetPCIAddressSpaceType(aa) == kPCIIOSpace;
result = las[i];
break;
}
bail:
DTFreeProp(aas);
DTFreeProp(las);
return result;
}
/* PCI "Command" config register address */
#define kPCIConfigCommandAddress 0x04
#define cwCommandEnableMemorySpace 0x0002
/* Enable access to PCI memory space */
OSStatus EnablePCIMemorySpace(RegEntryIDPtr dtNode)
{
OSStatus status;
UInt16 cmd;
lprintf("Reading cmd word...\n");
status = ExpMgrConfigReadWord(dtNode, (LogicalAddress)kPCIConfigCommandAddress, &cmd);
if( status )
return status;
lprintf("cmad word is: %04x, writing update...\n", cmd);
cmd |= cwCommandEnableMemorySpace;
return ExpMgrConfigWriteWord(dtNode, (LogicalAddress)kPCIConfigCommandAddress, cmd);
}
OSStatus SetupPCIInterrupt(RegEntryID *dtNode, IRQInfo *info,
InterruptHandler handler, void *refCon)
{
ISTProperty *ist;
RegPropertyValueSize istSize;
OSStatus err;
ist = DTGetProp(dtNode, kISTPropertyName, &istSize);
if (!ist) {
lprintf("SetupPCIInterrupt: No %s property\n", kISTPropertyName);
return paramErr;
}
info->interruptSetMember = (*ist)[kISTChipInterruptSource];
DTFreeProp(ist);
err = GetInterruptFunctions(info->interruptSetMember.setID,
info->interruptSetMember.member,
&info->refCon,
&info->handlerFunction,
&info->enableFunction,
&info->disableFunction);
if (err) {
lprintf("SetupPCIInterrupt: Error %d getting interrupt functions\n");
return err;
}
err = InstallInterruptFunctions(info->interruptSetMember.setID,
info->interruptSetMember.member,
refCon, handler, NULL, NULL);
if (err) {
lprintf("SetupPCIInterrupt: Error %d setting interrupt functions\n");
return err;
}
return noErr;
}
\ No newline at end of file diff --git a/roms/QemuMacDrivers/shared/MacDriverUtils.h b/roms/QemuMacDrivers/shared/MacDriverUtils.h new file mode 100644 index 000000000..d93429a94 --- /dev/null +++ b/roms/QemuMacDrivers/shared/MacDriverUtils.h @@ -0,0 +1 @@ +#ifndef __MAC_DRIVER_UTILS_H__
#define __MAC_DRIVER_UTILS_H__
#include <NameRegistry.h>
#include <DriverServices.h>
#include <PCI.h>
void *DTGetProp(RegEntryIDPtr dtNode,
RegPropertyNamePtr name,
RegPropertyValueSize *outSize);
void DTFreeProp(void *);
LogicalAddress GetDeviceBARAddress(RegEntryIDPtr dtNode,
PCIRegisterNumber barOffset,
ByteCount *size,
Boolean *isIO);
OSStatus EnablePCIMemorySpace(RegEntryIDPtr dtNode);
typedef struct IRQInfo {
InterruptSetMember interruptSetMember;
void* refCon;
InterruptHandler handlerFunction;
InterruptEnabler enableFunction;
InterruptDisabler disableFunction;
} IRQInfo;
OSStatus SetupPCIInterrupt(RegEntryID *dtNode, IRQInfo *info,
InterruptHandler handler, void *refCon);
#endif /* __MAC_DRIVER_UTILS_H__ */
\ No newline at end of file diff --git a/roms/QemuMacDrivers/shared/MakeFunction.s b/roms/QemuMacDrivers/shared/MakeFunction.s new file mode 100644 index 000000000..7d3820ff9 --- /dev/null +++ b/roms/QemuMacDrivers/shared/MakeFunction.s @@ -0,0 +1,29 @@ +; MakeFunction sets up everything you need to make an assembly function +; callable from C and debuggable with a symbolic debugger. It does the following: +; - export the function's transition vector +; - export the function name +; - create a toc entry for the function's transition vector +; - create the transition vector, which must contain +; - the function entry point (the name of the function) +; - the TOC anchor (the predefined variable TOC[tc0]) +; - tell PPCAsm to create a function entry point symbol for symbolic debuggers +; - create a csect for the function (one csect per function lets the +; linker do dead code stripping, resulting in smaller executables) + + MACRO + MakeFunction &fnName + EXPORT &fnName[DS] + EXPORT .&fnName[PR] + + TC &fnName[TC], &fnName[DS] + + CSECT &fnName[DS] + DC.L .&fnName[PR] + DC.L TOC[tc0] + + CSECT .&fnName[PR] + FUNCTION .&fnName[PR] + + ENDM + +
\ No newline at end of file diff --git a/roms/QemuMacDrivers/shared/logger.h b/roms/QemuMacDrivers/shared/logger.h new file mode 100644 index 000000000..6a65287c2 --- /dev/null +++ b/roms/QemuMacDrivers/shared/logger.h @@ -0,0 +1,32 @@ +/* + * Creation Date: <1999/03/20 07:38:38 samuel> + * Time-stamp: <2002/07/20 19:29:22 samuel> + * + * <logger.h> + * + * Interface to some logging functions + * + * Copyright (C) 1999, 2002 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef __LOGGER_H_ +#define __LOGGER_H_ + +#include <Types.h> + +#define DBG(x) do {x;} while(0) + +#ifdef DEBUG_OSI +extern void lprintf( char *fmt,... ); +extern OSStatus CheckStatus( OSStatus value, char *message); +#else +static inline void lprintf( char *fmt,... ) { } +static inline OSStatus CheckStatus( OSStatus value, char *message) { return value; } +#endif + +#endif diff --git a/roms/QemuMacDrivers/shared/vsprintf.c b/roms/QemuMacDrivers/shared/vsprintf.c new file mode 100755 index 000000000..b8eae5c21 --- /dev/null +++ b/roms/QemuMacDrivers/shared/vsprintf.c @@ -0,0 +1,343 @@ +/* + * String functions for logger. + */ + +/* + * linux/lib/vsprintf.c + * + * Copyright (C) 1991, 1992, Linus Torvalds + */ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include <stdarg.h> +#include "logger.h" + +/* we use this so that we can do without the ctype library */ +#define is_digit(c) ((c) >= '0' && (c) <= '9') + +static int skip_atoi(const char **s) +{ + int i=0; + + while (is_digit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ + +#define do_div(n,base) ({ \ +int __res; \ +__res = ((unsigned long) n) % (unsigned) base; \ +n = ((unsigned long) n) / (unsigned) base; \ +__res; }) + +static int mstrlen( const char *str ); + +static char * number(char * str, long num, int base, int size, int precision + ,int type) +{ + char c,sign,tmp[66]; + const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; + int i; + + if (type & LARGE) + digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++]='0'; + else while (num != 0) { +#if 0 + tmp[i++] = digits[do_div(num,base)]; +#endif + int __res; + __res = ((unsigned long) num) % (unsigned) base; + num = ((unsigned long) num) / (unsigned) base; + tmp[i++] = digits[__res]; + } + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type & SPECIAL) { + if (base==8) + *str++ = '0'; + else if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type & LEFT)) + while (size-- > 0) + *str++ = c; + while (i < precision--) + *str++ = '0'; + while (i-- > 0) + *str++ = tmp[i]; + while (size-- > 0) + *str++ = ' '; + return str; +} + +/* Forward decl. to keep compiler happy. */ +int sprintf(char * buf, const char *fmt, ...); +int vsprintf(char *buf, const char *fmt, va_list args); + + +int vsprintf(char *buf, const char *fmt, va_list args) +{ + int len; + unsigned long num; + int i, base; + char * str; + const char *s; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + + for (str=buf ; *fmt ; ++fmt) { + if (*fmt != '%') { + *str++ = *fmt; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (is_digit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + field_width = va_arg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (is_digit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + precision = va_arg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + ++fmt; + } + + /* default base */ + base = 10; + + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + *str++ = ' '; + *str++ = (unsigned char) va_arg(args, int); + while (--field_width > 0) + *str++ = ' '; + continue; + + case 's': + s = va_arg(args, char *); + if (!s) + s = "<NULL>"; + +#if 0 + len = strnlen(s, precision); +#else + len = mstrlen(s); + if( precision > len ) + len = precision; +#endif + + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + continue; + + case 'p': + if (field_width == -1) { + field_width = 2*sizeof(void *); + flags |= ZEROPAD; + } + str = number(str, + (unsigned long) va_arg(args, void *), 16, + field_width, precision, flags); + continue; + + + case 'n': + if (qualifier == 'l') { + long * ip = va_arg(args, long *); + *ip = (str - buf); + } else { + int * ip = va_arg(args, int *); + *ip = (str - buf); + } + continue; + + /* integer number formats - set up the flags and "break" */ + case 'o': + base = 8; + break; + + case 'X': + flags |= LARGE; + case 'x': + base = 16; + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + break; + + default: + if (*fmt != '%') + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + continue; + } + if (qualifier == 'l') + num = va_arg(args, unsigned long); + else if (qualifier == 'h') { + num = (unsigned short) va_arg(args, int); + if (flags & SIGN) + num = (short) num; + } else if (flags & SIGN) + num = va_arg(args, int); + else + num = va_arg(args, unsigned int); + str = number(str, num, base, field_width, precision, flags); + } + *str = '\0'; + return str-buf; +} + +int sprintf(char * buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vsprintf(buf,fmt,args); + va_end(args); + return i; +} + +static int mstrlen( const char *str ) +{ + int i=0; + if( str == NULL ) + return 0; + while( *str++ ) + i++; + return i; +} + +/* + * MOL OSI logging + */ + +#include "LinuxOSI.h" + +void lprintf( char *fmt,... ) +{ + va_list args; + char *p, buf[256]; + + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); + + OSI_PutC( '*' ); + OSI_PutC( '*' ); + OSI_PutC( '*' ); + OSI_PutC( ' ' ); + for( p=buf; *p; p++ ) + OSI_PutC( *p ); +} + +OSStatus +CheckStatus( OSStatus status, char *message ) +{ + if( status != noErr ) + lprintf("%s\n",message); + return status; +} |