toaruos/kernel/include/system.h

205 lines
6.3 KiB
C
Raw Normal View History

2011-01-16 04:01:19 +03:00
#ifndef __SYSTEM_H
#define __SYSTEM_H
2011-03-22 07:57:24 +03:00
#define _KERNEL_
#include <types.h>
2011-03-22 07:57:24 +03:00
/* Unimportant Kernel Strings */
#define KERNEL_UNAME "ToAruOS"
#define KERNEL_VERSION_STRING "0.0.1"
2011-01-31 02:00:38 +03:00
extern void *sbrk(uintptr_t increment);
2011-01-16 04:01:19 +03:00
/* Kernel Main */
2011-01-31 02:00:38 +03:00
extern void *memcpy(void *restrict dest, const void *restrict src, size_t count);
2011-01-18 03:22:48 +03:00
extern void *memset(void *dest, int val, size_t count);
2011-01-16 04:01:19 +03:00
extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
extern int strlen(const char *str);
2011-02-11 06:45:29 +03:00
extern int atoi(const char *str);
2011-01-31 02:00:38 +03:00
extern unsigned char inportb(unsigned short _port);
extern void outportb(unsigned short _port, unsigned char _data);
extern unsigned short inports(unsigned short _port);
extern void outports(unsigned short _port, unsigned short _data);
extern int strcmp(const char *a, const char *b);
extern char * strtok_r(char * str, const char * delim, char ** saveptr);
extern size_t lfind(const char * str, const char accept);
extern size_t strspn(const char * str, const char * accept);
extern char * strpbrk(const char * str, const char * accept);
extern uint32_t krand();
2011-01-16 04:01:19 +03:00
2011-01-21 04:49:35 +03:00
/* Panic */
#define HALT_AND_CATCH_FIRE(mesg) halt_and_catch_fire(mesg, __FILE__, __LINE__)
#define ASSERT(statement) ((statement) ? (void)0 : assert_failed(__FILE__, __LINE__, #statement))
#define assert(statement) ((statement) ? (void)0 : assert_failed(__FILE__, __LINE__, #statement))
2011-01-31 02:00:38 +03:00
void halt_and_catch_fire(char *error_message, const char *file, int line);
2011-01-21 04:49:35 +03:00
void assert_failed(const char *file, uint32_t line, const char *desc);
2011-01-16 04:01:19 +03:00
/* VGA driver */
extern void cls();
2011-01-16 19:56:44 +03:00
extern void puts(char *str);
2011-01-16 04:01:19 +03:00
extern void settextcolor(unsigned char forecolor, unsigned char backcolor);
extern void resettextcolor();
2011-03-25 04:24:59 +03:00
extern void brighttextcolor();
2011-01-16 04:01:19 +03:00
extern void init_video();
extern void placech(unsigned char c, int x, int y, int attr);
extern void writechf(unsigned char c);
extern void writech(unsigned char c);
2011-03-25 04:03:52 +03:00
extern void place_csr(uint32_t x, uint32_t y);
extern void store_csr();
extern void restore_csr();
extern void set_serial(int);
extern void set_csr(int);
2011-01-16 04:01:19 +03:00
2011-01-16 04:59:11 +03:00
/* GDT */
extern void gdt_install();
2011-01-31 02:00:38 +03:00
extern void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access,
unsigned char gran);
2011-01-16 04:59:11 +03:00
2011-01-16 06:41:17 +03:00
/* IDT */
extern void idt_install();
2011-01-31 02:00:38 +03:00
extern void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel,
unsigned char flags);
2011-01-16 06:41:17 +03:00
/* Registers */
struct regs {
2011-01-31 02:00:38 +03:00
unsigned int gs, fs, es, ds;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, useresp, ss;
2011-01-16 06:41:17 +03:00
};
2011-01-31 02:00:38 +03:00
typedef void (*irq_handler_t) (struct regs *);
2011-01-18 03:22:48 +03:00
2011-01-16 19:56:44 +03:00
/* ISRS */
extern void isrs_install();
2011-01-21 04:49:35 +03:00
extern void isrs_install_handler(int isrs, irq_handler_t);
extern void isrs_uninstall_handler(int isrs);
2011-01-16 19:56:44 +03:00
2011-01-16 07:17:42 +03:00
/* Interrupt Handlers */
extern void irq_install();
2011-01-18 03:22:48 +03:00
extern void irq_install_handler(int irq, irq_handler_t);
2011-01-16 07:17:42 +03:00
extern void irq_uninstall_handler(int irq);
2011-01-16 19:56:44 +03:00
/* Timer */
extern void timer_install();
2011-01-18 03:22:48 +03:00
extern long timer_ticks;
2011-01-16 19:56:44 +03:00
extern void timer_wait(int ticks);
2011-01-16 21:45:51 +03:00
/* Keyboard */
typedef void (*keyboard_buffer_t)(char ch);
keyboard_buffer_t keyboard_buffer_handler;
2011-01-16 21:45:51 +03:00
extern void keyboard_install();
extern void keyboard_wait();
extern void putch(unsigned char c);
2011-01-16 21:45:51 +03:00
2011-01-17 19:24:55 +03:00
/* kprintf */
extern void kprintf(const char *fmt, ...);
extern int kgets(char *buf, int size);
2011-01-17 19:24:55 +03:00
2011-01-21 04:49:35 +03:00
/* Memory Management */
extern uintptr_t placement_pointer;
2011-01-22 10:38:25 +03:00
extern void kmalloc_startat(uintptr_t address);
2011-01-21 04:49:35 +03:00
extern uintptr_t kmalloc_real(size_t size, int align, uintptr_t * phys);
extern uintptr_t kmalloc(size_t size);
extern uintptr_t kvmalloc(size_t size);
extern uintptr_t kmalloc_p(size_t size, uintptr_t * phys);
extern uintptr_t kvmalloc_p(size_t size, uintptr_t * phys);
typedef struct page {
2011-01-31 02:00:38 +03:00
uint32_t present:1;
uint32_t rw:1;
uint32_t user:1;
uint32_t accessed:1;
uint32_t dirty:1;
uint32_t unused:7;
uint32_t frame:20;
2011-01-21 04:49:35 +03:00
} page_t;
typedef struct page_table {
page_t pages[1024];
} page_table_t;
typedef struct page_directory {
2011-01-31 02:00:38 +03:00
page_table_t *tables[1024]; /* 1024 pointers to page tables... */
uintptr_t physical_tables[1024]; /* Physical addresses of the tables */
uintptr_t physical_address; /* The physical address of physical_tables */
2011-01-21 04:49:35 +03:00
} page_directory_t;
2011-01-31 02:00:38 +03:00
page_directory_t *kernel_directory;
page_directory_t *current_directory;
2011-01-21 04:49:35 +03:00
extern void paging_install(uint32_t memsize);
2011-01-31 02:00:38 +03:00
extern void switch_page_directory(page_directory_t * new);
extern page_t *get_page(uintptr_t address, int make, page_directory_t * dir);
2011-01-21 04:49:35 +03:00
extern void page_fault(struct regs *r);
2011-01-22 09:03:26 +03:00
void heap_install();
2011-01-21 04:49:35 +03:00
void alloc_frame(page_t *page, int is_kernel, int is_writeable);
/* klmalloc */
void * __attribute__ ((malloc)) malloc(size_t size);
2011-01-31 02:00:38 +03:00
void * __attribute__ ((malloc)) realloc(void *ptr, size_t size);
void * __attribute__ ((malloc)) calloc(size_t nmemb, size_t size);
2011-02-28 07:00:08 +03:00
void * __attribute__ ((malloc)) valloc(size_t size);
2011-01-31 02:00:38 +03:00
void free(void *ptr);
2011-01-21 04:49:35 +03:00
/* shell */
extern void start_shell();
2011-02-11 06:45:29 +03:00
/* Serial */
extern void serial_install();
extern char serial_recv();
extern void serial_send(char out);
/* Tasks */
extern uintptr_t read_eip();
extern void copy_page_physical(uint32_t, uint32_t);
extern page_directory_t * clone_directory(page_directory_t * src);
extern page_table_t * clone_table(page_table_t * src, uintptr_t * physAddr);
extern void move_stack(void *new_stack_start, size_t size);
typedef struct task {
uint32_t id;
uintptr_t esp;
uintptr_t ebp;
uintptr_t eip;
page_directory_t * page_directory;
struct task *next;
uintptr_t kernel_stack;
uintptr_t stack;
} task_t;
extern void tasking_install();
extern void switch_task();
extern uint32_t fork();
extern uint32_t getpid();
uintptr_t initial_esp;
2011-02-11 06:45:29 +03:00
/* Kernel Argument Parser */
extern void parse_args(char * argv);
2011-03-25 08:09:23 +03:00
/* CMOS */
extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
/* CPU Detect by Brynet */
extern int detect_cpu();
/* Video Drivers */
/* BOCHS / QEMU VBE Driver */
extern void graphics_install_bochs();
extern void bochs_set_bank(uint16_t bank);
extern void bochs_set_coord(uint16_t x, uint16_t y, uint32_t color);
extern void bochs_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color);
extern void bochs_draw_logo(char *);
extern void bochs_scroll();
extern void bochs_write_number(uint8_t val, uint16_t x, uint16_t y, uint32_t fg, uint32_t bg);
extern uint16_t bochs_resolution_x;
extern uint16_t bochs_resolution_y;
extern uint16_t bochs_resolution_b;
extern char number_font[][12];
2011-01-16 04:01:19 +03:00
#endif