setup.c 8.64 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7
/*
 *  linux/arch/i386/kernel/setup.c
 *
 *  Copyright (C) 1995  Linus Torvalds
 */

/*
Linus Torvalds's avatar
Linus Torvalds committed
8
 * This file handles the architecture-dependent parts of initialization
Linus Torvalds's avatar
Linus Torvalds committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22
 */

#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/malloc.h>
#include <linux/ldt.h>
#include <linux/user.h>
#include <linux/a.out.h>
#include <linux/tty.h>
Linus Torvalds's avatar
Linus Torvalds committed
23
#include <linux/ioport.h>
Linus Torvalds's avatar
Linus Torvalds committed
24
#include <linux/delay.h>
Linus Torvalds's avatar
Linus Torvalds committed
25
#include <linux/config.h>
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28

#include <asm/segment.h>
#include <asm/system.h>
Linus Torvalds's avatar
Linus Torvalds committed
29
#include <asm/smp.h>
Linus Torvalds's avatar
Linus Torvalds committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43

/*
 * Tell us the machine setup..
 */
char hard_math = 0;		/* set by boot/head.S */
char x86 = 0;			/* set by boot/head.S to 3 or 4 */
char x86_model = 0;		/* set by boot/head.S */
char x86_mask = 0;		/* set by boot/head.S */
int x86_capability = 0;		/* set by boot/head.S */
int fdiv_bug = 0;		/* set if Pentium(TM) with FP bug */

char x86_vendor_id[13] = "Unknown";

char ignore_irq13 = 0;		/* set if exception 16 works */
Linus Torvalds's avatar
Linus Torvalds committed
44
char wp_works_ok = -1;		/* set if paging hardware honours WP */ 
Linus Torvalds's avatar
Linus Torvalds committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
char hlt_works_ok = 1;		/* set if the "hlt" instruction works */

/*
 * Bus types ..
 */
int EISA_bus = 0;

/*
 * Setup options
 */
struct drive_info_struct { char dummy[32]; } drive_info;
struct screen_info screen_info;

unsigned char aux_device_present;
extern int ramdisk_size;
extern int root_mountflags;
Linus Torvalds's avatar
Linus Torvalds committed
61
extern int _etext, _edata, _end;
Linus Torvalds's avatar
Linus Torvalds committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

extern char empty_zero_page[PAGE_SIZE];

/*
 * This is set up by the setup-routine at boot-time
 */
#define PARAM	empty_zero_page
#define EXT_MEM_K (*(unsigned short *) (PARAM+2))
#define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
#define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
#define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
#define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
#define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
#define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
#define COMMAND_LINE ((char *) (PARAM+2048))
#define COMMAND_LINE_SIZE 256

static char command_line[COMMAND_LINE_SIZE] = { 0, };

