63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <limine.h>
|
|
#include "baseimg/baseimg.h"
|
|
#include "bootinfo/bootinfo.h"
|
|
#include "util/util.h"
|
|
#include "dlmalloc/malloc.h"
|
|
#include "FastLZ/fastlz.h"
|
|
#include "FastLZ/6unpack_mem.h"
|
|
#include "std/string.h"
|
|
#include "cpu/hang.h"
|
|
#include "kprintf.h"
|
|
|
|
#define BASEIMG_DECOMPRESSED (1024*1024*4)
|
|
|
|
size_t BASEIMG_DECOMP_SIZE;
|
|
uint8_t *BASEIMG_DECOMP_ADDR;
|
|
|
|
uint64_t baseimg_getaddr(void) {
|
|
return (uint64_t)BASEIMG_DECOMP_ADDR;
|
|
}
|
|
|
|
uint64_t baseimg_getsize(void) {
|
|
return (uint64_t)BASEIMG_DECOMP_SIZE;
|
|
}
|
|
|
|
void baseimg_init(void) {
|
|
struct limine_file *baseimg = NULL;
|
|
|
|
LOG("baseimg", "looking for base image...\n");
|
|
for (size_t i = 0; i < BOOT_INFO.modules->module_count; i++) {
|
|
struct limine_file *module = BOOT_INFO.modules->modules[i];
|
|
if (strcmp(util_get_filename(module->path), "base.img.6pk") == 0) {
|
|
baseimg = module;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (baseimg == NULL) {
|
|
ERR("baseimg", "base.img.6pk not found\n");
|
|
cpu_hang();
|
|
} else {
|
|
LOG("baseimg", "base.img.6pk found\n");
|
|
LOG("baseimg", "addr = %p, size = %lu\n", baseimg->address, baseimg->size);
|
|
for (size_t i = 0; i < 30; i++) {
|
|
kprintf("%02X ", ((uint8_t *)(baseimg->address))[i]);
|
|
if (i > 0 && (i + 1) % 10 == 0) {
|
|
kprintf("\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
BASEIMG_DECOMP_ADDR = dlmalloc(BASEIMG_DECOMPRESSED);
|
|
int res = sixpack_decompress_mem(baseimg->address, baseimg->size,
|
|
BASEIMG_DECOMP_ADDR, BASEIMG_DECOMPRESSED);
|
|
if (res < 0) {
|
|
ERR("baseimg", "could not uncompress base.img.6pk\n");
|
|
cpu_hang();
|
|
}
|
|
BASEIMG_DECOMP_SIZE = res;
|
|
kprintf("%p %zu\n", BASEIMG_DECOMP_ADDR, BASEIMG_DECOMP_SIZE);
|
|
}
|