flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Jumping to new file CD Bootloader

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
AnonymousUser



Joined: 25 Jul 2014
Posts: 32
AnonymousUser
I just did this to update the LBA of the file at Least I think this is what I am supposed to be doing :
Code:
        
        LEA EAX, [ES:DI]
        MOV DWORD[DiskAddressPacket.End],EAX
    

Instead of this:
Code:
        MOV WORD[DiskAddressPacket.Segment], ES
        MOV WORD[DiskAddressPacket.Offset], DI
    

But it won't work it just kinda freezes and executes garbage code I have a a screen shot attached


Description:
Filesize: 7.38 KB
Viewed: 1840 Time(s)

Zeroth10.png



_________________
Thanks in advance
Post 06 Aug 2014, 02:40
View user's profile Send private message Reply with quote
AnonymousUser



Joined: 25 Jul 2014
Posts: 32
AnonymousUser
Never mind it works if you do this:
Code:
        a32 
        LEA EAX, [ES:DI]
        MOV DWORD[DiskAddressPacket.End],EAX
        a16
    

But it still won't jump to the file and execute the code Any Ideas why?

_________________
Thanks in advance
Post 06 Aug 2014, 03:45
View user's profile Send private message Reply with quote
AnonymousUser



Joined: 25 Jul 2014
Posts: 32
AnonymousUser
I fixed it, now it works and goes to the next stage
Post 06 Aug 2014, 07:55
View user's profile Send private message Reply with quote
AnonymousUser



Joined: 25 Jul 2014
Posts: 32
AnonymousUser
Ok so I know this isn't part of this question but I might as well ask it here:
After I move onto the second stage I try to enter protected mode and what happens is that It crashes when I try and make the jump to the protected mode here is what I have done:
Code:
main:           
;first stage of bootloader is loaded at the address 0x07c0:0x0FFFE
        ;second stage of bootloader is loaded at address 0x9000:0x0FFFF
        
        
        cli
        mov ax, 0x200   ;adjust the segment registers
        mov ds, ax
        mov gs, ax
        mov fs, ax


Create_Stack:
        xor ax, ax
        mov es, ax
        mov ss, ax
        mov sp ,0x0FFFF
        sti

        mov [CDDriveNumber], dl
        
        
        
        
        call clear
        Print LOAD_SUCCESS, TEAL
        call Print_ln
        
        SwitchToProtectedMode:
        cli
        lgdt [GDT]

        
        mov eax, cr0
        or eax, 1
        mov cr0, eax
        
        
        ;enable 32 bit mode
        jmp 0x8:Protected_Mode
        
        [BITS 32]
        
        Protected_Mode:
        ;set up stack
        xor ax, ax
        MOV   AX, 0x10 ; 0x10 points at the new data selector
        MOV   DS, AX
        MOV   ES, AX
        MOV   FS, AX
        MOV   GS, AX
        MOV   SS, AX
        MOV ESP, 0x900000
        mov edi, VIDEO_MEM
        mov BYTE[edi], 'A'
        mov BYTE[edi+1], TEAL
        
        cli
        hlt
        

        
Entered_PMODE: db "YOu have succcessfully entered Protected Mode Very Happy", 0
LOAD_SUCCESS:   db "Stage 2 Loaded Successfully",0
CDDriveNumber:  db 0
GDT_START:
;null descriptor
dd 0
dd 0
;data descriptor
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
;code descriptor
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
GDT_END:


GDT:
dw GDT_END - GDT_START - 1
dd GDT_START


    

