Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 527bc83

Browse files
committedApr 19, 2012
Working Xen bytecode microkernel (via the .bcxen target)
For some reason, ocamlc -output-obj doesnt entirely respect -nostdlib and so references to -ltermcap sneak into the default primitives. Therefore, ocamlclean is required or else undefined primitives result.
·
1 parent 492afe1 commit 527bc83

14 files changed

+411
-24
lines changed
 

‎NOTES.md

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ For the UNIX targets, there are 3 targets (by the filename extension):
3232
* `.bcbin`: bytecode as an embedded callback
3333
* `.bcxbin`: bytecode with deadcode-elimination via ocamlclean [1]
3434

35+
For Xen, there is a bytecode (that requires ocamlclean) and native code:
36+
37+
* `.xen`: native code microkernel
38+
* `.bcxen`: bytecode microkernel with deadcode-elimination via ocamlclean [1]
39+
3540
Note that ocamlclean can be quite slow (minutes) for larger applications,
3641
hence it isnt done by default for the bytecode target.
3742

‎assemble.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function assemble_xen {
2323
echo Assembling: Xen
2424
OBJ=${BUILDDIR}/xen
2525
mkdir -p ${OBJ}/lib ${OBJ}/syntax
26-
for i in dietlibc/libdiet.a libm/libm.a ocaml/libocaml.a ocaml/libocamlbc.a kernel/libxen.a kernel/libxencaml.a kernel/x86_64.o; do
26+
for i in dietlibc/libdiet.a libm/libm.a ocaml/libocaml.a ocaml/libocamlbc.a kernel/libxen.a kernel/libxencaml.a kernel/longjmp.o kernel/x86_64.o; do
2727
cp ${ROOT}/lib/_build/xen/os/runtime_xen/$i ${OBJ}/lib/
2828
done
2929
cp ${ROOT}/lib/os/runtime_xen/kernel/mirage-x86_64.lds ${OBJ}/lib/

‎lib/os/runtime_xen/all.itarget

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ kernel/libxen.a
44
kernel/libxencaml.a
55
ocaml/libocaml.a
66
ocaml/libocamlbc.a
7+
kernel/longjmp.o
78
kernel/x86_64.o

‎lib/os/runtime_xen/kernel/longjmp.S

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <setjmp.h>
2+
3+
.text
4+
.global __longjmp
5+
.type __longjmp,@function
6+
__longjmp:
7+
mov $1,%eax
8+
/* Restore the return address now. */
9+
movq (JB_PC*8)(%rdi),%rdx
10+
/* Restore registers. */
11+
movq (JB_RBX*8)(%rdi),%rbx
12+
movq (JB_RBP*8)(%rdi),%rbp
13+
movq (JB_R12*8)(%rdi),%r12
14+
movq (JB_R13*8)(%rdi),%r13
15+
movq (JB_R14*8)(%rdi),%r14
16+
movq (JB_R15*8)(%rdi),%r15
17+
movq (JB_RSP*8)(%rdi),%rsp
18+
/* never return 0 */
19+
test %esi,%esi
20+
cmovne %esi,%eax
21+
/* Jump to saved PC. */
22+
jmp *%rdx
23+
.size __longjmp,.-__longjmp;

‎lib/os/runtime_xen/ocaml/backtrace_bc.c

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ void caml_stash_backtrace(value exn, code_t pc, value * sp)
125125
#define O_BINARY 0
126126
#endif
127127

128+
#ifdef SYS_xen
129+
static value read_debug_info(void) { return Val_false; }
130+
#else
128131
static value read_debug_info(void)
129132
{
130133
CAMLparam0();
@@ -165,6 +168,7 @@ static value read_debug_info(void)
165168
caml_close_channel(chan);
166169
CAMLreturn(events);
167170
}
171+
#endif
168172

169173
/* Search the event for the given PC. Return Val_false if not found. */
170174

@@ -263,6 +267,7 @@ CAMLexport void caml_print_exception_backtrace(void)
263267
struct loc_info li;
264268

265269
events = read_debug_info();
270+
266271
if (events == Val_false) {
267272
fprintf(stderr,
268273
"(Program not linked with -g, cannot print stack backtrace)\n");

‎lib/os/runtime_xen/ocaml/dynlink.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ static c_primitive lookup_primitive(char * name)
6060
if (strcmp(name, caml_names_of_builtin_cprim[i]) == 0)
6161
return caml_builtin_cprim[i];
6262
}
63+
#ifndef SYS_xen
6364
for (i = 0; i < shared_libs.size; i++) {
6465
res = caml_dlsym(shared_libs.contents[i], name);
6566
if (res != NULL) return (c_primitive) res;
6667
}
68+
#endif
6769
return NULL;
6870
}
6971

