Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1880 → Rev 1881

/trunk/kernel/generic/include/time/clock.h
32,8 → 32,8
/** @file
*/
 
#ifndef __CLOCK_H__
#define __CLOCK_H__
#ifndef KERN_CLOCK_H_
#define KERN_CLOCK_H_
 
#define HZ 100
 
/trunk/kernel/generic/include/time/delay.h
32,8 → 32,8
/** @file
*/
 
#ifndef __DELAY_H__
#define __DELAY_H__
#ifndef KERN_DELAY_H_
#define KERN_DELAY_H_
 
#include <arch/types.h>
 
/trunk/kernel/generic/include/time/timeout.h
32,8 → 32,8
/** @file
*/
 
#ifndef __TIMEOUT_H__
#define __TIMEOUT_H__
#ifndef KERN_TIMEOUT_H_
#define KERN_TIMEOUT_H_
 
#include <arch/types.h>
#include <typedefs.h>
/trunk/kernel/generic/include/cpu.h
32,8 → 32,8
/** @file
*/
 
#ifndef __CPU_H__
#define __CPU_H__
#ifndef KERN_CPU_H_
#define KERN_CPU_H_
 
#include <arch/cpu.h>
#include <proc/scheduler.h>
/trunk/kernel/generic/include/arch.h
32,8 → 32,8
/** @file
*/
 
#ifndef __ARCH_H__
#define __ARCH_H__
#ifndef KERN_ARCH_H_
#define KERN_ARCH_H_
 
#include <arch/types.h>
#include <arch/arch.h>
79,11 → 79,6
extern void arch_post_smp_init(void);
extern void calibrate_delay_loop(void);
 
extern ipl_t interrupts_disable(void);
extern ipl_t interrupts_enable(void);
extern void interrupts_restore(ipl_t ipl);
extern ipl_t interrupts_read(void);
 
#endif
 
/** @}
/trunk/kernel/generic/include/typedefs.h
32,8 → 32,8
/** @file
*/
 
#ifndef __TYPEDEFS_H__
#define __TYPEDEFS_H__
#ifndef KERN_TYPEDEFS_H_
#define KERN_TYPEDEFS_H_
 
#define false 0
#define true 1
/trunk/kernel/generic/src/cpu/cpu.c
109,6 → 109,6
}
}
 
/** @}
/** @}
*/
 
/trunk/kernel/arch/sparc64/include/boot/boot.h
83,10 → 83,15
} keyboard_t;
 
typedef struct {
uint32_t clock_frequency;
} processor_t;
 
typedef struct {
taskmap_t taskmap;
memmap_t memmap;
screen_t screen;
keyboard_t keyboard;
processor_t processor;
} bootinfo_t;
 
extern bootinfo_t bootinfo;
/trunk/kernel/arch/sparc64/include/asm.h
35,10 → 35,12
#ifndef KERN_sparc64_ASM_H_
#define KERN_sparc64_ASM_H_
 
#include <arch.h>
#include <typedefs.h>
#include <arch/types.h>
#include <arch/register.h>
#include <config.h>
#include <time/clock.h>
 
/** Read Processor State register.
*
335,7 → 337,7
 
extern void cpu_halt(void);
extern void cpu_sleep(void);
extern void asm_delay_loop(uint32_t t);
extern void asm_delay_loop(const uint32_t usec);
 
extern uint64_t read_from_ag_g7(void);
extern void write_to_ag_g6(uint64_t val);
/trunk/kernel/arch/sparc64/include/cpu.h
52,6 → 52,7
 
struct cpu_arch {
ver_reg_t ver;
uint32_t clock_frequency;
};
#endif
/trunk/kernel/arch/sparc64/include/drivers/tick.h
37,8 → 37,6
 
#include <typedefs.h>
 
#define TICK_DELTA 500000
 
extern void tick_init(void);
extern void tick_interrupt(int n, istate_t *istate);
 
/trunk/kernel/arch/sparc64/src/sparc64.c
42,6 → 42,7
#include <console/console.h>
#include <arch/boot/boot.h>
#include <arch/arch.h>
#include <arch/asm.h>
#include <arch/mm/page.h>
#include <arch/stack.h>
#include <userspace.h>
89,10 → 90,32
thread_ready(t);
}
 
/** Calibrate delay loop.
*
* On sparc64, we implement delay() by waiting for the TICK register to
* reach a pre-computed value, as opposed to performing some pre-computed
* amount of instructions of known duration. We set the delay_loop_const
* to 1 in order to neutralize the multiplication done by delay().
*/
void calibrate_delay_loop(void)
{
CPU->delay_loop_const = 1;
}
 
