flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Its me again...

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 08 Mar 2011, 16:48
Hi everyone,
Its me again. I rewrote my code :

Code:
        ORG 7C00h

        USE16

        CLI
        PM:
        lgdt [cs:GDT_DESC] ; GDT is setup now

        mov eax, cr0       ; going to th "Protected Land"
        bts eax, 0h
        mov cr0, eax

        USE32
        jmp 08h:anarchy
        anarchy:
        mov ax, 10h
        mov ss, ax
        mov ds, ax
        mov esp, 90000h

        Video_out:
        mov byte [0B8002h], 'H'
        mov byte [0B8003h], 01Fh








        times 1890 db 0

        GP dw 0h

        PModemsg    db  '   Welcome to the Protected mode!!' ; ; 33 symbols total

        ScanPCImsg  db  ' Scanning PCI-PCIX-PCIE devices...' ;   33 symbols total

        GDT_DESC:
                    dw GDT_ENDS - GDT_STARTS
                    dq GDT_STARTS

        GDT_STARTS:


        GDT_REC0    dq 0h


        GDT_REC1    dw 0FFFFh
                    dw 0h
                    db 0h
                    db 10011010b
                    db 11001111b
                    db 0h
        GDT_REC2    dw 0FFFFh
                    dw 0h
                    db 0h
                    db 10001001b
                    db 11001111b
                    db 0h
        GDT_ENDS:


        dw 0xAA55                                                                       

but it doesnt works... again
help me with it, Virtual Box, which I use gives me error
and please advise good 32bit debugger for windows which can debug .BIN files so, i dont ask so many of dumb questions =)
Post 08 Mar 2011, 16:48
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 08 Mar 2011, 17:38
i will highlight some mistakes, but I'm noob, so do not believe me too much:

Code:
ORG 7C00h 

        USE16 

        CLI 
        PM: 
        lgdt [cs:GDT_DESC] 

        mov eax, cr0      
        bts eax, 0h 
        mov cr0, eax 

        jmp 08h:anarchy 
        USE32             ; ########## use here instead
        anarchy:       
        mov ax, 10h 
        mov ss, ax 
        mov ds, ax 
        mov esp, 90000h   ; ###### you need to enable a20 in order to access this address

        Video_out: 
        mov byte [0B8002h], 'H'      ; ###### i'm not sure if you can do this in PM
        mov byte [0B8003h], 01Fh   ; ### idem

        times 1890 db 0 ; ############ Wrong: boot sector should be 512 bytes wide

        GP dw 0h 

        PModemsg    db  '   Welcome to the Protected mode!!' 

        ScanPCImsg  db  ' Scanning PCI-PCIX-PCIE devices...'

        GDT_DESC: 
                    dw GDT_ENDS - GDT_STARTS -1 ; ############ need to be size - 1
                    dq GDT_STARTS 

        GDT_STARTS: 


        GDT_REC0    dq 0h 


        GDT_REC1    dw 0FFFFh 
                    dw 0h 
                    db 0h 
                    db 10011010b 
                    db 11001111b 
                    db 0h 
        GDT_REC2    dw 0FFFFh 
                    dw 0h 
                    db 0h 
                    db 100[0]1001b ; ###### highlighted zero must be 1, no?, also: maybe you want 0010b in the end, if this is a data descriptor
                    db 11001111b 
                    db 0h 
        GDT_ENDS: 

                    ; ######## times 510 - size should come here
        dw 0xAA55                        

_________________
Sorry if bad english.
Post 08 Mar 2011, 17:38
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 08 Mar 2011, 17:50
Teehee wrote:
i will highlight some mistakes, but I'm noob, so do not believe me too much:

Code:
ORG 7C00h 

        USE16 

        CLI 
        PM: 
        lgdt [cs:GDT_DESC] 

        mov eax, cr0      
        bts eax, 0h 
        mov cr0, eax 

        jmp 08h:anarchy 
        USE32             ; ########## use here instead
        anarchy:       
        mov ax, 10h 
        mov ss, ax 
        mov ds, ax 
        mov esp, 90000h   ; ###### you need to enable a20 in order to access this address

        Video_out: 
        mov byte [0B8002h], 'H'      ; ###### i'm not sure if you can do this in PM
        mov byte [0B8003h], 01Fh   ; ### idem

        times 1890 db 0 ; ############ Wrong: boot sector should be 512 bytes wide

        GP dw 0h 

        PModemsg    db  '   Welcome to the Protected mode!!' 

        ScanPCImsg  db  ' Scanning PCI-PCIX-PCIE devices...'

        GDT_DESC: 
                    dw GDT_ENDS - GDT_STARTS -1 ; ############ need to be size - 1
                    dq GDT_STARTS 

        GDT_STARTS: 


        GDT_REC0    dq 0h 


        GDT_REC1    dw 0FFFFh 
                    dw 0h 
                    db 0h 
                    db 10011010b 
                    db 11001111b 
                    db 0h 
        GDT_REC2    dw 0FFFFh 
                    dw 0h 
                    db 0h 
                    db 100[0]1001b ; ###### highlighted zero must be 1, no?, also: maybe you want 0010b in the end, if this is a data descriptor
                    db 11001111b 
                    db 0h 
        GDT_ENDS: 

                    ; ######## times 510 - size should come here
        dw 0xAA55                        