void setup_arch(char **cmdline_p,
	unsigned long * memory_start_p, unsigned long * memory_end_p)
{
	unsigned long memory_start, memory_end;
	char c = ' ', *to = command_line, *from = COMMAND_LINE;
	int len = 0;
Linus Torvalds's avatar
Linus Torvalds committed
87 88 89 90 91 92 93
	static unsigned char smptrap=0;

	if(smptrap==1)
	{
		return;
	}
	smptrap=1;
Linus Torvalds's avatar
Linus Torvalds committed
94

Linus Torvalds's avatar
Linus Torvalds committed
95
 	ROOT_DEV = to_kdev_t(ORIG_ROOT_DEV);
Linus Torvalds's avatar
Linus Torvalds committed
96 97 98 99 100 101 102 103 104 105
 	drive_info = DRIVE_INFO;
 	screen_info = SCREEN_INFO;
	aux_device_present = AUX_DEVICE_INFO;
	memory_end = (1<<20) + (EXT_MEM_K<<10);
	memory_end &= PAGE_MASK;
	ramdisk_size = RAMDISK_SIZE;
#ifdef CONFIG_MAX_16M
	if (memory_end > 16*1024*1024)
		memory_end = 16*1024*1024;
#endif
Linus Torvalds's avatar
Linus Torvalds committed
106 107
	if (!MOUNT_ROOT_RDONLY)
		root_mountflags &= ~MS_RDONLY;
Linus Torvalds's avatar
Linus Torvalds committed
108
	memory_start = (unsigned long) &_end;
Linus Torvalds's avatar
Linus Torvalds committed
109
	init_task.mm->start_code = TASK_SIZE;
Linus Torvalds's avatar
Linus Torvalds committed
110 111 112
	init_task.mm->end_code = TASK_SIZE + (unsigned long) &_etext;
	init_task.mm->end_data = TASK_SIZE + (unsigned long) &_edata;
	init_task.mm->brk = TASK_SIZE + (unsigned long) &_end;
Linus Torvalds's avatar
Linus Torvalds committed
113 114

	for (;;) {
Linus Torvalds's avatar
Linus Torvalds committed
115 116 117 118 119
		/*
		 * "mem=nopentium" disables the 4MB page tables.
		 * "mem=XXX[kKmM]" overrides the BIOS-reported
		 * memory size
		 */
Linus Torvalds's avatar
Linus Torvalds committed
120
		if (c == ' ' && *(const unsigned long *)from == *(const unsigned long *)"mem=") {
Linus Torvalds's avatar
Linus Torvalds committed
121 122 123 124 125 126 127 128 129 130 131 132
			if (!memcmp(from+4, "nopentium", 9)) {
				from += 9+4;
				x86_capability &= ~8;
			} else {
				memory_end = simple_strtoul(from+4, &from, 0);
				if ( *from == 'K' || *from == 'k' ) {
					memory_end = memory_end << 10;
					from++;
				} else if ( *from == 'M' || *from == 'm' ) {
					memory_end = memory_end << 20;
					from++;
				}
Linus Torvalds's avatar
Linus Torvalds committed
133 134 135 136 137 138 139 140 141 142 143 144 145
			}
		}
		c = *(from++);
		if (!c)
			break;
		if (COMMAND_LINE_SIZE <= ++len)
			break;
		*(to++) = c;
	}
	*to = '\0';
	*cmdline_p = command_line;
	*memory_start_p = memory_start;
	*memory_end_p = memory_end;
Linus Torvalds's avatar
Linus Torvalds committed
146 147 148 149 150 151
	/* request io space for devices used on all i[345]86 PC'S */
	request_region(0x00,0x20,"dma1");
	request_region(0x40,0x20,"timer");
	request_region(0x70,0x10,"rtc");
	request_region(0x80,0x20,"dma page reg");
	request_region(0xc0,0x20,"dma2");
Linus Torvalds's avatar
Linus Torvalds committed
152
	request_region(0xf0,0x10,"npu");
Linus Torvalds's avatar
Linus Torvalds committed
153
}
Linus Torvalds's avatar
Linus Torvalds committed
154

Linus Torvalds's avatar
Linus Torvalds committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
static const char * i486model(unsigned int nr)
{
	static const char *model[] = {
		"0", "DX","SX","DX/2","4","SX/2","6","DX/2-WB","DX/4"
	};
	if (nr < sizeof(model)/sizeof(char *))
		return model[nr];
	return "Unknown";
}

static const char * i586model(unsigned int nr)
{
	static const char *model[] = {
		"0", "Pentium 60/66","Pentium 75+"
	};
	if (nr < sizeof(model)/sizeof(char *))
		return model[nr];
	return "Unknown";
}

static const char * getmodel(int x86, int model)
{
	switch (x86) {
		case 4:
			return i486model(model);
		case 5:
			return i586model(model);
	}
	return "Unknown";
}

