| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 Jakub 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 ia64
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #include <arch.h>
|
|---|
| 36 | #include <typedefs.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <interrupt.h>
|
|---|
| 39 | #include <macros.h>
|
|---|
| 40 | #include <str.h>
|
|---|
| 41 | #include <userspace.h>
|
|---|
| 42 | #include <console/console.h>
|
|---|
| 43 | #include <syscall/syscall.h>
|
|---|
| 44 | #include <sysinfo/sysinfo.h>
|
|---|
| 45 | #include <arch/drivers/it.h>
|
|---|
| 46 | #include <arch/drivers/kbd.h>
|
|---|
| 47 | #include <genarch/drivers/ega/ega.h>
|
|---|
| 48 | #include <genarch/drivers/i8042/i8042.h>
|
|---|
| 49 | #include <genarch/drivers/ns16550/ns16550.h>
|
|---|
| 50 | #include <genarch/drivers/legacy/ia32/io.h>
|
|---|
| 51 | #include <genarch/kbrd/kbrd.h>
|
|---|
| 52 | #include <genarch/srln/srln.h>
|
|---|
| 53 |
|
|---|
| 54 | /* NS16550 as a COM 1 */
|
|---|
| 55 | #define NS16550_IRQ (4 + LEGACY_INTERRUPT_BASE)
|
|---|
| 56 |
|
|---|
| 57 | bootinfo_t *bootinfo;
|
|---|
| 58 |
|
|---|
| 59 | static uint64_t iosapic_base = 0xfec00000;
|
|---|
| 60 |
|
|---|
| 61 | /** Performs ia64-specific initialization before main_bsp() is called. */
|
|---|
| 62 | void arch_pre_main(void)
|
|---|
| 63 | {
|
|---|
| 64 | init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
|
|---|
| 65 | size_t i;
|
|---|
| 66 | for (i = 0; i < init.cnt; i++) {
|
|---|
| 67 | init.tasks[i].addr =
|
|---|
| 68 | ((unsigned long) bootinfo->taskmap.tasks[i].addr) |
|
|---|
| 69 | VRN_MASK;
|
|---|
| 70 | init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
|
|---|
| 71 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
|
|---|
| 72 | bootinfo->taskmap.tasks[i].name);
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | void arch_pre_mm_init(void)
|
|---|
| 77 | {
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | static void iosapic_init(void)
|
|---|
| 81 | {
|
|---|
| 82 | uint64_t IOSAPIC = PA2KA((sysarg_t)(iosapic_base)) | FW_OFFSET;
|
|---|
| 83 | int i;
|
|---|
| 84 |
|
|---|
| 85 | int myid, myeid;
|
|---|
| 86 |
|
|---|
| 87 | myid = ia64_get_cpu_id();
|
|---|
| 88 | myeid = ia64_get_cpu_eid();
|
|---|
| 89 |
|
|---|
| 90 | for (i = 0; i < 16; i++) {
|
|---|
| 91 | if (i == 2)
|
|---|
| 92 | continue; /* Disable Cascade interrupt */
|
|---|
| 93 | ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i;
|
|---|
| 94 | srlz_d();
|
|---|
| 95 | ((uint32_t *)(IOSAPIC + 0x10))[0] = LEGACY_INTERRUPT_BASE + i;
|
|---|
| 96 | srlz_d();
|
|---|
| 97 | ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i + 1;
|
|---|
| 98 | srlz_d();
|
|---|
| 99 | ((uint32_t *)(IOSAPIC + 0x10))[0] = myid << (56 - 32) |
|
|---|
| 100 | myeid << (48 - 32);
|
|---|
| 101 | srlz_d();
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | void arch_post_mm_init(void)
|
|---|
| 107 | {
|
|---|
| 108 | if (config.cpu_active == 1) {
|
|---|
| 109 | iosapic_init();
|
|---|
| 110 | irq_init(INR_COUNT, INR_COUNT);
|
|---|
| 111 | }
|
|---|
| 112 | it_init();
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void arch_post_cpu_init(void)
|
|---|
| 116 | {
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | void arch_pre_smp_init(void)
|
|---|
| 120 | {
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | void arch_post_smp_init(void)
|
|---|
| 124 | {
|
|---|
| 125 | static const char *platform;
|
|---|
| 126 |
|
|---|
| 127 | /* Set platform name. */
|
|---|
| 128 | #ifdef MACHINE_ski
|
|---|
| 129 | platform = "ski";
|
|---|
| 130 | #endif
|
|---|
| 131 | #ifdef MACHINE_i460GX
|
|---|
| 132 | platform = "i460GX";
|
|---|
| 133 | #endif
|
|---|
| 134 | sysinfo_set_item_data("platform", NULL, (void *) platform,
|
|---|
| 135 | str_size(platform));
|
|---|
| 136 |
|
|---|
| 137 | #ifdef MACHINE_ski
|
|---|
| 138 | ski_instance_t *ski_instance = skiin_init();
|
|---|
| 139 | if (ski_instance) {
|
|---|
| 140 | srln_instance_t *srln_instance = srln_init();
|
|---|
| 141 | if (srln_instance) {
|
|---|
| 142 | indev_t *sink = stdin_wire();
|
|---|
| 143 | indev_t *srln = srln_wire(srln_instance, sink);
|
|---|
| 144 | skiin_wire(ski_instance, srln);
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | outdev_t *skidev = skiout_init();
|
|---|
| 149 | if (skidev)
|
|---|
| 150 | stdout_wire(skidev);
|
|---|
| 151 | #endif
|
|---|
| 152 |
|
|---|
| 153 | #ifdef CONFIG_EGA
|
|---|
| 154 | outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
|
|---|
| 155 | if (egadev)
|
|---|
| 156 | stdout_wire(egadev);
|
|---|
| 157 | #endif
|
|---|
| 158 |
|
|---|
| 159 | #ifdef CONFIG_NS16550
|
|---|
| 160 | ns16550_instance_t *ns16550_instance
|
|---|
| 161 | = ns16550_init((ns16550_t *) NS16550_BASE, NS16550_IRQ, NULL, NULL);
|
|---|
| 162 | if (ns16550_instance) {
|
|---|
| 163 | srln_instance_t *srln_instance = srln_init();
|
|---|
| 164 | if (srln_instance) {
|
|---|
| 165 | indev_t *sink = stdin_wire();
|
|---|
| 166 | indev_t *srln = srln_wire(srln_instance, sink);
|
|---|
| 167 | ns16550_wire(ns16550_instance, srln);
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | sysinfo_set_item_val("kbd", NULL, true);
|
|---|
| 172 | sysinfo_set_item_val("kbd.inr", NULL, NS16550_IRQ);
|
|---|
| 173 | sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550);
|
|---|
| 174 | sysinfo_set_item_val("kbd.address.physical", NULL,
|
|---|
| 175 | (uintptr_t) NS16550_BASE);
|
|---|
| 176 | sysinfo_set_item_val("kbd.address.kernel", NULL,
|
|---|
| 177 | (uintptr_t) NS16550_BASE);
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|
| 180 | #ifdef CONFIG_I8042
|
|---|
| 181 | i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
|
|---|
| 182 | if (i8042_instance) {
|
|---|
| 183 | kbrd_instance_t *kbrd_instance = kbrd_init();
|
|---|
| 184 | if (kbrd_instance) {
|
|---|
| 185 | indev_t *sink = stdin_wire();
|
|---|
| 186 | indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
|
|---|
| 187 | i8042_wire(i8042_instance, kbrd);
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | sysinfo_set_item_val("i8042", NULL, true);
|
|---|
| 192 | sysinfo_set_item_val("i8042.inr_a", NULL, IRQ_KBD);
|
|---|
| 193 | sysinfo_set_item_val("i8042.inr_b", NULL, IRQ_MOUSE);
|
|---|
| 194 | sysinfo_set_item_val("i8042.address.physical", NULL,
|
|---|
| 195 | (uintptr_t) I8042_BASE);
|
|---|
| 196 | sysinfo_set_item_val("i8042.address.kernel", NULL,
|
|---|
| 197 | (uintptr_t) I8042_BASE);
|
|---|
| 198 | #endif
|
|---|
| 199 |
|
|---|
| 200 | sysinfo_set_item_val("netif.ne2000.inr", NULL, IRQ_NE2000);
|
|---|
| 201 |
|
|---|
| 202 | sysinfo_set_item_val("ia64_iospace", NULL, true);
|
|---|
| 203 | sysinfo_set_item_val("ia64_iospace.address", NULL, true);
|
|---|
| 204 | sysinfo_set_item_val("ia64_iospace.address.virtual", NULL, IO_OFFSET);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | /** Enter userspace and never return. */
|
|---|
| 209 | void userspace(uspace_arg_t *kernel_uarg)
|
|---|
| 210 | {
|
|---|
| 211 | psr_t psr;
|
|---|
| 212 | rsc_t rsc;
|
|---|
| 213 |
|
|---|
| 214 | psr.value = psr_read();
|
|---|
| 215 | psr.cpl = PL_USER;
|
|---|
| 216 | psr.i = true; /* start with interrupts enabled */
|
|---|
| 217 | psr.ic = true;
|
|---|
| 218 | psr.ri = 0; /* start with instruction #0 */
|
|---|
| 219 | psr.bn = 1; /* start in bank 0 */
|
|---|
| 220 |
|
|---|
| 221 | asm volatile ("mov %0 = ar.rsc\n" : "=r" (rsc.value));
|
|---|
| 222 | rsc.loadrs = 0;
|
|---|
| 223 | rsc.be = false;
|
|---|
| 224 | rsc.pl = PL_USER;
|
|---|
| 225 | rsc.mode = 3; /* eager mode */
|
|---|
| 226 |
|
|---|
| 227 | /*
|
|---|
| 228 | * Switch to userspace.
|
|---|
| 229 | *
|
|---|
| 230 | * When calculating stack addresses, mind the stack split between the
|
|---|
| 231 | * memory stack and the RSE stack. Each occuppies STACK_SIZE / 2 bytes.
|
|---|
| 232 | */
|
|---|
| 233 | switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
|
|---|
| 234 | ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE / 2 -
|
|---|
| 235 | ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT),
|
|---|
| 236 | ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE / 2,
|
|---|
| 237 | (uintptr_t) kernel_uarg->uspace_uarg, psr.value, rsc.value);
|
|---|
| 238 |
|
|---|
| 239 | while (1)
|
|---|
| 240 | ;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | /** Set thread-local-storage pointer.
|
|---|
| 244 | *
|
|---|
| 245 | * We use r13 (a.k.a. tp) for this purpose.
|
|---|
| 246 | */
|
|---|
| 247 | sysarg_t sys_tls_set(uintptr_t addr)
|
|---|
| 248 | {
|
|---|
| 249 | return EOK;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | void arch_reboot(void)
|
|---|
| 253 | {
|
|---|
| 254 | pio_write_8((ioport8_t *)0x64, 0xfe);
|
|---|
| 255 | while (1);
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | /** Construct function pointer
|
|---|
| 259 | *
|
|---|
| 260 | * @param fptr function pointer structure
|
|---|
| 261 | * @param addr function address
|
|---|
| 262 | * @param caller calling function address
|
|---|
| 263 | *
|
|---|
| 264 | * @return address of the function pointer
|
|---|
| 265 | *
|
|---|
| 266 | */
|
|---|
| 267 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
|
|---|
| 268 | {
|
|---|
| 269 | fptr->fnc = (sysarg_t) addr;
|
|---|
| 270 | fptr->gp = ((sysarg_t *) caller)[1];
|
|---|
| 271 |
|
|---|
| 272 | return (void *) fptr;
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | void irq_initialize_arch(irq_t *irq)
|
|---|
| 276 | {
|
|---|
| 277 | (void) irq;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /** @}
|
|---|
| 281 | */
|
|---|