flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Protected mode jump

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 06 Mar 2011, 16:40
Hi everyone!
Im developping my own OS and ive just made protected mode jump from bootloader. But i cant make this code output a line of text on screen. here is the code:

Code:
  org 0x7C00

        cli
        BOOTING:
        mov bx, HelloMessage
        mov di, 81d
        mov ah, 0Eh


        WELCOME:                       ; procedure that writes hello message
        mov al, [cs:bx+di]
        int 10h
        dec di
        jnz WELCOME


        READCD:
        xor ax, ax

        call PMODEJMP
        call LOADGDT
        call CLS
        call OUTHELLO
        call FINDPCIE
        call READSATA


        NOTHING:
        nop
        jmp NOTHING


        READSATA: ;TO DO
        ret


        FINDPCIE: ;TO DO

        ret


        LOADGDT:
        mov dword eax, [GDT_REC0]
        mov dword [00100000h], eax
        mov dword eax, [GDT_REC0_1]
        mov dword [00100004h], eax
        mov dword eax, [GDT_REC1]
        mov dword [00100008h], eax
        mov dword eax, [GDT_REC1_1]
        mov dword [00100000Ch], eax
        mov dword eax, [GDT_REC2]
        mov dword [001000010h], eax
        mov dword eax, [GDT_REC2_1]
        mov dword [001000014h], eax
        ret



         CLS:
         mov ebx, 0B8000h
         mov ecx, 7D0h
         mov al, ' '
         mov ah, 01Fh
         CLNSCR:
         lea edx, [ebx+ecx*2]
         mov [edx], ax
         dec ecx
         jnz CLNSCR
         ret

;this is the code that doesnt works. note: some code comments may not express what it really does 

        OUTHELLO:                ; nothing very usefull, just Hello! message, so i can now that nothing failed during Pmode jump
        mov al, 'H'
        mov ah, 1Fh
        mov edx, 0B8000h
        mov ax, 0h
        mov cx, 0h
        mov edx, PModemsg
        mov bx, 33d
        call OutLINE
        mov ax, 2h
        mov cx, 3h
        mov edx, ScanPCImsg
        mov bx, 33d
        call OutLINE

        ret


        OutLINE:              ;IN: ax-line, cx-starting coulumn, EDX-startline address, BX- number of symbols
        STS:
        pusha
        add cx, bx            ; CX is ready to go now
        add edx, ebx
        pusha
        mov bl, [edx]
        mov bh, 1Fh
        call OUTSYMB
        popa
        popa
        dec bx
        jnz STS


        ret


        OUTSYMB:    ; bl - symbol, bh-parameters, ax-line, cx-coulumn
        push bx
        mov bx, 50h
        mul bx
        add bx, cx
        mov edx, ebx
        add edx, edx
        add edx, 0B8000h
        pop bx
        mov [edx], bx
        ret


; here it ends(the code wich bothers me)

        PMODEJMP:

        mov ax, 0x2401
        int 0x15               ; enabling A20 line

        CLI                    ; clearing interrupts
        mov bx, GDT_ADDRESS    ; loading GDTR
        lgdt [cs:bx]
        MOV EAX, CR0
        bts ax, 0h
        MOV CR0, EAX           ; Protected Mode!
        ret


        times 1591 db 0

        GP dw 2h

        CP dd 0h

        HelloMessage db ' edoM detcetorP eht ot gnipmuJ', 0Dh, 0Ah,  '.....SO gnitooB', 0Dh, 0Ah, 'redaoltooB 10.0 SOSN ot emocleW' ;47 symbols total  +32

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

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

        GDT_ADDRESS dw 0010h
                    dd 0000h, 0010h

        GDT_REC0    dd 0h
        GDT_REC0_1  dd 0h
                             ; '       '       '
        GDT_REC1    dd 00000000110011111111101000000000b   ; "'" - upon the 1st bit of next byte
        GDT_REC1_1  dd 0000FFFFh
                              ;'       '       '
        GDT_REC2    dd 00000000110011111110101000000000b
        GDT_REC2_1  dd 0000FFFFh                           ; BASE:FLAGS-LIMIT:ACCESSREG:BASE:BASE:BASE:LIMIT:LIMIT
                              ;'       '       '
        GDT_REC3    dd 00000000110000001001101000000000b  ;TO DO
        GDT_REC3_1  dd 7C000000h                                          ;TO DO

        dw 0xAA55         


