Executing binary files

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
mySilence
Posts: 3
Joined: Sat Dec 11, 2004 12:00 am

Executing binary files

Post 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.. :(
Last edited by mySilence on Sat Dec 11, 2004 12:00 am, edited 1 time in total.
cipek
Member
Member
Posts: 43
Joined: Mon Oct 25, 2004 11:00 pm
Location: Poland

Re: Executing binary files

Post 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 :)
mySilence
Posts: 3
Joined: Sat Dec 11, 2004 12:00 am

Re: Executing binary files

Post 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.. :)
slasher
Posts: 17
Joined: Sun Oct 24, 2004 11:00 pm
Contact:

Re: Executing binary files

Post 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
Last edited by slasher on Tue Feb 27, 2007 7:51 pm, edited 1 time in total.
[AlAdDiN]
Member
Member
Posts: 107
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: Executing binary files

Post 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 ;)
-----------------------
There are 10 types of people in this world... those that understand binary, and those that don't.
Post Reply