2011-01-11 19:27:45 +01:00
|
|
|
# Multiboot header, for multiboot boot loaders like GNU Grub.
|
|
|
|
# http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
|
|
|
|
#
|
|
|
|
# Using GRUB 2, you can boot xv6 from a file stored in a
|
|
|
|
# Linux file system by copying kernel or kernelmemfs to /boot
|
|
|
|
# and then adding this menu entry:
|
|
|
|
#
|
|
|
|
# menuentry "xv6" {
|
|
|
|
# insmod ext2
|
|
|
|
# set root='(hd0,msdos1)'
|
|
|
|
# set kernel='/boot/kernel'
|
|
|
|
# echo "Loading ${kernel}..."
|
|
|
|
# multiboot ${kernel} ${kernel}
|
|
|
|
# boot
|
|
|
|
# }
|
|
|
|
|
|
|
|
#include "asm.h"
|
2011-07-29 13:31:27 +02:00
|
|
|
#include "memlayout.h"
|
2011-08-08 19:30:08 +02:00
|
|
|
#include "mmu.h"
|
2011-01-11 19:27:45 +01:00
|
|
|
|
|
|
|
#define STACK 4096
|
|
|
|
|
|
|
|
# Multiboot header. Data to direct multiboot loader.
|
|
|
|
.p2align 2
|
|
|
|
.text
|
|
|
|
.globl multiboot_header
|
|
|
|
multiboot_header:
|
|
|
|
#define magic 0x1badb002
|
|
|
|
#define flags (1<<16 | 1<<0)
|
|
|
|
.long magic
|
|
|
|
.long flags
|
|
|
|
.long (-magic-flags)
|
|
|
|
.long multiboot_header # beginning of image
|
|
|
|
.long multiboot_header
|
|
|
|
.long edata
|
|
|
|
.long end
|
|
|
|
.long multiboot_entry
|
|
|
|
|
|
|
|
# Multiboot entry point. Machine is mostly set up.
|
|
|
|
# Configure the GDT to match the environment that our usual
|
|
|
|
# boot loader - bootasm.S - sets up.
|
|
|
|
.globl multiboot_entry
|
|
|
|
multiboot_entry:
|
2011-08-10 03:37:35 +02:00
|
|
|
# lgdt V2P_WO(gdtdesc)
|
|
|
|
# ljmp $(SEG_KCODE<<3), $mbstart32
|
2011-01-11 19:27:45 +01:00
|
|
|
|
|
|
|
mbstart32:
|
|
|
|
# Set up the protected-mode data segment registers
|
|
|
|
movw $(SEG_KDATA<<3), %ax # Our data segment selector
|
|
|
|
movw %ax, %ds # -> DS: Data Segment
|
|
|
|
movw %ax, %es # -> ES: Extra Segment
|
|
|
|
movw %ax, %ss # -> SS: Stack Segment
|
|
|
|
movw $0, %ax # Zero segments not ready for use
|
|
|
|
movw %ax, %fs # -> FS
|
|
|
|
movw %ax, %gs # -> GS
|
|
|
|
|
2011-08-10 03:37:35 +02:00
|
|
|
movl $(V2P_WO(bootpgdir)), %eax
|
|
|
|
movl %eax, %cr3
|
|
|
|
# Turn on paging.
|
|
|
|
movl %cr0, %eax
|
|
|
|
orl $(CR0_PE|CR0_PG|CR0_WP), %eax
|
|
|
|
movl %eax, %cr0
|
|
|
|
|
|
|
|
# now switch to using addresses above KERNBASE
|
|
|
|
# call addresses are pc-relative so we jump though this hoop:
|
|
|
|
mov $relocated, %eax
|
|
|
|
jmp *%eax
|
|
|
|
relocated:
|
2011-01-11 19:27:45 +01:00
|
|
|
# Set up the stack pointer and call into C.
|
|
|
|
movl $(stack + STACK), %esp
|
|
|
|
call main
|
|
|
|
spin:
|
|
|
|
jmp spin
|
|
|
|
|
|
|
|
.comm stack, STACK
|