Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

Handlers
[Kernel]


Functions

int page_fault_handler (dword err_code, dword cr2)
 This is the page-fault handler. Every time a page-fault occurs, this routine must be invoked.
Parameters:
err_code  The error code from the CPU.
cr2  The address that caused the fault.
Returns:
  • 0 success;
  • < 0 otherwise.


void floppy_handler ()
 This is the floppy interrupt handler routine. It is invoked every time that a floppy operation successfully completes.

void keyboard_handler ()
 This is the keyboard interrupt handler routine. It is invoked every time a key is pressed or released on the keyboard.

void rs232_handler_port1 ()
 The COM1 interrupt handler.

void rs232_handler_port2 ()
 The COM2 interrupt handler.

void rtl8139_handler ()
 The RTL8139 interrupt handler routine. It is invoked every time that an ethernet packet is received or when a packet has been transmitted.

void syscall_handler (dword *eax, dword *ebp)
 This procedure execute every system call invoked by INT 0x80.
Parameters:
eax  The EAX register of the calling procedure must contains the syscall id. At the end of the syscall it contains the returned value.
ebp  The EBP register of the calling procedure. It must point to the stack pointer of the calling procedure.



Detailed Description

System interrupt handlers.

Function Documentation

void floppy_handler  
 

This is the floppy interrupt handler routine. It is invoked every time that a floppy operation successfully completes.

Definition at line 440 of file floppy.c.

00441 {
00442         fdc_done = TRUE;
00443 }

void keyboard_handler  
 

This is the keyboard interrupt handler routine. It is invoked every time a key is pressed or released on the keyboard.

Definition at line 145 of file keyboard.c.

00146 {
00147         task_t *p;
00148         int console, count;
00149         // Current console structure.
00150         console_t *curr_cons = get_console_addr( get_curr_console() );
00151         // Key hitten ASCII code.
00152         word code;
00153         // Key hitten keyboard code.
00154         word keypressed = scan_key();
00155 
00156         // If CTRL+ALT+Canc => Reboot the system...                     //
00157         if (ctrl==1 && alt==1 && keypressed==DEL_SCAN) reboot();
00158 
00159         if (alt==1) code = with_alt[keypressed];
00160         else if (ctrl==1) code = with_control[keypressed];
00161         else
00162         {
00163                 if (curr_cons->caps_lock==0 && shift==0) code = regular[keypressed];
00164                 else if (curr_cons->caps_lock==0 && shift==1) code = with_shift[keypressed];
00165                 else if (curr_cons->caps_lock==1 && shift==0)
00166                 {
00167                         code = regular[keypressed];
00168                         if (((code&0xFF)>='a') && ((code&0xFF)<='z')) code-='a'-'A';
00169                 }
00170                 else
00171                 {
00172                         code = with_shift[keypressed];
00173                         if (((code&0xFF)>='A') && ((code&0xFF)<='Z')) code+='a'-'A';
00174                 }
00175                 if ((curr_cons->num_lock!=shift) && (keypressed>=71 && keypressed<=83))
00176                         code = keypad_char[keypressed-71];
00177         }
00178 
00179         // Print the char only if it's not released (bit 8 set)         //
00180         switch (keypressed)
00181         {
00182                 case 42:        // LShift
00183                 shift=1;
00184                 break;
00185 
00186                 case (42+128):
00187                 shift=0;
00188                 break;
00189 
00190                 case 54:        // RShift
00191                 shift=1;
00192                 break;
00193 
00194                 case (54+128):
00195                 shift=0;
00196                 break;
00197 
00198                 case 56:        // ALT
00199                 alt=1;
00200                 break;
00201 
00202                 case (56+128):
00203                 alt=0;
00204                 break;
00205 
00206                 case 29:        // CTRL
00207                 ctrl=1;
00208                 break;
00209 
00210                 case (29+128):
00211                 ctrl=0;
00212                 break;
00213 
00214                 case 58:        // CAPS LOCK
00215                 curr_cons->caps_lock ^= 1;
00216                 update_leds();
00217                 break;
00218 
00219                 case 69:        // NUM LOCK
00220                 curr_cons->num_lock ^= 1;
00221                 update_leds();
00222                 break;
00223 
00224                 case 70:        // SCROLL LOCK
00225                 curr_cons->scroll_lock ^= 1;
00226                 update_leds();
00227                 break;
00228 
00229                 case 0xE1:      // PAUSE
00230                 // Wait until released... //
00231                 while (scan_key() != 0xC5);
00232                 break;
00233 
00234                 default:
00235 
00236                 // Update keyboard buffer. This is an interrupt         //
00237                 // handler so we are already in mutual exclusion!!!     //
00238 
00239                 if (!(keypressed & 0x80))
00240                 {
00241                         if ( (code>=ALT_F1) && (code<=ALT_F10) )
00242                         {
00243                                 // Change console                       //
00244                                 console = ((code-ALT_F1) >> 8) + 1;
00245                                 switch_to_console( console );
00246 
00247                                 // Every task in the selected console
00248                                 // need to wake-up.
00249                                 count = count_queue( &keyb_queue );
00250                                 for ( ; count; --count )
00251                                 {
00252                                         p = pick_queue( &keyb_queue );
00253                                         if ( p->console==console )
00254                                         {
00255                                                 wakeup_task( p );
00256                                                 rem_queue( &keyb_queue, p );
00257                                         }
00258                                 }
00259                                 return;
00260                         }
00261                         // A key has been released => update the buffer //
00262                         if ( (curr_cons->keyb_buf_count) < KEYB_BUF_DIM )
00263                         {
00264                                 (curr_cons->keyb_buf_count)++;
00265                                 if ( ++(curr_cons->keyb_buf_write) >= KEYB_BUF_DIM )
00266                                         curr_cons->keyb_buf_write = 0;
00267                                 curr_cons->keyb_buffer[curr_cons->keyb_buf_write] = code;
00268                         }
00269                         else
00270                         {
00271                                 // Buffer full => beep!                 //
00272                                 beep();
00273                         }
00274                 }
00275                 break;
00276         }
00277 }

