1/**
2 * \file
3 * \brief Arch specific definition of the registers, can be included by anyone.
4 * Definitions only seen in the user.
5 */
6
7/*
8 * Copyright (c) 2010, 2011, 2012, ETH Zurich.
9 * All rights reserved.
10 *
11 * This file is distributed under the terms in the attached LICENSE file.
12 * If you do not find this file, copies can be found by writing to:
13 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
14 */
15
16#ifndef TARGET_X86_32_BARRELFISH_REGISTERS_H
17#define TARGET_X86_32_BARRELFISH_REGISTERS_H
18
19#include <target/x86_32/barrelfish_kpi/registers_target.h>
20#include <target/x86_32/barrelfish/dispatcher_target.h>
21#include "threads_priv.h"
22
23static inline void
24registers_x86_32_set_initial(struct registers_x86_32 *regs, struct thread *thread,
25                             lvaddr_t entry, lvaddr_t stack, uint32_t arg1,
26                             uint32_t arg2, uint32_t arg3, uint32_t arg4)
27{
28    assert(stack != 0);
29
30    // Put 4 arguments and return address on the function's stack
31    stack -= 5 * 4;
32    uint32_t *sp = (uint32_t *)stack;
33    sp[0] = 0;          // fake return address
34    sp[1] = arg1;
35    sp[2] = arg2;
36    sp[3] = arg3;
37    sp[4] = arg4;
38
39    regs->eip = entry;
40    regs->esp = stack;
41    regs->fs     = 0;
42    regs->gs     = get_dispatcher_x86_32(thread->disp)->disp_seg_selector;
43    regs->cs = USER_CS;
44    regs->ss = USER_SS;
45    regs->eflags = USER_EFLAGS;
46}
47
48#endif // TARGET_X86_32_BARRELFISH_REGISTERS_H
49