Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2262 → Rev 2263

/branches/arm/kernel/kernel.config
30,7 → 30,7
! [ARCH=amd64] MACHINE (choice)
 
# Machine type
@ "gxemul" GXEmul
@ "gxemul_testarm" GXEmul testarm
! [ARCH=arm32] MACHINE (choice)
 
# Machine type
/branches/arm/kernel/arch/arm32/include/mm/page.h
93,7 → 93,6
#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) set_pt_level1_flags((pte_level1_t *)(ptl3), (index_t)(i), (x))
 
#define PTE_VALID_ARCH(pte) (*((uint32_t *) (pte)) != 0)
// TODO: ?? != 0
#define PTE_PRESENT_ARCH(pte) ( ((pte_level0_t *)(pte))->descriptor_type != 0 )
 
/* pte should point into ptl3 */
119,11 → 118,10
}
 
/**
* Returns level 0 page table entry flags.
/** Returns level 0 page table entry flags.
*
* \param pt level 0 page table
* \param i index of the entry to return
* \param pt level 0 page table
* \param i index of the entry to return
*/
static inline int get_pt_level0_flags(pte_level0_t *pt, index_t i)
{
139,11 → 137,10
;
}
 
/**
* Returns level 1 page table entry flags.
/** Returns level 1 page table entry flags.
*
* \param pt level 1 page table
* \param i index of the entry to return
* \param pt level 1 page table
* \param i index of the entry to return
*/
static inline int get_pt_level1_flags(pte_level1_t *pt, index_t i)
{
162,14 → 159,11
;
}
 
/**
* Sets flags of level 0 page table entry.
/** Sets flags of level 0 page table entry.
*
* \param pt level 0 page table
* \param i index of the entry to be changed
* \param flags new flags
*
* TODO: why should_be_zero set to 1?
* \param pt level 0 page table
* \param i index of the entry to be changed
* \param flags new flags
*/
static inline void set_pt_level0_flags(pte_level0_t *pt, index_t i, int flags)
{
177,10 → 171,8
 
if (flags & PAGE_NOT_PRESENT) {
p->descriptor_type = PTE_DESCRIPTOR_NOT_PRESENT;
// ensures that the entry will be recognized as valid when PTE_VALID_ARCH applied
p->should_be_zero = 1;
// TODO: remove in final version
// For Michal: Have to be here ... ensures this entry contains at least 1 non zero bit
// all zero bits signals PTE_VALID_ARCH , it's different from not_present
} else {
p->descriptor_type = PTE_DESCRIPTOR_COARSE_TABLE;
p->should_be_zero = 0;
187,16 → 179,15
}
}
 