int page_fault_handler dword    err_code,
dword    cr2
 

This is the page-fault handler. Every time a page-fault occurs, this routine must be invoked.

Parameters:
err_code  The error code from the CPU.
cr2  The address that caused the fault.
Returns:
  • 0 success;
  • < 0 otherwise.

Definition at line 367 of file paging.c.

00368 {
00369         dword phys_addr;
00370 
00371 #ifdef PAGE_DEBUG
00372         kprintf("\n\rPAGE_FAULT : %#010x", cr2);
00373 #endif
00374         if( cr2==NULL )
00375         {
00376                 // Cannot map the NULL pointer.
00377                 return( -1 );
00378         }
00379 
00380         // Get a physical free frame.
00381         phys_addr = pop_frame()*PAGE_SIZE;
00382 
00383         // If out of memory => return!
00384         if (phys_addr == NULL)
00385         {
00386                 set_color(LIGHT_RED);
00387                 kprintf("\n\rPage fault handler panic: Out of memory!!!");
00388                 set_color(DEFAULT_COLOR);
00389                 return(-1);
00390         }
00391 
00392         // Get only valid err_code //
00393         err_code &= (P_PRESENT | P_WRITE | P_USER);
00394 
00395         // Map page with correct attributes //
00396         if (cr2 >= K_VIR_START)
00397         {
00398                 if (!(map_page(cr2, phys_addr, P_PRESENT | P_WRITE)))
00399                 {
00400                         // Out of memory!!! //
00401                         set_color(LIGHT_RED);
00402                         kprintf("\n\rPage fault handler panic: Out of memory!!!");
00403                         set_color(DEFAULT_COLOR);
00404                         return( -1 );
00405                 }
00406         }
00407         else
00408         {
00409                 if (!(map_page(cr2, phys_addr, P_PRESENT | P_WRITE | P_USER)))
00410                 {
00411                         // Out of memory!!! //
00412                         set_color(LIGHT_RED);
00413                         kprintf("\n\rPage fault handler panic: Out of memory!!!");
00414                         set_color(DEFAULT_COLOR);
00415                         return( -1 );
00416                 }
00417         }
00418         // Null the new page.
00419         // memsetl((void *)PAGE_ALIGN(cr2), 0, PAGE_SIZE/sizeof(uint32_t));
00420         fast_clear_page((void *)PAGE_ALIGN(cr2));
00421         return( 0 );
00422 }

