Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision 7e956eb53e39a5b6b5da0e92b2e789a596d7fc45)
+++ kernel/arch/ia32/src/asm.S	(revision b3cd9eb53290f21cd8d641b59597ef033013237e)
@@ -29,7 +29,7 @@
 ## very low and hardware-level functions
 
-# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
-# and 1 means interrupt with error word
-#define ERROR_WORD_INTERRUPT_LIST 0x00027D00
+# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error
+# word and 1 means interrupt with error word
+#define ERROR_WORD_INTERRUPT_LIST 0x00027d00
 
 .text
@@ -66,25 +66,25 @@
 memcpy_from_uspace:
 memcpy_to_uspace:
-	movl %edi, %edx				/* save %edi */
-	movl %esi, %eax				/* save %esi */
+	movl %edi, %edx			/* save %edi */
+	movl %esi, %eax			/* save %esi */
 	
 	movl MEMCPY_SIZE(%esp), %ecx
-	shrl $2, %ecx				/* size / 4 */
+	shrl $2, %ecx			/* size / 4 */
 	
 	movl MEMCPY_DST(%esp), %edi
 	movl MEMCPY_SRC(%esp), %esi
 	
-	rep movsl				/* copy as much as possible word by word */
+	rep movsl			/* copy whole words */
 
 	movl MEMCPY_SIZE(%esp), %ecx
-	andl $3, %ecx				/* size % 4 */
+	andl $3, %ecx			/* size % 4 */
 	jz 0f
 	
-	rep movsb				/* copy the rest byte by byte */
+	rep movsb			/* copy the rest byte by byte */
 
 0:
 	movl %edx, %edi
 	movl %eax, %esi
-	movl MEMCPY_SRC(%esp), %eax		/* MEMCPY_SRC(%esp), success */
+	movl MEMCPY_SRC(%esp), %eax	/* MEMCPY_SRC(%esp), success */
 	ret
 	
@@ -97,5 +97,5 @@
 	movl %edx, %edi
 	movl %eax, %esi
-	xorl %eax, %eax				/* return 0, failure */
+	xorl %eax, %eax			/* return 0, failure */
 	ret
 
@@ -105,7 +105,8 @@
 #
 paging_on:
-	movl %cr0,%edx
-	orl $(1<<31),%edx		# paging on
-	andl $~((1<<30)|(1<<29)),%edx	# clear Cache Disable and not Write Though
+	movl %cr0, %edx
+	orl $(1 << 31), %edx		# paging on
+	# clear Cache Disable and not Write Though
+	andl $~((1 << 30) | (1 << 29)), %edx
 	movl %edx,%cr0
 	jmp 0f
@@ -119,13 +120,9 @@
 #
 enable_l_apic_in_msr:
-	push %eax
-
 	movl $0x1b, %ecx
 	rdmsr
-	orl $(1<<11),%eax
-	orl $(0xfee00000),%eax
+	orl $(1 << 11), %eax
+	orl $(0xfee00000), %eax
 	wrmsr
-
-	pop %eax
 	ret
 
@@ -135,5 +132,5 @@
 	pushfl
 	pop %ecx
-	and $0xffffbfff,%ecx
+	and $0xffffbfff, %ecx
 	push %ecx
 	popfl
@@ -151,32 +148,40 @@
 .macro handler i n
 
-.ifeq \i-0x30     # Syscall handler
-	push %ds
-	push %es
-	push %fs
-	push %gs
-
-	# Push arguments on stack
-	push %edi
-	push %esi
-	push %edx
-	push %ecx
-	push %eax
+.ifeq \i - 0x30     # Syscall handler
+	pushl %ds
+	pushl %es
+	pushl %fs
+	pushl %gs
+
+	#
+	# Push syscall arguments onto the stack
+	#
+	# NOTE: The idea behind the order of arguments passed in registers is to
+	#	use all scratch registers first and preserved registers next.
+	#	An optimized libc syscall wrapper can make use of this setup.
+	#
+	pushl %eax
+	pushl %ebp
+	pushl %edi
+	pushl %esi
+	pushl %ebx
+	pushl %ecx
+	pushl %edx
 	
 	# we must fill the data segment registers
