diff --git a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S index edef508..1756e4a 100644 --- a/arch/i386/kernel/head.S +++ b/arch/i386/kernel/head.S @@ -62,7 +62,7 @@ ENTRY(startup_32) #endif /* - * Set segments to known values. + * Set segments and stack pointer to known values */ cld lgdt boot_gdt_descr - __PAGE_OFFSET @@ -71,10 +71,13 @@ ENTRY(startup_32) movl %eax,%es movl %eax,%fs movl %eax,%gs - + movl %eax,%ss + movl $(stack_start - __PAGE_OFFSET),%esp + /* * Clear BSS first so that there are no surprises... * No need to cld as DF is already clear from cld above... + * After this, it's permissible to use the stack. */ xorl %eax,%eax movl $__bss_start - __PAGE_OFFSET,%edi @@ -104,10 +107,18 @@ ENTRY(startup_32) addl $(OLD_CL_BASE_ADDR),%esi 2: movl $(saved_command_line - __PAGE_OFFSET),%edi - movl $(COMMAND_LINE_SIZE/4),%ecx - rep - movsl + movl $(COMMAND_LINE_SIZE-1),%ecx + +3: + lodsb + andb %al,%al + jz 1f + stosb + loop 3b + 1: + /* We don't have to actually write the terminating null byte, + since we have already zeroed .bss */ /* * Initialize page tables. This creates a PDE and a set of page @@ -115,28 +126,27 @@ ENTRY(startup_32) * init_pg_tables_end is set up to point to the first "safe" location. * Mappings are created both at virtual address 0 (identity mapping) * and PAGE_OFFSET for up to _end+sizeof(page tables)+INIT_MAP_BEYOND_END. - * - * Warning: don't use %esi or the stack in this code. However, %esp - * can be used as a GPR if you really need it... */ -page_pde_offset = (__PAGE_OFFSET >> 20); +page_pde_offset = __PAGE_OFFSET >> 20 +pte_attributes = 0x067 /* DIRTY+ACCESSED+USER+RW+PRESENT */ +pde_attributes = 0x027 /* ACCESSED+USER+RW+PRESENT */ - movl $(pg0 - __PAGE_OFFSET), %edi - movl $(swapper_pg_dir - __PAGE_OFFSET), %edx - movl $0x007, %eax /* 0x007 = PRESENT+RW+USER */ + movl $(pg0 - __PAGE_OFFSET),%edi + movl $(swapper_pg_dir - __PAGE_OFFSET),%edx + movl $pte_attributes,%eax 10: - leal 0x007(%edi),%ecx /* Create PDE entry */ + leal pde_attributes(%edi),%ecx /* Create PDE entry */ movl %ecx,(%edx) /* Store identity PDE entry */ movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */ addl $4,%edx - movl $1024, %ecx + movl $1024,%ecx 11: stosl addl $0x1000,%eax loop 11b - /* End condition: we must map up to and including INIT_MAP_BEYOND_END */ - /* bytes beyond the end of our own page tables; the +0x007 is the attribute bits */ - leal (INIT_MAP_BEYOND_END+0x007)(%edi),%ebp + /* End condition: we must map up to and including + * INIT_MAP_BEYOND_END bytes beyond the end of our own page tables. */ + leal (INIT_MAP_BEYOND_END+pte_attributes)(%edi),%ebp cmpl %ebp,%eax jb 10b movl %edi,(init_pg_tables_end - __PAGE_OFFSET)