im making cd bootsector, its 2048 bytes
and what about debugger???
Post 08 Mar 2011, 17:50
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 08 Mar 2011, 17:58
so me fail again? dam Smile

debug i know is http://www.ollydbg.de/ (idk if it debug bin) and Bochs debugger (it does).

_________________
Sorry if bad english.
Post 08 Mar 2011, 17:58
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 08 Mar 2011, 19:19
use a floppy boot code eg:
Code:
org 0x7C00
use16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00
;*****************************
; Setting up, to enter pmode.
;*****************************
        cli
        lgdt  [gdtr]
        mov   eax, cr0
        or    al,0x1 
        mov   cr0,eax
        jmp   0x10: protected
;*****************************
; Pmode. Wink
;*****************************
use32
protected:
        mov   ax,0x8 
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00
;*****************************
; Turn floppy off (if space).
;*****************************
        mov   dx,3F2h
        mov   al,0
        out   dx,al
;*****************************
; Print H in righthand corner
;*****************************
        mov   byte [fs:0xB809E], "H"
;*****************************
; Loop, but give CPU a rest
;*****************************
StopHere:
         hlt
         jmp  StopHere

;*************************************
; GDT. 
;*************************************
gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:       dw gdt_end - gdt - 1                                          
            dd gdt 
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start)  db 0  
dw 0xaa55
    


And write CD using floppy emulation.
Post 08 Mar 2011, 19:19
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Mar 2011, 07:25
BOTOKILLER wrote:
Hi everyone,
Its me again. I rewrote my code... but it doesnt works...
New code (and topic!) but same result Smile

Code:
  ORG 7C00h

  USE16

  CLI
  lgdt [cs:GDT_DESC] ; can be written before "CLI". Do you know what value cs holds? I don't. Maybe 7C0h or something else

  mov eax, cr0
  bts eax, 0h ; "or al, 1" is more compact and effective
  mov cr0, eax

  USE32
  jmp 08h:anarchy ; should be written before "USE32" but it should be kept 32-bit (with prefix). Add word "pword" or "fword"
anarchy:
  mov ax, 10h
  mov ss, ax
  mov ds, ax
  mov esp, 90000h ; it is better to put it directly after "mov ss, ax"

  mov byte [0B8002h], 'H' ; are you sure that videobuffer starts at 0B8000h? Add "mov ax, 3" and "int 10h" before "CLI" for more reliability
  mov byte [0B8003h], 01Fh


  times 1890 db 0 ; wow! Replace it with "jmp $" and add "rb 83FEh-$" under boot signature

GDT_DESC:
  dw GDT_ENDS - GDT_STARTS ; and minus 1
  dq GDT_STARTS ; "dd" still enough Smile

; "align 8" could be useful here
GDT_STARTS:

  dq 0h

  dw 0FFFFh
  dw 0h
  db 0h
  db 10011010b
  db 11001111b
  db 0h

  dw 0FFFFh
  dw 0h
  db 0h
  db 10001001b ; it is not 92h!!!
  db 11001111b
  db 0h
GDT_ENDS:

; put here that I said above
  dw 0xAA55    
Post 09 Mar 2011, 07:25
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 09 Mar 2011, 09:04
egos wrote:
BOTOKILLER wrote:
Hi everyone,
Its me again. I rewrote my code... but it doesnt works...
New code (and topic!) but same result Smile

Code:
  ORG 7C00h

  USE16

  CLI
  lgdt [cs:GDT_DESC] ; can be written before "CLI". Do you know what value cs holds? I don't. Maybe 7C0h or something else

  mov eax, cr0
  bts eax, 0h ; "or al, 1" is more compact and effective
  mov cr0, eax

  USE32
  jmp 08h:anarchy ; should be written before "USE32" but it should be kept 32-bit (with prefix). Add word "pword" or "fword"