/** Wait several microseconds.
*
* We assume that interrupts are already disabled.
*
* @param t Microseconds to wait.
*/
void asm_delay_loop(const uint32_t usec)
{
uint64_t stop = tick_read() + (uint64_t) usec * (uint64_t) CPU->arch.clock_frequency / 1000000;
 
while (tick_read() < stop)
;
}
 
/** Switch to userspace. */
void userspace(uspace_arg_t *kernel_uarg)
{
/trunk/kernel/arch/sparc64/src/cpu/cpu.c
32,14 → 32,16
/** @file
*/
 
#include <arch/asm.h>
#include <cpu.h>
#include <arch.h>
#include <arch/register.h>
#include <arch/asm.h>
#include <print.h>
#include <arch/boot/boot.h>
 
void cpu_arch_init(void)
{
CPU->arch.clock_frequency = bootinfo.processor.clock_frequency;
}
 
void cpu_identify(void)
93,7 → 95,8
break;
}
 
printf("cpu%d: manuf=%s, impl=%s, mask=%d\n", CPU->id, manuf, impl, CPU->arch.ver.mask);
printf("cpu%d: manuf=%s, impl=%s, mask=%d (%dMHz)\n",
CPU->id, manuf, impl, CPU->arch.ver.mask, CPU->arch.clock_frequency/1000000);
}
 
/** @}
/trunk/kernel/arch/sparc64/src/dummy.s
28,7 → 28,6
 
.text
 
.global asm_delay_loop
.global cpu_sleep
.global fpu_context_restore
.global fpu_context_save
38,7 → 37,6
 
.global dummy
 
asm_delay_loop:
cpu_sleep:
fpu_context_restore:
fpu_context_save:
/trunk/kernel/arch/sparc64/src/drivers/tick.c
36,10 → 36,15
#include <arch/interrupt.h>
#include <arch/asm.h>
#include <arch/register.h>
#include <typedefs.h>
#include <arch/cpu.h>
#include <arch/boot/boot.h>
#include <time/clock.h>
#include <arch.h>
#include <debug.h>
#include <time/clock.h>
#include <typedefs.h>
 
#define TICK_RESTART_TIME 50 /* Worst case estimate. */
 
/** Initialize tick interrupt. */
void tick_init(void)
{
47,7 → 52,7
interrupt_register(14, "tick_int", tick_interrupt);
compare.int_dis = false;
compare.tick_cmpr = TICK_DELTA;
compare.tick_cmpr = bootinfo.processor.clock_frequency/HZ;
tick_compare_write(compare.value);
tick_write(0);
}
60,6 → 65,7
void tick_interrupt(int n, istate_t *istate)
{
softint_reg_t softint, clear;
uint64_t next, compare, start, stop;
softint.value = softint_read();
83,7 → 89,15
/*
* Restart counter.
*/
tick_write(0);
compare = CPU->arch.clock_frequency/HZ;
start = tick_read();
next = start - compare;
while (next >= compare - TICK_RESTART_TIME) {
next -= compare;
CPU->missed_clock_ticks++;
}
stop = tick_read();
tick_write(next + (stop - start));
clock();
}
/trunk/kernel/arch/sparc64/src/start.S
60,16 → 60,14
* Setup basic runtime environment.
*/
 
flushw ! flush all but the active register window
wrpr %g0, 0, %tl ! TL = 0, primary context register is used
flushw ! flush all but the active register window
 
! Disable interrupts and disable 32-bit address masking.
rdpr %pstate, %g1
and %g1, ~(PSTATE_AM_BIT|PSTATE_IE_BIT), %g1
wrpr %g1, 0, %pstate
wrpr %g0, 0, %tl ! TL = 0, primary context register is used
 
wrpr %g0, 0, %pil ! intialize %pil
wrpr %g0, PSTATE_PRIV_BIT, %pstate ! Disable interrupts and disable 32-bit address masking.
 
wrpr %g0, 0, %pil ! intialize %pil
 
