Skip to content

Commit 4887518

Browse files
authored
Merge pull request #835 from fwsGonzo/dev
stdout: vector of delegates, elf: custom section for symbols
2 parents 939e98a + 35ec409 commit 4887518

170 files changed

Lines changed: 429 additions & 196534 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 & 21 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,7 +18,7 @@
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>
@@ -27,28 +27,31 @@
2727
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

3736
using irq_delg = delegate<void()>;
38-
37+
3938
template <uint16_t PORT>
4039
static Serial& port(){
4140
static Serial s{PORT};
4241
return s;
4342
}
44-
43+
44+
OS::print_func get_print_handler() {
45+
return OS::print_func::from(this, &Serial::print_handler);
46+
}
47+
4548
void on_data(on_data_handler del);
4649
void on_readline(on_string_handler del, char delim = '\r');
47-
50+
4851
void enable_interrupt();
4952
void disable_interrupt();
5053

51-
char read();
54+
char read();
5255
void write(char c);
5356
int received();
5457
int is_transmit_empty();
@@ -58,15 +61,16 @@ namespace hw{
5861
Serial( Serial&& ) = delete;
5962
Serial& operator=(Serial&) = delete;
6063
Serial operator=(Serial&&) = delete;
61-
62-
void init();
63-
64+
65+
void init();
66+
6467
private:
65-
68+
void print_handler(const char*, size_t);
69+
6670
Serial(int port);
67-
static constexpr uint16_t ports_[] {0x3F8, 0x2F8, 0x3E8, 0x2E8 };
68-
static constexpr uint8_t irqs_[] {4, 3, 15, 15 };
69-
71+
static constexpr uint16_t ports_[] {0x3F8, 0x2F8, 0x3E8, 0x2E8 };
72+
static constexpr uint8_t irqs_[] {4, 3, 15, 15 };
73+
7074
//static const char default_newline = '\r';
7175
char newline = '\r'; //default_newline;
7276

@@ -75,13 +79,13 @@ namespace hw{
7579
uint8_t irq_{4};
7680
std::string buf{};
7781

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-
82+
on_data_handler on_data_ = [](char c){ debug("Default on_data: %c \n", c); (void)c; };
83+
on_string_handler on_readline_ = [](const std::string& s) { (void)s; };
84+
8185
void irq_handler_ ();
8286
void readline_handler_(char c);
8387
};
84-
88+
8589
}
8690

8791
#endif

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 OS::print_func::from(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/profile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ struct StackSampler
4848
// enable or disable sample-taking
4949
// eg. disable sampling during stack sample result printout
5050
static void set_mask(bool);
51+
52+
enum mode_t {
53+
MODE_CURRENT,
54+
MODE_CALLER,
55+
};
56+
57+
// set sampling mode
58+
static void set_mode(mode_t);
5159
};
5260

53-
extern "C" {
54-
// print memory usage changes over time
55-
extern void print_heap_info();
56-
// used to validate that the backtrace is not corrupt
57-
extern void __validate_backtrace(char const* where, unsigned id = 0);
58-
}
59-
6061
#endif

0 commit comments

Comments
 (0)