1/**
2 * \file
3 * \brief Implementation of curdispatcher
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef ARCH_X86_32_BARRELFISH_CURDISPATCHER_H
16#define ARCH_X86_32_BARRELFISH_CURDISPATCHER_H
17
18/**
19 * \brief Returns pointer to current dispatcher, using thread register
20 */
21static inline dispatcher_handle_t curdispatcher(void)
22{
23    dispatcher_handle_t ret;
24
25    /* %gs refers to the dispatcher, but as a user we can't access it. However,
26     * the udisp field of the dispatcher conveniently contains its
27     * address, so we load that (as an offset from %gs).
28     */
29    // FIXME: this should be using TLS (and have %gs == thread ptr)
30    __asm("movl %%gs:(%c[off]), %[ret]"
31          : [ret] "=r" (ret)
32          : [off] "i" (offsetof(struct dispatcher_shared_generic, udisp)));
33
34    return ret;
35}
36
37#endif // ARCH_X86_32_BARRELFISH_CURDISPATCHER_H
38