Weird problem with my OS loader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sadosex
Posts: 2
Joined: Sun Jan 26, 2020 5:22 am

Weird problem with my OS loader

Post by sadosex »

I make a bootstrap program to be installed on boot sector of TAILS, Windows however the software that i make only work showing the boot message to the user when s/he power on the PC and startup my OS bootloader. I dont know what are wrong at my source because my source works on MS-DOS however dont works in Windows or TAILS Linux. Please read carefully my source in FASM:

Code: Select all

org 0x100
OS_LOADER:
    cli       
    xor ax,ax
    mov ds,ax
    mov es,ax
    mov ss,ax
    mov sp,07C00h
    sti
    Kernel:

    MOV AX,1300h
    MOV BX,30h
    MOV CX,10Ch
    MOV DX,0
    PUSH CS
    POP ES
    MOV BP,7C68h
    INT 10h
    L1:
    IN AL,60H
    CMP AL,1
    JNZ L1
    JMP L2
    Texto db "",0   ;198 bytes message
    L2:
    mov ah,8
    mov dl,80H
    mov di,0
    push es
    mov es,di
    INT 13H
    pop es 
    sub cl,6

    mov ax,0000h
    mov es,ax
    mov bx,500h
    mov dl,80h
    mov al,01h
    mov ah,02h
    int 13h
    jmp 0000:0500h

    codesize:

    SETOR db 512 dup (0)
Please someone tell me where is my error in my source.
sadosex
Posts: 2
Joined: Sun Jan 26, 2020 5:22 am

Re: Weird problem with my OS loader

Post by sadosex »

Here is my full source:

Code: Select all

org 0x100
mov ax,201h
mov bx,SETOR
mov cx,1
mov dx,80H
int 13h

mov ah,8
mov dx,80H
mov di,0
push es
mov es,di
INT 13H
pop es

mov ax,301h
sub cl,6
mov dl,80H
MOV WORD[SETOR+510],0AA55H
mov bx,SETOR
INT 13H

LEA DI,[SETOR]
MOV SI,OS_LOADER
MOV CX,336
REP MOVSB

mov bx,SETOR
MOV WORD[SETOR+510],0AA55H
mov ax,301h
mov cx,1
mov dx,80H
INT 13H

ret

OS_LOADER:
	    cli	      
	    xor ax,ax
	    mov ds,ax
	    mov es,ax
	    mov ss,ax
	    mov sp,07C00h
	    sti
		Kernel:

MOV AX,1300h
MOV BX,30h
MOV CX,10Ch
MOV DX,0
PUSH CS
POP ES
MOV BP,7C68h
INT 10h
L1:
IN AL,60H
CMP AL,1
JNZ L1
JMP L2
Texto db "",0	;message of 198 bytes
L2:
mov ah,8
mov dl,80H
mov di,0
push es
mov es,di
INT 13H
pop es
sub cl,6

mov ax,0000h
mov es,ax
mov bx,500h
mov dl,80h
mov al,01h
mov ah,02h
int 13h
jmp 0000:0500h

codesize:

SETOR db 512 dup (0)
Now tell me why i couldn't install my boot loader in Linux and Windows?
nullplan
Member
Member
Posts: 1794
Joined: Wed Aug 30, 2017 8:24 am

Re: Weird problem with my OS loader

Post by nullplan »

Org 0x100? Are you trying to write a boot sector or a COM file? If the former, then either use org 0 and perform a far jump to 07c0:0000, or use org 7c00h and perform a far jump to 0000:7c00. Plus whatever offset, of course. You are doing neither. Other than that the boot loader you have does not parse the partition table, it just loads the second sector to a nonstandard address and jumps there. I would not expect that to work.

Most MBRs relocate themselves to 0x600, look for an active partition in the partition table, and load its first sector to 0x7c00 and jump there, with DS:DI set to point to the partition table entry. Most PBRs require this interface. You are doing none of that. So of course this only works with MS-DOS, because you got lucky. Windows and Linux require a more modern approach which you fail to provide.
Carpe diem!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Weird problem with my OS loader

Post by Solar »

Also, there are those who'd say that work on your own OS shouldn't start at the MBR bootsector. Literally hundreds of solutions have been written for that, some of them quite sophisticated. Why not use one of the ready-made bootselectors, and focus on where your OS actually takes over -- e.g. with the first sector of your partition being chainloaded by whatever bootloader the user employs to select between YourOS, Windows, and Linux? That's still pretty low-level, but doesn't get into anyone's way or reimplement the wheel...
Every good solution is obvious once you've found it.
Post Reply