/*
* Copy the bootinfo structure passed from the boot loader
* to the kernel bootinfo structure.
/trunk/kernel/arch/ia64/src/drivers/it.c
26,7 → 26,7
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ia64
/** @addtogroup ia64
* @{
*/
/** @file
76,31 → 76,25
eoi_write(EOI);
m=itm_read();
m = itm_read();
while(1)
{
c=itc_read();
c+=IT_SERVICE_CLOCKS;
while (1) {
c = itc_read();
c += IT_SERVICE_CLOCKS;
 
m+=IT_DELTA;
if(m-c<0)
{
m += IT_DELTA;
if (m-c<0)
CPU->missed_clock_ticks++;
}
else break;
else
break;
}
itm_write(m);
srlz_d(); /* propagate changes */
clock();
poll_keyboard();
}
 
/** @}
/** @}
*/
 
/trunk/kernel/arch/mips32/include/asm.h
66,6 → 66,11
extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg,
uintptr_t entry);
 
extern ipl_t interrupts_disable(void);
extern ipl_t interrupts_enable(void);
extern void interrupts_restore(ipl_t ipl);
extern ipl_t interrupts_read(void);
 
#endif
 
/** @}
/trunk/kernel/arch/mips32/src/interrupt.c
26,7 → 26,7
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup mips32interrupt
/** @addtogroup mips32interrupt
* @{
*/
/** @file
141,6 → 141,6
int_register(irq, "ipc_int", ipc_int);
}
 
/** @}
/** @}
*/
 
/trunk/boot/genarch/ofw.h
90,12 → 90,22
 
extern uintptr_t ofw_cif;
 
 
extern phandle ofw_chosen;
extern ihandle ofw_stdout;
extern phandle ofw_root;
extern ihandle ofw_mmu;
extern phandle ofw_memory;
extern phandle ofw_aliases;
 
extern void ofw_init(void);
 
extern void ofw_write(const char *str, const int len);
 
extern int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen);
 
extern phandle ofw_get_child_node(const phandle node);
extern phandle ofw_get_peer_node(const phandle node);
extern phandle ofw_find_device(const char *name);
 
extern int ofw(ofw_args_t *arg);
/trunk/boot/genarch/ofw.c
145,7 → 145,16
return ret;
}
 
phandle ofw_get_child_node(const phandle node)
{
return ofw_call("child", 1, 1, NULL, node);
}
 
phandle ofw_get_peer_node(const phandle node)
{
return ofw_call("peer", 1, 1, NULL, node);
}
 
