http://www.aros.orgAROS-ExecTeam AROSAROS-Exec Archives

Home

English

Deutsch

Ελληυικά

Français

Italiano

Nederlands

Polski

Português

Русский

Español

Suomi

Svenska

Česky


News

Archive

Introduction

Status
Screenshots
Ports
License

Download


Documentation

Users
Installation
Using
Shell commands
Applications
FAQ
Developers
Contribute
Roadmap
Bug Tracker
Working with Subversion
Compiling
Application Development Manual
Zune Application Development Manual
System Development Manual
Debugging Manual
Reference
Specifications
UI Style Guide
Documenting
Porting
Translating
Summaries
Links

Contact

Mailing lists
IRC channels

Credits

Acknowledgements


Pictures

Developers
Developers en Masse

Sponsors

Linking

Links

SourceForge Logo

exec

Index


AbortIO() AddDevice() AddHead() AddIntServer()
AddLibrary() AddMemHandler() AddMemList() AddPort()
AddResource() AddSemaphore() AddTail() AddTask()
Alert() AllocAbs() Allocate() AllocEntry()
AllocMem() AllocPooled() AllocSignal() AllocTrap()
AllocVec() AttemptSemaphore() AttemptSemaphoreShared() AvailMem()
AVL_AddNode() AVL_FindFirstNode() AVL_FindLastNode() AVL_FindNextNodeByAddress()
AVL_FindNextNodeByKey() AVL_FindNode() AVL_FindPrevNodeByAddress() AVL_FindPrevNodeByKey()
AVL_RemNodeByAddress() AVL_RemNodeByKey() CacheClearE() CacheClearU()
CacheControl() CachePostDMA() CachePreDMA() Cause()
CheckIO() ChildFree() ChildOrphan() ChildStatus()
ChildWait() CloseDevice() CloseLibrary() ColdReboot()
CopyMem() CopyMemQuick() CreateIORequest() CreateMsgPort()
CreatePool() Deallocate() Debug() DeleteIORequest()
DeleteMsgPort() DeletePool() Disable() DoIO()
Enable() Enqueue() FindName() FindPort()
FindResident() FindSemaphore() FindTask() Forbid()
FreeEntry() FreeMem() FreePooled() FreeSignal()
FreeTrap() FreeVec() GetCC() GetMsg()
InitCode() InitResident() InitSemaphore() InitStruct()
Insert() MakeFunctions() MakeLibrary() NewAddTask()
NewAllocEntry() ObtainQuickVector() ObtainSemaphoreList() ObtainSemaphoreShared()
OldOpenLibrary() OpenDevice() OpenLibrary() OpenResource()
Permit() Procure() PutMsg() RawDoFmt()
ReleaseSemaphore() ReleaseSemaphoreList() RemDevice() RemHead()
RemIntServer() RemLibrary() RemMemHandler() Remove()
RemPort() RemResource() RemSemaphore() RemTail()
RemTask() ReplyMsg() SendIO() SetExcept()
SetFunction() SetIntVector() SetSignal() SetSR()
SetTaskPri() Signal() StackSwap() SumKickData()
SumLibrary() SuperState() Supervisor() Switch()
TypeOfMem() UserState() Vacate() VNewRawDoFmt()
Wait() WaitIO() WaitPort()  

AbortIO()

Synopsis

LONG AbortIO(
         struct IORequest * iORequest );

Function

Calls the AbortIO vector of the appropriate device to stop an
asynchronously started io request before completion. This may
or may not be done. You still have to do a WaitIO() on the
iorequest structure.

Inputs

iORequest - Pointer to iorequest structure.

Result

Errorcode if the abort request failed, 0 if the abort request went
well. io_Error will then be set to IOERR_ABORTED.

AddDevice()

Synopsis

void AddDevice(
         struct Device * device );

Function

Adds a given device to the system's device list after checksumming
the device vectors. This function is not for general use but
(of course) for building devices that don't use exec's MakeLibrary()
mechanism.

Inputs

device - Pointer to a ready for use device structure.

AddHead()

Synopsis

void AddHead(
         struct List * list,
         struct Node * node );

Function

Insert Node node as the first node of the list.

Inputs

list - The list to insert the node into
node - This node is to be inserted

Result

None.

Example

struct List * list;
struct Node * pred;

// Insert Node at top
AddHead (list, node);

AddIntServer()

Synopsis

void AddIntServer(
         ULONG intNumber,
         struct Interrupt * interrupt );

Notes

This function also enables the corresponding chipset interrupt if
run on a native Amiga.

AddLibrary()

Synopsis

void AddLibrary(
         struct Library * library );

Function

Adds a given library to the system's library list after checksumming
the library vectors. This function is not for general use but
(of course) for building shared librarys that don't use exec's
MakeLibrary() mechanism.

Inputs

library - Pointer to a ready for use library structure.

Notes

Some old Amiga software expects that AddLibrary returns the
library which was just added. When in binary compatibility mode
AROS does this too.

AddMemHandler()

Synopsis

void AddMemHandler(
         struct Interrupt * memHandler );

Function

Add some function to be called if the system is low on memory.

Inputs

memHandler - An Interrupt structure to add to the low memory
             handler list.

AddMemList()

Synopsis

void AddMemList(
         ULONG size,
         ULONG attributes,
         LONG pri,
         APTR base,
         STRPTR name );

Function

Add a new block of memory to the system memory lists.

Inputs

size       - Size of the block
attributes - The attributes the memory will have
pri        - Priority in the list of MemHeaders
base       - Base address
name       - A name associated with the memory

Notes

No argument checking done.

AddPort()

Synopsis

void AddPort(
         struct MsgPort * port );

Function

Add a port to the public port list. The ln_Name and ln_Pri fields
must be initialized prior to calling this function, while
the port itself is reinitialized before adding. Therefore it's
not allowed to add an active port.

