Skip to content

Commit 093c011

Browse files
authored
Merge pull request #1414 from alfred-bratterud/master
Merge dev
2 parents 44e4b3f + 8a770f3 commit 093c011

157 files changed

Lines changed: 4532 additions & 1240 deletions

File tree

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(CMAKE_C_COMPILER_TARGET ${TRIPLE})
1717

1818
message(STATUS "Target triple ${TRIPLE}")
1919

20+
option(WITH_SOLO5 "Install with solo5 support" ON)
21+
2022
set(CMAKE_TOOLCHAIN_FILE ${INCLUDEOS_ROOT}/cmake/${ARCH}-elf-toolchain.cmake)
2123

2224
project (includeos C CXX)
@@ -48,7 +50,7 @@ endif(cpu_feat_vanilla)
4850
option(single_threaded "Compile without SMP support" ON)
4951

5052
# create random hex string as stack protector canary
51-
string(RANDOM LENGTH 8 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)
53+
string(RANDOM LENGTH 16 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)
5254

5355
set(CAPABS "${CAPABS} -mno-red-zone -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE}")
5456

@@ -141,6 +143,7 @@ if(vmbuild)
141143
# Install vmbuilder as an external project
142144
ExternalProject_Add(vmbuild
143145
PREFIX vmbuild # Build where
146+
BUILD_ALWAYS 1
144147
SOURCE_DIR ${INCLUDEOS_ROOT}/vmbuild # Where is project located
145148
BINARY_DIR ${INCLUDEOS_ROOT}/vmbuild/build
146149
INSTALL_DIR ${BIN} # Where to install
@@ -151,6 +154,7 @@ endif(vmbuild)
151154
option(diskbuilder "Build and install memdisk helper tool" ON)
152155
if(diskbuilder)
153156
ExternalProject_Add(diskbuilder
157+
BUILD_ALWAYS 1
154158
SOURCE_DIR ${INCLUDEOS_ROOT}/diskimagebuild
155159
BINARY_DIR ${INCLUDEOS_ROOT}/diskimagebuild/build
156160
INSTALL_DIR ${BIN}
@@ -213,6 +217,7 @@ install(PROGRAMS
213217
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/grubify.sh
214218
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/qemu-ifup
215219
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/qemu_cmd.sh
220+
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/ukvm-ifup.sh
216221
${CMAKE_CURRENT_SOURCE_DIR}/etc/scripts/run.sh
217222
DESTINATION includeos/scripts)
218223

api/crash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// -*-C++-*-
2+
#pragma once
3+
#ifndef API_CRASH_HEADER
4+
#define API_CRASH_HEADER
5+
6+
#include <kernel/syscalls.hpp>
7+
8+
#endif

api/fs/dirent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace fs {
3838
size_{sz}, attrib_ {attr},
3939
modif {modt}
4040
{}
41+
Dirent(const Dirent&) noexcept;
4142

4243
Enttype type() const noexcept
4344
{ return ftype; }

api/fs/disk.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fs/filesystem.hpp>
2424
#include <fs/dirent.hpp>
2525
#include <hw/block_device.hpp>
26+
#include <common>
2627

2728
#include <deque>
2829
#include <vector>
@@ -129,7 +130,13 @@ namespace fs {
129130
// Returns a reference to a mounted filesystem
130131
// If no filesystem is mounted, the results are undefined
131132
File_system& fs() noexcept
132-
{ return *filesys; }
133+
{
134+
if(UNLIKELY(not fs_ready()))
135+
{
136+
throw Err_not_mounted{"Filesystem not ready - make sure to init_fs before accessing"};
137+
}
138+
return *filesys;
139+
}
133140

134141
private:
135142
void internal_init(partition_t part, on_init_func func);

api/hw/devices.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace hw {
4949
/** List all devices (decorated, as seen in boot output) */
5050
inline static void print_devices();
5151

52+
inline static void flush_all();
5253

5354
inline static void deactivate_all();
5455

@@ -161,6 +162,11 @@ namespace hw {
161162
deactivate_type(devices<hw::Block_device>());
162163
deactivate_type(devices<hw::Nic>());
163164
}
165+
inline void Devices::flush_all()
166+
{
167+
for (auto& dev : devices<hw::Nic>())
168+
dev->flush();
169+
}
164170

165171
} //< namespace hw
166172

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ namespace hw {
9696
/** Move this nic to current CPU **/
9797
virtual void move_to_this_cpu() = 0;
9898

99+
/** Flush remaining packets if possible. **/
100+
virtual void flush() = 0;
101+
99102
virtual ~Nic() {}
103+
104+
/** Trigger a read from buffers, pusing any packets up the stack */
105+
virtual void poll() = 0;
106+
100107
protected:
101108
/**
102109
* Constructor

api/hw/pci_device.hpp

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <cstdint>
2222
#include <common>
2323
#include <vector>
24+
#include <unordered_map>
2425

2526
#define PCI_CAP_ID_AF 0x13 /* PCI Advanced Features */
2627
#define PCI_CAP_ID_MAX PCI_CAP_ID_AF
@@ -43,6 +44,9 @@ namespace PCI {
4344

4445
static const uint32_t WTF {~0x0U};
4546

47+
static const uint32_t SOLO5_NET_DUMMY_ADDR {0xFFFE};
48+
static const uint32_t SOLO5_BLK_DUMMY_ADDR {0xFFFF};
49+
4650
/**
4751
* @brief PCI device message format
4852
*
@@ -71,7 +75,7 @@ namespace PCI {
7175
}; //< union msg
7276

7377
/** Relevant class codes (many more) */
74-
enum classcode_t {
78+
enum classcode : uint8_t {
7579
OLD = 0,
7680
STORAGE,
7781
NIC,
@@ -91,17 +95,23 @@ namespace PCI {
9195
ENCRYPTION,
9296
SIGPRO,
9397
OTHER=255
98+
99+
94100
}; //< enum classcode_t
95101

96-
enum {
102+
enum vendor_t : uint16_t {
97103
VENDOR_AMD = 0x1022,
98104
VENDOR_INTEL = 0x8086,
99105
VENDOR_CIRRUS = 0x1013,
100106
VENDOR_VIRTIO = 0x1AF4,
101107
VENDOR_REALTEK = 0x10EC,
102108
VENDOR_VMWARE = 0x15AD,
109+
VENDOR_SOLO5 = 0x5050,
103110
};
104111

112+
static inline const char* classcode_str(uint8_t code);
113+
static inline const char* vendor_str(uint16_t code);
114+
105115
struct Resource {
106116
int type;
107117
uint32_t start;
@@ -117,6 +127,8 @@ namespace PCI {
117127
} //< namespace PCI
118128

119129
namespace hw {
130+
131+
120132
struct msix_t;
121133
/**
122134
* @brief Communication class for all PCI devices
@@ -247,6 +259,8 @@ struct msix_t;
247259
};
248260
};
249261

262+
inline std::string to_string() const;
263+
250264
private:
251265
// @brief The 3-part PCI address
252266
uint16_t pci_addr_;
@@ -275,14 +289,60 @@ struct msix_t;
275289

276290
} //< namespace hw
277291

278-
namespace std {
279-
template<>
280-
struct hash<PCI::classcode_t> {
281-
public:
282-
std::size_t operator()(PCI::classcode_t const& key) const noexcept {
283-
return key;
284-
}
285-
};
292+
static const char* PCI::classcode_str(uint8_t code){
293+
const std::unordered_map<uint8_t, const char*> classcodes {
294+
{classcode::OLD, "Old"},
295+
{classcode::STORAGE, "Storage controller"},
296+
{classcode::NIC, "Network controller"},
297+
{classcode::DISPLAY, "Display controller"},
298+
{classcode::MULTIMEDIA, "Multimedia device"},
299+
{classcode::MEMORY, "Memory controller"},
300+
{classcode::BRIDGE, "Bridge device"},
301+
{classcode::COMMUNICATION, "Simple comm. controller "},
302+
{classcode::BASE_SYSTEM_PER,"Base system periph."},
303+
{classcode::INPUT_DEVICE, "Input device"},
304+
{classcode::DOCKING_STATION, "Docking station"},
305+
{classcode::PROCESSOR, "Processor"},
306+
{classcode::SERIAL_BUS, "Serial bus controller"},
307+
{classcode::WIRELESS, "Wireless"},
308+
{classcode::IO_CTL, "Intelligent IO controller"},
309+
{classcode::SATELLITE, "Satellite comm. controller"},
310+
{classcode::ENCRYPTION, "Encryption / decryption controller"},
311+
{classcode::SIGPRO,"Sigpro"},
312+
{classcode::OTHER, "Other"}
313+
};
314+
315+
auto it = classcodes.find(code);
316+
if (it != classcodes.end())
317+
return it->second;
318+
319+
return "Unknown classcode";
320+
}
321+
322+
static const char* PCI::vendor_str(uint16_t code){
323+
const std::unordered_map<uint16_t, const char*> classcodes {
324+
{VENDOR_AMD, "AMD"},
325+
{VENDOR_INTEL, "Intel"},
326+
{VENDOR_CIRRUS, "Cirrus"},
327+
{VENDOR_VIRTIO, "VirtIO"} ,
328+
{VENDOR_REALTEK, "REALTEK"},
329+
{VENDOR_VMWARE, "VMWare"}
330+
};
331+
332+
auto it = classcodes.find(code);
333+
return it == classcodes.end() ? "Unknown vendor" : it->second;
286334
}
287335

336+
337+
#include <sstream>
338+
std::string hw::PCI_Device::to_string() const {
339+
std::stringstream str;
340+
str << PCI::classcode_str(classcode()) << ", "
341+
<< PCI::vendor_str((PCI::vendor_t)vendor_id())
342+
<< std::hex << " ("<< vendor_id() << " / " << product_id() << ")";
343+
return str.str();
344+
};
345+
346+
347+
288348
#endif //< HW_PCI_DEVICE_HPP

api/kernel/cpuid.hpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
#ifndef KERNEL_CPUID_HPP
2020
#define KERNEL_CPUID_HPP
2121

22+
#include <unordered_map>
23+
#include <vector>
24+
2225
namespace CPUID
2326
{
27+
2428
enum class Feature
2529
{
2630
// ------------------------------------------------------------------------
@@ -46,7 +50,7 @@ namespace CPUID
4650
SSE4_1, // Streaming SIMD Extensions 4.1
4751
SSE4_2, // Streaming SIMD Extensions 4.2
4852
X2APIC, // Extended xAPIC Support
49-
MOVBE, // MOVBE Instruction
53+
MOVBE, // MOVBE Instruction (move after swapping bytes)
5054
POPCNT, // POPCNT Instruction
5155
TSC_DEADLINE, // Local APIC supports TSC Deadline
5256
AES, // AESNI Instruction
@@ -98,15 +102,32 @@ namespace CPUID
98102
SVM, // Secture Virtual Machines (AMD-V)
99103
// aka. AMD-V (AMD's virtualization extension)
100104
SSE4A, // SSE4a
105+
106+
// ------------------------------------------------------------------------
107+
// 4th gen. Core features
108+
// ------------------------------------------------------------------------
109+
AVX2, // AVX2
110+
BMI1, // Bit manipulation 1
111+
BMI2, // Bit manipulation 2
112+
LZCNT, // Count leading zero bits
101113
};
102114

115+
using Feature_map = const std::unordered_map<Feature, const char*>;
116+
using Feature_list = std::vector<Feature>;
117+
using Feature_names = std::vector<const char*>;
118+
119+
Feature_names detect_features_str();
120+
Feature_list detect_features();
121+
103122
bool is_amd_cpu() noexcept;
104123
bool is_intel_cpu() noexcept;
105124
bool has_feature(Feature f);
106125

107126
bool kvm_feature(unsigned id) noexcept;
108127
} //< CPUID
109128

129+
130+
110131
#define KVM_FEATURE_CLOCKSOURCE 0
111132
#define KVM_FEATURE_NOP_IO_DELAY 1
112133
#define KVM_FEATURE_MMU_OP 2 /* deprecated */

0 commit comments

Comments
 (0)