-	movw $16,%ax
-	movw %ax,%ds
-	movw %ax,%es
+	movw $16, %ax
+	movw %ax, %ds
+	movw %ax, %es
 	
 	sti
-	
-	call syscall_handler   # syscall_handler(ax,cx,dx,si,di)
+	# syscall_handler(edx, ecx, ebx, esi, edi, ebp, eax)
+	call syscall_handler   
 	cli
-	addl $20, %esp         # clean-up of parameters
-	
-	pop %gs
-	pop %fs
-	pop %es
-	pop %ds
+	addl $28, %esp         # clean-up of parameters
+	
+	popl %gs
+	popl %fs
+	popl %es
+	popl %ds
 	
 	CLEAR_NT_FLAG
@@ -189,5 +194,5 @@
 	 * handlers and istate_t can be the same for both types.
 	 */
-	.iflt \i-32
+	.iflt \i - 32
 		.if (1 << \i) & ERROR_WORD_INTERRUPT_LIST
 			/* 
@@ -207,62 +212,62 @@
 	.endif
 	
-	push %ds
-	push %es
-	push %fs
-	push %gs
+	pushl %ds
+	pushl %es
+	pushl %fs
+	pushl %gs
 
 #ifdef CONFIG_DEBUG_ALLREGS
-	push %ebx
-	push %ebp
-	push %edi
-	push %esi
+	pushl %ebx
+	pushl %ebp
+	pushl %edi
+	pushl %esi
 #else
-	sub $16, %esp
+	subl $16, %esp
 #endif
-	push %edx
-	push %ecx
-	push %eax
+	pushl %edx
+	pushl %ecx
+	pushl %eax
 	
 	# we must fill the data segment registers
-	movw $16,%ax
-	movw %ax,%ds
-	movw %ax,%es
+	movw $16, %ax
+	movw %ax, %ds
+	movw %ax, %es
 
 	pushl %esp          # *istate
 	pushl $(\i)         # intnum
 	call exc_dispatch   # excdispatch(intnum, *istate)
-	addl $8,%esp        # Clear arguments from stack
+	addl $8, %esp       # Clear arguments from stack
 
 	CLEAR_NT_FLAG # Modifies %ecx
 	
-	pop %eax
-	pop %ecx
-	pop %edx
+	popl %eax
+	popl %ecx
+	popl %edx
 #ifdef CONFIG_DEBUG_ALLREGS
-	pop %esi
-	pop %edi
-	pop %ebp
-	pop %ebx
+	popl %esi
+	popl %edi
+	popl %ebp
+	popl %ebx
 #else
-	add $16, %esp
+	addl $16, %esp
 #endif	
 	
-	pop %gs
-	pop %fs
-	pop %es
-	pop %ds
-
-	addl $4,%esp	# Skip error word, no matter whether real or fake.
+	popl %gs
+	popl %fs
+	popl %es
+	popl %ds
+
+	addl $4, %esp	# Skip error word, no matter whether real or fake.
 	iret
 .endif
 
 	.align INTERRUPT_ALIGN
-	.if (\n-\i)-1
-	handler "(\i+1)",\n
+	.if (\n- \i) - 1
+	handler "(\i + 1)", \n
 	.endif
 .endm
 
 # keep in sync with pm.h !!!
-IDT_ITEMS=64
+IDT_ITEMS = 64
 .align INTERRUPT_ALIGN
 interrupt_handlers:
@@ -274,3 +279,3 @@
 .global interrupt_handler_size
 
-interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS
+interrupt_handler_size: .long (h_end - h_start) / IDT_ITEMS
