Subversion Repositories HelenOS

Rev

Rev 2274 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2274 Rev 2280
Line 44... Line 44...
44
 
44
 
45
#include <arch/debug_print/print.h>
45
#include <arch/debug_print/print.h>
46
#include <print.h>
46
#include <print.h>
47
#include <config.h>
47
#include <config.h>
48
#include <interrupt.h>
48
#include <interrupt.h>
49
#include <arch/machine.h>
49
#include <arch/regutils.h>
50
 
-
 
-
 
50
//#include <arch/drivers/init.h>
-
 
51
#include <userspace.h>
51
bootinfo_t bootinfo;
52
bootinfo_t bootinfo;
52
 
53
 
-
 
54
//TODO: Remove include and move into exceptio.c
-
 
55
#include <arch/exception.h>
-
 
56
 
-
 
57
#include <syscall/syscall.h>
-
 
58
static void tmp_swi_exception(int exc_no, istate_t* istate)
-
 
59
{
-
 
60
    ASSERT(exc_no == EXC_SWI);
-
 
61
    ASSERT(istate);
-
 
62
    // TODO: Alf ... remove aftet swi_exception is tested
-
 
63
    dprintf("\nSWI - istate dump input :\n");
-
 
64
    dprintf("    r0:%X    r1:%X    r2:%X    r3:%X\n", istate->r0,  istate->r1, istate->r2,  istate->r3);
-
 
65
    dprintf("    r4:%X    r5:%X    r6:%X    r7:%X\n", istate->r4,  istate->r5, istate->r6,  istate->r7);
-
 
66
    dprintf("    r8:%X    r8:%X   r10:%X   r11:%X\n", istate->r8,  istate->r9, istate->r10, istate->r11);
-
 
67
    dprintf("   r12:%X    r13:%X    lr:%X  spsr:%X\n", istate->r12, istate->sp, istate->lr,  istate->spsr);
-
 
68
    dprintf("   prev_lr:%X    prev_sp:%X\n", istate->r12, istate->prev_lr, istate->prev_sp);
-
 
69
    // call kernel to serve syscall
-
 
70
    istate->r0 = syscall_handler(
-
 
71
        istate->r0,
-
 
72
        istate->r1,
-
 
73
        istate->r2,
-
 
74
        istate->r3,
-
 
75
        istate->r4);
-
 
76
 
-
 
77
    // TODO: Alf ... remove aftet swi_exception is tested
-
 
78
    dprintf("\nSWI - Istate dump after :\n");
-
 
79
    dprintf("    r0:%X    r1:%X    r2:%X    r3:%X\n", istate->r0,  istate->r1, istate->r2,  istate->r3);
-
 
80
    dprintf("    r4:%X    r5:%X    r6:%X    r7:%X\n", istate->r4,  istate->r5, istate->r6,  istate->r7);
-
 
81
    dprintf("    r8:%X    r8:%X   r10:%X   r11:%X\n", istate->r8,  istate->r9, istate->r10, istate->r11);
-
 
82
    dprintf("   r12:%X    r13:%X    lr:%X  spsr:%X\n", istate->r12, istate->sp, istate->lr,  istate->spsr);
-
 
83
    dprintf("   prev_lr:%X    prev_sp:%X\n", istate->r12, istate->prev_lr, istate->prev_sp);
-
 
84
}
-
 
85
 
-
 
86
 
53
void arch_pre_main(void)
87
void arch_pre_main(void)
54
{
88
{
55
    dprintf("arch_pre_main\n");
89
    dprintf("arch_pre_main\n");
56
    int i;
90
    int i;
57
 
91
 
Line 73... Line 107...
73
    /* It is not assumed by default */
107
    /* It is not assumed by default */
74
    interrupts_disable();
108
    interrupts_disable();
75
   
109
   
76
}
110
}
77
 
111
 
-
 
112
void prefetch_exception_generator(void);
-
 
113
 
78
void arch_post_mm_init(void)
114
void arch_post_mm_init(void)
79
{
115
{
80
    dprintf("arch_post_mm_init start()\n");
116
    dprintf("arch_post_mm_init start()\n");
81
    /* Initialize dispatch table
117
    /* Initialize dispatch table
82
       Note: Have to be after page_init() */
118
       Note: Have to be after page_init() */
83
    exception_init();
119
    exception_init();
84
 
120
 
85
    machine_hw_map_init();
121
//  drivers_init();
86
    interrupt_init();
122
    interrupt_init();
87
   
123
   
88
    console_init(device_assign_devno());
124
//  console_init(device_assign_devno());
89
    //fb_init(0x12000000, 640, 480, 1920, VISUAL_RGB_8_8_8);
125
    //fb_init(0x12000000, 640, 480, 1920, VISUAL_RGB_8_8_8);
90
   
126
   
91
    interrupts_enable();
127
//  interrupts_enable();
-
 
128
//  asm __volatile__ ("ldr pc, =0x70000000"); // prefetch exception
92
//  while(1);
129
    //while(1);
-
 
130
/*
-
 
131
    uspace_arg_t uspace;
-
 
132
    uspace.uspace_entry = (void*)prefetch_exception_generator;
-
 
133
    uspace.uspace_stack = (void*)0x6000000;
-
 
134
        uspace.uspace_uarg  = &uspace;
-
 
135
   
-
 
136
    userspace(&uspace);
-
 
137
*/
93
    dprintf("arch_post_mm_init end()\n");
138
    dprintf("arch_post_mm_init end()\n");
94
}
139
}
95
 
