Add vector table
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file arch.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef ARCH_H_F63C116D_51C9_4E25_9B1F_126833937268
|
||||
#define ARCH_H_F63C116D_51C9_4E25_9B1F_126833937268
|
||||
|
||||
#include <aarch64/aarch64.h>
|
||||
|
||||
#define k_arch_init(...) aarch64_init(__VA_ARGS__)
|
||||
|
||||
#endif /* !ARCH_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file irq.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <aarch64/bcm2837.h>
|
||||
#include "timer.h"
|
||||
#include "log.h"
|
||||
#include "irq.h"
|
||||
|
||||
static const char *m_types[] = {
|
||||
"EL1t_SYNC",
|
||||
"EL1t_IRQ",
|
||||
"EL1t_FIQ",
|
||||
"EL1t_ERROR",
|
||||
"EL1h_SYNC",
|
||||
"EL1h_IRQ",
|
||||
"EL1h_FIQ",
|
||||
"EL1h_ERROR",
|
||||
"EL0_64_SYNC",
|
||||
"EL0_64_IRQ",
|
||||
"EL0_64_FIQ",
|
||||
"EL0_64_ERROR",
|
||||
"EL0_32_SYNC",
|
||||
"EL0_32_IRQ",
|
||||
"EL0_32_FIQ",
|
||||
"EL0_32_ERROR"
|
||||
};
|
||||
|
||||
void
|
||||
k_irq_enable_controller()
|
||||
{
|
||||
aarch64_set32r(ENABLE_IRQS_1, SYSTEM_TIMER_IRQ_1);
|
||||
}
|
||||
|
||||
void
|
||||
k_irq_handler(void)
|
||||
{
|
||||
unsigned int irq = aarch64_get32r(IRQ_PENDING_1);
|
||||
switch(irq) {
|
||||
case SYSTEM_TIMER_IRQ_1:
|
||||
k_timer_irq_handler();
|
||||
break;
|
||||
|
||||
default:
|
||||
k_logs("Unhandled irq: ");
|
||||
k_logu(irq, 16);
|
||||
k_logs("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
k_irq_fallback(int type, unsigned long esr, unsigned long address)
|
||||
{
|
||||
k_logs(m_types[type]);
|
||||
k_logs(" -> ESR: ");
|
||||
k_logu(esr, 16);
|
||||
k_logs(", address: ");
|
||||
k_logu(address, 16);
|
||||
k_logs("\n");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file irq.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef IRQ_H_037ADD8D_3AAA_4541_A876_843DFF3A59E8
|
||||
#define IRQ_H_037ADD8D_3AAA_4541_A876_843DFF3A59E8
|
||||
|
||||
#include <aarch64/aarch64.h>
|
||||
|
||||
void
|
||||
k_irq_enable_controller(void);
|
||||
|
||||
void
|
||||
k_irq_handler(void);
|
||||
|
||||
void
|
||||
k_irq_fallback(int type, unsigned long esr, unsigned long address);
|
||||
|
||||
#define k_irq_enable(...) aarch64_irq_enable(__VA_ARGS__)
|
||||
|
||||
#define k_irq_disable(...) aarch64_irq_disable(__VA_ARGS__)
|
||||
|
||||
#endif /* !IRQ_H */
|
||||
@@ -0,0 +1,81 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file log.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <device/uart/uart.h>
|
||||
#include "log.h"
|
||||
|
||||
void
|
||||
k_log_init(void)
|
||||
{
|
||||
uart_init();
|
||||
}
|
||||
|
||||
Ki32
|
||||
k_logs(const Ki8 *string)
|
||||
{
|
||||
Ki8 c;
|
||||
const Ki8 *p = string;
|
||||
while((c = *p) != 0) {
|
||||
if (uart_write(c))
|
||||
return -1;
|
||||
p++;
|
||||
}
|
||||
return (Ki32)(p - string);
|
||||
}
|
||||
|
||||
Ki32
|
||||
k_logi(Ki64 value, Ku8 base)
|
||||
{
|
||||
Ki32 result;
|
||||
|
||||
if (value < 0) {
|
||||
if (uart_write('-'))
|
||||
return -1;
|
||||
value = -value;
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
result += k_logu(value, base);
|
||||
return (result) ? result : -1;
|
||||
}
|
||||
|
||||
Ki32
|
||||
k_logu(Ku64 value, Ku8 base)
|
||||
{
|
||||
Ki32 i = 0, result;
|
||||
Ku8 buffer[64];
|
||||
|
||||
if (!value) {
|
||||
return (uart_write('0')) ? -1 : 1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!(i < (sizeof(buffer) / sizeof(buffer[0]))))
|
||||
return -1;
|
||||
|
||||
Ku64 r = value % base;
|
||||
buffer[i++] = (r < 0x0A) ? '0' + r : 'A' + r - 0x0A;
|
||||
value /= base;
|
||||
} while (value);
|
||||
|
||||
result = i;
|
||||
|
||||
while (i--) {
|
||||
if (uart_write(buffer[i]))
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file print.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef LOG_H_AE38CD54_2822_47A5_AFB1_E785739FA01D
|
||||
#define LOG_H_AE38CD54_2822_47A5_AFB1_E785739FA01D
|
||||
|
||||
#include <core/types.h>
|
||||
|
||||
void
|
||||
k_log_init(void);
|
||||
|
||||
Ki32
|
||||
k_logs(const Ki8 *string);
|
||||
|
||||
Ki32
|
||||
k_logi(Ki64 value, Ku8 base);
|
||||
|
||||
Ki32
|
||||
k_logu(Ku64 value, Ku8 base);
|
||||
|
||||
#endif /* !LOG_H */
|
||||
@@ -0,0 +1,65 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file main.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <core/log.h>
|
||||
#include <core/arch.h>
|
||||
#include <core/irq.h>
|
||||
#include <core/timer.h>
|
||||
|
||||
|
||||
|
||||
void
|
||||
k_main(void);
|
||||
|
||||
|
||||
void
|
||||
k_main(void)
|
||||
{
|
||||
k_log_init();
|
||||
|
||||
k_logs("Starting Lowe OS (EL");
|
||||
k_logi(aarch64_get_el(), 10);
|
||||
k_logs(")\n");
|
||||
|
||||
if (k_arch_init())
|
||||
goto panic;
|
||||
|
||||
k_timer_init();
|
||||
k_irq_enable_controller();
|
||||
k_irq_enable();
|
||||
|
||||
goto ok;
|
||||
/*
|
||||
k_logs("\tclock");
|
||||
if (k_clock_init())
|
||||
goto panic;
|
||||
|
||||
k_logs(" - ok\n\tscheduler");
|
||||
if (k_scheduler_init())
|
||||
goto panic;
|
||||
|
||||
k_logs(" - ok\n");
|
||||
|
||||
k_scheduler_run();
|
||||
*/
|
||||
|
||||
panic:
|
||||
k_logs(" - ERROR\n");
|
||||
ok:
|
||||
for (;;) {
|
||||
__asm__("WFE");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file task.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef TASK_H_AE13C166_79B5_4256_ABF3_74DF04E1CD18
|
||||
#define TASK_H_AE13C166_79B5_4256_ABF3_74DF04E1CD18
|
||||
|
||||
#include <core/types.h>
|
||||
|
||||
typedef Ku32 KTaskId;
|
||||
typedef void (*KTaskCallback)(void *p_ctx);
|
||||
|
||||
struct k_task {
|
||||
KByte name[K_CONFIG_TASK_MAX_NAME_LEN + 1];
|
||||
KTaskCallback callback;
|
||||
Ku32 *stack;
|
||||
Ku32 stack_size;
|
||||
Ku32 priority;
|
||||
};
|
||||
|
||||
KTaskId
|
||||
k_task_create(struct k_task *p_task, KTaskCallback callback, Ku32 *stack
|
||||
, Ku32 stack_size);
|
||||
|
||||
|
||||
#endif /* !TASK_H */
|
||||
@@ -0,0 +1,39 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file timer.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include <aarch64/aarch64.h>
|
||||
#include <aarch64/bcm2837.h>
|
||||
#include "timer.h"
|
||||
#include "log.h"
|
||||
|
||||
const unsigned int m_interval = 200000;
|
||||
unsigned int m_current = 0;
|
||||
|
||||
void
|
||||
k_timer_init(void)
|
||||
{
|
||||
m_current = aarch64_get32r(TIMER_CLO);
|
||||
m_current += m_interval;
|
||||
aarch64_set32r(TIMER_C1, m_current);
|
||||
}
|
||||
|
||||
void
|
||||
k_timer_irq_handler(void)
|
||||
{
|
||||
m_current += m_interval;
|
||||
aarch64_set32r(TIMER_C1, m_current);
|
||||
aarch64_set32r(TIMER_CS, TIMER_CS_M1);
|
||||
k_logs("Timer interrupt\n");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file timer.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H_8D327261_47D6_4832_8DC5_31BF1614A21F
|
||||
#define TIMER_H_8D327261_47D6_4832_8DC5_31BF1614A21F
|
||||
|
||||
void
|
||||
k_timer_init(void);
|
||||
|
||||
void
|
||||
k_timer_irq_handler(void);
|
||||
|
||||
#endif /* !TIMER_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file types.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H_BC3DA9C0_C9EE_4853_B5F5_EAA4B801664C
|
||||
#define TYPES_H_BC3DA9C0_C9EE_4853_B5F5_EAA4B801664C
|
||||
|
||||
typedef int KRetCode;
|
||||
|
||||
typedef int Ki32;
|
||||
typedef unsigned int Ku32;
|
||||
typedef long long Ki64;
|
||||
typedef unsigned long long Ku64;
|
||||
typedef char Ki8;
|
||||
typedef unsigned char Ku8;
|
||||
typedef char KByte;
|
||||
|
||||
#endif /* !TYPES_H */
|
||||
Reference in New Issue
Block a user