File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,18 +131,24 @@ class OS {
131131 /* *
132132 * Write data to standard out callbacks
133133 */
134- static size_t print (const char * ptr, const size_t len);
134+ static void print (const char * ptr, const size_t len);
135135
136136 /* *
137137 * Add handler for standard output.
138138 */
139139 static void add_stdout (print_func func);
140140 /* *
141- * Add "default" serial port output
141+ * Add stdout handler that simply calls OS::default_stdout
142142 **/
143- static void add_stdout_default_serial ();
143+ static void add_default_stdout () {
144+ add_stdout (OS::default_stdout);
145+ }
144146
145- static void add_stdout_solo5 ();
147+ /* *
148+ * The default output method preferred by each platform
149+ * Directly writes the string to its output mechanism
150+ **/
151+ static void default_stdout (const char *, size_t );
146152
147153 /* * Memory page helpers */
148154 static constexpr uint32_t page_size () noexcept {
Original file line number Diff line number Diff line change @@ -25,6 +25,6 @@ void default_stdout_handlers()
2525 [] (const char * str, size_t len)
2626 {
2727 if (OS::is_booted () || OS::is_panicking ())
28- kprintf ( " %.*s " , len, str );
28+ OS::default_stdout (str , len);
2929 });
3030}
Original file line number Diff line number Diff line change @@ -43,7 +43,6 @@ Solo5Net::Solo5Net()
4343 mac_addr = MAC::Addr (solo5_net_mac_str ());
4444}
4545
46- #include < cstdlib>
4746void Solo5Net::transmit (net::Packet_ptr pckt)
4847{
4948 net::Packet_ptr tail = std::move (pckt);
@@ -53,12 +52,8 @@ void Solo5Net::transmit(net::Packet_ptr pckt)
5352 // next in line
5453 auto next = tail->detach_tail ();
5554 // write data to network
56- // explicitly release the data to prevent destructor being called
57- net::Packet* pckt = tail.release ();
58- uint8_t *buf = pckt->buf ();
59-
60- solo5_net_write_sync (buf, pckt->size ());
61-
55+ solo5_net_write_sync (tail->buf (), tail->size ());
56+ // set tail to next, releasing tail
6257 tail = std::move (next);
6358 // Stat increase packets transmitted
6459 packets_tx_++;
@@ -99,8 +94,10 @@ net::Packet_ptr Solo5Net::recv_packet()
9994void Solo5Net::poll ()
10095{
10196 auto pckt_ptr = recv_packet ();
102- if (pckt_ptr != nullptr )
97+
98+ if (LIKELY (pckt_ptr != nullptr )) {
10399 Link::receive (std::move (pckt_ptr));
100+ }
104101}
105102
106103void Solo5Net::deactivate ()
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ extern "C" {
3333#endif
3434
3535extern void __serial_print1 (const char * cstr );
36+ extern void __serial_print (const char * str , size_t len );
3637
3738/**
3839 * The earliest possible print function (requires no heap, global ctors etc.)
Original file line number Diff line number Diff line change @@ -65,7 +65,6 @@ std::string OS::cmdline{Service::binary_name()};
6565// stdout redirection
6666using Print_vec = fixedvector<OS::print_func, 8 >;
6767static Print_vec os_print_handlers (Fixedvector_Init::UNINIT);
68- extern void default_stdout_handlers ();
6968
7069// Plugins
7170OS::Plugin_vec OS::plugins_ (Fixedvector_Init::UNINIT);
@@ -102,23 +101,15 @@ void OS::add_stdout(OS::print_func func)
102101{
103102 os_print_handlers.add (func);
104103}
105- void OS::add_stdout_default_serial ()
106- {
107- add_stdout (
108- [] (const char * str, const size_t len) {
109- kprintf (" %.*s" , static_cast <int >(len), str);
110- });
111- }
112104__attribute__ ((weak))
113105void default_stdout_handlers()
114106{
115- OS::add_stdout_default_serial ();
107+ OS::add_default_stdout ();
116108}
117- size_t OS::print (const char * str, const size_t len)
109+ void OS::print (const char * str, const size_t len)
118110{
119111 for (auto & func : os_print_handlers)
120112 func (str, len);
121- return len;
122113}
123114
124115void OS::legacy_boot () {
Original file line number Diff line number Diff line change @@ -16,11 +16,6 @@ void __arch_poweroff()
1616 __builtin_unreachable ();
1717}
1818
19- void default_stdout_handlers ()
20- {
21- OS::add_stdout_default_serial ();
22- }
23-
2419void __platform_init (){
2520 // FIXME: set up minimal CPU exception handlers
2621 // TODO: set up minimal CPU exception handlers
Original file line number Diff line number Diff line change 2020
2121#include < cstdio>
2222#include < boot/multiboot.h>
23- #include < hw/cmos.hpp>
2423#include < kernel/os.hpp>
2524#include < kernel/irq_manager.hpp>
2625#include < kernel/rtc.hpp>
@@ -96,6 +95,10 @@ void OS::halt() {
9695 *os_cycles_hlt += cycles_since_boot () - *os_cycles_total;
9796}
9897
98+ void OS::default_stdout (const char * str, const size_t len)
99+ {
100+ __serial_print (str, len);
101+ }
99102
100103void OS::start (uint32_t boot_magic, uint32_t boot_addr)
101104{
@@ -226,5 +229,3 @@ void OS::event_loop()
226229 extern void __arch_poweroff ();
227230 __arch_poweroff ();
228231}
229-
230-
Original file line number Diff line number Diff line change @@ -22,3 +22,11 @@ void __serial_print1(const char* cstr)
2222 hw::outb (port, *cstr++);
2323 }
2424}
25+ extern " C"
26+ void __serial_print (const char * str, size_t len)
27+ {
28+ for (size_t i = 0 ; i < len; i++) {
29+ while (not (hw::inb (port + 5 ) & 0x20 ));
30+ hw::outb (port, str[i]);
31+ }
32+ }
Original file line number Diff line number Diff line change @@ -9,18 +9,12 @@ extern "C" {
99#include < solo5.h>
1010}
1111
12- extern void solo5_stdout_handlers ();
13- extern void __platform_init ();
12+ extern void __platform_init ();
13+ extern void default_stdout_handlers ();
1414
1515char cmdline[256 ];
1616uintptr_t mem_size;
1717
18- __attribute__ ((weak))
19- void solo5_stdout_handlers()
20- {
21- OS::add_stdout_solo5 ();
22- }
23-
2418extern " C" {
2519 void __init_sanity_checks ();
2620 void kernel_sanity_checks ();
@@ -38,7 +32,7 @@ extern "C" {
3832 void (*current_eoi_mechanism)();
3933 void (*current_intr_handler)();
4034 void (*cpu_sampling_irq_handler)();
41-
35+
4236
4337 void kernel_start ()
4438 {
@@ -68,7 +62,7 @@ extern "C" {
6862 _init_syscalls ();
6963
7064 // Initialize stdout handlers
71- solo5_stdout_handlers ();
65+ default_stdout_handlers ();
7266
7367 // Call global ctors
7468 __libc_init_array ();
Original file line number Diff line number Diff line change @@ -70,12 +70,9 @@ int64_t OS::micros_since_boot() noexcept {
7070 return uptime () / 1000 ;
7171}
7272
73- void OS::add_stdout_solo5 ( )
73+ void OS::default_stdout ( const char * str, const size_t len )
7474{
75- add_stdout (
76- [] (const char * str, const size_t len) {
77- solo5_console_write (str, len);
78- });
75+ solo5_console_write (str, len);
7976}
8077
8178void OS::start (char * _cmdline, uintptr_t mem_size)
You can’t perform that action at this time.
0 commit comments