Loading file data under fat12

If you are new to development, plan on spending some time here before visiting the other forums.

Moderator: Moderators

Loading file data under fat12

Postby xixpsychoxix » Mon Nov 02, 2009 4:32 am

Ok, so i have been working on some of my own code to locate a file in the root directory. Here is the code I have so far for the load:

Code: Select all

struct diskinfo_FAT12
{
   uint8_t  jmp1;
   uint8_t  jmp2;
   uint8_t  jmp3;
   uint8_t  OEM_Name[8];
   uint16_t BytesPerSector;
   uint8_t  SectorsPerCluster;
   uint16_t ReservedSectors;
   uint8_t  FATCount;
   uint16_t RootEntries;
   uint16_t TotalSectors;
   uint8_t  MediaType;
   uint16_t SectorsPerFAT;
   uint16_t SectorsPerTrack;
   uint16_t HeadsPerCylinder;
   uint32_t HiddenSectors;
   uint32_t SectorCountLarge;
   uint8_t  DriveNumber;
   uint8_t  Unused;
   uint8_t  ExtBootSig;
   uint32_t SerialNumber;
   uint8_t  VolumeLabel[11];
   uint8_t  FileSystem[8];
};

void LoadFile (char *filename)
{
   int root_size = (diskdat->RootEntries * 32) / diskdat->BytesPerSector;
   int root_location = (diskdat->FATCount * diskdat->SectorsPerFAT) + diskdat->ReservedSectors;
   char buffer[7186] = "";

   for (int i = 0; i < root_size; i++)
   {
      uint8_t *transfer = flpydsk_read_sector (root_location+i);

      for (int j = 0; j < diskdat->BytesPerSector; j++)
         buffer[(i*diskdat->BytesPerSector)+j] = (char) *transfer++;
   }

   printf ("\nI managed to load the root directory!\n");

   for (int a = 0; a < 7186; a += 32)
   {
      char *temp1 = filename, *temp2 = buffer;
      int i = 0;

      while ((*temp2++ == *temp1++) && i < 11)
         i++;

      if (i >= 11)
      {
         printf ("\nFile found!!!\n");
         return;
      }

      *buffer += 32;
   }
   printf ("\nI couldn't find your file, sorry!!!\n");
}



All of the rest of the code is nearly identical to the code in the tutorial. I am using the information presented in tutorial 21 as a base and attempting to add my own code to it. For some reason when I try to compile this code with Visual Studio 2008 Express I get the following errors:

Code: Select all

kernel.obj : error LNK2019: unresolved external symbol __chkstk referenced in function "void __cdecl LoadFile(char *)" (?LoadFile@@YAXPAD@Z)
kernel.obj : error LNK2019: unresolved external symbol _memcpy referenced in function "void __cdecl LoadFile(char *)" (?LoadFile@@YAXPAD@Z)
kernel.obj : error LNK2019: unresolved external symbol _memset referenced in function "void __cdecl LoadFile(char *)" (?LoadFile@@YAXPAD@Z)



Now as far as i can tell I am not attempting to use the above functions in any form, but i do not get an error when i comment out the following line:

Code: Select all

while ((*temp2++ == *temp1++) && i < 11)



As soon as i comment out this line the code will compile. Can anyone tell me where my problem is coming in?
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby Andyhhp » Mon Nov 02, 2009 11:01 am

Your compiler is trying to optimise using builtin functions.

You need to disable builtin functions completely (Settings -> C/C++ -> advanced)

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Loading file data under fat12

Postby xixpsychoxix » Mon Nov 02, 2009 7:40 pm

I cant find the compiler option for built-in functions under visual studio. are you sure it's under the c++ advanced tab?
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby djsilence » Tue Nov 03, 2009 4:27 am

You need to set Linker->Input->Ignore All Default Libraies to "Yes (/NODEFAULTLIB)". (In VS2005 works, have no 2008).
Thinking of great - thinking of little, thinking of little - thinking of great.
User avatar
djsilence
 
Posts: 30
Joined: Sun Feb 15, 2009 8:49 pm
Location: Kyiv, Ukraine

Re: Loading file data under fat12

Postby xixpsychoxix » Tue Nov 03, 2009 11:31 am

I have it set to ignore default libraries and it still isnt working. i also tried every optimization level and on some it has less errors but mostly its all the same.
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby Andyhhp » Tue Nov 03, 2009 11:36 am

@djsilence: these are not default lib functions, they are builtin functions which are different.

as a hack, try
Code: Select all
#define _memcpy <your memcpy function name>


~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Loading file data under fat12

Postby xixpsychoxix » Wed Nov 04, 2009 5:27 pm

I tried to do what you said about using #define to trick the compiler into using my function, but that didnt seem to work either. I dont believe that it is an optimization problem because even when i turn optimization off i have the same problem. I tried:

Code: Select all

#pragma optimize ( " ", off)

void MyFunction (void)
{
  //function body
}

#pragma optimize ( " ", on)



and i still have the problem. I have no clue what i am going to do here. maybe i'll just wait for the next chapter to come out... :cry:
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby xixpsychoxix » Wed Nov 04, 2009 6:03 pm

I solved the problem by changing buffer[7186] from a local variable to a global variable and for some odd reason it worked. if anyone has an explanation for that i would love to hear it so please let me know!
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby Mike » Wed Nov 04, 2009 6:40 pm

Hello,

7186 is alot of bytes to put on the stack. (I do wonder where 7186 came from as well...) If you want to use it as a local variable, insure that you have enough stack space that wont cause any problems.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Re: Loading file data under fat12

Postby xixpsychoxix » Thu Nov 05, 2009 3:34 am

actually 7186 is the size of the root directory in bytes for my floppy:

Code: Select all

int root_size = (diskdat->RootEntries * 32) / diskdat->BytesPerSector;



and it works out to 7186 because diskdat->RootEntries == 224 && diskdat->BytesPerSector == 512. And since i couldnt use an equation to dimension the array and i have no malloc i had to hard code it. yeah i should hide it behind a constant, sry this was just more of a test i didnt expect it to actually work!!! :D
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby xixpsychoxix » Sun Feb 21, 2010 7:34 am

yeah, i know this is another old topic but i took a break from OS Programming for awhile to work on games... anyhow, I am trying to write a routine to make a filename taken from the prompt into the format used to test for filename. so if my filename is this:

Code: Select all
test.txt


i need to write a routine to make it into this:

Code: Select all
TEST    TXT


anyone give me a start? nothing i try works. if anyone wants to see what i've started i'll post it but it doesnt even come close to doing what i want. thanks!
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm

Re: Loading file data under fat12

Postby Andyhhp » Sun Feb 21, 2010 7:36 am

In any other C programming situation, I would advise using scanf.

However, in this situation, i have to ask if you even have a method of getting user input?

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Loading file data under fat12

Postby xixpsychoxix » Mon Feb 22, 2010 3:56 am

well im working along side the tutorial so i am using the current kernel routine GetCommand to get a line.
xixpsychoxix
 
Posts: 59
Joined: Tue Oct 13, 2009 8:49 pm


Return to Beginners

Who is online

Users browsing this forum: No registered users and 1 guest

cron