Other experiments with loading Linux.

parent 7f053e8b
Pipeline #64902708 passed with stages
in 10 minutes and 28 seconds
Subproject commit 9b411a57f833a2be93b74599b91fad6dea89bffd
Subproject commit 1554cd549eaeedb0c998c912c77c7e732c56da63
......@@ -490,9 +490,7 @@ void *read_all_file(FILE *fin, size_t **size) {
//struct boot_params boot_params __attribute__((aligned(16)));
void prepare_boot_params(struct boot_params *real_mode) {
//memset(&boot_params, 0, sizeof(boot_params));
struct setup_header *hdr = &real_mode->hdr;
void prepare_setup_header(struct setup_header *hdr) {
hdr->vid_mode = 0xffff;
hdr->type_of_loader = 0xff;
hdr->loadflags = 0x81;
......@@ -502,8 +500,67 @@ void prepare_boot_params(struct boot_params *real_mode) {
hdr->cmd_line_ptr = 0x1e000;
}
void prepare_boot_params(struct boot_params *real_mode) {
prepare_setup_header(&real_mode->hdr);
//real_mode->screen_info.ext_mem_k = 0xf000;
//real_mode->alt_mem_k = 0x1234;
real_mode->e820_entries = 1;
real_mode->e820_table[0].addr = 0x100000;
real_mode->e820_table[0].size = 128 * 1024 * 1024;
real_mode->e820_table[0].type = 1;
}
#define SECT_SIZE 512
void load_linux32() {
download_file("http://10.0.2.2:8080/bzImage", "/ram/cont/bzImage");
printf("Loading Linux kernel\n");
FILE *fin = fopen("/ram/cont/bzImage", "rb");
struct boot_params *real_mode = malloc(SECT_SIZE);
size_t res = fread(real_mode, SECT_SIZE, 1, fin);
assert(res == 1);
if (real_mode->hdr.setup_sects == 0) {
real_mode->hdr.setup_sects = 4;
}
size_t real_mode_size = SECT_SIZE * (1 + real_mode->hdr.setup_sects);
printf("Real mode code/data is 0x%x bytes long\n", real_mode_size);
real_mode = realloc(real_mode, real_mode_size);
res = fread(((char*)real_mode) + SECT_SIZE, SECT_SIZE, real_mode->hdr.setup_sects, fin);
assert(res == real_mode->hdr.setup_sects);
assert(real_mode->hdr.boot_flag == 0xaa55);
assert(real_mode->hdr.header == 0x53726448);
size_t prot_mode_size;
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);
load_linux_gdt();
char *cmdline = "verbose";
// Here we really smash our operating system!
memset(0x10000, 0, 0x10000);
memcpy((void*) 0x10000, real_mode, real_mode_size);
memcpy((void*) 0x1e000, cmdline, strlen(cmdline));
//memcpy((void*) 0x100000, prot_mode, prot_mode_size);
asm volatile("mov $0x100000, %%edi \n\t"
"cld \n\t"
"rep movsb \n\t"
"mov $0x10000, %%esi \n\t"
"xor %%eax, %%eax \n\t"
"mov %%eax, %%ebp \n\t"
"mov %%eax, %%edi \n\t"
"mov %%eax, %%ebx \n\t"
"mov %%eax, %%ecx \n\t"
"mov %%eax, %%edx \n\t"
"mov $0xe000, %%esp \n\t"
"push $0x100000 \n\t"
"ret \n\t"
: : "S" (prot_mode), "c" (prot_mode_size));
free(real_mode);
free(prot_mode);
}
void load_linux() {
download_file("http://10.0.2.2:8080/bzImage", "/ram/cont/bzImage");
download_file("http://10.0.2.2:8080/realmode.bin", "/ram/cont/realmode.bin");
......@@ -526,7 +583,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_boot_params(real_mode);
prepare_setup_header(&real_mode->hdr);
//load_linux_gdt();
fin = fopen("/ram/cont/realmode.bin", "rb");
size_t trampoline_size;
......@@ -549,8 +606,32 @@ void load_linux() {
free(prot_mode);
}
void load_mlb() {
download_file("http://10.0.2.2:8080/realmode2", "/ram/cont/realmode.bin");
download_file("http://10.0.2.2:8080/example", "/ram/cont/bootloader");
FILE *fin = fopen("/ram/cont/realmode.bin", "rb");
size_t trampoline_size;
void *trampoline = read_all_file(fin, &trampoline_size);
printf("Trampoline is 0x%x bytes long\n", trampoline_size);
fclose(fin);
prepare_real_mode_gdt();
fin = fopen("/ram/cont/bootloader", "rb");
size_t bootloader_size;
void *bootloader = read_all_file(fin, &bootloader_size);
printf("Bootloader is 0x%x bytes long\n", bootloader_size);
fclose(fin);
prepare_real_mode_gdt();
memset(0x10000, 0, 0x10000);
memcpy((void*) 0x500, trampoline, trampoline_size);
memcpy((void*) 0x7c00, bootloader, bootloader_size);
((void (*)()) 0x500)();
}
int main() {
printf("Hello, continuing second world!\n");
//load_linux32();
//load_linux();
//load_mlb();
return 0;
}
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