Statistics
| Branch: | Revision:

scoutos / prex-0.9.0 / bsp / hal / x86 / pc / machdep.c @ 03e9c04a

History | View | Annotate | Download (3.3 KB)

1
/*-
2
 * Copyright (c) 2005-2009, Kohsuke Ohtani
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the author nor the names of any co-contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29

    
30
/*
31
 * machdep.c - machine-dependent functions for HAL
32
 */
33

    
34
#include <kernel.h>
35
#include <page.h>
36
#include <machine/syspage.h>
37
#include <sys/power.h>
38
#include <sys/bootinfo.h>
39
#include <mmu.h>
40
#include <cpu.h>
41
#include <cpufunc.h>
42
#include <locore.h>
43

    
44

    
45
#ifdef CONFIG_MMU
46
/*
47
 * Virtual and physical address mapping
48
 *
49
 *      { virtual, physical, size, type }
50
 */
51
static struct mmumap mmumap_table[] =
52
{
53
        /*
54
         * RAM
55
         */
56
        { 0x80000000, 0x00000000, AUTOSIZE, VMT_RAM },
57

    
58
        { 0,0,0,0 }
59
};
60
#endif
61

    
62
/*
63
 * Idle
64
 */
65
void
66
machine_idle(void)
67
{
68

    
69
        cpu_idle();
70
}
71

    
72
/*
73
 * Cause an i386 machine reset.
74
 */
75
static void
76
machine_reset(void)
77
{
78
        int i;
79

    
80
        /*
81
         * Try to do keyboard reset.
82
         */
83
        outb(0x64, 0xfe);
84
        for (i = 0; i < 10000; i++)
85
                outb(0x80, 0);
86

    
87
        /*
88
         * Do cpu reset.
89
         */
90
        cpu_reset();
91

    
92
        /* NOTREACHED */
93
}
94

    
95
/*
96
 * Power down system.
97
 */
98
void
99
machine_powerdown(int state)
100
{
101

    
102
        splhigh();
103

    
104
        DPRINTF(("Power down machine\n\n"));
105

    
106
        switch (state) {
107
        case PWR_SUSPEND:
108
        case PWR_OFF:
109
                for (;;)
110
                        cpu_idle();
111
                /* NOTREACHED */
112
                break;
113
        case PWR_REBOOT:
114
                machine_reset();
115
                /* NOTREACHED */
116
                break;
117
        }
118
}
119

    
120
/*
121
 * Get pointer to the boot information.
122
 */
123
void
124
machine_bootinfo(struct bootinfo **bip)
125
{
126
        ASSERT(bip != NULL);
127

    
128
        *bip = (struct bootinfo *)BOOTINFO;
129
}
130

    
131
void
132
machine_abort(void)
133
{
134

    
135
        for (;;) ;
136
}
137

    
138
/*
139
 * Machine-dependent startup code
140
 */
141
void
142
machine_startup(void)
143
{
144
#ifdef CONFIG_MMU
145
        struct bootinfo *bi = (struct bootinfo *)BOOTINFO;
146
#endif
147

    
148
        /*
149
         * Initialize CPU and basic hardware.
150
         */
151
        cpu_init();
152
        cache_init();
153

    
154
        /*
155
         * Reserve system pages.
156
         */
157
        page_reserve(kvtop(SYSPAGE), SYSPAGESZ);
158

    
159
#ifdef CONFIG_MMU
160
        /*
161
         * Modify page mapping
162
         * We assume the first block in ram[] for x86 is main memory.
163
         */
164
        mmumap_table[0].size = bi->ram[0].size;
165

    
166
        /*
167
         * Initialize MMU
168
         */
169
        mmu_init(mmumap_table);
170
#endif
171
}