wiki:common_utils

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

--

Kernel Utilities

The utils.c and util.h files define kernel functions that are used both by the boot_loader and by the kernel. They are prefixed by _ to remind that they can only be executed by a processor in kernel mode.

  • They are used by the boot-loader in the static phase, to build the page tables and initialize the schedulers and the peripherals.
  • They are also used by the kernel in the dynamic phase, to handle events such as interrupts, exceptions and syscalls.

1) CP0 registers access functions

unsigned int _get_sched( void )

Returns the virtual address of the scheduler, stored in the CP0_SCHED register, for the processor running the calling task.

unsigned int _get_epc( void )

Returns the value stored in the CP0_EPC register, for the processor running the calling task.

unsigned int _get_cr( void )

Returns the value stored in the CP0_CR register, for the processor running the calling task.

unsigned int _get_sr( void )

Returns the value stored in the CP0_SR register, for the processor running the calling task.

unsigned int _get_bvar( void )

Returns the value stored in the CP0_BVAR register, for the processor running the calling task.

unsigned int _get_procid( void )

Returns the global processor identifier stored in the CP0_PROCID register for the processor running the calling task.

unsigned int _get_protime( void )

Returns the cycle count stored in the CP0_TIME register for the processor running the calling task.

void _set_sched( unsigned int value )

Writes value in the CP0_SCHED register, for the processor running the calling task.

void _set_sr( unsigned int value )

Writes value in the CP0_SR register, for the processor running the calling task.

void _it_disable( unsigned int* save_sr_ptr )

Disables interrupts for the processor running the calling task and save the CP0_SR value at address save_sr_ptr.

void _it_restore( unsigned int* save_sr_ptr )

Writes the value pointed by save_sr_ptr into the CP0_SR register, for the processor running the calling task.

2) CP2 registers access functions

unsigned int _get_mmu_ptpr( void )

Returns the value stored in the CP2_PTPR register, for the processor running the calling task.

unsigned int _get_mmu_mode( void )

Returns the value stored in the CP2_MODE register, for the processor running the calling task.

void _set_mmu_ptpr( unsigned int value )

Writes value in the CP2_PTPR register, for the processor running the calling task.

void _set_mmu_mode( unsigned int value )

Writes value in the CP2_MODE register, for the processor running the calling task.

3) Physical addressing functions

unsigned int _physical_read( unsigned long long paddr )

Returns the 32 bits word stored at physical address paddr, after a temporary DTLB deactivation. It uses the CP2_PADDR_EXT register.

void _physical_write( unsigned long long paddr, unsigned int value )

Writes the 32 bits word value at physical address paddr, after a temporary DTLB deactivation. It uses the CP2_PADDR_EXT register.

unsigned long long _physical_read_ull( unsigned long long paddr )

Returns the 64 bits word stored at physical address paddr, after a temporary DTLB deactivation. It uses the CP2_PADDR_EXT register.

void _physical_write_ull( unsigned long long paddr, unsigned long long value )

Writes the 64 bits word value at physical address paddr, after a temporary DTLB deactivation. It uses the CP2_PADDR_EXT register.

void _physical_memcpy( unsigned long long dst_paddr, unsigned long long src paddr, unsigned int size )

This function makes a memcpy from a source buffer to a destination buffer, using physical addresses, after a temporary DTLB de-activation. The src_paddr, dst_paddr and size arguments must be multiple of 4 bytes.

unsigned int _io_extended_read( unsigned int* vaddr )

This function is used by the GIET-VM drivers to read a 32 bits word in a peripheral register. If the MMU is not activated, the virtual address is extended using X_IO and Y_IO (defined in the hard-config.h file) to reach the cluster_io.

void _io_extended_write( unsigned int* vaddr, unsigned int value )

This function is used by the GIET-VM drivers to write a 32 bits word in a peripheral register. If the MMU is not activated, the virtual address is extended using X_IO and Y_IO (defined in the hard-config.h file) to reach the cluster_io.

4) SpinLock? access functions

The giet_lock_t structure is defined in the utils.h file to have one single lock in a 64 bytes cache line. It should be aligned on a cache line boundary.

void _get_lock( giet_lock_t lock )

Takes a lock with a blocking ll/sc atomic access. If the cache coherence is granted by the hardware, the first read is a standard (cacheable) lw, as the local copy can be polled when the lock is already taken by another task, reducing trafic on the interconnect. When the lock is released by the owner task, the local copy is updated or invalidated by the coherence protocol. If there is no hardware cache coherence a pseudo random delay is introduced between two successive retry.

void _release_lock( giet_lock_t lock )

Releases (or initializes) a lock.

5) TTY0 access functions

void _puts( char* string )

Displays a string on kernel TTY0. This function does NOT take the TTY0 lock.

void _putx( unsigned int value )

Displays a 32 bits word as an hexadecimal string on kernel TTY0. This function does NOT take the TTY0 lock.

void _putl( unsigned long long value )

Displays a 64 bits word as an hexadecimal string on kernel TTY0. This function does NOT take the TTY0 lock.

void _putd( unsigned int value )

Displays a 32 bits word as an decimal string on kernel TTY0. This function does NOT take the TTY0 lock.

void _printf( char* format, ... )

Display a format on kernel TTY0. To provide an atomic display, this function takes the lock protecting exclusive access to TTY0, entering a critical section until the lock is released. Only a limited number of formats are supported:

  • %d : 32 bits signed decimal
  • %u : 32 bits unsigned decimal
  • %x : 32 bits unsigned hexa
  • %l : 64 bits unsigned hexa
  • %c : char
  • %s : string

void _getc( char* byte )

This blocking function uses a polling strategy on the TTY0 status register to get a single character.

6) Task context access functions

X) Miscelaneous functions