Strong typed Objects, part 1
[jamvm-avr32-jem.git] / src / os / linux / avr32 / init.c
blobf822ba6790e1df4a19841f9e3a2baefeb9537d47
1 /*
2 * Copyright (C) 2003, 2004, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //#include <fpu_control.h>
23 #include <string.h>
24 #include <sys/syscall.h>
25 #include <unistd.h>
26 #include <sys/mman.h>
27 #include <asm/cachectl.h>
28 #include "jam.h"
29 #include "arch/avr32_jem.h"
31 /* Change floating point precision to double (64-bit) from
32 * the extended (80-bit) Linux default. */
34 //void setDoublePrecision() {
35 // fpu_control_t cw;
37 // _FPU_GETCW(cw);
38 // cw &= ~_FPU_EXTENDED;
39 // cw |= _FPU_DOUBLE;
40 // _FPU_SETCW(cw);
41 //}
43 #ifdef JEM
44 extern size_t trap_h_size;
46 static char *trap_handler(void)
48 char *trap;
50 asm volatile (
51 " mov %[trap], pc\n"
52 " sub %[trap], -8\n" /* Return pointer to trap label */
53 " bral 1f\n" /* Leave the function */
54 /* The actual trap-handler */
55 "trap: mov r12, pc\n" /* Store trap entry point */
56 " .globl debug_jem_trap\n"
57 "debug_jem_trap:\n"
58 " mov pc, r10\n"
59 " .globl trap_h_size\n" /* and its size */
60 "trap_h_size:\n"
61 " .word . - trap\n"
62 " .size trap_h_size, . - trap_h_size\n"
63 "1:\n"
64 : [trap] "=r" (trap)
66 return trap;
69 extern int do_jamInstrps(struct jem_state *jem);
70 #endif
72 void initialisePlatform(void)
74 //TODO: is this needed for avr32? setDoublePrecision();
75 #ifdef JEM
76 /**
77 * Setup the real traps,the entries are actually loaded when entering
78 * the interpreter engine
80 char *trap_b, *trap_aligned, *trap_h;
81 int i;
83 trap_b = mmap(0, 8192, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
84 if (trap_b == MAP_FAILED)
85 exitVM(1);
87 trap_aligned = (void *)(((unsigned long)trap_b + 4095) & ~4095);
89 trap_h = trap_handler();
91 for (i = 0; i < 24; i++) {
92 int j;
93 memcpy(trap_aligned + i * 0x80, trap_h, trap_h_size);
94 printf("%p:", trap_aligned + i * 0x80);
95 for (j = 0; j < trap_h_size; j++)
96 printf(" %02x", trap_aligned[i * 0x80 + j]);
97 printf("\n");
100 /* Clean the data cache, flush the instruction cache */
101 syscall(__NR_cacheflush, CACHE_IFLUSH, trap_aligned, 4096);
102 syscall(__NR_java_settrap, trap_aligned);
103 #endif