OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 6:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Loading and reading from a text file
PostPosted: Tue May 27, 2008 2:36 pm 
Offline

Joined: Tue May 27, 2008 10:34 am
Posts: 3
I am using Neon's tutorials at brokenthorn, and I have just finished the Bootloader tutorial. I have a FAT system setup. I was going to pause from doing the tutorials and do a little work myself. I am just trying to load a text file and add two numbers from seperate lines inside and add them together. An example text file would be:

Code:
4
         2


I need to know how to load the file and read each line seperately using only BIOS commands. Any tips on how to do this?


Top
 Profile  
 
 Post subject: Re: Loading and reading from a text file
PostPosted: Tue May 27, 2008 3:07 pm 
Offline
Member
Member

Joined: Tue May 06, 2008 9:32 am
Posts: 87
Location: The Netherlands
Quote:
I need to know how to load the file and read each line seperately using only BIOS commands. Any tips on how to do this?


Search for documentation about "filesystems".


Top
 Profile  
 
 Post subject: Re: Loading and reading from a text file
PostPosted: Tue May 27, 2008 3:22 pm 
Offline
User avatar

Joined: Tue May 20, 2008 4:52 pm
Posts: 20
Location: St Louis, Missouri, USA
Loknar wrote:
I have a FAT system setup.



What do you mean when you say setup? Are you implying that you have a FAT file system on disk?

http://www.osdever.net/documents.php?cat=13&sort=1

There are some documents on FAT on osdever.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 6:11 pm 
Offline

Joined: Tue May 27, 2008 10:34 am
Posts: 3
By setup, I mean that I can search for and run a second stage in the form of a .sys file. I just do not know how to open a file and read from its contents.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 8:17 pm 
Offline
Member
Member

Joined: Sun Apr 20, 2008 5:32 pm
Posts: 42
Location: Index 0 of the nearest Array
Read the tutorials at http://www.Brokenthorn.com. There they go over the basics. The load a stage 1 bootloader which loads a stage 2 (which is saved as a .sys) and even load and run a C kernel (might be a c++ kernel) Not to mention they go over other basics like pmode, 32-bit, and other stuff that one might want.

_________________
My OS: SOS (Simple Operating System).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 8:55 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
The FAT12 code can be used to load a file of any type. Text files have no real specific format (Besides the EOF character, and parsing special characters like new lines)

I personally recommend waiting until the Stage 2 bootloader, as the first stage is limited to 512 bytes.

Once the image is in memory, then parse it line by line and go from there...

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 1:02 am 
Offline
Member
Member

Joined: Tue May 06, 2008 9:32 am
Posts: 87
Location: The Netherlands
neon wrote:
The FAT12 code can be used to load a file of any type. Text files have no real specific format (Besides the EOF character, and parsing special characters like new lines)

I personally recommend waiting until the Stage 2 bootloader, as the first stage is limited to 512 bytes.

Once the image is in memory, then parse it line by line and go from there...


My loader loads a file from a FAT12-volume without the need for non-fragmented systemfiles, support for both int 13h extensions and legacy int 13h functions, and no precalculated-sectors. It's a hard job to put that in 512 bytes, but it's possible. But before you even begin with an OS, learn the basics.

But it can only load the most necessary binary file for further loading the OS. Reading and parsing textfiles cannot be done from a small bootsector, waith until "stage 2" or whatever you call it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 6:27 am 
Offline

Joined: Tue May 27, 2008 10:34 am
Posts: 3
OK, I think I can put it in Stage two, I just need to get the FAT12 search code copied over. Will the FAT tables stay in memory after being loaded to run the second stage?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 6:33 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Yes - as long as you are certain that no other code / data has overwritten them (in other words, be careful that no other buffers overlap these areas).

Cheers,
Adam


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 45 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group