/**
* Sets flags of level 1 page table entry.
/** Sets flags of level 1 page table entry.
*
* We use same access rights for the whole page. When page is not preset then
* store 1 in acess_rigts_3.
* TODO: why access_right_3?
* We use same access rights for the whole page. When page is not preset we
* store 1 in acess_rigts_3 so that at least one bit is 1 (to mark correct
* page entry, see #PAGE_VALID_ARCH).
*
* \param pt level 1 page table
* \param i index of the entry to be changed
* \param flags new flags
* \param pt level 1 page table
* \param i index of the entry to be changed
* \param flags new flags
*/
static inline void set_pt_level1_flags(pte_level1_t *pt, index_t i, int flags)
{
/branches/arm/kernel/arch/arm32/include/drivers/gxemul.h
41,6 → 41,22
#define GXEMUL_IRQC_MAX_IRQ 8
#define GXEMUL_TIMER_FREQ 2
 
 
/** Struct containing mappings of gxemul HW devices into kernel part
* * of virtual address space. */
typedef struct {
uintptr_t videoram;
uintptr_t kbd;
uintptr_t rtc;
uintptr_t rtc_freq;
uintptr_t rtc_ack;
uintptr_t irqc;
uintptr_t irqc_mask;
uintptr_t irqc_unmask;
} gxemul_hw_map_t;
 
 
void gxemul_hw_map_init(void);
void gxemul_console(devno_t devno);
void gxemul_kbd_release(void);
void gxemul_kbd_grab(void);
52,6 → 68,7
void gxemul_timer_irq_init(void);
void gxemul_timer_start(uint32_t frequency);
 
size_t gxemul_get_memory_size(void);
 
 
/branches/arm/kernel/arch/arm32/include/drivers/init.h
0,0 → 1,45
/*
* Copyright (c) 2007 Michal Kebrt
* 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 arm32
* @{
*/
/** @file
*/
 
#ifndef KERN_arm32_DRIVERS_INIT_H_
#define KERN_arm32_DRIVERS_INIT_H_
 
 
void drivers_init(void);
 
 
#endif
 
/** @}
*/
/branches/arm/kernel/arch/arm32/Makefile.inc
40,8 → 40,11
 
CFLAGS += -fno-zero-initialized-in-bss
 
DEFS += -D__32_BITS__ -DMACHINE=$(MACHINE) -DKERNEL_LOAD_ADDRESS=$(KERNEL_LOAD_ADDRESS)
MACHINE_gxemul_testarm = 1
 
DEFS += -D__32_BITS__ -DMACHINE=$(MACHINE_$(MACHINE)) -DKERNEL_LOAD_ADDRESS=$(KERNEL_LOAD_ADDRESS) \
-DMACHINE_GXEMUL_TESTARM=$(MACHINE_gxemul_testarm)
 
CONFIG_GXEMUL = y
DEFS += -DCONFIG_GXEMUL
 
82,6 → 85,7
arch/$(ARCH)/src/aux_print/io.c \
arch/$(ARCH)/src/console.c \
arch/$(ARCH)/src/drivers/gxemul.c \
arch/$(ARCH)/src/drivers/init.c \
arch/$(ARCH)/src/exception.c \
arch/$(ARCH)/src/mm/memory_init.c
/branches/arm/kernel/arch/arm32/src/exception.c
148,6 → 148,7
*/
static void irq_exception(int exc_no, istate_t* istate)
{
#if MACHINE == MACHINE_GXEMUL_TESTARM
uint32_t sources = gxemul_irqc_get_sources();
int i = 0;
for (; i < GXEMUL_IRQC_MAX_IRQ; i++) {
163,6 → 164,7
}
}
}
#endif
/* TODO remove after testing the above code
noirq = 0;
if (i == CONSOLE_IRQ) {
/branches/arm/kernel/arch/arm32/src/console.c
38,7 → 38,9
 
void console_init(devno_t devno)
{
#if MACHINE == MACHINE_GXEMUL_TESTARM
gxemul_console(devno);
#endif
}
 
/** Acquire console back for kernel
46,7 → 48,9
*/
void arch_grab_console(void)
{
#if MACHINE == MACHINE_GXEMUL_TESTARM
gxemul_kbd_grab();
#endif
}
 
/** Return console to userspace
54,7 → 58,9
*/
void arch_release_console(void)
{
#if MACHINE == MACHINE_GXEMUL_TESTARM
gxemul_kbd_release();
#endif
}
 
/** @}
/branches/arm/kernel/arch/arm32/src/arm32.c
38,11 → 38,15
#include <config.h>
#include <arch/console.h>
#include <ddi/device.h>
#include <genarch/fb/fb.h>
#include <genarch/fb/visuals.h>
#include <ddi/irq.h>
 
#include "aux_print/printf.h"
#include <print.h>
#include <config.h>
#include <interrupt.h>
#include <arch/drivers/init.h>
 
bootinfo_t bootinfo;
 
53,12 → 57,9
 
init.cnt = bootinfo.cnt;
 
printf("Used memmory\n");
for (i = 0; i < bootinfo.cnt; ++i) {
init.tasks[i].addr = bootinfo.tasks[i].addr;
init.tasks[i].size = bootinfo.tasks[i].size;
 
// aux_printf("%L, %d\n", bootinfo.tasks[i].addr, bootinfo.tasks[i].size);
}
 
/* TODO this code just setups irq testing bed */
65,7 → 66,6
setup_exception_stacks();
}
 
#include <ddi/irq.h>
void arch_pre_mm_init(void)
{
aux_printf("arch_pre_mm_init\n");
75,20 → 75,21
/* Initialize dispatch table */
exception_init();
 
}
 
void arch_post_mm_init(void)
{
aux_printf("arch_post_mm_init\n");
interrupt_init(); // needs malloc ... so after mm init
console_init(device_assign_devno()); // need hash table of irq ... so after irq_init
aux_printf("arch_post_mm_init start()\n");
drivers_init();
interrupt_init();
/* TODO */
 
console_init(device_assign_devno());
//fb_init(0x12000000, 640, 480, 1920, VISUAL_RGB_8_8_8);
interrupts_enable();
while(1);
// while(1);
aux_printf("machine:\n", MACHINE );
aux_printf("arch_post_mm_init end()\n");
}
 
void arch_post_cpu_init(void)
/branches/arm/kernel/arch/arm32/src/mm/memory_init.c
34,15 → 34,12
 
#include <arch/mm/memory_init.h>
#include <arch/mm/page.h>
#include "../aux_print/printf.h"
#include <arch/drivers/gxemul.h>
 
