Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 7c137dd

Browse files
committed
Initial commit
1 parent 35efb8f commit 7c137dd

File tree

127 files changed

+45391
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+45391
-0
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sergii Iefremov <[email protected]>

LICENSE

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
runtime.js license follows:
2+
3+
========
4+
Copyright 2014, runtime.js project authors. All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
* Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above
13+
copyright notice, this list of conditions and the following
14+
disclaimer in the documentation and/or other materials provided
15+
with the distribution.
16+
* Neither the name of the runtime.js nor the names of its
17+
contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
========
33+
34+
This license applies to all parts of runtime.js that are not externally
35+
maintained libraries. The externally maintained libraries used by
36+
runtime.js are:
37+
38+
- ACPICA (https://www.acpica.org/), located at deps/acpica
39+
- EASTL (http://gpl.ea.com/), located at deps/eastl
40+
- libc++, C++ standard library (http://libcxx.llvm.org/), located at deps/libcxx
41+
- musl C standard library (http://www.musl-libc.org/), located at deps/musl
42+
- v8 JavaScript engine (https://code.google.com/p/v8/), located at deps/v8
43+
- tinyprintf (http://www.sparetimelabs.com/tinyprintf/tinyprintf.php), located at deps/printf
44+
- dlmalloc allocator by Doug Lea (ftp://gee.cs.oswego.edu/pub/misc/malloc.c)
45+
- crc64 function by Salvatore Sanfilippo <antirez at gmail dot com>
46+
47+
These libraries have their own licenses.

LICENSE.commentasm

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Copyright 2014, runtime.js project authors. All rights reserved.
2+
; Use of this source code is governed by a BSD-style license that can be
3+
; found in the LICENSE file.
4+

LICENSE.commentcc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright 2014, runtime.js project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+

SConstruct

+258
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
import os
2+
import sys
3+
import datetime
4+
5+
SetOption('num_jobs', 4)
6+
7+
build = "debug"
8+
9+
config = {
10+
"project_name": "runtimejs",
11+
"binary_output_file": "disk/boot/kernel.bin",
12+
"toolchain_bin_path": "tools/cross-4.8.2/bin",
13+
"fasm_pathname": "tools/cross/bin/fasm",
14+
"link_script": "etc/kernel.ld",
15+
"name_gxx": "x86_64-elf-g++",
16+
"name_gcc": "x86_64-elf-gcc",
17+
"name_as": "x86_64-elf-as",
18+
"name_ld": "x86_64-elf-ld",
19+
"name_ar": "x86_64-elf-ar",
20+
"name_ranlib": "x86_64-elf-ranlib",
21+
"name_objcopy": "x86_64-elf-objcopy",
22+
"flags_common": {
23+
"shared": set([
24+
'-m64',
25+
'-ffreestanding',
26+
'-nostdlib',
27+
'-mno-red-zone',
28+
'-mno-mmx',
29+
'-mno-sse3',
30+
'-mno-3dnow',
31+
'-nodefaultlibs',
32+
'-nostartfiles',
33+
'-Wall',
34+
'-Wextra',
35+
'-nostdinc',
36+
'-Wno-unused',
37+
'-fno-builtin',
38+
'-fno-exceptions',
39+
'-fno-stack-protector',
40+
'-Wno-unused-parameter',
41+
'-D__runtime_js__',
42+
'-DRUNTIMEJS_PLATFORM_X64',
43+
]),
44+
"release": set([
45+
]),
46+
"debug": set([
47+
'-g',
48+
]),
49+
},
50+
"flags_gxx": {
51+
"shared": set([
52+
'-nostdinc++',
53+
'-std=c++11',
54+
'-O3',
55+
'-fno-tree-vectorize', # misaligned movdqa %xmm1,(%rsp) generated without this option and O3
56+
'-fno-rtti',
57+
'-fno-strict-aliasing',
58+
'-U__STRICT_ANSI__',
59+
'-DENABLE_DEBUGGER_SUPPORT',
60+
'-DENABLE_DISASSEMBLER',
61+
'-DV8_HOST_ARCH_X64',
62+
'-DV8_TARGET_ARCH_X64',
63+
# '-DVERIFY_HEAP',
64+
# '-DDEBUG',
65+
# '-DOBJECT_PRINT',
66+
# '-DENABLE_EXTRA_CHECKS',
67+
# '-DENABLE_HANDLE_ZAPPING',
68+
]),
69+
"release": set([
70+
]),
71+
"debug": set([
72+
]),
73+
},
74+
"flags_gcc": {
75+
"shared": set([
76+
'-O2',
77+
'-c',
78+
'-std=c99',
79+
'-D_XOPEN_SOURCE=700',
80+
]),
81+
"release": set([
82+
]),
83+
"debug": set([
84+
]),
85+
},
86+
"flags_link": set([
87+
'-nostdlib',
88+
'-nodefaultlibs',
89+
# '-Map etc/map.txt',
90+
]),
91+
"locations": {
92+
"cc": [
93+
'src',
94+
'src/arch',
95+
'src/kernel',
96+
'src/kernel/x64',
97+
'src/common',
98+
'test/cc',
99+
],
100+
"asm": [
101+
'src',
102+
'src/kernel/x64',
103+
],
104+
"js": [
105+
'src/kernel/Js',
106+
],
107+
},
108+
"includes": [
109+
'deps/musl/src/internal',
110+
'deps/musl/include',
111+
'deps/musl/arch/x86_64',
112+
'deps/musl/arch/x86_64/bits',
113+
'deps/libcxx/include',
114+
'deps/eastl/include',
115+
'deps/v8/include',
116+
'deps/acpica/source/include',
117+
'deps/printf',
118+
'src',
119+
'test',
120+
],
121+
"libs": [
122+
'v8',
123+
'cxx',
124+
'eastl',
125+
'acpica',
126+
'printf',
127+
'musl',
128+
],
129+
}
130+
131+
def CreateToolchainPath(binpath, name):
132+
return os.path.join(binpath, name);
133+
134+
def CombineFlagsBuild(name, build):
135+
return config[name]["shared"] | config[name][build]
136+
137+
def EnvironmentCreate(build):
138+
gxx = CreateToolchainPath(config["toolchain_bin_path"], config["name_gxx"])
139+
gcc = CreateToolchainPath(config["toolchain_bin_path"], config["name_gcc"])
140+
ar = CreateToolchainPath(config["toolchain_bin_path"], config["name_ar"])
141+
ranlib = CreateToolchainPath(config["toolchain_bin_path"], config["name_ranlib"])
142+
_as = CreateToolchainPath(config["toolchain_bin_path"], config["name_as"])
143+
ld = CreateToolchainPath(config["toolchain_bin_path"], config["name_ld"])
144+
fasm = config["fasm_pathname"]
145+
146+
flags_shared = CombineFlagsBuild("flags_common", build)
147+
flags_gxx = flags_shared | CombineFlagsBuild("flags_gxx", build)
148+
flags_gcc = flags_shared | CombineFlagsBuild("flags_gcc", build)
149+
150+
proj_name = config["project_name"]
151+
152+
asm_builder = Builder(
153+
action = fasm + ' $SOURCE $TARGET >/dev/null',
154+
single_source = 1,
155+
suffix = '.asm_o',
156+
src_suffix = '.asm'
157+
)
158+
159+
js_builder = Builder(
160+
action = 'xxd -i < $SOURCE > $TARGET; echo ",0x00" >> $TARGET',
161+
single_source = 1,
162+
suffix = '.js.h',
163+
src_suffix = '.js'
164+
)
165+
166+
env = Environment(
167+
CXX = gxx,
168+
CC = gcc,
169+
AR = ar,
170+
AS = _as,
171+
RANLIB = ranlib,
172+
CXXFLAGS = " ".join(flags_gxx),
173+
CFLAGS = " ".join(flags_gcc),
174+
LINK = ld,
175+
LINKFLAGS = '-T ' + config["link_script"] + ' ' + ' '.join(config["flags_link"]) + ' -o ' + proj_name,
176+
CXXCOMSTR = '[cross] Build $TARGET',
177+
LINKCOMSTR = '[cross] Link $TARGET',
178+
RANLIBCOMSTR = '[cross] Index $TARGET',
179+
ARCOMSTR = '[cross] Archive $TARGET',
180+
)
181+
182+
env.Append(
183+
BUILDERS = {
184+
'asm': asm_builder,
185+
'js': js_builder,
186+
}
187+
)
188+
189+
return env
190+
191+
def EnvironmentCreateHost():
192+
hostenv = Environment(
193+
CXXFLAGS = '-std=c++11 -O3',
194+
CPPPATH = ['src', 'deps/printf'],
195+
OBJSUFFIX = '.host',
196+
CXXCOMSTR = '[host] Build $TARGET',
197+
LINKCOMSTR = '[host] Link $TARGET',
198+
RANLIBCOMSTR = '[host] Index $TARGET',
199+
ARCOMSTR = '[host] Archive $TARGET',
200+
)
201+
return hostenv
202+
203+
def BuildMkinitrd(hostenv):
204+
hostenv.Program('mkinitrd', ['src/mkinitrd/mkinitrd.cc', 'src/common/package.cc', 'src/common/crc64.cc'])
205+
return
206+
207+
def BuildTestsHost(hostenv):
208+
hostenv.Program('test-host', ['test/hostcc/test-host.cc', 'deps/printf/printf.cc'])
209+
return
210+
211+
def BuildProject(env_base):
212+
env = env_base.Clone();
213+
sources = {}
214+
for ext, dirs in config["locations"].items():
215+
if ext not in sources:
216+
sources[ext] = []
217+
for d in dirs:
218+
path = os.path.join(d, "*."+ext)
219+
sources[ext].append(Glob(path))
220+
221+
obj_asm = [env.asm(i) for i in sources["asm"]]
222+
env.Depends(obj_asm, Glob('src/*.inc'))
223+
224+
obj_js = [env.js(i) for i in sources["js"]]
225+
226+
env.Replace(CPPPATH = config["includes"])
227+
env.Replace(LIBS = config["libs"])
228+
env.Replace(LIBPATH = 'deps')
229+
230+
proj_name = config["project_name"]
231+
env.Depends(proj_name, obj_js);
232+
env.Depends(proj_name, config["link_script"])
233+
output_elf = env.Program(proj_name, sources["cc"] + obj_asm)
234+
235+
binary_output = config["binary_output_file"]
236+
objcopy = CreateToolchainPath(config["toolchain_bin_path"], config["name_objcopy"])
237+
output_bin = env.Command(binary_output, '',
238+
objcopy + ' -O binary --strip-all --set-section-flags \'.bss\'=alloc,load,contents,data ' +
239+
proj_name + ' ' + binary_output)
240+
env.Depends(output_bin, output_elf);
241+
242+
initrd = env.Command('disk/boot/initrd', '', './maketar.sh')
243+
env.Depends(initrd, Glob('initrd/*.*'))
244+
env.Depends(initrd, Glob('initrd/*/*.*'))
245+
env.Depends(initrd, Glob('initrd/*/*/*.*'))
246+
env.Depends(output_bin, initrd);
247+
return
248+
249+
# Build mkinitrd tool
250+
env_host = EnvironmentCreateHost()
251+
BuildMkinitrd(env_host)
252+
BuildTestsHost(env_host)
253+
254+
# Build kernel
255+
env_base = EnvironmentCreate(build)
256+
SConscript('deps/SConscript', exports = 'env_base')
257+
BuildProject(env_base)
258+

0 commit comments

Comments
 (0)