Subversion Repositories HelenOS

Rev

Rev 2280 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2128 jermar 1
/*
2159 kebrt 2
 * Copyright (c) 2007 Michal Kebrt
2128 jermar 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
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup arm32
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
 
36
#include <arch.h>
2159 kebrt 37
#include <arch/boot.h>
38
#include <config.h>
2173 kebrt 39
#include <arch/console.h>
40
#include <ddi/device.h>
2263 kebrt 41
#include <genarch/fb/fb.h>
42
#include <genarch/fb/visuals.h>
43
#include <ddi/irq.h>
2235 stepan 44
 
2264 kebrt 45
#include <arch/debug_print/print.h>
2200 jancik 46
#include <print.h>
47
#include <config.h>
2245 stepan 48
#include <interrupt.h>
2280 jancik 49
#include <arch/regutils.h>
50
//#include <arch/drivers/init.h>
51
#include <userspace.h>
2159 kebrt 52
bootinfo_t bootinfo;
53
 
2280 jancik 54
//TODO: Remove include and move into exceptio.c
55
#include <arch/exception.h>
56
 
57
#include <syscall/syscall.h>
2282 jancik 58
void tmp_swi_exception(int exc_no, istate_t* istate);
59
void tmp_swi_exception(int exc_no, istate_t* istate)
2280 jancik 60
{
61
    ASSERT(exc_no == EXC_SWI);
62
    ASSERT(istate);
63
    // TODO: Alf ... remove aftet swi_exception is tested
64
    dprintf("\nSWI - istate dump input :\n");
65
    dprintf("    r0:%X    r1:%X    r2:%X    r3:%X\n", istate->r0,  istate->r1, istate->r2,  istate->r3);
66
    dprintf("    r4:%X    r5:%X    r6:%X    r7:%X\n", istate->r4,  istate->r5, istate->r6,  istate->r7);
67
    dprintf("    r8:%X    r8:%X   r10:%X   r11:%X\n", istate->r8,  istate->r9, istate->r10, istate->r11);
68
    dprintf("   r12:%X    r13:%X    lr:%X  spsr:%X\n", istate->r12, istate->sp, istate->lr,  istate->spsr);
2282 jancik 69
//  dprintf("   prev_lr:%X    prev_sp:%X\n", istate->r12, istate->prev_lr, istate->prev_sp);
2280 jancik 70
    // call kernel to serve syscall
71
    istate->r0 = syscall_handler(
72
        istate->r0,
73
        istate->r1,
74
        istate->r2,
75
        istate->r3,
76
        istate->r4);
77
 
78
    // TODO: Alf ... remove aftet swi_exception is tested
79
    dprintf("\nSWI - Istate dump after :\n");
80
    dprintf("    r0:%X    r1:%X    r2:%X    r3:%X\n", istate->r0,  istate->r1, istate->r2,  istate->r3);
81
    dprintf("    r4:%X    r5:%X    r6:%X    r7:%X\n", istate->r4,  istate->r5, istate->r6,  istate->r7);
82
    dprintf("    r8:%X    r8:%X   r10:%X   r11:%X\n", istate->r8,  istate->r9, istate->r10, istate->r11);
83
    dprintf("   r12:%X    r13:%X    lr:%X  spsr:%X\n", istate->r12, istate->sp, istate->lr,  istate->spsr);
2282 jancik 84
//  dprintf("   prev_lr:%X    prev_sp:%X\n", istate->r12, istate->prev_lr, istate->prev_sp);
2280 jancik 85
}
86
 
87
 
2128 jermar 88
void arch_pre_main(void)
89
{
2264 kebrt 90
    dprintf("arch_pre_main\n");
2159 kebrt 91
    int i;
92
 
93
    init.cnt = bootinfo.cnt;
94
 
95
    for (i = 0; i < bootinfo.cnt; ++i) {
96
        init.tasks[i].addr = bootinfo.tasks[i].addr;
97
        init.tasks[i].size = bootinfo.tasks[i].size;
98
    }
99
 
2245 stepan 100
    /* TODO this code just setups irq testing bed */
2235 stepan 101
    setup_exception_stacks();
2128 jermar 102
}
103
 
104
void arch_pre_mm_init(void)
105
{
2264 kebrt 106
    dprintf("arch_pre_mm_init\n");
2245 stepan 107
 
108
    /* It is not assumed by default */
109
    interrupts_disable();
110
 
2128 jermar 111
}
112
 
2280 jancik 113
void prefetch_exception_generator(void);
114
 
