1187767Sluigi/*
2187767Sluigi * Copyright 2017, Data61
3187767Sluigi * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4187767Sluigi * ABN 41 687 119 230.
5187767Sluigi *
6187767Sluigi * This software may be distributed and modified according to the terms of
7187767Sluigi * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8187767Sluigi * See "LICENSE_BSD2.txt" for details.
9187767Sluigi *
10187767Sluigi * @TAG(DATA61_BSD)
11187767Sluigi */
12187767Sluigi/*
13187767Sluigi * A default crt0 for ia32. It does the bare minimum required to get into
14187767Sluigi * main() with a sensible C environment.
15187767Sluigi *
16187767Sluigi * This file will only be linked in if:
17187767Sluigi *   - no other file already provides a _start symbol, and
18187767Sluigi *   - _start is an undefined external symbol (force this by passing
19187767Sluigi *     "-u _start" to ld).
20187767Sluigi */
21187767Sluigi
22187767Sluigi#define __ASM__
23187767Sluigi#include <autoconf.h>
24187767Sluigi#include <sel4platsupport/gen_config.h>
25187767Sluigi
26187767Sluigi#ifdef CONFIG_LIB_SEL4_PLAT_SUPPORT_START
27187767Sluigi
28187767Sluigi#include <sel4/arch/constants.h>
29187767Sluigi
30187767Sluigi    .global _start
31187767Sluigi
32187767Sluigi    .text
33187767Sluigi
34187767Sluigi_start:
35187767Sluigi    leal    _stack_top, %esp
36187767Sluigi
37187767Sluigi    /* Setup segment selector for IPC buffer access. */
38187767Sluigi    movw    $IPCBUF_GDT_SELECTOR, %ax
39187767Sluigi    movw    %ax, %fs
40187767Sluigi
41187767Sluigi    /* Setup the global "bootinfo" structure. */
42187767Sluigi    pushl   %ebx
43187767Sluigi    call    seL4_InitBootInfo
44187767Sluigi    addl    $4, %esp
45187767Sluigi
46187767Sluigi    /* Call constructors and other initialisation functions. */
47187767Sluigi    call    _init
48187767Sluigi
49187767Sluigi    /* Start main. */
50187767Sluigi    call    main
51187767Sluigi
52187767Sluigi    /* Call exit with the return value from main. */
53187767Sluigi    pushl   %eax
54187767Sluigi    call    exit
55187767Sluigi1:  jmp     1b
56187767Sluigi
57187767Sluigi    .bss
58187767Sluigi    .balign  8
59187767Sluigi
60187767Sluigi_stack_bottom:
61187767Sluigi    .space  16384
62187767Sluigi_stack_top:
63187767Sluigi
64187767Sluigi#endif /* CONFIG_LIB_SEL4_PLAT_SUPPORT_START */
65187767Sluigi