Okay, this is stupid, I know. K&R hasn't helped so far, because they deal with static arrays within the same function, at least as far as I've skimmed. I'm trying to define an array of unsigned longs in sdram_enable, pass that to spd_set_sdram_registers where its set to the address offsets, and then have it used in do_ram_command to read from those offsets. What's the proper way to do this? Just an example of what I'm doing, hopefully someone can point out my error:
define it: unsigned long row_offsets[DIMM_SOCKETS * 2 - 1];
pass it on: spd_set_dram_size(ctrl, row_offsets);
accept it: static void spd_set_dram_size(const struct mem_controller *ctrl, unsigned long row_offsets)
set it: row_offsets[i * 2] = (dimm_size * 4 * 1024);
use it (in do_ram_command): read32(row_offsets[i] + addr_offset);
And the gcc error: /LinuxBIOSv2/src/mainboard/asus/mew-vm/auto.c -o auto.inc raminit.c:97.37: <which is where do_ram_command is defined, similar to spd_set_dram_size above> subscripted value is not a pointer make[1]: *** [auto.inc] Error 1 make[1]: Leaving directory `/home/amp/linuxbios/p2b/LinuxBIOSv2/targets/asus/mew-vm/mew-vm/normal' make: *** [normal/linuxbios.rom] Error 1
BTW, I've gotten the i810 as far as booting a filo payload (looking for linux in the wrong location), but haven't tried any further than that yet. Will probably try further once I can get this straightened out.
Thanks, Corey
raminit.c:97.37: <which is where do_ram_command is defined, similar to spd_set_dram_size above> subscripted value is not a pointer
The gcc error tells the trueth: you have a pointer problem! :)
An array, in C, is like a pointer. When you do:
unsigned long row_offsets[DIMM_SOCKETS * 2 - 1];
you'll get a pointer of type unsigned long with a size of sizeof(unsigned long * (DIMM_SOCKETS * 2 - 1));
So, if you want to pass it into a function you have to define the function with the parameter as being a pointer (and a good practice would be also pass the size of the array).
Okay, this is stupid, I know.
And there is no stupid questions! Just stupid answers.
http://en.wikipedia.org/wiki/C_(programming_language)#Data_structures
Cheers, Marcelo
On Tue, May 22, 2007 at 12:25:43PM +0100, Marcelo Coelho wrote:
So, if you want to pass it into a function you have to define the function with the parameter as being a pointer (and a good practice would be also pass the size of the array).
On Tue, May 22, 2007 at 07:15:14AM -0400, Corey Osgood wrote:
unsigned long row_offsets[DIMM_SOCKETS * 2 - 1]; spd_set_dram_size(ctrl, row_offsets);
static void spd_set_dram_size(const struct mem_controller *ctrl, unsigned long row_offsets)
To clarify, change the prototype and function to:
static void spd_set_dram_size(const struct mem_controller *ctrl, unsigned long *row_offsets)
If this static function is in the same file as row_offsets[] and the array is in file scope then you could just skip the parameter completely. This makes sense because you'll need to use another global entity (the DIMM_SOCKETS define) in the function anyway. The alternative clean way would be to pass DIMM_SOCKETS*2-1 to spd_set_dram_size() too, but in this case it could probably be OK to just skip both those parameters. Not sure without seeing complete code.
//Peter
Peter Stuge wrote:
On Tue, May 22, 2007 at 12:25:43PM +0100, Marcelo Coelho wrote:
So, if you want to pass it into a function you have to define the function with the parameter as being a pointer (and a good practice would be also pass the size of the array).
On Tue, May 22, 2007 at 07:15:14AM -0400, Corey Osgood wrote:
unsigned long row_offsets[DIMM_SOCKETS * 2 - 1]; spd_set_dram_size(ctrl, row_offsets);
static void spd_set_dram_size(const struct mem_controller *ctrl, unsigned long row_offsets)
To clarify, change the prototype and function to:
static void spd_set_dram_size(const struct mem_controller *ctrl, unsigned long *row_offsets)
That's what I figured after Marcelo's post, and something I tried last night as well. The error:
raminit.c:278.56: auto.c:88.21: 0x81b0e30 adecl Internal compiler error: adecl remains? make[1]: *** [auto.inc] Aborted (core dumped) make[1]: Leaving directory `/home/amp/linuxbios/p2b/LinuxBIOSv2/targets/asus/mew-vm/mew-vm/normal' make: *** [normal/linuxbios.rom] Error 1
If this static function is in the same file as row_offsets[] and the array is in file scope then you could just skip the parameter completely. This makes sense because you'll need to use another global entity (the DIMM_SOCKETS define) in the function anyway. The alternative clean way would be to pass DIMM_SOCKETS*2-1 to spd_set_dram_size() too, but in this case it could probably be OK to just skip both those parameters. Not sure without seeing complete code.
raminit.c is attached, I think I'm just very confused.
Thanks, Corey