taskswitch.c 794 Bytes
Newer Older
1
2
3
4
5
6
7
8
/*
 * Copyright 2010 Siemens AG
 * Author: Jan Kiszka
 *
 * Released under GPLv2.
 */

#include "libcflat.h"
Andrew Jones's avatar
Andrew Jones committed
9
#include "x86/desc.h"
10

11
#define TSS_RETURN		(FIRST_SPARE_SEL)
12
13
14
15
16
17

void fault_entry(void);

static __attribute__((used, regparm(1))) void
fault_handler(unsigned long error_code)
{
18
19
	print_current_tss_info();
	printf("error code %x\n", error_code);
20

21
	tss.eip += 2;
22

23
	gdt32[TSS_MAIN / 8].access &= ~2;
24

25
	set_gdt_task_gate(TSS_RETURN, tss_intr.prev);
26
27
28
29
30
31
}

asm (
	"fault_entry:\n"
	"	mov (%esp),%eax\n"
	"	call fault_handler\n"
32
	"	jmp $" xstr(TSS_RETURN) ", $0\n"
33
34
35
36
37
38
);

int main(int ac, char **av)
{
	const long invalid_segment = 0x1234;

39
40
	setup_tss32();
	set_intr_task_gate(13, fault_entry);
41
42
43
44
45
46
47
48
49
50

	asm (
		"mov %0,%%es\n"
		: : "r" (invalid_segment) : "edi"
	);

	printf("post fault\n");

	return 0;
}