#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/nodes.h>
#include <exec/resident.h>
#include <exec/errors.h>
#include <libraries/expansionbase.h>
#include <libraries/configvars.h>
#include <devices/trackdisk.h>

/*
 * Set SysBase to a local variable, that loads directly from 4 when it
 * has to be reloaded
 */
#define BASE_EXT_DECL
#define BASE_NAME (*(void **)4)
#include <inline/exec.h>
#include <inline/expansion.h>

#include <stddef.h>

#include "device.h"

/*
 * ATTENTION: this whole file is HEAVILY compiler dependent! It uses
 * several tricks to convince gcc to put certain DATA into the TEXT
 * part of the object file... the resident-tag HAS to be in the first
 * hunk, so this kludge is necessary...
 */

/* this trick makes "main" the ENTRY of the whole file... */
int main() asm(".begin"); /* don't use _main, use .begin for this symbol */

int
main()
{
  /* return an error, if the user tried to run us */
  return 20;
}

/*
 * this trick is quite dirty... we need to garantee, that our init-tag
 * goes into the code-hunk. Only in this arrangement, this seems to
 * work... this depends too on the fact, that we will compile this file
 * with the -fwritable-strings option:-))
 * HACK HACK HACK HACK... 
 */

static char *foo = SCSI_NAME;
static char *foo2 = SCSI_IDSTRING;

/* linker-symbol: end of code-hunk */
extern void end();
extern ulong Init[];

/*
 * gcc now thinks we're already in the .data part, and will not produce
 * a .data before the struct definition, therefore it's safe to output
 * the switch to .text mode 
 */
asm(".text");
struct Resident initDDescrip = {
  RTC_MATCHWORD,
  &initDDescrip,
  (APTR)end,
  RTF_AUTOINIT,
  SCSI_VERSION,
  NT_DEVICE,
  SCSI_PRIORITY,
  SCSI_NAME,
  SCSI_IDSTRING,
  (APTR)Init,
};
asm ("	.data");
