Skip to content

Commit 0c9fec8

Browse files
authored
Merge pull request #1398 from fwsGonzo/ukvm
uKVM-64 port
2 parents dc319ab + c00882f commit 0c9fec8

47 files changed

Lines changed: 1491 additions & 212 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ build_x86_64/
4747
CMakeFiles*
4848
CMakeCache*
4949
cmake_install.cmake
50+
51+
dummy.disk

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ install(PROGRAMS
213213
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/grubify.sh
214214
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/qemu-ifup
215215
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/qemu_cmd.sh
216+
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/ukvm-ifup.sh
216217
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/run.sh
217218
DESTINATION includeos/scripts)
218219

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ More information is [available on the wiki](https://github.com/hioa-cs/IncludeOS
9797

9898
### Writing your first service
9999

100-
1. Copy the [./seed/service](./seed/service) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service/service.cpp) (Very simple example provided). This function will be called once the OS is up and running.
100+
1. Copy the [./seed/service](./seed/service) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service/service.cpp) (very simple example provided). This function will be called once the OS is up and running.
101101
2. Update the [CMakeLists.txt](./seed/service/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc.
102102

103103
**Example:**

api/hw/mac_addr.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ union Addr {
6464
: part{a,b,c,d,e,f}
6565
{}
6666

67+
static uint8_t dehex(char c)
68+
{
69+
if (c >= '0' && c <= '9')
70+
return (c - '0');
71+
else if (c >= 'a' && c <= 'f')
72+
return 10 + (c - 'a');
73+
else if (c >= 'A' && c <= 'F')
74+
return 10 + (c - 'A');
75+
else
76+
return 0;
77+
}
78+
79+
Addr(const char *smac) noexcept
80+
{
81+
uint8_t macaddr[PARTS_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
82+
for (size_t i = 0; i < PARTS_LEN; i++) {
83+
macaddr[i] = dehex(*smac++) << 4;
84+
macaddr[i] |= dehex(*smac++);
85+
smac++;
86+
}
87+
memcpy(part, macaddr, PARTS_LEN);
88+
}
89+
6790
/**
6891
* Assignment operator
6992
*

api/hw/nic.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ namespace hw {
100100
virtual void flush() = 0;
101101

102102
virtual ~Nic() {}
103+
104+
/** Trigger a read from buffers, pusing any packets up the stack */
105+
virtual void poll() = 0;
106+
103107
protected:
104108
/**
105109
* Constructor

api/hw/pci_device.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ namespace PCI {
4444

4545
static const uint32_t WTF {~0x0U};
4646

47+
static const uint32_t SOLO5_NET_DUMMY_ADDR {0xFFFE};
48+
static const uint32_t SOLO5_BLK_DUMMY_ADDR {0xFFFF};
49+
4750
/**
4851
* @brief PCI device message format
4952
*
@@ -103,6 +106,7 @@ namespace PCI {
103106
VENDOR_VIRTIO = 0x1AF4,
104107
VENDOR_REALTEK = 0x10EC,
105108
VENDOR_VMWARE = 0x15AD,
109+
VENDOR_SOLO5 = 0x5050,
106110
};
107111

108112
static inline const char* classcode_str(uint8_t code);

api/kernel/os.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ class OS {
6969
static int64_t micros_since_boot() noexcept;
7070

7171
/** Timestamp for when OS was booted */
72-
static RTC::timestamp_t boot_timestamp()
73-
{ return RTC::boot_timestamp(); }
72+
static RTC::timestamp_t boot_timestamp();
7473

7574
/** Uptime in whole seconds. */
76-
static RTC::timestamp_t uptime() {
77-
return RTC::time_since_boot();
78-
}
75+
static RTC::timestamp_t uptime();
7976

8077
static MHz cpu_freq() noexcept
8178
{ return cpu_mhz_; }
@@ -145,6 +142,8 @@ class OS {
145142
**/
146143
static void add_stdout_default_serial();
147144

145+
static void add_stdout_solo5();
146+
148147
/** Memory page helpers */
149148
static constexpr uint32_t page_size() noexcept {
150149
return 4096;
@@ -217,6 +216,8 @@ class OS {
217216
/** Start the OS. @todo Should be `init()` - and not accessible from ABI */
218217
static void start(uint32_t boot_magic, uint32_t boot_addr);
219218

219+
static void start(char *cmdline, uintptr_t mem_size);
220+
220221
/** Get "kernel modules", provided by multiboot */
221222
static Span_mods modules();
222223

@@ -250,6 +251,9 @@ class OS {
250251
static bool power_;
251252
static bool boot_sequence_passed_;
252253
static MHz cpu_mhz_;
254+
255+
// XXX: Only used by solo5
256+
static RTC::timestamp_t booted_at_;
253257
static std::string version_str_;
254258
static std::string arch_str_;
255259
static Plugin_vec plugins_;

api/kernel/solo5_manager.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#ifndef KERNEL_SOLO5_MANAGER_HPP
19+
#define KERNEL_SOLO5_MANAGER_HPP
20+
21+
#include <memory>
22+
#include <delegate>
23+
#include <hw/devices.hpp>
24+
25+
class Solo5_manager {
26+
public:
27+
using Nic_ptr = std::unique_ptr<hw::Nic>;
28+
using Blk_ptr = std::unique_ptr<hw::Block_device>;
29+
30+
static void register_net(delegate<Nic_ptr()>);
31+
static void register_blk(delegate<Blk_ptr()>);
32+
33+
static void init();
34+
}; //< class Solo5_manager
35+
36+
#endif //< KERNEL_SOLO5_MANAGER_HPP

api/util/crc32.hpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,37 @@ static uint32_t crc_32_tab[] =
8989

9090
#ifdef __SSE4_2__
9191
#include <immintrin.h>
92+
inline bool ____is__aligned(const uint8_t* buffer, const int align) noexcept {
93+
return (((uintptr_t) buffer) & (align-1)) == 0;
94+
}
9295

93-
inline uint32_t crc32_hw(const uint8_t* buffer, size_t len)
96+
inline uint32_t crc32_hw(const uint8_t* buffer, size_t len) noexcept
9497
{
9598
uint32_t hash = 0xFFFFFFFF;
96-
for (size_t i = 0; i < len; i++) {
97-
hash = _mm_crc32_u8(hash, buffer[i]);
99+
// 8-bits until 4-byte aligned
100+
while (____is__aligned(buffer, 4) == false && len > 0) {
101+
hash = _mm_crc32_u8(hash, *buffer++); len--;
102+
}
103+
// 16 bytes at a time
104+
while (len >= 16) {
105+
hash = _mm_crc32_u32(hash, *(uint32_t*) (buffer + 0));
106+
hash = _mm_crc32_u32(hash, *(uint32_t*) (buffer + 4));
107+
hash = _mm_crc32_u32(hash, *(uint32_t*) (buffer + 8));
108+
hash = _mm_crc32_u32(hash, *(uint32_t*) (buffer + 12));
109+
buffer += 16; len -= 16;
110+
}
111+
// 4 bytes at a time
112+
while (len >= 4) {
113+
hash = _mm_crc32_u32(hash, *(uint32_t*) buffer);
114+
buffer += 4; len -= 4;
115+
}
116+
// remaining bytes
117+
if (len & 2) {
118+
hash = _mm_crc32_u16(hash, *(uint16_t*) buffer);
119+
buffer += 2;
120+
}
121+
if (len & 1) {
122+
hash = _mm_crc32_u8(hash, *buffer);
98123
}
99124
return hash ^ 0xFFFFFFFF;
100125
}

cmake/cross_compiled_libraries.txt

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ else(BUNDLE_LOC)
2828

2929
endif (BUNDLE_LOC)
3030

31+
ExternalProject_Add(solo5_repo
32+
PREFIX precompiled
33+
BUILD_IN_SOURCE 1
34+
GIT_REPOSITORY https://github.com/ricarkol/solo5.git
35+
GIT_TAG includeos64
36+
CONFIGURE_COMMAND ./configure.sh
37+
UPDATE_COMMAND ""
38+
BUILD_COMMAND make build
39+
INSTALL_COMMAND ""
40+
)
41+
42+
set(SOLO5_REPO_DIR ${CMAKE_CURRENT_BINARY_DIR}/precompiled/src/solo5_repo)
43+
set(SOLO5_INCLUDE_DIR ${SOLO5_REPO_DIR}/build/include/)
44+
set(SOLO5_LIB_DIR ${SOLO5_REPO_DIR}/build/${ARCH})
45+
46+
# solo5 in ukvm mode (let's call it "solo5")
47+
add_library(solo5 STATIC IMPORTED)
48+
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_LIB_DIR}/ukvm/solo5.o)
49+
50+
# ukvm-bin
51+
add_library(ukvm-bin STATIC IMPORTED)
52+
set_target_properties(solo5 PROPERTIES IMPORTED_LOCATION ${SOLO5_LIB_DIR}/ukvm/ukvm-bin)
53+
54+
add_dependencies(solo5 solo5_repo)
55+
add_dependencies(ukvm-bin solo5_repo)
56+
57+
# Some OS components depend on solo5 (for solo5.h for example)
58+
add_dependencies(PrecompiledLibraries solo5)
59+
3160
set(PRECOMPILED_DIR ${CMAKE_CURRENT_BINARY_DIR}/precompiled/src/PrecompiledLibraries/${ARCH})
3261

3362
set(LIBCXX_INCLUDE_DIR ${PRECOMPILED_DIR}/libcxx/include/)
@@ -54,10 +83,6 @@ add_library(libm STATIC IMPORTED)
5483
set_target_properties(libm PROPERTIES IMPORTED_LOCATION ${NEWLIB_LIB_DIR}/libm.a)
5584
add_dependencies(libm PrecompiledLibraries)
5685

57-
add_library(libgcc STATIC IMPORTED)
58-
set_target_properties(libgcc PROPERTIES IMPORTED_LOCATION ${LIBGCC_LIB_DIR}/libgcc.a)
59-
add_dependencies(libgcc PrecompiledLibraries)
60-
6186
set(CRTEND ${PRECOMPILED_DIR}/crt/crtend.o)
6287
set(CRTBEGIN ${PRECOMPILED_DIR}/crt/crtbegin.o)
6388

@@ -66,6 +91,13 @@ install(DIRECTORY ${LIBCXX_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/li
6691

6792
install(DIRECTORY ${NEWLIB_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/newlib)
6893

94+
install(DIRECTORY ${SOLO5_INCLUDE_DIR} DESTINATION includeos/${ARCH}/include/solo5)
95+
6996
install(FILES ${CRTEND} ${CRTBEGIN} DESTINATION includeos/${ARCH}/lib)
7097

98+
# Only x86_64 supported at the moment
99+
if ("${ARCH}" STREQUAL "x86_64")
100+
install(FILES ${SOLO5_LIB_DIR}/ukvm/solo5.o ${SOLO5_LIB_DIR}/ukvm/ukvm-bin DESTINATION includeos/${ARCH}/lib)
101+
endif()
102+
71103
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)

0 commit comments

Comments
 (0)