From d106968d775084f3bc3cfad9bd51c3d92674f74e Mon Sep 17 00:00:00 2001 From: Kees van Reeuwijk Date: Thu, 22 Apr 2010 07:49:40 +0000 Subject: [PATCH] Remove useless symbol declarations from headers, make symbols local where possible, add some explicit initialization to global variables. --- kernel/arch/i386/apic.c | 34 +++++++++--------- kernel/arch/i386/apic.h | 25 ------------- kernel/arch/i386/breakpoints.c | 2 +- kernel/arch/i386/exception.c | 2 +- kernel/arch/i386/i8259.c | 20 +++++------ kernel/arch/i386/proto.h | 2 -- kernel/glo.h | 3 +- kernel/interrupt.c | 3 +- kernel/main.c | 2 +- kernel/proto.h | 4 --- kernel/system.c | 65 +++++++++++++++++----------------- kernel/watchdog.c | 2 +- 12 files changed, 68 insertions(+), 96 deletions(-) diff --git a/kernel/arch/i386/apic.c b/kernel/arch/i386/apic.c index 9d39aa969..25406a642 100644 --- a/kernel/arch/i386/apic.c +++ b/kernel/arch/i386/apic.c @@ -45,25 +45,27 @@ #define VERBOSE_APIC(x) x -PUBLIC int reboot_type; -PUBLIC int ioapic_enabled; -PUBLIC u32_t ioapic_id_mask[8], lapic_id_mask[8]; +PRIVATE int reboot_type; +PRIVATE int ioapic_enabled; +PRIVATE u32_t ioapic_id_mask[8]; +PRIVATE u32_t lapic_id_mask[8]; PUBLIC u32_t lapic_addr_vaddr; PUBLIC vir_bytes lapic_addr; PUBLIC vir_bytes lapic_eoi_addr; -PUBLIC u32_t lapic_taskpri_addr; -PUBLIC int bsp_lapic_id; +PRIVATE u32_t lapic_taskpri_addr; PRIVATE volatile int probe_ticks; PRIVATE u64_t tsc0, tsc1; PRIVATE u32_t lapic_tctr0, lapic_tctr1; -u8_t apicid2cpuid[MAX_NR_APICIDS+1]; -unsigned apic_imcrp; -unsigned nioapics; -unsigned nbuses; -unsigned nintrs; -unsigned nlints; +/* FIXME: this is only accessed from assembly, never from C. Move to asm? */ +PUBLIC u8_t apicid2cpuid[MAX_NR_APICIDS+1]; /* Accessed from asm */ + +PRIVATE unsigned apic_imcrp; +PRIVATE unsigned nioapics; +PRIVATE unsigned nbuses; +PRIVATE unsigned nintrs; +PRIVATE const unsigned nlints = 0; /* * FIXME this should be a cpulocal variable but there are some problems with @@ -100,7 +102,7 @@ PRIVATE int calib_clk_handler(irq_hook_t * UNUSED(hook)) return 1; } -PUBLIC void apic_calibrate_clocks(void) +PRIVATE void apic_calibrate_clocks(void) { u32_t lvtt, val, lapic_delta; u64_t tsc_delta; @@ -213,19 +215,19 @@ PUBLIC void lapic_stop_timer(void) lapic_write(LAPIC_LVTTR, lvtt | APIC_LVTT_MASK); } -PUBLIC void lapic_microsec_sleep(unsigned count) +PRIVATE void lapic_microsec_sleep(unsigned count) { lapic_set_timer_one_shot(count); while (lapic_read (LAPIC_TIMER_CCR)); } -PUBLIC u32_t lapic_errstatus (void) +PRIVATE u32_t lapic_errstatus(void) { lapic_write(LAPIC_ESR, 0); return lapic_read(LAPIC_ESR); } -PUBLIC void lapic_disable(void) +PRIVATE void lapic_disable(void) { /* Disable current APIC and close interrupts from PIC */ u32_t val; @@ -432,7 +434,7 @@ PRIVATE void lapic_set_dummy_handlers(void) #endif /* Build descriptors for interrupt gates in IDT. */ -PUBLIC void apic_idt_init(const int reset) +PRIVATE void apic_idt_init(const int reset) { /* Set up idt tables for smp mode. */ diff --git a/kernel/arch/i386/apic.h b/kernel/arch/i386/apic.h index 45f8c9cb4..82bffa97c 100644 --- a/kernel/arch/i386/apic.h +++ b/kernel/arch/i386/apic.h @@ -92,11 +92,8 @@ #include "kernel/kernel.h" -EXTERN int ioapic_enabled; EXTERN vir_bytes lapic_addr; EXTERN u32_t lapic_eoi_addr; -EXTERN u32_t lapic_taskpri_addr; -EXTERN int bsp_lapic_id; #define MAX_NR_IOAPICS 32 #define MAX_NR_BUSES 32 @@ -104,39 +101,17 @@ EXTERN int bsp_lapic_id; #define MAX_NR_LCLINTS 2 EXTERN u8_t apicid2cpuid[MAX_NR_APICIDS+1]; -EXTERN unsigned apic_imcrp; -EXTERN unsigned nioapics; -EXTERN unsigned nbuses; -EXTERN unsigned nintrs; -EXTERN unsigned nlints; -EXTERN u32_t ioapic_id_mask[8]; -EXTERN u32_t lapic_id_mask[8]; EXTERN u32_t lapic_addr_vaddr; /* we remember the virtual address here until we switch to paging */ -_PROTOTYPE (void calc_bus_clock, (void)); -_PROTOTYPE (u32_t lapic_errstatus, (void)); /* _PROTOTYPE (u32_t ioapic_read, (u32_t addr, u32_t offset)); _PROTOTYPE (void ioapic_write, (u32_t addr, u32_t offset, u32_t data)); _PROTOTYPE (void lapic_eoi, (void)); */ -_PROTOTYPE (void lapic_microsec_sleep, (unsigned count)); -_PROTOTYPE (void smp_ioapic_unmask, (void)); -_PROTOTYPE (void ioapic_disable_irqs, (u32_t irq)); -_PROTOTYPE (void ioapic_enable_irqs, (u32_t irq)); -_PROTOTYPE (u32_t ioapic_irqs_inuse, (void)); -_PROTOTYPE (void smp_recv_ipi, (int arg)); -_PROTOTYPE (void ioapic_config_pci_irq, (u32_t data)); _PROTOTYPE (int lapic_enable, (void)); -_PROTOTYPE (void lapic_disable, (void)); - -_PROTOTYPE (void ioapic_disable_all, (void)); -_PROTOTYPE (int ioapic_enable_all, (void)); - -_PROTOTYPE(void apic_idt_init, (int reset)); _PROTOTYPE(int apic_single_cpu_init, (void)); diff --git a/kernel/arch/i386/breakpoints.c b/kernel/arch/i386/breakpoints.c index 189cb26c3..2863a90f9 100644 --- a/kernel/arch/i386/breakpoints.c +++ b/kernel/arch/i386/breakpoints.c @@ -3,7 +3,7 @@ #include "debugreg.h" -int breakpoint_set(phys_bytes linaddr, int bp, const int flags) +PRIVATE int breakpoint_set(phys_bytes linaddr, int bp, const int flags) { u32_t dr7, dr7flags; diff --git a/kernel/arch/i386/exception.c b/kernel/arch/i386/exception.c index 84cc18b3d..6a87223d5 100644 --- a/kernel/arch/i386/exception.c +++ b/kernel/arch/i386/exception.c @@ -11,7 +11,7 @@ #include "kernel/proc.h" #include "kernel/proto.h" -extern int catch_pagefaults; +extern int catch_pagefaults = 0; void pagefault( struct proc *pr, struct exception_frame * frame, diff --git a/kernel/arch/i386/i8259.c b/kernel/arch/i386/i8259.c index cc0bc419e..a2b0b6c8b 100644 --- a/kernel/arch/i386/i8259.c +++ b/kernel/arch/i386/i8259.c @@ -23,6 +23,16 @@ #define ICW4_PC_AEOI_SLAVE 0x0B /* not SFNM, buffered, auto EOI, 8086 */ #define ICW4_PC_AEOI_MASTER 0x0F /* not SFNM, buffered, auto EOI, 8086 */ +/*===========================================================================* + * intr_disabled * + *===========================================================================*/ +PRIVATE int intr_disabled(void) +{ + if(!(read_cpu_flags() & X86_FLAG_I)) + return 1; + return 0; +} + /*===========================================================================* * intr_init * *===========================================================================*/ @@ -73,16 +83,6 @@ PUBLIC int intr_init(const int mine, const int auto_eoi) return OK; } -/*===========================================================================* - * intr_disabled * - *===========================================================================*/ -PUBLIC int intr_disabled(void) -{ - if(!(read_cpu_flags() & X86_FLAG_I)) - return 1; - return 0; -} - PUBLIC void irq_8259_unmask(const int irq) { const unsigned ctl_mask = irq < 8 ? INT_CTLMASK : INT2_CTLMASK; diff --git a/kernel/arch/i386/proto.h b/kernel/arch/i386/proto.h index e421510ce..041e9d447 100644 --- a/kernel/arch/i386/proto.h +++ b/kernel/arch/i386/proto.h @@ -170,8 +170,6 @@ _PROTOTYPE(void __user_copy_msg_pointer_failure, (void)); #define BREAKPOINT_FLAG_MODE_LOCAL (1 << 4) #define BREAKPOINT_FLAG_MODE_GLOBAL (2 << 4) -_PROTOTYPE(int breakpoint_set, (phys_bytes linaddr, int index, int flags)); - /* functions defined in architecture-independent kernel source. */ #include "kernel/proto.h" diff --git a/kernel/glo.h b/kernel/glo.h index d3042d3dd..0868c461a 100644 --- a/kernel/glo.h +++ b/kernel/glo.h @@ -39,13 +39,12 @@ EXTERN int irq_use; /* map of all in-use irq's */ EXTERN u32_t system_hz; /* HZ value */ /* Miscellaneous. */ -EXTERN reg_t mon_ss, mon_sp; /* boot monitor stack */ +EXTERN reg_t mon_sp; /* boot monitor stack */ EXTERN int mon_return; /* true if we can return to monitor */ EXTERN int do_serial_debug; EXTERN time_t boottime; EXTERN char params_buffer[512]; /* boot monitor parameters */ EXTERN int minix_panicing; -EXTERN int locklevel; EXTERN char fpu_presence; EXTERN char osfxsr_feature; /* FXSAVE/FXRSTOR instructions support (SSEx) */ EXTERN int verboseboot; /* verbose boot, init'ed in cstart */ diff --git a/kernel/interrupt.c b/kernel/interrupt.c index 00d0310da..d315c19e6 100644 --- a/kernel/interrupt.c +++ b/kernel/interrupt.c @@ -21,7 +21,8 @@ #include "hw_intr.h" /* number of lists of IRQ hooks, one list per supported line. */ -PUBLIC irq_hook_t* irq_handlers[NR_IRQ_VECTORS] = {0}; +PRIVATE irq_hook_t* irq_handlers[NR_IRQ_VECTORS] = {0}; + /*===========================================================================* * put_irq_handler * *===========================================================================*/ diff --git a/kernel/main.c b/kernel/main.c index 500f68573..ffee52cf4 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -25,7 +25,7 @@ FORWARD _PROTOTYPE( void announce, (void)); /*===========================================================================* * main * *===========================================================================*/ -PUBLIC void main() +PUBLIC void main(void) { /* Start the ball rolling. */ struct boot_image *ip; /* boot image pointer */ diff --git a/kernel/proto.h b/kernel/proto.h index da4e8c25a..2cd5befc6 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -69,7 +69,6 @@ _PROTOTYPE( void system_init, (void) ); umap_local(proc_addr(proc_nr), D, (vir_addr), (bytes)) _PROTOTYPE( phys_bytes umap_grant, (struct proc *, cp_grant_id_t, vir_bytes)); _PROTOTYPE( void clear_endpoint, (struct proc *rc) ); -_PROTOTYPE( void clear_ipc, (struct proc *rc) ); _PROTOTYPE( void clear_ipc_refs, (struct proc *rc, int caller_ret) ); _PROTOTYPE( phys_bytes umap_bios, (vir_bytes vir_addr, vir_bytes bytes)); _PROTOTYPE( void kernel_call_resume, (struct proc *p)); @@ -136,8 +135,6 @@ _PROTOTYPE( void alloc_segments, (struct proc *rp) ); _PROTOTYPE( void vm_init, (struct proc *first) ); _PROTOTYPE( phys_bytes umap_local, (register struct proc *rp, int seg, vir_bytes vir_addr, vir_bytes bytes)); -_PROTOTYPE( void cp_mess, (int src,phys_clicks src_clicks, - vir_bytes src_offset, phys_clicks dst_clicks, vir_bytes dst_offset)); _PROTOTYPE( phys_bytes umap_remote, (const struct proc* rp, int seg, vir_bytes vir_addr, vir_bytes bytes) ); _PROTOTYPE( phys_bytes umap_virtual, (struct proc* rp, @@ -148,7 +145,6 @@ _PROTOTYPE( int vm_phys_memset, (phys_bytes source, u8_t pattern, _PROTOTYPE( vir_bytes alloc_remote_segment, (u32_t *, segframe_t *, int, phys_bytes, vir_bytes, int)); _PROTOTYPE( int intr_init, (int, int) ); -_PROTOTYPE( int intr_disabled, (void) ); _PROTOTYPE( void halt_cpu, (void) ); _PROTOTYPE( void arch_init, (void) ); _PROTOTYPE( void ser_putc, (char) ); diff --git a/kernel/system.c b/kernel/system.c index e49a20009..5510112c3 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -49,8 +49,8 @@ * because the dummy is declared extern. If an illegal call is given, the * array size will be negative and this won't compile. */ -PUBLIC int (*call_vec[NR_SYS_CALLS])(struct proc * caller, message *m_ptr); -char *callnames[NR_SYS_CALLS]; +PRIVATE int (*call_vec[NR_SYS_CALLS])(struct proc * caller, message *m_ptr); +PRIVATE char *callnames[NR_SYS_CALLS]; #define map(call_nr, handler) \ {extern int dummy[NR_SYS_CALLS>(unsigned)(call_nr-KERNEL_CALL) ? 1:-1];} \ @@ -473,6 +473,37 @@ vir_bytes bytes; /* size */ return ret; } +/*===========================================================================* + * clear_ipc * + *===========================================================================*/ +PRIVATE void clear_ipc( + register struct proc *rc /* slot of process to clean up */ +) +{ +/* Clear IPC data for a given process slot. */ + struct proc **xpp; /* iterate over caller queue */ + + if (RTS_ISSET(rc, RTS_SENDING)) { + int target_proc; + + okendpt(rc->p_sendto_e, &target_proc); + xpp = &proc_addr(target_proc)->p_caller_q; /* destination's queue */ + while (*xpp) { /* check entire queue */ + if (*xpp == rc) { /* process is on the queue */ + *xpp = (*xpp)->p_q_link; /* replace by next process */ +#if DEBUG_ENABLE_IPC_WARNINGS + printf("endpoint %d / %s removed from queue at %d\n", + rc->p_endpoint, rc->p_name, rc->p_sendto_e); +#endif + break; /* can only be queued once */ + } + xpp = &(*xpp)->p_q_link; /* proceed to next queued */ + } + rc->p_rts_flags &= ~RTS_SENDING; + } + rc->p_rts_flags &= ~RTS_RECEIVING; +} + /*===========================================================================* * clear_endpoint * *===========================================================================*/ @@ -501,36 +532,6 @@ register struct proc *rc; /* slot of process to clean up */ } -/*===========================================================================* - * clear_ipc * - *===========================================================================*/ -PUBLIC void clear_ipc(rc) -register struct proc *rc; /* slot of process to clean up */ -{ -/* Clear IPC data for a given process slot. */ - struct proc **xpp; /* iterate over caller queue */ - - if (RTS_ISSET(rc, RTS_SENDING)) { - int target_proc; - - okendpt(rc->p_sendto_e, &target_proc); - xpp = &proc_addr(target_proc)->p_caller_q; /* destination's queue */ - while (*xpp) { /* check entire queue */ - if (*xpp == rc) { /* process is on the queue */ - *xpp = (*xpp)->p_q_link; /* replace by next process */ -#if DEBUG_ENABLE_IPC_WARNINGS - printf("endpoint %d / %s removed from queue at %d\n", - rc->p_endpoint, rc->p_name, rc->p_sendto_e); -#endif - break; /* can only be queued once */ - } - xpp = &(*xpp)->p_q_link; /* proceed to next queued */ - } - rc->p_rts_flags &= ~RTS_SENDING; - } - rc->p_rts_flags &= ~RTS_RECEIVING; -} - /*===========================================================================* * clear_ipc_refs * *===========================================================================*/ diff --git a/kernel/watchdog.c b/kernel/watchdog.c index c10b4d6d4..489532e36 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -6,7 +6,7 @@ #include "watchdog.h" -unsigned watchdog_local_timer_ticks; +unsigned watchdog_local_timer_ticks = 0U; struct arch_watchdog *watchdog; int watchdog_enabled;