Changeset 9a5b556 in mainline


Ignore:
Timestamp:
2006-09-12T13:03:55Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6eabb6e6
Parents:
7bb6b06
Message:

sparc64 work:

  • find a CPU node and read its clock_frequency attribute
  • implement asm_delay_loop()
  • set TICK_COMPARE register according to processor frequency
  • small improvements at random places

OpenFirmware work:

  • two new functions for walking the device tree

Generic boot loader work:

  • added basic string functions

Usual pile of indentation and formatting fixes.

Files:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/sparc64/loader/Makefile

    r7bb6b06 r9a5b556  
    5252        main.c \
    5353        ../../../generic/printf.c \
     54        ../../../generic/string.c \
    5455        ../../../genarch/ofw.c \
    5556        ofwarch.c \
  • boot/arch/sparc64/loader/main.c

    r7bb6b06 r9a5b556  
    6767                printf("Error: unable to get keyboard properties\n");
    6868
     69        if (!ofw_cpu(&bootinfo.cpu))
     70                printf("Error: unable to get cpu properties\n");
     71
    6972        printf("\nDevice statistics\n");
     73        printf(" cpu: %dMHz\n", bootinfo.cpu.clock_frequency/1000000);
    7074        printf(" memory: %dM\n", bootinfo.memmap.total>>20);
    7175        printf(" screen at %P, resolution %dx%d, %d bpp (scanline %d bytes)\n", (uintptr_t) bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height, bootinfo.screen.bpp, bootinfo.screen.scanline);
  • boot/arch/sparc64/loader/main.h

    r7bb6b06 r9a5b556  
    4646
    4747typedef struct {
     48        uint32_t clock_frequency;
     49} cpu_t;
     50
     51typedef struct {
    4852        taskmap_t taskmap;
    4953        memmap_t memmap;
    5054        screen_t screen;
    5155        keyboard_t keyboard;
     56        cpu_t cpu;
    5257} bootinfo_t;
    5358
  • boot/arch/sparc64/loader/ofwarch.c

    r7bb6b06 r9a5b556  
    3535#include <ofw.h>
    3636#include <printf.h>
     37#include <string.h>
     38#include "main.h"
    3739
    3840int bpp2align[] = {
     
    8082        return true;
    8183}
     84
     85int ofw_cpu(cpu_t *cpu)
     86{
     87        char type_name[BUF_SIZE];
     88
     89        phandle node;
     90        node = ofw_get_child_node(ofw_root);
     91        if (node == 0 || node == -1) {
     92                printf("Could not find any child nodes of the root node.\n");
     93                return;
     94        }
     95       
     96        for (; node != 0 && node != -1; node = ofw_get_peer_node(node)) {
     97                if (ofw_get_property(node, "device_type", type_name, sizeof(type_name)) > 0) {
     98                        if (strncmp(type_name, "cpu", 3) == 0) {
     99                                uint32_t mhz;
     100                               
     101                                if (ofw_get_property(node, "clock-frequency", &mhz, sizeof(mhz)) <= 0)
     102                                        continue;
     103                                       
     104                                cpu->clock_frequency = mhz;
     105                                return 1;
     106                        }
     107                }
     108        };
     109
     110        return 0;
     111}
  • boot/arch/sparc64/loader/ofwarch.h

    r7bb6b06 r9a5b556  
    3030#define BOOT_sparc64_OFWARCH_H_
    3131
     32#include "main.h"
     33
    3234#define OFW_ADDRESS_CELLS       2
    3335#define OFW_SIZE_CELLS          2
     
    3537extern int bpp2align[];
    3638
     39extern int ofw_cpu(cpu_t *cpu);
     40
    3741#endif
  • boot/genarch/ofw.c

    r7bb6b06 r9a5b556  
    146146}
    147147
     148phandle ofw_get_child_node(const phandle node)
     149{
     150        return ofw_call("child", 1, 1, NULL, node);
     151}
     152
     153phandle ofw_get_peer_node(const phandle node)
     154{
     155        return ofw_call("peer", 1, 1, NULL, node);
     156}
    148157
    149158static ihandle ofw_open(const char *name)
  • boot/genarch/ofw.h

    r7bb6b06 r9a5b556  
    9191extern uintptr_t ofw_cif;
    9292
     93
     94extern phandle ofw_chosen;
     95extern ihandle ofw_stdout;
     96extern phandle ofw_root;
     97extern ihandle ofw_mmu;
     98extern phandle ofw_memory;
    9399extern phandle ofw_aliases;
    94100
    95101extern void ofw_init(void);
     102
    96103extern void ofw_write(const char *str, const int len);
    97104
    98105extern int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen);
     106
     107extern phandle ofw_get_child_node(const phandle node);
     108extern phandle ofw_get_peer_node(const phandle node);
    99109extern phandle ofw_find_device(const char *name);
    100110
  • boot/generic/gentypes.h

    r7bb6b06 r9a5b556  
    3434#define true 1
    3535
     36typedef unsigned long size_t;
     37
    3638#endif
  • kernel/arch/ia64/src/drivers/it.c

    r7bb6b06 r9a5b556  
    2727 */
    2828
    29  /** @addtogroup ia64   
     29/** @addtogroup ia64   
    3030 * @{
    3131 */
     
    7777        eoi_write(EOI);
    7878       
    79         m=itm_read();
     79        m = itm_read();
    8080       
    81         while(1)
    82         {
    83        
    84                 c=itc_read();
    85                 c+=IT_SERVICE_CLOCKS;
     81        while (1) {
     82                c = itc_read();
     83                c += IT_SERVICE_CLOCKS;
    8684
    87                 m+=IT_DELTA;
    88                 if(m-c<0)
    89                 {
     85                m += IT_DELTA;
     86                if (m-c<0)
    9087                        CPU->missed_clock_ticks++;
    91                 }
    92                 else break;
     88                else
     89                        break;
    9390        }
    9491       
     
    9693        srlz_d();                               /* propagate changes */
    9794       
    98        
    99        
    10095        clock();
    10196        poll_keyboard();
    10297}
    10398
    104  /** @}
     99/** @}
    105100 */
    106 
  • kernel/arch/mips32/include/asm.h

    r7bb6b06 r9a5b556  
    6767                          uintptr_t entry);
    6868
     69extern ipl_t interrupts_disable(void);
     70extern ipl_t interrupts_enable(void);
     71extern void interrupts_restore(ipl_t ipl);
     72extern ipl_t interrupts_read(void);
     73
    6974#endif
    7075
  • kernel/arch/mips32/src/interrupt.c

    r7bb6b06 r9a5b556  
    2727 */
    2828
    29  /** @addtogroup mips32interrupt
     29/** @addtogroup mips32interrupt
    3030 * @{
    3131 */
     
    142142}
    143143
    144  /** @}
     144/** @}
    145145 */
    146146
  • kernel/arch/sparc64/include/asm.h

    r7bb6b06 r9a5b556  
    3636#define KERN_sparc64_ASM_H_
    3737
     38#include <arch.h>
    3839#include <typedefs.h>
    3940#include <arch/types.h>
    4041#include <arch/register.h>
    4142#include <config.h>
     43#include <time/clock.h>
    4244
    4345/** Read Processor State register.
     
    336338extern void cpu_halt(void);
    337339extern void cpu_sleep(void);
    338 extern void asm_delay_loop(uint32_t t);
     340extern void asm_delay_loop(const uint32_t usec);
    339341
    340342extern uint64_t read_from_ag_g7(void);
  • kernel/arch/sparc64/include/boot/boot.h

    r7bb6b06 r9a5b556  
    8484
    8585typedef struct {
     86        uint32_t clock_frequency;
     87} processor_t;
     88
     89typedef struct {
    8690        taskmap_t taskmap;
    8791        memmap_t memmap;
    8892        screen_t screen;
    8993        keyboard_t keyboard;
     94        processor_t processor;
    9095} bootinfo_t;
    9196
  • kernel/arch/sparc64/include/cpu.h

    r7bb6b06 r9a5b556  
    5353struct cpu_arch {
    5454        ver_reg_t ver;
     55        uint32_t clock_frequency;
    5556};
    5657       
  • kernel/arch/sparc64/include/drivers/tick.h

    r7bb6b06 r9a5b556  
    3838#include <typedefs.h>
    3939
    40 #define TICK_DELTA        500000
    41 
    4240extern void tick_init(void);
    4341extern void tick_interrupt(int n, istate_t *istate);
  • kernel/arch/sparc64/src/cpu/cpu.c

    r7bb6b06 r9a5b556  
    3333 */
    3434
     35#include <arch/asm.h>
    3536#include <cpu.h>
    3637#include <arch.h>
    3738#include <arch/register.h>
    38 #include <arch/asm.h>
    3939#include <print.h>
     40#include <arch/boot/boot.h>
    4041
    4142void cpu_arch_init(void)
    4243{
     44        CPU->arch.clock_frequency = bootinfo.processor.clock_frequency;
    4345}
    4446
     
    9496        }
    9597
    96         printf("cpu%d: manuf=%s, impl=%s, mask=%d\n", CPU->id, manuf, impl, CPU->arch.ver.mask);
     98        printf("cpu%d: manuf=%s, impl=%s, mask=%d (%dMHz)\n",
     99                CPU->id, manuf, impl, CPU->arch.ver.mask, CPU->arch.clock_frequency/1000000);
    97100}
    98101
  • kernel/arch/sparc64/src/drivers/tick.c

    r7bb6b06 r9a5b556  
    3737#include <arch/asm.h>
    3838#include <arch/register.h>
     39#include <typedefs.h>
     40#include <arch/cpu.h>
     41#include <arch/boot/boot.h>
     42#include <time/clock.h>
     43#include <arch.h>
    3944#include <debug.h>
    40 #include <time/clock.h>
    41 #include <typedefs.h>
     45
     46#define TICK_RESTART_TIME       50      /* Worst case estimate. */
    4247
    4348/** Initialize tick interrupt. */
     
    4853        interrupt_register(14, "tick_int", tick_interrupt);
    4954        compare.int_dis = false;
    50         compare.tick_cmpr = TICK_DELTA;
     55        compare.tick_cmpr = bootinfo.processor.clock_frequency/HZ;
    5156        tick_compare_write(compare.value);
    5257        tick_write(0);
     
    6166{
    6267        softint_reg_t softint, clear;
     68        uint64_t next, compare, start, stop;
    6369       
    6470        softint.value = softint_read();
     
    8490         * Restart counter.
    8591         */
    86         tick_write(0);
     92        compare = CPU->arch.clock_frequency/HZ;
     93        start = tick_read();
     94        next = start - compare;
     95        while (next >= compare - TICK_RESTART_TIME) {
     96                next -= compare;
     97                CPU->missed_clock_ticks++;
     98        }
     99        stop = tick_read();
     100        tick_write(next + (stop - start));
    87101       
    88102        clock();
  • kernel/arch/sparc64/src/dummy.s

    r7bb6b06 r9a5b556  
    2929.text
    3030
    31 .global asm_delay_loop
    3231.global cpu_sleep
    3332.global fpu_context_restore
     
    3938.global dummy
    4039
    41 asm_delay_loop:
    4240cpu_sleep:
    4341fpu_context_restore:
  • kernel/arch/sparc64/src/sparc64.c

    r7bb6b06 r9a5b556  
    4343#include <arch/boot/boot.h>
    4444#include <arch/arch.h>
     45#include <arch/asm.h>
    4546#include <arch/mm/page.h>
    4647#include <arch/stack.h>
     
    9091}
    9192
     93/** Calibrate delay loop.
     94 *
     95 * On sparc64, we implement delay() by waiting for the TICK register to
     96 * reach a pre-computed value, as opposed to performing some pre-computed
     97 * amount of instructions of known duration. We set the delay_loop_const
     98 * to 1 in order to neutralize the multiplication done by delay().
     99 */
    92100void calibrate_delay_loop(void)
    93101{
     102        CPU->delay_loop_const = 1;
     103}
     104
     105/** Wait several microseconds.
     106 *
     107 * We assume that interrupts are already disabled.
     108 *
     109 * @param t Microseconds to wait.
     110 */
     111void asm_delay_loop(const uint32_t usec)
     112{
     113        uint64_t stop = tick_read() + (uint64_t) usec * (uint64_t) CPU->arch.clock_frequency / 1000000;
     114
     115        while (tick_read() < stop)
     116                ;
    94117}
    95118
  • kernel/arch/sparc64/src/start.S

    r7bb6b06 r9a5b556  
    6161         */
    6262
    63         flushw                          ! flush all but the active register window
    64         wrpr %g0, 0, %tl                ! TL = 0, primary context register is used
    65 
    66         ! Disable interrupts and disable 32-bit address masking.
    67         rdpr %pstate, %g1
    68         and %g1, ~(PSTATE_AM_BIT|PSTATE_IE_BIT), %g1
    69         wrpr %g1, 0, %pstate
    70 
    71         wrpr %g0, 0, %pil               ! intialize %pil
     63        flushw                                  ! flush all but the active register window
     64
     65        wrpr %g0, 0, %tl                        ! TL = 0, primary context register is used
     66
     67        wrpr %g0, PSTATE_PRIV_BIT, %pstate      ! Disable interrupts and disable 32-bit address masking.
     68
     69        wrpr %g0, 0, %pil                       ! intialize %pil
    7270
    7371        /*
  • kernel/generic/include/arch.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __ARCH_H__
    36 #define __ARCH_H__
     35#ifndef KERN_ARCH_H_
     36#define KERN_ARCH_H_
    3737
    3838#include <arch/types.h>
     
    8080extern void calibrate_delay_loop(void);
    8181
    82 extern ipl_t interrupts_disable(void);
    83 extern ipl_t interrupts_enable(void);
    84 extern void interrupts_restore(ipl_t ipl);
    85 extern ipl_t interrupts_read(void);
    86 
    8782#endif
    8883
  • kernel/generic/include/cpu.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __CPU_H__
    36 #define __CPU_H__
     35#ifndef KERN_CPU_H_
     36#define KERN_CPU_H_
    3737
    3838#include <arch/cpu.h>
  • kernel/generic/include/time/clock.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __CLOCK_H__
    36 #define __CLOCK_H__
     35#ifndef KERN_CLOCK_H_
     36#define KERN_CLOCK_H_
    3737
    3838#define HZ              100
  • kernel/generic/include/time/delay.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __DELAY_H__
    36 #define __DELAY_H__
     35#ifndef KERN_DELAY_H_
     36#define KERN_DELAY_H_
    3737
    3838#include <arch/types.h>
  • kernel/generic/include/time/timeout.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __TIMEOUT_H__
    36 #define __TIMEOUT_H__
     35#ifndef KERN_TIMEOUT_H_
     36#define KERN_TIMEOUT_H_
    3737
    3838#include <arch/types.h>
  • kernel/generic/include/typedefs.h

    r7bb6b06 r9a5b556  
    3333 */
    3434
    35 #ifndef __TYPEDEFS_H__
    36 #define __TYPEDEFS_H__
     35#ifndef KERN_TYPEDEFS_H_
     36#define KERN_TYPEDEFS_H_
    3737
    3838#define false 0
  • kernel/generic/src/cpu/cpu.c

    r7bb6b06 r9a5b556  
    110110}
    111111
    112  /** @}
     112/** @}
    113113 */
    114114
Note: See TracChangeset for help on using the changeset viewer.