Run a file in OS by Assembly

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
sht
Posts: 3
Joined: Mon Jun 20, 2011 1:46 am

Run a file in OS by Assembly

Post 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!
User avatar
Neolander
Member
Member
Posts: 228
Joined: Tue Mar 23, 2010 3:01 pm
Location: Uppsala, Sweden
Contact:

Re: Run a file in OS by Assembly

Post 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) ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Run a file in OS by Assembly

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sht
Posts: 3
Joined: Mon Jun 20, 2011 1:46 am

Re: Run a file in OS by Assembly

Post 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
Attachments
BOOT12.ASM
(13.32 KiB) Downloaded 97 times
Loader.asm
(2.81 KiB) Downloaded 68 times
1.asm
(1.26 KiB) Downloaded 88 times
User avatar
Neolander
Member
Member
Posts: 228
Joined: Tue Mar 23, 2010 3:01 pm
Location: Uppsala, Sweden
Contact:

Re: Run a file in OS by Assembly

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Run a file in OS by Assembly

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: Run a file in OS by Assembly

Post 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
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
sht
Posts: 3
Joined: Mon Jun 20, 2011 1:46 am

Re: Run a file in OS by Assembly

Post by sht »

Thanks alot for your helps.
Post Reply