#define TRACE_IRQS 0
// === TYPES ===
-typedef void (*tIRQ_Callback)(int);
+typedef void (*tIRQ_Callback)(int, void *);
// === PROTOTYPES ===
void IRQ_Handler(tRegs *Regs);
// === GLOBALS ===
tIRQ_Callback gIRQ_Handlers[16][MAX_CALLBACKS_PER_IRQ];
+void *gaIRQ_DataPointers[16][MAX_CALLBACKS_PER_IRQ];
// === CODE ===
/**
*/
void IRQ_Handler(tRegs *Regs)
{
- int i;
-
- Regs->int_num -= 0xF0; // Adjust
+ int i, irq = Regs->int_num - 0xF0;
//Log("IRQ_Handler: (Regs={int_num:%i})", Regs->int_num);
for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
{
- if( gIRQ_Handlers[Regs->int_num][i] ) {
- gIRQ_Handlers[Regs->int_num][i](Regs->int_num);
+ if( gIRQ_Handlers[irq][i] ) {
+ gIRQ_Handlers[irq][i](irq, gaIRQ_DataPointers[irq][i]);
#if TRACE_IRQS
- if( Regs->int_num != 8 )
+ if( irq != 8 )
Log("IRQ %i: Call %p", Regs->int_num, gIRQ_Handlers[Regs->int_num][i]);
#endif
}
}
//Log(" IRQ_Handler: Resetting");
- if(Regs->int_num >= 8)
+ if(irq >= 8)
outb(0xA0, 0x20); // ACK IRQ (Secondary PIC)
outb(0x20, 0x20); // ACK IRQ
//Log("IRQ_Handler: RETURN");
/**
* \fn int IRQ_AddHandler( int Num, void (*Callback)(int) )
*/
-int IRQ_AddHandler( int Num, void (*Callback)(int) )
+int IRQ_AddHandler( int Num, void (*Callback)(int, void*), void *Ptr )
{
int i;
for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
if( gIRQ_Handlers[Num][i] == NULL ) {
Log_Log("IRQ", "Added IRQ%i Cb#%i %p", Num, i, Callback);
gIRQ_Handlers[Num][i] = Callback;
+ gaIRQ_DataPointers[Num][i] = Ptr;
return 1;
}
}
// === PROTOTYPES ===
//Sint64 now(void);
int Time_Setup(void);
-void Time_Interrupt(int);
+void Time_Interrupt(int IRQ, void *Ptr);
Uint64 Time_ReadTSC(void);
// === CODE ===
outb(0x70, inb(0x70)|0x80); // Re-enable NMIs
// Install IRQ Handler
- IRQ_AddHandler(8, Time_Interrupt);
+ IRQ_AddHandler(8, Time_Interrupt, NULL);
// Make sure the RTC actually fires
outb(0x70, 0x0C); // Select register C
* \brief Called on the timekeeping IRQ
* \param irq IRQ number (unused)
*/
-void Time_Interrupt(int irq)
+void Time_Interrupt(int IRQ, void *Ptr)
{
//Log("RTC Tick");
Uint64 curTSC = Time_ReadTSC();
ret
-; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ))
+; int IRQ_AddHandler(int IRQ, void (*Handler)(int IRQ), void *Ptr)
; Return Values:
; 0 on Success
; -1 on an invalid IRQ Number
IRQ_AddHandler:
; RDI - IRQ Number
; RSI - Callback
+ ; RDX - Ptr
; Check for RDI >= 16
cmp rdi, 16
; Find a free callback slot
%rep NUM_IRQ_CALLBACKS
- mov rdx, [rax]
- test rdx, rdx
+ mov rcx, [rax]
+ test rcx, rcx
jz .assign
add rax, 8
%endrep
push rdi
push rsi
push rax
+ push rdx
sub rsp, 8
mov rcx, rdi ; IRQ Number
mov rdx, rsi ; Callback
mov rdi, csIRQ_Assigned
call Log
add rsp, 8
+ pop rdx
pop rax
pop rsi
pop rdi
; Assign and return
mov [rax], rsi
+ add rax, gaIRQ_DataPtrs - gaIRQ_Handlers
+ mov [rax], rdx
xor rax, rax
.ret:
jz .skip.%[i]
; Set RDI to IRQ number
mov rdi, [rsp+(16+2+1)*8] ; Get IRQ number
+ mov rsi, [rbx-gaIRQ_Handlers+gaIRQ_DataPtrs]
call rax ; Call
.skip.%[i]:
add rbx, 8 ; Next!
gaIRQ_Handlers:
times 16*NUM_IRQ_CALLBACKS dq 0
+gaIRQ_DataPtrs:
+ times 16*NUM_IRQ_CALLBACKS dq 0
// === FUNCTIONS ===
// --- IRQs ---
-extern int IRQ_AddHandler(int Num, void (*Callback)(int));
+extern int IRQ_AddHandler(int Num, void (*Callback)(int, void*), void *Ptr);
extern void IRQ_RemHandler(int Handle);
// --- Logging ---
// === PROTOTYPES ===
void KBC8042_Init(void);
-void KBC8042_KeyboardHandler(int IRQ);
-void KBC8042_MouseHandler(int IRQ);
+void KBC8042_KeyboardHandler(int IRQ, void *Ptr);
+void KBC8042_MouseHandler(int IRQ, void *Ptr);
void KBC8042_EnableMouse(void);
static inline void KBC8042_SendDataAlt(Uint8 data);
static inline void KBC8042_SendData(Uint8 data);
// === CODE ===
void KBC8042_Init(void)
{
- IRQ_AddHandler(1, KBC8042_KeyboardHandler);
- IRQ_AddHandler(12, KBC8042_MouseHandler); // Set IRQ
+ IRQ_AddHandler(1, KBC8042_KeyboardHandler, NULL);
+ IRQ_AddHandler(12, KBC8042_MouseHandler, NULL); // Set IRQ
{
Uint8 temp;
}
}
-void KBC8042_KeyboardHandler(int IRQ)
+void KBC8042_KeyboardHandler(int IRQ, void *Ptr)
{
Uint8 scancode;
KB_HandleScancode( scancode );
}
-void KBC8042_MouseHandler(int IRQ)
+void KBC8042_MouseHandler(int IRQ, void *Ptr)
{
PS2Mouse_HandleInterrupt( inb(0x60) );
}
int Ne2k_int_ReadDMA(tCard *Card, int FirstPage, int NumPages, void *Buffer);
Uint8 Ne2k_int_GetWritePage(tCard *Card, Uint16 Length);
-void Ne2k_IRQHandler(int IntNum);
+void Ne2k_IRQHandler(int IntNum, void *Ptr);
// === GLOBALS ===
MODULE_DEFINE(0, VERSION, Ne2k, Ne2k_Install, NULL, NULL);
gpNe2k_Cards[ k ].NextRXPage = RX_FIRST;
// Install IRQ Handler
- IRQ_AddHandler(gpNe2k_Cards[ k ].IRQ, Ne2k_IRQHandler);
+ IRQ_AddHandler(gpNe2k_Cards[ k ].IRQ, Ne2k_IRQHandler, &gpNe2k_Cards[k]);
// Reset Card
outb( base + 0x1F, inb(base + 0x1F) );
/**
* \fn void Ne2k_IRQHandler(int IntNum)
*/
-void Ne2k_IRQHandler(int IntNum)
+void Ne2k_IRQHandler(int IntNum, void *Ptr)
{
- int i;
Uint8 byte;
- for( i = 0; i < giNe2k_CardCount; i++ )
- {
- if(gpNe2k_Cards[i].IRQ == IntNum)
- {
- byte = inb( gpNe2k_Cards[i].IOBase + ISR );
-
- LOG("byte = 0x%02x", byte);
-
+ tCard *card = Ptr;
+
+ if(card->IRQ != IntNum) return;
+
+ byte = inb( card->IOBase + ISR );
+
+ LOG("byte = 0x%02x", byte);
- // Reset All (save for RDMA), that's polled
- outb( gpNe2k_Cards[i].IOBase + ISR, 0xFF&(~0x40) );
- // 0: Packet recieved (no error)
- if( byte & 1 )
- {
- //if( gpNe2k_Cards[i].NumWaitingPackets > MAX_PACKET_QUEUE )
- // gpNe2k_Cards[i].NumWaitingPackets = MAX_PACKET_QUEUE;
- if( Semaphore_Signal( &gpNe2k_Cards[i].Semaphore, 1 ) != 1 ) {
- // Oops?
- }
- }
- // 1: Packet sent (no error)
- // 2: Recieved with error
- // 3: Transmission Halted (Excessive Collisions)
- // 4: Recieve Buffer Exhausted
- // 5:
- // 6: Remote DMA Complete
- // 7: Reset
+ // Reset All (save for RDMA), that's polled
+ outb( card->IOBase + ISR, 0xFF&(~0x40) );
- return ;
+ // 0: Packet recieved (no error)
+ if( byte & 1 )
+ {
+ //if( card->NumWaitingPackets > MAX_PACKET_QUEUE )
+ // card->NumWaitingPackets = MAX_PACKET_QUEUE;
+ if( Semaphore_Signal( &card->Semaphore, 1 ) != 1 ) {
+ // Oops?
}
}
- Log_Warning("Ne2k", "Recieved Unknown IRQ %i", IntNum);
+ // 1: Packet sent (no error)
+ // 2: Recieved with error
+ // 3: Transmission Halted (Excessive Collisions)
+ // 4: Recieve Buffer Exhausted
+ // 5:
+ // 6: Remote DMA Complete
+ // 7: Reset
}
Uint64 RTL8139_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
Uint64 RTL8139_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
int RTL8139_IOCtl(tVFS_Node *Node, int ID, void *Arg);
-void RTL8139_IRQHandler(int Num);
+void RTL8139_IRQHandler(int Num, void *Ptr);
// === GLOBALS ===
MODULE_DEFINE(0, VERSION, RTL8139, RTL8139_Install, NULL, NULL);
card->IRQ = PCI_GetIRQ( id );
// Install IRQ Handler
- IRQ_AddHandler(card->IRQ, RTL8139_IRQHandler);
+ IRQ_AddHandler(card->IRQ, RTL8139_IRQHandler, card);
// Power on
outb( base + CONFIG1, 0x00 );
return 0;
}
-void RTL8139_IRQHandler(int Num)
+void RTL8139_IRQHandler(int Num, void *Ptr)
{
- int i, j;
- tCard *card;
+ int j;
+ tCard *card = Ptr;
Uint16 status;
LOG("Num = %i", Num);
- for( i = 0; i < giRTL8139_CardCount; i ++ )
- {
- card = &gaRTL8139_Cards[i];
- if( Num != card->IRQ ) break;
+ if( Num != card->IRQ ) return;
- status = inw(card->IOBase + ISR);
- LOG("status = 0x%02x", status);
+ status = inw(card->IOBase + ISR);
+ LOG("status = 0x%02x", status);
- // Transmit OK, a transmit descriptor is now free
- if( status & FLAG_ISR_TOK )
+ // Transmit OK, a transmit descriptor is now free
+ if( status & FLAG_ISR_TOK )
+ {
+ for( j = 0; j < 4; j ++ )
{
- for( j = 0; j < 4; j ++ )
- {
- if( ind(card->IOBase + TSD0 + j*4) & 0x8000 ) { // TSD TOK
- Mutex_Release( &card->TransmitInUse[j] );
- // TODO: Update semaphore once implemented
- }
+ if( ind(card->IOBase + TSD0 + j*4) & 0x8000 ) { // TSD TOK
+ Mutex_Release( &card->TransmitInUse[j] );
+ // TODO: Update semaphore once implemented
}
- outw(card->IOBase + ISR, FLAG_ISR_TOK);
}
+ outw(card->IOBase + ISR, FLAG_ISR_TOK);
+ }
+
+ // Recieve OK, inform read
+ if( status & FLAG_ISR_ROK )
+ {
+ int read_ofs, end_ofs;
+ int packet_count = 0;
+ int len;
- // Recieve OK, inform read
- if( status & FLAG_ISR_ROK )
+ // Scan recieve buffer for packets
+ end_ofs = inw(card->IOBase + CBA);
+ read_ofs = card->SeenOfs;
+ LOG("read_ofs = %i, end_ofs = %i", read_ofs, end_ofs);
+ if( read_ofs > end_ofs )
{
- int read_ofs, end_ofs;
- int packet_count = 0;
- int len;
-
- // Scan recieve buffer for packets
- end_ofs = inw(card->IOBase + CBA);
- read_ofs = card->SeenOfs;
- LOG("read_ofs = %i, end_ofs = %i", read_ofs, end_ofs);
- if( read_ofs > end_ofs )
- {
- while( read_ofs < card->ReceiveBufferLength )
- {
- packet_count ++;
- len = *(Uint16*)&card->ReceiveBuffer[read_ofs+2];
- LOG("%i 0x%x Pkt Hdr: 0x%04x, len: 0x%04x",
- packet_count, read_ofs,
- *(Uint16*)&card->ReceiveBuffer[read_ofs],
- len
- );
- if(len > 2000) {
- Log_Warning("RTL8139", "IRQ: Packet in buffer exceeds sanity (%i>2000)", len);
- }
- read_ofs += len + 4;
- read_ofs = (read_ofs + 3) & ~3; // Align
- }
- read_ofs -= card->ReceiveBufferLength;
- LOG("wrapped read_ofs");
- }
- while( read_ofs < end_ofs )
+ while( read_ofs < card->ReceiveBufferLength )
{
packet_count ++;
+ len = *(Uint16*)&card->ReceiveBuffer[read_ofs+2];
LOG("%i 0x%x Pkt Hdr: 0x%04x, len: 0x%04x",
packet_count, read_ofs,
*(Uint16*)&card->ReceiveBuffer[read_ofs],
- *(Uint16*)&card->ReceiveBuffer[read_ofs+2]
+ len
);
- read_ofs += *(Uint16*)&card->ReceiveBuffer[read_ofs+2] + 4;
+ if(len > 2000) {
+ Log_Warning("RTL8139", "IRQ: Packet in buffer exceeds sanity (%i>2000)", len);
+ }
+ read_ofs += len + 4;
read_ofs = (read_ofs + 3) & ~3; // Align
}
- if( read_ofs != end_ofs ) {
- Log_Warning("RTL8139", "IRQ: read_ofs (%i) != end_ofs(%i)", read_ofs, end_ofs);
- read_ofs = end_ofs;
- }
- card->SeenOfs = read_ofs;
-
- LOG("packet_count = %i, read_ofs = 0x%x", packet_count, read_ofs);
-
- if( packet_count )
- {
- if( Semaphore_Signal( &card->ReadSemaphore, packet_count ) != packet_count ) {
- // Oops?
- }
- VFS_MarkAvaliable( &card->Node, 1 );
+ read_ofs -= card->ReceiveBufferLength;
+ LOG("wrapped read_ofs");
+ }
+ while( read_ofs < end_ofs )
+ {
+ packet_count ++;
+ LOG("%i 0x%x Pkt Hdr: 0x%04x, len: 0x%04x",
+ packet_count, read_ofs,
+ *(Uint16*)&card->ReceiveBuffer[read_ofs],
+ *(Uint16*)&card->ReceiveBuffer[read_ofs+2]
+ );
+ read_ofs += *(Uint16*)&card->ReceiveBuffer[read_ofs+2] + 4;
+ read_ofs = (read_ofs + 3) & ~3; // Align
+ }
+ if( read_ofs != end_ofs ) {
+ Log_Warning("RTL8139", "IRQ: read_ofs (%i) != end_ofs(%i)", read_ofs, end_ofs);
+ read_ofs = end_ofs;
+ }
+ card->SeenOfs = read_ofs;
+
+ LOG("packet_count = %i, read_ofs = 0x%x", packet_count, read_ofs);
+
+ if( packet_count )
+ {
+ if( Semaphore_Signal( &card->ReadSemaphore, packet_count ) != packet_count ) {
+ // Oops?
}
-
- outw(card->IOBase + ISR, FLAG_ISR_ROK);
+ VFS_MarkAvaliable( &card->Node, 1 );
}
- }
+
+ outw(card->IOBase + ISR, FLAG_ISR_ROK);
+ }
}
int ATA_ReadDMA(Uint8 Disk, Uint64 Address, Uint Count, void *Buffer);
int ATA_WriteDMA(Uint8 Disk, Uint64 Address, Uint Count, const void *Buffer);
// IRQs
-void ATA_IRQHandlerPri(int UNUSED(IRQ));
-void ATA_IRQHandlerSec(int UNUSED(IRQ));
+void ATA_IRQHandlerPri(int UNUSED(IRQ), void *UNUSED(Ptr));
+void ATA_IRQHandlerSec(int UNUSED(IRQ), void *UNUSED(Ptr));
// Controller IO
Uint8 ATA_int_BusMasterReadByte(int Ofs);
Uint32 ATA_int_BusMasterReadDWord(int Ofs);
}
// Register IRQs and get Buffers
- IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri );
- IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec );
+ IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri, NULL );
+ IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec, NULL );
gATA_PRDTs[0].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[0] );
gATA_PRDTs[1].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[1] );
/**
* \brief Primary ATA Channel IRQ handler
*/
-void ATA_IRQHandlerPri(int UNUSED(IRQ))
+void ATA_IRQHandlerPri(int UNUSED(IRQ), void *UNUSED(Ptr))
{
Uint8 val;
/**
* \brief Second ATA Channel IRQ handler
*/
-void ATA_IRQHandlerSec(int UNUSED(IRQ))
+void ATA_IRQHandlerSec(int UNUSED(IRQ), void *UNUSED(Ptr))
{
Uint8 val;
// IRQ bit set for Secondary Controller
int FDD_ReadSector(Uint32 disk, Uint64 lba, void *Buffer);
int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer);
// --- Helpers
-void FDD_IRQHandler(int Num);
+void FDD_IRQHandler(int Num, void *Ptr);
inline void FDD_WaitIRQ();
void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl);
int FDD_int_SendByte(int base, Uint8 Byte);
}
// Install IRQ6 Handler
- IRQ_AddHandler(6, FDD_IRQHandler);
+ IRQ_AddHandler(6, FDD_IRQHandler, NULL);
// Ensure the FDD version is 0x90
{
* \fn void FDD_IRQHandler(int Num)
* \brief Handles IRQ6
*/
-void FDD_IRQHandler(int Num)
+void FDD_IRQHandler(int Num, void *Ptr)
{
gbFDD_IrqFired = 1;
}
int UHCI_DataOUT(void *Ptr, int Fcn, int Endpt, int DataTgl, void *Data, size_t Length);
int UHCI_SendSetup(void *Ptr, int Fcn, int Endpt, int DataTgl, void *Data, size_t Length);
int UHCI_Int_InitHost(tUHCI_Controller *Host);
-void UHCI_InterruptHandler(int IRQ);
+void UHCI_InterruptHandler(int IRQ, void *Ptr);
// === GLOBALS ===
tUHCI_TD gaUHCI_TDPool[NUM_TDs];
Log_Debug("UHCI", "Controller PCI #%i: IO Base = 0x%x, IRQ %i",
id, cinfo->IOBase, cinfo->IRQNum);
- IRQ_AddHandler(cinfo->IRQNum, UHCI_InterruptHandler);
+ IRQ_AddHandler(cinfo->IRQNum, UHCI_InterruptHandler, cinfo);
// Initialise Host
ret = UHCI_Int_InitHost(&gUHCI_Controllers[i]);
outw( Host->IOBase + FRNUM, 0 );
// Enable Interrupts
- //PCI_WriteWord( Host->PciId, 0xC0, 0x2000 );
+// PCI_WriteWord( Host->PciId, 0xC0, 0x2000 );
LEAVE('i', 0);
return 0;
}
+
+void UHCI_InterruptHandler(int IRQ, void *Ptr)
+{
+
+}