Version 5 (modified by 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.
-
Kernel Utilities
-
1) CP0 registers access functions
- unsigned int _get_sched( void )
- unsigned int _get_epc( void )
- unsigned int _get_cr( void )
- unsigned int _get_sr( void )
- unsigned int _get_bvar( void )
- unsigned int _get_procid( void )
- unsigned int _get_protime( void )
- void _set_sched( unsigned int value )
- void _set_sr( unsigned int value )
- void _it_disable( unsigned int* save_sr_ptr )
- void _it_restore( unsigned int* save_sr_ptr )
- 2) CP2 registers access functions
-
3) Physical addressing functions
- unsigned int _physical_read( unsigned long long paddr )
- void _physical_write( unsigned long long paddr, unsigned int value )
- unsigned long long _physical_read_ull( unsigned long long paddr )
- void _physical_write_ull( unsigned long long paddr, unsigned long long …
- void _physical_memcpy( unsigned long long dst_paddr, unsigned long …
- unsigned int _io_extended_read( unsigned int* vaddr )
- void _io_extended_write( unsigned int* vaddr, unsigned int value )
- 4) SpinLock? access functions
- X) Miscelaneous functions
-
1) CP0 registers access functions
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.
_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.
_release_lock( giet_lock_t lock )
Releases (or initializes) a lock.