Skip to content

Commit 7e6c62d

Browse files
committed
Merge branch 'dev' of https://github.com/hioa-cs/IncludeOS into test_improvements
2 parents d92e4e9 + 0c9d09b commit 7e6c62d

196 files changed

Lines changed: 975 additions & 196665 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: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
*.o
44
*.out
55
*.log
6-
\#*
7-
\*.*
8-
\.\#*
96
*.iso
107
*.qcow2
118
*.vdi
@@ -25,8 +22,6 @@ src/compile_commands.json
2522
*.project
2623
*.workspace
2724

28-
vmbuild/vmbuild
29-
3025
*.img
3126
*.img.*
3227

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ IncludeOS is being developed on GitHub. Create your own fork, send us a pull req
9797

9898
## C++ Guidelines
9999

100-
We want to adhere as much as possible to the [ISO C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines), maintained by the [Jedi Council](https://isocpp.org/). When (not if) you find code in IncludeOS which doesn't adhere, please let us know in the [issue tracker](https://github.com/hioa-cs/IncludeOS/issues) - or even better, fix it in your own fork and send us a [pull-request](https://github.com/hioa-cs/IncludeOS/pulls).
100+
We want to adhere as much as possible to the [ISO C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines). When (not if) you find code in IncludeOS which doesn't adhere, please let us know in the [issue tracker](https://github.com/hioa-cs/IncludeOS/issues) - or even better, fix it in your own fork and send us a [pull-request](https://github.com/hioa-cs/IncludeOS/pulls).
101101

102102
## Read more on the wiki
103103

api/hw/serial.hpp

Lines changed: 25 additions & 23 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.
@@ -18,37 +18,38 @@
1818
#ifndef HW_SERIAL_HPP
1919
#define HW_SERIAL_HPP
2020

21-
//#define DEBUG
21+
//#define DEBUG
2222

2323
#include <os>
2424
#include <hw/ioport.hpp>
2525
#include <cstdio>
2626

27-
namespace hw{
27+
namespace hw {
2828

2929
class Serial {
30-
3130
public:
32-
31+
3332
/** On Data handler. Return value indicates if the buffer should be flushed **/
3433
using on_data_handler = delegate<void(char c)>;
35-
using on_string_handler = delegate<void(const std::string s)>;
34+
using on_string_handler = delegate<void(const std::string& s)>;
3635

37-
using irq_delg = delegate<void()>;
38-
3936
template <uint16_t PORT>
4037
static Serial& port(){
4138
static Serial s{PORT};
4239
return s;
4340
}
44-
41+
42+
OS::print_func get_print_handler() {
43+
return {this, &Serial::print_handler};
44+
}
45+
4546
void on_data(on_data_handler del);
4647
void on_readline(on_string_handler del, char delim = '\r');
47-
48+
4849
void enable_interrupt();
4950
void disable_interrupt();
5051

51-
char read();
52+
char read();
5253
void write(char c);
5354
int received();
5455
int is_transmit_empty();
@@ -58,15 +59,16 @@ namespace hw{
5859
Serial( Serial&& ) = delete;
5960
Serial& operator=(Serial&) = delete;
6061
Serial operator=(Serial&&) = delete;
61-
62-
void init();
63-
62+
63+
void init();
64+
6465
private:
65-
66+
void print_handler(const char*, size_t);
67+
6668
Serial(int port);
67-
static constexpr uint16_t ports_[] {0x3F8, 0x2F8, 0x3E8, 0x2E8 };
68-
static constexpr uint8_t irqs_[] {4, 3, 15, 15 };
69-
69+
static constexpr uint16_t ports_[] {0x3F8, 0x2F8, 0x3E8, 0x2E8 };
70+
static constexpr uint8_t irqs_[] {4, 3, 15, 15 };
71+
7072
//static const char default_newline = '\r';
7173
char newline = '\r'; //default_newline;
7274

@@ -75,13 +77,13 @@ namespace hw{
7577
uint8_t irq_{4};
7678
std::string buf{};
7779

78-
on_data_handler on_data_ = [](char c){ debug("Default on_data: %c \n", c); (void)c; };
79-
on_string_handler on_readline_ = [](std::string s) { (void)s; };
80-
80+
on_data_handler on_data_ = [](char c){ debug("Default on_data: %c \n", c); (void)c; };
81+
on_string_handler on_readline_ = [](const std::string& s) { (void)s; };
82+
8183
void irq_handler_ ();
8284
void readline_handler_(char c);
8385
};
84-
86+
8587
}
8688

8789
#endif

api/kernel/cpuid.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
#define KERNEL_CPUID_HPP
2121

2222
struct CPUID {
23-
struct cpuid_t {
24-
unsigned int EAX;
25-
unsigned int EBX;
26-
unsigned int ECX;
27-
unsigned int EDX;
28-
};
29-
3023
static bool isAmdCpu();
3124
static bool isIntelCpu();
3225
static bool hasRDRAND();

api/kernel/irq_manager.hpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,19 @@ class IRQ_manager {
117117
/**
118118
* Get the IRQ manager instance
119119
*/
120-
static inline IRQ_manager& get(){
121-
static IRQ_manager bsp{0};
120+
static inline IRQ_manager& get() {
121+
static IRQ_manager bsp;
122122
return bsp;
123123
}
124124

125125
uint8_t get_next_msix_irq();
126126
void register_irq(uint8_t vector);
127127

128-
/** Get the total number of cycles spent in halt **/
129-
uint64_t cycles_hlt(){
130-
return cycles_hlt_;
131-
}
132-
133-
/** Get the total number of cycles since boot **/
134-
uint64_t cycles_total(){
135-
return cycles_total_;
136-
}
128+
/** process all pending interrupts */
129+
void process_interrupts();
137130

138131
private:
139-
140-
IRQ_manager(uint8_t cpu);
132+
IRQ_manager() = default;
141133
IRQ_manager(IRQ_manager&) = delete;
142134
IRQ_manager(IRQ_manager&&) = delete;
143135
IRQ_manager& operator=(IRQ_manager&&) = delete;
@@ -151,9 +143,6 @@ class IRQ_manager {
151143
MemBitmap irq_pend;
152144
MemBitmap irq_todo;
153145

154-
uint64_t& cycles_hlt_;
155-
uint64_t& cycles_total_;
156-
157146
static const char default_attr {static_cast<char>(0x8e)};
158147
static const uint16_t default_sel {0x8};
159148

@@ -176,9 +165,6 @@ class IRQ_manager {
176165

177166
void bsp_init();
178167

179-
/** Notify all delegates waiting for interrupts */
180-
void notify();
181-
182168
}; //< IRQ_manager
183169

184170
#endif //< KERNEL_IRQ_MANAGER_HPP

api/kernel/os.hpp

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
#include <vector>
2828
#include <kernel/rtc.hpp>
2929

30-
namespace hw{ class Serial; }
31-
3230
/**
3331
* The entrypoint for OS services
3432
*
3533
* @note For device access, see Dev
3634
*/
3735
class OS {
3836
public:
39-
using rsprint_func = delegate<void(const char*, size_t)>;
37+
using print_func = delegate<void(const char*, size_t)>;
4038
using Custom_init = delegate<void()>;
4139

4240
/* Get the version of the os */
@@ -71,24 +69,9 @@ class OS {
7169
static void shutdown();
7270

7371
/**
74-
* Write a cstring to serial port. @todo Should be moved to Dev::serial(n).
75-
*
76-
* @param ptr: The string to write to serial port
77-
*/
78-
static size_t rsprint(const char* ptr);
79-
static size_t rsprint(const char* ptr, const size_t len);
80-
81-
/**
82-
* Write a character to serial port.
83-
*
84-
* @param c: The character to print to serial port
85-
*/
86-
static void rswrite(const char c);
87-
88-
/**
89-
* Write to serial port with rswrite.
72+
* Write data to standard out callbacks
9073
*/
91-
static void default_rsprint(const char*, size_t);
74+
static size_t print(const char* ptr, const size_t len);
9275

9376
/** Start the OS. @todo Should be `init()` - and not accessible from ABI */
9477
static void start(uint32_t boot_magic, uint32_t boot_addr);
@@ -102,21 +85,21 @@ class OS {
10285
static void halt();
10386

10487
/**
105-
* Set handler for serial output.
88+
* Add handler for standard output.
10689
*/
107-
static void set_rsprint(rsprint_func func) {
108-
rsprint_handler_ = func;
90+
static void add_stdout(print_func func) {
91+
print_handlers.push_back(func);
10992
}
11093

11194
/** Memory page helpers */
112-
static inline constexpr uint32_t page_size() {
95+
static constexpr uint32_t page_size() {
11396
return 4096;
11497
}
115-
static inline constexpr uint32_t page_nr_from_addr(uint32_t x){
116-
return x >> page_shift_;
98+
static constexpr uint32_t page_nr_from_addr(uint32_t x) {
99+
return x >> PAGE_SHIFT;
117100
}
118-
static inline constexpr uint32_t base_from_page_nr(uint32_t x){
119-
return x << page_shift_;
101+
static constexpr uint32_t base_from_page_nr(uint32_t x) {
102+
return x << PAGE_SHIFT;
120103
}
121104

122105
/** Currently used dynamic memory, in bytes */
@@ -132,7 +115,7 @@ class OS {
132115
static Memory_map& memory_map () noexcept {
133116
static Memory_map memmap_ {};
134117
return memmap_;
135-
};
118+
}
136119

137120
/**
138121
* Register a custom initialization function. The provided delegate is
@@ -149,7 +132,7 @@ class OS {
149132
/** Process multiboot info. Called by 'start' if multibooted **/
150133
static void multiboot(uint32_t boot_magic, uint32_t boot_addr);
151134

152-
static const int page_shift_ = 12;
135+
static constexpr int PAGE_SHIFT = 12;
153136

154137
/** Indicate if the OS is running. */
155138
static bool power_;
@@ -159,9 +142,7 @@ class OS {
159142

160143
static MHz cpu_mhz_;
161144

162-
static rsprint_func rsprint_handler_;
163-
164-
static hw::Serial& com1;
145+
static std::vector<print_func> print_handlers;
165146

166147
static RTC::timestamp_t booted_at_;
167148
static std::string version_field;
@@ -190,7 +171,6 @@ class OS {
190171
~OS() = delete;
191172
// Prohibit construction
192173
OS() = delete;
193-
friend void begin_stack_sampling(uint16_t);
194174

195175
}; //< OS
196176

api/kernel/vga.hpp

Lines changed: 12 additions & 7 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.
@@ -18,6 +18,7 @@
1818
#ifndef KERNEL_VGA_HPP
1919
#define KERNEL_VGA_HPP
2020

21+
#include <os>
2122
#include <stdint.h>
2223

2324
class ConsoleVGA {
@@ -45,29 +46,33 @@ class ConsoleVGA {
4546

4647
explicit ConsoleVGA() noexcept;
4748

49+
OS::print_func get_print_handler() {
50+
return {this, &ConsoleVGA::write};
51+
}
52+
4853
constexpr static uint8_t make_color(const vga_color fg, const vga_color bg) noexcept
4954
{ return fg | bg << 4; }
50-
55+
5156
void write(const char* data, const size_t len) noexcept;
5257
void clear() noexcept;
53-
58+
5459
static const size_t VGA_WIDTH {80};
5560
static const size_t VGA_HEIGHT {25};
56-
61+
5762
uint16_t get(uint8_t x, uint8_t y);
5863
void put(const char, uint8_t color, uint8_t x, uint8_t y) noexcept;
5964
void put(const char, uint8_t x, uint8_t y) noexcept;
6065
void set_cursor(uint8_t, uint8_t) noexcept;
6166
void newline() noexcept;
6267
inline void set_color(vga_color c)
6368
{ color = c; };
64-
69+
6570
private:
6671
void increment(int) noexcept;
6772
void write(char) noexcept;
6873
static const uint16_t DEFAULT_ENTRY;
6974
void putent(uint16_t, uint8_t, uint8_t) noexcept;
70-
75+
7176
size_t row;
7277
size_t column;
7378
uint8_t color;

api/net/ip4/arp.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ namespace net {
9797
// @TODO: Add HÅREK-mapping here
9898
switch (nm) {
9999
case HH_MAP:
100-
arp_resolver_ = Arp_resolver::from<Arp, &Arp::hh_map>(*this);
100+
arp_resolver_ = {this, &Arp::hh_map};
101101
break;
102102
default:
103-
arp_resolver_ = Arp_resolver::from<Arp, &Arp::arp_resolve>(*this);
103+
arp_resolver_ = {this, &Arp::arp_resolve};
104104
}
105105
}
106106

@@ -145,7 +145,7 @@ namespace net {
145145
void arp_resolve(Packet_ptr);
146146
void hh_map(Packet_ptr);
147147

148-
Arp_resolver arp_resolver_ = Arp_resolver::from<Arp, &Arp::arp_resolve>(*this);
148+
Arp_resolver arp_resolver_ = {this, &Arp::arp_resolve};
149149

150150
PacketQueue waiting_packets_;
151151

0 commit comments

Comments
 (0)