Linus Torvalds's avatar
Linus Torvalds committed
186 187 188
int get_cpuinfo(char * buffer)
{
	char mask[2];
Linus Torvalds's avatar
Linus Torvalds committed
189
#ifndef __SMP__	
Linus Torvalds's avatar
Linus Torvalds committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	mask[0] = x86_mask+'@';
	mask[1] = '\0';
	return sprintf(buffer,"cpu\t\t: %c86\n"
			      "model\t\t: %s\n"
			      "mask\t\t: %s\n"
			      "vid\t\t: %s\n"
			      "fdiv_bug\t: %s\n"
			      "math\t\t: %s\n"
			      "hlt\t\t: %s\n"
			      "wp\t\t: %s\n"
			      "Integrated NPU\t: %s\n"
			      "Enhanced VM86\t: %s\n"
			      "IO Breakpoints\t: %s\n"
			      "4MB Pages\t: %s\n"
			      "TS Counters\t: %s\n"
			      "Pentium MSR\t: %s\n"
			      "Mach. Ch. Exep.\t: %s\n"
			      "CMPXCHGB8B\t: %s\n"
		              "BogoMips\t: %lu.%02lu\n",
			      x86+'0', 
Linus Torvalds's avatar
Linus Torvalds committed
210
			      getmodel(x86, x86_model),
Linus Torvalds's avatar
Linus Torvalds committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
			      x86_mask ? mask : "Unknown",
			      x86_vendor_id,
			      fdiv_bug ? "yes" : "no",
			      hard_math ? "yes" : "no",
			      hlt_works_ok ? "yes" : "no",
			      wp_works_ok ? "yes" : "no",
			      x86_capability & 1 ? "yes" : "no",
			      x86_capability & 2 ? "yes" : "no",
			      x86_capability & 4 ? "yes" : "no",
			      x86_capability & 8 ? "yes" : "no",
			      x86_capability & 16 ? "yes" : "no",
			      x86_capability & 32 ? "yes" : "no",
			      x86_capability & 128 ? "yes" : "no",
			      x86_capability & 256 ? "yes" : "no",
		              loops_per_sec/500000, (loops_per_sec/5000) % 100
			      );
Linus Torvalds's avatar
Linus Torvalds committed
227 228 229 230 231 232 233 234 235 236
#else
	char *bp=buffer;
	int i;	
	bp+=sprintf(bp,"cpu\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%c86             ",cpu_data[i].x86+'0');
	bp+=sprintf(bp,"\nmodel\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
Linus Torvalds's avatar
Linus Torvalds committed
237
			bp+=sprintf(bp,"%-16s",getmodel(cpu_data[i].x86,cpu_data[i].x86_model));
Linus Torvalds's avatar
Linus Torvalds committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
	bp+=sprintf(bp,"\nmask\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
		{
			mask[0] = cpu_data[i].x86_mask+'@';
			mask[1] = '\0';		
			bp+=sprintf(bp,"%-16s", cpu_data[i].x86_mask ? mask : "Unknown");
		}
	bp+=sprintf(bp,"\nvid\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].x86_vendor_id);
	bp+=sprintf(bp,"\nfdiv_bug\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].fdiv_bug?"yes":"no");
	bp+=sprintf(bp,"\nmath\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].hard_math?"yes":"no");
	bp+=sprintf(bp,"\nhlt\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].hlt_works_ok?"yes":"no");
	bp+=sprintf(bp,"\nwp\t\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].wp_works_ok?"yes":"no");
	bp+=sprintf(bp,"\nIntegrated NPU\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].x86_capability&1?"yes":"no");
	bp+=sprintf(bp,"\nEnhanced VM86\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", cpu_data[i].x86_capability&2?"yes":"no");
	bp+=sprintf(bp,"\nIO Breakpoints\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability&4)?"yes":"no");
	bp+=sprintf(bp,"\n4MB Pages\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability)&8?"yes":"no");
	bp+=sprintf(bp,"\nTS Counters\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability&16)?"yes":"no");
	bp+=sprintf(bp,"\nPentium MSR\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability&32)?"yes":"no");
	bp+=sprintf(bp,"\nMach. Ch. Exep.\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability&128)?"yes":"no");
	bp+=sprintf(bp,"\nCMPXCHG8B\t: ");
	for(i=0;i<32;i++)
		if(cpu_present_map&(1<<i))
			bp+=sprintf(bp,"%-16s", (cpu_data[i].x86_capability&256)?"yes":"no");
	bp+=sprintf(bp,"\nBogoMips\t: ");
	for(i=0;i<32;i++)
	{
		char tmp[17];
		if(cpu_present_map&(1<<i))
		{
			sprintf(tmp,"%lu.%02lu",cpu_data[i].udelay_val/500000L,
						   (cpu_data[i].udelay_val/5000L)%100);
			bp+=sprintf(bp,"%-16s",tmp);
		}
	}
	*bp++='\n';
	return bp-buffer;
#endif			      
Linus Torvalds's avatar
Linus Torvalds committed
312
}