Page 1 of 1

Floppy driver problems

Posted: Thu Aug 31, 2006 5:35 am
by srg_13
Hi,

I am trying to write a floppy driver, and I have come accross a problem. I am trying to memcpy the disk parameters from their location in the memory, but I get a parse error when I try to compile it. Here's the code:

Code: Select all

#define DISK_PARAMETER_ADDRESS 0x000fefc7 
//location where disk parameters are stored by bios

typedef struct{
  unsigned char steprate_headunload;
  unsigned char headload_ndma;
  unsigned char motor_delay_off; /*specified in clock ticks*/
  unsigned char bytes_per_sector;
  unsigned char sectors_per_track;
  unsigned char gap_length;
  unsigned char data_length; /*used only when bytes per sector == 0*/
  unsigned char format_gap_length;
  unsigned char filler;
  unsigned char head_settle_time; /*specified in milliseconds*/
  unsigned char motor_start_time; /*specified in 1/8 seconds*/
}floppy_parameters;

floppy_parameters floppy_disk; //declare variable of floppy_parameters type

memcpy(&floppy_disk, (unsigned char *)DISK_PARAMETER_ADDRESS, sizeof(floppy_parameters)); 
// Copy parameters (doesn't work) 
I have tried many variations, but I still can't get it to compile... If I comment out the last line, it does compile, but then the driver won't work... The error is:

Code: Select all

In file included from floppy.c:4:
include/floppy.h:26: error: parse error before '&' token
-Stephen

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 5:46 am
by Kemp
Try this:

Code: Select all

struct floppy_parameters {
<snip>
};
IIRC the name before the braces gives the name of the structure, the name after the braces creates a variable of the structure type.

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 5:54 am
by Pype.Clicker
and actually, that sounds weird to me to have memcpy(...) in a .h file, at top level. that line should be part of your main() function, not as a standalone declaration :P

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 5:56 am
by Habbit
Steve the Pirate wrote:

Code: Select all

memcpy(&floppy_disk, (unsigned char *)DISK_PARAMETER_ADDRESS, sizeof(floppy_parameters)); 
// Copy parameters (doesn't work) 
I have tried many variations, but I still can't get it to compile... If I comment out the last line, it does compile, but then the driver won't work... The error is:

Code: Select all

In file included from floppy.c:4:
include/floppy.h:26: error: parse error before '&' token
I may be wrong, but I think this is crystal clear: you're writing code outsite a function! C is no scripting language, dude, the only thing you can write at the global scope is definitions (of functions, variables, structs)... You are calling memcpy from the global scope, which does not work because the compiler won't know where to put that code.
Make up your mind and think where that code should go (first of all: NOT in a .h file - header files are for definitions, not code). If you are sure that the best place would be the global scope - because it performs some type of disk driver initialization - bad luck, because there is no global scope: put it into some disk_driver_initialize() function and make sure it gets called before other disk driver functions.

Have a good OS developing time!

Edit: D'oh! I'm late... Pype has already pointed this out

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 6:03 am
by srg_13
I still get the parse error on the

Code: Select all

memcpy(&floppy_disk, (unsigned char *)DISK_PARAMETER_ADDRESS, sizeof(floppy_parameters)); 
-Stephen ???

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 6:14 am
by Habbit
Steve the Pirate wrote: I still get the parse error on the

Code: Select all

memcpy(&floppy_disk, (unsigned char *)DISK_PARAMETER_ADDRESS, sizeof(floppy_parameters)); 
You still get the parse error after doing what?

Re:Floppy driver problems

Posted: Thu Aug 31, 2006 6:27 am
by srg_13
Sorry, that was a reply to Kemp's post. I read the post, messed around with my code for 10 minutes, and then hit reply. I didn't realise that two other people had posted in that time! :P

Putting the memcpy in the init function worked ;D . The reason it was in the header was because I cleaned up my c file by copying the parameters structure and a bunch of defines into the header, and that memcpy was in the middle of it all...

Thanks for the advice,

-Stephen