]> git.sesse.net Git - vlc/blob - src/interface/main.c
. vlc.init et vlc.channels sont � nouveau lus et interpr�t�s lorsqu'il
[vlc] / src / interface / main.c
1 /*****************************************************************************
2  * main.c: main vlc source
3  * Includes the main() function for vlc. Parses command line, start interface
4  * and spawn threads.
5  *****************************************************************************
6  * Copyright (C) 1998, 1999, 2000 VideoLAN
7  *
8  * Authors:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
31 #include <getopt.h>                                              /* getopt() */
32 #include <stdio.h>                                              /* sprintf() */
33
34 #include <errno.h>                                                 /* ENOMEM */
35 #include <stdlib.h>                                  /* getenv(), strtol(),  */
36 #include <string.h>                                            /* strerror() */
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42 #include "plugins.h"
43 #include "input_vlan.h"
44 #include "input_ps.h"
45
46 #include "intf_msg.h"
47 #include "interface.h"
48
49 #include "audio_output.h"
50
51 #ifdef SYS_BEOS
52 #include "beos_specific.h"
53 #endif
54
55 #include "main.h"
56
57 /*****************************************************************************
58  * Command line options constants. If something is changed here, be sure that
59  * GetConfiguration and Usage are also changed.
60  *****************************************************************************/
61
62 /* Long options return values - note that values corresponding to short options
63  * chars, and in general any regular char, should be avoided */
64 #define OPT_NOAUDIO             150
65 #define OPT_AOUT                151
66 #define OPT_STEREO              152
67 #define OPT_MONO                153
68
69 #define OPT_NOVIDEO             160
70 #define OPT_VOUT                161
71 #define OPT_DISPLAY             162
72 #define OPT_WIDTH               163
73 #define OPT_HEIGHT              164
74 #define OPT_COLOR               165
75
76 #define OPT_NOVLANS             170
77 #define OPT_SERVER              171
78 #define OPT_PORT                172
79
80 /* Usage fashion */
81 #define USAGE                     0
82 #define SHORT_HELP                1
83 #define LONG_HELP                 2
84
85 /* Long options */
86 static const struct option longopts[] =
87 {
88     /*  name,               has_arg,    flag,   val */
89
90     /* General/common options */
91     {   "help",             0,          0,      'h' },
92     {   "longhelp",         0,          0,      'H' },
93     {   "version",          0,          0,      'v' },
94
95     /* Audio options */
96     {   "noaudio",          0,          0,      OPT_NOAUDIO },
97     {   "aout",             1,          0,      OPT_AOUT },
98     {   "stereo",           0,          0,      OPT_STEREO },
99     {   "mono",             0,          0,      OPT_MONO },
100
101     /* Video options */
102     {   "novideo",          0,          0,      OPT_NOVIDEO },
103     {   "vout",             1,          0,      OPT_VOUT },
104     {   "display",          1,          0,      OPT_DISPLAY },
105     {   "width",            1,          0,      OPT_WIDTH },
106     {   "height",           1,          0,      OPT_HEIGHT },
107     {   "grayscale",        0,          0,      'g' },
108     {   "color",            0,          0,      OPT_COLOR },
109
110     /* DVD options */
111     {   "dvdaudio",         1,          0,      'a' },
112     {   "dvdchannel",       1,          0,      'c' },
113     {   "dvdsubtitle",      1,          0,      's' },
114     
115     /* Input options */
116     {   "novlans",          0,          0,      OPT_NOVLANS },
117     {   "server",           1,          0,      OPT_SERVER },
118     {   "port",             1,          0,      OPT_PORT },
119
120     {   0,                  0,          0,      0 }
121 };
122
123 /* Short options */
124 static const char *psz_shortopts = "hHvga:s:c:";
125
126 /*****************************************************************************
127  * Global variable program_data - this is the one and only, see main.h
128  *****************************************************************************/
129 main_t *p_main;
130
131 /*****************************************************************************
132  * Local prototypes
133  *****************************************************************************/
134 static void SetDefaultConfiguration ( void );
135 static int  GetConfiguration        ( int i_argc, char *ppsz_argv[], char *ppsz_env[] );
136 static void Usage                   ( int i_fashion );
137 static void Version                 ( void );
138
139 static void InitSignalHandler       ( void );
140 static void SignalHandler           ( int i_signal );
141 #ifdef HAVE_MMX
142 static int  TestMMX                 ( void );
143 #endif
144
145 /*****************************************************************************
146  * main: parse command line, start interface and spawn threads
147  *****************************************************************************
148  * Steps during program execution are:
149  *      -configuration parsing and messages interface initialization
150  *      -openning of audio output device and some global modules
151  *      -execution of interface, which exit on error or on user request
152  *      -closing of audio output device and some global modules
153  * On error, the spawned threads are cancelled, and the open devices closed.
154  *****************************************************************************/
155 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
156 {
157     main_t  main_data;                      /* root of all data - see main.h */
158     char **p_playlist;
159     int i_list_index;
160
161     p_main = &main_data;                       /* set up the global variable */
162
163     /*
164      * System specific initialization code
165      */
166 #ifdef SYS_BEOS
167     beos_Init();
168 #endif
169
170     /*
171      * Read configuration, initialize messages interface and set up program
172      */
173 #ifdef HAVE_MMX
174     if( !TestMMX() )
175     {
176         fprintf( stderr, "Sorry, this program needs an MMX processor. Please run the non-MMX version.\n" );
177         return( 1 );
178     }
179 #endif
180     p_main->p_msg = intf_MsgCreate();
181     if( !p_main->p_msg )                         /* start messages interface */
182     {
183         fprintf( stderr, "critical error: can't initialize messages interface (%s)\n",
184                 strerror(errno) );
185         return( errno );
186     }
187     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
188     {
189         intf_MsgDestroy();
190         return( errno );
191     }
192
193     /* get command line files */
194     i_list_index = 0;
195
196     if( optind < i_argc )
197     {
198         int i_index = 0;
199         p_playlist = malloc( (i_list_index = i_argc - optind)
200                                         * sizeof(int) );
201
202         while( i_argc - i_index > optind )
203         {
204             p_playlist[ i_index ] = ppsz_argv[ i_argc - i_index - 1];
205             i_index++;
206         }
207     }
208     else
209     {
210         p_playlist = NULL;
211     }
212
213     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );          /* print welcome message */
214
215     /*
216      * Initialize shared resources and libraries
217      */
218     if( main_data.b_vlans && input_VlanCreate() )
219     {
220         /* On error during vlans initialization, switch of vlans */
221         intf_Msg( "Virtual LANs initialization failed : vlans management is deactivated\n" );
222         main_data.b_vlans = 0;
223     }
224
225     /*
226      * Open audio device and start aout thread
227      */
228     if( main_data.b_audio )
229     {
230         main_data.p_aout = aout_CreateThread( NULL );
231         if( main_data.p_aout == NULL )
232         {
233             /* On error during audio initialization, switch of audio */
234             intf_Msg( "Audio initialization failed : audio is deactivated\n" );
235             main_data.b_audio = 0;
236         }
237     }
238
239     /*
240      * Run interface
241      */
242     main_data.p_intf = intf_Create();
243     if( main_data.p_intf != NULL )
244     {
245         main_data.p_intf->p_playlist = p_playlist;
246         main_data.p_intf->i_list_index = i_list_index;
247
248         InitSignalHandler();             /* prepare signals for interception */
249
250         intf_Run( main_data.p_intf );
251         intf_Destroy( main_data.p_intf );
252     }
253
254     /*
255      * Close audio device
256      */
257     if( main_data.b_audio )
258     {
259         aout_DestroyThread( main_data.p_aout, NULL );
260     }
261
262     /*
263      * Free shared resources and libraries
264      */
265     if( main_data.b_vlans )
266     {
267         input_VlanDestroy();
268     }
269
270     /*
271      * System specific cleaning code
272      */
273 #ifdef SYS_BEOS
274     beos_Clean();
275 #endif
276
277     /*
278      * Terminate messages interface and program
279      */
280     intf_Msg( "Program terminated.\n" );
281     intf_MsgDestroy();
282     return( 0 );
283 }
284
285 /*****************************************************************************
286  * main_GetIntVariable: get the int value of an environment variable
287  *****************************************************************************
288  * This function is used to read some default parameters in modules.
289  *****************************************************************************/
290 int main_GetIntVariable( char *psz_name, int i_default )
291 {
292     char *      psz_env;                                /* environment value */
293     char *      psz_end;                             /* end of parsing index */
294     long int    i_value;                                            /* value */
295
296     psz_env = getenv( psz_name );
297     if( psz_env )
298     {
299         i_value = strtol( psz_env, &psz_end, 0 );
300         if( (*psz_env != '\0') && (*psz_end == '\0') )
301         {
302             return( i_value );
303         }
304     }
305     return( i_default );
306 }
307
308 /*****************************************************************************
309  * main_GetPszVariable: get the string value of an environment variable
310  *****************************************************************************
311  * This function is used to read some default parameters in modules.
312  *****************************************************************************/
313 char * main_GetPszVariable( char *psz_name, char *psz_default )
314 {
315     char *psz_env;
316
317     psz_env = getenv( psz_name );
318     if( psz_env )
319     {
320         return( psz_env );
321     }
322     return( psz_default );
323 }
324
325 /*****************************************************************************
326  * main_PutPszVariable: set the string value of an environment variable
327  *****************************************************************************
328  * This function is used to set some default parameters in modules. The use of
329  * this function will cause some memory leak: since some systems use the pointer
330  * passed to putenv to store the environment string, it can't be freed.
331  *****************************************************************************/
332 void main_PutPszVariable( char *psz_name, char *psz_value )
333 {
334     char *psz_env;
335
336     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
337     if( psz_env == NULL )
338     {
339         intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
340     }
341     else
342     {
343         sprintf( psz_env, "%s=%s", psz_name, psz_value );
344         if( putenv( psz_env ) )
345         {
346             intf_ErrMsg( "error: %s\n", strerror(errno) );
347         }
348     }
349 }
350
351 /*****************************************************************************
352  * main_PutIntVariable: set the integer value of an environment variable
353  *****************************************************************************
354  * This function is used to set some default parameters in modules. The use of
355  * this function will cause some memory leak: since some systems use the pointer
356  * passed to putenv to store the environment string, it can't be freed.
357  *****************************************************************************/
358 void main_PutIntVariable( char *psz_name, int i_value )
359 {
360     char psz_value[ 256 ];                               /* buffer for value */
361
362     sprintf( psz_value, "%d", i_value );
363     main_PutPszVariable( psz_name, psz_value );
364 }
365
366 /* following functions are local */
367
368 /*****************************************************************************
369  * SetDefaultConfiguration: set default options
370  *****************************************************************************
371  * This function is called by GetConfiguration before command line is parsed.
372  * It sets all the default values required later by the program. At this stage,
373  * most structure are not yet allocated, so initialization must be done using
374  * environment.
375  *****************************************************************************/
376 static void SetDefaultConfiguration( void )
377 {
378     /*
379      * All features are activated by default
380      */
381     p_main->b_audio  = 1;
382     p_main->b_video  = 1;
383     p_main->b_vlans  = 1;
384 }
385
386 /*****************************************************************************
387  * GetConfiguration: parse command line
388  *****************************************************************************
389  * Parse command line and configuration file for configuration. If the inline
390  * help is requested, the function Usage() is called and the function returns
391  * -1 (causing main() to exit). The messages interface is initialized at this
392  * stage, but most structures are not allocated, so only environment should
393  * be used.
394  *****************************************************************************/
395 static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
396 {
397     int c, i_opt;
398
399     /* Set default configuration and copy arguments */
400     p_main->i_argc    = i_argc;
401     p_main->ppsz_argv = ppsz_argv;
402     p_main->ppsz_env  = ppsz_env;
403     SetDefaultConfiguration();
404
405     /* Parse command line options */
406     opterr = 0;
407     while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
408     {
409         switch( c )
410         {
411         /* General/common options */
412         case 'h':                                              /* -h, --help */
413             Usage( SHORT_HELP );
414             return( -1 );
415             break;
416         case 'H':                                          /* -H, --longhelp */
417             Usage( LONG_HELP );
418             return( -1 );
419             break;
420         case 'v':                                           /* -v, --version */
421             Version();
422             return( -1 );
423             break;
424
425         /* Audio options */
426         case OPT_NOAUDIO:                                       /* --noaudio */
427             p_main->b_audio = 0;
428             break;
429         case OPT_AOUT:                                             /* --aout */
430             main_PutPszVariable( AOUT_METHOD_VAR, optarg );
431             break;
432         case OPT_STEREO:                                         /* --stereo */
433             main_PutIntVariable( AOUT_STEREO_VAR, 1 );
434             break;
435         case OPT_MONO:                                             /* --mono */
436             main_PutIntVariable( AOUT_STEREO_VAR, 0 );
437             break;
438
439         /* Video options */
440         case OPT_NOVIDEO:                                       /* --novideo */
441             p_main->b_video = 0;
442             break;
443         case OPT_VOUT:                                             /* --vout */
444             main_PutPszVariable( VOUT_METHOD_VAR, optarg );
445             break;
446         case OPT_DISPLAY:                                       /* --display */
447             main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
448             break;
449         case OPT_WIDTH:                                           /* --width */
450             main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
451             break;
452         case OPT_HEIGHT:                                         /* --height */
453             main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
454             break;
455
456         case 'g':                                         /* -g, --grayscale */
457             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
458             break;
459         case OPT_COLOR:                                           /* --color */
460             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
461             break;
462
463         /* DVD options */
464         case 'a':
465             if ( ! strcmp(optarg, "mpeg") )
466                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
467             else if ( ! strcmp(optarg, "lpcm") )
468                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
469             else if ( ! strcmp(optarg, "off") )
470                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
471             else
472                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
473             break;
474         case 'c':
475             main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
476             break;
477         case 's':
478             main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
479             break;
480
481         /* Input options */
482         case OPT_NOVLANS:                                       /* --novlans */
483             p_main->b_vlans = 0;
484             break;
485         case OPT_SERVER:                                         /* --server */
486             main_PutPszVariable( INPUT_SERVER_VAR, optarg );
487             break;
488         case OPT_PORT:                                             /* --port */
489             main_PutPszVariable( INPUT_PORT_VAR, optarg );
490             break;
491
492         /* Internal error: unknown option */
493         case '?':
494         default:
495             intf_ErrMsg( "intf error: unknown option `%s'\n", ppsz_argv[optind - 1] );
496             Usage( USAGE );
497             return( EINVAL );
498             break;
499         }
500     }
501
502     /* Parse command line parameters - no check is made for these options */
503     for( i_opt = optind; i_opt < i_argc; i_opt++ )
504     {
505         putenv( ppsz_argv[ i_opt ] );
506     }
507     return( 0 );
508 }
509
510 /*****************************************************************************
511  * Usage: print program usage
512  *****************************************************************************
513  * Print a short inline help. Message interface is initialized at this stage.
514  *****************************************************************************/
515 static void Usage( int i_fashion )
516 {
517     /* Usage */
518     intf_Msg( "Usage: vlc [options] [parameters]\n" );
519
520     if( i_fashion == USAGE )
521     {
522         intf_Msg( "Try `vlc --help' for more information.\n" );
523         return;
524     }
525
526     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );
527
528     /* Options */
529     intf_Msg( "\n"
530               "Options:\n"
531               "      --noaudio                  \tdisable audio\n"
532               "      --aout <plugin>            \taudio output method\n"
533               "      --stereo, --mono           \tstereo/mono audio\n"
534               "\n"
535               "      --novideo                  \tdisable video\n"
536               "      --vout <plugin>            \tvideo output method\n"
537               "      --display <display>        \tdisplay string\n"
538               "      --width <w>, --height <h>  \tdisplay dimensions\n"
539               "  -g, --grayscale                \tgrayscale output\n"
540               "      --color                    \tcolor output\n"
541               "\n"
542               "  -a, --dvdaudio                 \tchoose DVD audio type\n"
543               "  -c, --dvdchannel               \tchoose DVD audio channel\n"
544               "  -s, --dvdsubtitle              \tchoose DVD subtitle channel\n"
545               "\n"
546               "      --novlans                  \tdisable vlans\n"
547               "      --server <host>            \tvideo server address\n"
548               "      --port <port>              \tvideo server port\n"
549               "\n"
550               "  -h, --help                     \tprint help and exit\n"
551               "  -H, --longhelp                 \tprint long help and exit\n"
552               "  -v, --version                  \toutput version information and exit\n" );
553
554     if( i_fashion == SHORT_HELP )
555         return;
556
557     /* Interface parameters */
558     intf_Msg( "\n"
559               "Interface parameters:\n"
560               "  " INTF_INIT_SCRIPT_VAR "=<filename>             \tinitialization script\n"
561               "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n" );
562
563     /* Audio parameters */
564     intf_Msg( "\n"
565               "Audio parameters:\n"
566               "  " AOUT_METHOD_VAR "=<method name>        \taudio method\n"
567               "  " AOUT_DSP_VAR "=<filename>              \tdsp device path\n"
568               "  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output\n"
569               "  " AOUT_RATE_VAR "=<rate>             \toutput rate\n" );
570
571     /* Video parameters */
572     intf_Msg( "\n"
573               "Video parameters:\n"
574               "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method\n"
575               "  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used\n"
576               "  " VOUT_WIDTH_VAR "=<width>               \tdisplay width\n"
577               "  " VOUT_HEIGHT_VAR "=<height>             \tdislay height\n"
578               "  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path\n"
579               "  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output\n" );
580
581     /* DVD parameters */
582     intf_Msg( "\n"
583               "DVD parameters:\n"
584               "  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type\n"
585               "  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel\n"
586               "  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel\n" );
587
588     /* Input parameters */
589     intf_Msg( "\n"
590               "Input parameters:\n"
591               "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n"
592               "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n"
593               "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"
594               "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n"
595               "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n" );
596 }
597
598 /*****************************************************************************
599  * Version: print complete program version
600  *****************************************************************************
601  * Print complete program version and build number.
602  *****************************************************************************/
603 static void Version( void )
604 {
605     intf_Msg( VERSION_MESSAGE
606               "This program comes with NO WARRANTY, to the extent permitted by law.\n"
607               "You may redistribute it under the terms of the GNU General Public License;\n"
608               "see the file named COPYING for details.\n"
609               "Written by the VideoLAN team at Ecole Centrale, Paris.\n" );
610
611 }
612
613 /*****************************************************************************
614  * InitSignalHandler: system signal handler initialization
615  *****************************************************************************
616  * Set the signal handlers. SIGTERM is not intercepted, because we need at
617  * at least a method to kill the program when all other methods failed, and
618  * when we don't want to use SIGKILL.
619  *****************************************************************************/
620 static void InitSignalHandler( void )
621 {
622     /* Termination signals */
623     signal( SIGHUP,  SignalHandler );
624     signal( SIGINT,  SignalHandler );
625     signal( SIGQUIT, SignalHandler );
626 }
627
628 /*****************************************************************************
629  * SignalHandler: system signal handler
630  *****************************************************************************
631  * This function is called when a signal is received by the program. It tries to
632  * end the program in a clean way.
633  *****************************************************************************/
634 static void SignalHandler( int i_signal )
635 {
636     /* Once a signal has been trapped, the termination sequence will be armed and
637      * following signals will be ignored to avoid sending messages to an interface
638      * having been destroyed */
639     signal( SIGHUP,  SIG_IGN );
640     signal( SIGINT,  SIG_IGN );
641     signal( SIGQUIT, SIG_IGN );
642
643     /* Acknowledge the signal received */
644     intf_ErrMsgImm("intf: signal %d received\n", i_signal );
645
646     /* Try to terminate everything - this is done by requesting the end of the
647      * interface thread */
648     p_main->p_intf->b_die = 1;
649 }
650
651 #ifdef HAVE_MMX
652 /*****************************************************************************
653  * TestMMX: tests if the processor has MMX support.
654  *****************************************************************************
655  * This function is called if HAVE_MMX is enabled, to check whether the
656  * cpu really supports MMX.
657  *****************************************************************************/
658 static int TestMMX( void )
659 {
660 /* FIXME: under beos, gcc does not support the foolowing inline assembly */ 
661 #ifdef SYS_BEOS
662     return( 1 );
663 #else
664
665     int i_reg, i_dummy = 0;
666
667     /* test for a 386 cpu */
668     asm volatile ( "pushfl
669                     popl %%eax
670                     movl %%eax, %%ecx
671                     xorl $0x40000, %%eax
672                     pushl %%eax
673                     popfl
674                     pushfl
675                     popl %%eax
676                     xorl %%ecx, %%eax
677                     andl $0x40000, %%eax"
678                  : "=a" ( i_reg ) );
679
680     if( !i_reg )
681         return( 0 );
682
683     /* test for a 486 cpu */
684     asm volatile ( "movl %%ecx, %%eax
685                     xorl $0x200000, %%eax
686                     pushl %%eax
687                     popfl
688                     pushfl
689                     popl %%eax
690                     xorl %%ecx, %%eax
691                     pushl %%ecx
692                     popfl
693                     andl $0x200000, %%eax"
694                  : "=a" ( i_reg ) );
695
696     if( !i_reg )
697         return( 0 );
698
699     /* the cpu supports the CPUID instruction - get its level */
700     asm volatile ( "cpuid"
701                  : "=a" ( i_reg ),
702                    "=b" ( i_dummy ),
703                    "=c" ( i_dummy ),
704                    "=d" ( i_dummy )
705                  : "a"  ( 0 ),       /* level 0 */
706                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
707
708     /* this shouldn't happen on a normal cpu */
709     if( !i_reg )
710         return( 0 );
711
712     /* test for the MMX flag */
713     asm volatile ( "cpuid
714                     andl $0x00800000, %%edx" /* X86_FEATURE_MMX */
715                  : "=a" ( i_dummy ),
716                    "=b" ( i_dummy ),
717                    "=c" ( i_dummy ),
718                    "=d" ( i_reg )
719                  : "a"  ( 1 ),       /* level 1 */
720                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
721
722     if( !i_reg )
723         return( 0 );
724
725     return( 1 );
726
727 #endif
728 }
729 #endif