I was looking at the disassembly of the code and It looks like it jumps but it doesent stop after the cli hlt Why would that be???
here it is :
Code:
00005000  EA86000002        jmp word 0x200:0x86
00005005  0000              add [bx+si],al
00005007  60                pushaw
00005008  8A360600          mov dh,[0x6]
0000500C  B402              mov ah,0x2
0000500E  B700              mov bh,0x0
00005010  FEC6              inc dh
00005012  B200              mov dl,0x0
00005014  CD10              int 0x10
00005016  88360600          mov [0x6],dh
0000501A  C606050000        mov byte [0x5],0x0
0000501F  61                popaw
00005020  C3                ret
00005021  EB0C              jmp short 0x502f
00005023  F7D8              neg ax
00005025  50                push ax
00005026  B02D              mov al,0x2d
00005028  B40E              mov ah,0xe
0000502A  CD10              int 0x10
0000502C  58                pop ax
0000502D  EB0A              jmp short 0x5039
0000502F  31DB              xor bx,bx
00005031  B90A00            mov cx,0xa
00005034  83F800            cmp ax,byte +0x0
00005037  7CEA              jl 0x5023
00005039  31D2              xor dx,dx
0000503B  F7F1              div cx
0000503D  52                push dx
0000503E  43                inc bx
0000503F  85C0              test ax,ax
00005041  75F6              jnz 0x5039
00005043  58                pop ax
00005044  83C030            add ax,byte +0x30
00005047  B40E              mov ah,0xe
00005049  CD10              int 0x10
0000504B  4B                dec bx
0000504C  83FB00            cmp bx,byte +0x0
0000504F  75F2              jnz 0x5043
00005051  C3                ret
00005052  B409              mov ah,0x9
00005054  B90100            mov cx,0x1
00005057  AC                lodsb
00005058  84C0              test al,al
0000505A  740C              jz 0x5068
0000505C  CD10              int 0x10
0000505E  B402              mov ah,0x2
00005060  B700              mov bh,0x0
00005062  FEC2              inc dl
00005064  CD10              int 0x10
00005066  EBEA              jmp short 0x5052
00005068  C3                ret
00005069  B40F              mov ah,0xf
0000506B  B000              mov al,0x0
0000506D  CD10              int 0x10
0000506F  B400              mov ah,0x0
00005071  CD10              int 0x10
00005073  B402              mov ah,0x2
00005075  B701              mov bh,0x1
00005077  B600              mov dh,0x0
00005079  B200              mov dl,0x0
0000507B  CD10              int 0x10
0000507D  88360600          mov [0x6],dh
00005081  88160500          mov [0x5],dl
00005085  C3                ret
00005086  FA                cli
00005087  B80002            mov ax,0x200
0000508A  8ED8              mov ds,ax
0000508C  8EE8              mov gs,ax
0000508E  8EE0              mov fs,ax
00005090  31C0              xor ax,ax
00005092  8EC0              mov es,ax
00005094  8ED0              mov ss,ax
00005096  BCFFFF            mov sp,0xffff
00005099  FB                sti
0000509A  88164601          mov [0x146],dl
0000509E  E8C8FF            call word 0x5069
000050A1  60                pushaw
000050A2  31C0              xor ax,ax
000050A4  31D2              xor dx,dx
000050A6  8A360600          mov dh,[0x6]
000050AA  8A160500          mov dl,[0x5]
000050AE  31DB              xor bx,bx
000050B0  B303              mov bl,0x3
000050B2  BE2A01            mov si,0x12a
000050B5  E89AFF            call word 0x5052
000050B8  88160500          mov [0x5],dl
000050BC  61                popaw
000050BD  E847FF            call word 0x5007
000050C0  FA                cli
000050C1  0F01165F01        lgdt [0x15f]
000050C6  0F20C0            mov eax,cr0
000050C9  6683C801          or eax,byte +0x1
000050CD  0F22C0            mov cr0,eax
000050D0  EAD5000800        jmp word 0x8:0xd5;the jump 
;setting up the stack
000050D5  6631C0            xor eax,eax
000050D8  66B810008ED8      mov eax,0xd88e0010
000050DE  8EC0              mov es,ax
000050E0  8EE0              mov fs,ax
000050E2  8EE8              mov gs,ax
000050E4  8ED0              mov ss,ax
000050E6  BC0000            mov sp,0x0
000050E9  90                nop
000050EA  00BF0080          add [bx-0x8000],bh
000050EE  0B00              or ax,[bx+si]
000050F0  C60741            mov byte [bx],0x41
000050F3  C6470103          mov byte [bx+0x1],0x3
000050F7  FA                cli   ;clear interrupts and halts
000050F8  F4                hlt
;doesent halt WHy????
000050F9  59                pop cx
000050FA  4F                dec di
000050FB  7520              jnz 0x511d
000050FD  686176            push word 0x7661
00005100  65207375          and [gs:bp+di+0x75],dh
00005104  636363            arpl [bp+di+0x63],sp
00005107  657373            gs jnc 0x517d
0000510A  66756C            o32 jnz 0x5179
0000510D  6C                insb
0000510E  7920              jns 0x5130
00005110  656E              gs outsb
00005112  7465              jz 0x5179
00005114  7265              jc 0x517b
00005116  64205072          and [fs:bx+si+0x72],dl
0000511A  6F                outsw
0000511B  7465              jz 0x5182
0000511D  637465            arpl [si+0x65],si
00005120  64204D6F          and [fs:di+0x6f],cl
00005124  6465203A          and [gs:bp+si],bh
00005128  44                inc sp
00005129  005374            add [bp+di+0x74],dl
0000512C  61                popaw
0000512D  67652032          and [gs:edx],dh
00005131  204C6F            and [si+0x6f],cl
00005134  61                popaw
00005135  646564205375      and [fs:bp+di+0x75],dl
0000513B  636365            arpl [bp+di+0x65],sp
0000513E  7373              jnc 0x51b3
00005140  66756C            o32 jnz 0x51af
00005143  6C                insb
00005144  7900              jns 0x5146
00005146  0000              add [bx+si],al
00005148  0000              add [bx+si],al
0000514A  0000              add [bx+si],al
0000514C  0000              add [bx+si],al
0000514E  00FF              add bh,bh
00005150  FF00              inc word [bx+si]
00005152  0000              add [bx+si],al
00005154  9ACF00FFFF        call word 0xffff:0xcf
00005159  0000              add [bx+si],al
0000515B  0092CF00          add [bp+si+0xcf],dl
0000515F  17                pop ss
00005160  004701            add [bx+0x1],al
00005163  0000              add [bx+si],al
    

