diff --git a/.gitignore b/.gitignore index 0216052a..cf7b0c95 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,4 @@ qemu-vlan0.pcap contrib cdrom toaruos.iso +modpack.kop diff --git a/kernel/main.c b/kernel/main.c index a27e09a9..0991dda6 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -69,6 +69,11 @@ fs_node_t _early_log = { .write = &_early_log_write }; #define DISABLE_EARLY_BOOT_LOG() #endif +struct pack_header { + char head[4]; + uint32_t region_size; +}; + /* * multiboot i386 (pc) kernel entry point */ @@ -170,16 +175,33 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) { uint32_t module_end = mod->mod_end; size_t module_size = module_end - module_start; - if (!module_quickcheck((void *)module_start)) { - debug_print(NOTICE, "Loading ramdisk: 0x%x:0x%x", module_start, module_end); - ramdisk_mount(module_start, module_size); - } else { - + int check_result = module_quickcheck((void *)module_start); + if (check_result == 1) { debug_print(NOTICE, "Loading a module: 0x%x:0x%x", module_start, module_end); module_data_t * mod_info = (module_data_t *)module_load_direct((void *)(module_start), module_size); if (mod_info) { debug_print(NOTICE, "Loaded: %s", mod_info->mod_info->name); } + } else if (check_result == 2) { + /* Mod pack */ + debug_print(NOTICE, "Loading modpack. %x", module_start); + struct pack_header * pack_header = (struct pack_header *)module_start; + while (pack_header->region_size) { + void * start = (void *)((uintptr_t)pack_header + 4096); + int result = module_quickcheck(start); + if (result != 1) { + debug_print(WARNING, "Not actually a module?! %x", start); + } + module_data_t * mod_info = (module_data_t *)module_load_direct(start, pack_header->region_size); + if (mod_info) { + debug_print(NOTICE, "Loaded: %s", mod_info->mod_info->name); + } + pack_header = (struct pack_header *)((uintptr_t)start + pack_header->region_size); + } + debug_print(NOTICE, "Done with modpack."); + } else { + debug_print(NOTICE, "Loading ramdisk: 0x%x:0x%x", module_start, module_end); + ramdisk_mount(module_start, module_size); } } diff --git a/kernel/sys/module.c b/kernel/sys/module.c index c50f7574..c052b9cb 100644 --- a/kernel/sys/module.c +++ b/kernel/sys/module.c @@ -50,6 +50,11 @@ int module_quickcheck(void * blob) { target->e_ident[2] != ELFMAG2 || target->e_ident[3] != ELFMAG3) { + char * head = (char *)blob; + if (head[0] == 'P' && head[1] == 'A' && head[2] == 'C' && head[3] == 'K') { + return 2; + } + return 0; } diff --git a/util/package-mods.py b/util/package-mods.py new file mode 100644 index 00000000..a1cdd41c --- /dev/null +++ b/util/package-mods.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +import os +import struct + +# This is ORDERED, so don't screw it up. +mods_to_pack = [ + 'zero', + 'random', + 'serial', + 'procfs', + 'tmpfs', + 'ext2', + 'ps2kbd', + 'ps2mouse', + 'lfbvideo', + 'packetfs', +] + + +with open('modpack.kop','wb') as pack: + for mod in mods_to_pack: + with open('hdd/mod/{mod}.ko'.format(mod=mod),'rb') as m: + print "Writing", mod + pack.write("PACK") + size = os.stat(m.name).st_size + extra = 0 + while (size + extra) % 4096 != 0: + extra += 1 + pack.write(struct.pack("I", size+extra)) + pack.write('\0' * (4096-8)) + pack.write(m.read(size)) + pack.write('\0' * extra) + pack.write("PACK") + pack.write('\0\0\0\0') + +