Subversion Repositories HelenOS

Rev

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

Rev 3022 Rev 4055
Line 31... Line 31...
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch.h>
35
#include <arch.h>
36
#include <arch/boot.h>
-
 
37
#include <arch/cp0.h>
36
#include <arch/cp0.h>
38
#include <arch/exception.h>
37
#include <arch/exception.h>
39
#include <mm/as.h>
38
#include <mm/as.h>
40
 
39
 
41
#include <userspace.h>
40
#include <userspace.h>
Line 46... Line 45...
46
#include <print.h>
45
#include <print.h>
47
#include <syscall/syscall.h>
46
#include <syscall/syscall.h>
48
#include <sysinfo/sysinfo.h>
47
#include <sysinfo/sysinfo.h>
49
 
48
 
50
#include <arch/interrupt.h>
49
#include <arch/interrupt.h>
51
#include <arch/drivers/arc.h>
-
 
52
#include <console/chardev.h>
50
#include <console/chardev.h>
-
 
51
#include <arch/barrier.h>
53
#include <arch/debugger.h>
52
#include <arch/debugger.h>
54
#include <genarch/fb/fb.h>
53
#include <genarch/fb/fb.h>
55
#include <genarch/fb/visuals.h>
54
#include <genarch/fb/visuals.h>
56
#include <macros.h>
55
#include <macros.h>
57
#include <ddi/device.h>
56
#include <ddi/device.h>
-
 
57
#include <config.h>
-
 
58
#include <string.h>
-
 
59
#include <arch/drivers/msim.h>
58
 
60
 
59
#include <arch/asm/regname.h>
61
#include <arch/asm/regname.h>
60
 
62
 
61
/* Size of the code jumping to the exception handler code
63
/* Size of the code jumping to the exception handler code
62
 * - J+NOP
64
 * - J+NOP
63
 */
65
 */
64
#define EXCEPTION_JUMP_SIZE    8
66
#define EXCEPTION_JUMP_SIZE  8
65
 
67
 
66
#define TLB_EXC ((char *) 0x80000000)
68
#define TLB_EXC    ((char *) 0x80000000)
67
#define NORM_EXC ((char *) 0x80000180)
69
#define NORM_EXC   ((char *) 0x80000180)
68
#define CACHE_EXC ((char *) 0x80000100)
70
#define CACHE_EXC  ((char *) 0x80000100)
69
 
71
 
70
 
72
 
71
/* Why the linker moves the variable 64K away in assembler
73
/* Why the linker moves the variable 64K away in assembler
72
 * when not in .text section ????????
74
 * when not in .text section?
73
 */
75
 */
74
uintptr_t supervisor_sp __attribute__ ((section (".text")));
-
 
-
 
76
 
75
/* Stack pointer saved when entering user mode */
77
/* Stack pointer saved when entering user mode */
76
/* TODO: How do we do it on SMP system???? */
-
 
77
bootinfo_t bootinfo __attribute__ ((section (".text")));
78
uintptr_t supervisor_sp __attribute__ ((section (".text")));
-
 
79
 
-
 
80
count_t cpu_count = 0;
78
 
81
 
-
 
82
/** Performs mips32-specific initialization before main_bsp() is called. */
79
void arch_pre_main(void)
83
void arch_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
80
{
84
{
81
    /* Setup usermode */
85
    /* Setup usermode */
82
    init.cnt = bootinfo.cnt;
86
    init.cnt = bootinfo->cnt;
83
   
87
   
84
    uint32_t i;
88
    count_t i;
-
 
89
    for (i = 0; i < min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
-
 
90
        init.tasks[i].addr = bootinfo->tasks[i].addr;
-
 
91
        init.tasks[i].size = bootinfo->tasks[i].size;
-
 
92
        strncpy(init.tasks[i].name, bootinfo->tasks[i].name,
-
 
93
            CONFIG_TASK_NAME_BUFLEN);
-
 
94
    }
85
   
95
   
86
    for (i = 0; i < bootinfo.cnt; i++) {
96
    for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
87
        init.tasks[i].addr = bootinfo.tasks[i].addr;
97
        if ((bootinfo->cpumap & (1 << i)) != 0)
88
        init.tasks[i].size = bootinfo.tasks[i].size;
98
            cpu_count++;
89
    }
99
    }
90
}
100
}
91
 
