Index: arch/ia32/Makefile.inc
===================================================================
--- arch/ia32/Makefile.inc	(revision 23c0c081a1f1288545468b0396566432757bd3e6)
+++ arch/ia32/Makefile.inc	(revision 7b7d7d1cbbddea9be6f0e75c0adabf7bda19ad53)
@@ -14,5 +14,5 @@
 
 CPPFLAGS=$(DEFS) -nostdinc -I../include
-CFLAGS=$(CPPFLAGS) -nostdlib -fno-builtin -fomit-frame-pointer -Wmissing-prototypes -Werror -O1
+CFLAGS=$(CPPFLAGS) -nostdlib -fno-builtin -fomit-frame-pointer -Wmissing-prototypes -Werror -O3
 LFLAGS=-M -no-check-sections -T ../arch/ia32/_link.ld
 
Index: arch/ia32/boot/boot.S
===================================================================
--- arch/ia32/boot/boot.S	(revision 23c0c081a1f1288545468b0396566432757bd3e6)
+++ arch/ia32/boot/boot.S	(revision 7b7d7d1cbbddea9be6f0e75c0adabf7bda19ad53)
@@ -35,4 +35,13 @@
 
 
+# KERNEL_SIZE is passed from the outside to the preprocessor
+#if (KERNEL_SIZE%512>0)
+#define TAIL		1
+#else
+#define	TAIL		0
+#endif
+
+#define SECTORS		(KERNEL_SIZE/512+TAIL)
+
 .text
 .global _start_0x7c00
@@ -42,26 +51,21 @@
 	xorw %ax,%ax		# reset, %al will be used below
 	movw %ax,%dx		# fd0, %dh and %dl will be used below
-	int $0x13
+    	movw %dx,%ds
+
+	movw %dx,%ss		# initialize stack
+	movw $stack,%sp
+
+	int $0x13		# reset floppy
 	jc stop_trying
 
-	movb $2,%ah		# read
-	incb %al		# one sector
-	movb %ah,%cl		# from disk sector 2
-	movw %dx,%es
+    	movw %dx,%ds
+	movw %dx,%ss
+	movw $0x7c00,%sp
+	movw $0xffe0,%si	# after next increment, %si will become 0x0000
+	movw %si,%es
 	movw $0x8000,%bx	# at %es:%bx
-	int $0x13
-	jc stop_trying
-
-	pushw $('.')
-	call echo_mark
-	add $2,%sp
-    
-    	movw %dx,%ds
 	
-	# KERNEL_SIZE is passed from the outside to the preprocessor
-	movl $(KERNEL_SIZE),%edi
+	movl $(SECTORS),%edi
 	
-	shrl $9,%edi		# number of sectors that kernel occupies (%edi div 512)
-    
 read_next:
 	test %edi,%edi
@@ -72,14 +76,12 @@
 	outb %al,%dx
 
-	pushw $('$')
+	movb $('$'),%al
 	call echo_mark
-	add $2,%sp	
 	
 	jmpl $0,$0x8000
 
 read_sectors:
-	pushw $('.')
+	movb $('.'),%al	
 	call echo_mark
-	add $2,%sp
 
 	decl %edi
@@ -105,7 +107,6 @@
 	jnc read_next
 
-	pushw $('R')
+	movb $('R'),%al
 	call echo_mark
-	add $2,%sp
 
 	xorw %ax,%ax			# try to reset
@@ -115,7 +116,6 @@
 
 stop_trying:
-	pushw $('F')
+	movb $('F'),%al	
 	call echo_mark
-	add $2,%sp
 
 	cli
@@ -128,5 +128,4 @@
 	pusha
     
-	movw CH(%bp),%ax
 	movb $0xe,%ah
 	movb $7,%bl
@@ -139,10 +138,9 @@
 # current logical sector from the beginning of the disk
 logical_sector:
-	.word 1
+	.word 0
 
 # number of sectors per track on 1440 floppy
 sectors:
 	.byte 18
-
 
 # boot floppy signature
@@ -151,2 +149,3 @@
 	.byte 0x55
 	.byte 0xaa
+stack:
