[PATCH 2 of 5] General improvements to arch dependent code
Juan Perez-Sanchez <[email protected]>
| Newsgroups | org.kernel.vger.linux-8086 |
|---|---|
| Message-ID | <CAD6VGubZOn4nR-Yctnj8jNqZHj5u6PxNe+xUbQpv1PsCaTgvaA@mail.gmail.com> |
Hi, This patch rationalises the code in files "arch/i86/kernel/irq.c" and "arch/i86/kernel/timer.c". Now the file irq.c contains only code related to interrupt handling, and file timer.c contains all timer code. Resulting code in this files is easier to understand. After building the image, code size was unchanged. The kernel was built and the Image tested in qemu and dioscuri emulators. Also tested in a ppro pc booting from floppy. Greetings, Juan
elksC.patch
(application/octet-stream, 7.5 KB)
diff -Nurb elks.orig/arch/i86/kernel/irq.c elks/arch/i86/kernel/irq.c --- elks.orig/arch/i86/kernel/irq.c 2012-05-11 13:26:27.000000000 -0500 +++ elks/arch/i86/kernel/irq.c 2012-05-24 10:12:51.000000000 -0500 @@ -12,12 +12,6 @@ * * 9/1999 For ROM debuggers you can configure that not all interrupts * disable. - * 9/1999 The 100 Hz system timer 0 can configure for variable input - * frequency. Christian Mardm"oller ([email protected]) - * - * 4/2001 Use macros to directly generate timer constants based on the - * value of HZ macro. This works the same for both the 8253 and - * 8254 timers. - Thomas McWilliams <[email protected]> */ #include <linuxmt/config.h> @@ -27,7 +21,6 @@ #include <linuxmt/kernel.h> #include <linuxmt/sched.h> #include <linuxmt/timer.h> -#include <linuxmt/timex.h> #include <linuxmt/types.h> #include <arch/io.h> @@ -65,11 +58,6 @@ return irq; } -static void arch_init_IRQ(void) -{ - /* Do nothing */ -} - #else /* @@ -124,41 +112,6 @@ return irq; } -/* These 8253/8254 macros generate proper timer constants based on the - * timer tick macro HZ which is defined in timex.h (usually 100 Hz). - * - * The PC timer chip can be programmed to divide its reference frequency - * by a 16 bit unsigned number. The reference frequency of 1193181.8 Hz - * happens to be 1/3 of the NTSC color burst frequency. In fact, the - * hypothetical exact reference frequency for the timer is 39375000/33 Hz. - * The macros use scaled fixed point arithmetic for greater accuracy. - */ - -#define TIMER_CMDS_PORT ((void *) 0x43) /* command port */ -#define TIMER_DATA_PORT ((void *) 0x40) /* data port */ - -#define TIMER_MODE0 0x30 /* timer 0, binary count, mode 0, lsb/msb */ -#define TIMER_MODE2 0x34 /* timer 0, binary count, mode 2, lsb/msb */ - -#define TIMER_LO_BYTE (__u8)(((5+(11931818L/(HZ)))/10)%256) -#define TIMER_HI_BYTE (__u8)(((5+(11931818L/(HZ)))/10)/256) - -static void arch_init_IRQ(void) -{ - /* Stop the timer */ - outb (TIMER_MODE0, TIMER_CMDS_PORT); - outb (0, TIMER_DATA_PORT); - outb (0, TIMER_DATA_PORT); -} - -void enable_timer_tick(void) -{ - /* set the clock frequency */ - outb (TIMER_MODE2, TIMER_CMDS_PORT); - outb (TIMER_LO_BYTE, TIMER_DATA_PORT); /* LSB */ - outb (TIMER_HI_BYTE, TIMER_DATA_PORT); /* MSB */ -} - #endif /* @@ -288,7 +241,7 @@ cache_21 = inb_p(0x21); #endif - arch_init_IRQ(); + stop_timer(); /* Old IRQ 8 handler is nuked in this routine */ irqtab_init(); /* Store DS */ diff -Nurb elks.orig/arch/i86/kernel/irqtab.c elks/arch/i86/kernel/irqtab.c --- elks.orig/arch/i86/kernel/irqtab.c 2012-05-11 13:26:27.000000000 -0500 +++ elks/arch/i86/kernel/irqtab.c 2012-05-24 10:01:45.000000000 -0500 @@ -218,7 +218,6 @@ .data .extern _cache_A1 .extern _cache_21 - .extern _jiffies .text diff -Nurb elks.orig/arch/i86/kernel/timer.c elks/arch/i86/kernel/timer.c --- elks.orig/arch/i86/kernel/timer.c 2012-05-11 13:26:27.000000000 -0500 +++ elks/arch/i86/kernel/timer.c 2012-05-24 10:01:45.000000000 -0500 @@ -1,28 +1,55 @@ #include <linuxmt/config.h> #include <linuxmt/timer.h> +#include <linuxmt/timex.h> + +#include <arch/io.h> /* - * Test timer tick routine + * Timer tick routine + * + * 9/1999 The 100 Hz system timer 0 can configure for variable input + * frequency. Christian Mardm"oller ([email protected]) + * + * 4/2001 Use macros to directly generate timer constants based on the + * value of HZ macro. This works the same for both the 8253 and + * 8254 timers. - Thomas McWilliams <[email protected]> */ -unsigned long jiffies=0; +jiff_t jiffies = 0; extern void do_timer(struct pt_regs *); extern void keyboard_irq(int, struct pt_regs *, void *); -void timer_tick(int irq, struct pt_regs *regs, void *data) -{ #ifndef CONFIG_ARCH_SIBO - do_timer(regs); +/* These 8253/8254 macros generate proper timer constants based on the + * timer tick macro HZ which is defined in timex.h (usually 100 Hz). + * + * The PC timer chip can be programmed to divide its reference frequency + * by a 16 bit unsigned number. The reference frequency of 1193181.8 Hz + * happens to be 1/3 of the NTSC color burst frequency. In fact, the + * hypothetical exact reference frequency for the timer is 39375000/33 Hz. + * The macros use scaled fixed point arithmetic for greater accuracy. + */ + +#define TIMER_CMDS_PORT ((void *) 0x43) /* command port */ +#define TIMER_DATA_PORT ((void *) 0x40) /* data port */ + +#define TIMER_MODE0 0x30 /* timer 0, binary count, mode 0, lsb/msb */ +#define TIMER_MODE2 0x34 /* timer 0, binary count, mode 2, lsb/msb */ + +#define TIMER_LO_BYTE (__u8)(((5+(11931818L/(HZ)))/10)%256) +#define TIMER_HI_BYTE (__u8)(((5+(11931818L/(HZ)))/10)/256) -#ifdef NEED_RESCHED /* need_resched is not checked anywhere */ - if (((int)jiffies & 7) == 0) - need_resched=1; /* how primitive can you get? */ #endif -#ifndef S_SPLINT_S +void timer_tick(int irq, struct pt_regs *regs, void *data) +{ + do_timer(regs); +#ifndef CONFIG_ARCH_SIBO + +#ifndef S_SPLINT_S #if 0 #asm ! rotate the 20th character on the 3rd screen line @@ -34,24 +61,16 @@ pop es #endasm #endif - -#ifdef CONFIG_DEBUG_TIMER -#asm - mov al,_jiffies - out 0x80,al -#endasm #endif +#ifdef CONFIG_DEBUG_TIMER + outb (jiffies, 0x80); #endif #else - jiffies++; - - -#ifndef S_SPLINT_S - /* As we are now responsible for clearing interrupt */ +#ifndef S_SPLINT_S #asm cli mov ax, #0x0000 @@ -62,18 +81,6 @@ out 0x10, al sti #endasm - -#endif - -#if 0 - -#ifdef NEED_RESCHED /* need_resched is not checked anywhere */ - - if (!((int) jiffies & 7)) - need_resched=1; /* how primitive can you get? */ - -#endif - #endif keyboard_irq(1, regs, NULL); @@ -81,21 +88,28 @@ #endif } -#ifdef CONFIG_ARCH_SIBO - void enable_timer_tick(void) { -#ifndef S_SPLINT_S -#asm - mov al, #0x00 - out 0x15, al +#ifndef CONFIG_ARCH_SIBO + /* set the clock frequency */ + outb (TIMER_MODE2, TIMER_CMDS_PORT); + outb (TIMER_LO_BYTE, TIMER_DATA_PORT); /* LSB */ + outb (TIMER_HI_BYTE, TIMER_DATA_PORT); /* MSB */ - mov al, #0x02 - out 0x08, al -#endasm -#endif +#else + outb (0x00, 0x15); + outb (0x02, 0x08); printk("Timer enabled...\n"); + +#endif } +void stop_timer(void) +{ +#ifndef CONFIG_ARCH_SIBO + outb (TIMER_MODE0, TIMER_CMDS_PORT); + outb (0, TIMER_DATA_PORT); + outb (0, TIMER_DATA_PORT); #endif +} diff -Nurb elks.orig/arch/i86/sibo/irqtab.c elks/arch/i86/sibo/irqtab.c --- elks.orig/arch/i86/sibo/irqtab.c 2012-05-11 13:26:27.000000000 -0500 +++ elks/arch/i86/sibo/irqtab.c 2012-05-24 10:01:45.000000000 -0500 @@ -173,7 +173,6 @@ .extern _cache_A1 .extern _cache_21 - .extern _jiffies .text diff -Nurb elks.orig/include/linuxmt/timer.h elks/include/linuxmt/timer.h --- elks.orig/include/linuxmt/timer.h 2012-05-11 13:26:27.000000000 -0500 +++ elks/include/linuxmt/timer.h 2012-05-24 10:01:45.000000000 -0500 @@ -90,5 +90,6 @@ extern int del_timer(struct timer_list *); extern void timer_tick(int, struct pt_regs *, void *); extern void enable_timer_tick(void); +extern void stop_timer(void); #endif diff -Nurb elks.orig/kernel/sched.c elks/kernel/sched.c --- elks.orig/kernel/sched.c 2012-05-11 13:26:27.000000000 -0500 +++ elks/kernel/sched.c 2012-05-24 10:01:53.000000000 -0500 @@ -286,7 +286,13 @@ void do_timer(struct pt_regs *regs) { - (*(jiff_t *) & jiffies)++; + jiffies++; + +#ifdef NEED_RESCHED /* need_resched is not checked anywhere */ + if (!((int) jiffies & 7)) + need_resched = 1; /* how primitive can you get? */ +#endif + } void sched_init(void)