Page 1 of 1

Run a file in OS by Assembly

Posted: Mon Jun 20, 2011 2:27 am
by sht
Hello every body!
I've written a very simple"Hello world" OS using assembly language. now I want that when user press a specific key (for example"1") my OS runs the file 1.bin (1.bin is a simple file that just print a sentence on the screen.) But I don't know how I should do it. :(
Help me please to do that!

Re: Run a file in OS by Assembly

Posted: Mon Jun 20, 2011 3:30 am
by Neolander
To give you a clear reply, I need you to answer the following questions first :
  • I assume that you develop for x86, correct me if wrong. In which CPU mode does your OS run ? Real mode ? Protected mode ? Long mode ?
  • Where is "1.bin" located ? Is it a file on the floppy/cdrom/disk drive which your OS is installed on, or do you want the bootloader to load it in RAM for you ? In the latter case, which bootloader do you use ? GRUB ?
  • What kind of executable format do you use ? ELF ? A.out ? COM ?
  • Do you use fixed-position code (designed to run at a specific location of memory, requires use of paging or segmentation tricks to run elsewhere) or position-independent code (designed to run at any location of memory, requires run-time symbol relocation on x86 except in long mode) ?

Re: Run a file in OS by Assembly

Posted: Mon Jun 20, 2011 7:21 am
by Combuster
sht wrote:I've written a very simple"Hello world" OS using assembly language. now I want that when user press a specific key (for example"1") my OS runs the file 1.bin (1.bin is a simple file that just print a sentence on the screen.) But I don't know how I should do it. :(
Help me please to do that!
I see you asking about three problems in one sentence:
- Get a keypress.
- Read a file from storage.
- Start a program.
Which can very well be implemented in that order. You can use the name of the actual responsible device as an index into the wiki. As you go you'll probably raise more and more specific questions which you will enter into google and get specific answers for. As far as your description goes, there's no problem other than you just having to get to work. Or you had anything specific in mind?

Re: Run a file in OS by Assembly

Posted: Tue Jun 21, 2011 12:38 am
by sht
Hello again
Thanks for your replies.
My files are in floppy drive.(I use image of floppy in vmware).
I use nasm to compile '1.asm' to '1.com'. and iI want to execute 1.com.
The main file of my OS is loader.bin.
I'm new and so inexpert. So I don't know that my codes are correct or not.
I attach My files here.
I'll be happy if you help me

Re: Run a file in OS by Assembly

Posted: Tue Jun 21, 2011 12:58 am
by Neolander
sht wrote:My files are in floppy drive.(I use image of floppy in vmware).
And you want to load it from the floppy yourself ? Alright, then you need to answer at least my first question : in which CPU mode does your OS run ?

This is important because if your CPU is in so-called real mode, you can access the floppy drive very easily, whereas if it is in protected or long mode, you'll need a bit more work (but get access to all of your CPU's modern capabilities as a counterpart).
I'm new and so inexpert. So I don't know that my codes are correct or not.
I attach My files here.
I'm not talking about code at the moment. This is about design choices, which will in turn tell you which kind of code you want you write. In an ideal scenario, you should care about those before writing a single line of code, but I guess nearly everybody on OSdev can confirm that it's not how things happen when you begin in the field.

Let me repeat this again : there are several solutions to your problem. Each one has a set of advantages and drawbacks. Which one you choose determine what your operating system will be like. It's because of such choices that not all operating systems are alike :mrgreen:

I currently have the feeling that you are using other people's code without truly understanding what its outcome is. This is a bad practice. You may think that you can get away with it in the short run, but in the long run you will get burned. You can't truly master things without understanding the theory behind them.

Re: Run a file in OS by Assembly

Posted: Tue Jun 21, 2011 1:14 am
by Combuster
I'm new and so inexpert. So I don't know that my codes are correct or not.
I don't know, therefore I try :wink:

Re: Run a file in OS by Assembly

Posted: Tue Jun 21, 2011 2:13 am
by M-Saunders
sht wrote:The main file of my OS is loader.bin.
Why does your OS try to call DOS (int 21h)? It looks like you've pasted various pieces of code together, have no clue what's going on, and you're now totally stuck. As to be expected.

OS development is demanding work! Your approach is like saying: "I'm going to be a heart surgeon", cutting open someone's chest and then saying "Help, what do I do with this red gooey stuff?"

Learn assembly. Properly. Learn how PC hardware works, how interrupts work, how FAT12 works (essential if you want to load programs). You've got to spend many months learning before tackling such a hard subject. My primer might help, but it's just a simple start:

http://mikeos.berlios.de/write-your-own-os.html

Mike

Re: Run a file in OS by Assembly

Posted: Thu Jun 30, 2011 3:06 am
by sht
Thanks alot for your helps.