Inputs

port - Pointer to messageport structure.

AddResource()

Synopsis

void AddResource(
         APTR resource );

Function

Adds a given resource to the system's resource list.

Inputs

resource - Pointer to a ready for use resource.

AddSemaphore()

Synopsis

void AddSemaphore(
         struct SignalSemaphore * sigSem );

Function

Adds a semaphore to the system public semaphore list. Since the
semaphore gets initialized by this function it must be free at
this time. Also the ln_Name field must be set.

Inputs

sigSem - Pointer to semaphore structure

Notes

Semaphores are shared between the tasks that use them and must
therefore lie in public (or at least shared) memory.

AddTail()

Synopsis

void AddTail(
         struct List * list,
         struct Node * node );

Function

Insert Node node at the end of a list.

Inputs

list - The list to insert the node into
node - This node is to be inserted

Example

struct List * list;
struct Node * pred;

// Insert Node at end of the list
AddTail (list, node);

AddTask()

Synopsis

APTR AddTask(
         struct Task * task,
         APTR initialPC,
         APTR finalPC );

Function

Add a new task to the system. If the new task has the highest
priority of all and task switches are allowed it will be started
immediately.

You must initialise certain fields, and allocate a stack before
calling this function. The fields that must be initialised are:
tc_SPLower, tc_SPUpper, tc_SPReg, and the tc_Node structure.

If any other fields are initialised to zero, then they will be
filled in with the system defaults.

The value of tc_SPReg will be used as the location for the stack
pointer. You can place any arguments you wish to pass to the Task
onto the stack before calling AddTask(). However note that you may
need to consider the stack direction on your processor.

Memory can be added to the tc_MemEntry list and will be freed when
the task dies. The new task's registers are set to 0.

Inputs

task      - Pointer to task structure.
initialPC - Entry point for the new task.
finalPC   - Routine that is called if the initialPC() function
            returns. A NULL pointer installs the default finalizer.

Result

The address of the new task or NULL if the operation failed.

Alert()

Synopsis

void Alert(
         ULONG alertNum );

Function

Alerts the user of a serious system problem.

Inputs

alertNum - This is a number which contains information about
        the reason for the call.

Result

This routine may return, if the alert is not a dead-end one.

Example

// Dead-End alert: 680x0 Access To Odd Address
Alert (0x80000003);

Notes

You should not call this routine because it halts the machine,
displays the message and then may reboot it.

AllocAbs()

Synopsis

APTR AllocAbs(
         ULONG byteSize,
         APTR location );

Function

Allocate some memory from the system memory pool at a given address.

Inputs

byteSize - Number of bytes you want to get
location - Where you want to get the memory

Result

A pointer to some memory including the requested bytes or NULL if
the memory couldn't be allocated

Allocate()

Synopsis

APTR Allocate(
         struct MemHeader * freeList,
         ULONG byteSize );

Function

Allocate memory out of a private region handled by the MemHeader
structure.

Inputs

freeList - Pointer to the MemHeader structure which holds the memory
byteSize - Number of bytes you want to get

Result

A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated

Example

#define POOLSIZE 4096
\* Get a MemHeader structure and some private memory *\
mh=(struct MemHeader *)
    AllocMem(sizeof(struct MemHeader)+POOLSIZE,MEMF_ANY);
if(mh!=NULL)
{
    \* Build a private pool *\
    mh->mh_First=(struct MemChunk *)(mh+1);
    mh->mh_First->mc_Next=NULL;
    mh->mh_First->mc_Bytes=POOLSIZE;
    mh->mh_Free=POOLSIZE;
    {
        \* Use the pool *\
        UBYTE *mem1,*mem2;
        mem1=Allocate(mh,1000);
        mem2=Allocate(mh,2000);
        \* Do something with memory... *\
    }
    \* Free everything at once *\
    FreeMem(mh,sizeof(struct MemHeader)+POOLSIZE);
}

Notes

The memory is aligned to sizeof(struct MemChunk). All requests
are rounded up to a multiple of that size.

AllocEntry()

Synopsis

struct MemList * AllocEntry(
         struct MemList * entry );

Function

Allocate a number of memory blocks through a MemList structure.

Inputs

entry - The MemList with one MemEntry for each block you want to get

Result

The allocation was successful if the most significant bit of the
result is 0. The result then contains a pointer to a copy of
the MemList structure with the me_Addr fields filled.
If the most significant bit is set the result contains the type of
memory that couldn't be allocated.

AllocMem()

Synopsis

APTR AllocMem(
         ULONG byteSize,
         ULONG requirements );

Function

Allocate some memory from the sytem memory pool with the given
requirements.

Inputs

byteSize     - Number of bytes you want to get
requirements - Type of memory

Result

A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated

Example

mytask=(struct Task *)AllocMem(sizeof(struct Task),MEMF_PUBLIC|MEMF_CLEAR);

Notes

The memory is aligned to sizeof(struct MemChunk). All requests
are rounded up to a multiple of that size.

AllocPooled()

Synopsis

APTR AllocPooled(
         APTR poolHeader,
         ULONG memSize );

Function

Allocate memory out of a private memory pool.

Inputs

poolHeader - Handle of the memory pool
memSize    - Number of bytes you want to get

Result

A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated

AllocSignal()

Synopsis

BYTE AllocSignal(
         LONG signalNum );

Function

Allocate a given signal out of the current task's pool of signals.
Every task has a set of signals to communicate with other tasks.
Half of them are reserved for the system and half of them are
free for general use. Some of the reserved signals (e.g.
SIGBREAKF_CTRL_C) have a defined behaviour and may be used by user
code, however.

You must not allocate or free signals from exception handlers.