@@ -72,6 +74,7 @@ static c_primitive lookup_primitive(char * name)
7274

7375
#define LD_CONF_NAME "ld.conf"
7476

77+
#ifndef SYS_xen
7578
static char * parse_ld_conf(void)
7679
{
7780
char * stdlib, * ldconfname, * config, * p, * q;
@@ -177,6 +180,8 @@ void caml_build_primitive_table(char * lib_path,
177180
caml_ext_table_free(&caml_shared_libs_path, 0);
178181
}
179182

183+
#endif /* SYS_xen */
184+
180185
/* Build the table of primitives as a copy of the builtin primitive table.
181186
Used for executables generated by ocamlc -output-obj. */
182187

@@ -191,7 +196,7 @@ void caml_build_primitive_table_builtin(void)
191196
#endif /* NATIVE_CODE */
192197

193198
/** dlopen interface for the bytecode linker **/
194-
199+
#ifndef SYS_xen
195200
#define Handle_val(v) (*((void **) (v)))
196201

197202
CAMLprim value caml_dynlink_open_lib(value mode, value filename)
@@ -265,3 +270,4 @@ value caml_dynlink_get_current_libs(value unit)
265270
}
266271

267272
#endif /* NATIVE_CODE */
273+
#endif

‎lib/os/runtime_xen/ocaml/fail_bc.c

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/***********************************************************************/
2+
/* */
3+
/* Objective Caml */
4+
/* */
5+
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
6+
/* */
7+
/* Copyright 1996 Institut National de Recherche en Informatique et */
8+
/* en Automatique. All rights reserved. This file is distributed */
9+
/* under the terms of the GNU Library General Public License, with */
10+
/* the special exception on linking described in file ../LICENSE. */
11+
/* */
12+
/***********************************************************************/
13+
14+
/* $Id$ */
15+
16+
/* Raising exceptions from C. */
17+
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include "alloc.h"
21+
#include "fail.h"
22+
#include "io.h"
23+
#include "gc.h"
24+
#include "memory.h"
25+
#include "misc.h"
26+
#include "mlvalues.h"
27+
#include "printexc.h"
28+
#include "signals.h"
29+
#include "stacks.h"
30+
31+
CAMLexport struct longjmp_buffer * caml_external_raise = NULL;
32+
value caml_exn_bucket;
33+
34+
CAMLexport void caml_raise(value v)
35+
{
36+
Unlock_exn();
37+
caml_exn_bucket = v;
38+
if (caml_external_raise == NULL) caml_fatal_uncaught_exception(v);
39+
siglongjmp(caml_external_raise->buf, 1);
40+
}
41+
42+
CAMLexport void caml_raise_constant(value tag)
43+
{
44+
CAMLparam1 (tag);
45+
CAMLlocal1 (bucket);
46+
47+
bucket = caml_alloc_small (1, 0);
48+
Field(bucket, 0) = tag;
49+
caml_raise(bucket);
50+
CAMLnoreturn;
51+
}
52+
53+
CAMLexport void caml_raise_with_arg(value tag, value arg)
54+
{
55+
CAMLparam2 (tag, arg);
56+
CAMLlocal1 (bucket);
57+
58+
bucket = caml_alloc_small (2, 0);
59+
Field(bucket, 0) = tag;
60+
Field(bucket, 1) = arg;
61+
caml_raise(bucket);
62+
CAMLnoreturn;
63+
}
64+
65+
CAMLexport void caml_raise_with_args(value tag, int nargs, value args[])
66+
{
67+
CAMLparam1 (tag);
68+
CAMLxparamN (args, nargs);
69+
value bucket;
70+
int i;
71+
72+
Assert(1 + nargs <= Max_young_wosize);
73+
bucket = caml_alloc_small (1 + nargs, 0);
74+
Field(bucket, 0) = tag;
75+
for (i = 0; i < nargs; i++) Field(bucket, 1 + i) = args[i];
76+
caml_raise(bucket);
77+
CAMLnoreturn;
78+
}
79+
80+
CAMLexport void caml_raise_with_string(value tag, char const *msg)
81+
{
82+
CAMLparam1 (tag);
83+
CAMLlocal1 (vmsg);
84+
85+
vmsg = caml_copy_string(msg);
86+
caml_raise_with_arg(tag, vmsg);
87+
CAMLnoreturn;
88+
}
89+
90+
/* PR#5115: Failure and Invalid_argument can be triggered by
91+
input_value while reading the initial value of [caml_global_data]. */
92+
93+
CAMLexport void caml_failwith (char const *msg)
94+
{
95+
if (caml_global_data == 0) {
96+
fprintf(stderr, "Fatal error: exception Failure(\"%s\")\n", msg);
97+
exit(2);
98+
}
99+
caml_raise_with_string(Field(caml_global_data, FAILURE_EXN), msg);
100+
}
101+
102+
CAMLexport void caml_invalid_argument (char const *msg)
103+
{
104+
if (caml_global_data == 0) {
105+
fprintf(stderr, "Fatal error: exception Invalid_argument(\"%s\")\n", msg);
106+
exit(2);
107+
}
108+
caml_raise_with_string(Field(caml_global_data, INVALID_EXN), msg);
109+
}
110+
111+
CAMLexport void caml_array_bound_error(void)
112+
{
113+
caml_invalid_argument("index out of bounds");
114+
}
115+
116+
/* Problem: we can't use [caml_raise_constant], because it allocates and
117+
we're out of memory... Here, we allocate statically the exn bucket
118+
for [Out_of_memory]. */
119+
120+
static struct {
121+
header_t hdr;
122+
value exn;
123+
} out_of_memory_bucket = { 0, 0 };
124+
125+
CAMLexport void caml_raise_out_of_memory(void)
126+
{
127+
if (out_of_memory_bucket.exn == 0)
128+
caml_fatal_error
129+
("Fatal error: out of memory while raising Out_of_memory\n");
130+
caml_raise((value) &(out_of_memory_bucket.exn));
131+
}
132+
133+
CAMLexport void caml_raise_stack_overflow(void)
134+
{
135+
caml_raise_constant(Field(caml_global_data, STACK_OVERFLOW_EXN));
136+
}
137+
138+
CAMLexport void caml_raise_sys_error(value msg)
139+
{
140+
caml_raise_with_arg(Field(caml_global_data, SYS_ERROR_EXN), msg);
141+
}
142+
143+
CAMLexport void caml_raise_end_of_file(void)
144+
{
145+
caml_raise_constant(Field(caml_global_data, END_OF_FILE_EXN));
146+
}
147+
148+
CAMLexport void caml_raise_zero_divide(void)
149+
{
150+
caml_raise_constant(Field(caml_global_data, ZERO_DIVIDE_EXN));
151+
}
152+
153+
CAMLexport void caml_raise_not_found(void)
154+
{
155+
caml_raise_constant(Field(caml_global_data, NOT_FOUND_EXN));
156+
}
157+
158+
CAMLexport void caml_raise_sys_blocked_io(void)
159+
{
160+
caml_raise_constant(Field(caml_global_data, SYS_BLOCKED_IO));
161+
}
162+
163+
/* Initialization of statically-allocated exception buckets */
164+
165+
void caml_init_exceptions(void)
166+
{
167+
out_of_memory_bucket.hdr = Make_header(1, 0, Caml_white);
168+
out_of_memory_bucket.exn = Field(caml_global_data, OUT_OF_MEMORY_EXN);
169+
caml_register_global_root(&out_of_memory_bucket.exn);
170+
}

