1818#include < os>
1919#include < cstdint>
2020#include < util/elf_binary.hpp>
21- #include < util/sha1.hpp>
2221
2322bool verb = true ;
24-
2523#define MYINFO (X,...) INFO(" chainload" , X, ##__VA_ARGS__)
2624
2725extern " C" void hotswap (const char * base, int len, char * dest, void * start,
@@ -30,50 +28,38 @@ extern "C" void hotswap(const char* base, int len, char* dest, void* start,
3028extern uintptr_t __multiboot_magic;
3129extern uintptr_t __multiboot_addr;
3230
33- constexpr int bits () { return sizeof (void *) * 8 ; }
34-
35- /* * Modify multiboot data to show first module as the kernel */
36- void promote_mod_to_kernel (){
31+ static void steal_commandline_from_module ()
32+ {
3733 auto * bootinfo = (multiboot_info_t *) __multiboot_addr;
3834
3935 Expects (bootinfo->mods_count );
40- auto * mod = (multiboot_module_t *)bootinfo->mods_addr ;
36+ auto * mod = (multiboot_module_t *) bootinfo->mods_addr ;
4137
4238 // Set command line param to mod param
4339 bootinfo->cmdline = mod->cmdline ;
44-
45- // Subtract one module
46- (bootinfo->mods_count )--;
47-
48- if (bootinfo->mods_count )
49- bootinfo->mods_addr = (uintptr_t )((multiboot_module_t *)bootinfo->mods_addr + 1 );
50-
5140}
5241
5342void Service::start (const std::string&)
5443{
5544 auto mods = OS::modules ();
56-
57- MYINFO ( " %i-bit chainloader found %i modules " , bits () , mods.size ());
45+ MYINFO ( " %u-bit chainloader found %u modules " ,
46+ sizeof ( void *) * 8 , mods.size ());
5847
5948 if (mods.size () <= 0 ) {
6049 MYINFO (" Nothing to do. Exiting." );
6150 exit (1 );
6251 }
6352 multiboot_module_t binary = mods[0 ];
6453
65- // MYINFO("Verifying ELF binary");
66-
67- Elf_binary<Elf64> elf ({(char *)binary.mod_start ,
54+ Elf_binary<Elf64> elf (
55+ {(char *)binary.mod_start ,
6856 (int )(binary.mod_end - binary.mod_start )});
6957
7058 void * hotswap_addr = (void *)0x200000 ;
71-
7259 extern char __hotswap_end;
7360
7461 debug (" Moving hotswap function (begin at %p end at %p) of size %i" ,
7562 &hotswap, &__hotswap_end, &__hotswap_end - (char *)&hotswap);
76-
7763 memcpy (hotswap_addr,(void *)&hotswap, &__hotswap_end - (char *)&hotswap );
7864
7965 extern uintptr_t __multiboot_magic;
@@ -83,22 +69,17 @@ void Service::start(const std::string&)
8369
8470 char * base = (char *)binary.mod_start ;
8571 int len = (int )(binary.mod_end - binary.mod_start );
72+ // FIXME: determine kernel base from ELF program header
8673 char * dest = (char *)0xA00000 ;
8774 void * start = (void *)elf.entry ();
8875
89- SHA1 sha;
90- sha.update (base, len);
91- debug (" Sha1 of ELF binary module: %s" , sha.as_hex ().c_str ());
92-
93-
9476 MYINFO (" Hotswapping with params: base: %p, len: %i, dest: %p, start: %p" ,
9577 base, len, dest, start);
9678
97- promote_mod_to_kernel ();
79+ steal_commandline_from_module ();
9880
9981 asm (" cli" );
10082 ((decltype (&hotswap))hotswap_addr)(base, len, dest, start, __multiboot_magic, __multiboot_addr);
10183
10284 panic (" Should have jumped\n " );
103-
10485}
0 commit comments