Inputs

signalNum - Number of the signal to allocate or -1 if any signal
            will do.

Result

Number of the signal or -1 if the signal couldn't be allocated.

AllocTrap()

Synopsis

LONG AllocTrap(
         long trapNum );

AllocVec()

Synopsis

APTR AllocVec(
         ULONG byteSize,
         ULONG requirements );

Function

Allocate some memory from the sytem memory pool with the given
requirements and without the need to memorize the actual size
of the block.

Inputs

byteSize     - Number of bytes you want to get
requirements - Type of memory

Result

A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated

AttemptSemaphore()

Synopsis

ULONG AttemptSemaphore(
         struct SignalSemaphore * sigSem );

Function

Tries to get an exclusive lock on a signal semaphore. If the semaphore
is already in use by another task this function does not wait but
return false instead.

Inputs

sigSem - Pointer so semaphore structure.

Result

TRUE if the semaphore could be obtained, FALSE otherwise.

Notes

The lock must be freed with ReleaseSemaphore().

AttemptSemaphoreShared()

Synopsis

ULONG AttemptSemaphoreShared(
         struct SignalSemaphore * sigSem );

Function

Tries to get a shared lock on a signal semaphore. If the lock cannot
be obtained false is returned. There may be more than one shared lock
at a time but an exclusive lock prevents all other locks. The lock
must be released with ReleaseSemaphore().

Inputs

sigSem - pointer to semaphore structure

Result

True if the semaphore could be obtained, false otherwise.

AvailMem()

Synopsis

ULONG AvailMem(
         ULONG attributes );

Function

Return either the total available memory or the largest available
chunk of a given type of memory.

Inputs

attributes - The same attributes you would give to AllocMem().

Result

Either the total of the available memory or the largest chunk if
MEMF_LARGEST ist set in the attributes.

Example

Print the total available memory.

printf("Free memory: %lu bytes\n",AvailMem(0));

Print the size of the largest chunk of chip memory.

printf("Largest chipmem chunk: %lu bytes\n",
       AvailMem(MEMF_CHIP|MEMF_LARGEST));

Notes

Due to the nature of multitasking the returned value may already
be obsolete if this function returns.

AVL_AddNode()

Synopsis

struct AVLNode * AVL_AddNode(
         struct AVLNode ** root,
         struct AVLNode * node,
         AVLNODECOMP func );

Function

Add a new node to an AVL tree.

Inputs

Root  - The root node of the tree to which the new node will be added.
        Initially and if the tree is empty, this will be NULL.

Node  - The new node to add.  Any key information must alread be
        initialised.

Func  - A key comparison function.  It will be passed 2 nodes,
        node1 and node2 to compare and must return <0, 0 or >0 to
        reflect node1 < node2, node1 == node, or node1 > node2
        respectively.

Result

NULL if the node was added to the tree, or a pointer to a node with the
same key which already exists in the tree.

Example

This is a fragment which counts the occurances of every word in a file.
Also note that this example embeds the struct AVLNode data at
the start of the structure, so simple casts suffice for translating
AVLNode to ExampleNode addresses.

struct ExampleNode {
    struct AVLNode avl;
    STRPTR key;
    ULONG count;
};

static LONG ExampleNodeComp(const struct AVLNode *a1, const struct AVLNode *a2)
{
    const struct ExampleNode *e1 = (const struct ExampleNode *)a1;
    const struct ExampleNode *e2 = (const struct ExampleNode *)e2;

    return strcmp(a1->key, a2->key);
}

static LONG ExampleKeyComp(const struct AVLNode *a1, AVLKey key)
{
    const struct ExampleNode *e1 = (const struct ExampleNode *)a1;
    char *skey = key;

    return strcmp(a1->key, skey);
}

void CountWords(wordfile)
{
    struct ExampleNode *node;
    struct AVLNode *root = NULL, *check;

    node = AllocMem(sizeof(struct ExampleNode), 0);
    node->count = 1;

    while (node->key = read_word(wordfile)) {
        check = AVL_AddNode(&root, &node->avl, ExampleNodecomp);

        if (check != NULL) {
            struct ExampleNode *work = (struct ExampleNode *)check;

            check->count += 1;
        } else {
            free(node->key);
            node = AllocMem(sizeof(struct ExampleNode), 0);
            node->count = 1;
        }
    }
    FreeMem(node, sizeof(struct ExampleNode));
}

Notes

AVL trees are balanced binary search trees.  This implementation is
based on embedding the struct AVLNode within your own data object
and providing custom comparison functions wherever they are needed.

Two comparison functions are needed for different cases.  It is entirely
up to the application as to how it interprets the nodes and compares
the keys.

AVLNODECOMP is used to compare the keys of two nodes.

typedef LONG *AVLNODECOMP(const struct AVLNode *avlnode1,
                          const struct AVLNode *avlnode2);
        D0                A0, A1

AVLKEYCOMP is used to compare a key to a node.

typedef LONG *AVLKEYCOMP(const struct AVLNode *avlnode,
                         AVLKey key);
        D0               A0, A1

These functions must return the same sense for the same key values.
That is,
    <0  if key of avlnode1 <  key of avlnode2
        if key of avlnode  <  key
     0  if key of avlnode1 == key of avlnode2
        if key of avlnode  == key
    >0  if key of avlnode1 >  key of avlnode2
        if key of avlnode  <  key

Since this function returns the existing node if the keys match,
this function can be used to efficiently add items to the tree or
update existing items without requiring additional lookups.

AVL_FindFirstNode()

Synopsis

struct AVLNode * AVL_FindFirstNode(
         const struct AVLNode * Root );

Function

Find the smallest node in an AVL tree.

Inputs

Root - The root node of the AVL tree.

Result