anarchy:
  mov ax, 10h
  mov ss, ax
  mov ds, ax
  mov esp, 90000h ; it is better to put it directly after "mov ss, ax"

  mov byte [0B8002h], 'H' ; are you sure that videobuffer starts at 0B8000h? Add "mov ax, 3" and "int 10h" before "CLI" for more reliability
  mov byte [0B8003h], 01Fh


  times 1890 db 0 ; wow! Replace it with "jmp $" and add "rb 83FEh-$" under boot signature

GDT_DESC:
  dw GDT_ENDS - GDT_STARTS ; and minus 1
  dq GDT_STARTS ; "dd" still enough Smile

; "align 8" could be useful here
GDT_STARTS:

  dq 0h

  dw 0FFFFh
  dw 0h
  db 0h
  db 10011010b
  db 11001111b
  db 0h

  dw 0FFFFh
  dw 0h
  db 0h
  db 10001001b ; it is not 92h!!!
  db 11001111b
  db 0h
GDT_ENDS:

; put here that I said above
  dw 0xAA55    

thanks, it seems to work(no error message), at least for now=), i think problem was there:
Code:
jmp 08h:anarchy    

i corrected it like this
Code:
jmp fword 08h:anarchy    


and what about debugger?????????
olydbg couldnt debug bin file, any other debuggers for windows??
Post 09 Mar 2011, 09:04
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4332
Location: Now
edfed 09 Mar 2011, 14:11
Teehee wrote:
i will highlight some mistakes, but I'm noob, so do not believe me too much:


helping others, and try to find mistakes in the code from others it is a very good way to learn. Smile
Post 09 Mar 2011, 14:11
View user's profile Send private message Visit poster's website Reply with quote
Coty



Joined: 17 May 2010
Posts: 553
Location: ␀
Coty 09 Mar 2011, 14:39
BOTOKILLER wrote:
and what about debugger?????????
olydbg couldnt debug bin file, any other debuggers for windows??

I believe Bochs emulator has built in debug? I would not know to much as I never use debugers Smile

_________________
http://codercat.org/
Post 09 Mar 2011, 14:39
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 09 Mar 2011, 15:17
Quote:
lgdt [cs:GDT_DESC] ; can be written before "CLI". Do you know what value cs holds? I don't. Maybe 7C0h or something else

You do not care. Your code must be position independent.
you address GDT_DESC using a register + displacement. Use near call to get offset, and cs to get cs.

it should be like this:
Code:
;here bios start executing ur bootsector
call near _code
IDT:
dw ?
dd ?
GDT:
dw ?
dd ?
_code:
pop bx
lgdt [cs:bx + 6]
lidt [cs:bx]

...
    


Code:
bts eax, 0h ; "or al, 1" is more compact and effective     

bt* suck, not avaiable on 8086. use or/and instead.

Code:
  mov ax, 10h
  mov ss, ax
  mov ds, ax
  mov esp, 90000h ; it is better to put it directly after "mov ss, ax"     

no, its retarded to put it anywhere else. Even with clear IF you can still get NMI or exception.
Post 09 Mar 2011, 15:17
View user's profile Send private message Reply with quote
poupougne



Joined: 04 May 2007
Posts: 15
Location: Lyon, France
poupougne 09 Mar 2011, 16:13
I already debug with Bochs built-in debugger, and that was helpfull !
Post 09 Mar 2011, 16:13
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Mar 2011, 16:21
b1528932 wrote:
Quote:
lgdt [cs:GDT_DESC] ; can be written before "CLI". Do you know what value cs holds? I don't. Maybe 7C0h or something else

You do not care. Your code must be position independent.
It is not necessary. I meant to do something like this:
Code:
  xor ax,ax
  mov ds,ax
  lgdt [GDTR]
    

_________________
If you have seen bad English in my words, tell me what's wrong, please.
Post 09 Mar 2011, 16:21
View user's profile Send private message Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 13 Mar 2011, 09:07
YEAH!!!!
I MADE IT!!
the problem was there:
Code:
    lea eax, [GDT_DESC]
             lgdt [eax]     

it just couldnt load GDTR without effective address
i found debugger in VirtualBox, here what it writes:
VirtualBox wrote:
VBoxDbg> dg
0008 CodeER Bas=00000000 Lim=fffff000 DPL=0 P NA G BIG AVL=0 L=0
0010 DataRW Bas=00000000 Lim=fffff000 DPL=0 P NA G BIG AVL=0 L=0
Post 13 Mar 2011, 09:07
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.