void * KrnAddExceptionHandler( uint8_t num, exhandler_t * handler, void * handlerData, void * handlerData2 );
Add a raw CPU exception handler to the chain of handlers.
num - CPU-specific exception number handler - Pointer to a handler function handlerData, handlerData2 - User-defined data which is passed to the handler. Handler function uses a C calling convention and must be declared as follows: int ExceptionHandler(void *ctx, void *handlerData, void *handlerData2) handlerData and handlerData2 will be values passed to the KrnAddExceptionHandler() function. ctx is a CPU context handle. Consider this parameter private and reserved for now. Exception handler should return nonzero value if it processes the exception and wants to continue program execution. Otherwise it should return zero. If all exception handlers in the chain return zero, the exception will be passed on to exec.library trap handler pointed to by tc_TrapCode field of task structure.
An opaque handle that can be used for handler removal or NULL in case of failure (like unsupported exception number).
The specification of this function is preliminary and subject to change. Consider it private for now.
void * KrnAddIRQHandler( uint8_t irq, irqhandler_t * handler, void * handlerData, void * handlerData2 );
Add a raw hardware IRQ handler to the chain of handlers.
num - hardware-specific IRQ number handler - Pointer to a handler function handlerData, handlerData2 - User-defined data which is passed to the handler. Handler function uses a C calling convention and must be declared as follows: void IRQHandler(void *handlerData, void *handlerData2) handlerData and handlerData2 will be values passed to the KrnAddExceptionHandler() function. There is no return code for the IRQ handler.
An opaque handle that can be used for handler removal or NULL in case of failure (like unsupported exception number).
void * KrnAllocPages( void * addr, uintptr_t length, uint32_t flags );
Allocate physical memory pages
addr - Starting address of region which must be included in the allocated region or NULL for the system to choose the starting address. Normally you will supply NULL here. length - Length of the memory region to allocate flags - Flags describing type of needed memory. These are the same flags as passed to exec.library/AllocMem().
Real starting address of the allocated region.
Since this allocator is page-based, length will always be round up to system's memory page size. The same applies to starting address (if specified), it will be rounded down to page boundary. This function works only on systems with MMU support. Without MMU it will always return NULL.
int KrnBug( const char * format, va_list args );
Output a formatted string to low-level debug output stream. The function supports the same set of formatting specifiers as standard C printf() function.
format - A format string args - A list of arguments
Number of successfully printed characters
void KrnCause();
Run software interrupt processing sequence
None
None
This entry point directly calls interrupt processing routine in supervisor mode. It neither performs any checks of caller status nor obeys interrupt enable state. This function is safe to call only from within user mode. This function is considered internal, and not meant to be called by user's software.
void KrnCli();
Instantly disable interrupts.
None
None
This is low level function, it does not have nesting count and state tracking mechanism. It operates directly on the CPU. Normal applications should consider using exec.library/Disable(). This function isn't implemented on all platforms.
void * KrnCreateContext();
Allocate and initialize CPU context storage area.
None.
A pointer to a CPU context storage area.
CPU context storage is considered private and accessible only from within supevisor mode.
void KrnDeleteContext( void * context );
Free CPU context storage area
context - a pointer to a CPU context storage previously allocated using KrnCreateContext()
None.
void KrnDispatch();
Run the next available task
None
None
This entry point directly calls task dispatch routine in supervisor mode. It neither performs any checks of caller status nor obeys interrupt enable state. After calling this function, caller's task will be replaced by another one, and caller's state will be lost. This function is safe to call only from within user mode. This function is considered internal, and not meant to be called by user's software.
void KrnDisplayAlert( uint32_t code, const char * text );
Inform the user about critical system failure.
code - Corresponding alert code. text - A NULL-terminated text to print out. First three lines are assumed to be a header. Some implementations may print them centered inside a frame.
None. This function is not guaranteed to return.
This function exists for system internal purposes. Please do not call it from within regular applications! In 99% of cases this function will halt or reboot the machine. Certain structures in RAM, as well as video hardware state, will be irreversibly destroyed. 'code' parameter is passed for convenience. Based on it, the system can make a decision to log the alert in debug output and continue, instead of displaying a message and halting. This function is currently experimental. Its definition may change.
int KrnFormatStr( void * putch, const char * format, va_list args );
Format a string using C printf() convention, using 'putch' as character output function.
putch - A pointer to the output function format - A format string args - A list of arguments A character output function needs to be declared as: int myPutCh(int char, void *KernelBase) It is expected to return 1 on success and 0 on failure.
Number of successfully printed characters
void KrnFreePages( void * addr, uintptr_t length );
This function works only on systems with MMU support.
struct TagItem * KrnGetBootInfo();
unsigned int KrnGetCPUCount();
Return total number of processors in the system
None
Number of running CPUs in this system
uint32_t KrnGetCPUMask( uint32_t id );
Return the affinity mask for the specified CPU number
CPU number (as returned by KrnGetCPUNumber())
CPU's affinity mask
uint32_t KrnGetCPUNumber();
Return number of the caller CPU
None
Number of the CPU on which the function is called
KRN_SchedType KrnGetScheduler();
intptr_t KrnGetSystemAttr( uint32_t id );
Get value of internal system attributes. Currently defined attributes are: KATTR_Architecture [.G] (char *) - Name of architecture the kernel built for. KATTR_PeripheralBase [.G] IPTR - IO Base address for ARM peripherals
id - ID of the attribute to get
Value of the attribute
void KrnInitMemory( struct MemHeader * mh );
Initialize kernel memory management on a given memory region
mh - Address of a filled in structure describing the region.
None.
int KrnIsSuper();
Determine if the caller is running in supervisor mode
None
Nonzero for supervisor mode, zero for user mode
Callers should only test the return value against zero. Nonzero values may actually be different, since they may carry some private implementation-dependent information (like CPU privilege level, for example).
int KrnMapGlobal( void * virtual, void * physical, uint32_t length, KRN_MapAttr flags );
int KrnMayGetChar();
Read a single character from low-level debug input stream
None
An ASCII code of the character or -1 if there's no character available
This function never waits. If there is no character available on the stream it just returns with -1
void KrnModifyIRQHandler( void * handle, void * handlerData, void * handlerData2 );
Modify the data passed to a raw hardware IRQ handler.
handle - Existing handle handlerData, handlerData2 - User-defined data which is passed to the handler.
int KrnObtainInput();
Take over low-level debug input hardware and initialize the input
None
Nonzero for success, zero for failure (for example there's no input channel)
void KrnPutChar( char c );
Output a single character to low-level debug output stream
c - A character to output
None
void KrnReleaseInput();
Release low-level debug input hardware and hand it back to the operating system
None
None
void KrnRemExceptionHandler( void * handle );
Remove previously installed CPU exception handler
handle - an opaque handler returned by KrnAddExceptionHandler() function
None
void KrnRemIRQHandler( void * handle );
Remove previously installed hardware IRQ handler
handle - an opaque handler returned by KrnAddIRQHandler() function
None
void KrnSchedule();
Run task scheduling sequence
None
None
This entry point directly calls task scheduling routine in supervisor mode. It neither performs any checks of caller status nor obeys interrupt enable state. This function is safe to call only from within user mode. This function is considered internal, and not meant to be called by user's software.
void KrnSetProtection( void * address, uint32_t length, KRN_MapAttr flags );
void KrnSetScheduler( KRN_SchedType sched );
void KrnSpinInit( spinlock_t * lock );
int KrnSpinIsLocked( spinlock_t * lock );
spinlock_t * KrnSpinLock( spinlock_t * lock, struct Hook * failhook, ULONG mode );
lock - spinlock to lock failhook - called if the lock is already held mode - type of lock to obtain.
returns a pointer to the spinlock "handle".
spinlock_t * KrnSpinTryLock( spinlock_t * lock, ULONG mode );
void KrnSpinUnLock( spinlock_t * lock );
ULONG KrnStatMemoryA( ULONG flags, struct TagItem * query ); ULONG KrnStatMemory( ULONG flags, TAG tag, ... );
Get various statistics about memory usage
query - An array of TagItems containing query specification. Each TagItem consists of tag ID and a pointer to a value of specified type which will contain the result of the query. Available tag IDs are: KMS_Free (IPTR) - Get amount of free memory in bytes KMS_Total (IPTR) - Get total amount of memory in bytes KMS_LargestAlloc (IPTR) - Get size of the largest allocated chunk in bytes KMS_SmallestAlloc (IPTR) - Get size of the smallest allocated chunk in bytes KMS_LargestFree (IPTR) - Get size of the largest free chunk in bytes KMS_SmallestFree (IPTR) - Get size of the smallest free chunk in bytes KMS_NumAlloc (IPTR) - Get number of allocated chunks KMS_NumFree (IPTR) - Get number of free chunks KMS_PageSize (ULONG) - Get memory page size flags - Flags which specify physical properties of the memory to query. These are the same flags as passed to exec.library/AllocMem().
TRUE if the function worked, FALSE if MMU is not up and running on the system. If the function returns FALSE, values will stay uninitialized.
For all unknown tag IDs result values will be set to 0.
void KrnSti();
Instantly enable interrupts.
None
None
This is low level function, it does not have nesting count and state tracking mechanism. It operates directly on the CPU. Normal applications should consider using exec.library/Enable(). This function isn't implemented on all platforms.
void KrnSwitch();
Save context of caller's task and dispatch the next available task
None
None
This entry point directly calls task switch routine in supervisor mode. It neither performs any checks of caller status nor obeys interrupt enable state. After calling this function, caller's task will be replaced by another one, and it's caller's responsibility to do anything to prevent task loss. This function is safe to call only from within user mode. This function is considered internal, and not meant to be called by user's software.
int KrnUnmapGlobal( void * virtual, uint32_t length );
void * KrnVirtualToPhysical( void * virtual );