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

syscall.c File Reference

System Calls. More...

#include <const.h>
#include <arch/i386.h>
#include <arch/mem.h>
#include <kernel/console.h>
#include <kernel/keyboard.h>
#include <kernel/kernel.h>
#include <kernel/speaker.h>
#include <kernel/task.h>
#include <kernel/umalloc.h>
#include <kernel/syscall.h>

Go to the source code of this file.

Data Structures

struct  syscall_t
 System call entry. More...


Defines

#define SYS_CALL_NR   ( sizeof(syscall_table)/sizeof(dword) )
 Total amount of system calls.


Typedefs

typedef syscall_t syscall_t
 System call entry.


Functions

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.



Variables

syscall_t syscall_table []
 This is the array of the known system calls.


Detailed Description

System Calls.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2004-01-03
Note:
Copyright (©) 2003 Andrea Righi

Definition in file syscall.c.


Define Documentation

#define SYS_CALL_NR   ( sizeof(syscall_table)/sizeof(dword) )
 

Total amount of system calls.

Definition at line 23 of file syscall.c.


Typedef Documentation

typedef struct syscall_t syscall_t
 

System call entry.


Function Documentation

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 }


Variable Documentation

syscall_t syscall_table[] [static]
 

Initial value:

 {

        {       (size_t)&auto_kill,     1               },
        {       (size_t)&kgetchar,      0               },
        {       (size_t)&kputchar,      1               },
        {       (size_t)&keyb_read,     0               },
        {       (size_t)&umalloc,       1               },
        {       (size_t)&ufree,         1               },
}
This is the array of the known system calls.

Definition at line 35 of file syscall.c.


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