101
 
92
void arch_pre_mm_init(void)
102
void arch_pre_mm_init(void)
93
{
103
{
94
    /* It is not assumed by default */
104
    /* It is not assumed by default */
95
    interrupts_disable();
105
    interrupts_disable();
96
   
106
   
97
    /* Initialize dispatch table */
107
    /* Initialize dispatch table */
98
    exception_init();
108
    exception_init();
99
    arc_init();
-
 
100
 
109
 
101
    /* Copy the exception vectors to the right places */
110
    /* Copy the exception vectors to the right places */
102
    memcpy(TLB_EXC, (char *) tlb_refill_entry, EXCEPTION_JUMP_SIZE);
111
    memcpy(TLB_EXC, (char *) tlb_refill_entry, EXCEPTION_JUMP_SIZE);
-
 
112
    smc_coherence_block(TLB_EXC, EXCEPTION_JUMP_SIZE);
103
    memcpy(NORM_EXC, (char *) exception_entry, EXCEPTION_JUMP_SIZE);
113
    memcpy(NORM_EXC, (char *) exception_entry, EXCEPTION_JUMP_SIZE);
-
 
114
    smc_coherence_block(NORM_EXC, EXCEPTION_JUMP_SIZE);
104
    memcpy(CACHE_EXC, (char *) cache_error_entry, EXCEPTION_JUMP_SIZE);
115
    memcpy(CACHE_EXC, (char *) cache_error_entry, EXCEPTION_JUMP_SIZE);
-
 
116
    smc_coherence_block(CACHE_EXC, EXCEPTION_JUMP_SIZE);
105
   
117
   
106
    /*
118
    /*
107
     * Switch to BEV normal level so that exception vectors point to the kernel.
119
     * Switch to BEV normal level so that exception vectors point to the
108
     * Clear the error level.
120
     * kernel. Clear the error level.
109
     */
121
     */
-
 
122
    cp0_status_write(cp0_status_read() &
110
    cp0_status_write(cp0_status_read() & ~(cp0_status_bev_bootstrap_bit|cp0_status_erl_error_bit));
123
        ~(cp0_status_bev_bootstrap_bit | cp0_status_erl_error_bit));
111
 
124
   
112
    /*
125
    /*
113
     * Mask all interrupts
126
     * Mask all interrupts
114
     */
127
     */
115
    cp0_mask_all_int();
128
    cp0_mask_all_int();
116
       
129
   
117
    debugger_init();
130
    debugger_init();
118
}
131
}
119
 
132
 
120
void arch_post_mm_init(void)
133
void arch_post_mm_init(void)
121
{
134
{
122
    interrupt_init();
135
    interrupt_init();
123
    console_init(device_assign_devno());
136
    msim_console(device_assign_devno());
124
#ifdef CONFIG_FB
137
#ifdef CONFIG_FB
-
 
138
    /* GXemul framebuffer */
-
 
139
    fb_properties_t gxemul_prop = {
-
 
140
        .addr = 0x12000000,
-
 
141
        .offset = 0,
-
 
142
        .x = 640,
-
 
143
        .y = 480,
-
 
144
        .scan = 1920,
-
 
145
        .visual = VISUAL_BGR_8_8_8,
-
 
146
    };
-
 
147
    fb_init(&gxemul_prop);
-
 
148
#endif
-
 
149
 
-
 
150
#ifdef MACHINE_msim
-
 
151
    sysinfo_set_item_val("machine.msim", NULL, 1);
-
 
152
#endif
-
 
153
 
-
 
154
#ifdef MACHINE_simics
-
 
155
    sysinfo_set_item_val("machine.simics", NULL, 1);
-
 
156
#endif
-
 
157
 
-
 
158
#ifdef MACHINE_bgxemul
125
    fb_init(0x12000000, 640, 480, 1920, VISUAL_RGB_8_8_8); // gxemul framebuffer
159
    sysinfo_set_item_val("machine.bgxemul", NULL, 1);
-
 
160
#endif
-
 
161
 
-
 
162
#ifdef MACHINE_lgxemul
-
 
163
    sysinfo_set_item_val("machine.lgxemul", NULL, 1);
126
#endif
164
#endif
127
    sysinfo_set_item_val("machine." STRING(MACHINE), NULL, 1);
-
 
128
}
165
}
129
 