NULL if the tree is empty (i.e. Root is NULL), or the node
which contains the least value in the tree as determined by
the comparision function used to add the node.

Example

See AVL_FindNextNodeByAddress()

Notes

AVL trees are balanced but not minimal.  This operation
must iterate the full depth of the tree on one side -
approximately 1.44Log(N).

AVL_FindLastNode()

Synopsis

struct AVLNode * AVL_FindLastNode(
         const struct AVLNode * Root );

Function

Find the largest node in an AVL tree.

Inputs

Root - The root node of the AVL tree.

Result

NULL if the tree is empty (i.e. Root is NULL), or the node
which contains the greatest value in the tree as determined by
the comparision function used to add the node.

Example

See AVL_FindPrevNodeByAddress()

Notes

AVL trees are balanced but not minimal.  This operation
must iterate the full depth of the tree on one side -
approximately 1.44Log(N).

AVL_FindNextNodeByAddress()

Synopsis

struct AVLNode * AVL_FindNextNodeByAddress(
         const struct AVLNode * Node );

Function

Perform an in-order traversal to the next node in the tree.

Inputs

Node - The current node.  The node must be present in the tree.

Result

The next-greatest node in the tree, or NULL if Node was already
the highest valued node in the tree.

Example

... in-order traversal of all nodes
node = (struct ExampleNode *)AVL_FindFirstNode(root);
while (node) {
    printf(" %s\n", node->key);
    node = (struct ExampleNode *)AVL_FindNextNodeByAddress(node);
}

... in-order traversal of all nodes - with safe deletion
node = (struct ExampleNode *)AVL_FindFirstNode(root);
next = (struct ExampleNode *)AVL_FindNextNodeByAddress(node);
while (node) {
    printf(" %s\n", node->key);

    if (DELETE_NODE(node))
        AVL_RemNodeByAddress(&root, node);

    node = next;
    next = (struct ExampleNode *)AVL_FindNextNodeByAddress(node);
}

Notes

This implementation uses a parent pointer to avoid needing
a stack or state to track it's current position in the tree.

Although this operation is typically O(1), in the worst case it
iterate the full depth of the tree - approximately 1.44Log(N).

AVL_FindNextNodeByKey()

Synopsis

struct AVLNode * AVL_FindNextNodeByKey(
         const struct AVLNode * Root,
         AVLKEYCOMP func );

Function

Find the node matching the key, or if such a node does not exist,
then the node with the next-highest value.

Inputs

Root - The root of the AVL tree.

key  - The key to search.

func - The AVLKEYCOMP key comparision function for this tree.

Result

A pointer to the struct AVLNode which matches this key, or
if that key is not present in the tree, the next highest node.
Or NULL if key is higher than the key of any node in the tree.

Notes

This is only O(1.44log(n)) in the worst case.

AVL_FindNode()

Synopsis

struct AVLNode * AVL_FindNode(
         const struct AVLNode * Root,
         AVLKEYCOMP func );

Function

Find an entry in the AVL tree by key.

Inputs

Root - The root of the AVL tree.

key  - The key to search.

func - The AVLKEYCOMP key comparision function for this tree.

Result

A pointer to the node matching key if it exists in the
tree, or NULL if no such node exists.

Example

node = (struct ExampleNode *)AVL_FindNode(root, "aros", ExampleKeyComp);
if (node)
    printf(" `%s' occurs %d times\n", node->key, node->count);

AVL_FindPrevNodeByAddress()

Synopsis

struct AVLNode * AVL_FindPrevNodeByAddress(
         const struct AVLNode * Node );

Function

Perform an inverse-order traversal to the previous node in the tree.

Inputs

Node - The current node.  The node must be present in the tree.

Result

The next-least node in the tree, or NULL if Node was already
the lowest valued node in the tree.

Example

... inverse-order traversal of all nodes
node = (struct ExampleNode *)AVL_FindLastNode(root);
while (node) {
    printf(" %s\n", node->key);
    node = (struct ExampleNode *)AVL_FindPrevNodeByAddress(node);
}

... inverse-order traversal of all nodes - with safe deletion
node = (struct ExampleNode *)AVL_FindLastNode(root);
prev = (struct ExampleNode *)AVL_FindPrevNodeByAddress(node);
while (node) {
    printf(" %s\n", node->key);

    if (DELETE_NODE(node))
        AVL_RemNodeByAddress(&root, node);

    node = prev;
    prev = (struct ExampleNode *)AVL_FindPrevNodeByAddress(node);
}

Notes

This implementation uses a parent pointer to avoid needing
a stack or state to track it's current position in the tree.

Although this operation is typically O(1), in the worst case it
iterate the full depth of the tree - approximately 1.44Log(N).

AVL_FindPrevNodeByKey()

Synopsis

struct AVLNode * AVL_FindPrevNodeByKey(
         const struct AVLNode * root,
         AVLKEYCOMP func );

Function

Find the node matching the key, or if such a node does not exist,
then the node with the next-lowest value.

Inputs

Root - The root of the AVL tree.

key  - The key to search.

func - The AVLKEYCOMP key comparision function for this tree.

Result

A pointer to the struct AVLNode which matches this key, or
if that key is not present in the tree, the next lowest node.
Or NULL if key is lower than the key of any node in the tree.

Notes

This is only O(1.44log(n)) in the worst case.

AVL_RemNodeByAddress()

Synopsis

struct AVLNode * AVL_RemNodeByAddress(
         struct AVLNode ** Root,
         struct AVLNode * Node );

Function

Remove a given node from the tree.

Inputs

Root - A pointer to a pointer to the root node of the tree.

Node - A struct AVLNode to remove.  The node must be present
       in the tree.

Result

Node is returned.

Example

See AVL_FindNextNodeByAddress(), AVL_FindPrevNodeByAddress()

