boot: Add multiboot support

Not yet fully spec-compliant; work in progress
This commit is contained in:
Arun Thomas
2011-06-24 17:20:25 +02:00
parent e785381d4d
commit 93ae43f577
31 changed files with 663 additions and 82 deletions

View File

@@ -25,7 +25,7 @@
#include "oxpcie.h"
#include "kernel/proc.h"
#include "kernel/debug.h"
#include "multiboot.h"
#include <machine/multiboot.h>
#include "glo.h"

View File

@@ -0,0 +1,43 @@
OUTPUT_ARCH("i386")
ENTRY(MINIX)
SECTIONS
{
. = 0x200000 + SIZEOF_HEADERS;
.text . : AT (ADDR(.text) - 0x0000) {
*(.text)
*(.text.*)
. = ALIGN(4096);
}
_etext = .;
etext = .;
.data . : AT (ADDR(.data) - 0x0000) {
_rodata = .;
/* kernel data starts with this magic number */
SHORT(0x526f);
*(.rodata)
*(.rodata.*)
_erodata = .;
*(.data)
*(.data.*)
. = ALIGN(4096);
}
_edata = .;
.bss . : AT (ADDR(.bss) - 0x0000) {
*(.bss)
*(.bss.*)
*(COMMON)
}
_end = .;
end = .;
/DISCARD/ :
{
*(.eh_frame)
*(.comment)
*(.comment.*)
*(.note)
*(.note.*)
}
}

View File

@@ -9,7 +9,7 @@
#include "archconst.h"
#include "kernel/const.h"
#include "sconst.h"
#include "multiboot.h"
#include <machine/multiboot.h>
/*
* This file contains a number of assembly code utility routines needed by the

View File

@@ -8,7 +8,7 @@
#include "archconst.h"
#include "kernel/const.h"
#include "sconst.h"
#include "multiboot.h"
#include <machine/multiboot.h>
/*
* This file contains a number of 16-bit assembly code utility routines needed by the

View File

@@ -53,7 +53,7 @@ begbss:
#include "kernel/const.h"
#include "kernel/proc.h"
#include "sconst.h"
#include "multiboot.h"
#include <machine/multiboot.h>
#include "arch_proto.h" /* K_STACK_SIZE */
@@ -84,9 +84,7 @@ MINIX:
/* this is the entry point for the MINIX kernel */
#if defined(__ELF__)
/* Check if Multibooting */
cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax
je _C_LABEL(multiboot_init)
jmp _C_LABEL(multiboot_init)
#endif
jmp over_flags /* skip over the next few bytes */

View File

@@ -8,7 +8,7 @@
#include "kernel/const.h"
#include "kernel/proc.h"
#include "sconst.h"
#include "multiboot.h"
#include <machine/multiboot.h>
#define GDT_SET_ENTRY(selector, base, limit) \
mov %ebp, %edi; \
@@ -44,6 +44,8 @@ reload_cs:
mov %eax, %ds
mov %eax, %ss
mov %eax, %es
mov %eax, %fs
mov %eax, %gs
mov $(multiboot_stack + MULTIBOOT_STACK_SIZE), %esp

View File

@@ -1,128 +0,0 @@
#ifndef __MULTIBOOT_H__
#define __MULTIBOOT_H__
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* Must pass memory information to OS. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
#define MULTIBOOT_MEMORY_INFO 0x00000002
#define MULTIBOOT_VIDEO_MODE 0x00000004
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
#define MULTIBOOT_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN)
/* consts used for Multiboot pre-init */
#define MULTIBOOT_VIDEO_MODE_EGA 1
#define MULTIBOOT_VIDEO_BUFFER 0xB8000
/* Usable lower memory chunk has a upper bound */
#define MULTIBOOT_LOWER_MEM_MAX 0x7f800
#define MULTIBOOT_CONSOLE_LINES 25
#define MULTIBOOT_CONSOLE_COLS 80
#define MULTIBOOT_STACK_SIZE 4096
#define MULTIBOOT_PARAM_BUF_SIZE 1024
/* Flags to be set in the flags member of the multiboot info structure. */
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* Is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* Is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* Are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
#ifndef __ASSEMBLY__
#include <minix/types.h>
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
u32_t tabsize;
u32_t strsize;
u32_t addr;
u32_t reserved;
};
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
u32_t num;
u32_t size;
u32_t addr;
u32_t shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
struct multiboot_info
{
/* Multiboot info version number */
u32_t flags;
/* Available memory from BIOS */
u32_t mem_lower;
u32_t mem_upper;
/* "root" partition */
u32_t boot_device;
/* Kernel command line */
u32_t cmdline;
/* Boot-Module list */
u32_t mods_count;
u32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
u32_t mmap_length;
u32_t mmap_addr;
/* Drive Info buffer */
u32_t drives_length;
u32_t drives_addr;
/* ROM configuration table */
u32_t config_table;
/* Boot Loader Name */
u32_t boot_loader_name;
/* APM table */
u32_t apm_table;
/* Video */
u32_t vbe_control_info;
u32_t vbe_mode_info;
u16_t vbe_mode;
u16_t vbe_interface_seg;
u16_t vbe_interface_off;
u16_t vbe_interface_len;
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_mod_list
{
/* Memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
u32_t mod_start;
u32_t mod_end;
/* Module command line */
u32_t cmdline;
/* Pad struct to 16 bytes (must be zero) */
u32_t pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* Buffer for multiboot parameters */
extern char multiboot_param_buf[];
#endif /* __ASSEMBLY__ */
#endif /* __MULTIBOOT_H__ */

View File

@@ -17,7 +17,7 @@
#include "string.h"
#include "arch_proto.h"
#include "libexec.h"
#include "multiboot.h"
#include <machine/multiboot.h>
#define MULTIBOOT_VERBOSE 1
@@ -279,10 +279,6 @@ PRIVATE void get_parameters(multiboot_info_t *mbi)
mb_set_param("memory", mem_value);
}
/* FIXME: this is dummy value,
* we can't get real image file name from multiboot */
mb_set_param("image", "boot/image_latest");
if (mbi->flags&MULTIBOOT_INFO_CMDLINE) {
/* Override values with cmdline argument */
p = mb_cmd_buff;
@@ -353,11 +349,9 @@ PRIVATE void mb_extract_image(multiboot_info_t mbi)
mb_print("\nKernel: ");
mb_print_hex(trunc_page(text_paddr));
mb_print("-");
mb_print_hex(trunc_page(data_paddr) + data_membytes + stack_bytes);
mb_print_hex(trunc_page(data_paddr) + data_membytes);
mb_print(" Entry: ");
mb_print_hex(pc);
mb_print(" Stack: ");
mb_print_hex(stack_bytes);
#endif
mb_module_info = ((multiboot_module_t *)mbi.mods_addr);