require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_MODULE_H_)) {
    eval 'sub _SYS_MODULE_H_ () {1;}' unless defined(&_SYS_MODULE_H_);
    require 'sys/types.ph';
    require 'sys/param.ph';
    require 'sys/cdefs.ph';
    require 'sys/uio.ph';
    eval 'sub MAXMODNAME () {32;}' unless defined(&MAXMODNAME);
    eval 'sub MAXMODDEPS () {10;}' unless defined(&MAXMODDEPS);
    eval("sub MODULE_CLASS_ANY () { 0; }") unless defined(&MODULE_CLASS_ANY);
    eval("sub MODULE_CLASS_MISC () { 1; }") unless defined(&MODULE_CLASS_MISC);
    eval("sub MODULE_CLASS_VFS () { 2; }") unless defined(&MODULE_CLASS_VFS);
    eval("sub MODULE_CLASS_DRIVER () { 3; }") unless defined(&MODULE_CLASS_DRIVER);
    eval("sub MODULE_CLASS_EXEC () { 4; }") unless defined(&MODULE_CLASS_EXEC);
    eval("sub MODULE_CLASS_SECMODEL () { 5; }") unless defined(&MODULE_CLASS_SECMODEL);
    eval("sub MODULE_CLASS_BUFQ () { 6; }") unless defined(&MODULE_CLASS_BUFQ);
    eval("sub MODULE_CLASS_MAX () { 7; }") unless defined(&MODULE_CLASS_MAX);
    eval("sub MODULE_SOURCE_KERNEL () { 0; }") unless defined(&MODULE_SOURCE_KERNEL);
    eval("sub MODULE_SOURCE_BOOT () { 1; }") unless defined(&MODULE_SOURCE_BOOT);
    eval("sub MODULE_SOURCE_FILESYS () { 2; }") unless defined(&MODULE_SOURCE_FILESYS);
    eval("sub MODULE_CMD_INIT () { 0; }") unless defined(&MODULE_CMD_INIT);
    eval("sub MODULE_CMD_FINI () { 1; }") unless defined(&MODULE_CMD_FINI);
    eval("sub MODULE_CMD_STAT () { 2; }") unless defined(&MODULE_CMD_STAT);
    eval("sub MODULE_CMD_AUTOUNLOAD () { 3; }") unless defined(&MODULE_CMD_AUTOUNLOAD);
    if(defined(&_KERNEL)) {
	require 'sys/kernel.ph';
	require 'sys/mutex.ph';
	require 'sys/queue.ph';
	require 'sys/specificdata.ph';
	require 'prop/proplib.ph';
	eval 'sub MODFLG_MUST_FORCE () {0x1;}' unless defined(&MODFLG_MUST_FORCE);
	eval 'sub MODFLG_AUTO_LOADED () {0x2;}' unless defined(&MODFLG_AUTO_LOADED);
	if(defined(&RUMP_USE_CTOR)) {
	    eval 'sub _MODULE_REGISTER {
	        my($name) = @_;
    		eval q( &static \'struct modinfo_chain\'  &__CONCAT( &mc,$name) = { . &mc_info = & &__CONCAT($name, &_modinfo), };  &static  &void  &__CONCAT( &modctor_,$name)( &void)  &__attribute__(( &__constructor__)); &static  &void  &__CONCAT( &modctor_,$name)( &void) {  &extern \'struct modinfo_boot_chain\'  &modinfo_boot_chain;  &if ( &cold) { \'struct modinfo_chain\' * &mc = & &__CONCAT( &mc,$name);  &LIST_INSERT_HEAD( &modinfo_boot_chain,  &mc,  &mc_entries); } }  &static  &void  &__CONCAT( &moddtor_,$name)( &void)  &__attribute__(( &__destructor__)); &static  &void  &__CONCAT( &moddtor_,$name)( &void) { \'struct modinfo_chain\' * &mc = & &__CONCAT( &mc,$name);  &if ( &cold) {  &LIST_REMOVE( &mc,  &mc_entries); } });
	    }' unless defined(&_MODULE_REGISTER);
	} else {
	    eval 'sub _MODULE_REGISTER {
	        my($name) = @_;
    		eval q( &__link_set_add_rodata( &modules,  &__CONCAT($name, &_modinfo)););
	    }' unless defined(&_MODULE_REGISTER);
	}
	eval 'sub MODULE {
	    my($class, $name, $required) = @_;
    	    eval q( &static \'int\'  &__CONCAT($name, &_modcmd)( &modcmd_t,  &void *);  &static  &const  &modinfo_t  &__CONCAT($name, &_modinfo) = { . &mi_version =  &__NetBSD_Version__, . &mi_class = ($class), . &mi_modcmd =  &__CONCAT($name, &_modcmd), . &mi_name =  &__STRING($name), . &mi_required = ($required) };  &_MODULE_REGISTER($name));
	}' unless defined(&MODULE);
	if(defined(&_MODULE_INTERNAL)) {
	}
	eval 'sub MODULE_BASE_SIZE () {64;}' unless defined(&MODULE_BASE_SIZE);
    } else {
	require 'stdint.ph';
    }
    eval 'sub MODCTL_NO_PROP () {0x2;}' unless defined(&MODCTL_NO_PROP);
    eval 'sub MODCTL_LOAD_FORCE () {0x1;}' unless defined(&MODCTL_LOAD_FORCE);
    eval("sub MODCTL_LOAD () { 0; }") unless defined(&MODCTL_LOAD);
    eval("sub MODCTL_UNLOAD () { 1; }") unless defined(&MODCTL_UNLOAD);
    eval("sub MODCTL_OSTAT () { 2; }") unless defined(&MODCTL_OSTAT);
    eval("sub MODCTL_EXISTS () { 3; }") unless defined(&MODCTL_EXISTS);
    eval("sub MODCTL_STAT () { 4; }") unless defined(&MODCTL_STAT);
    if(defined(&_KERNEL)) {
    }
}
1;