166
 
130
void arch_post_cpu_init(void)
167
void arch_post_cpu_init(void)
131
{
168
{
132
}
169
}
Line 137... Line 174...
137
 
174
 
138
void arch_post_smp_init(void)
175
void arch_post_smp_init(void)
139
{
176
{
140
}
177
}
141
 
178
 
-
 
179
void calibrate_delay_loop(void)
-
 
180
{
-
 
181
}
-
 
182
 
142
void userspace(uspace_arg_t *kernel_uarg)
183
void userspace(uspace_arg_t *kernel_uarg)
143
{
184
{
144
    /* EXL = 1, UM = 1, IE = 1 */
185
    /* EXL = 1, UM = 1, IE = 1 */
145
    cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
186
    cp0_status_write(cp0_status_read() | (cp0_status_exl_exception_bit |
146
        cp0_status_um_bit | cp0_status_ie_enabled_bit));
187
        cp0_status_um_bit | cp0_status_ie_enabled_bit));
147
    cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
188
    cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
148
    userspace_asm(((uintptr_t) kernel_uarg->uspace_stack + PAGE_SIZE),
189
    userspace_asm(((uintptr_t) kernel_uarg->uspace_stack + PAGE_SIZE),
149
        (uintptr_t) kernel_uarg->uspace_uarg,
190
        (uintptr_t) kernel_uarg->uspace_uarg,
150
        (uintptr_t) kernel_uarg->uspace_entry);
191
        (uintptr_t) kernel_uarg->uspace_entry);
151
   
192
   
152
    while (1);
193
    while (1);
153
}
194
}
154
 
195
 
155
/** Perform mips32 specific tasks needed before the new task is run. */
196
/** Perform mips32 specific tasks needed before the new task is run. */
Line 158... Line 199...
158
}
199
}
159
 
200
 
160
/** Perform mips32 specific tasks needed before the new thread is scheduled. */
201
/** Perform mips32 specific tasks needed before the new thread is scheduled. */
161
void before_thread_runs_arch(void)
202
void before_thread_runs_arch(void)
162
{
203
{
163
    supervisor_sp = (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
204
    supervisor_sp = (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE -
-
 
205
        SP_DELTA];
164
}
206
}
165
 
207
 
166
void after_thread_ran_arch(void)
208
void after_thread_ran_arch(void)
167
{
209
{
168
}
210
}
Line 177... Line 219...
177
    return 0;
219
    return 0;
178
}
220
}
179
 
221
 
180
void arch_reboot(void)
222
void arch_reboot(void)
181
{
223
{
182
    if (!arc_reboot())
-
 
183
        ___halt();
224
    ___halt();
184
   
225
   
185
    while (1);
226
    while (1);
186
}
227
}
187
 
228
 
-
 
229
/** Construct function pointer
-
 
230
 *
-
 
231
 * @param fptr   function pointer structure
-
 
232
 * @param addr   function address
-
 
233
 * @param caller calling function address
-
 
234
 *
-
 
235
 * @return address of the function pointer
-
 
236
 *
-
 
237
 */
-
 
238
void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
-
 
239
{
-
 
240
    return addr;
-
 
241
}
-
 
242
 
188
/** @}
243
/** @}
189
 */
244
 */