reimplmenets the previous iteration with a brand new custom build system
This commit is contained in:
12
kernel/include/kernel/_kernel.h
Normal file
12
kernel/include/kernel/_kernel.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_KERNEL_H
|
||||
#define _KERNEL_KERNEL_H
|
||||
|
||||
void kerror(const char*);
|
||||
|
||||
void kwarn(const char*);
|
||||
|
||||
void kinfo(const char*);
|
||||
|
||||
|
||||
#endif
|
||||
|
91
kernel/include/kernel/serial.h
Normal file
91
kernel/include/kernel/serial.h
Normal file
@ -0,0 +1,91 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _KERNEL_SERIAL_H
|
||||
#define _KERNEL_SERIAL_H
|
||||
|
||||
/**
|
||||
* serial_initialize:
|
||||
* Initializes the serial port for writing.
|
||||
*/
|
||||
void serial_initialize(void);
|
||||
|
||||
/**
|
||||
* serial_configure_baud_rate:
|
||||
* Sets the speed of the data being sent.
|
||||
* The argument is a divisor of that number, hence the speed becomes
|
||||
* (speed / divisor) bits/s.
|
||||
*
|
||||
* @param com The COM port to configure
|
||||
* @param divisor The divisor
|
||||
*/
|
||||
void serial_configure_baud_rate(unsigned short com, unsigned short divisor);
|
||||
|
||||
/**
|
||||
* serial_configure_line:
|
||||
* Configures the line of the given serial port. The port is set to have a
|
||||
* data length of 8 bits, no parity bits, one stop bit and break control
|
||||
* disabled.
|
||||
*
|
||||
* @param com The serial port to configure
|
||||
*/
|
||||
void serial_configure_line(unsigned short com);
|
||||
|
||||
/**
|
||||
* serial_configure_buffers:
|
||||
* Configures the buffer of the given serial port. The port is set to
|
||||
* enable FIFO, clear the receiver and transmission FIFO queues,
|
||||
* and to use 14 bytes as a size of the queue.
|
||||
*
|
||||
* @param com The serial port to configure
|
||||
*/
|
||||
void serial_configure_buffers(unsigned short com);
|
||||
|
||||
/**
|
||||
* serial_configure_modem:
|
||||
* Configures the modem of the given serial port.
|
||||
* We don't need interrupts, and just need RTS and DTS.
|
||||
*
|
||||
* @param com The serial port to configure
|
||||
*/
|
||||
void serial_configure_modem(unsigned short com);
|
||||
|
||||
/**
|
||||
* serial_is_transmit_fifo_empty:
|
||||
* Checks whether the transmit FIFO queue is empty or not for the given COM port.
|
||||
*
|
||||
* @param com The COM port
|
||||
*
|
||||
* @return 0 if the transmit FIFO queue is not empty
|
||||
* 1 if the transmit FIFO queue is empty
|
||||
*/
|
||||
int serial_is_transmit_fifo_empty(unsigned int com);
|
||||
|
||||
/**
|
||||
* serial_write_byte:
|
||||
* Writes a byte to the serial port, and adhering to the FIFO queue,
|
||||
* ensures bytes aren't overwritten
|
||||
*
|
||||
* @param com The serial port
|
||||
* @param c The character to write
|
||||
*/
|
||||
void serial_write_byte(unsigned short com, char c);
|
||||
|
||||
/**
|
||||
* serial_write:
|
||||
* Writes to the serial output (DEFAULTS TO COM1)
|
||||
*
|
||||
* @param buf The character buffer
|
||||
* @param len The length of the buffer
|
||||
*/
|
||||
void serial_write(const char* buf, size_t len);
|
||||
|
||||
/**
|
||||
* serial_writestring:
|
||||
* Writes toe the serial output (DEFAULT TO COM1)
|
||||
*
|
||||
* @param buf The character buffer
|
||||
*/
|
||||
void serial_writestring(const char* buf);
|
||||
|
||||
#endif
|
||||
|
80
kernel/include/kernel/tty.h
Normal file
80
kernel/include/kernel/tty.h
Normal file
@ -0,0 +1,80 @@
|
||||
#ifndef _KERNEL_TTY_H
|
||||
#define _KERNEL_TTY_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* terminal_clear:
|
||||
* Clears the terminal
|
||||
*/
|
||||
void terminal_clear(void);
|
||||
|
||||
/**
|
||||
* terminal_initialize:
|
||||
* Initialize the framebuffer variables.
|
||||
*/
|
||||
void terminal_initialize(void);
|
||||
|
||||
/**
|
||||
* terminal_move_cursor:
|
||||
* Moves the cursor of the framebuffer to the given position
|
||||
*
|
||||
* @param pos The new position of the cursor
|
||||
*/
|
||||
void terminal_move_cursor(unsigned short pos);
|
||||
|
||||
/**
|
||||
* terminal_get_pos:
|
||||
* Calculates the position of the cursor
|
||||
*
|
||||
* @return The position
|
||||
*/
|
||||
size_t terminal_get_pos(void);
|
||||
|
||||
/**
|
||||
* terminal_write_cell:
|
||||
* Writes a character with the given foreground and background to the framebuffer
|
||||
*
|
||||
* @param i The location in the framebuffer
|
||||
* @param c The character
|
||||
* @param fg The foreground colour
|
||||
* @param bg The background colour
|
||||
*/
|
||||
void terminal_write_cell(unsigned int i, char c);
|
||||
|
||||
/**
|
||||
* terminal_write_character:
|
||||
* Parses the given character, enacts any edge cases, and passes
|
||||
* the rest of the write information down to terminal_write_cell
|
||||
*
|
||||
* @param i The location in the terminal_buffer
|
||||
* @param c The character
|
||||
* @param fg The foreground colour
|
||||
* @param bg The background colour
|
||||
*/
|
||||
void terminal_write_character(unsigned int i, char c);
|
||||
|
||||
/**
|
||||
* terminal_write:
|
||||
* Writes the content of the buffer to the framebuffer
|
||||
*
|
||||
* @param buf Buffer containing text to write to the framebuffer
|
||||
* @param len Length of the buffer
|
||||
*/
|
||||
void terminal_write(const char* buf, size_t len);
|
||||
|
||||
/**
|
||||
* terminal_writestring:
|
||||
* Writes the content of the buffer to the framebuffer
|
||||
*
|
||||
* @param buf Buffer containing text to write to the framebuffer
|
||||
*/
|
||||
void terminal_writestring(const char* buf);
|
||||
/**
|
||||
* terminal_scroll_screen:
|
||||
* Scrolls the terminal screen up one.
|
||||
*/
|
||||
void terminal_scroll_screen(void);
|
||||
|
||||
#endif
|
||||
|
60
kernel/include/kernel/x86/gdt.h
Normal file
60
kernel/include/kernel/x86/gdt.h
Normal file
@ -0,0 +1,60 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef ARCH_I386_GDT_H
|
||||
#define ARCH_I386_GDT_H
|
||||
|
||||
// Each define here is for a specific flag in the descriptor.
|
||||
// Refer to the intel documentation for a description of what each one does.
|
||||
#define SEG_DESCTYPE(x) ((x) << 0x04) // Descriptor type (0 for system, 1 for code/data)
|
||||
#define SEG_PRES(x) ((x) << 0x07) // Present
|
||||
#define SEG_SAVL(x) ((x) << 0x0C) // Available for system use
|
||||
#define SEG_LONG(x) ((x) << 0x0D) // Long mode
|
||||
#define SEG_SIZE(x) ((x) << 0x0E) // Size (0 for 16-bit, 1 for 32)
|
||||
#define SEG_GRAN(x) ((x) << 0x0F) // Granularity (0 for 1B - 1MB, 1 for 4KB - 4GB)
|
||||
#define SEG_PRIV(x) (((x) & 0x03) << 0x05) // Set privilege level (0 - 3)
|
||||
|
||||
#define SEG_DATA_RD 0x00 // Read-Only
|
||||
#define SEG_DATA_RDA 0x01 // Read-Only, accessed
|
||||
#define SEG_DATA_RDWR 0x02 // Read/Write
|
||||
#define SEG_DATA_RDWRA 0x03 // Read/Write, accessed
|
||||
#define SEG_DATA_RDEXPD 0x04 // Read-Only, expand-down
|
||||
#define SEG_DATA_RDEXPDA 0x05 // Read-Only, expand-down, accessed
|
||||
#define SEG_DATA_RDWREXPD 0x06 // Read/Write, expand-down
|
||||
#define SEG_DATA_RDWREXPDA 0x07 // Read/Write, expand-down, accessed
|
||||
#define SEG_CODE_EX 0x08 // Execute-Only
|
||||
#define SEG_CODE_EXA 0x09 // Execute-Only, accessed
|
||||
#define SEG_CODE_EXRD 0x0A // Execute/Read
|
||||
#define SEG_CODE_EXRDA 0x0B // Execute/Read, accessed
|
||||
#define SEG_CODE_EXC 0x0C // Execute-Only, conforming
|
||||
#define SEG_CODE_EXCA 0x0D // Execute-Only, conforming, accessed
|
||||
#define SEG_CODE_EXRDC 0x0E // Execute/Read, conforming
|
||||
#define SEG_CODE_EXRDCA 0x0F // Execute/Read, conforming, accessed
|
||||
|
||||
#define GDT_CODE_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
|
||||
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
|
||||
SEG_PRIV(0) | SEG_CODE_EXRD
|
||||
|
||||
#define GDT_DATA_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
|
||||
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
|
||||
SEG_PRIV(0) | SEG_DATA_RDWR
|
||||
|
||||
#define GDT_CODE_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
|
||||
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
|
||||
SEG_PRIV(3) | SEG_CODE_EXRD
|
||||
|
||||
#define GDT_DATA_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
|
||||
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
|
||||
SEG_PRIV(3) | SEG_DATA_RDWR
|
||||
|
||||
|
||||
|
||||
void setGdt(unsigned short limit, uint64_t* base);
|
||||
|
||||
void reloadSegments();
|
||||
|
||||
uint64_t create_descriptor(uint32_t base, uint32_t limit, uint16_t flag);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user