flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Halp!)

Author
Thread Post new topic Reply to topic
BOTOKILLER



Joined: 07 Jan 2011
Posts: 154
Location: Ukraine
BOTOKILLER
Hi everyone Exclamation
The following code has been working successfuly until today
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 1h          ;11h

        DAT:
        DAT_Disk_Num         db 80h         ;12h          number of device 80h-winchester
        DAT_Num_Of_Sects     dw 8h          ;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 0067h         ;TSS
                    dw 0800h
                    db 0h
                    db 10010010b
                    db 01000000b
                    db 0h
        GDT_REC4    dw 0198h         ;System data segment - for storing system data ROM
                    dw 0868h
                    db 0h
                    db 11110000b
                    db 01000000b
                    db 0h
        GDT_REC5    dw 03FFh         ;IDT ROM
                    dw 0A00h
                    db 0h
                    db 11110000b
                    db 01000000b
                    db 0h
        GDT_REC6    dw 01FFh         ;SYSTEM STACK
                    dw 0E00h
                    db 0h
                    db 10010010b
                    db 01000000b
                    db 0h
        GDT_REC7    dw 0FA00h         ;(interrupts)
                    dw 1000h
                    db 0h
                    db 10011110b
                    db 01001001b
                    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
        jc ERROR                               ;jmp there on error
        popa                                   ;restore registers
        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
        mov eax, 80000008h
        cpuid
        mov [es:14h], eax
        ;Maybe will be more, so.........

        PMODEJMP:
        cli

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

        lea eax, [cs:GDT_DESC-START1+1h]                              ;GDT_DESC-START1+9FA00h
        lgdt [eax]

        mov eax, cr0
        or eax, 1
        mov cr0, eax
        jmp pword 08h:THEMODEP-START1+9FA01h                          ;to count address in bootloader do that - DESTINATION_LABEL-START1+9FA01h


        USE32

        THEMODEP:

        SEG_REG_SET:
        mov sp, 10h
        mov ds, sp
        mov fs, sp
        mov gs, sp
        mov ss, sp
        mov esp, 3071d
        mov ax, 28h
        mov es, ax


        ; __________________________________________________________________
        ;| MOVING GDT TO ITS WORKING LOCATION AT PHYSICAL ADDRESS 00000006h |
        ;|__________________________________________________________________|
        MOVGDT2WORKLOCATION:
        mov word [ds:0000h], 64d
        mov dword [ds:0002h], 6d
        mov ebp, GDT_STARTS-START1+9FA01h
        mov esi, 6d
        mov ecx, 64d
        call MOVE32
        lea eax, [ds:0000h]
        lgdt [eax]

        PASSING_CONTROL:;the place where the shit happens
        jmp 0A00h






        HAPPY_END:
        nop
        jmp HAPPY_END

        MOVE32:
        mov al, [ds:ebp+ecx-1]
        mov [ds:esi+ecx-1], al
        loop MOVE32
        ret



        times 148 db 0
        dw 0AA55h          

Kernel is located inside of 2 segments after bootloader(1 and 2 segment)
My debugger shows that problem is somewhere in the place where it loads kernel into memory - the kernel just doesnt gets loaded into memory.
The question is - Why?

*Note: the part that loads kernel worked before

_________________
_______________________________
NSOS
Post 16 May 2011, 16:53
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.