mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 23:44:35 +00:00
CMOS clock
This commit is contained in:
parent
7c4d43fec3
commit
f3aea7e1bd
1
.vscode/c_boilerplates.code-snippets
vendored
1
.vscode/c_boilerplates.code-snippets
vendored
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"Fennix Kernel Header": {
|
"Fennix Kernel Header": {
|
||||||
"scope": "c",
|
|
||||||
"prefix": [
|
"prefix": [
|
||||||
"head",
|
"head",
|
||||||
],
|
],
|
||||||
|
1
.vscode/c_cpp_properties.json
vendored
1
.vscode/c_cpp_properties.json
vendored
@ -6,6 +6,7 @@
|
|||||||
"${workspaceFolder}/include/**"
|
"${workspaceFolder}/include/**"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
|
"__debug_vscode__",
|
||||||
"KERNEL_NAME=\"Fennix\"",
|
"KERNEL_NAME=\"Fennix\"",
|
||||||
"KERNEL_VERSION=\"1.0\"",
|
"KERNEL_VERSION=\"1.0\"",
|
||||||
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
|
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
|
||||||
|
35
Kernel.cpp
35
Kernel.cpp
@ -1,10 +1,34 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
|
#include <display.hpp>
|
||||||
#include <memory.hpp>
|
#include <memory.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <time.hpp>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
BootInfo *bInfo = nullptr;
|
BootInfo *bInfo = nullptr;
|
||||||
|
Video::Display *Display = nullptr;
|
||||||
|
|
||||||
|
// For the Display class. Printing on first buffer.
|
||||||
|
extern "C" void putchar(char c) { Display->Print(c, 0); }
|
||||||
|
|
||||||
|
#ifdef __debug_vscode__
|
||||||
|
extern "C" int printf_(const char *format, ...);
|
||||||
|
extern "C" int vprintf_(const char *format, va_list arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void KPrint(const char *format, ...)
|
||||||
|
{
|
||||||
|
Time tm = ReadClock();
|
||||||
|
printf_("[%02ld:%02ld:%02ld] ", tm.Hour, tm.Minute, tm.Second);
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vprintf_(format, args);
|
||||||
|
va_end(args);
|
||||||
|
putchar('\n');
|
||||||
|
Display->SetBuffer(0);
|
||||||
|
}
|
||||||
|
|
||||||
EXTERNC void kernel_aarch64_entry(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
|
EXTERNC void kernel_aarch64_entry(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
|
||||||
{
|
{
|
||||||
@ -20,11 +44,12 @@ EXTERNC void kernel_entry(BootInfo *Info)
|
|||||||
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
|
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
|
||||||
memcpy(bInfo, Info, sizeof(BootInfo));
|
memcpy(bInfo, Info, sizeof(BootInfo));
|
||||||
debug("BootInfo structure is at %p", bInfo);
|
debug("BootInfo structure is at %p", bInfo);
|
||||||
|
Display = new Video::Display(bInfo->Framebuffer[0]);
|
||||||
|
printf_("%s - %s(%s)\n", KERNEL_NAME, KERNEL_VERSION, GIT_COMMIT_SHORT);
|
||||||
|
Display->SetBuffer(0);
|
||||||
|
for (size_t i = 0; i < 70; i++)
|
||||||
|
KPrint("Hello, World! (%ld)", i);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
CPU::Halt();
|
CPU::Halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement screen printing
|
|
||||||
extern "C" void putchar(int a, int b)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
38
arch/Time.cpp
Normal file
38
arch/Time.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <time.hpp>
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
Time ReadClock()
|
||||||
|
{
|
||||||
|
Time tm;
|
||||||
|
#if defined(__amd64__) || defined(__i386__)
|
||||||
|
uint32_t t = 0;
|
||||||
|
outb(0x70, 0x00);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Second = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
outb(0x70, 0x02);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Minute = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
outb(0x70, 0x04);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Hour = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
outb(0x70, 0x07);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Day = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
outb(0x70, 0x08);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Month = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
outb(0x70, 0x09);
|
||||||
|
t = inb(0x71);
|
||||||
|
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
|
||||||
|
tm.Counter = 0;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
tm.Year = 0;
|
||||||
|
tm.Month = 0;
|
||||||
|
tm.Day = 0;
|
||||||
|
tm.Hour = 0;
|
||||||
|
tm.Minute = 0;
|
||||||
|
tm.Second = 0;
|
||||||
|
tm.Counter = 0;
|
||||||
|
#endif
|
||||||
|
return tm;
|
||||||
|
}
|
11
core/README.md
Normal file
11
core/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Core components
|
||||||
|
|
||||||
|
This directory contains the core components of the project. These components are used by the kernel to provide the basic functionality of the operating system.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💾 Memory
|
||||||
|
|
||||||
|
Contains the memory management code.
|
||||||
|
It is responsible for allocating and freeing memory.
|
||||||
|
It also provides the `kmalloc`, `kcalloc`, `krealloc` and `kfree` functions that are used by the rest of the kernel.
|
242
include/printf.h
242
include/printf.h
@ -39,20 +39,21 @@
|
|||||||
#ifndef PRINTF_H_
|
#ifndef PRINTF_H_
|
||||||
#define PRINTF_H_
|
#define PRINTF_H_
|
||||||
|
|
||||||
# include <stdarg.h>
|
#include <stdarg.h>
|
||||||
# include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
# define ATTR_PRINTF(one_based_format_index, first_arg) \
|
#define ATTR_PRINTF(one_based_format_index, first_arg) \
|
||||||
__attribute__((format(__printf__, (one_based_format_index), (first_arg))))
|
__attribute__((format(__printf__, (one_based_format_index), (first_arg))))
|
||||||
# define ATTR_VPRINTF(one_based_format_index) ATTR_PRINTF((one_based_format_index), 0)
|
#define ATTR_VPRINTF(one_based_format_index) ATTR_PRINTF((one_based_format_index), 0)
|
||||||
#else
|
#else
|
||||||
# define ATTR_PRINTF((one_based_format_index), (first_arg))
|
#define ATTR_PRINTF((one_based_format_index), (first_arg))
|
||||||
# define ATTR_VPRINTF(one_based_format_index)
|
#define ATTR_VPRINTF(one_based_format_index)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
#ifndef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
||||||
@ -60,12 +61,12 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
||||||
# define printf_ printf
|
#define printf_ printf
|
||||||
# define sprintf_ sprintf
|
#define sprintf_ sprintf
|
||||||
# define vsprintf_ vsprintf
|
#define vsprintf_ vsprintf
|
||||||
# define snprintf_ snprintf
|
#define snprintf_ snprintf
|
||||||
# define vsnprintf_ vsnprintf
|
#define vsnprintf_ vsnprintf
|
||||||
# define vprintf_ vprintf
|
#define vprintf_ vprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If you want to include this implementation file directly rather than
|
// If you want to include this implementation file directly rather than
|
||||||
@ -76,124 +77,119 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
|
|||||||
#define PRINTF_VISIBILITY
|
#define PRINTF_VISIBILITY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints/send a single character to some opaque output entity
|
* Prints/send a single character to some opaque output entity
|
||||||
*
|
*
|
||||||
* @note This function is not implemented by the library, only declared; you must provide an
|
* @note This function is not implemented by the library, only declared; you must provide an
|
||||||
* implementation if you wish to use the @ref printf / @ref vprintf function (and possibly
|
* implementation if you wish to use the @ref printf / @ref vprintf function (and possibly
|
||||||
* for linking against the library, if your toolchain does not support discarding unused functions)
|
* for linking against the library, if your toolchain does not support discarding unused functions)
|
||||||
*
|
*
|
||||||
* @note The output could be as simple as a wrapper for the `write()` system call on a Unix-like
|
* @note The output could be as simple as a wrapper for the `write()` system call on a Unix-like
|
||||||
* system, or even libc's @ref putchar , for replicating actual functionality of libc's @ref printf
|
* system, or even libc's @ref putchar , for replicating actual functionality of libc's @ref printf
|
||||||
* function; but on an embedded system it may involve interaction with a special output device,
|
* function; but on an embedded system it may involve interaction with a special output device,
|
||||||
* like a UART, etc.
|
* like a UART, etc.
|
||||||
*
|
*
|
||||||
* @note in libc's @ref putchar, the parameter type is an int; this was intended to support the
|
* @note in libc's @ref putchar, the parameter type is an int; this was intended to support the
|
||||||
* representation of either a proper character or EOF in a variable - but this is really not
|
* representation of either a proper character or EOF in a variable - but this is really not
|
||||||
* meaningful to pass into @ref putchar and is discouraged today. See further discussion in:
|
* meaningful to pass into @ref putchar and is discouraged today. See further discussion in:
|
||||||
* @link https://stackoverflow.com/q/17452847/1593077
|
* @link https://stackoverflow.com/q/17452847/1593077
|
||||||
*
|
*
|
||||||
* @param c the single character to print
|
* @param c the single character to print
|
||||||
*/
|
*/
|
||||||
PRINTF_VISIBILITY
|
PRINTF_VISIBILITY
|
||||||
void putchar(char c);
|
void putchar(char c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of the C standard's printf/vprintf
|
||||||
|
*
|
||||||
|
* @note you must implement a @ref putchar_ function for using this function - it invokes @ref putchar_
|
||||||
|
* rather than directly performing any I/O (which insulates it from any dependence on the operating system
|
||||||
|
* and external libraries).
|
||||||
|
*
|
||||||
|
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
||||||
|
* additional arguments.
|
||||||
|
* @param arg Additional arguments to the function, one for each %-specifier in @p format string
|
||||||
|
* @return The number of characters written into @p s, not counting the terminating null character
|
||||||
|
*/
|
||||||
|
///@{
|
||||||
|
PRINTF_VISIBILITY
|
||||||
|
int printf_(const char *format, ...) ATTR_PRINTF(1, 2);
|
||||||
|
PRINTF_VISIBILITY
|
||||||
|
int vprintf_(const char *format, va_list arg) ATTR_VPRINTF(1);
|
||||||
|
///@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of the C standard's printf/vprintf
|
* An implementation of the C standard's sprintf/vsprintf
|
||||||
*
|
*
|
||||||
* @note you must implement a @ref putchar_ function for using this function - it invokes @ref putchar_
|
* @note For security considerations (the potential for exceeding the buffer bounds), please consider using
|
||||||
* rather than directly performing any I/O (which insulates it from any dependence on the operating system
|
* the size-constrained variant, @ref snprintf / @ref vsnprintf , instead.
|
||||||
* and external libraries).
|
*
|
||||||
*
|
* @param s An array in which to store the formatted string. It must be large enough to fit the formatted
|
||||||
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
* output!
|
||||||
* additional arguments.
|
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
||||||
* @param arg Additional arguments to the function, one for each %-specifier in @p format string
|
* additional arguments.
|
||||||
* @return The number of characters written into @p s, not counting the terminating null character
|
* @param arg Additional arguments to the function, one for each specifier in @p format
|
||||||
*/
|
* @return The number of characters written into @p s, not counting the terminating null character
|
||||||
///@{
|
*/
|
||||||
PRINTF_VISIBILITY
|
///@{
|
||||||
int printf_(const char* format, ...) ATTR_PRINTF(1, 2);
|
PRINTF_VISIBILITY
|
||||||
PRINTF_VISIBILITY
|
int sprintf_(char *s, const char *format, ...) ATTR_PRINTF(2, 3);
|
||||||
int vprintf_(const char* format, va_list arg) ATTR_VPRINTF(1);
|
PRINTF_VISIBILITY
|
||||||
///@}
|
int vsprintf_(char *s, const char *format, va_list arg) ATTR_VPRINTF(2);
|
||||||
|
///@}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of the C standard's snprintf/vsnprintf
|
||||||
|
*
|
||||||
|
* @param s An array in which to store the formatted string. It must be large enough to fit either the
|
||||||
|
* entire formatted output, or at least @p n characters. Alternatively, it can be NULL, in which case
|
||||||
|
* nothing will be printed, and only the number of characters which _could_ have been printed is
|
||||||
|
* tallied and returned.
|
||||||
|
* @param n The maximum number of characters to write to the array, including a terminating null character
|
||||||
|
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
||||||
|
* additional arguments.
|
||||||
|
* @param arg Additional arguments to the function, one for each specifier in @p format
|
||||||
|
* @return The number of characters that COULD have been written into @p s, not counting the terminating
|
||||||
|
* null character. A value equal or larger than @p n indicates truncation. Only when the returned value
|
||||||
|
* is non-negative and less than @p n, the null-terminated string has been fully and successfully printed.
|
||||||
|
*/
|
||||||
|
///@{
|
||||||
|
PRINTF_VISIBILITY
|
||||||
|
int snprintf_(char *s, size_t count, const char *format, ...) ATTR_PRINTF(3, 4);
|
||||||
|
PRINTF_VISIBILITY
|
||||||
|
int vsnprintf_(char *s, size_t count, const char *format, va_list arg) ATTR_VPRINTF(3);
|
||||||
|
///@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of the C standard's sprintf/vsprintf
|
* printf/vprintf with user-specified output function
|
||||||
*
|
*
|
||||||
* @note For security considerations (the potential for exceeding the buffer bounds), please consider using
|
* An alternative to @ref printf_, in which the output function is specified dynamically
|
||||||
* the size-constrained variant, @ref snprintf / @ref vsnprintf , instead.
|
* (rather than @ref putchar_ being used)
|
||||||
*
|
*
|
||||||
* @param s An array in which to store the formatted string. It must be large enough to fit the formatted
|
* @param out An output function which takes one character and a type-erased additional parameters
|
||||||
* output!
|
* @param extra_arg The type-erased argument to pass to the output function @p out with each call
|
||||||
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
||||||
* additional arguments.
|
* additional arguments.
|
||||||
* @param arg Additional arguments to the function, one for each specifier in @p format
|
* @param arg Additional arguments to the function, one for each specifier in @p format
|
||||||
* @return The number of characters written into @p s, not counting the terminating null character
|
* @return The number of characters for which the output f unction was invoked, not counting the terminating null character
|
||||||
*/
|
*
|
||||||
///@{
|
*/
|
||||||
PRINTF_VISIBILITY
|
PRINTF_VISIBILITY
|
||||||
int sprintf_(char* s, const char* format, ...) ATTR_PRINTF(2, 3);
|
int fctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, ...) ATTR_PRINTF(3, 4);
|
||||||
PRINTF_VISIBILITY
|
PRINTF_VISIBILITY
|
||||||
int vsprintf_(char* s, const char* format, va_list arg) ATTR_VPRINTF(2);
|
int vfctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, va_list arg) ATTR_VPRINTF(3);
|
||||||
///@}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An implementation of the C standard's snprintf/vsnprintf
|
|
||||||
*
|
|
||||||
* @param s An array in which to store the formatted string. It must be large enough to fit either the
|
|
||||||
* entire formatted output, or at least @p n characters. Alternatively, it can be NULL, in which case
|
|
||||||
* nothing will be printed, and only the number of characters which _could_ have been printed is
|
|
||||||
* tallied and returned.
|
|
||||||
* @param n The maximum number of characters to write to the array, including a terminating null character
|
|
||||||
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
|
||||||
* additional arguments.
|
|
||||||
* @param arg Additional arguments to the function, one for each specifier in @p format
|
|
||||||
* @return The number of characters that COULD have been written into @p s, not counting the terminating
|
|
||||||
* null character. A value equal or larger than @p n indicates truncation. Only when the returned value
|
|
||||||
* is non-negative and less than @p n, the null-terminated string has been fully and successfully printed.
|
|
||||||
*/
|
|
||||||
///@{
|
|
||||||
PRINTF_VISIBILITY
|
|
||||||
int snprintf_(char* s, size_t count, const char* format, ...) ATTR_PRINTF(3, 4);
|
|
||||||
PRINTF_VISIBILITY
|
|
||||||
int vsnprintf_(char* s, size_t count, const char* format, va_list arg) ATTR_VPRINTF(3);
|
|
||||||
///@}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* printf/vprintf with user-specified output function
|
|
||||||
*
|
|
||||||
* An alternative to @ref printf_, in which the output function is specified dynamically
|
|
||||||
* (rather than @ref putchar_ being used)
|
|
||||||
*
|
|
||||||
* @param out An output function which takes one character and a type-erased additional parameters
|
|
||||||
* @param extra_arg The type-erased argument to pass to the output function @p out with each call
|
|
||||||
* @param format A string specifying the format of the output, with %-marked specifiers of how to interpret
|
|
||||||
* additional arguments.
|
|
||||||
* @param arg Additional arguments to the function, one for each specifier in @p format
|
|
||||||
* @return The number of characters for which the output f unction was invoked, not counting the terminating null character
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
PRINTF_VISIBILITY
|
|
||||||
int fctprintf(void (*out)(char c, void* extra_arg), void* extra_arg, const char* format, ...) ATTR_PRINTF(3, 4);
|
|
||||||
PRINTF_VISIBILITY
|
|
||||||
int vfctprintf(void (*out)(char c, void* extra_arg), void* extra_arg, const char* format, va_list arg) ATTR_VPRINTF(3);
|
|
||||||
|
|
||||||
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
||||||
# undef printf_
|
#undef printf_
|
||||||
# undef sprintf_
|
#undef sprintf_
|
||||||
# undef vsprintf_
|
#undef vsprintf_
|
||||||
# undef snprintf_
|
#undef snprintf_
|
||||||
# undef vsnprintf_
|
#undef vsnprintf_
|
||||||
# undef vprintf_
|
#undef vprintf_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // PRINTF_H_
|
#endif // PRINTF_H_
|
14
include/time.hpp
Normal file
14
include/time.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef __FENNIX_KERNEL_TIME_H__
|
||||||
|
#define __FENNIX_KERNEL_TIME_H__
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
struct Time
|
||||||
|
{
|
||||||
|
uint64_t Year, Month, Day, Hour, Minute, Second;
|
||||||
|
uint64_t Counter;
|
||||||
|
};
|
||||||
|
|
||||||
|
Time ReadClock();
|
||||||
|
|
||||||
|
#endif // !__FENNIX_KERNEL_TIME_H__
|
Loading…
x
Reference in New Issue
Block a user