Notes

Removing a node may require multiple rebalancing steps
in the tree.  Each step however runs in constant time
and no more than 1.44log(n) steps will be required.

AVL_RemNodeByKey()

Synopsis

struct AVLNode * AVL_RemNodeByKey(
         struct AVLNode ** root,
         AVLKEYCOMP func );

Function

Looks up a node in the tree by key, and removes it if it
is found.

Inputs

Root - A pointer to a pointer to the root node of the AVL tree.

key  - The key to search for.

func - An AVLKEYCOMP function used to compare the key and nodes
       in the tree.

Result

If the key was present in the tree, then a pointer to the node
for that key.  Otherwise NULL if no such key existed in the
tree.

Notes

See AVL_RemNodeByAddress().

CacheClearE()

Synopsis

void CacheClearE(
         APTR address,
         ULONG length,
         ULONG caches );

Function

Flush the contents of the CPU instruction or data caches. If some
of the cache contains dirty data, push it to memory first.

For most systems DMA will not effect processor caches. If *any*
external (non-processor) event changes system memory, you MUST
clear the cache. For example:

    DMA
    Code relocation to run at a different address
    Building jump tables
    Loading code from disk

Inputs

address -   Address to start the operation. This address may be
            rounded DOWN due to hardware granularity.
length  -   Length of the memory to flush. This will be rounded
            up, of $FFFFFFFF to indicate that all addresses
            should be cleared.
caches  -   Bit flags to indicate which caches should be cleared

                CACRF_ClearI    -   Clear the instruction cache
                CACRF_ClearD    -   Clear the data cache

            All other bits are reserved.

Result

The caches will be flushed.

Notes

It is possible that on some systems the entire cache will be
even if this was not the specific request.

CacheClearU()

Synopsis

void CacheClearU();

Function

Flush the entire contents of the CPU instruction and data caches.
If some of the cache contains dirty data, push it to memory first.

For most systems DMA will not effect processor caches. If *any*
external (non-processor) event changes system memory, you MUST
clear the cache. For example:

    DMA
    Code relocation to run at a different address
    Building jump tables
    Loading code from disk

Result

The caches will be flushed.

Notes

It is possible that on some systems the entire cache will be
even if this was not the specific request.

CacheControl()

Synopsis

ULONG CacheControl(
         ULONG cacheBits,
         ULONG cacheMask );

Function

This function will provide global control of all the processor
instruction and data caches. It is not possible to have per
task control.

The actions undertaken by this function are very CPU dependant,
however the actions performed will match the specified options
as close as is possible.

The commands currently defined in the include file exec/execbase.h
are closely related to the cache control register of the Motorola
MC68030 CPU.

Inputs

cacheBits   -   The new state of the bits
cacheMask   -   A mask of the bits you wish to change.

Result

oldBits     -   The complete value of the cache control bits
                prior to the call of this function.

Your requested actions will have been performed. As a side effect
this function will also cause the caches to be cleared.

Notes

On CPU's without a separate instruction and data cache, these will
be considered as equal.

CachePostDMA()

Synopsis

void CachePostDMA(
         APTR address,
         ULONG * length,
         ULONG flags );

void CachePostDM(
         APTR address,
         ULONG * length,
         TAG tag, ... );

Function

Do everything necessary to make CPU caches aware that a DMA has
happened.

Inputs

address - Virtual address of memory affected by the DMA
*length - Number of bytes affected
flags   - DMA_NoModify    - Indicate that the memory did not change.
          DMA_ReadFromRAM - Indicate that the DMA goes from RAM
                            to the device. Set this bit in
                            both calls.

Notes

DMA must follow a call to CachePreDMA() and must be followed
by a call to CachePostDMA().

CachePreDMA()

Synopsis

APTR CachePreDMA(
         APTR address,
         ULONG * length,
         ULONG flags );

APTR CachePreDM(
         APTR address,
         ULONG * length,
         TAG tag, ... );

Function

Do everything necessary to make CPU caches aware that a DMA
will happen. Virtual memory systems will make it possible
that your memory is not at one block and not at the address
you thought. This function gives you all the information
you need to split the DMA request up and to convert virtual
to physical addresses.

Inputs

address - Virtual address of memory affected by the DMA
*length - Number of bytes affected
flags   - DMA_Continue    - This is a call to continue a
                            request that was broken up.
          DMA_ReadFromRAM - Indicate that the DMA goes from
                            RAM to the device. Set this bit
                            in both calls.

Result

The physical address in memory.
*length contains the number of contiguous bytes in physical
memory.

Notes

DMA must follow a call to CachePreDMA() and must be followed
by a call to CachePostDMA().

Cause()

Synopsis

void Cause(
         struct Interrupt * softint );

Function

Schedule a software interrupt to occur. If the processor is
currently running a user task, then the software interrupt will
prempt the current task and run itself. From a real interrupt, it
will queue the software interrupt for a later time.

Software interrupts are useful from hardware interrupts if you
wish to defer your processing down to a lower level. They can
also be used in some special cases of device I/O. The timer.device
and audio.device allow software interrupt driven timing and
audio output respectively.

Software interrupts are restricted to 5 different priority levels,
+32, +16, 0, -16, -32.

Software interrupts can only be scheduled once.

The software interrupt is called with the following prototype:

AROS_UFH3(void, YourIntCode,
    AROS_UFHA(APTR, interruptData, A1),
    AROS_UFHA(APTR, interruptCode, A5),
    AROS_UFHA(struct ExecBase *, SysBase, A6))

The interruptData is the value of the is_Data field, interruptCode
is the value of the is_Code field - it is included for historical
and compatibility reasons. You can ignore the value of interruptCode,
but you must declare it.

Inputs

