root/entry.S

/* [<][>][^][v][top][bottom][index][help] */
   1 # Multiboot header, for multiboot boot loaders like GNU Grub.
   2 # http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
   3 #
   4 # Using GRUB 2, you can boot xv6 from a file stored in a
   5 # Linux file system by copying kernel or kernelmemfs to /boot
   6 # and then adding this menu entry:
   7 #
   8 # menuentry "xv6" {
   9 #       insmod ext2
  10 #       set root='(hd0,msdos1)'
  11 #       set kernel='/boot/kernel'
  12 #       echo "Loading ${kernel}..."
  13 #       multiboot ${kernel} ${kernel}
  14 #       boot
  15 # }
  16 
  17 #include "asm.h"
  18 #include "memlayout.h"
  19 #include "mmu.h"
  20 #include "param.h"
  21 
  22 # Multiboot header.  Data to direct multiboot loader.
  23 .p2align 2
  24 .text
  25 .globl multiboot_header
  26 multiboot_header:
  27   #define magic 0x1badb002
  28   #define flags 0
  29   .long magic
  30   .long flags
  31   .long (-magic-flags)
  32 
  33 # By convention, the _start symbol specifies the ELF entry point.
  34 # Since we haven't set up virtual memory yet, our entry point is
  35 # the physical address of 'entry'.
  36 .globl _start
  37 _start = V2P_WO(entry)
  38 
  39 # Entering xv6 on boot processor, with paging off.
  40 .globl entry
  41 entry:
  42   # Turn on page size extension for 4Mbyte pages
  43   movl    %cr4, %eax
  44   orl     $(CR4_PSE), %eax
  45   movl    %eax, %cr4
  46   # Set page directory
  47   movl    $(V2P_WO(entrypgdir)), %eax
  48   movl    %eax, %cr3
  49   # Turn on paging.
  50   movl    %cr0, %eax
  51   orl     $(CR0_PG|CR0_WP), %eax
  52   movl    %eax, %cr0
  53 
  54   # Set up the stack pointer.
  55   movl $(stack + KSTACKSIZE), %esp
  56 
  57   # Jump to main(), and switch to executing at
  58   # high addresses. The indirect call is needed because
  59   # the assembler produces a PC-relative instruction
  60   # for a direct jump.
  61   mov $main, %eax
  62   jmp *%eax
  63 
  64 .comm stack, KSTACKSIZE

/* [<][>][^][v][top][bottom][index][help] */