After screwing up my previous working os loader source code and doing some experiment, I found
out that LGDT instruction does not working with LINEAR ADDRESS/ABSOLUTE ADDRESS GDT at all, this is
really nasty bug =(, not documented anywhere ???, but at least I found the right way to do it =).
This instruction need to be given an ADDRESS of GDT which is calculated relative to the contents
of CS register right before LGDT instruction executed. Here's an example:

    [*] If you specify the segment:offset of the 2nd stage loader as 0x07C0:0x0000 in the 1st stage loader,
    then you have to specify the LGDT instruction in the 2nd stage loader as:
    lgdt [gdt_desc_ptr]
    , with gdt_desc_ptr is a pointer calculated relative to 0x07C0:0x0000 (0x7C00 absolute address).
    [*] If you specify the segment:offset of the 2nd stage loader as 0x0000:0x7C00 in the 1st stage loader,
    then you have to specify the LGDT instruction in the 2nd stage loader as:
    lgdt [gdt_desc]
    , with gdt_desc is the absolute address/linear address of the gdt calculated by nasm (the address is
    calculated by summing up the offset of the gdt in the 2nd stage loader file and the
    ORG 0x7C00 

    directive in the beginning of the file).
    -- If you do it as described here, you're guaranteed to switch to P-Mode without any bug --
    [*] One fact you have to taken into account, if you are loading the P-Mode switching instructions
    using int 13h, you have to use absolute address for the gdt, i.e. like the approach in point 2
    above, since CS register will be preloaded with segment 0x0000. I conclude this after doing
    some experiment too =).

    Please correct me if I'm wrong,
    :stupid:

    Here's the source code for the 1st version of the loader (described in point 1):
Posted on 2004-04-12 02:22:12 by Pinczakko
here's the source code for the 2nd version of the loader (described in point 2) :
Posted on 2004-04-12 02:38:01 by Pinczakko
Try this maybe...



jmp word OS_Load_Seg:OS_Load_Offset
Posted on 2004-04-12 04:00:43 by SpooK