flat assembler
Message board for the users of flat assembler.

Index > OS Construction > use32 or user bug?

Author
Thread Post new topic Reply to topic
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
Hi every body!
I am testing a boot code to load some sectors from hdd. I am putting loaded code at 80000h and it works fine in real mode. But when protected mode some thing is going wrong Sad
I think the problem is with use32 directive because qemu dump shows me the compiled code at 7c00h and jmp 80000h is truncated to jmp 0xfffe.
On the other hand, RAM dump at 80000h shows no code at all when in protected mode Sad
There must be something wrong but the code is fine... or not? I have made a bunch of test, but there is no way the screen changes for me at PM.
What happens here?
Thanks in advance...
Code:
format binary as 'img'
org 7C00h
          cli

             call    loadCore                ; load 127 sectors from HDD

             lgdt    fword[gdtr]             ; this is the 'classical' code
            mov     eax,cr0
             or      al,1
                mov     cr0,eax
             jmp     8:protectedMode
use32
 protectedMode: jmp 80000h                  ; Compiles to 0xfffe!!!! Sad
                                                ; even if using coreCode label
                                              ; What about 80000h??

align 8
           gdt:
         dq 0000000000000000h 
               dq 00cf9a000000ffffh            ; sys code
          dq 00cf92000000ffffh            ; and data
    .end:

       gdtr: dw (gdt.end-gdt)-1
              dd gdt

      loadCore: mov   ah,0x02                 ; read
              mov     al,0x7F                 ; 127 sectors
               mov     ch,0x00                 ; from track zero
           mov     cl,0x02                 ; starting at sector two
            mov     dh,0x00                 ; on head zero
              mov     dl,0x80                 ; using HDD
         mov     bx,0x8000               ; copy to 8000:0
                mov     es,bx
               mov     bx,0x0000
       @@: int 0x13                    ; should go to 80000h
               jc      @b
          ret

times 510-($-$$) db 0
             dw 0aa55h

org 80000h
      coreCode:     mov     edi,0b8000h             ; the test code
             mov     [edi],dword 744b744fh
               hlt                             ; let me see the screen...

 times (127*512)-($-$$)       db 0                    ; fill the sectors, just in case
    

_________________
i don't hate goto
Post 28 Mar 2012, 05:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
flash: Your loadCore code is in a use32 section. You will likely have trouble calling that from 16-bit code.
Post 28 Mar 2012, 08:59
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
Oh! my...! this is embarrassing. Thank's revolution. Now ii works perfectly, but still disassembly shows:
Code:
ljmp   $0x2b4,$0x87c4a
    

instead of jmp 0x80000, Any idea...?
Post 28 Mar 2012, 10:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
flash wrote:
Oh! my...! this is embarrassing. Thank's revolution. Now ii works perfectly, but still disassembly shows:
Code:
ljmp   $0x2b4,$0x87c4a
    

instead of jmp 0x80000, Any idea...?
You need to tell your disassembler that the instruction at that address needs to be disassembled in 32-bit context. Things look different when you try to look at a 32-bit instruction in a 16-bit context.
Post 28 Mar 2012, 10:05
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash
That's right... my mistake Smile
Post 29 Mar 2012, 01:26
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.