140
 
96
void arch_post_cpu_init(void)
141
void arch_post_cpu_init(void)
97
{
142
{
Line 123... Line 168...
123
void after_thread_ran_arch(void)
168
void after_thread_ran_arch(void)
124
{
169
{
125
    /* TODO */
170
    /* TODO */
126
}
171
}
127
 
172
 
-
 
173
/** Struct to hold general purpose register values */
-
 
174
typedef struct {
-
 
175
    uint32_t r0;
-
 
176
    uint32_t r1;
-
 
177
    uint32_t r2;
-
 
178
    uint32_t r3;
-
 
179
    uint32_t r4;
-
 
180
    uint32_t r5;
-
 
181
    uint32_t r6;
-
 
182
    uint32_t r7;
-
 
183
    uint32_t r8;
-
 
184
    uint32_t r9;
-
 
185
    uint32_t r10;
-
 
186
    uint32_t r11;
-
 
187
    uint32_t r12;
-
 
188
    uint32_t sp;
-
 
189
    uint32_t lr;
-
 
190
    uint32_t pc;
-
 
191
} ustate_t;
-
 
192
 
-
 
193
 
-
 
194
void prefetch_exception_generator(void)  {
-
 
195
 asm __volatile__ (
-
 
196
    "ldr pc, =0x7000000"
-
 
197
 );
-
 
198
 
-
 
199
}
-
 
200
 
-
 
201
/** Change processor mode and jump into addres specified in
-
 
202
 *  kernel_uarg.uspace_entry
-
 
203
 * \param kernel_uarg information needed for correct setting of userspace
-
 
204
 */
-
 
205
void userspace(uspace_arg_t *kernel_uarg)
-
 
206
{
-
 
207
// WILL be changed .. after exception return .. eret will be done
-
 
208
/*
-
 
209
        volatile ustate_t ustate;
-
 
210
    dprintf("userspce krnl_uard  .uspace_uarg(%X), .uspace_entry(%X), .uspace_stack(%X)\n",
-
 
211
      (unsigned int)(kernel_uarg->uspace_uarg),
-
 
212
      kernel_uarg->uspace_entry,
-
 
213
      kernel_uarg->uspace_stack);
-
 
214
    // Step 1 ... prepare user space environmen
-
 
215
    // set first paramater
-
 
216
    ustate.r0 = (uintptr_t) kernel_uarg->uspace_uarg;
-
 
217
    // clear other registers
-
 
218
    ustate.r1 = ustate.r2  = ustate.r3  = ustate.r4  =
-
 
219
        ustate.r5 = ustate.r6  = ustate.r7  = ustate.r8  =
-
 
220
        ustate.r9 = ustate.r10 = ustate.r11 = ustate.r12 = 1;
-
 
221
        ustate.lr = 3;
-
 
222
        // set user stack
-
 
223
        ustate.sp = ((uint32_t)kernel_uarg->uspace_stack)+PAGE_SIZE;
-
 
224
        // set where uspace executin starts
-
 
225
        ustate.pc = (uintptr_t) kernel_uarg->uspace_entry;
-
 
226
 
-
 
227
    // status register in user mode
-
 
228
    ipl_t cpsr = current_status_reg_read();
-
 
229
        cpsr &= ~STATUS_REG_MODE_MASK | USER_MODE;
-
 
230
    //
-
 
231
    ipl_t tmpsr = (cpsr & ~STATUS_REG_MODE_MASK) | ABORT_MODE;
-
 
232
 
-
 
233
    asm __volatile__ (
-
 
234
        "mov r0, %0        \n" // save pointer into ustate struct
-
 
235
        "mov r1, %1        \n" // save cspr
-
 
236
        "msr cpsr_c, %2    \n" // change mode into any exception mode
-
 
237
        "msr spsr_c, r1    \n" // set saved cpsr ... as user mode
-
 
238
        "ldmfd r0, {r0-r12, sp, lr, pc}^\n" // jump into user mode
-
 
239
    : // no output
-
 
240
    : "r"(&ustate), "r"(cpsr), "r"(tmpsr) //
-
 
241
    : "r0","r1"
-
 
242
    );
-
 
243
 
-
 
244
    while(1)
-
 
245
        ;
-
 
246
        */
-
 
247
       
-
 
248
}
128
/** @}
249
/** @}
129
 */
250
 */
-
 
251
 
-
 
252
 
-
 
253
 
-
 
254
 
-
 
255
 
-
 
256
 
-
 
257
 
-
 
258
 
-
 
259
 
-
 
260
 
-
 
261
 
-
 
262
 
-
 
263
 
-
 
264