_________________
Thanks in advance
Post 06 Aug 2014, 18:11
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
I am not home to look over what I have done, but I think you also need to initiate an IVT, you needs to at least setup the first so many (I can't recall how many) so that if you encounter general purpose faults you can adjust to them.
Post 07 Aug 2014, 16:34
View user's profile Send private message Reply with quote
AnonymousUser



Joined: 25 Jul 2014
Posts: 32
AnonymousUser
I fixed it but I think I should set up an IVT soon here is what I did:
Code:
[BITS 16]
org 0x2000

Start:

 jmp  main
;;;;;;;;;;;;;;;;;;
;                                ;
;                                ;
;    Constants   ;
;                                ;
;;;;;;;;;;;;;;;;;;
%DEFINE TEAL 0x03
%DEFINE RED 0x04
%DEFINE PURPLE 0x05
%DEFINE VIDEO_MEM 0xB8000
%DEFINE COLS    80                      ; width and height of screen
%DEFINE LINES   25


X_POS:  db 0
Y_POS:  db 0


;;;;;;;;;;;;;;;;;;
;    Enabling    ;
;    The A20     ;
;         line           ;
;;;;;;;;;;;;;;;;;;
EnableA20:

in al, 0x92
or al, 2
out 0x92, al

ret



        



main:           
;first stage of bootloader is loaded at the address 0x07c0:0
        ;second stage of bootloader is loaded at address 0x200:0x0
        
        
        cli
   xor ax, ax         ; All segments set to 0, flat memory model
   mov ds, ax
   mov es, ax
   mov gs, ax
   mov fs, ax
   mov ss, ax
   ;
   ; Set stack top SS:0xffff
   ;
   mov sp, 0x0FFFF
   ;


        mov [CDDriveNumber], dl
        
        SwitchToProtectedMode:
        
        lgdt [GDT];load the gdt
        call EnableA20
        
  
        
        mov eax, cr0
        or eax, 1
        mov cr0, eax
        
        
         ; Flush CS and set code selector
   ;
        jmp 0x8:Protected_Mode
        
        [BITS 32];Declare 32 bits
        
        Protected_Mode:
        
        
        
        ;set up segment registers
        XOR   AX, AX
        MOV   AX, 0x10 
        MOV   DS, AX
        MOV   ES, AX
        MOV   FS, AX
        MOV   GS, AX
        MOV   SS, AX
        MOV   ESP, 0x900000
        
        
        
        ;prints an A to the top of the screen
        
        call clear
        
        
        xor bx, bx
        
        mov bx, LOAD_SUCCESS
        call sPrint
        
        mov bx, Entered_PMODE
        call sPrint
        
        SwitchToLongMode:
        
        
        
        
        
        
        
        
        
        
        
        cli
        hlt
        
        clear:
        
        pusha
        mov edi, VIDEO_MEM
        mov BYTE[edi], ' '
        mov BYTE[edi+1], 14
        rep stosw
        MOV BYTE[X_POS], 0x0
        MOV BYTE [Y_POS], 0x0
        popa
        ret
        
        sPrint:
        pusha
                jmp .start
                .Row:
                call NewLine
                MOV BYTE[EDI], ' '
                jmp .Next
                .start:
                MOV EDI, VIDEO_MEM
                xor ecx, ecx
                xor eax, eax
                mov     ecx, COLS*2             ; Mode 7 has 2 bytes per char, so its COLS*2 bytes per line
                mov     al, BYTE [Y_POS]        ; get y pos
                mul     ecx                     ; multiply y*COLS
                push    eax                     ; save eax--the multiplication
                 
                mov     al, byte [X_POS]        ; multiply _CurX by 2 because it is 2 bytes per char
                mov     cl, 2
                mul     cl
                pop     ecx                     ; pop y*COLS result
                add     eax, ecx
                
                
                add edi, eax
                mov al,BYTE[bx]
                
                cmp al, 0x0;check if end
                je .Done
                cmp al, 0xA;check if new line
                je .Row
                
                mov BYTE[edi],al 
                .Next:
                mov BYTE[edi+1], TEAL
                INC BX
                inc     BYTE[X_POS]             ; go to next character
                cmp     BYTE[X_POS], COLS               ; are we at the end of the line?
                je      .Row                    ; yep-go to next row
                
                
                jmp .start
        .Done:
        
        
        popa
        
        ret
        NewLine:
        inc BYTE[Y_POS]
        MOV BYTE[X_POS], -1
        
        ret
        
Entered_PMODE:  db "You have succcessfully entered Protected Mode Very Happy",0xA, 0
LOAD_SUCCESS:   db "Stage 2 Loaded Successfully",0xA, 0
CDDriveNumber:  db 0



GDT_START:
;null descriptor
dd 0
dd 0
;data descriptor
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
;code descriptor
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
GDT_END:
align 4
GDT:
dw GDT_END - GDT_START - 1
dd GDT_START
    
Post 07 Aug 2014, 16:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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.