summaryrefslogtreecommitdiff
path: root/sys/src/9/pc/rebootcode.s
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/9/pc/rebootcode.s
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/9/pc/rebootcode.s')
-rwxr-xr-xsys/src/9/pc/rebootcode.s54
1 files changed, 54 insertions, 0 deletions
diff --git a/sys/src/9/pc/rebootcode.s b/sys/src/9/pc/rebootcode.s
new file mode 100755
index 000000000..34ee4ca36
--- /dev/null
+++ b/sys/src/9/pc/rebootcode.s
@@ -0,0 +1,54 @@
+#include "mem.h"
+
+/*
+ * Turn off MMU, then memmory the new kernel to its correct location
+ * in physical memory. Then jumps the to start of the kernel.
+ */
+
+TEXT main(SB),$0
+ MOVL p1+0(FP), DI /* destination */
+ MOVL DI, AX /* entry point */
+ MOVL p2+4(FP), SI /* source */
+ MOVL n+8(FP), CX /* byte count */
+
+/*
+ * disable paging
+ */
+ MOVL CR0, DX
+ ANDL $~0x80000000, DX /* ~(PG) */
+ MOVL DX, CR0
+ MOVL $0, DX
+ MOVL DX, CR3
+
+/*
+ * the source and destination may overlap.
+ * determine whether to copy forward or backwards
+ */
+ CMPL SI, DI
+ JGT _forward
+ MOVL SI, DX
+ ADDL CX, DX
+ CMPL DX, DI
+ JGT _back
+
+_forward:
+ CLD
+ REP; MOVSB
+ JMP _startkernel
+
+_back:
+ ADDL CX, DI
+ ADDL CX, SI
+ SUBL $1, DI
+ SUBL $1, SI
+ STD
+ REP; MOVSB
+ JMP _startkernel
+/*
+ * JMP to kernel entry point. Note the true kernel entry point is
+ * the virtual address KZERO|AX, but this must wait until
+ * the MMU is enabled by the kernel in l.s
+ */
+_startkernel:
+ ORL AX, AX /* NOP: avoid link bug */
+ JMP* AX