/*	boot.h - Info between different parts of boot.	Author: Kees J. Bot
 */

/* Constants describing the metal: */

#define SECTOR_SIZE	512
#define SECTOR_SHIFT	9
#define RATIO		(BLOCK_SIZE / SECTOR_SIZE)
#define HRATIO		(SECTOR_SIZE / HCLICK_SIZE)

#define PARAMSEC	1	/* Sector containing boot parameters. */

#define DSKBASE		0x1E	/* Floppy disk parameter vector. */
#define DSKPARSIZE	11	/* There are this many bytes of parameters. */

#define ESC		'\33'	/* Escape key. */

#define HEADERSEG	0x0060	/* Place for an array of struct exec's. */

#define MINIXSEG	0x0080	/* Minix is loaded here (rounded up towards
				 * the click size).
				 */
#define BOOTSEG		0x07C0	/* Bootstraps are loaded here. */
#define SIGNATURE	0xAA55	/* Proper bootstraps have this signature. */
#define SIGNATPOS	510	/* Offset within bootblock. */

#define FREESEG		0x0800	/* Memory from FREESEG to cseg is free to
				 * play with.
				 */

/* Scan codes for four different keyboards (from kernel/keyboard.c). */
#define DUTCH_EXT_SCAN	  32	/* 'd' */
#define OLIVETTI_SCAN	  12	/* '=' key on olivetti */
#define STANDARD_SCAN	  13	/* '=' key on IBM */
#define US_EXT_SCAN	  22	/* 'u' */


/* Variables shared with boothead.s: */
#ifndef EXTERN
#define EXTERN extern
#endif

typedef struct vector {
	u16_t	offset;
	u16_t	segment;
} vector;

EXTERN vector rem_part;		/* Boot partition table entry. */

EXTERN u16_t cseg, dseg;	/* Code and data segment of the boot program. */
EXTERN u32_t runsize;		/* Size of this program. */

EXTERN u16_t device;		/* Drive being booted from. */
EXTERN u16_t heads, sectors;	/* its number of heads and sectors. */

extern u16_t eqscancode;	/* Set by peek/getchar() if they see a '='. */


/* Functions defined by boothead.s: */

void reboot();		/* When disaster strikes. */
void raw_copy();	/* Copy bytes from anywhere to anywhere. */
void raw_clear();	/* Clear bytes anywhere. */
u16_t get_word();	/* Get a word from anywhere. */
void put_word();	/* Put a word anywhere. */
void relocate();	/* Switch to a copy of this program. */
int dev_geometry();	/* Set parameters for the current device. */
int readsectors();	/* Read 1 or more sectors from "device". */
int writesectors();	/* Write 1 or more sectors to "device". */
int getchar();		/* Blocking read for a keyboard character. */
int peekchar();		/* Nonblocking keyboard read. */
void putchar();		/* Send a character to the screen. */
void reset_video();	/* Reset and clear the screen. */
void set_cursor();	/* Set cursor to a given column and row. */

u16_t get_video();	/* Display type, from MDA to color VGA. */
u16_t get_ext_memsize();/* Amount of extended memory in K. */
u16_t get_low_memsize();/* Amount of low memory in K. */
u16_t get_processor();	/* Processor type (86, 186, 286, 386). */
u32_t get_tick();	/* Current value of the clock tick counter. */
#define MSEC_PER_TICK	55	/* 18.2 ticks per second. */

void bootstrap();	/* Execute a bootstrap routine loaded at 0x07C00. */
void minix86();		/* Start 8086 Minix. */
void minix386();	/* Start 80386 Minix by switching to 386 mode. */


/* Shared between boot.c and bootimage.c: */

/* Sticky attributes. */
#define E_SPECIAL	0x01	/* These are known to the program. */
#define E_DEV		0x02	/* The value is a device name. */
#define E_RESERVED	0x04	/* May not be set by user, e.g. scancode */
#define E_STICKY	0x07	/* Don't go once set. */
/* Volatile attributes. */
#define E_VAR		0x08	/* Variable */
#define E_FUNCTION	0x10	/* Function definition. */

typedef struct environment {
	struct environment *next;
	char	flags;
	char	*name;		/* name = value */
	char	*arg;		/* name(arg) {value} */
	char	*value;
	char	*defval;	/* Safehouse for default values. */
} environment;

EXTERN environment *env;	/* Lists the environment. */

char *b_value();		/* Get the value of a variable. */

EXTERN int fsok;	/* True if the boot device contains an FS. */
EXTERN u32_t lowsec;	/* Offset to the file system on the boot device. */

/* Called by boot.c: */

void minix();			/* Load and start a Minix image. */


/* Called by bootimage.c: */

void readerr();		/* Report a read error. */
char *u2a(), *ul2a();	/* Transform an u16_t or u32_t to decimal. */
long a2l();		/* Cheap atol() */
dev_t name2dev();	/* Translate a device name to a device number. */
int numprefix();	/* True for a numeric prefix. */
int numeric();		/* True for a numeric string. */
char *unix_err();	/* Give a descriptive text for some UNIX errors. */
void invalidate_cache();/* About to load an image where the cache sits. */
void init_cache();	/* Turn the block cache back on. */
int delay();		/* Delay for several millisec. */