softint     -   The interrupt you wish to schedule. When setting up
                you should set the type of the interrupt to either
                NT_INTERRUPT or NT_UNKNOWN.

Result

The software interrupt will be delivered, or queued for later
delivery.

Notes

No bounds checking on the software interrupt priority is done.
Passing a bad priority to the system can have a strange effect.

Bugs

Older versions of the Amiga operating system require that the
software interrupts preserve the A6 register.

Software interrupts which are added from a software interrupt of
lower priority may not be called immediately.

CheckIO()

Synopsis

struct IORequest * CheckIO(
         struct IORequest * iORequest );

Function

Check if an I/O request is completed.

Inputs

iORequest - Pointer to iorequest structure.

Result

Pointer to the iorequest structure or NULL if the device is still
at work.

ChildFree()

Synopsis

void ChildFree(
         APTR tid );

Function

Clean up after a child process.

Inputs

tid     --  Id of the child to clean up. This is not the same as
            the Task pointer.

Result

The child will be freed.

Notes

This function will work correctly only for child tasks that are
processes created with NP_NotifyOnDeath set to TRUE.

Calling ChildFree() on a running child is likely to crash your
system badly.

ChildOrphan()

Synopsis

ULONG ChildOrphan(
         APTR tid );

Function

ChildOrphan() will detach the specified task from the its parent
task child task tree. This is useful if the parent task will be
exiting, and no longer needs to be told about child task events.

Note that the default Task finaliser will orphan any remaining
children when the task exits. This function can be used if you just
do not wish to be told about a particular task.

Inputs

tid     --  The ID of the task to orphan, or 0 for all tasks. Note
            that this is NOT the pointer to the task.

Result

Will return 0 on success or CHILD_* on an error.

The child/children will no longer participate in child task
actions.

ChildStatus()

Synopsis

ULONG ChildStatus(
         APTR tid );

Function

Return the status of a child task. This allows the Task to
determine whether a particular child task is still running or not.

Inputs

tid     --  The ID of the task to examine. Note that this is _NOT_
            a task pointer.

Result

One of the CHILD_* values.

Notes

This function will work correctly only for child tasks that are
processes created with NP_NotifyOnDeath set to TRUE. Otherwise
it may report CHILD_NOTFOUND even if child already exited.

ChildWait()

Synopsis

IPTR ChildWait(
         APTR tid );

Function

Wait for either a specific child task, or any child task to finish.
If you specify tid = 0, then this call will return when any child
task exits, otherwise it will not return until the requested task
finishes.

Note that the tid is NOT the task control block (ie struct Task *),
rather it is the value of the ETask et_UniqueID field. Passing in a
Task pointer will cause your Task to deadlock.

You must call ChildFree() on the returned task before calling
ChildWait() again. Ie.

    struct ETask *et;

    et = ChildWait(0);
    ChildFree(et->et_UniqueID);

Inputs

tid -   The UniqueID of a task.

Result

Returns either the ETask structure of the child, or one of the
CHILD_* values on error.

This allows you to work out which of the children has exited.

Notes

This function will work correctly only for child tasks that are
processes created with NP_NotifyOnDeath set to TRUE.

Calling ChildWait() on a task that isn't your child will result in
a deadlock.

Bugs

Be careful with the return result of this function.

CloseDevice()

Synopsis

void CloseDevice(
         struct IORequest * iORequest );

Function

Closes a previously opened device. Any outstanding I/O requests must
be finished. It is safe to call CloseDevice with a cleared iorequest
structure or one that failed to open.

Inputs

iORequest - Pointer to iorequest structure.

CloseLibrary()

Synopsis

void CloseLibrary(
         struct Library * library );

Function

Closes a previously opened library. It is legal to call this function
with a NULL pointer.

Inputs

library - Pointer to library structure or NULL.

ColdReboot()

Synopsis

void ColdReboot();

Function

This function will reboot the computer.

Inputs

None.

Result

This function does not return.

Notes

It can be quite harmful to call this function. It may be possible that
you will lose data from other tasks not having saved, or disk buffers
not being flushed. Plus you could annoy the (other) users.

CopyMem()

Synopsis

void CopyMem(
         CONST_APTR source,
         APTR dest,
         ULONG size );

Function

Copy some memory from one destination in memory to another using
a fast copying method.

Inputs

source - Pointer to source area
dest   - Pointer to destination
size   - number of bytes to copy

Notes

The source and destination area are not allowed to overlap.

CopyMemQuick()

Synopsis

void CopyMemQuick(
         CONST_APTR source,
         APTR dest,
         ULONG size );

Function

Copy some longwords from one destination in memory to another using
a fast copying method.

Inputs

source - Pointer to source area (must be ULONG aligned)
dest   - Pointer to destination (must be ULONG aligned)
size   - number of bytes to copy (must be a multiple of sizeof(ULONG))

Notes

The source and destination area are not allowed to overlap.

CreateIORequest()

Synopsis

struct IORequest * CreateIORequest(
         struct MsgPort * ioReplyPort,
         ULONG size );

Function

Create an I/O request structure bound to a given messageport.
I/O requests are normally used to communicate with exec devices
but can be used as normal messages just as well.

Inputs

ioReplyPort - Pointer to that one of your messageports where
              the messages are replied to. A NULL port is legal
              but then the function fails always.
size        - Size of the message structure including the struct
              IORequest header. The minimal allowable size is that
              of a struct Message.

Result

Pointer to a new I/O request structure or NULL if the function
failed.

CreateMsgPort()

Synopsis

struct MsgPort * CreateMsgPort();

Function

Create a new message port. A signal will be allocated and the message
port set to signal you task

Result

Pointer to messageport structure

CreatePool()

Synopsis

APTR CreatePool(
         ULONG requirements,
         ULONG puddleSize,
         ULONG threshSize );

Function