static ihandle ofw_open(const char *name)
{
return ofw_call("open", 1, 1, NULL, name);
/trunk/boot/generic/gentypes.h
33,4 → 33,6
#define false 0
#define true 1
 
typedef unsigned long size_t;
 
#endif
/trunk/boot/generic/string.c
0,0 → 1,153
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
 
#include <string.h>
 
/**
* @file
* @brief String manipulation functions.
*/
 
/** Return number of characters in a string.
*
* @param str NULL terminated string.
*
* @return Number of characters in str.
*/
size_t strlen(const char *str)
{
int i;
for (i = 0; str[i]; i++)
;
return i;
}
 
/** Compare two NULL terminated strings
*
* Do a char-by-char comparison of two NULL terminated strings.
* The strings are considered equal iff they consist of the same
* characters on the minimum of their lengths and specified maximal
* length.
*
* @param src First string to compare.
* @param dst Second string to compare.
* @param len Maximal length for comparison.
*
* @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
*
*/
int strncmp(const char *src, const char *dst, size_t len)
{
int i;
i = 0;
for (;*src && *dst && i < len;src++,dst++,i++) {
if (*src < *dst)
return -1;
if (*src > *dst)
return 1;
}
if (i == len || *src == *dst)
return 0;
if (!*src)
return -1;
return 1;
}
 
/** Copy NULL terminated string.
*
* Copy at most 'len' characters from string 'src' to 'dest'.
* If 'src' is shorter than 'len', '\0' is inserted behind the
* last copied character.
*
* @param src Source string.
* @param dest Destination buffer.
* @param len Size of destination buffer.
*/
void strncpy(char *dest, const char *src, size_t len)
{
int i;
for (i = 0; i < len; i++) {
if (!(dest[i] = src[i]))
return;
}
dest[i-1] = '\0';
}
 
/** Convert ascii representation to unative_t
*
* Supports 0x for hexa & 0 for octal notation.
* Does not check for overflows, does not support negative numbers
*
* @param text Textual representation of number
* @return Converted number or 0 if no valid number ofund
*/
unative_t atoi(const char *text)
{
int base = 10;
unative_t result = 0;
 
if (text[0] == '0' && text[1] == 'x') {
base = 16;
text += 2;
} else if (text[0] == '0')
base = 8;
 
while (*text) {
if (base != 16 && \
((*text >= 'A' && *text <= 'F' )
|| (*text >='a' && *text <='f')))
break;
if (base == 8 && *text >='8')
break;
 
if (*text >= '0' && *text <= '9') {
result *= base;
result += *text - '0';
} else if (*text >= 'A' && *text <= 'F') {
result *= base;
result += *text - 'A' + 10;
} else if (*text >= 'a' && *text <= 'f') {
result *= base;
result += *text - 'a' + 10;
} else
break;
text++;
}
 
return result;
}
 
/** @}
*/
/trunk/boot/generic/string.h
0,0 → 1,48
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef BOOT_STRING_H_
#define BOOT_STRING_H_
 
#include <types.h>
 
extern size_t strlen(const char *str);
extern int strncmp(const char *src, const char *dst, size_t len);
extern void strncpy(char *dest, const char *src, size_t len);
extern unative_t atoi(const char *text);
 
#endif
 
/** @}
*/
/trunk/boot/arch/sparc64/loader/ofwarch.h
29,9 → 29,13
#ifndef BOOT_sparc64_OFWARCH_H_
#define BOOT_sparc64_OFWARCH_H_
 
#include "main.h"
 
#define OFW_ADDRESS_CELLS 2
#define OFW_SIZE_CELLS 2
 
extern int bpp2align[];
 
extern int ofw_cpu(cpu_t *cpu);
 
#endif
/trunk/boot/arch/sparc64/loader/main.c
66,7 → 66,11
if (!ofw_keyboard(&bootinfo.keyboard))
printf("Error: unable to get keyboard properties\n");
 
if (!ofw_cpu(&bootinfo.cpu))
printf("Error: unable to get cpu properties\n");
 
printf("\nDevice statistics\n");
printf(" cpu: %dMHz\n", bootinfo.cpu.clock_frequency/1000000);
printf(" memory: %dM\n", bootinfo.memmap.total>>20);
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);
printf(" keyboard at %P (size %d bytes)\n", (uintptr_t) bootinfo.keyboard.addr, bootinfo.keyboard.size);
/trunk/boot/arch/sparc64/loader/main.h
45,10 → 45,15
} taskmap_t;
 
typedef struct {
uint32_t clock_frequency;
} cpu_t;
 
typedef struct {
taskmap_t taskmap;
memmap_t memmap;
screen_t screen;
keyboard_t keyboard;
cpu_t cpu;
} bootinfo_t;
 
extern void start(void);
/trunk/boot/arch/sparc64/loader/ofwarch.c
34,6 → 34,8
#include <ofwarch.h>
#include <ofw.h>
#include <printf.h>
#include <string.h>
#include "main.h"
 
int bpp2align[] = {
[0] = 0, /** Invalid bpp. */
79,3 → 81,31
 
return true;
}
 
int ofw_cpu(cpu_t *cpu)
{
char type_name[BUF_SIZE];
 
phandle node;
node = ofw_get_child_node(ofw_root);
if (node == 0 || node == -1) {
printf("Could not find any child nodes of the root node.\n");
return;
}
for (; node != 0 && node != -1; node = ofw_get_peer_node(node)) {
if (ofw_get_property(node, "device_type", type_name, sizeof(type_name)) > 0) {
if (strncmp(type_name, "cpu", 3) == 0) {
uint32_t mhz;
if (ofw_get_property(node, "clock-frequency", &mhz, sizeof(mhz)) <= 0)
continue;
cpu->clock_frequency = mhz;
return 1;
}
}
};
 
return 0;
}
/trunk/boot/arch/sparc64/loader/Makefile
51,6 → 51,7
SOURCES = \
main.c \
../../../generic/printf.c \
../../../generic/string.c \
../../../genarch/ofw.c \
ofwarch.c \
asm.S \