and one more thing, if you can, please say am i correct in protected mode jump and gdt loading?
[/b]
Post 06 Mar 2011, 16:40
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 06 Mar 2011, 17:03
ignore this.


Last edited by Teehee on 06 Mar 2011, 17:19; edited 1 time in total
Post 06 Mar 2011, 17:03
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 06 Mar 2011, 17:19
Hey, you are doing cli and then doing an int. That can't work Very Happy

[edit:]its me or you really have a weird code? Shocked

_________________
Sorry if bad english.
Post 06 Mar 2011, 17:19
View user's profile Send private message Reply with quote
Coty



Joined: 17 May 2010
Posts: 553
Location: ␀
Coty 06 Mar 2011, 18:02
Well First I see this.
Code:
        xor ax, ax 

        call PMODEJMP <<<< DONT CALL PM JUMP!!! Calling from real mode and retrurning in PM could screw up as they use different addressing!
        call LOADGDT 
        call CLS 
    

And then I see;
Code:
        PMODEJMP: 

        mov ax, 0x2401 
        int 0x15               ; enabling A20 line 

        CLI    PMODEJMP                ; clearing interrupts 
        mov bx, GDT_ADDRESS    ; loading GDTR 
        lgdt [cs:bx] 
        MOV EAX, CR0 
        bts ax, 0h 
        MOV CR0, EAX           ; Protected Mode! 
        ret                        << ??? SHOULD YOU NOT DO A LONG JUMP HERE ???
    


Acording to the intel i386 manuel you have to do a long jump that points CS to your code selector. eg.

Code:
JMP 0x0008:_PM

_PM:
     ; We in PM now.    


Were do you tell FASM to generate 32bit code?
Code:
use32    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

teehee wrote:
Hey, you are doing cli and then doing an int. That can't work

AFAIK A software generated int is OK, those wont be ignored, there kinda like forced ints. but those generated by PIC will be ignored by CLI.

_________________
http://codercat.org/


Last edited by Coty on 06 Mar 2011, 22:08; edited 1 time in total
Post 06 Mar 2011, 18:02
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman 06 Mar 2011, 18:28
You loaded up an address into bx, but bx gets used for other things by the int10 function you called:

AH = 0Eh
AL = character to write
BH = page number
BL = foreground color
Post 06 Mar 2011, 18:28
View user's profile Send private message Visit poster's website Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 07 Mar 2011, 04:46
Coty wrote:
Well First I see this.
Code:
        xor ax, ax 

        call PMODEJMP <<<< DONT CALL PM JUMP!!! Calling from real mode and retrurning in PM could screw up as they use different addressing!
        call LOADGDT 
        call CLS 
    

And then I see;
Code:
        PMODEJMP: 

        mov ax, 0x2401 
        int 0x15               ; enabling A20 line 

        CLI    PMODEJMP                ; clearing interrupts 
        mov bx, GDT_ADDRESS    ; loading GDTR 
        lgdt [cs:bx] 
        MOV EAX, CR0 
        bts ax, 0h 
        MOV CR0, EAX           ; Protected Mode! 
        ret                        << ??? SHOULD YOU NOT DO A LONG JUMP HERE ???
    


Acording to the intel i386 manuel you have to do a long jump that points CS to your code selector. eg.

Code:
JMP 0x0008:_PM

_PM:
     ; We in PM now.    


Were do you tell FASM to generate 32bit code?
Code:
use32    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

teehee wrote:
Hey, you are doing cli and then doing an int. That can't work

AFAIK A software generated int is OK, those wont be ignored, there kinda like forced ints. but those generated by PIC will be ignored by CLI.

damn, it looks like i'll have to rewrite my code completely
Post 07 Mar 2011, 04:46
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 08 Mar 2011, 00:31
Coty wrote:
teehee wrote:
Hey, you are doing cli and then doing an int. That can't work
AFAIK A software generated int is OK, those wont be ignored, there kinda like forced ints. but those generated by PIC will be ignored by CLI.
Someone said to me that INT does not work Sad

[edit:] i put a cli in the first line of my boot and it worked normaly. I think you'r right. Smile

_________________
Sorry if bad english.
Post 08 Mar 2011, 00:31
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.