‎lib/os/runtime_xen/ocaml/interp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/* */
1212
/***********************************************************************/
1313

14-
/* $Id: interp.c 9547 2010-01-22 12:48:24Z doligez $ */
14+
/* $Id$ */
1515

1616
/* The bytecode interpreter */
1717
#include <stdio.h>

‎lib/os/runtime_xen/ocaml/jumptbl.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
&&lbl_ACC0, &&lbl_ACC1, &&lbl_ACC2, &&lbl_ACC3, &&lbl_ACC4, &&lbl_ACC5, &&lbl_ACC6, &&lbl_ACC7,
2+
&&lbl_ACC, &&lbl_PUSH,
3+
&&lbl_PUSHACC0, &&lbl_PUSHACC1, &&lbl_PUSHACC2, &&lbl_PUSHACC3,
4+
&&lbl_PUSHACC4, &&lbl_PUSHACC5, &&lbl_PUSHACC6, &&lbl_PUSHACC7,
5+
&&lbl_PUSHACC, &&lbl_POP, &&lbl_ASSIGN,
6+
&&lbl_ENVACC1, &&lbl_ENVACC2, &&lbl_ENVACC3, &&lbl_ENVACC4, &&lbl_ENVACC,
7+
&&lbl_PUSHENVACC1, &&lbl_PUSHENVACC2, &&lbl_PUSHENVACC3, &&lbl_PUSHENVACC4, &&lbl_PUSHENVACC,
8+
&&lbl_PUSH_RETADDR, &&lbl_APPLY, &&lbl_APPLY1, &&lbl_APPLY2, &&lbl_APPLY3,
9+
&&lbl_APPTERM, &&lbl_APPTERM1, &&lbl_APPTERM2, &&lbl_APPTERM3,
10+
&&lbl_RETURN, &&lbl_RESTART, &&lbl_GRAB,
11+
&&lbl_CLOSURE, &&lbl_CLOSUREREC,
12+
&&lbl_OFFSETCLOSUREM2, &&lbl_OFFSETCLOSURE0, &&lbl_OFFSETCLOSURE2, &&lbl_OFFSETCLOSURE,
13+
&&lbl_PUSHOFFSETCLOSUREM2, &&lbl_PUSHOFFSETCLOSURE0,
14+
&&lbl_PUSHOFFSETCLOSURE2, &&lbl_PUSHOFFSETCLOSURE,
15+
&&lbl_GETGLOBAL, &&lbl_PUSHGETGLOBAL, &&lbl_GETGLOBALFIELD, &&lbl_PUSHGETGLOBALFIELD, &&lbl_SETGLOBAL,
16+
&&lbl_ATOM0, &&lbl_ATOM, &&lbl_PUSHATOM0, &&lbl_PUSHATOM,
17+
&&lbl_MAKEBLOCK, &&lbl_MAKEBLOCK1, &&lbl_MAKEBLOCK2, &&lbl_MAKEBLOCK3, &&lbl_MAKEFLOATBLOCK,
18+
&&lbl_GETFIELD0, &&lbl_GETFIELD1, &&lbl_GETFIELD2, &&lbl_GETFIELD3, &&lbl_GETFIELD, &&lbl_GETFLOATFIELD,
19+
&&lbl_SETFIELD0, &&lbl_SETFIELD1, &&lbl_SETFIELD2, &&lbl_SETFIELD3, &&lbl_SETFIELD, &&lbl_SETFLOATFIELD,
20+
&&lbl_VECTLENGTH, &&lbl_GETVECTITEM, &&lbl_SETVECTITEM,
21+
&&lbl_GETSTRINGCHAR, &&lbl_SETSTRINGCHAR,
22+
&&lbl_BRANCH, &&lbl_BRANCHIF, &&lbl_BRANCHIFNOT, &&lbl_SWITCH, &&lbl_BOOLNOT,
23+
&&lbl_PUSHTRAP, &&lbl_POPTRAP, &&lbl_RAISE, &&lbl_CHECK_SIGNALS,
24+
&&lbl_C_CALL1, &&lbl_C_CALL2, &&lbl_C_CALL3, &&lbl_C_CALL4, &&lbl_C_CALL5, &&lbl_C_CALLN,
25+
&&lbl_CONST0, &&lbl_CONST1, &&lbl_CONST2, &&lbl_CONST3, &&lbl_CONSTINT,
26+
&&lbl_PUSHCONST0, &&lbl_PUSHCONST1, &&lbl_PUSHCONST2, &&lbl_PUSHCONST3, &&lbl_PUSHCONSTINT,
27+
&&lbl_NEGINT, &&lbl_ADDINT, &&lbl_SUBINT, &&lbl_MULINT, &&lbl_DIVINT, &&lbl_MODINT,
28+
&&lbl_ANDINT, &&lbl_ORINT, &&lbl_XORINT, &&lbl_LSLINT, &&lbl_LSRINT, &&lbl_ASRINT,
29+
&&lbl_EQ, &&lbl_NEQ, &&lbl_LTINT, &&lbl_LEINT, &&lbl_GTINT, &&lbl_GEINT,
30+
&&lbl_OFFSETINT, &&lbl_OFFSETREF, &&lbl_ISINT,
31+
&&lbl_GETMETHOD,
32+
&&lbl_BEQ, &&lbl_BNEQ, &&lbl_BLTINT, &&lbl_BLEINT, &&lbl_BGTINT, &&lbl_BGEINT,
33+
&&lbl_ULTINT, &&lbl_UGEINT,
34+
&&lbl_BULTINT, &&lbl_BUGEINT,
35+
&&lbl_GETPUBMET, &&lbl_GETDYNMET,
36+
&&lbl_STOP,
37+
&&lbl_EVENT, &&lbl_BREAK
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
amd64.bc.o
2+
alloc.bc.o
3+
array.bc.o
4+
backtrace.bc.o
5+
callback.bc.o
6+
compact.bc.o
7+
compare.bc.o
8+
custom.bc.o
9+
debugger.bc.o
10+
dynlink.bc.o
11+
extern.bc.o
12+
fail.bc.o
13+
finalise.bc.o
14+
floats.bc.o
15+
freelist.bc.o
16+
gc_ctrl.bc.o
17+
globroots.bc.o
18+
hash.bc.o
19+
instrtrace.bc.o
20+
intern.bc.o
21+
ints.bc.o
22+
io.bc.o
23+
lexing.bc.o
24+
main.bc.o
25+
major_gc.bc.o
26+
md5.bc.o
27+
memory.bc.o
28+
meta.bc.o
29+
minor_gc.bc.o
30+
misc.bc.o
31+
natdynlink.bc.o
32+
obj.bc.o
33+
parsing.bc.o
34+
printexc.bc.o
35+
roots.bc.o
36+
signals.bc.o
37+
stacks.bc.o
38+
startup_bc.bc.o
39+
str.bc.o
40+
sys.bc.o
41+
terminfo.bc.o
42+
weak.bc.o

0 commit comments

Comments
 (0)
Please sign in to comment.