Page 1 of 1

Loading file data under fat12

Posted: Mon Nov 02, 2009 4:32 am
by xixpsychoxix
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?

Re: Loading file data under fat12

Posted: Mon Nov 02, 2009 11:01 am
by Andyhhp
Your compiler is trying to optimise using builtin functions.

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

~Andrew

Re: Loading file data under fat12

Posted: Mon Nov 02, 2009 7:40 pm
by xixpsychoxix
I cant find the compiler option for built-in functions under visual studio. are you sure it's under the c++ advanced tab?

Re: Loading file data under fat12

Posted: Tue Nov 03, 2009 4:27 am
by djsilence
You need to set Linker->Input->Ignore All Default Libraies to "Yes (/NODEFAULTLIB)". (In VS2005 works, have no 2008).

Re: Loading file data under fat12

Posted: Tue Nov 03, 2009 11:31 am
by xixpsychoxix
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.

Re: Loading file data under fat12

Posted: Tue Nov 03, 2009 11:36 am
by Andyhhp
@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

Re: Loading file data under fat12

Posted: Wed Nov 04, 2009 5:27 pm
by xixpsychoxix
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:

Re: Loading file data under fat12

Posted: Wed Nov 04, 2009 6:03 pm
by xixpsychoxix
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!

Re: Loading file data under fat12

Posted: Wed Nov 04, 2009 6:40 pm
by Mike
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.

Re: Loading file data under fat12

Posted: Thu Nov 05, 2009 3:34 am
by xixpsychoxix
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

Re: Loading file data under fat12

Posted: Sun Feb 21, 2010 7:34 am
by xixpsychoxix
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!

Re: Loading file data under fat12

Posted: Sun Feb 21, 2010 7:36 am
by Andyhhp
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

Re: Loading file data under fat12

Posted: Mon Feb 22, 2010 3:56 am
by xixpsychoxix
well im working along side the tutorial so i am using the current kernel routine GetCommand to get a line.