2016-08-10 11:22:36 -04:00
|
|
|
# The xv6 kernel starts executing in this file. This file is linked with
|
|
|
|
# the kernel C code, so it can refer to kernel symbols such as main().
|
|
|
|
# The boot block (bootasm.S and bootmain.c) jumps to entry below.
|
|
|
|
|
2011-01-11 13:27:45 -05: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 07:31:27 -04:00
|
|
|
#include "memlayout.h"
|
2011-08-08 13:30:08 -04:00
|
|
|
#include "mmu.h"
|
2011-09-01 12:18:43 -04:00
|
|
|
#include "param.h"
|
2011-01-11 13:27:45 -05:00
|
|
|
|
|
|
|
# Multiboot header. Data to direct multiboot loader.
|
|
|
|
.p2align 2
|
|
|
|
.text
|
|
|
|
.globl multiboot_header
|
|
|
|
multiboot_header:
|
|
|
|
#define magic 0x1badb002
|
2011-09-04 15:51:46 -04:00
|
|
|
#define flags 0
|
2011-01-11 13:27:45 -05:00
|
|
|
.long magic
|
|
|
|
.long flags
|
|
|
|
.long (-magic-flags)
|
2011-09-04 15:51:46 -04:00
|
|
|
|
|
|
|
# By convention, the _start symbol specifies the ELF entry point.
|
|
|
|
# Since we haven't set up virtual memory yet, our entry point is
|
|
|
|
# the physical address of 'entry'.
|
|
|
|
.globl _start
|
|
|
|
_start = V2P_WO(entry)
|
2011-01-11 13:27:45 -05:00
|
|
|
|
2011-09-13 12:28:45 -04:00
|
|
|
# Entering xv6 on boot processor, with paging off.
|
2011-08-15 20:11:13 -04:00
|
|
|
.globl entry
|
|
|
|
entry:
|
2011-08-15 17:41:58 -04:00
|
|
|
# Turn on page size extension for 4Mbyte pages
|
|
|
|
movl %cr4, %eax
|
|
|
|
orl $(CR4_PSE), %eax
|
|
|
|
movl %eax, %cr4
|
|
|
|
# Set page directory
|
2011-08-30 20:50:19 -04:00
|
|
|
movl $(V2P_WO(entrypgdir)), %eax
|
2011-08-09 21:37:35 -04:00
|
|
|
movl %eax, %cr3
|
|
|
|
# Turn on paging.
|
|
|
|
movl %cr0, %eax
|
2011-08-30 20:50:19 -04:00
|
|
|
orl $(CR0_PG|CR0_WP), %eax
|
2011-08-09 21:37:35 -04:00
|
|
|
movl %eax, %cr0
|
|
|
|
|
2011-08-31 05:38:05 -04:00
|
|
|
# Set up the stack pointer.
|
2011-09-01 12:18:43 -04:00
|
|
|
movl $(stack + KSTACKSIZE), %esp
|
2011-08-31 05:38:05 -04:00
|
|
|
|
2011-09-01 12:02:49 -04:00
|
|
|
# Jump to main(), and switch to executing at
|
2011-08-31 05:38:05 -04:00
|
|
|
# high addresses. The indirect call is needed because
|
|
|
|
# the assembler produces a PC-relative instruction
|
2011-09-01 12:02:49 -04:00
|
|
|
# for a direct jump.
|
2011-08-31 05:38:05 -04:00
|
|
|
mov $main, %eax
|
|
|
|
jmp *%eax
|
2011-01-11 13:27:45 -05:00
|
|
|
|
2011-09-01 12:18:43 -04:00
|
|
|
.comm stack, KSTACKSIZE
|