First run attempts.
[jamvm-avr32-jem.git] / src / os / linux / avr32 / init.c
blobef7f28d08e7ee5cf7f359aaa212b403345e902ab
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 <stdio.h>
24 #include <sys/syscall.h>
25 #include <unistd.h>
26 #include <sys/mman.h>
27 #include "jam.h"
29 /* Change floating point precision to double (64-bit) from
30 * the extended (80-bit) Linux default. */
32 //void setDoublePrecision() {
33 // fpu_control_t cw;
35 // _FPU_GETCW(cw);
36 // cw &= ~_FPU_EXTENDED;
37 // cw |= _FPU_DOUBLE;
38 // _FPU_SETCW(cw);
39 //}
40 #ifdef JEM
41 //real global trap table used for JEM
42 // char *trap_h;
43 #endif
46 extern size_t trap_h_size;
48 static char *trap_handler(void)
50 char *trap;
52 asm volatile (
53 " mov %[trap], pc\n"
54 " sub %[trap], -8\n" /* Return pointer to trap label */
55 " bral 1f\n" /* Leave the function */
56 /* The actual trap-handler */
57 "trap: mov r12, pc\n" /* Store trap entry point */
58 " sub r10, -4\n"
59 " mov pc, r10\n"
60 " .globl trap_h_size\n" /* and its size */
61 "trap_h_size:\n"
62 " .word . - trap\n"
63 " .size trap_h_size, . - trap_h_size\n"
64 "1:\n"
65 : [trap] "=r" (trap)
67 return trap;
70 void initialisePlatform() {
71 //TODO: is this needed for avr32? setDoublePrecision();
72 #ifdef JEM
73 /**
74 * Setup the real traps,the entries are actually loaded when entering
75 * the interpreter engine
77 char *trap_b, *trap_aligned, *trap_h;
78 int i;
80 trap_b = mmap(0, 8192, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
81 if (trap_b == MAP_FAILED)
82 exitVM(1);
84 trap_aligned = (void *)(((unsigned long)trap_b + 4095) & ~4095);
86 trap_h = trap_handler();
88 for (i = 0; i < 24; i++) {
89 memcpy(trap_aligned + i * 0x80, trap_h, trap_h_size);
90 printf("%p\n", trap_aligned + i * 0x80);
93 syscall(__NR_java_settrap, trap_aligned);
94 #endif