Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problems with a bootloader

I have a problem.i made a bootloader that loads a number of sectors begining with sector 2 at address 1000h:100h.I use this bootloader to load a code that enters pmode but when i make the far jump to change the CS the CPU resets.
The code works perfect if I don't use the bootloader and gets loaded from the first sector at offset 0x7c00 the problem is when loading the code with the bootloader.

I'll paste the code for the bootloader and the code that is loaded and dosn't work:

This is the bootloader:
[BITS 16]
[ORG 0x7c00]

jmp start

size equ 1

start:

cli
mov ax,0x9000
mov ss,ax
mov sp,0ffffh
sti


mov ah,02h
mov al,size
mov ch,0
mov cl,2
mov dh,0
mov dl,0
mov bx,1000h
mov es,bx
mov bx,100h
int 13h


mov ax,es
mov ds,ax
push ax
mov ax,100h
push ax

mov ah, 00h
mov al, 3h
int 10h

retf



Here is the code:

[BITS 16]
[ORG 0x100]

start:jmp initpmode

;********************************************************
initpmode:xor eax,eax
mov ax,cs
mov ds,ax
mov ah, 00h
mov al, 3h
int 10h

cli
lgdt [gdtr]
mov eax,cr0
or al,0x1
mov cr0,eax
jmp 0x10: protected

[BITS 32]


protected:mov ax,0x8
mov ds,ax
mov es,ax
mov ss,ax
mov esp,0x7C00

mov dx,3F2h
mov al,0
out dx,al

mov word [0xB8000],0x8258
mov ax,0x18
mov es,ax
mov word [es:2],0x8258

jmp $


gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code: dw 0xFFFF, 0x0000, 0x9A00, 0x00CF
sys_video: dw 0x0FA0
dw 0x8000
db 0x0b
db 0x92
db 0x40
db 0
gdt_end:

gdtr: dw gdt_end - gdt - 1
dd gdt

Can you tell me what is wrong?
10x

