Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ HelenOS.config	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -70,4 +70,5 @@
 @ "pentium4" Pentium 4
 @ "pentium3" Pentium 3
+@ "i486" i486
 @ "core" Core Solo/Duo
 @ "athlon_xp" Athlon XP
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/Makefile.inc	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -64,4 +64,8 @@
 endif
 
+ifeq ($(PROCESSOR),i486)
+	CMN2 = -march=i486
+endif
+
 ifeq ($(PROCESSOR),core)
 	CMN2 = -march=prescott
Index: kernel/arch/ia32/include/asm.h
===================================================================
--- kernel/arch/ia32/include/asm.h	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/include/asm.h	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -311,4 +311,5 @@
 }
 
+#ifndef PROCESSOR_i486
 /** Write to MSR */
 NO_TRACE static inline void write_msr(uint32_t msr, uint64_t value)
@@ -335,4 +336,5 @@
 	return ((uint64_t) dx << 32) | ax;
 }
+#endif
 
 
Index: kernel/arch/ia32/include/atomic.h
===================================================================
--- kernel/arch/ia32/include/atomic.h	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/include/atomic.h	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -121,5 +121,7 @@
 	asm volatile (
 		"0:\n"
+#ifndef PROCESSOR_i486
 		"pause\n"        /* Pentium 4's HT love this instruction */
+#endif
 		"mov %[count], %[tmp]\n"
 		"testl %[tmp], %[tmp]\n"
Index: kernel/arch/ia32/include/cycle.h
===================================================================
--- kernel/arch/ia32/include/cycle.h	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/include/cycle.h	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -40,4 +40,7 @@
 NO_TRACE static inline uint64_t get_cycle(void)
 {
+#ifdef PROCESSOR_i486
+	return 0;
+#else
 	uint64_t v;
 	
@@ -48,4 +51,5 @@
 	
 	return v;
+#endif
 }
 
Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/src/asm.S	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -405,5 +405,11 @@
 	xorl %eax, %eax
 	cmpl $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%esp)
+#ifdef PROCESSOR_i486
+	jz 0f
+	movl %eax, %ebp
+0:
+#else
 	cmovnzl %eax, %ebp
+#endif
 
 	movl %ebp, ISTATE_OFFSET_EBP_FRAME(%esp)
Index: kernel/arch/ia32/src/boot/boot.S
===================================================================
--- kernel/arch/ia32/src/boot/boot.S	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/src/boot/boot.S	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -97,20 +97,4 @@
 	pm_status $status_prot
 	
-	movl $(INTEL_CPUID_LEVEL), %eax
-	cpuid
-	cmp $0x0, %eax  /* any function > 0? */
-	jbe pse_unsupported
-	
-	movl $(INTEL_CPUID_STANDARD), %eax
-	cpuid
-	bt $(INTEL_PSE), %edx
-	jc pse_supported
-	
-	pse_unsupported:
-		
-		pm_error $err_pse
-	
-	pse_supported:
-	
 #include "vesa_prot.inc"
 	
@@ -140,4 +124,71 @@
 		jmp hlt0
 
