IBNOS
Functions
util.c File Reference
#include <util/util.h>
#include <console/console.h>
Include dependency graph for util.c:

Go to the source code of this file.

Functions

uint32_t stringLength (const char *str)
 Returns the length of a nullterminated string. More...
 
bool stringIsEqual (const char *str, const char *buf, uint32_t len)
 Checks if the string is equal to the memory region. More...
 
uint32_t stringParseOctal (const char *str, uint32_t len)
 Converts an octal string to a integer number. More...
 
void * memset (void *ptr, int value, size_t num)
 Fills a memory region with some specific byte value. More...
 
void * memcpy (void *destination, const void *source, size_t num)
 Copies a block of memory from source to destination. More...
 
void * memmove (void *destination, const void *source, size_t num)
 Moves a block of memory from source to destination. More...
 
void debugCaptureCpuContext (struct taskContext *context)
 Fills out the task context structure with the values from the currently running code. More...
 
 asm (".text\align 4\ ".globl debugCaptureCpuContext\" "debugCaptureCpuContext:\" " pushl %eax\" " movl 8(%esp), %eax\" "\" " popl 0x28(%eax)\" " movl %ecx, 0x2C(%eax)\" " movl %edx, 0x30(%eax)\" " movl %ebx, 0x34(%eax)\" " leal 4(%esp), %edx\" " movl %edx, 0x38(%eax)\" " movl %ebp, 0x3C(%eax)\" " movl %esi, 0x40(%eax)\" " movl %edi, 0x44(%eax)\" "\" " movw %es, 0x48(%eax)\" " movw %cs, 0x4C(%eax)\" " movw %ss, 0x50(%eax)\" " movw %ds, 0x54(%eax)\" " movw %fs, 0x58(%eax)\" " movw %gs, 0x5C(%eax)\" "\" " movl %cr3, %edx\" " movl %edx, 0x1C(%eax)\" " movl(%esp), %edx\" " movl %edx, 0x20(%eax)\" " pushfl\" " popl 0x24(%eax)\" "\" " ret\")
 
void debugAssertFailed (const char *assertion, const char *file, const char *function, const char *line, struct taskContext *context)
 Used internally to implement assert() More...
 
void debugNotImplemented (const char *file, const char *function, const char *line, struct taskContext *context)
 Used internally to implement NOTIMPLEMENTED() More...
 

Function Documentation

◆ asm()

asm ( ".text\lign 4\".globl debugCaptureCpuContext\" "debugCaptureCpuContext:\" " pushl %eax\" " movl   8%esp,
%eax\" "\" " popl 0x28(%eax)\" " movl %  ecx,
0x2C(%eax)\" " movl %  edx,
0x30(%eax)\" " movl %  ebx,
0x34(%eax)\" " leal 4(%esp)  ,
%edx\" " movl %  edx,
0x38(%eax)\" " movl %  ebp,
0x3C(%eax)\" " movl %  esi,
0x40(%eax)\" " movl %  edi,
0x44(%eax)\" "\" " movw %  es,
0x48(%eax)\" " movw %  cs,
0x4C(%eax)\" " movw %  ss,
0x50(%eax)\" " movw %  ds,
0x54(%eax)\" " movw %  fs,
0x58(%eax)\" " movw %  gs,
0x5C(%eax)\" "\" " movl %  cr3,
%edx\" " movl %  edx,
0x1C(%eax)\" " movl(%esp)  ,
%edx\" " movl %  edx,
0x20(%eax)\" " pushfl\" " popl 0x24(%eax)\" "\" " ret\"   
)

◆ debugAssertFailed()

void debugAssertFailed ( const char *  assertion,
const char *  file,
const char *  function,
const char *  line,
struct taskContext context 
)

Used internally to implement assert()

This function shows an assertion message. Normally it shouldn't be necessary to call this function manually, all values will automatically be filled out by using the assert() macro from util.h.

Parameters
assertionString containing the condition which failed
fileFile in which the assertion occured
functionFunction in which the assertion occured
lineString representing the line number, where the assertion occured
contextTask context structure containing the CPU registers after the error occured

Definition at line 228 of file util.c.

◆ debugCaptureCpuContext()

void debugCaptureCpuContext ( struct taskContext context)

Fills out the task context structure with the values from the currently running code.

This function will capture all registers, segment registers, and control registers and save these values to the task context structure. The stack pointer and EIP will be adjusted, so that they point immediately after this function returns.

Parameters
contextPointer to a task context structure

◆ debugNotImplemented()

void debugNotImplemented ( const char *  file,
const char *  function,
const char *  line,
struct taskContext context 
)

Used internally to implement NOTIMPLEMENTED()

Parameters
fileFile in which the feature is missing
functionFunction in which the assertion occured
lineString representing the line number, where the assertion occured
contextTask context structure containing the CPU registers

Definition at line 251 of file util.c.

◆ memcpy()

void* memcpy ( void *  destination,
const void *  source,
size_t  num 
)

Copies a block of memory from source to destination.

The source and destination blocks shouldn't be overlapping, otherwise it is not safe to call this function. If the regions could be overlapping please use memmove() instead.

Parameters
destinationPointer to the destination memory region
sourcePointer to the source memory region
numLength of the memory region to copy, in bytes
Returns
destination

Definition at line 141 of file util.c.

◆ memmove()

void* memmove ( void *  destination,
const void *  source,
size_t  num 
)

Moves a block of memory from source to destination.

Similar to memcpy(), but will also work safely if both source and destination regions are overlapping.

Parameters
destinationPointer to the destination memory region
sourcePointer to the source memory region
numLength of the memory region to copy, in bytes
Returns
destination

Definition at line 159 of file util.c.

◆ memset()

void* memset ( void *  ptr,
int  value,
size_t  num 
)

Fills a memory region with some specific byte value.

Parameters
ptrPointer to the start of the memory region
valueValue used to fill the memory region
numLength of the memory region in bytes
Returns
ptr

Definition at line 123 of file util.c.

◆ stringIsEqual()

bool stringIsEqual ( const char *  str,
const char *  buf,
uint32_t  len 
)

Checks if the string is equal to the memory region.

Parameters
strPointer to the nullterminated string
bufPointer to a buffer
lenLength of the buffer
Returns
True if both strings are equal, otherwise false

Definition at line 57 of file util.c.

◆ stringLength()

uint32_t stringLength ( const char *  str)

Returns the length of a nullterminated string.

Parameters
strPointer to the nullterminated string
Returns
Length in characters (not including the terminating null character)

Definition at line 37 of file util.c.

◆ stringParseOctal()

uint32_t stringParseOctal ( const char *  str,
uint32_t  len 
)

Converts an octal string to a integer number.

Parameters
strPointer to a string
lenLength of the buffer
Returns
Parsed integer number

Definition at line 84 of file util.c.