#define GXEMUL_MP_ADDRESS 0x11000000
#define GXEMUL_MP_MEMSIZE_OFFSET 0x0090
size_t get_memory_size(void)
{
//TODO preprocessor don't work
#if MACHINE == gxemul
return *((int*)(GXEMUL_MP_ADDRESS+GXEMUL_MP_MEMSIZE_OFFSET));
#if MACHINE == MACHINE_GXEMUL_TESTARM
return gxemul_get_memory_size();
#endif
}
 
/branches/arm/kernel/arch/arm32/src/mm/page.c
115,19 → 115,14
 
// TODO: move to the kernel space
page_mapping_insert(AS_KERNEL, 0x00000000, 0x00000000, flags);
// TODO: remove when aux_printf not needed
page_mapping_insert(AS_KERNEL, 0x10000000, 0x10000000, flags);
page_mapping_insert(AS_KERNEL, 0x15000000, 0x15000000, flags);
page_mapping_insert(AS_KERNEL, 0x16000000, 0x16000000, flags);
 
exc_register(EXC_DATA_ABORT, "page_fault data abort", (iroutine) data_abourt);
exc_register(EXC_PREFETCH_ABORT, "page_fault prefetch abort", (iroutine) prefetch_abourt);
 
exc_register(EXC_DATA_ABORT, "page_fault data abort", (iroutine) data_abourt);
exc_register(EXC_PREFETCH_ABORT, "page_fault prefetch abort", (iroutine) prefetch_abourt);
as_switch(NULL, AS_KERNEL);
 
/* Sets mapping to kernel mapping. It's nessesary to hw_map changes take place immediately
* after hw_map function is called. */
as_switch( NULL, AS_KERNEL);
 
// note for Alf: kernel part of page table is copied in generic/mm/as_pt.c/ptl0_create
// TODO: register fault routine
}
 
/branches/arm/kernel/arch/arm32/src/interrupt.c
93,8 → 93,10
{
irq_init(IRQ_COUNT, IRQ_COUNT);
 
#if MACHINE == MACHINE_GXEMUL_TESTARM
gxemul_timer_irq_init();
gxemul_timer_start(GXEMUL_TIMER_FREQ);
#endif
}
 
 
/branches/arm/kernel/arch/arm32/src/drivers/gxemul.c
1,5 → 1,5
/*
* Copyright (c) 2005-2007 Ondrej Palkovsky, Michal Kebrt, Petr Stepan
* Copyright (c) 2007 Michal Kebrt, Petr Stepan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
40,21 → 40,26
#include <sysinfo/sysinfo.h>
#include <print.h>
#include <ddi/device.h>
#include <mm/page.h>
 
/** Address of devices. */
#define GXEMUL_VIDEORAM 0x10000000
#define GXEMUL_KBD_ADDRESS 0x10000000
#define GXEMUL_RTC 0x15000000
#define GXEMUL_RTC_FREQ 0x15000100
#define GXEMUL_RTC_ACK 0x15000110
#define GXEMUL_IRQC 0x16000000
#define GXEMUL_IRQC_MASK 0x16000004
#define GXEMUL_IRQC_UNMASK 0x16000008
#define GXEMUL_VIDEORAM 0x10000000
#define GXEMUL_KBD 0x10000000
#define GXEMUL_RTC 0x15000000
#define GXEMUL_RTC_FREQ_OFFSET 0x100
#define GXEMUL_RTC_ACK_OFFSET 0x110
#define GXEMUL_IRQC 0x16000000
#define GXEMUL_IRQC_MASK_OFFSET 0x4
#define GXEMUL_IRQC_UNMASK_OFFSET 0x8
#define GXEMUL_MP 0x11000000
#define GXEMUL_MP_MEMSIZE_OFFSET 0x0090
 
 
/** IRQs */
#define GXEMUL_KBD_IRQ 2
#define GXEMUL_TIMER_IRQ 4
 
static gxemul_hw_map_t gxemul_hw_map;
static chardev_t console;
static irq_t gxemul_irq;
static irq_t gxemul_timer_irq;
71,10 → 76,25
.read = gxemul_do_read,
};
 
 
/** Initializes #gxemul_hw_map. */
void gxemul_hw_map_init(void)
{
gxemul_hw_map.videoram = hw_map(GXEMUL_VIDEORAM, PAGE_SIZE);
gxemul_hw_map.kbd = hw_map(GXEMUL_KBD, PAGE_SIZE);
gxemul_hw_map.rtc = hw_map(GXEMUL_RTC, PAGE_SIZE);
gxemul_hw_map.irqc = hw_map(GXEMUL_IRQC, PAGE_SIZE);
 
gxemul_hw_map.rtc_freq = gxemul_hw_map.rtc + GXEMUL_RTC_FREQ_OFFSET;
gxemul_hw_map.rtc_ack = gxemul_hw_map.rtc + GXEMUL_RTC_ACK_OFFSET;
gxemul_hw_map.irqc_mask = gxemul_hw_map.irqc + GXEMUL_IRQC_MASK_OFFSET;
gxemul_hw_map.irqc_unmask = gxemul_hw_map.irqc + GXEMUL_IRQC_UNMASK_OFFSET;
}
 
