flat assembler
Message board for the users of flat assembler.

Index > OS Construction > protected mode variable far jmp,

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
I'm writing boot code in the second segment ie org 10000h, Razz

and I want to switch to protected mode from real mode,

the intel docs say that after setting bit 0 of cr0
the immediate next instruction must do a
far jump and this will reset cs,

I am using flat addressing without the MMU,
now the problem is because the code is in 10000h to 1ffffh
need a 17 bit offset,

Intels example code suggests:

Code:

  mov eax,cr0
  or eax,1
  mov cr0,eax

  jmp trick

trick:
...

    


the problem is this is no use for me as the CPU cannot
know which segment selector I meant,

when I tried this I echoed the value of cs afterwards
and it is unchanged at 1000h, which is garbage as
we are now in protected mode,

this Intel suggested code functions fine, but
it has garbage for cs,


Now I've tried things like:

[code]

redirect: dd trick
dw gdt.code - gdt ; index to flat code segment,
; code descriptor at gdt.code: gdt table at gdt:
...

mov bx,gdt.data-gdt ; pointer to flat data segment descriptor
mov gs,bx

mov ebx,redirect

....

mov eax,cr0
or eax,1
mov cr0,eax

jmp far dword [gs:ebx]

trick:

[\code]

this and all other things I have tried cause the machine
to reset! Sad

how do I do this? Surprised

remember this is in the second segment 10000h to 1ffffh
so I need 17 bit offsets,

redirect: dw trick and 0ffffh

is no use as trick is 17 bit, I have tried also using
segments with base address 10000h but the
jmp also resets the machine,
Post 16 Mar 2006, 01:05
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
I suggest you jump to the address in realmode, then change to pmode
Example from BOS:
Boot end code:
Code:
-----------------------;;  the file is loaded   ;;-----------------------;quit:          jmp     0x1000:0x0000                       ; jump to loaded file (64kb in mem);-------------------------------------;; set the BOOT-signature at byte 510. ;;-------------------------------------;          rb boot+512-2-$          dw 0xAA55    

Second stage:
Code:
;-------------------------------------------------------;;                     BOS kernel                        ;;-------------------------------------------------------;;    BOS 32-bit kernel, expects to be loaded at 64kb    ;;    in mem.   Small amount of 16-bit code included.    ;;                                                       ;;      For any comments on this code, mail me.          ;;   http://bos.asmhackers.net/   asmhacker@gmail.com    ;;                                                       ;;             by: Christoffer Bubach, 2003-2005         ;;-------------------------------------------------------;use16org 0x10000;---------------------------;;  jump to starting point   ;;---------------------------;          jmp     start;----------------------------------------;;     16-bit include files               ;;----------------------------------------;        ; some include files here:;--------------------------;;   16-bit entry point     ;;--------------------------;start:          cli          mov     ax, cs          mov     ds, ax                                                      ; fasm is more strict about          xor     eax, eax                            ; "org 0x10000" then nasm, so          mov     es, ax                              ; i have to do -0x10000 from          mov     fs, ax                              ; all variable addresses while          mov     gs, ax                              ; in realmode.          sti          call    enable_a20          call    do_all_16bit                        ; ...  Razz          cli          mov     ax, cs                              ; save cs          mov     [realmode_cs - 0x10000], ax         ; in variables.inc          lgdt    [gdtr - 0x10000]                    ; Load the GDT descriptor          lidt    [idtr - 0x10000]                    ; Load the IDT descriptor          mov     eax, cr0          or      al, 1          mov     cr0, eax          jmp     pword 0x08:flush                    ; dword in nasm;--------------------------;;   32-bit entry point     ;;--------------------------;use32flush:          mov     ax, 0x10                            ; refresh all segment registers          mov     ds, ax          mov     es, ax          mov     fs, ax          mov     gs, ax          mov     ss, ax          mov     esp, 0xFFFC          call    bos_init                            ; fix everything    


For more info see BOS source here:
http://bos.asmhackers.net/downloads.php
Post 16 Mar 2006, 01:29
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
Hi Dex4u,

that looks promising, I'll try the new ideas in your post and
report back.

I think it will succeed,

Razz
Post 16 Mar 2006, 13:21
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1
Hi again,

your suggestion has done the trick! Very Happy

at first the machine no longer reset Razz
but echo statements stopped functioning, Sad

after much debugging I found I was being careless
with the use16 and use32 declarations,

the bug was because of include files,
the use32 declaration in the one include file
was now extending to further include files
which should have been use16,

I have been putting asm code in include files Laughing

anyway everything is fine now Cool
Post 16 Mar 2006, 16:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.