Add support for initramfs.

parent 28033c3b
Pipeline #64993334 passed with stages
in 9 minutes and 56 seconds
......@@ -490,18 +490,18 @@ void *read_all_file(FILE *fin, size_t **size) {
//struct boot_params boot_params __attribute__((aligned(16)));
void prepare_setup_header(struct setup_header *hdr) {
void prepare_setup_header(struct setup_header *hdr, void *initrd, size_t initrd_size) {
hdr->vid_mode = 0xffff;
hdr->type_of_loader = 0xff;
hdr->loadflags = 0x81;
hdr->ramdisk_image = 0;
hdr->ramdisk_size = 0;
hdr->ramdisk_image = initrd;
hdr->ramdisk_size = initrd_size;
hdr->heap_end_ptr = 0xde00;
hdr->cmd_line_ptr = 0x1e000;
}
void prepare_boot_params(struct boot_params *real_mode) {
prepare_setup_header(&real_mode->hdr);
void prepare_boot_params(struct boot_params *real_mode, void *initrd, size_t initrd_size) {
prepare_setup_header(&real_mode->hdr, initrd, initrd_size);
//real_mode->screen_info.ext_mem_k = 0xf000;
//real_mode->alt_mem_k = 0x1234;
real_mode->e820_entries = 1;
......@@ -514,6 +514,7 @@ void prepare_boot_params(struct boot_params *real_mode) {
void load_linux32() {
download_file("http://10.0.2.2:8080/bzImage", "/ram/cont/bzImage");
download_file("http://10.0.2.2:8080/initrd.img", "/ram/cont/initrd.img");
printf("Loading Linux kernel\n");
FILE *fin = fopen("/ram/cont/bzImage", "rb");
struct boot_params *real_mode = malloc(SECT_SIZE);
......@@ -533,7 +534,16 @@ void load_linux32() {
void *prot_mode = read_all_file(fin, &prot_mode_size);
printf("Protected mode code/data is 0x%x bytes long\n", prot_mode_size);
fclose(fin);
prepare_boot_params(real_mode);
fin = fopen("/ram/cont/initrd.img", "rb");
size_t initrd_size;
void *initrd = read_all_file(fin, &initrd_size);
printf("Initrd is 0x%x bytes long\n", initrd_size);
fclose(fin);
// Align initrd
initrd = realloc(initrd, initrd_size + 4096);
void *initrd_aligned = (void*)(((((unsigned long)initrd)-1) | (4096-1)) + 1);
memmove(initrd_aligned, initrd, initrd_size);
prepare_boot_params(real_mode, initrd_aligned, initrd_size);
load_linux_gdt();
char *cmdline = "verbose";
......@@ -557,6 +567,7 @@ void load_linux32() {
"ret \n\t"
: : "S" (prot_mode), "c" (prot_mode_size));
free(initrd);
free(real_mode);
free(prot_mode);
}
......@@ -583,7 +594,7 @@ void load_linux() {
void *prot_mode = read_all_file(fin, &prot_mode_size);
printf("Protected mode code/data is 0x%x bytes long\n", prot_mode_size);
fclose(fin);
prepare_setup_header(&real_mode->hdr);
prepare_setup_header(&real_mode->hdr, 0, 0);
//load_linux_gdt();
fin = fopen("/ram/cont/realmode.bin", "rb");
size_t trampoline_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment