Skip to content

Commit c9c81f3

Browse files
authored
Merge pull request #1479 from fwsGonzo/dev
Fix initialization problems with high BSS value
2 parents 53069ba + 27899a5 commit c9c81f3

27 files changed

Lines changed: 222 additions & 299 deletions

api/kernel/os.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OS {
5959
* other mechanisms. The first argument is always
6060
* the binary name.
6161
**/
62-
static const std::string& cmdline_args() noexcept;
62+
static const char* cmdline_args() noexcept;
6363

6464
/** Clock cycles since boot. */
6565
static uint64_t cycles_since_boot() {
@@ -257,18 +257,15 @@ class OS {
257257
static bool boot_sequence_passed_;
258258
static MHz cpu_mhz_;
259259

260-
// XXX: Only used by solo5
261260
static RTC::timestamp_t booted_at_;
262261
static uintptr_t liveupdate_loc_;
263262
static std::string version_str_;
264263
static std::string arch_str_;
265264
static Plugin_vec plugins_;
266-
static uintptr_t low_memory_size_;
267-
static uintptr_t high_memory_size_;
268265
static uintptr_t memory_end_;
269266
static uintptr_t heap_max_;
270267
static const uintptr_t elf_binary_size_;
271-
static std::string cmdline;
268+
static const char* cmdline;
272269

273270
// Prohibit copy and move operations
274271
OS(OS&) = delete;

api/kernel/service.hpp

Lines changed: 4 additions & 4 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.
@@ -30,12 +30,12 @@ class Service {
3030
/**
3131
* @return: The (descriptive) name of the service
3232
*/
33-
static std::string name();
33+
static const char* name();
3434

3535
/**
3636
* @return: The name of the service binary
3737
*/
38-
static std::string binary_name();
38+
static const char* binary_name();
3939

4040

4141
/**

cmake/post.service.cmake

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,22 @@ endif()
377377

378378
# all the OS and C/C++ libraries + crt end
379379
target_link_libraries(service
380-
libplatform
381-
libarch
382380
libos
383381
libbotan
384382
libosdeps
385-
cxxabi
386-
libc
387-
libcxx
388-
libm
389-
libg
390-
libgcc
391383

392384
libplatform
393385
libarch
394386
libos
395-
libbotan
396-
libosdeps
387+
388+
libplatform
389+
libarch
390+
libos
391+
libplatform
392+
397393
cxxabi
398394
libc
395+
libos
399396
libcxx
400397
libm
401398
libg

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ include_directories(${BOTAN_DIR})
2222

2323
# TODO: i wanted to use a glob, but then found out that not everything is included
2424
set(OS_OBJECTS
25-
kernel/kernel_start.cpp kernel/multiboot.cpp
25+
kernel/multiboot.cpp
2626
kernel/syscalls.cpp kernel/os.cpp kernel/cpuid.cpp
2727
kernel/events.cpp kernel/memmap.cpp kernel/pci_manager.cpp
28-
kernel/heap.cpp kernel/service_stub.cpp kernel/main_call.cpp
28+
kernel/heap.cpp kernel/service_stub.cpp
2929
kernel/elf.cpp kernel/terminal.cpp kernel/terminal_disk.cpp
3030
kernel/vga.cpp kernel/context.cpp kernel/context_asm.asm
3131
kernel/fiber.cpp kernel/tls.cpp

src/crt/c_abi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ void _init_bss()
4646
{
4747
/// Initialize .bss section
4848
extern char _BSS_START_, _BSS_END_;
49-
streamset8(&_BSS_START_, 0, &_BSS_END_ - &_BSS_START_);
49+
__builtin_memset(&_BSS_START_, 0, &_BSS_END_ - &_BSS_START_);
5050
}
5151

5252
void _init_heap(uintptr_t free_mem_begin)
5353
{
5454
// NOTE: Initialize the heap before exceptions
5555
// cache-align heap, because its not aligned
5656
heap_begin = (void*) free_mem_begin + HEAP_ALIGNMENT;
57-
heap_begin = (void*) ((size_t)heap_begin & ~HEAP_ALIGNMENT);
57+
heap_begin = (void*) ((uintptr_t)heap_begin & ~HEAP_ALIGNMENT);
5858
// heap end tracking, used with sbrk
5959
heap_end = heap_begin;
6060
}
6161

62-
uintptr_t _move_symbols(void* sym_loc)
62+
uint32_t _move_symbols(void* sym_loc)
6363
{
6464
extern char _ELF_SYM_START_;
6565
/// read out size of symbols **before** moving them
@@ -74,7 +74,7 @@ uintptr_t _move_symbols(void* sym_loc)
7474
return elfsym_size;
7575
}
7676

77-
void _crt_sanity_checks()
77+
static void crt_sanity_checks()
7878
{
7979
// validate that heap is aligned
8080
int validate_heap_alignment =
@@ -105,7 +105,7 @@ void _init_c_runtime()
105105
extern void _init_elf_parser();
106106
_init_elf_parser();
107107

108-
_crt_sanity_checks();
108+
crt_sanity_checks();
109109
}
110110

111111
// stack-protector

src/kernel/main_call.cpp

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/kernel/multiboot.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ void OS::multiboot(uint32_t boot_addr)
100100
uint32_t mem_high_end = mem_high_start + (bootinfo_->mem_upper * 1024) - 1;
101101
uint32_t mem_high_kb = bootinfo_->mem_upper;
102102

103-
OS::low_memory_size_ = mem_low_kb * 1024;
104-
OS::high_memory_size_ = mem_high_kb * 1024;
105-
OS::memory_end_ = high_memory_size_ + mem_high_start;
103+
OS::memory_end_ = mem_high_end;
106104

107105
INFO2("* Valid memory (%i Kib):", mem_low_kb + mem_high_kb);
108106
INFO2("\t 0x%08x - 0x%08x (%i Kib)",
@@ -118,7 +116,7 @@ void OS::multiboot(uint32_t boot_addr)
118116
if (bootinfo_->flags & MULTIBOOT_INFO_CMDLINE) {
119117
INFO2("* Booted with parameters @ 0x%x: %s", bootinfo_->cmdline,
120118
reinterpret_cast<const char*>(bootinfo_->cmdline));
121-
cmdline = reinterpret_cast<const char*>(bootinfo_->cmdline);
119+
OS::cmdline = reinterpret_cast<const char*>(bootinfo_->cmdline);
122120
}
123121

124122
if (bootinfo_->flags & MULTIBOOT_INFO_MEM_MAP) {

src/kernel/os.cpp

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@
1818
//#define DEBUG
1919
#define MYINFO(X,...) INFO("Kernel", X, ##__VA_ARGS__)
2020

21-
#include <cstdio>
22-
#include <boot/multiboot.h>
23-
#include <hw/cmos.hpp>
2421
#include <kernel/os.hpp>
2522
#include <kernel/rng.hpp>
26-
#include <kernel/cpuid.hpp>
2723
#include <util/fixedvec.hpp>
2824
#include <kprint>
2925
#include <service>
30-
#include <statman>
26+
#include <cstdio>
3127
#include <cinttypes>
3228

3329
//#define ENABLE_PROFILERS
@@ -53,12 +49,9 @@ bool OS::power_ = true;
5349
bool OS::boot_sequence_passed_ = false;
5450
MHz OS::cpu_mhz_ {-1};
5551
uintptr_t OS::liveupdate_loc_ = 0;
56-
uintptr_t OS::low_memory_size_ = 0;
57-
uintptr_t OS::high_memory_size_ = 0;
5852
uintptr_t OS::memory_end_ = 0;
59-
uintptr_t OS::heap_max_ {0xfffffff};
53+
uintptr_t OS::heap_max_ = (uintptr_t) -1;
6054
const uintptr_t OS::elf_binary_size_ {(uintptr_t)&_ELF_END_ - (uintptr_t)&_ELF_START_};
61-
std::string OS::cmdline{Service::binary_name()};
6255

6356
// stdout redirection
6457
using Print_vec = fixedvector<OS::print_func, 8>;
@@ -79,8 +72,8 @@ void* OS::liveupdate_storage_area() noexcept
7972
return (void*) OS::liveupdate_loc_;
8073
}
8174

82-
const std::string& OS::cmdline_args() noexcept
83-
{
75+
const char* OS::cmdline = nullptr;
76+
const char* OS::cmdline_args() noexcept {
8477
return cmdline;
8578
}
8679

@@ -141,7 +134,7 @@ void OS::post_start()
141134
printf(" IncludeOS %s (%s / %i-bit)\n",
142135
version().c_str(), arch().c_str(),
143136
static_cast<int>(sizeof(uintptr_t)) * 8);
144-
printf(" +--> Running [ %s ]\n", Service::name().c_str());
137+
printf(" +--> Running [ %s ]\n", Service::name());
145138
FILLINE('~');
146139

147140
Service::start();
@@ -151,11 +144,6 @@ void OS::add_stdout(OS::print_func func)
151144
{
152145
os_print_handlers.add(func);
153146
}
154-
__attribute__ ((weak))
155-
void default_stdout_handlers()
156-
{
157-
OS::add_stdout(&OS::default_stdout);
158-
}
159147
__attribute__((weak))
160148
bool os_enable_boot_logging = false;
161149
void OS::print(const char* str, const size_t len)
@@ -165,49 +153,3 @@ void OS::print(const char* str, const size_t len)
165153
callback(str, len);
166154
}
167155
}
168-
169-
void OS::legacy_boot() {
170-
// Fetch CMOS memory info (unfortunately this is maximally 10^16 kb)
171-
auto mem = hw::CMOS::meminfo();
172-
if (low_memory_size_ == 0) {
173-
low_memory_size_ = mem.base.total * 1024;
174-
INFO2("* Low memory: %i Kib", mem.base.total);
175-
}
176-
if (high_memory_size_ == 0) {
177-
high_memory_size_ = mem.extended.total * 1024;
178-
INFO2("* High memory (from cmos): %i Kib", mem.extended.total);
179-
}
180-
181-
auto& memmap = memory_map();
182-
183-
// No guarantees without multiboot, but we assume standard memory layout
184-
memmap.assign_range({0x0009FC00, 0x0009FFFF,
185-
"EBDA", "Extended BIOS data area"});
186-
memmap.assign_range({0x000A0000, 0x000FFFFF,
187-
"VGA/ROM", "Memory mapped video memory"});
188-
189-
// @note : since the maximum size of a span is unsigned (ptrdiff_t) we may need more than one
190-
uintptr_t addr_max = std::numeric_limits<std::size_t>::max();
191-
uintptr_t span_max = std::numeric_limits<std::ptrdiff_t>::max();
192-
193-
uintptr_t unavail_start = 0x100000 + high_memory_size_;
194-
size_t interval = std::min(span_max, addr_max - unavail_start) - 1;
195-
uintptr_t unavail_end = unavail_start + interval;
196-
197-
while (unavail_end < addr_max){
198-
INFO2("* Unavailable memory: 0x%" PRIxPTR" - 0x%" PRIxPTR, unavail_start, unavail_end);
199-
memmap.assign_range({unavail_start, unavail_end,
200-
"N/A", "Reserved / outside physical range" });
201-
unavail_start = unavail_end + 1;
202-
interval = std::min(span_max, addr_max - unavail_start);
203-
// Increment might wrapped around
204-
if (unavail_start > unavail_end + interval or unavail_start + interval == addr_max){
205-
INFO2("* Last chunk of memory: 0x%" PRIxPTR" - 0x%" PRIxPTR, unavail_start, addr_max);
206-
memmap.assign_range({unavail_start, addr_max,
207-
"N/A", "Reserved / outside physical range" });
208-
break;
209-
}
210-
211-
unavail_end += interval;
212-
}
213-
}

0 commit comments

Comments
 (0)