flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Need help with code

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 16 Apr 2011, 08:01
Hi everyone!
Here is the code:
Code:
 USE16
        ORG 7C00h

        START1:

        jmp START

        DATASECT:

        DAP:
        DAP_Size             db 10h         ;1h
        DAP_Res1             db 0           ;2h
        DAP_Bytes2Transfer   db 1h          ;3h
        DAP_Res2             db 0           ;4h
        DAP_Buff_Addr1       dw 7FFh        ;6h
        DAP_Buff_Addr2       dw 0h          ;8h
        DAP_LBA              dq 1h          ;11h

        DAT:
        DAT_Disk_Num         db 80h         ;12h          number of device 80h-winchester
        DAT_Num_Of_Sects     dw 1h          ;13h          the number of 512byte sectors, that contain your kernel your kernel + 1

        GDT:
        GDT_DESC:
                    dw GDT_ENDS - GDT_STARTS - 1h            ;15h
                    dd GDT_STARTS                            ;17h

        GDT_STARTS:


        GDT_REC0    dq 0h                                    ;1Bh


        GDT_REC1    dw 0FFFFh        ;code segment           ;23h
                    dw 0h
                    db 0h
                    db 10011010b
                    db 11001111b
                    db 0h
        GDT_REC2    dw 0FFFFh        ;data segment           ;2Bh
                    dw 0h
                    db 0h
                    db 10010010b
                    db 11001111b
                    db 0h
        GDT_ENDS:    ;all these are resource that ill need later

        START:

        MOV_:
        mov bp, 9FA0h
        mov ds, bp
        mov bp, 7BFFh
        mov cx, 510d

        MOV_LOOP:
        mov si, cx
        mov al, [cs:bp+si]
        mov [ds:si], al
        loop MOV_LOOP

        CHANGE_PLACE:
        mov bp, JUMP_POINT - START1 + 1
        jmp far [ds:bp]


        JUMP_POINT:

        HAPPY_END:
        nop
        jmp HAPPY_END

        times 429 db 0
        dw 0AA55h                           

It have to move boot sector to high memory location 9FA00h, and jump to execute code in that location, but it fails on CHANGE_PLACE procedure(I checked rest of the code without it and it worked properly)
Why?
Post 16 Apr 2011, 08:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 16 Apr 2011, 10:52
I think the problem is here:
BOTOKILLER wrote:
Code:
jmp far [ds:bp]    
The contents of ds:bp does not contain a far call address, it contains code.

You could try something like this instead:
Code:
push ds ;our new CS
push JUMP_POINT - START1 + 1 ;our new IP
retf    
Post 16 Apr 2011, 10:52
View user's profile Send private message Visit poster's website Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER 16 Apr 2011, 12:29
thanx that worked, but why does fasm shows me an error when I try
Code:
jmp far ds:bp ; without brackets
    
?
Post 16 Apr 2011, 12:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 16 Apr 2011, 14:03
BOTOKILLER wrote:
... but why does fasm shows me an error when I try
Code:
jmp far ds:bp ; without brackets
    
?
The x86 architecture does not have that addressing mode for jmp.
Post 16 Apr 2011, 14:03
View user's profile Send private message Visit poster's website 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.