No... I don't get it - I'm sorry.
It doesn't matter whether you put your kernel at 1mb or 16mb or 200mb. The i386 in pmode can access 4GB linearly without any paging. With paging and PAE you can theoritcally access 64GB.
What I do in my kernel startup code is
1) Check whether GRUB loaded me - else display a blinking "B" and hang
2) Check whether data segment has been properly linked, else display "D" and hang
3) load my GDT (two descriptors, code and data 0 - 4GB) (i.e. "flat" mode)
4) Reload CS
5) Reload DS, ES, FS, GS, SS
5) Set up my stack pointer
6) Run global ctors (I use C++)
7) Push the pointer to the mbi
Run my main
9) Clean up the stack after main
10) Run global dtors (I use C++)
11) Display blinking "E"
11) Hang
And here is my code:
The #define ASM is required by multiboot.h
__KERNEL_CS and __KERNEL_DS are located in x86 and should correspond to your actual selectors described in the GDT. GDT_ENTRIES is also defined in x86.h and is curently set to 256
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=->
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 021339, USA. */
/* This file is based on boot.S from GRUB's doc/ directory. */
#define ASM 1
#define DMAGIC 0xdeadda7a
#include <x86.h>
#include <multiboot.h>
.text
.globl start, _start, EXT_C(gdt), EXT_C(gdt_descr)
start:
_start:
jmp multiboot_entry
/* Align 32 bits boundary. */
.align 4
/* Multiboot header. */
multiboot_header:
/* magic */
.long MULTIBOOT_HEADER_MAGIC
/* flags */
.long MULTIBOOT_HEADER_FLAGS
/* checksum */
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
multiboot_entry:
/* Reset EFLAGS. */
pushl $0
popf
/* check that we were loaded by a Multiboot loader */
checkboot:
cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax
je checkdata
/* Blinking 'B' */
movw $0x9F42, 0xb8000
jmp loop
/* Check that the data segment is properly linked */
checkdata:
cmpl $DMAGIC, data_magic(,1)
je kstart
/* Blinking 'D' */
movw $0x9F44, 0xb8000
jmp loop
kstart:
/* setup the new GDT as soon as we can as we can't rely on GRUB's GDT */
lgdt EXT_C(gdt_descr)
ljmp $__KERNEL_CS,$1f
/* Reload data segment registers... */
1: movl $__KERNEL_DS,%eax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss
/* Initialize the stack pointer. */
movl $(stack + STACK_SIZE), %esp
/* See libk/runtime.cpp for notes */
call EXT_C(do_global_ctor)
/* Push the pointer to the Multiboot information structure. */
pushl %ebx
call EXT_C(main)
/* we shouldn't get here */
addl $4, %esp
call EXT_C(do_global_dtor)
cli
/* Blinking 'E' */
movw $0x9F45, 0xb8000
loop: jmp loop
/* data section */
.data
.align 4
data_magic:
.long DMAGIC
.align 2
EXT_C(gdt_descr):
.word GDT_ENTRIES * 8 - 1
.long EXT_C(gdt)
.align 16 /* align on 64 bit boundary */
EXT_C(gdt):
.quad 0x0000000000000000 /* NULL descriptor */
.quad 0x00cf9a000000ffff /* 0x8 kernel 4GB code at 0x00000000 */
.quad 0x00cf92000000ffff /* 0x10 kernel 4GB data at 0x00000000 */
.fill GDT_ENTRIES - 3,8,0 /* Space for LDT, TSS and whatever */
/* Our stack area. */
.comm stack, STACK_SIZE
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=->