wiki:common_utils

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

--

Kernel Utilities

The utils.c and util.h files define useful 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.

X) Miscelaneous functions