+/** Calculate unmapped address of the end of the kernel. */
+calc_end_of_kernel:
+	movl $hardcoded_load_address, %edi
+	andl $0x7fffffff, %edi
+	movl (%edi), %esi
+	andl $0x7fffffff, %esi
+	
+	movl $hardcoded_ktext_size, %edi
+	andl $0x7fffffff, %edi
+	addl (%edi), %esi
+	andl $0x7fffffff, %esi
+	
+	movl $hardcoded_kdata_size, %edi
+	andl $0x7fffffff, %edi
+	addl (%edi), %esi
+	andl $0x7fffffff, %esi
+	movl %esi, end_of_kernel
+	ret
+
+/** Find free 2M (+4k for alignment) region where to store page tables */
+find_mem_for_pt:
+	/* Check if multiboot info is present */
+	cmpl $0x2BADB002, grub_eax
+	je check_multiboot_map
+	ret
+check_multiboot_map:
+	/* Copy address of the multiboot info to ebx */
+	movl grub_ebx, %ebx
+	/* Check if memory map flag is present */
+	movl (%ebx), %edx
+	andl $(1 << 6), %edx
+	jnz use_multiboot_map
+	ret
+use_multiboot_map:
+	/* Copy address of the memory map to edx */
+	movl 48(%ebx), %edx
+	movl %edx, %ecx
+	addl 44(%ebx), %ecx
+	/* Find a free region at least 2M in size */
+	check_memmap_loop:
+		/* Is this a free region? */
+		cmp $1, 20(%edx)
+		jnz next_region
+		/* Check size */
+		cmp $0, 16(%edx)
+		jnz next_region
+		cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)
+		jbe next_region
+		cmp $0, 8(%edx)
+		jz found_region
+	next_region:
+		cmp %ecx, %edx
+		jbe next_region_do
+		ret
+	next_region_do:
+		addl (%edx), %edx
+		addl $4, %edx
+		jmp check_memmap_loop
+	found_region:
+		/* Use end of the found region */
+		mov 4(%edx), %ecx
+		add 12(%edx), %ecx
+		sub $(2 * 1024 * 1024), %ecx
+		mov %ecx, free_area
+	ret
+		
+
 /** Setup mapping for the kernel.
  *
@@ -148,16 +199,54 @@
 .global map_kernel
 map_kernel:
+	/* Paging features */
 	movl %cr4, %ecx
-	orl $(1 << 4), %ecx      /* PSE on */
 	andl $(~(1 << 5)), %ecx  /* PAE off */
 	movl %ecx, %cr4
 	
+	call calc_end_of_kernel
+	call find_mem_for_pt
+	mov end_of_kernel, %esi
+	mov free_area, %ecx
+	cmpl %esi, %ecx
+	jbe use_end_of_kernel
+	mov %ecx, %esi
+	/* Align address down to 4k */
+	andl $(~4095), %esi
+use_end_of_kernel:
+	
+	/* Align address to 4k */
+	addl $4095, %esi
+	andl $(~4095), %esi
+	
+	/* Allocate space for page tables*/	
+	movl %esi, pt_loc
+	movl $ballocs, %edi
+	andl $0x7fffffff, %edi
+	movl %esi, (%edi)
+	addl $4, %edi
+	movl $(2*1024*1024), (%edi)
+	
+	/* Fill page tables */
+	xorl %ecx, %ecx
+	xorl %ebx, %ebx
+	
+	floop_pt:
+		movl $((1 << 1) | (1 << 0)), %eax
+		orl %ebx, %eax
+		movl %eax, (%esi, %ecx, 4)
+		addl $(4 * 1024), %ebx
+		
+		incl %ecx
+		cmpl $(512 * 1024), %ecx
+		jl floop_pt
+	
+	/* Fill page directory */
 	movl $(page_directory + 0), %esi
 	movl $(page_directory + 2048), %edi
 	xorl %ecx, %ecx
-	xorl %ebx, %ebx
+	movl pt_loc, %ebx
 	
 	floop:
-		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
+		movl $((1 << 1) | (1 << 0)), %eax
 		orl %ebx, %eax
 		/* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
@@ -165,5 +254,5 @@
 		/* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
 		movl %eax, (%edi, %ecx, 4)
-		addl $(4 * 1024 * 1024), %ebx
+		addl $(4 * 1024), %ebx
 		
 		incl %ecx
@@ -523,4 +612,11 @@
 
 grub_ebx:
+	.long 0
+
+pt_loc:
+	.long 0
+end_of_kernel:
+	.long 0
+free_area:
 	.long 0
 
Index: kernel/arch/ia32/src/cpu/cpu.c
===================================================================
--- kernel/arch/ia32/src/cpu/cpu.c	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/src/cpu/cpu.c	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -118,9 +118,11 @@
 		);
 	}
-	
+
+#ifndef PROCESSOR_i486
 	if (CPU->arch.fi.bits.sep) {
 		/* Setup fast SYSENTER/SYSEXIT syscalls */
 		syscall_setup_cpu();
 	}
+#endif
 }
 