Create a private pool for memory allocations.

Inputs

requirements - The type of the memory
puddleSize   - The number of bytes that the pool expands
               if it is too small.
threshSize   - Allocations beyond the threshSize are given
               directly to the system. threshSize must be
               smaller or equal than the puddleSize.

Result

A handle for the memory pool or NULL if the pool couldn't
be created

Example

\* Get the handle to a private memory pool *\
po=CreatePool(MEMF_ANY,16384,8192);
if(po!=NULL)
{
    \* Use the pool *\
    UBYTE *mem1,*mem2;
    mem1=AllocPooled(po,1000);
    mem2=AllocPooled(po,2000);
    \* Do something with the memory... *\

    \* Free everything at once *\
    DeletePool(po);
}

Deallocate()

Synopsis

void Deallocate(
         struct MemHeader * freeList,
         APTR memoryBlock,
         ULONG byteSize );

Function

Free block of memory associated with a given MemHandler structure.

Inputs

freeList    - Pointer to the MemHeader structure
memoryBlock - Pointer to the memory to be freed
byteSize    - Size of the block

Notes

The start and end borders of the block are aligned to
a multiple of sizeof(struct MemChunk) and to include the block.

Debug()

Synopsis

void Debug(
         unsigned long flags );

DeleteIORequest()

Synopsis

void DeleteIORequest(
         struct IORequest * iorequest );

Function

Delete an I/O request created with CreateIORequest().

Inputs

iorequest - Pointer to I/O request structure or NULL.

DeleteMsgPort()

Synopsis

void DeleteMsgPort(
         struct MsgPort * port );

Function

Delete a messageport allocated with CreateMsgPort(). The signal bit
is freed and the memory is given back to the memory pool. Remaining
messages are not replied. It is safe to call this function with a
NULL pointer.

Inputs

port - Pointer to messageport structure.

DeletePool()

Synopsis

void DeletePool(
         APTR poolHeader );

Function

Delete a pool including all it's memory.

Inputs

poolHeader - The pool allocated with CreatePool() or NULL.

Disable()

Synopsis

void Disable();

Function

This function will prevent interrupts from occuring. You can
start the interrupts again with a call to Enable().

Note that calls to Disable() nest, and for every call to
Disable() you need a matching call to Enable().

***** WARNING *****

Using this function is considered very harmful, and it is
not recommended to use this function for ** ANY ** reason.

It is quite possible to either crash the system, or to prevent
normal activities (disk/port i/o) from occuring.

Note: As taskswitching is driven by the interrupts subsystem,
      this function has the side effect of disabling
      multitasking.

Result

Interrupts will be disabled AFTER this call returns.

Example

No you DEFINITELY don't want to use this function.

Notes

This function preserves all registers.

To prevent deadlocks calling Wait() in disabled state breaks
the disable - thus interrupts may happen again.

Bugs

The only architecture that you can rely on the registers being
saved is on the Motorola mc68000 family.

DoIO()

Synopsis

BYTE DoIO(
         struct IORequest * iORequest );

Function

Start an I/O request by calling the devices's BeginIO() vector.
It waits until the request is complete.

Inputs

iORequest - Pointer to iorequest structure.

Enable()

Synopsis

void Enable();

Function

This function will allow interrupts to occur after they have
been disabled by Disable().

Note that calls to Disable() nest, and for every call to
Disable() you need a matching call to Enable().

***** WARNING *****

Using this function is considered very harmful, and it is
not recommended to use this function for ** ANY ** reason.

It is quite possible to either crash the system, or to prevent
normal activities (disk/port i/o) from occuring.

Note: As taskswitching is driven by the interrupts subsystem,
      this function has the side effect of disabling
      multitasking.

Inputs

None.

Result

Interrupts will be enabled again when this call returns.

Example

No you DEFINITATELY don't want to use this function.

Notes

This function preserves all registers.

To prevent deadlocks calling Wait() in disabled state breaks
the disable - thus interrupts may happen again.

Bugs

The only architecture that you can rely on the registers being
saved is on the Motorola mc68000 family.

Enqueue()

Synopsis

void Enqueue(
         struct List * list,
         struct Node * node );

Function

Sort a node into a list. The sort-key is the field node->ln_Pri.
The node will be inserted into the list before the first node
with lower priority. This creates a FIFO queue for nodes with
the same priority.

Inputs

list - Insert into this list. The list has to be in descending
        order in respect to the field ln_Pri of all nodes.
node - This node is to be inserted. Note that this has to
        be a complete node and not a MinNode !

Result

The new node will be inserted before nodes with lower
priority.

Example

struct List * list;
struct Node * node;

node->ln_Pri = 5;

// Sort the node at the correct place into the list
Enqueue (list, node);

Notes

The list has to be in descending order in respect to the field
ln_Pri of all nodes.

FindName()

Synopsis

struct Node * FindName(
         struct List * list,
         const UBYTE * name );

Function

Look for a node with a certain name in a list.

Inputs

list - Search this list.
name - This is the name to look for.

Example

struct List * list;
struct Node * node;

// Look for a node with the name "Hello"
node = FindName (list, "Hello");

Notes

The search is case-sensitive, so "Hello" will not find a node
named "hello".

The list must contain complete Nodes and no MinNodes.

When supplied with a NULL list argument, defaults to the exec port list.

FindPort()

Synopsis

struct MsgPort * FindPort(
         STRPTR name );

Function

Look for a public messageport by name. This function doesn't
arbitrate for the port list and must be protected with a Forbid()
Permit() pair.

Inputs

port - Pointer to NUL terminated C string.

Result

Pointer to struct MsgPort or NULL if there is no port of that name.

FindResident()

Synopsis

struct Resident * FindResident(
         const UBYTE * name );

Function

