feat: multiboot2 géré à partir d'une routine asm
This commit is contained in:
parent
48778a7ef6
commit
31b139ab01
|
@ -0,0 +1,385 @@
|
|||
#include "types.h"
|
||||
|
||||
/* How many bytes from the start of the file we search for the header. */
|
||||
#define MULTIBOOT_SEARCH 32768
|
||||
#define MULTIBOOT_HEADER_ALIGN 8
|
||||
|
||||
/* The magic field should contain this. */
|
||||
#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
|
||||
|
||||
/* This should be in %eax. */
|
||||
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
|
||||
|
||||
/* Alignment of multiboot modules. */
|
||||
#define MULTIBOOT_MOD_ALIGN 0x00001000
|
||||
|
||||
/* Alignment of the multiboot info structure. */
|
||||
#define MULTIBOOT_INFO_ALIGN 0x00000008
|
||||
|
||||
/* Flags set in the 'flags' member of the multiboot header. */
|
||||
|
||||
#define MULTIBOOT_TAG_ALIGN 8
|
||||
#define MULTIBOOT_TAG_TYPE_END 0
|
||||
#define MULTIBOOT_TAG_TYPE_CMDLINE 1
|
||||
#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2
|
||||
#define MULTIBOOT_TAG_TYPE_MODULE 3
|
||||
#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
|
||||
#define MULTIBOOT_TAG_TYPE_BOOTDEV 5
|
||||
#define MULTIBOOT_TAG_TYPE_MMAP 6
|
||||
#define MULTIBOOT_TAG_TYPE_VBE 7
|
||||
#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
|
||||
#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9
|
||||
#define MULTIBOOT_TAG_TYPE_APM 10
|
||||
#define MULTIBOOT_TAG_TYPE_EFI32 11
|
||||
#define MULTIBOOT_TAG_TYPE_EFI64 12
|
||||
#define MULTIBOOT_TAG_TYPE_SMBIOS 13
|
||||
#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14
|
||||
#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15
|
||||
#define MULTIBOOT_TAG_TYPE_NETWORK 16
|
||||
#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17
|
||||
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
|
||||
#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
|
||||
#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
|
||||
#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21
|
||||
|
||||
#define MULTIBOOT_HEADER_TAG_END 0
|
||||
#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
|
||||
#define MULTIBOOT_HEADER_TAG_ADDRESS 2
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3
|
||||
#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
|
||||
#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5
|
||||
#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6
|
||||
#define MULTIBOOT_HEADER_TAG_EFI_BS 7
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32 8
|
||||
#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9
|
||||
#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10
|
||||
|
||||
#define MULTIBOOT_ARCHITECTURE_I386 0
|
||||
#define MULTIBOOT_ARCHITECTURE_MIPS32 4
|
||||
#define MULTIBOOT_HEADER_TAG_OPTIONAL 1
|
||||
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_NONE 0
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_LOW 1
|
||||
#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2
|
||||
|
||||
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
|
||||
#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
|
||||
|
||||
struct multiboot_header
|
||||
{
|
||||
/* Must be MULTIBOOT_MAGIC - see above. */
|
||||
u32 magic;
|
||||
|
||||
/* ISA */
|
||||
u32 architecture;
|
||||
|
||||
/* Total header length. */
|
||||
u32 header_length;
|
||||
|
||||
/* The above fields plus this one must equal 0 mod 2^32. */
|
||||
u32 checksum;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_information_request
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 requests[0];
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_address
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 header_addr;
|
||||
u32 load_addr;
|
||||
u32 load_end_addr;
|
||||
u32 bss_end_addr;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_entry_address
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 entry_addr;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_console_flags
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 console_flags;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_framebuffer
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 depth;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_module_align
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct multiboot_header_tag_relocatable
|
||||
{
|
||||
u16 type;
|
||||
u16 flags;
|
||||
u32 size;
|
||||
u32 min_addr;
|
||||
u32 max_addr;
|
||||
u32 align;
|
||||
u32 preference;
|
||||
};
|
||||
|
||||
struct multiboot_color
|
||||
{
|
||||
u8 red;
|
||||
u8 green;
|
||||
u8 blue;
|
||||
};
|
||||
|
||||
struct multiboot_mmap_entry
|
||||
{
|
||||
u64 addr;
|
||||
u64 len;
|
||||
#define MULTIBOOT_MEMORY_AVAILABLE 1
|
||||
#define MULTIBOOT_MEMORY_RESERVED 2
|
||||
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
|
||||
#define MULTIBOOT_MEMORY_NVS 4
|
||||
#define MULTIBOOT_MEMORY_BADRAM 5
|
||||
u32 type;
|
||||
u32 zero;
|
||||
};
|
||||
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
||||
|
||||
struct multiboot_tag
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
struct multiboot_tag_string
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u8 string[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_module
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 mod_start;
|
||||
u32 mod_end;
|
||||
u8 cmdline[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_basic_meminfo
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 mem_lower;
|
||||
u32 mem_upper;
|
||||
};
|
||||
|
||||
struct multiboot_tag_bootdev
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 biosdev;
|
||||
u32 slice;
|
||||
u32 part;
|
||||
};
|
||||
|
||||
struct multiboot_tag_mmap
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 entry_size;
|
||||
u32 entry_version;
|
||||
struct multiboot_mmap_entry entries[0];
|
||||
};
|
||||
|
||||
struct multiboot_vbe_info_block
|
||||
{
|
||||
u8 external_specification[512];
|
||||
};
|
||||
|
||||
struct multiboot_vbe_mode_info_block
|
||||
{
|
||||
u8 external_specification[256];
|
||||
};
|
||||
|
||||
struct multiboot_tag_vbe
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
|
||||
u16 vbe_mode;
|
||||
u16 vbe_interface_seg;
|
||||
u16 vbe_interface_off;
|
||||
u16 vbe_interface_len;
|
||||
|
||||
struct multiboot_vbe_info_block vbe_control_info;
|
||||
struct multiboot_vbe_mode_info_block vbe_mode_info;
|
||||
};
|
||||
|
||||
struct multiboot_tag_framebuffer_common
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
|
||||
u64 framebuffer_addr;
|
||||
u32 framebuffer_pitch;
|
||||
u32 framebuffer_width;
|
||||
u32 framebuffer_height;
|
||||
u8 framebuffer_bpp;
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
|
||||
u8 framebuffer_type;
|
||||
u16 reserved;
|
||||
};
|
||||
|
||||
struct multiboot_tag_framebuffer
|
||||
{
|
||||
struct multiboot_tag_framebuffer_common common;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
u16 framebuffer_palette_num_colors;
|
||||
struct multiboot_color framebuffer_palette[0];
|
||||
};
|
||||
struct
|
||||
{
|
||||
u8 framebuffer_red_field_position;
|
||||
u8 framebuffer_red_mask_size;
|
||||
u8 framebuffer_green_field_position;
|
||||
u8 framebuffer_green_mask_size;
|
||||
u8 framebuffer_blue_field_position;
|
||||
u8 framebuffer_blue_mask_size;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct multiboot_tag_elf_sections
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 num;
|
||||
u32 entsize;
|
||||
u32 shndx;
|
||||
u8 sections[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_apm
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u16 version;
|
||||
u16 cseg;
|
||||
u32 offset;
|
||||
u16 cseg_16;
|
||||
u16 dseg;
|
||||
u16 flags;
|
||||
u16 cseg_len;
|
||||
u16 cseg_16_len;
|
||||
u16 dseg_len;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi32
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi64
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u64 pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_smbios
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u8 major;
|
||||
u8 minor;
|
||||
u8 reserved[6];
|
||||
u8 tables[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_old_acpi
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u8 rsdp[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_new_acpi
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u8 rsdp[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_network
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u8 dhcpack[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi_mmap
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 descr_size;
|
||||
u32 descr_vers;
|
||||
u8 efi_mmap[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi32_ih
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_efi64_ih
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u64 pointer;
|
||||
};
|
||||
|
||||
struct multiboot_tag_load_base_addr
|
||||
{
|
||||
u32 type;
|
||||
u32 size;
|
||||
u32 load_base_addr;
|
||||
};
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include
|
||||
LINK=ld -m elf_i386 -r -o
|
||||
OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o gdt.o shell.o syscall.o
|
||||
SRCS= $(wildcard *.c)
|
||||
OBJS= $(SRCS:.c=.o)
|
||||
|
||||
all: makeall
|
||||
|
||||
|
@ -11,6 +12,10 @@ libs.o:$(OBJS)
|
|||
|
||||
.o: .c
|
||||
$(CC) $^
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
||||
indent:
|
||||
indent -linux -i8 -ts8 *.c
|
||||
indent -linux -i8 -ts8 ./VGA/*.c
|
||||
|
|
23
makefile
23
makefile
|
@ -1,6 +1,12 @@
|
|||
all: makall
|
||||
all: bits32 bits64 floppy harddisk uefi
|
||||
sync
|
||||
|
||||
makall: lib/libs.o system/system.sys final/harddisk.img.final
|
||||
bits32: ARCH=bits32
|
||||
bits32: lib/libs.o system/system.sys harddisk
|
||||
sync
|
||||
|
||||
bits64: ARCH=bits64
|
||||
bits64: lib/libs.o system/system.sys uefi
|
||||
sync
|
||||
|
||||
floppy: boot/boot12.bin final/floppy.img.final
|
||||
|
@ -26,16 +32,21 @@ littleclean:
|
|||
(cd final;make littleclean)
|
||||
sync
|
||||
|
||||
indent:
|
||||
(cd system; make indent)
|
||||
(cd lib;make indent)
|
||||
sync
|
||||
|
||||
backup: clean
|
||||
(cd .. ; tar cf - Source\ C | gzip -f - > backup.tar.gz)
|
||||
|
||||
test: all harddisk qemu
|
||||
test: bits32 harddisk qemu
|
||||
|
||||
test64: all uefi qemu64
|
||||
test64: bits64 uefi qemu64
|
||||
|
||||
retest: littleclean test
|
||||
|
||||
retest64: all uefi qemu64
|
||||
retest64: littleclean test64
|
||||
|
||||
floppytest: floppy qemu-floppy
|
||||
|
||||
|
@ -74,7 +85,7 @@ qemu-floppy:
|
|||
(killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/floppy.img.final --enable-kvm -cpu host -s &)
|
||||
|
||||
system/system.sys:
|
||||
(cd system; make)
|
||||
(cd system; make ARCH=$(ARCH))
|
||||
|
||||
boot/boot12.bin:
|
||||
(cd boot; make)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
OUTPUT_FORMAT("elf32-i386", "elf32-i386",
|
||||
"elf32-i386")
|
||||
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
|
||||
OUTPUT_ARCH(i386)
|
||||
|
||||
ENTRY(mymain)
|
||||
ENTRY(start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x100000;
|
||||
.boot ALIGN(4) :
|
||||
.boot ALIGN(8) :
|
||||
{
|
||||
*(.multiboot)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o
|
||||
|
||||
LINK=ld -m elf_i386 -T linker.lds -e main -n -o
|
||||
ASM=nasm
|
||||
LINK=ld -m elf_i386 -T linker.lds -n -o
|
||||
|
||||
all: system.sys
|
||||
sync
|
||||
|
||||
system.sys:
|
||||
system.sys: multiboot.o system.o ../lib/libs.o
|
||||
$(LINK) system.sys multiboot.o system.o ../lib/libs.o
|
||||
|
||||
system.o:
|
||||
$(GCC) system.o system.c
|
||||
$(LINK) system.sys system.o ../lib/libs.o
|
||||
|
||||
multiboot.o:
|
||||
$(ASM) -f elf -o multiboot.o multiboot.asm -dARCH=$(ARCH)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
@ -16,4 +21,5 @@ clean:
|
|||
rm -f *.sys
|
||||
rm -f *.s
|
||||
|
||||
|
||||
indent:
|
||||
indent -linux -i8 -ts8 *.c
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
[BITS 32]
|
||||
|
||||
SECTION .multiboot
|
||||
|
||||
%define MULTIBOOT_TAG_ALIGN 8
|
||||
%define MULTIBOOT2_HEADER_MAGIC 0xe85250d6
|
||||
%define MULTIBOOT_ARCHITECTURE_I386 0
|
||||
|
||||
%define MULTIBOOT_HEADER_TAG_OPTIONAL 1
|
||||
|
||||
%define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4
|
||||
|
||||
%define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8
|
||||
|
||||
%define MULTIBOOT_HEADER_TAG_END 0
|
||||
|
||||
%define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
|
||||
|
||||
%defstr arch ARCH
|
||||
|
||||
multiboot_header:
|
||||
align MULTIBOOT_TAG_ALIGN
|
||||
dd MULTIBOOT2_HEADER_MAGIC ; magic
|
||||
dd MULTIBOOT_ARCHITECTURE_I386 ; architecture
|
||||
dd multiboot_header_end - multiboot_header
|
||||
dd -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
|
||||
align MULTIBOOT_TAG_ALIGN
|
||||
%if arch = "bits32"
|
||||
%warning "Avec la console VGA/EGA."
|
||||
console_tag_start:
|
||||
dw MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS ; type
|
||||
dw MULTIBOOT_HEADER_TAG_OPTIONAL ; flags
|
||||
dd console_tag_end - console_tag_start
|
||||
dd MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
|
||||
console_tag_end:
|
||||
%else
|
||||
align MULTIBOOT_TAG_ALIGN
|
||||
framebuffer_tag_start:
|
||||
%warning "Avec le FRAMEBUFFER VESA."
|
||||
dw MULTIBOOT_TAG_TYPE_FRAMEBUFFER ; type
|
||||
dw MULTIBOOT_HEADER_TAG_OPTIONAL ; flags
|
||||
dd framebuffer_tag_end - framebuffer_tag_start
|
||||
dd 1024 ; width
|
||||
dd 768 ; height
|
||||
dd 32 ; depth
|
||||
%endif
|
||||
align MULTIBOOT_TAG_ALIGN
|
||||
framebuffer_tag_end:
|
||||
dw MULTIBOOT_HEADER_TAG_END
|
||||
dw 0
|
||||
dd 8
|
||||
multiboot_header_end:
|
||||
|
||||
SECTION .text
|
||||
|
||||
global start
|
||||
extern main
|
||||
|
||||
start:
|
||||
push ebx
|
||||
push eax
|
||||
call main
|
||||
hlt
|
|
@ -12,8 +12,7 @@
|
|||
#include "gdt.h"
|
||||
#include "shell.h"
|
||||
#include "syscall.h"
|
||||
|
||||
static u8 __attribute__((section(".multiboot"))) magicmultiboot[28]={0xD6,0x50,0x52,0xE8,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x12,0xaf,0xad,0x17,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00};
|
||||
#include "multiboot2.h"
|
||||
|
||||
static u8 warnmsg[] =
|
||||
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
|
||||
|
@ -41,12 +40,16 @@ void error()
|
|||
return;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
int main(unsigned long magic, unsigned long addr)
|
||||
{
|
||||
asm("movl $0x0000FFFF, %esp");
|
||||
cli();
|
||||
setvmode(0x02);
|
||||
/* Efface l'ecran */
|
||||
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC)
|
||||
{
|
||||
printf ("Nombre magic inconnu: 0x%x\n", (u32) magic);
|
||||
return;
|
||||
}
|
||||
print("\033[2J\000");
|
||||
printf(ansilogo);
|
||||
|
||||
|
|
Loading…
Reference in New Issue