Got basic tty driver & implemented Stack Smash Protector

This commit is contained in:
2025-02-17 21:02:10 +01:00
parent 983174a081
commit f9dece59ce
8 changed files with 114 additions and 24 deletions
+41 -3
View File
@@ -1,6 +1,33 @@
#ifndef _KERNEL_H
#define _KERNEL_H
// Null definition
#define NULL ((void*)0)
/*
* Variable arguments
*/
typedef void* va_list;
#define va_start(ap, param) (void)((ap) = (char*)(&(param) + 1))
#define va_end(ap) (void)((ap) = 0)
#define va_arg(ap, type) (((type*)((ap) = ((ap) + sizeof(type))))[-1])
/*
* Utility macros
*/
#define ARRAY_SIZE(_a) (sizeof((_a)) / sizeof((_a)[0]))
#define BIT(_n) (1UL << (_n))
#define BIT_MASK(_n) (BIT(_n) - 1)
#define ALIGN(_x, _a) __ALIGN_MASK((_x), (typeof(_x))(_a) - 1)
#define __ALIGN_MASK(_x, _m) (((_x) + (_m)) & ~(_m))
#define container_of(_p, _t, _m) \
((_t*)((char*)(_p) - offsetof(_t, _m)))
#define swap(_a, _b) ({ typeof(_a) _tmp = (_a); (_a) = (_b); (_b) = (_a); })
#define min(_x, _y) ({ typeof(_x) __x = (_x); typeof(_y) __y = (_y); __x < __y ? __x : __y; })
#define max(_x, _y) ({ typeof(_x) __x = (_x); typeof(_y) __y = (_y); __x > __y ? __x : __y; })
#define ceil(_x, _y) ((((_x) + (_y)) (_y)) * (_y))
#define floor(_x, _y) ((_x) - ((_x) % (_y)))
/*
* Attribute definitions
*/
@@ -20,18 +47,29 @@
/*
* Standard int types
*/
// Unsigned
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
// Signed
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long int64_t;
// Size
typedef uint32_t size_t;
typedef int32_t ssize_t;
typedef uint32_t uintptr_t;
typedef int32_t intptr_t;
/*
* Logging and errors
*/
// TODO: Logging with printk()
// TODO: Log levels & pr_*() wrappers for printk()
#define BUG() (panic("BUG()"))
#define WARN() NULL
#define BUG_ON(_e) ((_e) ? BUG() : NULL)
#define WARN_ON(_e) ((_e) ? WARN() : NULL)
// TODO: Write a panic()
#define panic(_s) while(1);
#endif
+6 -4
View File
@@ -2,13 +2,15 @@
#define _TTY_H
/* VGA Text mode */
#define VGA_ATTR(_fg, _bg) ((_fg) | ((_bg) << 4)
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define VGA_MEMORY 0xb8000
int tty_init(void);
int tty_write(char* buf, size_t len);
int tty_putc(char c);
int tty_puts(char* s);
void tty_init(void);
void tty_clear(void);
void tty_setattr(uint8_t attr);
void tty_putc(char c);
void tty_puts(char* s);
#endif