Skip to content

Commit af634ec

Browse files
authored
Merge pull request #1475 from hioa-cs/dev
Merge Dev
2 parents 938bda1 + c9c81f3 commit af634ec

47 files changed

Lines changed: 547 additions & 449 deletions

Some content is hidden

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

api/kernel/os.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OS {
5959
* other mechanisms. The first argument is always
6060
* the binary name.
6161
**/
62-
static const std::string& cmdline_args() noexcept;
62+
static const char* cmdline_args() noexcept;
6363

6464
/** Clock cycles since boot. */
6565
static uint64_t cycles_since_boot() {
@@ -257,18 +257,15 @@ class OS {
257257
static bool boot_sequence_passed_;
258258
static MHz cpu_mhz_;
259259

260-
// XXX: Only used by solo5
261260
static RTC::timestamp_t booted_at_;
262261
static uintptr_t liveupdate_loc_;
263262
static std::string version_str_;
264263
static std::string arch_str_;
265264
static Plugin_vec plugins_;
266-
static uintptr_t low_memory_size_;
267-
static uintptr_t high_memory_size_;
268265
static uintptr_t memory_end_;
269266
static uintptr_t heap_max_;
270267
static const uintptr_t elf_binary_size_;
271-
static std::string cmdline;
268+
static const char* cmdline;
272269

273270
// Prohibit copy and move operations
274271
OS(OS&) = delete;

api/kernel/service.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
88
// You may obtain a copy of the License at
9-
//
9+
//
1010
// http://www.apache.org/licenses/LICENSE-2.0
11-
//
11+
//
1212
// Unless required by applicable law or agreed to in writing, software
1313
// distributed under the License is distributed on an "AS IS" BASIS,
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,12 +30,12 @@ class Service {
3030
/**
3131
* @return: The (descriptive) name of the service
3232
*/
33-
static std::string name();
33+
static const char* name();
3434

3535
/**
3636
* @return: The name of the service binary
3737
*/
38-
static std::string binary_name();
38+
static const char* binary_name();
3939

4040

4141
/**

api/util/elf_binary.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ class Elf_binary {
4343
public:
4444

4545
using Span = gsl::span<char>;
46+
using Elf_header = typename Arch::Ehdr;
4647
using Section_header = typename Arch::Shdr;
4748
using Section_headers = gsl::span<Section_header>;
49+
using Program_header = typename Arch::Phdr;
50+
using Program_headers = gsl::span<Program_header>;
51+
using Addr = typename Arch::Addr;
4852

4953
Elf_binary(Span data)
5054
: data_{data}
5155
{
5256
validate();
5357
}
5458

55-
const typename Arch::Ehdr& elf_header() const;
56-
const typename Arch::Phdr& program_header() const;
57-
const typename Arch::Shdr& section_header() const;
59+
const Elf_header& elf_header() const;
60+
const Program_headers program_headers() const;
61+
const Section_header& section_header() const;
5862

5963
/** Make sure this is a valid ELF binary. Throws if not. **/
6064
void validate();
@@ -67,7 +71,10 @@ class Elf_binary {
6771
void print_summary();
6872

6973
/** Program entry point **/
70-
typename Arch::Addr entry();
74+
Addr entry();
75+
76+
/** Program headers marked loadable */
77+
std::vector<const Program_header*> loadable_segments();
7178

7279
/** Get the span of seciton headers **/
7380
const Section_headers section_headers() const;
@@ -82,6 +89,7 @@ class Elf_binary {
8289

8390
private:
8491
Span data_;
92+
Program_header& program_header() const;
8593

8694
};
8795

api/util/elf_binary.inc

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -*-C++-*-
12
// This file is a part of the IncludeOS unikernel - www.includeos.org
23
//
34
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
@@ -20,26 +21,32 @@
2021
template <typename Arch>
2122
const typename Arch::Ehdr& Elf_binary<Arch>::elf_header() const{
2223
Expects(data_.size() >= (long) sizeof(typename Arch::Ehdr));
23-
return *reinterpret_cast<typename Arch::Ehdr*>(data_.data());
24+
return *reinterpret_cast<Elf_header*>(data_.data());
2425
}
2526

2627
template <typename Arch>
27-
const typename Arch::Phdr& Elf_binary<Arch>::program_header() const{
28+
typename Arch::Phdr& Elf_binary<Arch>::program_header() const{
2829
auto hdr = elf_header();
2930
Expects(data_.size() >= (long)(hdr.e_phoff + sizeof(typename Arch::Phdr)));
30-
return *reinterpret_cast<typename Arch::Phdr*>(data_.data() + hdr.e_phoff);
31+
return *reinterpret_cast<Program_header*>(data_.data() + hdr.e_phoff);
32+
}
33+
34+
35+
template <typename Arch>
36+
const typename Elf_binary<Arch>::Program_headers Elf_binary<Arch>::program_headers() const {
37+
return {reinterpret_cast<Program_header*>(&program_header()), elf_header().e_phnum};
3138
}
3239

3340

3441
template <typename Arch>
3542
void Elf_binary<Arch>::print_summary() {
3643

37-
auto hdr = elf_header();
44+
auto hdr = elf_header();
3845

3946
for(int i {0}; i < EI_NIDENT; ++i) {
4047
std::cout << hdr.e_ident[i];
4148
}
42-
49+
4350
std::cout << "\nType: "
4451
<< ((hdr.e_type == ET_EXEC) ? " ELF Executable\n" : "Non-executable\n");
4552
std::cout << "Machine: ";
@@ -52,34 +59,34 @@ void Elf_binary<Arch>::print_summary() {
5259
break;
5360
default:
5461
std::cout << "Other (" << hdr.e_machine << ")\n";
55-
break;
62+
break;
5663
}
57-
64+
5865
std::cout << "Version: " << hdr.e_version << '\n';
5966
std::cout << "Entry point: 0x" << std::hex << hdr.e_entry << '\n';
6067
std::cout << "Number of program headers: " << std::dec << hdr.e_phnum << '\n';
6168
std::cout << "Program header offset: " << hdr.e_phoff << '\n';
6269
std::cout << "Number of section headers: " << hdr.e_shnum << '\n';
6370
std::cout << "Section header offset: " << hdr.e_shoff << '\n';
64-
std::cout << "Size of ELF-header: " << hdr.e_ehsize << " bytes\n";
71+
std::cout << "Size of ELF-header: " << hdr.e_ehsize << " bytes\n";
6572
}
6673

6774

6875
template <typename Arch>
6976
bool Elf_binary<Arch>::is_executable(){
70-
return elf_header().e_type == ET_EXEC;
77+
return elf_header().e_type == ET_EXEC;
7178
}
7279

7380
template <typename Arch>
7481
bool Elf_binary<Arch>::is_bootable(){
7582

7683
bool has_multiboot = false;
77-
84+
7885
try {
7986
section_header(".multiboot");
8087
has_multiboot = true;
8188
}catch(...) {}
82-
89+
8390
return is_executable() and has_multiboot;
8491
}
8592

@@ -90,24 +97,36 @@ bool Elf_binary<Arch>::is_ELF(){
9097
data_[EI_MAG0] == ELFMAG0 and
9198
data_[EI_MAG1] == ELFMAG1 and
9299
data_[EI_MAG2] == ELFMAG2 and
93-
data_[EI_MAG3] == ELFMAG3;
94-
100+
data_[EI_MAG3] == ELFMAG3;
101+
95102
}
96103

97104

98105
template <typename Arch>
99106
void Elf_binary<Arch>::validate(){
100-
107+
101108
if (not is_ELF() or not is_bootable() or not is_executable())
102-
throw Elf_exception("Not a bootable ELF binary.");
103-
109+
throw Elf_exception("Not a bootable and executable ELF binary.");
110+
104111
}
105112

106113
template <typename Arch>
107114
typename Arch::Addr Elf_binary<Arch>::entry() {
108115
return elf_header().e_entry;
109116
}
110117

118+
119+
template <typename Arch>
120+
std::vector<const typename Arch::Phdr*> Elf_binary<Arch>::loadable_segments() {
121+
std::vector<const Program_header*> hdrs;
122+
for (auto& phdr : program_headers()) {
123+
if (phdr.p_type == PT_LOAD)
124+
hdrs.push_back(&phdr);
125+
}
126+
return hdrs;
127+
};
128+
129+
111130
template <typename Arch>
112131
const typename Elf_binary<Arch>::Section_headers Elf_binary<Arch>::section_headers() const {
113132
return {reinterpret_cast<Section_header*>(data_.data() + elf_header().e_shoff),

cmake/cross_compiled_libraries.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,39 @@ if (WITH_SOLO5)
3232
ExternalProject_Add(solo5_repo
3333
PREFIX precompiled
3434
BUILD_IN_SOURCE 1
35-
GIT_REPOSITORY https://github.com/ricarkol/solo5.git
36-
GIT_TAG includeos64
37-
CONFIGURE_COMMAND ./configure.sh
35+
GIT_REPOSITORY https://github.com/solo5/solo5.git
36+
GIT_TAG f8a277f83807333685742228ffef0d87270207cf
37+
CONFIGURE_COMMAND CC=gcc ./configure.sh
3838
UPDATE_COMMAND ""
39-
BUILD_COMMAND make build
39+
BUILD_COMMAND make
4040
INSTALL_COMMAND ""
4141
)
4242

4343
set(SOLO5_REPO_DIR ${CMAKE_CURRENT_BINARY_DIR}/precompiled/src/solo5_repo)
44-
set(SOLO5_INCLUDE_DIR ${SOLO5_REPO_DIR}/build/include/)
45-
set(SOLO5_LIB_DIR ${SOLO5_REPO_DIR}/build/${ARCH})
44+
set(SOLO5_INCLUDE_DIR ${SOLO5_REPO_DIR}/kernel)
4645

4746
# solo5 in ukvm mode (let's call it "solo5")
4847
add_library(solo5 STATIC IMPORTED)
49-
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_LIB_DIR}/ukvm/solo5.o)
48+
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_REPO_DIR}/kernel/ukvm/solo5.o)
5049

5150
# ukvm-bin
5251
add_library(ukvm-bin STATIC IMPORTED)
53-
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_LIB_DIR}/ukvm/ukvm-bin)
52+
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_REPO_DIR}/ukvm/ukvm-bin)
5453

