summaryrefslogtreecommitdiff
path: root/entry.S
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2011-08-15 12:02:59 -0400
committerFrans Kaashoek <[email protected]>2011-08-15 12:02:59 -0400
commitc60a3551c2dba29006f5d7917308281e47fa5fef (patch)
tree3fad525469c88a1521220ff8d0468dddbdb47af5 /entry.S
parentc95ce31c5978bd43e1f0d34e51a4e3d7bcc41b14 (diff)
downloadxv6-labs-c60a3551c2dba29006f5d7917308281e47fa5fef.tar.gz
xv6-labs-c60a3551c2dba29006f5d7917308281e47fa5fef.tar.bz2
xv6-labs-c60a3551c2dba29006f5d7917308281e47fa5fef.zip
Separate more clearly bootloader from xv6 by renaming multiboot.S to entry.S etc.
Maybe the string boot shouldn't appear in xv6 code?
Diffstat (limited to 'entry.S')
-rw-r--r--entry.S60
1 files changed, 60 insertions, 0 deletions
diff --git a/entry.S b/entry.S
new file mode 100644
index 0000000..cd6a62b
--- /dev/null
+++ b/entry.S
@@ -0,0 +1,60 @@
+# 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"
+#include "memlayout.h"
+#include "mmu.h"
+
+#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.
+.globl multiboot_entry
+multiboot_entry:
+ 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:
+ # Set up the stack pointer and call into C.
+ movl $(stack + STACK), %esp
+ call main
+spin:
+ jmp spin
+
+.comm stack, STACK