Comments

  • lateeflateef Posts: 22Member
    : I have a problem.i made a bootloader that loads a number of sectors begining with sector 2 at address 1000h:100h.I use this bootloader to load a code that enters pmode but when i make the far jump to change the CS the CPU resets.
    : The code works perfect if I don't use the bootloader and gets loaded from the first sector at offset 0x7c00 the problem is when loading the code with the bootloader.
    :
    : I'll paste the code for the bootloader and the code that is loaded and dosn't work:
    :
    : This is the bootloader:
    : [BITS 16]
    : [ORG 0x7c00]
    :
    : jmp start
    :
    : size equ 1
    :
    : start:
    :
    : cli
    : mov ax,0x9000
    : mov ss,ax
    : mov sp,0ffffh
    : sti
    :
    :
    : mov ah,02h
    : mov al,size
    : mov ch,0
    : mov cl,2
    : mov dh,0
    : mov dl,0
    : mov bx,1000h
    : mov es,bx
    : mov bx,100h
    : int 13h
    :
    :
    : mov ax,es
    : mov ds,ax
    : push ax
    : mov ax,100h
    : push ax
    :
    : mov ah, 00h
    : mov al, 3h
    : int 10h
    :
    : retf
    :
    :
    :
    : Here is the code:
    :
    : [BITS 16]
    : [ORG 0x100]
    :
    : start:jmp initpmode
    :
    : ;********************************************************
    : initpmode:xor eax,eax
    : mov ax,cs
    : mov ds,ax
    : mov ah, 00h
    : mov al, 3h
    : int 10h
    :
    : cli
    : lgdt [gdtr]
    : mov eax,cr0
    : or al,0x1
    : mov cr0,eax
    : jmp 0x10: protected
    :
    : [BITS 32]
    :
    :
    : protected:mov ax,0x8
    : mov ds,ax
    : mov es,ax
    : mov ss,ax
    : mov esp,0x7C00
    :
    : mov dx,3F2h
    : mov al,0
    : out dx,al
    :
    : mov word [0xB8000],0x8258
    : mov ax,0x18
    : mov es,ax
    : mov word [es:2],0x8258
    :
    : jmp $
    :
    :
    : gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    : sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    : sys_code: dw 0xFFFF, 0x0000, 0x9A00, 0x00CF
    : sys_video: dw 0x0FA0
    : dw 0x8000
    : db 0x0b
    : db 0x92
    : db 0x40
    : db 0
    : gdt_end:
    :
    : gdtr: dw gdt_end - gdt - 1
    : dd gdt
    :
    : Can you tell me what is wrong?
    : 10x
    :

    You loaded your code at linear address 0x00001100 (0x1000:0x0100), right?
    Now look at the line where you have
    jmp 0x10: protected

    You are attempting to jump to some code in a segment with a base linear
    address of 0x00000000 (See your defination of descriptor 0x10). The code
    would definately crash. Define another code descriptor that matches the address your code is loaded to.





  • bogdanul2003bogdanul2003 Posts: 153Member
    : : I have a problem.i made a bootloader that loads a number of sectors begining with sector 2 at address 1000h:100h.I use this bootloader to load a code that enters pmode but when i make the far jump to change the CS the CPU resets.
    : : The code works perfect if I don't use the bootloader and gets loaded from the first sector at offset 0x7c00 the problem is when loading the code with the bootloader.
    : :
    : : I'll paste the code for the bootloader and the code that is loaded and dosn't work:
    : :
    : : This is the bootloader:
    : : [BITS 16]
    : : [ORG 0x7c00]
    : :
    : : jmp start
    : :
    : : size equ 1
    : :
    : : start:
    : :
    : : cli
    : : mov ax,0x9000
    : : mov ss,ax
    : : mov sp,0ffffh
    : : sti
    : :
    : :
    : : mov ah,02h
    : : mov al,size
    : : mov ch,0
    : : mov cl,2
    : : mov dh,0
    : : mov dl,0
    : : mov bx,1000h
    : : mov es,bx
    : : mov bx,100h
    : : int 13h
    : :
    : :
    : : mov ax,es
    : : mov ds,ax
    : : push ax
    : : mov ax,100h
    : : push ax
    : :
    : : mov ah, 00h
    : : mov al, 3h
    : : int 10h
    : :
    : : retf
    : :
    : :
    : :
    : : Here is the code:
    : :
    : : [BITS 16]
    : : [ORG 0x100]
    : :
    : : start:jmp initpmode
    : :
    : : ;********************************************************
    : : initpmode:xor eax,eax
    : : mov ax,cs
    : : mov ds,ax
    : : mov ah, 00h
    : : mov al, 3h
    : : int 10h
    : :
    : : cli
    : : lgdt [gdtr]
    : : mov eax,cr0
    : : or al,0x1
    : : mov cr0,eax
    : : jmp 0x10: protected
    : :
    : : [BITS 32]
    : :
    : :
    : : protected:mov ax,0x8
    : : mov ds,ax
    : : mov es,ax
    : : mov ss,ax
    : : mov esp,0x7C00
    : :
    : : mov dx,3F2h
    : : mov al,0
    : : out dx,al
    : :
    : : mov word [0xB8000],0x8258
    : : mov ax,0x18
    : : mov es,ax
    : : mov word [es:2],0x8258
    : :
    : : jmp $
    : :
    : :
    : : gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
    : : sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
    : : sys_code: dw 0xFFFF, 0x0000, 0x9A00, 0x00CF
    : : sys_video: dw 0x0FA0
    : : dw 0x8000
    : : db 0x0b
    : : db 0x92
    : : db 0x40
    : : db 0
    : : gdt_end:
    : :
    : : gdtr: dw gdt_end - gdt - 1
    : : dd gdt
    : :
    : : Can you tell me what is wrong?
    : : 10x
    : :
    :
    : You loaded your code at linear address 0x00001100 (0x1000:0x0100), right?
    : Now look at the line where you have
    : jmp 0x10: protected
    :
    : You are attempting to jump to some code in a segment with a base linear
    : address of 0x00000000 (See your defination of descriptor 0x10). The code
    : would definately crash. Define another code descriptor that matches the address your code is loaded to.
    :
    :
    :
    :
    :
    :

    I still don't get it.I defined the 0x10 descriptor as haveing the base at 0x00000000 and a limit of 4 GB.Dosen't this mean that it will include the address at which I'm loading my aplication?(0x10100)Why it won't work ?
    10x

Sign In or Register to comment.