flat assembler
Message board for the users of flat assembler.

Index > OS Construction > PMODE PROBLEM

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER
Hi everyone!
I have almost made a bootloader, but problem occured whikle pmode jump
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 0h          ;6h
        DAP_Buff_Addr2       dw 80h          ;8h
        DAP_LBA              dq 2049h          ;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        ;kernel code segment           ;23h
                    dw 0h
                    db 0h
                    db 10011010b
                    db 11001111b
                    db 0h
        GDT_REC2    dw 0FFFFh        ;kernel data segment           ;2Bh
                    dw 0h
                    db 0h
                    db 10010010b
                    db 11001111b
                    db 0h
        GDT_REC3    dw 0A00h         ;System data segment - for storing system data
                    dw 800h
                    db 0h
                    db 11110000b
                    db 01000000b
                    db 0h
        GDT_ENDS:

        ERROR:
        jmp ERROR

        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:
        push ds
        push JUMP_POINT - START1 + 1
        retf

        JUMP_POINT:

        mov bp, 80h                            ;loading
        mov es, bp                             ;es with 810h, so I can access sectors that were read from HD
        mov bp, 1h                             ;loading base pointer with adderss of start of code, so I can access data easily

        READ_HD:                               ;READ_HD - procedure that reads amount of sectors specified in DAT_Num_Of_Sects to es:0h
        mov ah, 42h                            ;function num - 42h
        xor al, al                             ;al =0
        mov dl, [cs:bp+12h]                    ;loading number of drive(80h by default)
        mov si, cs                             ;loading
        mov ds, si                             ;ds with segment, where our code is
        mov si, DAP - START1 + 1               ;loading si to point to the DAP
        mov word cx, [cs:bp+13h]               ;loading cx with number of sectors to read

        RHD_LOOP:                              ;loop which reads sectors
        pusha                                  ;save all registers
        int 13h                                ;call int 13h with parameters selected above
        popa                                   ;restore registers
        jc ERROR                               ;jmp there on error
        add word [ds:si+8h], 20h               ;next time it will write 512 bytes further
        inc word [ds:si+11h]                   ;incrementing lba of sector to read
        loop RHD_LOOP                          ;doing it amount of times specified in cx

        DETECT_MEMORY:                         ;detecting highest address in memory
        mov ax, 0E801h                         ;loading ax with function number
        pusha                                  ;save all registers
        int 15h                                ;calling int 15h
        jc ERROR                               ;if error jmp to error
        xchg ax, bx                            ;ax = bx, bx = ax
        mov bx, 0FFFFh                         ;amount of high memoty is give in 64k blocks, so, I need to multiply it by amount of bytes in 64k block
        mul bx                                 ;
        shl edx, 10h                           ;part of result is placed into dx
        add eax, edx                           ;so, I combine ax and dx
        add eax, 0FFFFFFh                      ;I dont expect systems with less than 16mb of memory
        mov dword [es:0h], eax                 ;placing this data to os config space

        COLLECT_OTHER_DATA:
        xor eax, eax
        cpuid
        mov [es:4h], ecx
        mov eax, 1h
        cpuid
        mov [es:8h], eax
        mov eax, 80000001h
        cpuid
        mov [es:0Ah], edx
        mov [es:10h], ecx
        ;Maybe will be more, so.........

        PMODEJMP:

        mov ax, 0x2401                         ;function num
        int 0x15                               ;Damn A20 line

        lea eax, [GDT_DESC]
        lgdt [eax]

        mov eax, cr0
        or eax, 1
        mov cr0, eax
        jmp pword 08h:THEMODEP-START1+9FA01h  ; i think the problem is here

        USE32
        THEMODEP:
        sti



        HAPPY_END:
        nop
        jmp HAPPY_END

        times 291 db 0
        dw 0AA55h  
    

as you can see, i cant use label directly because i moved my bootloader to high memory location(the first byte of code is 9FA0h:0001h)
what to do ?
how to solve it?
Post 20 Apr 2011, 15:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Remove the "+ 1".
Code:
        push JUMP_POINT - START1 ;+ 1
    
Post 20 Apr 2011, 15:16
View user's profile Send private message Visit poster's website Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER
revolution wrote:
Remove the "+ 1".
Code:
        push JUMP_POINT - START1 ;+ 1
    


no, its allright there but the thing which doesnt work is pmode jump
Post 20 Apr 2011, 15:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Remove the "+ 1" from all places:
Code:
        mov si, DAP - START1 ;+ 1               ;loading si to point to the DAP
;...
        jmp pword 08h:THEMODEP-START1+9FA00h  ;9fa00    
Post 20 Apr 2011, 16:23
View user's profile Send private message Visit poster's website Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER
revolution wrote:
Remove the "+ 1" from all places:
Code:
        mov si, DAP - START1 ;+ 1               ;loading si to point to the DAP
;...
        jmp pword 08h:THEMODEP-START1+9FA00h  ;9fa00    

omg, its +1h because it loads to 9fa0h:0001h
problem is only with PMODEjump(i even tried 9fa00h instead of 9fa01h)
there is no problems with the rest of code
Post 20 Apr 2011, 16:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Did you update the linear address of the GDT?
Code:
                   dd GDT_STARTS                            ;17h    
Post 20 Apr 2011, 17:01
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
By using the offset of + 1 everywhere all your alignments will be out-of-alignment. I would suggest to make your coding job easier to simply remove all the + 1 offsets, then you don't have to worry about things failing later due to some forgotten place where you need + 1 and also having aligned data moving out of alignment.

Surely you don't want to make you job even harder with all the unneeded + 1 stuff, right?

I see I missed one place also:
Code:
        mov bp, $ ;7BFFh    
Post 20 Apr 2011, 17:17
View user's profile Send private message Visit poster's website Reply with quote
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER
revolution wrote:
Did you update the linear address of the GDT?
Code:
                   dd GDT_STARTS                            ;17h    

yes, thats it(didnt tried yet but that is what can be wrong)
Post 21 Apr 2011, 10:56
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos
BOTOKILLER, sorry, but you have done bad work again.

Don't destroy EBDA.
Initialize the stack.
Use "movs" instruction.
Don't allow interrupts until you have done interrupt initialization in PM.
And so on.

Try this sample:
Code:
  relseg equ 60h

  org 7C00h

  xor ax,ax
  cli
  mov ss,ax
  mov sp,$$
  sti

  mov ds,ax
  mov si,relbase
  mov ax,relseg
  mov es,ax
  xor di,di
  push es
  push di
  mov cx,(relsize+1)/2
  cld
  rep movsw
  retf

  align 2
relbase:
  org 0
  ...
  jmp fword 8:Startup32

  org 16*relseg+$
  use32
Startup32:
  ...
  jmp $
  label relsize at $-16*relseg

  org relbase+relsize
  rb 7DFEh-$
  dw 0AA55h
    
Post 21 Apr 2011, 14:27
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.