/** Putchar that works with gxemul */
void gxemul_write(chardev_t *dev, const char ch)
{
*((char *) GXEMUL_VIDEORAM) = ch;
*((char *) gxemul_hw_map.videoram) = ch;
}
 
/* Called from getc(). */
97,7 → 117,7
char ch;
 
while (1) {
ch = *((volatile char *) GXEMUL_KBD_ADDRESS);
ch = *((volatile char *) gxemul_hw_map.kbd);
if (ch) {
if (ch == '\r')
return '\n';
116,7 → 136,7
else {
char ch = 0;
ch = *((char *) GXEMUL_KBD_ADDRESS);
ch = *((char *) gxemul_hw_map.kbd);
if (ch =='\r')
ch = '\n';
if (ch == 0x7f)
134,7 → 154,7
void gxemul_kbd_grab(void)
{
ipl_t ipl = interrupts_disable();
spinlock_lock(&msim_irq.lock);
spinlock_lock(&gxemul_irq.lock);
gxemul_irq.notif_cfg.notify = false;
spinlock_unlock(&gxemul_irq.lock);
interrupts_restore(ipl);
151,10 → 171,10
}
 
 
/** Return console object representing msim console */
/** Return console object representing gxemul console */
void gxemul_console(devno_t devno)
{
chardev_initialize("msim_console", &console, &gxemul_ops);
chardev_initialize("gxemul_console", &console, &gxemul_ops);
stdin = &console;
stdout = &console;
171,13 → 191,13
sysinfo_set_item_val("kbd", NULL, true);
sysinfo_set_item_val("kbd.devno", NULL, devno);
sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
sysinfo_set_item_val("kbd.address.virtual", NULL, GXEMUL_KBD_ADDRESS);
sysinfo_set_item_val("kbd.address.virtual", NULL, gxemul_hw_map.kbd);
}
 
/** Return the mask of active interrupts. */
inline uint32_t gxemul_irqc_get_sources(void)
{
return *(uint32_t*) GXEMUL_IRQC;
return *(uint32_t*) gxemul_hw_map.irqc;
}
 
/** Masks interrupt.
186,7 → 206,7
*/
inline void gxemul_irqc_mask(uint32_t irq)
{
*(uint32_t*) GXEMUL_IRQC_MASK = irq;
*(uint32_t*) gxemul_hw_map.irqc_mask = irq;
}
 
/** Unmasks interrupt.
195,7 → 215,7
*/
inline void gxemul_irqc_unmask(uint32_t irq)
{
*(uint32_t*) GXEMUL_IRQC_UNMASK = irq;
*(uint32_t*) gxemul_hw_map.irqc_unmask = irq;
}
 
 
205,7 → 225,7
*/
void gxemul_timer_start(uint32_t frequency)
{
*(uint32_t*) GXEMUL_RTC_FREQ = frequency;
*(uint32_t*) gxemul_hw_map.rtc_freq = frequency;
}
 
static irq_ownership_t gxemul_timer_claim(void)
237,7 → 257,7
spinlock_lock(&irq->lock);
 
/* acknowledge tick */
*(uint32_t*) GXEMUL_RTC_ACK = 0;
*(uint32_t*) gxemul_hw_map.rtc_ack = 0;
/* TODO what's that? *
if (virtual_timer_fnc != NULL)
259,6 → 279,10
irq_register(&gxemul_timer_irq);
}
 
size_t gxemul_get_memory_size(void)
{
return *((int*)(GXEMUL_MP + GXEMUL_MP_MEMSIZE_OFFSET));
}
 
/** @}
*/
/branches/arm/kernel/arch/arm32/src/drivers/init.c
0,0 → 1,46
/*
* Copyright (c) 2007 Michal Kebrt
* 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 arm32
* @{
*/
/** @file
*/
 
#include <arch/drivers/init.h>
#include <arch/drivers/gxemul.h>
 
void drivers_init(void) {
#if MACHINE == MACHINE_GXEMUL_TESTARM
gxemul_hw_map_init();
#endif
}
 
 
/** @}
*/