mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 10:53:16 +01:00
Initial commit
This commit is contained in:
10
src/platform/pb926/SConscript
Normal file
10
src/platform/pb926/SConscript
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
# Inherit global environment
|
||||
Import('env')
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
src_local = ['printascii.S','platform.c', 'uart.c', 'timer.c', 'irq.c']
|
||||
|
||||
obj = env.Object(src_local)
|
||||
Return('obj')
|
||||
57
src/platform/pb926/irq.c
Normal file
57
src/platform/pb926/irq.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Support for generic irq handling using platform irq controller (PL190)
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
#include <l4/generic/platform.h>
|
||||
#include <l4/generic/irq.h>
|
||||
#include <l4/generic/time.h>
|
||||
#include INC_PLAT(irq.h)
|
||||
#include INC_PLAT(platform.h)
|
||||
#include INC_ARCH(exception.h)
|
||||
#include <l4/drivers/irq/pl190/pl190_vic.h>
|
||||
#include <l4/drivers/timer/sp804/sp804_timer.h>
|
||||
|
||||
struct irq_chip irq_chip_array[IRQ_CHIPS_MAX] = {
|
||||
[0] = {
|
||||
.name = "Vectored irq controller",
|
||||
.level = 0,
|
||||
.cascade = IRQ_SIC,
|
||||
.offset = 0,
|
||||
.ops = {
|
||||
.init = pl190_vic_init,
|
||||
.read_irq = pl190_read_irq,
|
||||
.ack_and_mask = pl190_mask_irq,
|
||||
.unmask = pl190_unmask_irq,
|
||||
},
|
||||
},
|
||||
[1] = {
|
||||
.name = "Secondary irq controller",
|
||||
.level = 1,
|
||||
.cascade = IRQ_NIL,
|
||||
.offset = SIRQ_CHIP_OFFSET,
|
||||
.ops = {
|
||||
.init = pl190_sic_init,
|
||||
.read_irq = pl190_sic_read_irq,
|
||||
.ack_and_mask = pl190_sic_mask_irq,
|
||||
.unmask = pl190_sic_unmask_irq,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static int platform_timer_handler(void)
|
||||
{
|
||||
sp804_irq_handler();
|
||||
return do_timer_irq();
|
||||
}
|
||||
|
||||
/* Built-in irq handlers initialised at compile time.
|
||||
* Else register with register_irq() */
|
||||
struct irq_desc irq_desc_array[IRQS_MAX] = {
|
||||
[IRQ_TIMER01] = {
|
||||
.name = "Timer01",
|
||||
.chip = &irq_chip_array[0],
|
||||
.handler = platform_timer_handler,
|
||||
},
|
||||
};
|
||||
|
||||
63
src/platform/pb926/platform.c
Normal file
63
src/platform/pb926/platform.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* PB926 platform-specific initialisation and setup
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*
|
||||
*/
|
||||
|
||||
#include <l4/generic/platform.h>
|
||||
#include <l4/generic/space.h>
|
||||
#include <l4/generic/irq.h>
|
||||
#include INC_ARCH(linker.h)
|
||||
#include INC_PLAT(printascii.h)
|
||||
#include INC_SUBARCH(mm.h)
|
||||
#include INC_SUBARCH(mmu_ops.h)
|
||||
#include INC_GLUE(memory.h)
|
||||
#include INC_GLUE(memlayout.h)
|
||||
#include INC_PLAT(offsets.h)
|
||||
#include INC_PLAT(platform.h)
|
||||
#include INC_PLAT(uart.h)
|
||||
#include INC_PLAT(irq.h)
|
||||
#include INC_ARCH(asm.h)
|
||||
|
||||
void init_platform_console(void)
|
||||
{
|
||||
add_mapping(PB926_UART0_BASE, PL011_BASE, PAGE_SIZE,
|
||||
MAP_IO_DEFAULT_FLAGS);
|
||||
|
||||
/*
|
||||
* Map same UART IO area to userspace so that primitive uart-based
|
||||
* userspace printf can work. Note, this raw mapping is to be
|
||||
* removed in the future, when file-based io is implemented.
|
||||
*/
|
||||
add_mapping(PB926_UART0_BASE, USERSPACE_UART_BASE, PAGE_SIZE,
|
||||
MAP_USR_IO_FLAGS);
|
||||
|
||||
uart_init();
|
||||
}
|
||||
|
||||
void init_platform_timer(void)
|
||||
{
|
||||
add_mapping(PB926_TIMER01_BASE, PLATFORM_TIMER_BASE, PAGE_SIZE,
|
||||
MAP_IO_DEFAULT_FLAGS);
|
||||
add_mapping(PB926_SYSCTRL_BASE, PB926_SYSCTRL_VBASE, PAGE_SIZE,
|
||||
MAP_IO_DEFAULT_FLAGS);
|
||||
timer_init();
|
||||
}
|
||||
|
||||
void init_platform_irq_controller()
|
||||
{
|
||||
add_mapping(PB926_VIC_BASE, PLATFORM_IRQCTRL_BASE, PAGE_SIZE,
|
||||
MAP_IO_DEFAULT_FLAGS);
|
||||
add_mapping(PB926_SIC_BASE, PLATFORM_SIRQCTRL_BASE, PAGE_SIZE,
|
||||
MAP_IO_DEFAULT_FLAGS);
|
||||
irq_controllers_init();
|
||||
}
|
||||
|
||||
void platform_init(void)
|
||||
{
|
||||
init_platform_console();
|
||||
init_platform_timer();
|
||||
init_platform_irq_controller();
|
||||
}
|
||||
|
||||
74
src/platform/pb926/printascii.S
Normal file
74
src/platform/pb926/printascii.S
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
#include INC_PLAT(debug-macro.S)
|
||||
#include INC_ARCH(asm.h)
|
||||
#include INC_GLUE(memlayout.h)
|
||||
.text
|
||||
/*
|
||||
* Useful debugging routines
|
||||
*/
|
||||
BEGIN_PROC(printhex8)
|
||||
mov r1, #8
|
||||
b printhex
|
||||
|
||||
BEGIN_PROC(printhex4)
|
||||
mov r1, #4
|
||||
b printhex
|
||||
|
||||
BEGIN_PROC(printhex2)
|
||||
mov r1, #2
|
||||
printhex: adr r2, hexbuf
|
||||
add r3, r2, r1
|
||||
mov r1, #0
|
||||
strb r1, [r3]
|
||||
1: and r1, r0, #15
|
||||
mov r0, r0, lsr #4
|
||||
cmp r1, #10
|
||||
addlt r1, r1, #'0'
|
||||
addge r1, r1, #'a' - 10
|
||||
strb r1, [r3, #-1]!
|
||||
teq r3, r2
|
||||
bne 1b
|
||||
mov r0, r2
|
||||
b printascii
|
||||
|
||||
.ltorg
|
||||
|
||||
|
||||
.align
|
||||
|
||||
@ vmem-linked image has strings in vmem addresses. This replaces
|
||||
@ the reference with corresponding physical address. Note this
|
||||
@ won't work if memory offsets aren't clear cut values for
|
||||
@ orr'ing and bic'ing. rm = mmu bits rs = string address.
|
||||
.macro get_straddr rs, rm
|
||||
mrc p15, 0, \rm, c1, c0 @ Get MMU bits.
|
||||
tst \rm, #1 @ MMU enabled?
|
||||
biceq \rs, \rs, #KERNEL_AREA_START @ Clear Virtual mem offset.
|
||||
orreq \rs, \rs, #PHYS_ADDR_BASE @ Add Phy mem offset.
|
||||
.endm
|
||||
|
||||
BEGIN_PROC(printascii)
|
||||
get_straddr r0, r1
|
||||
addruart r3
|
||||
b 2f
|
||||
1: waituart r2, r3
|
||||
senduart r1, r3
|
||||
busyuart r2, r3
|
||||
teq r1, #'\n'
|
||||
moveq r1, #'\r'
|
||||
beq 1b
|
||||
2: teq r0, #0
|
||||
ldrneb r1, [r0], #1
|
||||
teqne r1, #0
|
||||
bne 1b
|
||||
mov pc, lr
|
||||
END_PROC(printascii)
|
||||
|
||||
BEGIN_PROC(printch)
|
||||
addruart r3
|
||||
mov r1, r0
|
||||
mov r0, #0
|
||||
b 1b
|
||||
|
||||
hexbuf: .space 16
|
||||
|
||||
28
src/platform/pb926/timer.c
Normal file
28
src/platform/pb926/timer.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Ties up platform timer with generic timer api
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*
|
||||
*/
|
||||
#include <l4/generic/irq.h>
|
||||
#include <l4/generic/platform.h>
|
||||
#include INC_PLAT(platform.h)
|
||||
#include <l4/drivers/timer/sp804/sp804_timer.h>
|
||||
#include <l4/drivers/misc/sp810/sp810_sysctrl.h>
|
||||
|
||||
void timer_init(void)
|
||||
{
|
||||
/* Set timer 0 to 1MHz */
|
||||
sp810_set_timclk(0, 1);
|
||||
|
||||
/* Initialise timer */
|
||||
sp804_init();
|
||||
}
|
||||
|
||||
void timer_start(void)
|
||||
{
|
||||
irq_enable(IRQ_TIMER01);
|
||||
sp804_set_irq(0, 1); /* Enable timer0 irq */
|
||||
sp804_enable(0, 1); /* Enable timer0 */
|
||||
}
|
||||
|
||||
28
src/platform/pb926/uart.c
Normal file
28
src/platform/pb926/uart.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Ties up platform's uart driver functions with generic API
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
#include <l4/generic/platform.h>
|
||||
#include INC_PLAT(platform.h)
|
||||
|
||||
#include <l4/drivers/uart/pl011/pl011_uart.h>
|
||||
|
||||
extern struct pl011_uart uart;
|
||||
|
||||
void uart_init()
|
||||
{
|
||||
uart.base = PL011_BASE;
|
||||
uart.ops.initialise(&uart);
|
||||
}
|
||||
|
||||
/* Generic uart function that lib/putchar.c expects to see implemented */
|
||||
void uart_putc(char c)
|
||||
{
|
||||
int res;
|
||||
/* Platform specific uart implementation */
|
||||
do {
|
||||
res = uart.ops.tx_char(c);
|
||||
} while (res < 0);
|
||||
}
|
||||
|
||||
10
src/platform/tests/SConscript
Normal file
10
src/platform/tests/SConscript
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
# Inherit global environment
|
||||
Import('env')
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
src_local = ['offsets.c']
|
||||
|
||||
obj = env.Object(src_local)
|
||||
Return('obj')
|
||||
7
src/platform/tests/offsets.c
Normal file
7
src/platform/tests/offsets.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <macros.h>
|
||||
#include <config.h>
|
||||
#include INC_PLAT(offsets.h)
|
||||
|
||||
unsigned int PHYS_MEM_START = 0; /* Dynamically allocated */
|
||||
unsigned int PHYS_MEM_END = 0; /* Dynamically allocated */
|
||||
unsigned int PHYS_ADDR_BASE = 0; /* Dynamically allocated */
|
||||
Reference in New Issue
Block a user