2128 jermar 115
void arch_post_mm_init(void)
116
{
2264 kebrt 117
    dprintf("arch_post_mm_init start()\n");
2270 jancik 118
    /* Initialize dispatch table
119
       Note: Have to be after page_init() */
120
    exception_init();
121
 
2280 jancik 122
//  drivers_init();
2263 kebrt 123
    interrupt_init();
2235 stepan 124
 
2280 jancik 125
//  console_init(device_assign_devno());
2263 kebrt 126
    //fb_init(0x12000000, 640, 480, 1920, VISUAL_RGB_8_8_8);
127
 
2280 jancik 128
//  interrupts_enable();
129
//  asm __volatile__ ("ldr pc, =0x70000000"); // prefetch exception
130
    //while(1);
131
/*
132
    uspace_arg_t uspace;
133
    uspace.uspace_entry = (void*)prefetch_exception_generator;
134
    uspace.uspace_stack = (void*)0x6000000;
135
        uspace.uspace_uarg  = &uspace;
136
 
137
    userspace(&uspace);
138
*/
2264 kebrt 139
    dprintf("arch_post_mm_init end()\n");
2128 jermar 140
}
141
 
142
void arch_post_cpu_init(void)
143
{
144
    /* TODO */
145
}
146
 
147
void arch_pre_smp_init(void)
148
{
149
    /* TODO */
150
}
151
 
152
void arch_post_smp_init(void)
153
{
154
    /* TODO */
155
}
156
 
157
/** Perform arm32 specific tasks needed before the new task is run. */
158
void before_task_runs_arch(void)
159
{
160
    /* TODO */
161
}
162
 
163
/** Perform arm32 specific tasks needed before the new thread is scheduled. */
164
void before_thread_runs_arch(void)
165
{
166
    /* TODO */
167
}
168
 
169
void after_thread_ran_arch(void)
170
{
171
    /* TODO */
172
}
173
 
2280 jancik 174
/** Struct to hold general purpose register values */
175
typedef struct {
176
    uint32_t r0;
177
    uint32_t r1;
178
    uint32_t r2;
179
    uint32_t r3;
180
    uint32_t r4;
181
    uint32_t r5;
182
    uint32_t r6;
183
    uint32_t r7;
184
    uint32_t r8;
185
    uint32_t r9;
186
    uint32_t r10;
187
    uint32_t r11;
188
    uint32_t r12;
189
    uint32_t sp;
190
    uint32_t lr;
191
    uint32_t pc;
192
} ustate_t;
193
 
194
 
195
void prefetch_exception_generator(void)  {
196
 asm __volatile__ (
197
    "ldr pc, =0x7000000"
198
 );
199
 
200
}
201
 
202
/** Change processor mode and jump into addres specified in
203
 *  kernel_uarg.uspace_entry
204
 * \param kernel_uarg information needed for correct setting of userspace
205
 */
206
void userspace(uspace_arg_t *kernel_uarg)
207
{
208
// WILL be changed .. after exception return .. eret will be done
209
/*
210
        volatile ustate_t ustate;
211
    dprintf("userspce krnl_uard  .uspace_uarg(%X), .uspace_entry(%X), .uspace_stack(%X)\n",
212
      (unsigned int)(kernel_uarg->uspace_uarg),
213
      kernel_uarg->uspace_entry,
214
      kernel_uarg->uspace_stack);
215
    // Step 1 ... prepare user space environmen
216
    // set first paramater
217
    ustate.r0 = (uintptr_t) kernel_uarg->uspace_uarg;
218
    // clear other registers
219
    ustate.r1 = ustate.r2  = ustate.r3  = ustate.r4  =
220
        ustate.r5 = ustate.r6  = ustate.r7  = ustate.r8  =
221
        ustate.r9 = ustate.r10 = ustate.r11 = ustate.r12 = 1;
222
        ustate.lr = 3;
223
        // set user stack
224
        ustate.sp = ((uint32_t)kernel_uarg->uspace_stack)+PAGE_SIZE;
225
        // set where uspace executin starts
226
        ustate.pc = (uintptr_t) kernel_uarg->uspace_entry;
227
 
228
    // status register in user mode
229
    ipl_t cpsr = current_status_reg_read();
230
        cpsr &= ~STATUS_REG_MODE_MASK | USER_MODE;
231
    //
232
    ipl_t tmpsr = (cpsr & ~STATUS_REG_MODE_MASK) | ABORT_MODE;
233
 
234
    asm __volatile__ (
235
        "mov r0, %0        \n" // save pointer into ustate struct
236
        "mov r1, %1        \n" // save cspr
237
        "msr cpsr_c, %2    \n" // change mode into any exception mode
238
        "msr spsr_c, r1    \n" // set saved cpsr ... as user mode
239
        "ldmfd r0, {r0-r12, sp, lr, pc}^\n" // jump into user mode
240
    : // no output
241
    : "r"(&ustate), "r"(cpsr), "r"(tmpsr) //
242
    : "r0","r1"
243
    );
2282 jancik 244
*/
2280 jancik 245
    while(1)
246
        ;
247
 
248
}
2128 jermar 249
/** @}
250
 */
2280 jancik 251
 
252
 
253
 
254
 
255
 
256
 
257
 
258
 
259
 
260
 
261
 
262
 
263
 
264