Skip to content

Commit e3aad09

Browse files
committed
kernel: Store LiveUpdate location, use 1/4 of memory, make soft-reset arch neutral
1 parent 339062f commit e3aad09

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

api/kernel/os.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class OS {
259259

260260
// XXX: Only used by solo5
261261
static RTC::timestamp_t booted_at_;
262+
static uintptr_t liveupdate_loc_;
262263
static std::string version_str_;
263264
static std::string arch_str_;
264265
static Plugin_vec plugins_;

src/kernel/os.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern uintptr_t _ELF_END_;
5252
bool OS::power_ = true;
5353
bool OS::boot_sequence_passed_ = false;
5454
MHz OS::cpu_mhz_ {-1};
55+
uintptr_t OS::liveupdate_loc_ = 0;
5556
uintptr_t OS::low_memory_size_ = 0;
5657
uintptr_t OS::high_memory_size_ = 0;
5758
uintptr_t OS::memory_end_ = 0;
@@ -75,8 +76,7 @@ std::string OS::arch_str_ = ARCH;
7576

7677
void* OS::liveupdate_storage_area() noexcept
7778
{
78-
// Default: 32MB below heap_max
79-
return (void*) (OS::heap_max() & 0xFFFFFFF0 - 0x2000000);
79+
return (void*) OS::liveupdate_loc_;
8080
}
8181

8282
const std::string& OS::cmdline_args() noexcept
@@ -102,6 +102,13 @@ void OS::shutdown()
102102

103103
void OS::post_start()
104104
{
105+
if (OS::liveupdate_loc_ == 0)
106+
{
107+
// default size is 1/4 of heap from the end of memory
108+
auto size = OS::heap_max() / 4;
109+
OS::liveupdate_loc_ = (OS::heap_max() - size) & 0xFFFFFFF0;
110+
}
111+
105112
MYINFO("Initializing RNG");
106113
PROFILE("RNG init");
107114
RNG::init();

src/platform/x86_pc/idt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static void set_intr_entry(
6767
#ifdef ARCH_x86_64
6868
idt_entry->ist = ist;
6969
#else
70+
(void) ist;
7071
idt_entry->zero = 0;
7172
#endif
7273
}

src/platform/x86_pc/softreset.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ namespace x86 {
1313
struct softreset_t
1414
{
1515
uint32_t checksum;
16-
uintptr_t high_mem;
16+
uint64_t liveupdate_loc;
17+
uint64_t high_mem;
1718
MHz cpu_freq;
1819
uint32_t apic_ticks;
19-
void* extra;
20-
size_t extra_len;
20+
uint64_t extra;
21+
uint32_t extra_len;
2122
};
2223

2324
bool OS::is_softreset_magic(uint32_t value)
@@ -44,14 +45,15 @@ void OS::resume_softreset(intptr_t addr)
4445
data->checksum = csum_copy;
4546

4647
/// restore known values
47-
OS::memory_end_ = data->high_mem;
48+
OS::liveupdate_loc_ = data->liveupdate_loc;
49+
OS::memory_end_ = data->high_mem;
4850
OS::low_memory_size_ = 0x100000;
4951
OS::high_memory_size_ = OS::memory_end_ - 0x100000;
5052
OS::cpu_mhz_ = data->cpu_freq;
5153
x86::apic_timer_set_ticks(data->apic_ticks);
5254

5355
/// call service-specific softreset handler
54-
softreset_service_handler(data->extra, data->extra_len);
56+
softreset_service_handler((void*) data->extra, data->extra_len);
5557
}
5658

5759
extern "C"
@@ -60,10 +62,11 @@ void* __os_store_soft_reset(void* extra, size_t extra_len)
6062
// store softreset data in low memory
6163
auto* data = (softreset_t*) SOFT_RESET_LOCATION;
6264
data->checksum = 0;
65+
data->liveupdate_loc = (uintptr_t) OS::liveupdate_storage_area();
6366
data->high_mem = OS::memory_end();
6467
data->cpu_freq = OS::cpu_freq();
6568
data->apic_ticks = x86::apic_timer_get_ticks();
66-
data->extra = extra;
69+
data->extra = (uint64_t) extra;
6770
data->extra_len = extra_len;
6871

6972
uint32_t csum = crc32_fast(data, sizeof(softreset_t));

0 commit comments

Comments
 (0)