New developer version 0.6.8; added select () function; added demonstrating example...
[ZeXOS.git] / kernel / arch / i386 / arch.c
blob2bccc45d7d78bb1390db54aece4bfeebb8a25dbc
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 static unsigned long read_pentium_clock ()
25 register unsigned lb;
26 register unsigned hb;
28 __asm__ __volatile__ ("rdtsc" : "=a" (lb), "=d" (hb));
30 return( ((unsigned long) hb) << 24 | lb );
33 void cpu_info ()
35 printf ("CPU: i386 compatibile\nClock: %lu MHz\n", read_pentium_clock ());
38 /* enable interrupts */
39 unsigned int_enable ()
41 __asm__ __volatile__("sti"
46 return 1;
49 /* disable interrupts */
50 unsigned int_disable ()
52 unsigned ret;
54 __asm__ __volatile__("pushfl\n"
55 "popl %0\n"
56 "cli"
57 : "=a"(ret)
58 :);
60 return ret;
63 /* wait one tick */
64 void arch_cpu_hlt ()
66 #ifndef CONFIG_COMPAT_QEMU /* dont know, but it is probably Qemu bug, because it hard halt cpu */
67 asm volatile ("hlt");
68 #endif
71 unsigned arch_cpu_reset ()
73 outb (0x64, 0xFE);
75 return 1;
78 unsigned arch_cpu_shutdown ()
81 return 1;
84 /* architecture initialization process */
85 unsigned init_arch ()
87 if (!gdt_install ())
88 return 0;
90 if (!idt_install ())
91 return 0;
93 if (!isrs_install ())
94 return 0;
96 if (!irq_install ())
97 return 0;
99 if (!timer_install ())
100 return 0;
102 return 1;