Search for a Resident module in the system resident list.

Inputs

name - pointer to the name of a Resident module to find

Result

pointer to the Resident module (struct Resident *), or null if
not found.

FindSemaphore()

Synopsis

struct SignalSemaphore * FindSemaphore(
         STRPTR name );

Function

Find a semaphore with a given name in the system global semaphore list.
Note that this call doesn't arbitrate for the list - use Forbid() to
do this yourself.

Inputs

name - Pointer to name.

Result

Address of semaphore structure found or NULL.

FindTask()

Synopsis

struct Task * FindTask(
         STRPTR name );

Function

Find a task with a given name or get the address of the current task.
Finding the address of the current task is a very quick function
call, but finding a special task is a very CPU intensive instruction.
Note that generally a task may already be gone when this function
returns.

Inputs

name - Pointer to name or NULL for current task.

Result

Address of task structure found.

Forbid()

Synopsis

void Forbid();

Function

Forbid any further taskswitches until a matching call to Permit().
Naturally disabling taskswitches means:

THIS CALL IS DANGEROUS

Do not use it without thinking very well about it or better
do not use it at all. Most of the time you can live without
it by using semaphores or similar.

Calls to Forbid() nest, i.e. for each call to Forbid() you
need one call to Permit().

Inputs

None.

Result

The multitasking state will be disabled AFTER this function
returns to the caller.

Example

No you really don't want to use this function.

Notes

This function preserves all registers.

To prevent deadlocks calling Wait() in forbidden state breaks
the forbid - thus taskswitches may happen again.

Bugs

The only architecture that you can rely on the registers being
saved is on the Motorola mc68000 family.

FreeEntry()

Synopsis

void FreeEntry(
         struct MemList * entry );

Function

Free some memory allocated with AllocEntry().

Inputs

entry - The MemList you got from AllocEntry().

FreeMem()

Synopsis

void FreeMem(
         APTR memoryBlock,
         ULONG byteSize );

Function

Give a block of memory back to the system pool.

Inputs

memoryBlock - Pointer to the memory to be freed
byteSize    - Size of the block

FreePooled()

Synopsis

void FreePooled(
         APTR poolHeader,
         APTR memory,
         ULONG memSize );

Function

Free memory allocated out of a private memory pool.

Inputs

poolHeader - Handle of the memory pool
memory     - Pointer to the memory
memSize    - Size of the memory chunk

FreeSignal()

Synopsis

void FreeSignal(
         LONG signalNum );

Function

Free a signal allocated with AllocSignal().

Inputs

signalNum - Number of the signal to free or -1 to do nothing.

FreeTrap()

Synopsis

void FreeTrap(
         long trapNum );

FreeVec()

Synopsis

void FreeVec(
         APTR memoryBlock );

Function

Free some memory previously allocated with AllocVec().

Inputs

memoryBlock - The memory to be freed. It is safe to try to free a NULL
              pointer.

GetCC()

Synopsis

UWORD GetCC();

Function

Read the contents of the CPU condition code register in a system
independant way. The flags return will be in the same format as
the Motorola MC680x0 family of microprocessors.

Inputs

None.

Result

The CPU condition codes or ~0ul if this function has not been
implemented.

Bugs

This function may not be implemented on platforms other than
Motorola mc680x0 processors.

GetMsg()

Synopsis

struct Message * GetMsg(
         struct MsgPort * port );

Function

Get a message from a given messageport. This function doesn't wait
and returns NULL if the messageport is empty. Therefore it's
generally a good idea to WaitPort() or Wait() on the given port first.

Inputs

port - Pointer to messageport

Result

Pointer to message removed from the port.

InitCode()

Synopsis

void InitCode(
         ULONG startClass,
         ULONG version );

Function

Traverse the ResModules array and InitResident() all modules with
versions greater than or equal to version, and of a class equal to
startClass.

Inputs

startClass - which type of module to start
version - a version number

InitResident()

Synopsis

APTR InitResident(
         struct Resident * resident,
         BPTR segList );

Function

Test the resident structure and build the library or device
with the information given therein. The Init() vector is
called and the base address returned.

The Init() vector is called with the following registers:
        D0 = 0
        A0 = segList
        A6 = ExecBase

Inputs

resident - Pointer to resident structure.
segList  - Pointer to loaded module, 0 for resident modules.

Result

A pointer returned from the Init() vector. Usually this is the
base of the library/device/resource. NULL for failure.

Notes

AUTOINIT modules are automatically added to the correct exec list.
Non AUTOINIT modules have to do all the work themselves.

InitSemaphore()

Synopsis

void InitSemaphore(
         struct SignalSemaphore * sigSem );

Function

Prepares a semaphore structure for use by the exec semaphore system,
i.e. this function must be called after allocating the semaphore and
before using it or the semaphore functions will fail.

Inputs

sigSem - Pointer to semaphore structure

Notes

Semaphores are shared between the tasks that use them and must
therefore lie in public (or at least shared) memory.

InitStruct()

Synopsis

void InitStruct(
         APTR initTable,
         APTR memory,
         ULONG size );

Function

Initialize some library base or other structure depending on the
information in the init table. The init table consists of
instructions starting with an action byte followed by more
information. The instruction byte looks like:

iisscccc where ii is the instruction code:
                  0 - copy following c+1 elements
                  1 - repeat following element c+1 times
                  2 - take next byte as offset, then copy
                  3 - take the next 3 bytes (in the machine's
                      particular byte ordering) as offset, then
                      copy
               ss is the element size
                  0 - LONGs
                  1 - WORDs
                  2 - BYTEs
                  3 - QUADs
               cccc is the element count-1

Instruction bytes must follow the same alignment restrictions as LONGs;
the following elements are aligned to their particular restrictions.

A 0 instruction ends the init table.