summaryrefslogtreecommitdiff
path: root/sos-code-article6.5/bootstrap
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-03-28 17:09:15 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-03-28 17:09:15 +0100
commita8968330aff45e0b8cf278f49fa337d5fcb9bfd8 (patch)
treededf697b1a5c3c96e77f77e551e9e6af8785a51c /sos-code-article6.5/bootstrap
parent8d9e22df8afa4c3339e52c7b3b77388ca0e69fac (diff)
downloadSOS-a8968330aff45e0b8cf278f49fa337d5fcb9bfd8.tar.gz
SOS-a8968330aff45e0b8cf278f49fa337d5fcb9bfd8.zip
Import and compile code for article 6.5
Diffstat (limited to 'sos-code-article6.5/bootstrap')
-rw-r--r--sos-code-article6.5/bootstrap/multiboot.S85
-rw-r--r--sos-code-article6.5/bootstrap/multiboot.h133
2 files changed, 218 insertions, 0 deletions
diff --git a/sos-code-article6.5/bootstrap/multiboot.S b/sos-code-article6.5/bootstrap/multiboot.S
new file mode 100644
index 0000000..546d947
--- /dev/null
+++ b/sos-code-article6.5/bootstrap/multiboot.S
@@ -0,0 +1,85 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA.
+*/
+
+
+/* The operating system is booted by Grub, so we almost have nothing
+ to do to boot it. We only have to conform to the Multiboot
+ standard, as defined by the Grub documentation */
+
+#define ASM 1
+/* The multiboot.h header contains a lot of multiboot standard
+ definitions */
+#include "multiboot.h"
+
+ /* The multiboot header itself. It must come first. */
+.section ".multiboot"
+ /* Multiboot header must be aligned on a 4-byte boundary */
+ .align 4
+multiboot_header:
+ /* magic= */ .long MULTIBOOT_HEADER_MAGIC
+ /* flags= */ .long MULTIBOOT_HEADER_FLAGS
+ /* checksum= */ .long -(MULTIBOOT_HEADER_MAGIC \
+ +MULTIBOOT_HEADER_FLAGS)
+ /* header_addr= */ .long multiboot_header
+ /* load_addr= */ .long __b_load
+ /* load_end_addr=*/ .long __e_load
+ /* bss_end_addr= */ .long __e_kernel
+ /* entry_addr= */ .long multiboot_entry
+
+/* Here is the beginning of the code of our operating system */
+.text
+
+.globl start, _start
+start:
+_start:
+multiboot_entry:
+ /* Set up a stack */
+ movl $(stack + MULTIBOOT_STACK_SIZE), %ebp
+ movl %ebp, %esp
+
+ /* Set EFLAGS to 0 */
+ pushl $0
+ /* pop stack into the EFLAGS register */
+ popf
+
+ /* Push the magic and the address on the stack, so that they
+ will be the parameters of the cmain function */
+ pushl %ebx
+ pushl %eax
+
+ /* Call the cmain function (os.c) */
+ call EXT_C(sos_main)
+
+ /* Should never get there */
+loop:
+ hlt
+ jmp loop
+
+/* Here is the stack */
+.section ".init_stack", "aw", @nobits
+.size stack, MULTIBOOT_STACK_SIZE
+stack:
+ .space MULTIBOOT_STACK_SIZE
+
+/* Some data characterizing the stack addresses */
+.data
+ .globl bootstrap_stack_bottom
+bootstrap_stack_bottom: .long stack
+
+ .globl bootstrap_stack_size
+bootstrap_stack_size: .long MULTIBOOT_STACK_SIZE
diff --git a/sos-code-article6.5/bootstrap/multiboot.h b/sos-code-article6.5/bootstrap/multiboot.h
new file mode 100644
index 0000000..ee9cdbd
--- /dev/null
+++ b/sos-code-article6.5/bootstrap/multiboot.h
@@ -0,0 +1,133 @@
+#ifndef __MULTIBOOT_H__
+#define __MULTIBOOT_H__
+
+/* multiboot.h - the header for Multiboot */
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Macros. */
+
+/* The magic number for the Multiboot header. */
+#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
+
+/* The flags for the Multiboot header. */
+#define MULTIBOOT_HEADER_FLAGS 0x00010003
+
+/* The magic number passed by a Multiboot-compliant boot loader. */
+#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
+
+/* The size of our stack (16KB). */
+#define MULTIBOOT_STACK_SIZE 0x4000
+
+#define MULTIBOOT_CMDLINE 4
+#define MULTIBOOT_MODS 8
+
+/* C symbol format. HAVE_ASM_USCORE is defined by configure. */
+#ifdef HAVE_ASM_USCORE
+# define EXT_C(sym) _ ## sym
+#else
+# define EXT_C(sym) sym
+#endif
+
+#ifndef ASM
+/* Do not include here in the assembler sources. */
+
+#include <sos/types.h>
+
+/* The address of the stack of the bootstrap thread */
+extern sos_vaddr_t bootstrap_stack_bottom;
+extern sos_size_t bootstrap_stack_size;
+
+/* Types. */
+
+/* The Multiboot header. */
+typedef struct multiboot_header
+{
+ unsigned long magic;
+ unsigned long flags;
+ unsigned long checksum;
+ unsigned long header_addr;
+ unsigned long load_addr;
+ unsigned long load_end_addr;
+ unsigned long bss_end_addr;
+ unsigned long entry_addr;
+} multiboot_header_t;
+
+/* The symbol table for a.out. */
+typedef struct aout_symbol_table
+{
+ unsigned long tabsize;
+ unsigned long strsize;
+ unsigned long addr;
+ unsigned long reserved;
+} aout_symbol_table_t;
+
+/* The section header table for ELF. */
+typedef struct elf_section_header_table
+{
+ unsigned long num;
+ unsigned long size;
+ unsigned long addr;
+ unsigned long shndx;
+} elf_section_header_table_t;
+
+/* The Multiboot information. */
+typedef struct multiboot_info
+{
+ unsigned long flags;
+ unsigned long mem_lower;
+ unsigned long mem_upper;
+ unsigned long boot_device;
+ unsigned long cmdline;
+ unsigned long mods_count;
+ unsigned long mods_addr;
+ union
+ {
+ aout_symbol_table_t aout_sym;
+ elf_section_header_table_t elf_sec;
+ } u;
+ unsigned long mmap_length;
+ unsigned long mmap_addr;
+ unsigned long drives_length;
+ unsigned long drives_addr;
+} multiboot_info_t;
+
+/* The module structure. */
+typedef struct module
+{
+ unsigned long mod_start;
+ unsigned long mod_end;
+ unsigned long string;
+ unsigned long reserved;
+} module_t;
+
+/* The memory map. Be careful that the offset 0 is base_addr_low
+ but no size. */
+typedef struct memory_map
+{
+ unsigned long size;
+ unsigned long base_addr_low;
+ unsigned long base_addr_high;
+ unsigned long length_low;
+ unsigned long length_high;
+ unsigned long type;
+} memory_map_t;
+
+void dump_multiboot_info(multiboot_info_t *mbi);
+
+#endif /* ! ASM */
+
+#endif /* __MULTIBOOT_H__ */