-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use pragma instead of header guards - add interrupt and exception support - add assert.h - improve stdio - add stream support with the help of file.h (streams are files now) - add file stream operations - add file.h - other minor fixes
- Loading branch information
Showing
38 changed files
with
805 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#pragma once | ||
#include <utils.h> | ||
|
||
/** | ||
* @brief Get the hartid | ||
* @return int hartid | ||
*/ | ||
static inline int get_hartid(){ | ||
unsigned id; | ||
asm volatile("csrr %0, mhartid" : "=r" (id)); | ||
return id; | ||
} | ||
|
||
/** | ||
* @brief enable global interrupts | ||
*/ | ||
static inline void arch_en_int(){ | ||
unsigned bits = (1 << 3); | ||
asm volatile("csrs mstatus, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Disable global interrupts | ||
*/ | ||
static inline void arch_di_int(){ | ||
unsigned bits = (1 << 3); | ||
asm volatile("csrc mstatus, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Enable machine software interrupts | ||
*/ | ||
static inline void arch_en_msi() | ||
{ | ||
unsigned bits = (1 << 3); | ||
asm volatile("csrs mie, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Disable machine software interrupts | ||
*/ | ||
static inline void arch_di_msi() | ||
{ | ||
unsigned bits = (1 << 3); | ||
asm volatile("csrc mie, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Enable machine timer interrupts | ||
*/ | ||
static inline void arch_en_mti() | ||
{ | ||
unsigned bits = (1 << 7); | ||
asm volatile("csrs mie, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Disable machine timer interrupts | ||
*/ | ||
static inline void arch_di_mti() | ||
{ | ||
unsigned bits = (1 << 7); | ||
asm volatile("csrc mie, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Enable machine external interrupts | ||
*/ | ||
static inline void arch_en_mei() | ||
{ | ||
unsigned bits = (1 << 11); | ||
asm volatile("csrs mie, %0" : : "r" (bits)); | ||
} | ||
|
||
/** | ||
* @brief Disable machine external interrupts | ||
*/ | ||
static inline void arch_di_mei() | ||
{ | ||
unsigned bits = (1 << 11); | ||
asm volatile("csrc mie, %0" : : "r" (bits)); | ||
} | ||
|
||
_WEAK void arch_unhandled_irq(); | ||
_WEAK void arch_unhandled_exception(); | ||
|
||
/** | ||
* @brief Register exception handler | ||
* @param id exception id | ||
* @param handler handler function | ||
*/ | ||
void register_exception_handler(unsigned id, void (*handler)(void)); | ||
|
||
/** | ||
* @brief Deregister exception handler | ||
* @param id exception id | ||
*/ | ||
void deregister_exception_handler(unsigned id); | ||
|
||
/** | ||
* @brief Register interrupt handler | ||
* @param id Interrupt id | ||
* @param handler handler function | ||
*/ | ||
void register_interrupt_handler(unsigned id, void (*handler)(void)); | ||
|
||
/** | ||
* @brief Deregister interrupt handler | ||
* @param id interrupt id | ||
*/ | ||
void deregister_interrupt_handler(unsigned id); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <utils.h> | ||
|
||
|
||
#define assert(x) \ | ||
if(!(x)) { \ | ||
puts("[ERROR]: Assert Failed:" EXPAND_AND_STRINGIFY(__FILE__) EXPAND_AND_STRINGIFY(__LINE__)); \ | ||
exit(1); \ | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
// Pseudo File System | ||
typedef struct { | ||
int (*write)(char *, uint32_t); | ||
int (*read)(char *, uint32_t); | ||
} Device_t; | ||
|
||
extern Device_t stddev[]; | ||
|
||
/** | ||
* @brief Write characters into device from buffer | ||
* | ||
* @param dev device | ||
* @param buf buffer | ||
* @param n number of chars | ||
* @return int | ||
*/ | ||
int dev_write(const Device_t *dev, char *buf, uint32_t n); | ||
|
||
/** | ||
* @brief Read characters into buffer from device | ||
* | ||
* @param dev device | ||
* @param buf buffer | ||
* @param n number of chars | ||
* @return int | ||
*/ | ||
int dev_read(const Device_t *dev, char *buf, uint32_t n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
#ifndef __MMIO_H__ | ||
#define __MMIO_H__ | ||
#pragma once | ||
|
||
// Memory-Mapped Reg Access Macros | ||
#define REG8(base, offset) *((volatile uint8_t*) (base + offset)) | ||
#define REG16(base, offset) *((volatile uint16_t*) (base + offset)) | ||
#define REG32(base, offset) *((volatile uint32_t*) (base + offset)) | ||
|
||
#endif // __MMIO_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.