wiki:kernel_syscalls

Version 9 (modified by alain, 10 years ago) (diff)

--

GIET-VM / Syscall Handler

The sys_handler.c and sys_handler.h files define the kernel data structure and functions that are used to handle the system calls. They are prefixed by _ to remind that they can only be executed by a processor in kernel mode.

The _syscall_vector array contains the 64 kernel functions (syscal handlers) defined by the GIET-VM to handle system calls.

TTY related syscall handlers

int _sys_tty_alloc()

This function allocates a private TTY terminal to the calling task, and registers the TTY index in the task context. Returns 0 if success, returns -1 if not enough terminals.

int _sys_tty_write( const char* buffer, unsigned int length, unsigned int channel )

This non-blocking function writes a character string from a fixed-length buffer to a TTY terminal identified by the channel argument. If channel argument is 0xFFFFFFFF, the TTY index is found in the task context. It is non blocking: it tests the TTY_STATUS register, and stops the transfer as soon as the TTY_STATUS[WRITE] bit is set. Returns -1 if no TTT terminal allocated to the calling task. Returns the number of characters that have been written if a terminal is allocated.

int _sys_tty_read( char* buffer, unsigned int length, unsigned int channel )

This non-blocking function fetches one character from the terminal identified by the channel argument. If the channel argument is 0xFFFFFFFF, the TTY index is obtained from the current task context. It uses the TTY_GET_IRQ[tty_id] interrupt and the buffer must have been filled by the TTY_ISR. It test the _tty_rx_full[tty_id] variable, read the _tty_rx_buf[tty_id] buffer, writes this character to the target buffer, and resets the_tty_rx_full[tty_id] register. The length argument is not used. Returns -1 if no TTY terminal allocated to the calling task. Returns the number of characters that have been read if a terminal is allocated (can be 0 or 1).

int _sys_tty_get_lock( unsigned int channel, unsigned int* save_sr_ptr )

This blocking function try to take the lock protecting exclusive access to TTY terminal identified by the "channel" argument. It enters a critical section before taking the lock, and save the SR value at address defined by the save_sr_ptr argument. Returns -1 if no TTY terminal allocated to the calling task. If a TTY terminal is allocated, it returns only when the lock has been successfully taken.

int _sys_tty_release_lock( unsigned int channel, unsigned int* save_sr_ptr )

This function releases the lock protecting exclusive access to TTY terminal identified by the channel argument. It exit the critical section after lock release, and restore SR value from address defined by the save_sr_ptr argument. Returns -1 if no TTY terminal allocated to the calling task.

TIM retated syscall handlers

int _sys_tim_alloc()

This function allocates a private timer to the calling task, and register the timer index in the task context. Return -1 if no timer available.

int _sys_tim_start( unsigned int period )

This function starts the user timer channel allocated to the calling task. Returns 0 if success. Returns -1 if no allocated timer.

int _sys_tim_stop()

This function stops the user timer channel allocated to the calling task. Returns 0 if success. Returns -1 if no allocated timer.

NIC related syscall handlers

int _sys_nic_alloc()

This function allocates a private NIC channel to the calling task, and register the channel index in the task context. Return -1 if no NIC channel available.

int _sys_nic_sync_send( void* vbuf )

This function uses a physical_memcpy() to transfer a 4kbytes container from an user buffer to a private NIC TX channel. It computes the physical base address associated to the user buffer. Returns 0 if success, returns -1 if the buffer address is illegal, or if there is no NIC channel allocated to the calling task.

int _sys_nic_sync_receive( void* vbuf )

This function uses a physical_memcpy() to transfer a 4kbytes container from a private NIC RX channel to an user buffer. It computes the physical base address associated to the user buffer. Returns 0 if success, returns -1 if the buffer address is illegal, or if there is no NIC channel allocated to the calling task.

Miscelaneous syscall handlers

int _sys_ukn()

Function executed in case of undefined syscall

int _sys_proc_xyp( unsigned int* x, unsigned int*, unsigned int* p )

This function returns the processor (x,y,p) identifiers.

int _sys_task_exit()

The calling task goes to sleeping state, after printing an exit message. It is descheduled and enters the "not runable" mode.

int _context_switch()

This function deschedules the calling task. It mask interrupts before calling the _ctx_switch, and restore it when the task is rescheduled.

int _sys_local_task_id()

This function returns the current task local index (amongst tasks running on a given processor).

int _sys'_global_task_id()

This function returns the current task global index (amongst all tasks running on all processors).

int _sys_thread_id()

This function returns the current task thread index (amongst all tasks in a given multi-tasks application).

int _sys_procs_number( unsigned int x, unsigned int y, unsigned int* number )

Returns in the number argument the number of processors in cluster[x,y].

int _sys_vobj_get_vbase( char* vspace_name, char* vobj_name, unsigned int* vbase )

This function returns in the vbase argument the virtual base address of the vobj identified by the (vspace_name / vobj_name ) couple. Returns 0 if success, -1 if vobj not found.

int _sys_vobj_get_length( char* vspace_name, char* vobj_name, unsigned int* length )

This function returns in the length argument the length of the vobj identified by the (vspace_name / vobj_name ) couple. Returns 0 if success, -1 if vobj not found

int _sys_xy_from_ptr( void* ptr, unsigned int* x, unsigned int* y )

This function returns in the (x,y) arguments the coordinates of the cluster where is mapped the ptr virtual address. It use the _get_context_slot() function to get the calling task page table, and uses the _v2p_translate() function to obtain the physical address. Returns 0 if success, -1 if ptr not mapped in the calling task vspace.

int _sys_heap_info( unsigned int* vaddr, unsigned int* length, unsigned int x, unsigned int y )

This function returns the information associated to a heap : vaddr and length.

  • If (x < X_SIZE) and (y < Y_SIZE), it return the heap associated to any task running in cluster(x,y).
  • else, it return the heap associated to the calling task.

It uses the global task index (CTX_GTID_ID, unique for each giet task) and the vspace index (CTX_VSID_ID), that are defined in the calling task context to find the vobj_id containing the heap. Returns 0 if success, returns -1 if not found.