Index: kernel/arch/ia32/src/proc/scheduler.c
===================================================================
--- kernel/arch/ia32/src/proc/scheduler.c	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/src/proc/scheduler.c	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -60,8 +60,10 @@
 	uintptr_t kstk = (uintptr_t) &THREAD->kstack[STACK_SIZE];
 	
+#ifndef PROCESSOR_i486
 	if (CPU->arch.fi.bits.sep) {
 		/* Set kernel stack for CP3 -> CPL0 switch via SYSENTER */
 		write_msr(IA32_MSR_SYSENTER_ESP, kstk - sizeof(istate_t));
 	}
+#endif
 	
 	/* Set kernel stack for CPL3 -> CPL0 switch via interrupt */
Index: kernel/arch/ia32/src/syscall.c
===================================================================
--- kernel/arch/ia32/src/syscall.c	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ kernel/arch/ia32/src/syscall.c	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -39,4 +39,5 @@
 #include <arch/pm.h>
 
+#ifndef PROCESSOR_i486
 /** Enable & setup support for SYSENTER/SYSEXIT */
 void syscall_setup_cpu(void)
@@ -49,4 +50,5 @@
 	write_msr(IA32_MSR_SYSENTER_EIP, (uint32_t) sysenter_handler);
 }
+#endif
 
 /** @}
Index: uspace/lib/c/arch/ia32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.common	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ uspace/lib/c/arch/ia32/Makefile.common	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -28,5 +28,9 @@
 
 CLANG_ARCH = i386
+ifeq ($(PROCESSOR),i486)
+GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer
+else
 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
+endif
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -28,5 +28,5 @@
 
 ARCH_SOURCES = \
-	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entry.S \
 	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
Index: uspace/lib/c/arch/ia32/src/entry.S
===================================================================
--- uspace/lib/c/arch/ia32/src/entry.S	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
+++ uspace/lib/c/arch/ia32/src/entry.S	(revision d767cb1f2e5e380442819b0ff1e5a265d08b8060)
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+INTEL_CPUID_STANDARD = 1
+INTEL_SEP = 11
+
+.section .init, "ax"
+
+.org 0
+
+.globl __entry
+
+## User-space task entry point
+#
+# %edi contains the PCB pointer
+#
+__entry:
+	mov %ss, %ax
+	mov %ax, %ds
+	mov %ax, %es
+	mov %ax, %fs
+	# Do not set %gs, it contains descriptor that can see TLS
+
+#ifndef PROCESSOR_i486	
+	# Detect the mechanism used for making syscalls
+	movl $(INTEL_CPUID_STANDARD), %eax
+	cpuid
+	bt $(INTEL_SEP), %edx
+	jnc 0f
+	leal __syscall_fast_func, %eax
+	movl $__syscall_fast, (%eax)
+0:
+#endif
+	#
+	# Create the first stack frame.
+	#
+	pushl $0
+	movl %esp, %ebp
+	
+	# Pass the PCB pointer to __main as the first argument
+	pushl %edi
+	call __main
Index: pace/lib/c/arch/ia32/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia32/src/entry.s	(revision c2cf033ad76b063262d022161f2336ff136331cd)
+++ 	(revision )
@@ -1,65 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-INTEL_CPUID_STANDARD = 1
-INTEL_SEP = 11
-
-.section .init, "ax"
-
-.org 0
-
-.globl __entry
-
-## User-space task entry point
-#
-# %edi contains the PCB pointer
-#
-__entry:
-	mov %ss, %ax
-	mov %ax, %ds
-	mov %ax, %es
-	mov %ax, %fs
-	# Do not set %gs, it contains descriptor that can see TLS
-	
-	# Detect the mechanism used for making syscalls
-	movl $(INTEL_CPUID_STANDARD), %eax
-	cpuid
-	bt $(INTEL_SEP), %edx
-	jnc 0f
-	leal __syscall_fast_func, %eax
-	movl $__syscall_fast, (%eax)
-0:
-	#
-	# Create the first stack frame.
-	#
-	pushl $0
-	movl %esp, %ebp
-	
-	# Pass the PCB pointer to __main as the first argument
-	pushl %edi
-	call __main
