* question regarding put data in the specified section
@ 2003-11-14 17:42 Teresa Tao
2003-11-14 17:42 ` Teresa Tao
2003-11-15 12:53 ` Ralf Baechle
0 siblings, 2 replies; 8+ messages in thread
From: Teresa Tao @ 2003-11-14 17:42 UTC (permalink / raw)
To: linux-mips
Hi there,
Does anyone know how to put my userland program's data in a specified section?
I know there is an attribute "section" to put my data inside a specified section, for example, int data __attribute__ ((section("INITDAT"));
But how do I initialize/setup the INITDAT section? We use the commercial toolchain, and we don't have the source code for it, is there still a way to specify the postion of the INITDAT section?
Thanks in advance!
Teresa
^ permalink raw reply [flat|nested] 8+ messages in thread* question regarding put data in the specified section
2003-11-14 17:42 question regarding put data in the specified section Teresa Tao
@ 2003-11-14 17:42 ` Teresa Tao
2003-11-15 12:53 ` Ralf Baechle
1 sibling, 0 replies; 8+ messages in thread
From: Teresa Tao @ 2003-11-14 17:42 UTC (permalink / raw)
To: linux-mips
Hi there,
Does anyone know how to put my userland program's data in a specified section?
I know there is an attribute "section" to put my data inside a specified section, for example, int data __attribute__ ((section("INITDAT"));
But how do I initialize/setup the INITDAT section? We use the commercial toolchain, and we don't have the source code for it, is there still a way to specify the postion of the INITDAT section?
Thanks in advance!
Teresa
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: question regarding put data in the specified section
2003-11-14 17:42 question regarding put data in the specified section Teresa Tao
2003-11-14 17:42 ` Teresa Tao
@ 2003-11-15 12:53 ` Ralf Baechle
2003-11-16 9:00 ` file handling in kernel mode durai
1 sibling, 1 reply; 8+ messages in thread
From: Ralf Baechle @ 2003-11-15 12:53 UTC (permalink / raw)
To: Teresa Tao; +Cc: linux-mips
On Fri, Nov 14, 2003 at 09:42:34AM -0800, Teresa Tao wrote:
> Does anyone know how to put my userland program's data in a specified section?
>
> I know there is an attribute "section" to put my data inside a specified section, for example, int data __attribute__ ((section("INITDAT"));
> But how do I initialize/setup the INITDAT section? We use the
> commercial toolchain, and we don't have the source code for it, is
> there still a way to specify the postion of the INITDAT section?
If your commercial toolchain understands the __attribute__ syntax then
I suspect it's based on gcc which would mean you have a right to the
sourcecode.
No initialization needed; Ld will use the flags of the first instance
of an input section for the output section which usually is right. In
the rare case this isn't suitable you can use a .section pseudo-op
in inline assembler or assembler to setup the section with the right
flags. Just make sure this section is linked first.
Ralf
^ permalink raw reply [flat|nested] 8+ messages in thread* file handling in kernel mode
2003-11-15 12:53 ` Ralf Baechle
@ 2003-11-16 9:00 ` durai
2003-11-16 9:00 ` durai
2003-11-16 22:51 ` Ralf Baechle
0 siblings, 2 replies; 8+ messages in thread
From: durai @ 2003-11-16 9:00 UTC (permalink / raw)
To: linux-mips
[-- Attachment #1: Type: text/plain, Size: 1901 bytes --]
Hello,
I need to read a file from a device driver and i wrote a sample driver like this
This kernel mode code which try to read the file until end of file is reached. This code had been is working without any problems in RedHat linux and uClinux.
But the same code causes a General Protection Fault in my mips linux. I tested the same code in mips running on uClinux which runs well.
what is wrong with mips linux?
#define __KERNEL_SYSCALLS__
#include <linux/version.h>
#ifdef MODULE
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/io.h>
int test_open(void );
int init_module(void)
{
printk("\n init_module ");
test_open();
return 0;
}
void cleanup_module(void)
{
printk("\n cleanup module");
}
int test_open(void )
{
int ifp,bcount;
mm_segment_t fs;
char buffer[0x1000];
// for file opening temporarily tell the kernel I am not a user for
// memory management segment access
fs = get_fs();
set_fs(KERNEL_DS);
// open the file with the firmware for uploading
if (ifp = open( "/etc/hotplug/isl3890.arm", O_RDONLY, 0 ), ifp < 0)
{
// error opening the file
printk( "ERROR: File opening did not success \n");
set_fs(fs);
return -1;
}
// enter a loop which reads data blocks from the file and writes them
// to the Direct Memory Windows
do
{
bcount = read(ifp, &buffer, sizeof(buffer));
printk("\n bcount %x ",bcount);
}
while (bcount != 0);
close(ifp);
// switch back the segment setting
set_fs(fs);
return 0;
}
thanks & regards
durai
[-- Attachment #2: Type: text/html, Size: 4231 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* file handling in kernel mode
2003-11-16 9:00 ` file handling in kernel mode durai
@ 2003-11-16 9:00 ` durai
2003-11-16 22:51 ` Ralf Baechle
1 sibling, 0 replies; 8+ messages in thread
From: durai @ 2003-11-16 9:00 UTC (permalink / raw)
To: linux-mips
[-- Attachment #1: Type: text/plain, Size: 1901 bytes --]
Hello,
I need to read a file from a device driver and i wrote a sample driver like this
This kernel mode code which try to read the file until end of file is reached. This code had been is working without any problems in RedHat linux and uClinux.
But the same code causes a General Protection Fault in my mips linux. I tested the same code in mips running on uClinux which runs well.
what is wrong with mips linux?
#define __KERNEL_SYSCALLS__
#include <linux/version.h>
#ifdef MODULE
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/module.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/io.h>
int test_open(void );
int init_module(void)
{
printk("\n init_module ");
test_open();
return 0;
}
void cleanup_module(void)
{
printk("\n cleanup module");
}
int test_open(void )
{
int ifp,bcount;
mm_segment_t fs;
char buffer[0x1000];
// for file opening temporarily tell the kernel I am not a user for
// memory management segment access
fs = get_fs();
set_fs(KERNEL_DS);
// open the file with the firmware for uploading
if (ifp = open( "/etc/hotplug/isl3890.arm", O_RDONLY, 0 ), ifp < 0)
{
// error opening the file
printk( "ERROR: File opening did not success \n");
set_fs(fs);
return -1;
}
// enter a loop which reads data blocks from the file and writes them
// to the Direct Memory Windows
do
{
bcount = read(ifp, &buffer, sizeof(buffer));
printk("\n bcount %x ",bcount);
}
while (bcount != 0);
close(ifp);
// switch back the segment setting
set_fs(fs);
return 0;
}
thanks & regards
durai
[-- Attachment #2: Type: text/html, Size: 4231 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: file handling in kernel mode
2003-11-16 9:00 ` file handling in kernel mode durai
2003-11-16 9:00 ` durai
@ 2003-11-16 22:51 ` Ralf Baechle
2003-11-17 0:46 ` Brad Parker
1 sibling, 1 reply; 8+ messages in thread
From: Ralf Baechle @ 2003-11-16 22:51 UTC (permalink / raw)
To: durai; +Cc: linux-mips
On Sun, Nov 16, 2003 at 02:30:05PM +0530, durai wrote:
> Hello,
> I need to read a file from a device driver and i wrote a sample driver
> like this
>
> This kernel mode code which try to read the file until end of file is
> reached. This code had been is working without any problems in RedHat
> linux and uClinux.
> But the same code causes a General Protection Fault in my mips linux.
> I tested the same code in mips running on uClinux which runs well.
> what is wrong with mips linux?
If the screen says general protection fault it's wasn't a MIPS box :-)
> #define __KERNEL_SYSCALLS__
>
> #include <linux/version.h>
> #ifdef MODULE
> #ifdef MODVERSIONS
> #include <linux/modversions.h>
> #endif
> #include <linux/module.h>
> #else
> #define MOD_INC_USE_COUNT
> #define MOD_DEC_USE_COUNT
> #endif
Ouch. You can replace that all with a single line:
#include <linux/module.h>
> int init_module(void)
[...]
> void cleanup_module(void)
[...]
The use of init_module and cleanup_module is deprecated, use something
like this instead:
#include <linux/init.h>
static int __init foo_init_module(void)
{
return 0;
}
static void __exit foo_cleanup_module(void)
{
}
module_init(foo_init_module);
module_exit(foo_cleanup_module);
> int test_open(void )
> {
> int ifp,bcount;
> mm_segment_t fs;
> char buffer[0x1000];
^^^^^^
And this is the BIG no-no. Never allocate large amounts of data on the
kernel stack which is only 8k which are used for various other stuff
also..
>
> // for file opening temporarily tell the kernel I am not a user for
> // memory management segment access
> fs = get_fs();
> set_fs(KERNEL_DS);
> // open the file with the firmware for uploading
> if (ifp = open( "/etc/hotplug/isl3890.arm", O_RDONLY, 0 ), ifp < 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^
Hard coding file names is generally considered bad design; this topic has
been discussed to death numerous times on linux-kernel. The general
recommendation is to use a special such as /dev/foodevice; the firmware
would then simply be loader by cat bar > //dev/foodevice or similar.
For 2.4.23 (I'm going to merge with 2.4.23-rc1 tonight) and 2.6 the
recommendation is to use CONFIG_FW_LOADER, the new standard interface
for loading firmware.
Ralf
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: file handling in kernel mode
2003-11-16 22:51 ` Ralf Baechle
@ 2003-11-17 0:46 ` Brad Parker
2003-11-17 1:06 ` Ralf Baechle
0 siblings, 1 reply; 8+ messages in thread
From: Brad Parker @ 2003-11-17 0:46 UTC (permalink / raw)
To: Ralf Baechle; +Cc: durai, linux-mips
>On Sun, Nov 16, 2003 at 02:30:05PM +0530, durai wrote:
>
>> Hello,
>> I need to read a file from a device driver and i wrote a sample driver
>> like this
>>
>> This kernel mode code which try to read the file until end of file is
>> reached. This code had been is working without any problems in RedHat
>> linux and uClinux.
>> But the same code causes a General Protection Fault in my mips linux.
>> I tested the same code in mips running on uClinux which runs well.
>> what is wrong with mips linux?
Shouldn't someone point out that having a driver read a file is
very, very wrong and a classic FAQ question?
Perhaps I'm mistaken but this seems to come up once a year on every port
list I'm on.
The "unix way" is to have something in userland feed the data to the
driver. Things in the kernel should never reach back up into the file
system. It's just not done.
Drivers are passive objects which do the bidding of "managers" which
live in userland. Add an ioctl to the driver which allows a userland
daemon to feed the microcode/firmware/fpga-data/whatever to the driver
in pieces.
Resist the temptation to put code in the driver to access the file
system.
ps: isn't hotplug already setup to notice when a device comes up and to
have a shell script run? it's bad enough that the hotplug code runs a
shell script from the kernel. I can't believe that got through...
(and if you have time, go read the plan 9 design docs. then ask yourself
what those guys would do :-)
-brad
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: file handling in kernel mode
2003-11-17 0:46 ` Brad Parker
@ 2003-11-17 1:06 ` Ralf Baechle
0 siblings, 0 replies; 8+ messages in thread
From: Ralf Baechle @ 2003-11-17 1:06 UTC (permalink / raw)
To: Brad Parker; +Cc: durai, linux-mips
On Sun, Nov 16, 2003 at 07:46:35PM -0500, Brad Parker wrote:
> Shouldn't someone point out that having a driver read a file is
> very, very wrong and a classic FAQ question?
It is.
> Perhaps I'm mistaken but this seems to come up once a year on every port
> list I'm on.
I think it's the first time on this list. In my previous posting I suggested
request_firmware for 2.4.23 / 2.6. For kernels older than this I suggest
arch/i386/kernel/microcode.c as an example for how to easily implement
a character special file.
> Resist the temptation to put code in the driver to access the file
> system.
Amen.
> ps: isn't hotplug already setup to notice when a device comes up and to
> have a shell script run? it's bad enough that the hotplug code runs a
> shell script from the kernel. I can't believe that got through...
>
> (and if you have time, go read the plan 9 design docs. then ask yourself
> what those guys would do :-)
2.6 certainly is quite a bit more plan 9-ish. What would you expect from
Al Viro :-)
Ralf
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-11-17 1:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-14 17:42 question regarding put data in the specified section Teresa Tao
2003-11-14 17:42 ` Teresa Tao
2003-11-15 12:53 ` Ralf Baechle
2003-11-16 9:00 ` file handling in kernel mode durai
2003-11-16 9:00 ` durai
2003-11-16 22:51 ` Ralf Baechle
2003-11-17 0:46 ` Brad Parker
2003-11-17 1:06 ` Ralf Baechle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox