Move headers to include/
This commit is contained in:
45
include/config.h
Normal file
45
include/config.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief PepperOS configuration file
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
/* version */
|
||||
#define PEPPEROS_VERSION_MAJOR "0"
|
||||
#define PEPPEROS_VERSION_MINOR "0"
|
||||
#define PEPPEROS_VERSION_PATCH "58"
|
||||
#define PEPPEROS_SPLASH "\x1b[38;5;196mPepperOS\x1b[0m version \x1b[38;5;220m"PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\x1b[0m built on \x1b[38;5;40m"__DATE__" "__TIME__"\x1b[0m\n"
|
||||
|
||||
/* process */
|
||||
#define PROCESS_NAME_MAX 64
|
||||
#define PROCESS_STACK_SIZE 0x10000 // 64kb
|
||||
#define PROCESS_BASE 0x400000
|
||||
#define PROCESS_STACK_BASE 0x1000000
|
||||
|
||||
/* sched */
|
||||
// 1 tick = 1 ms => quantum = 10ms
|
||||
#define SCHEDULER_QUANTUM 10
|
||||
|
||||
/* kernel */
|
||||
#define KERNEL_BASE 0xFFFFFFFF80000000ULL
|
||||
// 2 MB should be enough (as of now, the whole kernel ELF is around 75kb)
|
||||
#define KERNEL_SIZE 0x200000
|
||||
#define KERNEL_STACK_SIZE 65536
|
||||
#define KERNEL_IDT_ENTRIES 33
|
||||
|
||||
/* paging */
|
||||
#define PAGING_MAX_PHYS 0x100000000
|
||||
|
||||
/* heap */
|
||||
#define KHEAP_SIZE (32*1024*1024)
|
||||
|
||||
/* term */
|
||||
#define TERM_HISTORY_MAX_LINES 256
|
||||
|
||||
/* time */
|
||||
#define TIMER_FREQUENCY 1000
|
||||
|
||||
#endif
|
||||
59
include/idt/idt.h
Normal file
59
include/idt/idt.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Interrupt Descriptor Table setup and dispatching
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef IDT_H
|
||||
#define IDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void idt_init(void);
|
||||
|
||||
struct interrupt_descriptor {
|
||||
uint16_t address_low;
|
||||
uint16_t selector;
|
||||
uint8_t ist;
|
||||
uint8_t flags;
|
||||
uint16_t address_mid;
|
||||
uint32_t address_high;
|
||||
uint32_t reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idtr {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} __attribute__((packed));
|
||||
|
||||
// All general-purpose registers (except rsp) as stored on the stack,
|
||||
// plus the values we pushed (vector number, error code) and the iret frame
|
||||
// In reverse order because the stack grows downwards.
|
||||
struct cpu_status_t {
|
||||
uint64_t r15;
|
||||
uint64_t r14;
|
||||
uint64_t r13;
|
||||
uint64_t r12;
|
||||
uint64_t r11;
|
||||
uint64_t r10;
|
||||
uint64_t r9;
|
||||
uint64_t r8;
|
||||
uint64_t rbp;
|
||||
uint64_t rdi;
|
||||
uint64_t rsi;
|
||||
uint64_t rdx;
|
||||
uint64_t rcx;
|
||||
uint64_t rbx;
|
||||
uint64_t rax;
|
||||
|
||||
uint64_t vector_number;
|
||||
uint64_t error_code;
|
||||
|
||||
uint64_t iret_rip;
|
||||
uint64_t iret_cs;
|
||||
uint64_t iret_flags;
|
||||
uint64_t iret_rsp;
|
||||
uint64_t iret_ss;
|
||||
};
|
||||
|
||||
#endif
|
||||
40
include/io/kbd/ps2.h
Normal file
40
include/io/kbd/ps2.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief PS/2 Keyboard driver
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef PS2_H
|
||||
#define PS2_H
|
||||
|
||||
void keyboard_handler(void);
|
||||
|
||||
#define SHIFT_PRESSED_BIT 0b00000001
|
||||
#define ALT_PRESSED_BIT 0b00000010
|
||||
#define CTRL_PRESSED_BIT 0b00000100
|
||||
|
||||
enum SpecialKeys {
|
||||
SHIFT = 255,
|
||||
ALT = 254,
|
||||
CTRL = 253
|
||||
};
|
||||
|
||||
enum SpecialScancodes {
|
||||
LEFT_SHIFT_PRESSED = 0x2A,
|
||||
LEFT_SHIFT_RELEASED = 0xAA,
|
||||
RIGHT_SHIFT_PRESSED = 0x36,
|
||||
RIGHT_SHIFT_RELEASED = 0xB6,
|
||||
CTRL_PRESSED = 0x1D,
|
||||
CTRL_RELEASED = 0x9D,
|
||||
ALT_PRESSED = 0x38,
|
||||
ALT_RELEASED = 0xB8
|
||||
};
|
||||
|
||||
enum KeyboardLayout {
|
||||
US,
|
||||
FR
|
||||
};
|
||||
|
||||
void keyboard_init(unsigned char layout);
|
||||
|
||||
#endif
|
||||
20
include/io/serial/serial.h
Normal file
20
include/io/serial/serial.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Debug serial driver
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef SERIAL_H
|
||||
#define SERIAL_H
|
||||
|
||||
// COM1
|
||||
#define PORT 0x3F8
|
||||
|
||||
void outb(int port, unsigned char data);
|
||||
unsigned char inb(int port);
|
||||
|
||||
int serial_init(void);
|
||||
void skputs(const char* str);
|
||||
void skputc(char c);
|
||||
|
||||
#endif
|
||||
72
include/io/term/flanterm.h
Normal file
72
include/io/term/flanterm.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/* Copyright (C) 2022-2026 Mintsuki and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef FLANTERM_H
|
||||
#define FLANTERM_H 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FLANTERM_CB_DEC 10
|
||||
#define FLANTERM_CB_BELL 20
|
||||
#define FLANTERM_CB_PRIVATE_ID 30
|
||||
#define FLANTERM_CB_STATUS_REPORT 40
|
||||
#define FLANTERM_CB_POS_REPORT 50
|
||||
#define FLANTERM_CB_KBD_LEDS 60
|
||||
#define FLANTERM_CB_MODE 70
|
||||
#define FLANTERM_CB_LINUX 80
|
||||
#define FLANTERM_CB_OSC 90
|
||||
|
||||
#ifdef FLANTERM_IN_FLANTERM
|
||||
|
||||
#include "flanterm_private.h"
|
||||
|
||||
#else
|
||||
|
||||
struct flanterm_context;
|
||||
|
||||
#endif
|
||||
|
||||
void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count);
|
||||
void flanterm_flush(struct flanterm_context *ctx);
|
||||
void flanterm_full_refresh(struct flanterm_context *ctx);
|
||||
void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *ptr, size_t size));
|
||||
|
||||
void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows);
|
||||
void flanterm_set_autoflush(struct flanterm_context *ctx, bool state);
|
||||
void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
79
include/io/term/flanterm_backends/fb.h
Normal file
79
include/io/term/flanterm_backends/fb.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/* Copyright (C) 2022-2026 Mintsuki and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef FLANTERM_FB_H
|
||||
#define FLANTERM_FB_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../flanterm.h"
|
||||
|
||||
#ifdef FLANTERM_IN_FLANTERM
|
||||
|
||||
#include "fb_private.h"
|
||||
|
||||
#endif
|
||||
|
||||
#define FLANTERM_FB_ROTATE_0 0
|
||||
#define FLANTERM_FB_ROTATE_90 1
|
||||
#define FLANTERM_FB_ROTATE_180 2
|
||||
#define FLANTERM_FB_ROTATE_270 3
|
||||
|
||||
struct flanterm_context *flanterm_fb_init(
|
||||
/* If _malloc and _free are nulled, use the bump allocated instance (1 use only). */
|
||||
void *(*_malloc)(size_t size),
|
||||
void (*_free)(void *ptr, size_t size),
|
||||
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
|
||||
uint8_t red_mask_size, uint8_t red_mask_shift,
|
||||
uint8_t green_mask_size, uint8_t green_mask_shift,
|
||||
uint8_t blue_mask_size, uint8_t blue_mask_shift,
|
||||
uint32_t *canvas, /* If nulled, no canvas. */
|
||||
uint32_t *ansi_colours, uint32_t *ansi_bright_colours, /* If nulled, default. */
|
||||
uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */
|
||||
uint32_t *default_bg_bright, uint32_t *default_fg_bright, /* If nulled, default. */
|
||||
/* If font is null, use default font and font_width and font_height ignored. */
|
||||
void *font, size_t font_width, size_t font_height, size_t font_spacing,
|
||||
/* If scale_x and scale_y are 0, automatically scale font based on resolution. */
|
||||
size_t font_scale_x, size_t font_scale_y,
|
||||
size_t margin,
|
||||
/* One of FLANTERM_FB_ROTATE_* values. */
|
||||
int rotation
|
||||
);
|
||||
|
||||
void flanterm_fb_set_flush_callback(struct flanterm_context *ctx, void (*flush_callback)(volatile void *address, size_t length));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
127
include/io/term/flanterm_backends/fb_private.h
Normal file
127
include/io/term/flanterm_backends/fb_private.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/* Copyright (C) 2022-2026 Mintsuki and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef FLANTERM_FB_PRIVATE_H
|
||||
#define FLANTERM_FB_PRIVATE_H 1
|
||||
|
||||
#ifndef FLANTERM_IN_FLANTERM
|
||||
#error "Do not use fb_private.h. Use interfaces defined in fb.h only."
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FLANTERM_FB_FONT_GLYPHS 256
|
||||
|
||||
struct flanterm_fb_char {
|
||||
uint32_t c;
|
||||
uint32_t fg;
|
||||
uint32_t bg;
|
||||
};
|
||||
|
||||
struct flanterm_fb_queue_item {
|
||||
size_t x, y;
|
||||
struct flanterm_fb_char c;
|
||||
};
|
||||
|
||||
struct flanterm_fb_context {
|
||||
struct flanterm_context term;
|
||||
|
||||
void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y);
|
||||
void (*flush_callback)(volatile void *address, size_t length);
|
||||
|
||||
size_t font_width;
|
||||
size_t font_height;
|
||||
size_t glyph_width;
|
||||
size_t glyph_height;
|
||||
|
||||
size_t font_scale_x;
|
||||
size_t font_scale_y;
|
||||
|
||||
size_t offset_x, offset_y;
|
||||
|
||||
volatile uint32_t *framebuffer;
|
||||
size_t pitch;
|
||||
size_t width;
|
||||
size_t height;
|
||||
size_t phys_height;
|
||||
size_t bpp;
|
||||
|
||||
uint8_t red_mask_size, red_mask_shift;
|
||||
uint8_t green_mask_size, green_mask_shift;
|
||||
uint8_t blue_mask_size, blue_mask_shift;
|
||||
|
||||
int rotation;
|
||||
|
||||
size_t font_bits_size;
|
||||
uint8_t *font_bits;
|
||||
size_t font_bool_size;
|
||||
bool *font_bool;
|
||||
|
||||
uint32_t ansi_colours[8];
|
||||
uint32_t ansi_bright_colours[8];
|
||||
uint32_t default_fg, default_bg;
|
||||
uint32_t default_fg_bright, default_bg_bright;
|
||||
|
||||
size_t canvas_size;
|
||||
uint32_t *canvas;
|
||||
|
||||
size_t grid_size;
|
||||
size_t queue_size;
|
||||
size_t map_size;
|
||||
|
||||
struct flanterm_fb_char *grid;
|
||||
|
||||
struct flanterm_fb_queue_item *queue;
|
||||
size_t queue_i;
|
||||
|
||||
struct flanterm_fb_queue_item **map;
|
||||
|
||||
uint32_t text_fg;
|
||||
uint32_t text_bg;
|
||||
size_t cursor_x;
|
||||
size_t cursor_y;
|
||||
|
||||
uint32_t saved_state_text_fg;
|
||||
uint32_t saved_state_text_bg;
|
||||
size_t saved_state_cursor_x;
|
||||
size_t saved_state_cursor_y;
|
||||
|
||||
size_t old_cursor_x;
|
||||
size_t old_cursor_y;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
133
include/io/term/flanterm_private.h
Normal file
133
include/io/term/flanterm_private.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/* Copyright (C) 2022-2026 Mintsuki and contributors.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef FLANTERM_PRIVATE_H
|
||||
#define FLANTERM_PRIVATE_H 1
|
||||
|
||||
#ifndef FLANTERM_IN_FLANTERM
|
||||
#error "Do not use flanterm_private.h. Use interfaces defined in flanterm.h only."
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FLANTERM_MAX_ESC_VALUES 16
|
||||
|
||||
struct flanterm_context {
|
||||
/* internal use */
|
||||
|
||||
size_t tab_size;
|
||||
bool autoflush;
|
||||
bool cursor_enabled;
|
||||
bool scroll_enabled;
|
||||
bool wrap_enabled;
|
||||
bool origin_mode;
|
||||
bool control_sequence;
|
||||
bool escape;
|
||||
bool osc;
|
||||
bool osc_escape;
|
||||
size_t osc_buf_i;
|
||||
uint8_t osc_buf[256];
|
||||
bool rrr;
|
||||
bool discard_next;
|
||||
bool bold;
|
||||
bool bg_bold;
|
||||
bool reverse_video;
|
||||
bool dec_private;
|
||||
bool insert_mode;
|
||||
bool csi_unhandled;
|
||||
uint64_t code_point;
|
||||
size_t unicode_remaining;
|
||||
uint8_t g_select;
|
||||
uint8_t charsets[2];
|
||||
size_t current_charset;
|
||||
size_t escape_offset;
|
||||
size_t esc_values_i;
|
||||
size_t saved_cursor_x;
|
||||
size_t saved_cursor_y;
|
||||
size_t current_primary;
|
||||
size_t current_bg;
|
||||
size_t scroll_top_margin;
|
||||
size_t scroll_bottom_margin;
|
||||
uint32_t esc_values[FLANTERM_MAX_ESC_VALUES];
|
||||
uint8_t last_printed_char;
|
||||
bool last_was_graphic;
|
||||
bool saved_state_bold;
|
||||
bool saved_state_bg_bold;
|
||||
bool saved_state_reverse_video;
|
||||
bool saved_state_origin_mode;
|
||||
bool saved_state_wrap_enabled;
|
||||
size_t saved_state_current_charset;
|
||||
uint8_t saved_state_charsets[2];
|
||||
size_t saved_state_current_primary;
|
||||
size_t saved_state_current_bg;
|
||||
|
||||
/* to be set by backend */
|
||||
|
||||
size_t rows, cols;
|
||||
|
||||
void (*raw_putchar)(struct flanterm_context *, uint8_t c);
|
||||
void (*clear)(struct flanterm_context *, bool move);
|
||||
void (*set_cursor_pos)(struct flanterm_context *, size_t x, size_t y);
|
||||
void (*get_cursor_pos)(struct flanterm_context *, size_t *x, size_t *y);
|
||||
void (*set_text_fg)(struct flanterm_context *, size_t fg);
|
||||
void (*set_text_bg)(struct flanterm_context *, size_t bg);
|
||||
void (*set_text_fg_bright)(struct flanterm_context *, size_t fg);
|
||||
void (*set_text_bg_bright)(struct flanterm_context *, size_t bg);
|
||||
void (*set_text_fg_rgb)(struct flanterm_context *, uint32_t fg);
|
||||
void (*set_text_bg_rgb)(struct flanterm_context *, uint32_t bg);
|
||||
void (*set_text_fg_default)(struct flanterm_context *);
|
||||
void (*set_text_bg_default)(struct flanterm_context *);
|
||||
void (*set_text_fg_default_bright)(struct flanterm_context *);
|
||||
void (*set_text_bg_default_bright)(struct flanterm_context *);
|
||||
void (*move_character)(struct flanterm_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y);
|
||||
void (*scroll)(struct flanterm_context *);
|
||||
void (*revscroll)(struct flanterm_context *);
|
||||
void (*swap_palette)(struct flanterm_context *);
|
||||
void (*save_state)(struct flanterm_context *);
|
||||
void (*restore_state)(struct flanterm_context *);
|
||||
void (*double_buffer_flush)(struct flanterm_context *);
|
||||
void (*full_refresh)(struct flanterm_context *);
|
||||
void (*deinit)(struct flanterm_context *, void (*)(void *, size_t));
|
||||
|
||||
/* to be set by client */
|
||||
|
||||
void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
};
|
||||
|
||||
void flanterm_context_reinit(struct flanterm_context *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1597
include/io/term/nanoprintf.h
Normal file
1597
include/io/term/nanoprintf.h
Normal file
File diff suppressed because it is too large
Load Diff
15
include/io/term/term.h
Normal file
15
include/io/term/term.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Framebuffer-based terminal driver
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef TERM_H
|
||||
#define TERM_H
|
||||
|
||||
void kputs(const char* str);
|
||||
void _putchar(char character);
|
||||
void term_init(void);
|
||||
int printf(const char* fmt, ...);
|
||||
|
||||
#endif
|
||||
63
include/kernel.h
Normal file
63
include/kernel.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Kernel global macros
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef KERNEL_H
|
||||
#define KERNEL_H
|
||||
|
||||
enum ErrorCodes {
|
||||
ENOMEM,
|
||||
EIO
|
||||
};
|
||||
|
||||
#define CLEAR_INTERRUPTS __asm__ volatile("cli")
|
||||
#define SET_INTERRUPTS __asm__ volatile("sti")
|
||||
|
||||
#include <io/serial/serial.h>
|
||||
#include <io/term/term.h>
|
||||
#include <idt/idt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern volatile uint64_t ticks;
|
||||
#define DEBUG(log, ...) printf("[%8u] debug: <%s>: " log "\r\n", ticks, __func__, ##__VA_ARGS__)
|
||||
|
||||
/* #define DEBUG(log, ...) \
|
||||
printf("debug: [%s]: " log "\r\n", __FILE__, ##__VA_ARGS__); \
|
||||
fctprintf((void*)&skputc, 0, "debug: [%s]: " log "\r\n", __FILE__, ##__VA_ARGS__)
|
||||
*/
|
||||
|
||||
#define DIE_DEBUG(str) printf(str)
|
||||
|
||||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
||||
|
||||
// printf("debug: [%s]: " log "\n", __FILE__, ##__VA_ARGS__);
|
||||
|
||||
void panic(struct cpu_status_t* ctx, const char* str);
|
||||
void hcf(void);
|
||||
void idle(void);
|
||||
|
||||
/* debug */
|
||||
void debug_stack_trace(unsigned int max_frames);
|
||||
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset);
|
||||
void boot_mem_display(void);
|
||||
|
||||
#define assert(check) do { if(!(check)) hcf(); } while(0)
|
||||
|
||||
struct boot_context {
|
||||
struct limine_framebuffer* fb;
|
||||
struct limine_memmap_response* mmap;
|
||||
struct limine_hhdm_response* hhdm;
|
||||
struct limine_kernel_address_response* kaddr;
|
||||
};
|
||||
|
||||
// Are these modules initialized yet?
|
||||
struct init_status {
|
||||
bool terminal;
|
||||
bool serial;
|
||||
bool keyboard;
|
||||
bool timer;
|
||||
};
|
||||
|
||||
#endif
|
||||
754
include/limine.h
Normal file
754
include/limine.h
Normal file
@@ -0,0 +1,754 @@
|
||||
/* BSD Zero Clause License */
|
||||
|
||||
/* Copyright (C) 2022-2025 Mintsuki and contributors.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LIMINE_H
|
||||
#define LIMINE_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Misc */
|
||||
|
||||
#ifdef LIMINE_NO_POINTERS
|
||||
# define LIMINE_PTR(TYPE) uint64_t
|
||||
#else
|
||||
# define LIMINE_PTR(TYPE) TYPE
|
||||
#endif
|
||||
|
||||
#ifndef LIMINE_API_REVISION
|
||||
# define LIMINE_API_REVISION 0
|
||||
#endif
|
||||
|
||||
#if LIMINE_API_REVISION > 3
|
||||
# error "limine.h API revision unsupported"
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define LIMINE_DEPRECATED __attribute__((__deprecated__))
|
||||
# define LIMINE_DEPRECATED_IGNORE_START \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
||||
# define LIMINE_DEPRECATED_IGNORE_END \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
# define LIMINE_DEPRECATED
|
||||
# define LIMINE_DEPRECATED_IGNORE_START
|
||||
# define LIMINE_DEPRECATED_IGNORE_END
|
||||
#endif
|
||||
|
||||
#define LIMINE_REQUESTS_START_MARKER \
|
||||
uint64_t limine_requests_start_marker[4] = { 0xf6b8f4b39de7d1ae, 0xfab91a6940fcb9cf, \
|
||||
0x785c6ed015d3e316, 0x181e920a7852b9d9 };
|
||||
#define LIMINE_REQUESTS_END_MARKER \
|
||||
uint64_t limine_requests_end_marker[2] = { 0xadc0e0531bb10d03, 0x9572709f31764c62 };
|
||||
|
||||
#define LIMINE_REQUESTS_DELIMITER LIMINE_REQUESTS_END_MARKER
|
||||
|
||||
#define LIMINE_BASE_REVISION(N) \
|
||||
uint64_t limine_base_revision[3] = { 0xf9562b2d5c95a6c8, 0x6a7b384944536bdc, (N) };
|
||||
|
||||
#define LIMINE_BASE_REVISION_SUPPORTED (limine_base_revision[2] == 0)
|
||||
|
||||
#define LIMINE_LOADED_BASE_REV_VALID (limine_base_revision[1] != 0x6a7b384944536bdc)
|
||||
#define LIMINE_LOADED_BASE_REVISION (limine_base_revision[1])
|
||||
|
||||
#define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
|
||||
|
||||
struct limine_uuid {
|
||||
uint32_t a;
|
||||
uint16_t b;
|
||||
uint16_t c;
|
||||
uint8_t d[8];
|
||||
};
|
||||
|
||||
#define LIMINE_MEDIA_TYPE_GENERIC 0
|
||||
#define LIMINE_MEDIA_TYPE_OPTICAL 1
|
||||
#define LIMINE_MEDIA_TYPE_TFTP 2
|
||||
|
||||
struct limine_file {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) address;
|
||||
uint64_t size;
|
||||
LIMINE_PTR(char *) path;
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
LIMINE_PTR(char *) string;
|
||||
#else
|
||||
LIMINE_PTR(char *) cmdline;
|
||||
#endif
|
||||
uint32_t media_type;
|
||||
uint32_t unused;
|
||||
uint32_t tftp_ip;
|
||||
uint32_t tftp_port;
|
||||
uint32_t partition_index;
|
||||
uint32_t mbr_disk_id;
|
||||
struct limine_uuid gpt_disk_uuid;
|
||||
struct limine_uuid gpt_part_uuid;
|
||||
struct limine_uuid part_uuid;
|
||||
};
|
||||
|
||||
/* Boot info */
|
||||
|
||||
#define LIMINE_BOOTLOADER_INFO_REQUEST { LIMINE_COMMON_MAGIC, 0xf55038d8e2a1202f, 0x279426fcf5f59740 }
|
||||
|
||||
struct limine_bootloader_info_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(char *) name;
|
||||
LIMINE_PTR(char *) version;
|
||||
};
|
||||
|
||||
struct limine_bootloader_info_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_bootloader_info_response *) response;
|
||||
};
|
||||
|
||||
/* Executable command line */
|
||||
|
||||
#define LIMINE_EXECUTABLE_CMDLINE_REQUEST { LIMINE_COMMON_MAGIC, 0x4b161536e598651e, 0xb390ad4a2f1f303a }
|
||||
|
||||
struct limine_executable_cmdline_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(char *) cmdline;
|
||||
};
|
||||
|
||||
struct limine_executable_cmdline_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_executable_cmdline_response *) response;
|
||||
};
|
||||
|
||||
/* Firmware type */
|
||||
|
||||
#define LIMINE_FIRMWARE_TYPE_REQUEST { LIMINE_COMMON_MAGIC, 0x8c2f75d90bef28a8, 0x7045a4688eac00c3 }
|
||||
|
||||
#define LIMINE_FIRMWARE_TYPE_X86BIOS 0
|
||||
#define LIMINE_FIRMWARE_TYPE_UEFI32 1
|
||||
#define LIMINE_FIRMWARE_TYPE_UEFI64 2
|
||||
#define LIMINE_FIRMWARE_TYPE_SBI 3
|
||||
|
||||
struct limine_firmware_type_response {
|
||||
uint64_t revision;
|
||||
uint64_t firmware_type;
|
||||
};
|
||||
|
||||
struct limine_firmware_type_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_firmware_type_response *) response;
|
||||
};
|
||||
|
||||
/* Stack size */
|
||||
|
||||
#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
|
||||
|
||||
struct limine_stack_size_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct limine_stack_size_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_stack_size_response *) response;
|
||||
uint64_t stack_size;
|
||||
};
|
||||
|
||||
/* HHDM */
|
||||
|
||||
#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }
|
||||
|
||||
struct limine_hhdm_response {
|
||||
uint64_t revision;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
struct limine_hhdm_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_hhdm_response *) response;
|
||||
};
|
||||
|
||||
/* Framebuffer */
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_REQUEST { LIMINE_COMMON_MAGIC, 0x9d5827dcd881dd75, 0xa3148604f6fab11b }
|
||||
|
||||
#define LIMINE_FRAMEBUFFER_RGB 1
|
||||
|
||||
struct limine_video_mode {
|
||||
uint64_t pitch;
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
uint16_t bpp;
|
||||
uint8_t memory_model;
|
||||
uint8_t red_mask_size;
|
||||
uint8_t red_mask_shift;
|
||||
uint8_t green_mask_size;
|
||||
uint8_t green_mask_shift;
|
||||
uint8_t blue_mask_size;
|
||||
uint8_t blue_mask_shift;
|
||||
};
|
||||
|
||||
struct limine_framebuffer {
|
||||
LIMINE_PTR(void *) address;
|
||||
uint64_t width;
|
||||
uint64_t height;
|
||||
uint64_t pitch;
|
||||
uint16_t bpp;
|
||||
uint8_t memory_model;
|
||||
uint8_t red_mask_size;
|
||||
uint8_t red_mask_shift;
|
||||
uint8_t green_mask_size;
|
||||
uint8_t green_mask_shift;
|
||||
uint8_t blue_mask_size;
|
||||
uint8_t blue_mask_shift;
|
||||
uint8_t unused[7];
|
||||
uint64_t edid_size;
|
||||
LIMINE_PTR(void *) edid;
|
||||
/* Response revision 1 */
|
||||
uint64_t mode_count;
|
||||
LIMINE_PTR(struct limine_video_mode **) modes;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_response {
|
||||
uint64_t revision;
|
||||
uint64_t framebuffer_count;
|
||||
LIMINE_PTR(struct limine_framebuffer **) framebuffers;
|
||||
};
|
||||
|
||||
struct limine_framebuffer_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_framebuffer_response *) response;
|
||||
};
|
||||
|
||||
/* Terminal */
|
||||
|
||||
#define LIMINE_TERMINAL_REQUEST { LIMINE_COMMON_MAGIC, 0xc8ac59310c2b0844, 0xa68d0c7265d38878 }
|
||||
|
||||
#define LIMINE_TERMINAL_CB_DEC 10
|
||||
#define LIMINE_TERMINAL_CB_BELL 20
|
||||
#define LIMINE_TERMINAL_CB_PRIVATE_ID 30
|
||||
#define LIMINE_TERMINAL_CB_STATUS_REPORT 40
|
||||
#define LIMINE_TERMINAL_CB_POS_REPORT 50
|
||||
#define LIMINE_TERMINAL_CB_KBD_LEDS 60
|
||||
#define LIMINE_TERMINAL_CB_MODE 70
|
||||
#define LIMINE_TERMINAL_CB_LINUX 80
|
||||
|
||||
#define LIMINE_TERMINAL_CTX_SIZE ((uint64_t)(-1))
|
||||
#define LIMINE_TERMINAL_CTX_SAVE ((uint64_t)(-2))
|
||||
#define LIMINE_TERMINAL_CTX_RESTORE ((uint64_t)(-3))
|
||||
#define LIMINE_TERMINAL_FULL_REFRESH ((uint64_t)(-4))
|
||||
|
||||
/* Response revision 1 */
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_GET ((uint64_t)(-10))
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_SET ((uint64_t)(-11))
|
||||
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OCRNL (1 << 0)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OFDEL (1 << 1)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OFILL (1 << 2)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OLCUC (1 << 3)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONLCR (1 << 4)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONLRET (1 << 5)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_ONOCR (1 << 6)
|
||||
#define LIMINE_TERMINAL_OOB_OUTPUT_OPOST (1 << 7)
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_START
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal;
|
||||
|
||||
typedef void (*limine_terminal_write)(struct limine_terminal *, const char *, uint64_t);
|
||||
typedef void (*limine_terminal_callback)(struct limine_terminal *, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal {
|
||||
uint64_t columns;
|
||||
uint64_t rows;
|
||||
LIMINE_PTR(struct limine_framebuffer *) framebuffer;
|
||||
};
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal_response {
|
||||
uint64_t revision;
|
||||
uint64_t terminal_count;
|
||||
LIMINE_PTR(struct limine_terminal **) terminals;
|
||||
LIMINE_PTR(limine_terminal_write) write;
|
||||
};
|
||||
|
||||
struct LIMINE_DEPRECATED limine_terminal_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_terminal_response *) response;
|
||||
LIMINE_PTR(limine_terminal_callback) callback;
|
||||
};
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_END
|
||||
|
||||
/* Paging mode */
|
||||
|
||||
#define LIMINE_PAGING_MODE_REQUEST { LIMINE_COMMON_MAGIC, 0x95c1a0edab0944cb, 0xa4e5cb3842f7488a }
|
||||
|
||||
#if defined (__x86_64__) || defined (__i386__)
|
||||
#define LIMINE_PAGING_MODE_X86_64_4LVL 0
|
||||
#define LIMINE_PAGING_MODE_X86_64_5LVL 1
|
||||
#define LIMINE_PAGING_MODE_MIN LIMINE_PAGING_MODE_X86_64_4LVL
|
||||
#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_X86_64_4LVL
|
||||
#elif defined (__aarch64__)
|
||||
#define LIMINE_PAGING_MODE_AARCH64_4LVL 0
|
||||
#define LIMINE_PAGING_MODE_AARCH64_5LVL 1
|
||||
#define LIMINE_PAGING_MODE_MIN LIMINE_PAGING_MODE_AARCH64_4LVL
|
||||
#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_AARCH64_4LVL
|
||||
#elif defined (__riscv) && (__riscv_xlen == 64)
|
||||
#define LIMINE_PAGING_MODE_RISCV_SV39 0
|
||||
#define LIMINE_PAGING_MODE_RISCV_SV48 1
|
||||
#define LIMINE_PAGING_MODE_RISCV_SV57 2
|
||||
#define LIMINE_PAGING_MODE_MIN LIMINE_PAGING_MODE_RISCV_SV39
|
||||
#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_RISCV_SV48
|
||||
#elif defined (__loongarch__) && (__loongarch_grlen == 64)
|
||||
#define LIMINE_PAGING_MODE_LOONGARCH64_4LVL 0
|
||||
#define LIMINE_PAGING_MODE_MIN LIMINE_PAGING_MODE_LOONGARCH64_4LVL
|
||||
#define LIMINE_PAGING_MODE_DEFAULT LIMINE_PAGING_MODE_LOONGARCH64_4LVL
|
||||
#else
|
||||
#error Unknown architecture
|
||||
#endif
|
||||
|
||||
struct limine_paging_mode_response {
|
||||
uint64_t revision;
|
||||
uint64_t mode;
|
||||
};
|
||||
|
||||
struct limine_paging_mode_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_paging_mode_response *) response;
|
||||
uint64_t mode;
|
||||
uint64_t max_mode;
|
||||
uint64_t min_mode;
|
||||
};
|
||||
|
||||
/* 5-level paging */
|
||||
|
||||
#define LIMINE_5_LEVEL_PAGING_REQUEST { LIMINE_COMMON_MAGIC, 0x94469551da9b3192, 0xebe5e86db7382888 }
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_START
|
||||
|
||||
struct LIMINE_DEPRECATED limine_5_level_paging_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct LIMINE_DEPRECATED limine_5_level_paging_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_5_level_paging_response *) response;
|
||||
};
|
||||
|
||||
LIMINE_DEPRECATED_IGNORE_END
|
||||
|
||||
/* MP */
|
||||
|
||||
#if LIMINE_API_REVISION >= 1
|
||||
# define LIMINE_MP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
|
||||
# define LIMINE_MP(TEXT) limine_mp_##TEXT
|
||||
#else
|
||||
# define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
|
||||
# define LIMINE_MP(TEXT) limine_smp_##TEXT
|
||||
#endif
|
||||
|
||||
struct LIMINE_MP(info);
|
||||
|
||||
typedef void (*limine_goto_address)(struct LIMINE_MP(info) *);
|
||||
|
||||
#if defined (__x86_64__) || defined (__i386__)
|
||||
|
||||
#if LIMINE_API_REVISION >= 1
|
||||
# define LIMINE_MP_X2APIC (1 << 0)
|
||||
#else
|
||||
# define LIMINE_SMP_X2APIC (1 << 0)
|
||||
#endif
|
||||
|
||||
struct LIMINE_MP(info) {
|
||||
uint32_t processor_id;
|
||||
uint32_t lapic_id;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
struct LIMINE_MP(response) {
|
||||
uint64_t revision;
|
||||
uint32_t flags;
|
||||
uint32_t bsp_lapic_id;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct LIMINE_MP(info) **) cpus;
|
||||
};
|
||||
|
||||
#elif defined (__aarch64__)
|
||||
|
||||
struct LIMINE_MP(info) {
|
||||
uint32_t processor_id;
|
||||
uint32_t reserved1;
|
||||
uint64_t mpidr;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
struct LIMINE_MP(response) {
|
||||
uint64_t revision;
|
||||
uint64_t flags;
|
||||
uint64_t bsp_mpidr;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct LIMINE_MP(info) **) cpus;
|
||||
};
|
||||
|
||||
#elif defined (__riscv) && (__riscv_xlen == 64)
|
||||
|
||||
struct LIMINE_MP(info) {
|
||||
uint64_t processor_id;
|
||||
uint64_t hartid;
|
||||
uint64_t reserved;
|
||||
LIMINE_PTR(limine_goto_address) goto_address;
|
||||
uint64_t extra_argument;
|
||||
};
|
||||
|
||||
struct LIMINE_MP(response) {
|
||||
uint64_t revision;
|
||||
uint64_t flags;
|
||||
uint64_t bsp_hartid;
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct LIMINE_MP(info) **) cpus;
|
||||
};
|
||||
|
||||
#elif defined (__loongarch__) && (__loongarch_grlen == 64)
|
||||
|
||||
struct LIMINE_MP(info) {
|
||||
uint64_t reserved;
|
||||
};
|
||||
|
||||
struct LIMINE_MP(response) {
|
||||
uint64_t cpu_count;
|
||||
LIMINE_PTR(struct LIMINE_MP(info) **) cpus;
|
||||
};
|
||||
|
||||
#else
|
||||
#error Unknown architecture
|
||||
#endif
|
||||
|
||||
struct LIMINE_MP(request) {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct LIMINE_MP(response) *) response;
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
/* Memory map */
|
||||
|
||||
#define LIMINE_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x67cf3d9d378a806f, 0xe304acdfc50c3c62 }
|
||||
|
||||
#define LIMINE_MEMMAP_USABLE 0
|
||||
#define LIMINE_MEMMAP_RESERVED 1
|
||||
#define LIMINE_MEMMAP_ACPI_RECLAIMABLE 2
|
||||
#define LIMINE_MEMMAP_ACPI_NVS 3
|
||||
#define LIMINE_MEMMAP_BAD_MEMORY 4
|
||||
#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
# define LIMINE_MEMMAP_EXECUTABLE_AND_MODULES 6
|
||||
#else
|
||||
# define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
|
||||
#endif
|
||||
#define LIMINE_MEMMAP_FRAMEBUFFER 7
|
||||
|
||||
struct limine_memmap_entry {
|
||||
uint64_t base;
|
||||
uint64_t length;
|
||||
uint64_t type;
|
||||
};
|
||||
|
||||
struct limine_memmap_response {
|
||||
uint64_t revision;
|
||||
uint64_t entry_count;
|
||||
LIMINE_PTR(struct limine_memmap_entry **) entries;
|
||||
};
|
||||
|
||||
struct limine_memmap_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_memmap_response *) response;
|
||||
};
|
||||
|
||||
/* Entry point */
|
||||
|
||||
#define LIMINE_ENTRY_POINT_REQUEST { LIMINE_COMMON_MAGIC, 0x13d86c035a1cd3e1, 0x2b0caa89d8f3026a }
|
||||
|
||||
typedef void (*limine_entry_point)(void);
|
||||
|
||||
struct limine_entry_point_response {
|
||||
uint64_t revision;
|
||||
};
|
||||
|
||||
struct limine_entry_point_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_entry_point_response *) response;
|
||||
LIMINE_PTR(limine_entry_point) entry;
|
||||
};
|
||||
|
||||
/* Executable File */
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
# define LIMINE_EXECUTABLE_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
|
||||
#else
|
||||
# define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
|
||||
#endif
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
struct limine_executable_file_response {
|
||||
#else
|
||||
struct limine_kernel_file_response {
|
||||
#endif
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
LIMINE_PTR(struct limine_file *) executable_file;
|
||||
#else
|
||||
LIMINE_PTR(struct limine_file *) kernel_file;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
struct limine_executable_file_request {
|
||||
#else
|
||||
struct limine_kernel_file_request {
|
||||
#endif
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
LIMINE_PTR(struct limine_executable_file_response *) response;
|
||||
#else
|
||||
LIMINE_PTR(struct limine_kernel_file_response *) response;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Module */
|
||||
|
||||
#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
|
||||
|
||||
#define LIMINE_INTERNAL_MODULE_REQUIRED (1 << 0)
|
||||
#define LIMINE_INTERNAL_MODULE_COMPRESSED (1 << 1)
|
||||
|
||||
struct limine_internal_module {
|
||||
LIMINE_PTR(const char *) path;
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
LIMINE_PTR(const char *) string;
|
||||
#else
|
||||
LIMINE_PTR(const char *) cmdline;
|
||||
#endif
|
||||
uint64_t flags;
|
||||
};
|
||||
|
||||
struct limine_module_response {
|
||||
uint64_t revision;
|
||||
uint64_t module_count;
|
||||
LIMINE_PTR(struct limine_file **) modules;
|
||||
};
|
||||
|
||||
struct limine_module_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_module_response *) response;
|
||||
|
||||
/* Request revision 1 */
|
||||
uint64_t internal_module_count;
|
||||
LIMINE_PTR(struct limine_internal_module **) internal_modules;
|
||||
};
|
||||
|
||||
/* RSDP */
|
||||
|
||||
#define LIMINE_RSDP_REQUEST { LIMINE_COMMON_MAGIC, 0xc5e77b6b397e7b43, 0x27637845accdcf3c }
|
||||
|
||||
struct limine_rsdp_response {
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 1
|
||||
uint64_t address;
|
||||
#else
|
||||
LIMINE_PTR(void *) address;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct limine_rsdp_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_rsdp_response *) response;
|
||||
};
|
||||
|
||||
/* SMBIOS */
|
||||
|
||||
#define LIMINE_SMBIOS_REQUEST { LIMINE_COMMON_MAGIC, 0x9e9046f11e095391, 0xaa4a520fefbde5ee }
|
||||
|
||||
struct limine_smbios_response {
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 1
|
||||
uint64_t entry_32;
|
||||
uint64_t entry_64;
|
||||
#else
|
||||
LIMINE_PTR(void *) entry_32;
|
||||
LIMINE_PTR(void *) entry_64;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct limine_smbios_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_smbios_response *) response;
|
||||
};
|
||||
|
||||
/* EFI system table */
|
||||
|
||||
#define LIMINE_EFI_SYSTEM_TABLE_REQUEST { LIMINE_COMMON_MAGIC, 0x5ceba5163eaaf6d6, 0x0a6981610cf65fcc }
|
||||
|
||||
struct limine_efi_system_table_response {
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 1
|
||||
uint64_t address;
|
||||
#else
|
||||
LIMINE_PTR(void *) address;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct limine_efi_system_table_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_efi_system_table_response *) response;
|
||||
};
|
||||
|
||||
/* EFI memory map */
|
||||
|
||||
#define LIMINE_EFI_MEMMAP_REQUEST { LIMINE_COMMON_MAGIC, 0x7df62a431d6872d5, 0xa4fcdfb3e57306c8 }
|
||||
|
||||
struct limine_efi_memmap_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) memmap;
|
||||
uint64_t memmap_size;
|
||||
uint64_t desc_size;
|
||||
uint64_t desc_version;
|
||||
};
|
||||
|
||||
struct limine_efi_memmap_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_efi_memmap_response *) response;
|
||||
};
|
||||
|
||||
/* Date at boot */
|
||||
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
# define LIMINE_DATE_AT_BOOT_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
|
||||
#else
|
||||
# define LIMINE_BOOT_TIME_REQUEST { LIMINE_COMMON_MAGIC, 0x502746e184c088aa, 0xfbc5ec83e6327893 }
|
||||
#endif
|
||||
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
struct limine_date_at_boot_response {
|
||||
#else
|
||||
struct limine_boot_time_response {
|
||||
#endif
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
int64_t timestamp;
|
||||
#else
|
||||
int64_t boot_time;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
struct limine_date_at_boot_request {
|
||||
#else
|
||||
struct limine_boot_time_request {
|
||||
#endif
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 3
|
||||
LIMINE_PTR(struct limine_date_at_boot_response *) response;
|
||||
#else
|
||||
LIMINE_PTR(struct limine_boot_time_response *) response;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Executable address */
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
# define LIMINE_EXECUTABLE_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
|
||||
#else
|
||||
# define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
|
||||
#endif
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
struct limine_executable_address_response {
|
||||
#else
|
||||
struct limine_kernel_address_response {
|
||||
#endif
|
||||
uint64_t revision;
|
||||
uint64_t physical_base;
|
||||
uint64_t virtual_base;
|
||||
};
|
||||
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
struct limine_executable_address_request {
|
||||
#else
|
||||
struct limine_kernel_address_request {
|
||||
#endif
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
#if LIMINE_API_REVISION >= 2
|
||||
LIMINE_PTR(struct limine_executable_address_response *) response;
|
||||
#else
|
||||
LIMINE_PTR(struct limine_kernel_address_response *) response;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Device Tree Blob */
|
||||
|
||||
#define LIMINE_DTB_REQUEST { LIMINE_COMMON_MAGIC, 0xb40ddb48fb54bac7, 0x545081493f81ffb7 }
|
||||
|
||||
struct limine_dtb_response {
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(void *) dtb_ptr;
|
||||
};
|
||||
|
||||
struct limine_dtb_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_dtb_response *) response;
|
||||
};
|
||||
|
||||
/* RISC-V Boot Hart ID */
|
||||
|
||||
#define LIMINE_RISCV_BSP_HARTID_REQUEST { LIMINE_COMMON_MAGIC, 0x1369359f025525f9, 0x2ff2a56178391bb6 }
|
||||
|
||||
struct limine_riscv_bsp_hartid_response {
|
||||
uint64_t revision;
|
||||
uint64_t bsp_hartid;
|
||||
};
|
||||
|
||||
struct limine_riscv_bsp_hartid_request {
|
||||
uint64_t id[4];
|
||||
uint64_t revision;
|
||||
LIMINE_PTR(struct limine_riscv_bsp_hartid_response *) response;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
31
include/mem/gdt.h
Normal file
31
include/mem/gdt.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Global Descriptor Table (for legacy reasons)
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef GDT_H
|
||||
#define GDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// We're using the GDT for segmentation, but as we want to target Long Mode,
|
||||
// we'll only use this as a requirement for paging, not more.
|
||||
// This means base 0 and no limit (whole address space)
|
||||
|
||||
#define NUM_GDT_ENTRIES 5
|
||||
|
||||
#define NULL_SELECTOR 0x00
|
||||
#define KERNEL_CODE_SEGMENT 0x08
|
||||
#define KERNEL_DATA_SEGMENT 0x10
|
||||
#define USER_CODE_SEGMENT 0x18
|
||||
#define USER_DATA_SEGMENT 0x20
|
||||
|
||||
struct GDTR {
|
||||
uint16_t limit;
|
||||
uint64_t address;
|
||||
} __attribute__((packed));
|
||||
|
||||
void gdt_init(void);
|
||||
|
||||
#endif
|
||||
32
include/mem/kheap.h
Normal file
32
include/mem/kheap.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Kernel heap
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef KHEAP_H
|
||||
#define KHEAP_H
|
||||
|
||||
// We need some kind of simple kernel heap to make our linked list
|
||||
// for the VMM, as we need "malloc" and "free" for that data structure.
|
||||
// When the kernel heap is ready, we can alloc our VM object linked list
|
||||
// and then continue working on the VMM.
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct heap_block_t {
|
||||
size_t size;
|
||||
bool free; // 1byte
|
||||
uint8_t reserved[7]; // (7+1 = 8 bytes)
|
||||
struct heap_block_t* next;
|
||||
} __attribute__((aligned(16)));
|
||||
|
||||
void kheap_init(void);
|
||||
void* kmalloc(size_t size);
|
||||
void kfree(void* ptr);
|
||||
void* kalloc_stack(void);
|
||||
void kheap_map_page(void);
|
||||
|
||||
#endif
|
||||
55
include/mem/paging.h
Normal file
55
include/mem/paging.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief x64 4-level paging implementation
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef PAGING_H
|
||||
#define PAGING_H
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limine.h>
|
||||
#include <mem/kheap.h>
|
||||
#include <kernel.h>
|
||||
|
||||
void paging_init(struct boot_context boot_ctx);
|
||||
void paging_map_page(uint64_t* root_table, uint64_t virt, uint64_t phys, uint64_t flags);
|
||||
|
||||
// To swap root page tables
|
||||
void load_cr3(uint64_t value);
|
||||
|
||||
extern uint64_t hhdm_off;
|
||||
|
||||
#define PHYS_TO_VIRT(x) ((void*)((uintptr_t)(x) + hhdm_off))
|
||||
#define VIRT_TO_PHYS(x) ((uintptr_t)(x) - hhdm_off)
|
||||
|
||||
#define PTE_ADDR_MASK 0x000FFFFFFFFFF000
|
||||
// Stole it
|
||||
#define ALIGN_UP(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
||||
#define ALIGN_DOWN(x, align) ((x) & ~((align) - 1))
|
||||
#define PAGE_ALIGN_DOWN(x) ((x) & PTE_ADDR_MASK)
|
||||
|
||||
#define ALIGN(size) ALIGN_UP(size, 16)
|
||||
#define BLOCK_MIN_SIZE (sizeof(struct heap_block_t) + 16)
|
||||
|
||||
#define PML4_INDEX(x) (((x) >> 39) & 0x1FF)
|
||||
#define PDPT_INDEX(x) (((x) >> 30) & 0x1FF)
|
||||
#define PD_INDEX(x) (((x) >> 21) & 0x1FF)
|
||||
#define PT_INDEX(x) (((x) >> 12) & 0x1FF)
|
||||
|
||||
// Page entry special bits
|
||||
// Bits set on a parent (directory, table) fall back to their children
|
||||
enum PTE_FLAGS
|
||||
{
|
||||
PTE_PRESENT = (1ULL << 0),
|
||||
PTE_WRITABLE = (1ULL << 1),
|
||||
PTE_USER = (1ULL << 2),
|
||||
PTE_PWT = (1ULL << 3),
|
||||
PTE_PCD = (1ULL << 4),
|
||||
PTE_HUGE = (1ULL << 7),
|
||||
PTE_NOEXEC = (1ULL << 63)
|
||||
};
|
||||
|
||||
#endif
|
||||
17
include/mem/pmm.h
Normal file
17
include/mem/pmm.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Physical memory manager from freelist
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef PAGING_PMM_H
|
||||
#define PAGING_PMM_H
|
||||
|
||||
#include <limine.h>
|
||||
#include <kernel.h>
|
||||
|
||||
void pmm_init(struct boot_context boot_ctx);
|
||||
void pmm_free(uintptr_t addr);
|
||||
uintptr_t pmm_alloc(void);
|
||||
|
||||
#endif
|
||||
21
include/mem/utils.h
Normal file
21
include/mem/utils.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Common memory utilities
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef MEM_UTILS_H
|
||||
#define MEM_UTILS_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void* memcpy(void* restrict dest, const void* restrict src, size_t n);
|
||||
void* memset(void* s, int c, size_t n);
|
||||
void* memmove(void *dest, const void* src, size_t n);
|
||||
int memcmp(const void* s1, const void* s2, size_t n);
|
||||
|
||||
// DEBUG
|
||||
void memmap_display(struct limine_memmap_response* response);
|
||||
void hhdm_display(struct limine_hhdm_response* hhdm);
|
||||
|
||||
#endif
|
||||
34
include/mem/vmm.h
Normal file
34
include/mem/vmm.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Virtual memory manager
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef VMM_H
|
||||
#define VMM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
This will be our linked list of virtual memory objects.
|
||||
Flags here aren't x86 flags, they are platform-agnostic
|
||||
kernel-defined flags.
|
||||
*/
|
||||
|
||||
struct vm_object {
|
||||
uintptr_t base;
|
||||
size_t length;
|
||||
size_t flags;
|
||||
struct vm_object* next;
|
||||
};
|
||||
|
||||
// Flags bitfield
|
||||
#define VM_FLAG_NONE 0
|
||||
#define VM_FLAG_WRITE (1 << 0)
|
||||
#define VM_FLAG_EXEC (1 << 1)
|
||||
#define VM_FLAG_USER (1 << 2)
|
||||
|
||||
void vmm_init(void);
|
||||
|
||||
#endif
|
||||
39
include/sched/process.h
Normal file
39
include/sched/process.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Process definition
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
READY,
|
||||
RUNNING,
|
||||
DEAD
|
||||
} status_t;
|
||||
|
||||
struct process_t {
|
||||
size_t pid;
|
||||
char name[PROCESS_NAME_MAX];
|
||||
|
||||
status_t status;
|
||||
struct cpu_status_t* context;
|
||||
void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511]
|
||||
struct process_t* next;
|
||||
};
|
||||
|
||||
void process_init(void);
|
||||
struct process_t* process_create(char* name, void(*function)(void*), void* arg);
|
||||
void process_add(struct process_t** processes_list, struct process_t* process);
|
||||
void process_delete(struct process_t** processes_list, struct process_t* process);
|
||||
struct process_t* process_get_next(struct process_t* process);
|
||||
void process_exit(void);
|
||||
|
||||
void process_display_list(struct process_t* processes_list);
|
||||
|
||||
#endif
|
||||
13
include/sched/scheduler.h
Normal file
13
include/sched/scheduler.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Round-robin scheduler
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef SCHEDULER_H
|
||||
#define SCHEDULER_H
|
||||
|
||||
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context);
|
||||
void scheduler_init(void);
|
||||
|
||||
#endif
|
||||
22
include/sched/spinlock.h
Normal file
22
include/sched/spinlock.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Spinlock implementation
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef SPINLOCK_H
|
||||
#define SPINLOCK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct spinlock_t
|
||||
{
|
||||
bool locked;
|
||||
uint64_t rflags;
|
||||
};
|
||||
|
||||
void spinlock_acquire(struct spinlock_t* lock);
|
||||
void spinlock_release(struct spinlock_t* lock);
|
||||
|
||||
#endif
|
||||
16
include/string/string.h
Normal file
16
include/string/string.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief String manipulation functions
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strcat(char *dest, const char *src);
|
||||
void strncpy(char* dst, const char* src, size_t n);
|
||||
|
||||
#endif
|
||||
13
include/time/timer.h
Normal file
13
include/time/timer.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief PIT functions
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
void timer_init(void);
|
||||
void timer_wait(unsigned int wait_ticks);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user