Page 1 of 1

Executing binary files

Posted: Sat Dec 11, 2004 12:00 am
by mySilence
Umm.. A little question for all of you..
How can I load a program into a memory and execute it?
In NASM.
I have some code for it but it keeps messing up my print functions.. :(

Re: Executing binary files

Posted: Sun Dec 12, 2004 12:00 am
by cipek
ORG 0X7C00

Begin:

MOV SI, Welcome
CALL WriteString

MOV SI, Init
CALL WriteString

CALL Point

CLI
MOV AX, 07C0h
MOV SS, AX
MOV SP, 0
STI

CALL Point

MOV [BootDrv], DL

CALL Point

XOR AX, AX
MOV DL, [BootDrv]
INT 13h

CALL Point

MOV SI, LoadKernelMSG
CALL WriteString

CALL Point

PUSH ES
MOV AX, 1000h
MOV ES, AX
MOV BX, 0
MOV AH, 2
MOV AL, 3
MOV CH, 0
MOV CL, 2
MOV DX, 0
INT 13H
POP ES

CALL Point

MOV AX, 1000h
MOV ES, AX
MOV DS, AX
MOV SS, AX
XOR AX, AX
XOR BX, BX
XOR CX, CX
XOR DX, DX
XOR SI, SI
XOR DI, DI
XOR SP, SP
XOR BP, BP
CALL LONG 1000H:0000H
Point:
MOV AH, 0Eh
MOV BH, 0
MOV AL, '.'
INT 10h
RETN

WriteString:
LODSB
CMP AL, 0
JE SHORT WriteStringEnd
MOV AH, 0Eh
MOV BH, 0
INT 10h
JMP SHORT WriteString

WriteStringEnd:
RETN



Welcome db 13,10,'CSOS Boot(by Cipek 2004) - Ladowanie Kernela',13,10,0
Init db 13,10,'Iniciowanie [',0
LoadKernelMSG db ']',13,10,'Ladowanie Kernela [',0
BootDrv DB 0

TIMES 512-($-$$)-2 DB 0
DW 0AA55H


May be this code will help you :)

Re: Executing binary files

Posted: Sun Dec 12, 2004 12:00 am
by mySilence
I meant that how could kernel execute an another binary file from the disk.
So the OS would work like this:
BOOT -------> KERNEL.BIN <-------> PROG.BIN

If that made any sense.. :)

Re: Executing binary files

Posted: Sun Dec 12, 2004 12:00 am
by slasher
you need to write
1. floppy/hard disk driver
2. File system
3. file loader
use driver to pass sectors requested from the file system. The file system takes a file path name, parses it, finds the entry for the file name and the needed sectors, allocates memory for the file, requests the sectors to be read from the driver (floppy/hard disk). Once sectors are loaded, jump to the address where the file is loaded (or start a new process with the mem address)
This is a ROUGH summary but should give you the needed ideas

Re: Executing binary files

Posted: Mon Dec 13, 2004 12:00 am
by [AlAdDiN]
that depend on what mode ur kernel is using (real/protected) and it u r using pmode, what, memory management policy r u using

so give us more information to allow us help u ;)