| 1 |
2 |
drasko |
.TH UTCB 7 2009-11-02 "Codezero" "Codezero Programmer's Manual"
|
| 2 |
|
|
.SH NAME
|
| 3 |
|
|
.nf
|
| 4 |
|
|
.BR "UTCB" " - Userspace Thread Control Block"
|
| 5 |
|
|
|
| 6 |
|
|
.SH SYNOPSIS
|
| 7 |
|
|
|
| 8 |
|
|
.B #include
|
| 9 |
|
|
|
| 10 |
|
|
|
| 11 |
|
|
.fi
|
| 12 |
|
|
.SH DESCRIPTION
|
| 13 |
|
|
|
| 14 |
|
|
UTCB is a per-thread data structure designated as thread local storage for IPC message registers and private data. The UTCB area in a thread's address space is a virtual address region that is unique for each thread available on the system. It is discovered at run-time by reading the
|
| 15 |
|
|
.BR "Kernel Interface Page"
|
| 16 |
|
|
utcb field.
|
| 17 |
|
|
|
| 18 |
|
|
The UTCB stores message registers that are transferred between threads during an IPC. Depending on whether the IPC is a send or a receive, the message register fields are either transferred to other threads, or overwritten by message registers of other threads. For details on IPC behaviour please refer to the
|
| 19 |
|
|
.BR l4_ipc ()
|
| 20 |
|
|
system call reference page.
|
| 21 |
|
|
|
| 22 |
|
|
.RI "UTCB may also be used for any thread-local information that is private to each thread in an address space. For example on stacked IPCs where a new IPC is initiated before the current IPC has been completed, " "saved_tag " "and " "saved_sender " "fields serve the purpose of saving the unfinished IPC information. For a full description of each field please refer to below. "
|
| 23 |
|
|
.fi
|
| 24 |
|
|
|
| 25 |
|
|
.nf
|
| 26 |
|
|
.B struct utcb {
|
| 27 |
|
|
.BI " u32 " "mr[MR_TOTAL]" "; /* MRs that are mapped to real registers */"
|
| 28 |
|
|
.BI " u32 " "saved_tag" "; /* Saved tag field for stacked ipc */"
|
| 29 |
|
|
.BI " u32 " "saved_sender" "; /* Saved sender field for stacked ipc */"
|
| 30 |
|
|
.BI " u32 " "mr_rest[MR_REST]" "; /* Complete the utcb to 64 words */"
|
| 31 |
|
|
};
|
| 32 |
|
|
|
| 33 |
|
|
.TP
|
| 34 |
|
|
.fi
|
| 35 |
|
|
.I mr[MR_TOTAL]
|
| 36 |
|
|
.RB "Primary message registers. On the ARM Architecture there are 6 of these registers, named as " "MR0 - MR5" ". As an optimisation, these registers may be mapped to real registers by the kernel during an ipc. However this behaviour is not warranted by the kernel API."
|
| 37 |
|
|
|
| 38 |
|
|
.TP
|
| 39 |
|
|
.fi
|
| 40 |
|
|
.I saved_tag
|
| 41 |
|
|
Saved IPC tag field on a stacked IPC.
|
| 42 |
|
|
.TP
|
| 43 |
|
|
.fi
|
| 44 |
|
|
.I saved_sender
|
| 45 |
|
|
Saved sender id on a stacked IPC.
|
| 46 |
|
|
.TP
|
| 47 |
|
|
.fi
|
| 48 |
|
|
.I mr_rest[MR_REST]
|
| 49 |
|
|
.RB "Rest of the message registers located on the UTCB. These registers are transferred upon an ipc only if the ipc type is a " "full ipc" ". See " "l4_ipc" "(7) for more details."
|
| 50 |
|
|
|
| 51 |
|
|
.SH UTCB ALLOCATION
|
| 52 |
|
|
UTCB address and memory allocation is not maintained by Codezero Microkernel. Both UTCB allocation and maintainence is expected to be handled in userspace.
|
| 53 |
|
|
As an example, a pager for a group of threads may use the UTCB management functions to allocate and manage multiple UTCBs. This would be a more complicated but well-addressed approach, since this library would maintain multiple utcb areas across different address spaces, and differentiate between address spaces upon allocation. Otherwise a single address space multi-threaded application may simply use a pool of memory and virtual addresses to manage per-thread UTCB areas.
|
| 54 |
|
|
|
| 55 |
|
|
UTCB addresses may be any virtual address, however there is a restriction that the utcb address region must lie in a disjoint virtual memory region. This is required because when an IPC is established, the kernel does a direct copy between UTCB regions, without the need for page-table manipulation.
|
| 56 |
|
|
|
| 57 |
|
|
The simplest solution to create a UTCB is to simply declare a UTCB size aligned array of utcb structures statically by the below macro:
|
| 58 |
|
|
|
| 59 |
|
|
.BI "#define DECLARE_UTCB(" name ")
|
| 60 |
|
|
.B struct utcb name ALIGN(sizeof(struct utcb))
|
| 61 |
|
|
|
| 62 |
|
|
and use it by:
|
| 63 |
|
|
|
| 64 |
|
|
.B DECLARE_UTCB(utcb);
|
| 65 |
|
|
|
| 66 |
|
|
While this works, it requires the statically allocated structure to lie in a virtual address area that is disjoint from any other virtual address in the system.
|
| 67 |
|
|
|
| 68 |
|
|
.RB "Pagers may set a thread's utcb by the " "l4_exchange_registers() " "system call. Please see " "l4_exchange_registers" "(7) for more details."
|
| 69 |
|
|
|
| 70 |
|
|
.fi
|
| 71 |
|
|
The UTCB structure may be of variable size, and has been set to a total of 256 bytes on an ARM system. The UTCB structure is subject to change. New fields may be reserved on the UTCB as needed.
|
| 72 |
|
|
|
| 73 |
|
|
|
| 74 |
|
|
.in 8
|
| 75 |
|
|
.SH L4 USERSPACE LIBRARY
|
| 76 |
|
|
.nf
|
| 77 |
|
|
|
| 78 |
|
|
/* Functions to read/write utcb registers */
|
| 79 |
|
|
.BI "static inline unsigned int read_mr(int " "offset");
|
| 80 |
|
|
.BI "static inline void write_mr(unsigned int " "offset" ", unsigned int " "val" ")"
|
| 81 |
|
|
|
| 82 |
|
|
.SH SEE ALSO
|
| 83 |
|
|
.BR "l4_ipc"(7), " l4_exchange_registers"(7)
|