5554
add_dependencies(solo5 solo5_repo)
5655
add_dependencies(ukvm-bin solo5_repo)
5756

5857
# Some OS components depend on solo5 (for solo5.h for example)
5958
add_dependencies(PrecompiledLibraries solo5)
59+
add_dependencies(PrecompiledLibraries ukvm-bin)
6060

6161
# Only x86_64 supported at the moment
6262
if ("${ARCH}" STREQUAL "x86_64")
63-
install(FILES ${SOLO5_LIB_DIR}/ukvm/solo5.o ${SOLO5_LIB_DIR}/ukvm/ukvm-bin DESTINATION includeos/${ARCH}/lib)
63+
install(FILES ${SOLO5_REPO_DIR}/kernel/ukvm/solo5.o ${SOLO5_REPO_DIR}/ukvm/ukvm-bin DESTINATION includeos/${ARCH}/lib)
6464
endif()
6565

66+
install(FILES ${SOLO5_INCLUDE_DIR}/solo5.h DESTINATION includeos/${ARCH}/include)
67+
6668
endif (WITH_SOLO5)
6769

6870
set(PRECOMPILED_DIR ${CMAKE_CURRENT_BINARY_DIR}/precompiled/src/PrecompiledLibraries/${ARCH})
@@ -99,8 +101,6 @@ install(DIRECTORY ${LIBCXX_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/li
99101

100102
install(DIRECTORY ${NEWLIB_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/newlib)
101103

102-
install(DIRECTORY ${SOLO5_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/solo5)
103-
104104
install(FILES ${CRTEND} ${CRTBEGIN} DESTINATION includeos/${ARCH}/lib)
105105

106106
install(FILES ${NEWLIB_LIB_DIR}/libc.a ${NEWLIB_LIB_DIR}/libg.a ${NEWLIB_LIB_DIR}/libm.a ${LIBGCC_LIB_DIR}/libgcc.a ${LIBCXX_LIB_DIR}/libc++.a ${LIBCXX_LIB_DIR}/libc++abi.a DESTINATION includeos/${ARCH}/lib)

cmake/post.service.cmake

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,22 @@ endif()
377377

378378
# all the OS and C/C++ libraries + crt end
379379
target_link_libraries(service
380-
libplatform
381-
libarch
382380
libos
383381
libbotan
384382
libosdeps
385-
cxxabi
386-
libc
387-
libcxx
388-
libm
389-
libg
390-
libgcc
391383

392384
libplatform
393385
libarch
394386
libos
395-
libbotan
396-
libosdeps
387+
388+
libplatform
389+
libarch
390+
libos
391+
libplatform
392+
397393
cxxabi
398394
libc
395+
libos
399396
libcxx
400397
libm
401398
libg

lib/uplink/starbase/config.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2-
"net" : [["10.20.17.111", "255.255.255.0", "10.20.17.1", "10.20.17.1"]],
2+
"net" : [
3+
{
4+
"iface": 0,
5+
"config": "static",
6+
"address": "10.0.0.42",
7+
"netmask": "255.255.255.0",
8+
"gateway": "10.0.0.1"
9+
}
10+
],
311
"uplink" : {
4-
"url" : "10.20.17.12:9090",
12+
"url" : "10.0.0.1:9090",
513
"token" : "kappa123",
614
"reboot" : true
715
}

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ include_directories(${BOTAN_DIR})
2222

2323
# TODO: i wanted to use a glob, but then found out that not everything is included
2424
set(OS_OBJECTS
25-
kernel/kernel_start.cpp kernel/multiboot.cpp
25+
kernel/multiboot.cpp
2626
kernel/syscalls.cpp kernel/os.cpp kernel/cpuid.cpp
2727
kernel/events.cpp kernel/memmap.cpp kernel/pci_manager.cpp
28-
kernel/heap.cpp kernel/service_stub.cpp kernel/main_call.cpp
28+
kernel/heap.cpp kernel/service_stub.cpp
2929
kernel/elf.cpp kernel/terminal.cpp kernel/terminal_disk.cpp
3030
kernel/vga.cpp kernel/context.cpp kernel/context_asm.asm
3131
kernel/fiber.cpp kernel/tls.cpp

src/arch/i686/linker.ld

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ SECTIONS
2323
PROVIDE ( _ELF_START_ = . + 0x100000);
2424
PROVIDE ( _LOAD_START_ = _ELF_START_); /* For convenience w. multiboot */
2525

26-
.multiboot (_ELF_START_ + SIZEOF_HEADERS): {
26+
. = _ELF_START_;
27+
28+
.multiboot (_ELF_START_ ): {
2729
PROVIDE(_MULTIBOOT_START_ = .);
2830
*(.multiboot)
2931
}
3032

3133
PROVIDE( _TEXT_START_ = . );
32-
.text (_TEXT_START_ ) :
34+
.text ALIGN(0x10) :
3335
{
3436
*(.text)
3537
*(.text.*)

src/arch/x86_64/arch_start.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern __multiboot_addr
2424
%define P4_TAB 0x1000
2525
%define P3_TAB 0x2000 ;; - 0x5fff
2626
%define P2_TAB 0x100000
27-
%define STACK_LOCATION 0xA00000
27+
%define STACK_LOCATION 0x9ffff0
2828

2929
[BITS 32]
3030
__arch_start:

0 commit comments

Comments
 (0)