Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / clients / net-snk / kernel / init.c
1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 #include <stdint.h>
14 #include <string.h>
15 #include <stdlib.h> /* malloc */
16 #include <of.h>
17 #include <pci.h>
18 #include <kernel.h>
19 #include <cpu.h>
20 #include <fileio.h>
21
22 /* Application entry point .*/
23 extern int _start(unsigned char *arg_string, long len);
24 extern int main(int, char**);
25 int _start_kernel(unsigned long p0, unsigned long p1);
26 void * malloc_aligned(size_t size, int align);
27
28 unsigned long exception_stack_frame;
29
30 snk_fileio_t fd_array[FILEIO_MAX];
31
32 extern uint64_t tb_freq;
33
34 extern char __client_start;
35 extern char __client_end;
36
37 void * malloc_aligned(size_t size, int align)
38 {
39         unsigned long p = (unsigned long) malloc(size + align - 1);
40         p = p + align - 1;
41         p = p & ~(align - 1);
42
43         return (void *) p;
44 }
45
46 int _start_kernel(unsigned long p0, unsigned long p1)
47 {
48         int rc;
49         unsigned int timebase;
50
51         /* initialize all file descriptor by marking them as empty */
52         for(rc=0; rc<FILEIO_MAX; ++rc)
53                 fd_array[rc].type = FILEIO_TYPE_EMPTY;
54
55         /* this is step is e.g. resposible to initialize file descriptor 0 and 1 for STDIO */
56         rc = of_glue_init(&timebase, (size_t)(unsigned long)&__client_start,
57                           (size_t)(unsigned long)&__client_end - (size_t)(unsigned long)&__client_start);
58         if(rc < 0)
59                 return -1;
60
61         tb_freq = (uint64_t) timebase;
62         rc = _start((unsigned char *) p0, p1);
63
64         of_glue_release();
65         return rc;
66 }
67