void rs232_handler_port1  
 

The COM1 interrupt handler.

Definition at line 108 of file serial.c.

00109 {
00110         rs232_handler(PORT1);
00111 }

void rs232_handler_port2  
 

The COM2 interrupt handler.

Definition at line 115 of file serial.c.

00116 {
00117         rs232_handler(PORT2);
00118 }

void rtl8139_handler  
 

The RTL8139 interrupt handler routine. It is invoked every time that an ethernet packet is received or when a packet has been transmitted.

Definition at line 626 of file rtl8139.c.

00627 {
00628         uint16_t status;
00629 
00630         out16(rtl->iobase + IntrMask, 0);
00631 
00632         status = in16(rtl->iobase + IntrStatus);
00633         // Acknowledge all known interrupts                             //
00634         out16(rtl->iobase + IntrStatus, status & ~(RxFIFOOver | RxOverflow | RxOK));
00635 
00636         if (status & (RxOK | RxErr))
00637                 rtl8139_handle_rx(rtl);
00638         else
00639                 if (status & (TxOK | TxErr))
00640                         rtl8139_handle_tx(rtl);
00641                 // #ifdef DEBUG
00642                 else
00643                         kprintf("\n\rRTL8139: unknown interrupt: isr = %#010x\n", status);
00644                 // #endif
00645 
00646         // Re-enable interrupts from the RTL8139 card                   //
00647         out16(rtl->iobase + IntrStatus, status & (RxFIFOOver | RxOverflow | RxOK));
00648         out16(rtl->iobase + IntrMask, IntrDefault);
00649 }

void syscall_handler dword   eax,
dword   ebp
 

This procedure execute every system call invoked by INT 0x80.

Parameters:
eax  The EAX register of the calling procedure must contains the syscall id. At the end of the syscall it contains the returned value.
ebp  The EBP register of the calling procedure. It must point to the stack pointer of the calling procedure.

Copy the stack parameters from the stack pointer of the calling procedure (pointed by ebp) to the current stack pointer. Then the opportune syscall is invoked.

Definition at line 60 of file syscall.c.

00061 {
00062         // Function pointer.
00063         size_t (*p)() = (void *)syscall_table[*eax].address;
00064         // How many parameters.
00065         int paramcnt = syscall_table[*eax].paramcnt;
00066         // Start of parameters'address.
00067         size_t *args = (size_t *)(*ebp);
00068 
00069         register int i;
00070 
00071         // Check if the system call id does not exceed the syscall table.
00072         // NOTE: sycall id is 0-based!!!
00073         if ( *eax < SYS_CALL_NR )
00074         {
00075                 // Pass the parameters to the system call routine.
00076                 for( i=paramcnt; i; --i)
00077                         __asm__ __volatile__ ("pushl %0" : : "r"(*(args+i-1)));
00078                 // Execute the system call.
00079                 // The result will be returned into the task's eax register.
00080                 *eax = (*p)();
00081                 // Pop elements out of the stack.
00082                 __asm__ __volatile__ ("add %0, %%esp" : : "r"(paramcnt*sizeof(size_t)));
00083         }
00084         else
00085         {
00086                 // Invalid syscall id! => kill the task.
00087                 kprintf("\n\rsyscall: %u", *eax);
00088                 error("Invalid system call");
00089         }
00090 }


Generated on Fri Feb 20 15:32:23 2004 for Minirighi by doxygen1.2.18