forked from PoliEcho-holding-org/kern
Moved header files into their lib directory
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
#ifndef DISK_DISK_H
|
||||
#define DISK_DISK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PIO_PORT 0x1f0
|
||||
#define READ_COMMAND 0x20
|
||||
#define WRITE_COMMAND 0x30
|
||||
#define CACHE_FLUSH 0xE7
|
||||
|
||||
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst);
|
||||
void diskWrite(uint32_t lbaAddress, uint8_t sectorCount, char* src);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef ERROR_BIGERR_H
|
||||
#define ERROR_BIGERR_H
|
||||
|
||||
/*
|
||||
* Something went VERY wrong.
|
||||
* Eg. kernel.bin is missing, no filesystem, Virtual Memory failed, etc.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void bigError(uint32_t err);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,83 @@
|
||||
#ifndef FS_FS_H
|
||||
#define FS_FS_H
|
||||
|
||||
/*
|
||||
* For info, read the fs-spec.txt document inside of docs/
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// FS Definitions
|
||||
#define FS_SECTOR_SIZE 512
|
||||
#define FS_BLOCK_SIZE 4096
|
||||
|
||||
// Conversion Macros (beatiful)
|
||||
#define BYTES2BLOCKS(_n) ( (_n) == 0 ? 0 : \
|
||||
(_n) <= (FS_BLOCK_SIZE) ? 1 : \
|
||||
((_n) / FS_BLOCK_SIZE) + (((_n) % FS_BLOCK_SIZE) > 0 ? 1 : 0) )
|
||||
|
||||
#define BYTES2SECTORS(_n) ( (_n) == 0 ? 0 : \
|
||||
(_n) <= (FS_SECTOR_SIZE) ? 1 : \
|
||||
((_n) / FS_SECTOR_SIZE) + (((_n) % FS_SECTOR_SIZE) > 0 ? 1 : 0) )
|
||||
|
||||
// Filetypes
|
||||
#define FT_FILE 0
|
||||
#define FT_DIR 1
|
||||
|
||||
// FS Structures
|
||||
// TODO: datetime_t?
|
||||
|
||||
typedef struct {
|
||||
uint8_t sectors[FS_BLOCK_SIZE / FS_SECTOR_SIZE][FS_SECTOR_SIZE];
|
||||
} __attribute__ ((packed)) bootblock_t;
|
||||
|
||||
// Superblock - Padded to 4096 Bytes
|
||||
typedef struct {
|
||||
// Constant data
|
||||
uint16_t deviceId;
|
||||
uint16_t extentsPerIndirect;
|
||||
uint32_t maxFileSize;
|
||||
uint16_t inodesPerSector;
|
||||
|
||||
// INode data
|
||||
uint32_t inodeCount;
|
||||
uint32_t inodeBitmapBlock;
|
||||
uint32_t inodesStart;
|
||||
uint32_t inodeBlockCount;
|
||||
|
||||
// Data data :)
|
||||
uint32_t dataBitmapBlock;
|
||||
uint32_t dataStart;
|
||||
uint32_t dataBlockCount;
|
||||
|
||||
// Other
|
||||
uint32_t rootInodePtr;
|
||||
uint32_t firstUnreservedInode;
|
||||
} __attribute__ ((packed)) superblock_t;
|
||||
|
||||
// Extent - 8 Bytes
|
||||
typedef struct {
|
||||
uint32_t block;
|
||||
uint32_t length;
|
||||
} __attribute__ ((packed)) extent_t;
|
||||
|
||||
// INode - 64 Bytes
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
uint8_t type;
|
||||
uint32_t sizeBytes; // Size in bytes
|
||||
uint32_t sizeSectors; // Size in sectors
|
||||
uint8_t mode; // Access permisions
|
||||
extent_t extent[4];
|
||||
uint32_t singleIndirect;
|
||||
uint32_t doubleIndirect;
|
||||
|
||||
uint8_t reserved[10];
|
||||
} __attribute__ ((packed)) inode_t;
|
||||
|
||||
typedef struct {
|
||||
char name[60];
|
||||
uint32_t id;
|
||||
} __attribute__ ((packed)) dirEntry_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef FS_IMPL_H
|
||||
#define FS_IMPL_H
|
||||
|
||||
#include <fs/fs.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_OPEN_FILES 256
|
||||
|
||||
typedef struct {
|
||||
FILE* openFileTable;
|
||||
uint32_t openFiles;
|
||||
} fsInfo_t;
|
||||
|
||||
extern superblock_t* impl_superblock;
|
||||
extern fsInfo_t* fsInfo;
|
||||
|
||||
inode_t* getInode(char* path, dirEntry_t* dentries);
|
||||
uint8_t loadFile(inode_t* inode, void* dest);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef INTERRUPT_EXCEPTIONS_H
|
||||
#define INTERRUPT_EXCEPTIONS_H
|
||||
|
||||
void setupExceptions();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef INTERRUPT_IDT_H
|
||||
#define INTERRUPT_IDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define TRAP_GATE_FLAGS 0x8f // P = 1, DPL = 00, S = 0, Type = 1111 (32-bit Trap gate)
|
||||
#define INT_GATE_FLAGS 0x8e // P = 1, DPL = 00, S = 0, Type = 1110 (32-bit Int gate)
|
||||
#define USR_INT_GAME_FLAGS 0xee // P = 1, DPL = 11, S = 0, Type = 1110 (32-bit Int gate)
|
||||
|
||||
typedef struct {
|
||||
uint16_t offsetLow;
|
||||
uint16_t selector;
|
||||
uint8_t zero;
|
||||
uint8_t typeAttr;
|
||||
uint16_t offsetHigh;
|
||||
} __attribute__ ((packed)) idtEntry_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t limit;
|
||||
uint32_t base;
|
||||
} __attribute__ ((packed)) idtp_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t eip;
|
||||
uint32_t cs;
|
||||
uint32_t eflags;
|
||||
uint32_t esp;
|
||||
uint32_t ss;
|
||||
} __attribute__ ((packed)) intFrame_t;
|
||||
|
||||
void idtSetGate(uint8_t i, void* handler, uint8_t flags);
|
||||
void setupIdt();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef INTERRUPT_PIC_H
|
||||
#define INTERRUPT_PIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// PIC I/O Ports
|
||||
#define PIC_1_CMD 0x20
|
||||
#define PIC_1_DATA 0x21
|
||||
#define PIC_2_CMD 0xA0
|
||||
#define PIC_2_DATA 0xA1
|
||||
|
||||
// IRQs
|
||||
#define NEW_IRQ_0 0x20 // IRQ 0 : int 32
|
||||
#define NEW_IRQ_8 0x28 // IRQ 8 : int 40
|
||||
|
||||
// Commands
|
||||
#define PIC_EOI 0x20 // End Of Interrupt
|
||||
#define PIC_DISABLE 0xff
|
||||
|
||||
void sendPicEOI(uint8_t irq);
|
||||
void disableIrqs();
|
||||
void setIrqMask(uint8_t irq);
|
||||
void unsetIrqMask(uint8_t irq);
|
||||
void remapPic();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef INTERRUPT_PIT_H
|
||||
#define INTERRUPT_PIT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
|
||||
#define COMMAND 0x43
|
||||
#define INPUT_CLK 1193182
|
||||
|
||||
void setPitPhase(uint8_t channel, uint8_t opMode, uint16_t hz);
|
||||
void setupTimer();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef INTERRUPT_RTC_H
|
||||
#define INTERRUPT_RTC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define CMOS_ADDRESS 0x70
|
||||
#define CMOS_DATA 0x71
|
||||
|
||||
typedef struct {
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint16_t year;
|
||||
} __attribute__ ((packed)) datetime_t;
|
||||
|
||||
bool cmosUpdateProgress();
|
||||
uint8_t getRtcRegister(uint8_t reg);
|
||||
void enableRtc();
|
||||
void disableRtc();
|
||||
void setupRtc();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef INTERRUPT_SYSCALLS_H
|
||||
#define INTERRUPT_SYSCALLS_H
|
||||
|
||||
#include <interrupt/idt.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t esp;
|
||||
uint32_t ebx;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
uint32_t esi;
|
||||
uint32_t edi;
|
||||
uint32_t ebp;
|
||||
uint32_t ds;
|
||||
uint32_t es;
|
||||
uint32_t fs;
|
||||
uint32_t gs;
|
||||
uint32_t eax;
|
||||
} __attribute__ ((packed)) sys_regs_t;
|
||||
|
||||
__attribute__ ((naked)) void syscallHandler(intFrame_t* iframe);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef KEYBOARD_KEYBOARD_H
|
||||
#define KEYBOARD_KEYBOARD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char character;
|
||||
bool shift;
|
||||
} keyboardState_t;
|
||||
|
||||
void setupKeyboard();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef KEYBOARD_KEYS_H
|
||||
#define KEYBOARD_KEYS_H
|
||||
|
||||
#define LEFT_SHIFT_PRESS 0x2a
|
||||
#define LEFT_SHIFT_RELEASE (LEFT_SHIFT_PRESS | 0x80)
|
||||
#define RIGHT_SHIFT_PRESS 0x36
|
||||
#define RIGHT_SHIFT_RELEASE (RIGHT_SHIFT_PRESS | 0x80)
|
||||
#define LEFT_CTRL_PRESS 0x1D
|
||||
#define LEFT_CTRL_RELEASE (LEFT_CTRL_PRESS | 0x80)
|
||||
#define RIGHT_CTRL_PRESS 0x1D
|
||||
#define RIGHT_CTRL_RELEASE (RIGHT_CTRL_PRESS | 0x80)
|
||||
#define LEFT_ALT_PRESS 0x38
|
||||
#define LEFT_ALT_RELEASE (LEFT_ALT_PRESS | 0x80)
|
||||
#define RIGHT_ALT_PRESS 0x38
|
||||
#define RIGHT_ALT_RELEASE (RIGHT_ALT_PRESS | 0x80)
|
||||
|
||||
// Basic US Keyboard layout
|
||||
#define US_KEYBOARD {\
|
||||
{\
|
||||
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',\
|
||||
'\t','q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',\
|
||||
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'','`',\
|
||||
0, '\\','z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0,\
|
||||
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
|
||||
'7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',\
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\
|
||||
},\
|
||||
{\
|
||||
0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', '\t',\
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S',\
|
||||
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V',\
|
||||
'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\
|
||||
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',\
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\
|
||||
}\
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef MEMORY_ADDRESSES_H
|
||||
#define MEMORY_ADDRESSES_H
|
||||
|
||||
/*
|
||||
* Memory layout of addresses 0x0000 - 0x12000
|
||||
* 0x0000-0x0fff - Probably shouldn't mess with this? idk it feels wrong
|
||||
* 0x1000-0x17ff - Free
|
||||
* 0x1800-0x1fff - Global Variables
|
||||
* 0x2000-0x2fff - Larger structs
|
||||
* 0x3000-0x3fff - Filesystem Info
|
||||
* 0x4000-0x4fff - Font area
|
||||
* 0x6000-0x6fff - VBE info area
|
||||
* 0x7000-0x7bff - SMAP Area
|
||||
* 0x7c00-0x8bff - Bootblock
|
||||
* 0x8c00-0x9bff - Superblock
|
||||
* 0x9c00-0xafff - Free
|
||||
* 0xb000-0xbfff - Bootloader first INode
|
||||
* 0xc000-0xcfff - Scratch INode block
|
||||
*/
|
||||
|
||||
// Global Variables 0x1800-0x1fff
|
||||
#define SLEEP_TIMER 0x1800
|
||||
#define CURRENT_PAGE_DIR_ADDR 0x1804
|
||||
#define PHYS_MEM_MAX_BLOCKS 0x1808
|
||||
#define PHYS_MEM_USED_BLOCKS 0x180C
|
||||
|
||||
// Some structs 0x2000-0x2fff
|
||||
#define TERMINAL_INFO_LOC 0x2000
|
||||
#define KEYBOARD_STATE_LOC 0x2100
|
||||
#define DATETIME_LOC 0x2200
|
||||
|
||||
// Filesystem Area 0x3000 - 0x3fff
|
||||
#define FS_INFO_LOC 0x3000
|
||||
|
||||
// Font area 0x4000 - 0x4fff
|
||||
#define FONT_LOC 0x4000
|
||||
|
||||
// VBE Info Area 0x6000 - 0x6fff
|
||||
#define MODE_INFO_BLOCK_LOC 0x6000 // 512 Bytes
|
||||
|
||||
// Smap Area 0x7000 - 0x7bff
|
||||
#define SMAP_ENTRY_COUNT 0x7000
|
||||
#define SMAP_ENTRIES 0x7004
|
||||
|
||||
// Bootblock 0x7c00-0x9bff
|
||||
#define BOOTBLOCK_LOC 0x7c00
|
||||
|
||||
// Superblock 0x9c00-0xabff
|
||||
#define SUPERBLOCK_LOC 0x8c00
|
||||
|
||||
// First INode from bootloader
|
||||
#define BOOT_FIRST_INODE_LOC 0xb000
|
||||
#define SCRATCH_BLOCK_LOC 0xc000
|
||||
|
||||
// Other addresses
|
||||
#define KERNEL_LOC 0x100000
|
||||
#define KERNEL_MALLOC_AREA 0x300000
|
||||
#define MEMMAP_AREA 0x30000
|
||||
#define OPEN_FILE_LOC 0xd000
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MEMORY_MALLOC_H
|
||||
#define MEMORY_MALLOC_H
|
||||
|
||||
#include <memory/virtual.h>
|
||||
#include <memory/physical.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Singly linked list!
|
||||
typedef struct mallocNode_s {
|
||||
uint32_t size;
|
||||
bool free;
|
||||
struct mallocNode_s* next;
|
||||
} mallocNode_t;
|
||||
|
||||
extern mallocNode_t* mallocListHead;
|
||||
extern uint32_t mallocVirtualAddr;
|
||||
extern uint32_t mallocPhysicalAddr;
|
||||
extern uint32_t mallocPages;
|
||||
|
||||
void mallocInit(uint32_t size);
|
||||
void mallocSplit(mallocNode_t* node, uint32_t size);
|
||||
void* mallocNextNode(uint32_t size);
|
||||
void mallocMergeFree();
|
||||
void mallocFree(void* ptr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef MEMORY_PHYSICAL_H
|
||||
#define MEMORY_PHYSICAL_H
|
||||
|
||||
#include <memory/addresses.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BLOCK_SIZE 4096 // 4kB
|
||||
#define BLOCKS_PER_BYTE 8
|
||||
|
||||
typedef struct smapEntry_s {
|
||||
uint64_t baseAddress;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
uint32_t acpiAttr;
|
||||
} __attribute__ ((packed)) smapEntry_t;
|
||||
|
||||
extern uint32_t* memoryMap;
|
||||
extern uint32_t maxBlocks;
|
||||
extern uint32_t usedBlocks;
|
||||
|
||||
void setBlock(uint32_t block);
|
||||
void unsetBlock(uint32_t block);
|
||||
uint8_t testBlock(uint32_t block);
|
||||
|
||||
int32_t findFreeBlocks(uint32_t blockCount);
|
||||
void setupPhysicalMemoryManager(uint32_t startAddress, uint32_t size);
|
||||
void initMemoryRegion(uint32_t baseAddress, uint32_t size);
|
||||
void deinitMemoryRegion(uint32_t baseAddress, uint32_t size);
|
||||
void* allocBlocks(uint32_t blockCount);
|
||||
void freeBlocks(void* address, uint32_t blockCount);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef MEMORY_VIRTUAL_H
|
||||
#define MEMORY_VIRTUAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory/physical.h>
|
||||
|
||||
#define PAGES_PER_TABLE 1024
|
||||
#define TABLES_PER_DIRECTORY 1024
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#define PD_INDEX(_vAddress) ((_vAddress) >> 22)
|
||||
#define PT_INDEX(_vAddress) (((_vAddress) >> 12) & 0x3ff)
|
||||
#define PAGE_PHYS_ADDRESS(_dirEntry) (*(_dirEntry) & ~ 0xfff)
|
||||
#define SET_ATTR(_entry, _attr) (*(_entry) |= (_attr))
|
||||
#define CLEAR_ATTR(_entry, _attr) (*(_entry) &= ~(_attr))
|
||||
#define TEST_ATTR(_entry, _attr) (*(_entry) & (_attr))
|
||||
#define SET_FRAME(_entry, _address) (*(_entry) = (*(_entry) & ~0xfffff000) | (_address))
|
||||
|
||||
typedef uint32_t ptEntry_t;
|
||||
typedef uint32_t pdEntry_t;
|
||||
|
||||
typedef enum {
|
||||
PTE_PRESENT = 0x01,
|
||||
PTE_READ_WRITE = 0x02,
|
||||
PTE_USER = 0x04,
|
||||
PTE_WRITE_THROUGH = 0x08,
|
||||
PTE_CACHE_DISABLE = 0x10,
|
||||
PTE_ACCESSED = 0x20,
|
||||
PTE_DIRTY = 0x40,
|
||||
PTE_PAT = 0x80,
|
||||
PTE_GLOBAL = 0x100,
|
||||
PTE_FRAME = 0x7ffff000,
|
||||
} PAGE_TABLE_FLAGS;
|
||||
|
||||
typedef enum {
|
||||
PDE_PRESENT = 0x01,
|
||||
PDE_READ_WRITE = 0x02,
|
||||
PDE_USER = 0x04,
|
||||
PDE_WRITE_THROUGH = 0x08,
|
||||
PDE_CACHE_DISABLE = 0x10,
|
||||
PDE_ACCESSED = 0x20,
|
||||
PDE_DIRTY = 0x40, // Only with 4MB pages
|
||||
PDE_PAGE_SIZE = 0x80, // Is page 4MB
|
||||
PDE_GLOBAL = 0x100,
|
||||
PDE_PAT = 0x2000,
|
||||
PDE_FRAME = 0x7ffff000,
|
||||
} PAGE_DIR_FLAGS;
|
||||
|
||||
typedef struct {
|
||||
ptEntry_t entries[PAGES_PER_TABLE];
|
||||
} pageTable_t;
|
||||
|
||||
typedef struct {
|
||||
pdEntry_t entries[TABLES_PER_DIRECTORY];
|
||||
} pageDirectory_t;
|
||||
|
||||
extern pageDirectory_t* currentPd;
|
||||
|
||||
ptEntry_t* getPtEntry(pageTable_t* pt, uint32_t virtualAddress);
|
||||
pdEntry_t* getPdEntry(pageDirectory_t* pd, uint32_t virtualAddress);
|
||||
ptEntry_t* getPage(uint32_t virtualAddress);
|
||||
void* allocPage(ptEntry_t* page);
|
||||
void freePage(ptEntry_t* page);
|
||||
uint8_t setPageDirectory(pageDirectory_t* pd);
|
||||
void flushTlbEntry(uint32_t virtualAddress);
|
||||
uint8_t mapPage(void* physicalAddr, void* virtualAddr);
|
||||
void unmapPage(void* virtualAddress);
|
||||
uint8_t setupVirtualMemoryManager();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef PORTS_IO_H
|
||||
#define PORTS_IO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Port functions
|
||||
uint8_t inb(uint16_t port);
|
||||
void outb(uint16_t port, uint8_t data);
|
||||
uint16_t inw(uint16_t port);
|
||||
void outw(uint16_t port, uint16_t data);
|
||||
void ioWait();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef PORTS_SERIAL_H
|
||||
#define PORTS_SERIAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PORT_COM1 0x3f8
|
||||
#define PORT_COM2 0x2f8
|
||||
#define PORT_COM3 0x3e8
|
||||
#define PORT_COM4 0x2e8
|
||||
#define PORT_COM5 0x5f8
|
||||
#define PORT_COM6 0x4f8
|
||||
#define PORT_COM7 0x5e8
|
||||
#define PORT_COM8 0x4e8
|
||||
|
||||
int setupSerial(uint32_t port);
|
||||
|
||||
int serialTransmitEmpty(uint32_t port);
|
||||
int serialRecieved(uint32_t port);
|
||||
|
||||
void serialWrite(uint32_t port, char c);
|
||||
void serialPrint(uint32_t port, char* s);
|
||||
char serialRead(uint32_t port);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef SCREEN_GFXMODE_H
|
||||
#define SCREEN_GFXMODE_H
|
||||
|
||||
#include <memory/addresses.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BG_COLOR 0x00010b17
|
||||
#define FG_COLOR 0x00ebddf4
|
||||
|
||||
typedef struct modeInfoBlock_s {
|
||||
// Required by all VBE revisions
|
||||
uint16_t modeAttr;
|
||||
uint8_t windowAAtrr;
|
||||
uint8_t windowBAttr;
|
||||
uint16_t windowGranularity;
|
||||
uint16_t windowSize;
|
||||
uint16_t windowASegment;
|
||||
uint16_t windowBSegment;
|
||||
uint32_t windowFunctionPtr;
|
||||
uint16_t bytesPerScanline;
|
||||
|
||||
// Required by VBE 1.2+
|
||||
uint16_t xRes;
|
||||
uint16_t yRes;
|
||||
uint8_t xCharSize;
|
||||
uint8_t yCharSize;
|
||||
uint8_t planeCount;
|
||||
uint8_t bpp;
|
||||
uint8_t bankCount;
|
||||
uint8_t memoryModel;
|
||||
uint8_t bankSize;
|
||||
uint8_t imagePageCount;
|
||||
uint8_t reserved1;
|
||||
|
||||
// Direct color fields
|
||||
uint8_t redMaskSize;
|
||||
uint8_t redFieldPos;
|
||||
uint8_t greenMaskSize;
|
||||
uint8_t greenFieldPos;
|
||||
uint8_t blueMaskSize;
|
||||
uint8_t blueFieldPos;
|
||||
uint8_t reservedMaskSize;
|
||||
uint8_t reservedFieldPos;
|
||||
uint8_t directColorModeInfo;
|
||||
|
||||
// Required by VBE 2.0+
|
||||
uint32_t physicalBasePtr;
|
||||
uint32_t reserved2;
|
||||
uint16_t reserved3;
|
||||
|
||||
// Required by VBE 3.0+
|
||||
uint16_t linearBytesPerScanline;
|
||||
uint8_t bankImagePageCount;
|
||||
uint8_t linearImagePageCount;
|
||||
uint8_t linearRedMaskSize;
|
||||
uint8_t linearRedFieldPos;
|
||||
uint8_t linearGreenMaskSize;
|
||||
uint8_t linearGreenFieldPos;
|
||||
uint8_t linearBlueMaskSize;
|
||||
uint8_t linearBlueFieldPos;
|
||||
uint8_t linearReservedMaskSize;
|
||||
uint8_t linearReservedFieldPos;
|
||||
uint32_t maxPixelClock;
|
||||
|
||||
uint8_t reserved4[190];
|
||||
} __attribute__ ((packed)) modeInfoBlock_t;
|
||||
|
||||
extern modeInfoBlock_t* gfxMode;
|
||||
|
||||
uint32_t convertColor(uint32_t color);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef SCREEN_GRAPHICS_H
|
||||
#define SCREEN_GRAPHICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff )
|
||||
|
||||
void drawPixel(int32_t x, int32_t y, uint32_t color);
|
||||
void drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
|
||||
void drawRect(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
|
||||
void drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color);
|
||||
void drawCircle(int32_t x, int32_t y, uint16_t radius, uint32_t color);
|
||||
void boundaryFill(int32_t x, int32_t y, uint32_t fillColor, uint32_t boundaryColor);
|
||||
void fillRect(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
|
||||
void fillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, uint32_t color);
|
||||
void fillCircle(int32_t x, int32_t y, uint16_t radius, uint32_t color);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef SCREEN_TEXT_H
|
||||
#define SCREEN_TEXT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
};
|
||||
uint8_t data[4096];
|
||||
} __attribute__ ((packed)) font_t;
|
||||
|
||||
void drawChar(char c, uint32_t x, uint32_t y, uint32_t fgColor, uint32_t bgColor);
|
||||
void scroll();
|
||||
void clearScreen(uint32_t bgColor);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
#ifndef SOUND_NOTES_H
|
||||
#define SOUND_NOTES_H
|
||||
|
||||
/*
|
||||
|
||||
0 1 2 3 4 5 6 7 8
|
||||
C 16.35 32.7 65.41 130.81 261.63 523.25 1046.5 2093 4186
|
||||
C# 17.32 34.65 69.3 138.59 277.18 554.37 1108.73 2217.46 4434.92
|
||||
D 18.35 36.71 73.42 146.83 293.66 587.33 1174.66 2349.32 4698.63
|
||||
D# 19.45 38.89 77.78 155.56 311.13 622.25 1244.51 2489 4978
|
||||
E 20.6 41.2 82.41 164.81 329.63 659.25 1318.51 2637 5274
|
||||
F 21.83 43.65 87.31 174.61 349.23 698.46 1396.91 2793.83 5587.65
|
||||
F# 23.12 46.25 92.5 185 369.99 739.99 1479.98 2959.96 5919.91
|
||||
G 24.5 49 98 196 392 783.99 1567.98 3135.96 6271.93
|
||||
G# 25.96 51.91 103.83 207.65 415.3 830.61 1661.22 3322.44 6644.88
|
||||
A 27.5 55 110 220 440 880 1760 3520 7040
|
||||
A# 29.14 58.27 116.54 233.08 466.16 932.33 1864.66 3729.31 7458.62
|
||||
B 30.87 61.74 123.47 246.94 493.88 987.77 1975.53 3951 7902.13
|
||||
*/
|
||||
|
||||
// Note frequencies in Hz (rounded down)
|
||||
// b - Flat
|
||||
// s - Sharp (#)
|
||||
typedef enum {
|
||||
// 2nd Octave
|
||||
C2 = 65,
|
||||
Cs2 = 69,
|
||||
Db2 = Cs2,
|
||||
D2 = 73,
|
||||
Ds2 = 77,
|
||||
Eb2 = Ds2,
|
||||
E2 = 82,
|
||||
F2 = 87,
|
||||
Fs2 = 92,
|
||||
Gb2 = Fs2,
|
||||
G2 = 98,
|
||||
Gs2 = 103,
|
||||
Ab2 = Gs2,
|
||||
A2 = 110,
|
||||
As2 = 116,
|
||||
Hb2 = As2,
|
||||
H2 = 123,
|
||||
// 3rd Octave
|
||||
C3 = 130,
|
||||
Cs3 = 138,
|
||||
Db3 = Cs3,
|
||||
D3 = 146,
|
||||
Ds3 = 155,
|
||||
Eb3 = Ds3,
|
||||
E3 = 164,
|
||||
F3 = 174,
|
||||
Fs3 = 185,
|
||||
Gb3 = Fs3,
|
||||
G3 = 196,
|
||||
Gs3 = 207,
|
||||
Ab3 = Gs3,
|
||||
A3 = 220,
|
||||
As3 = 233,
|
||||
Hb3 = As3,
|
||||
H3 = 246,
|
||||
// 4th Octave
|
||||
C4 = 261,
|
||||
Cs4 = 277,
|
||||
Db4 = Cs4,
|
||||
D4 = 293,
|
||||
Ds4 = 311,
|
||||
Eb4 = Ds4,
|
||||
E4 = 329,
|
||||
F4 = 349,
|
||||
Fs4 = 370,
|
||||
Gb4 = Fs4,
|
||||
G4 = 392,
|
||||
Gs4 = 415,
|
||||
Ab4 = Gs4,
|
||||
A4 = 440, // Standard A, 440Hz
|
||||
As4 = 466,
|
||||
Hb4 = As4,
|
||||
H4 = 493,
|
||||
// 5th Octave
|
||||
C5 = 523,
|
||||
Cs5 = 554,
|
||||
Db5 = Cs5,
|
||||
D5 = 587,
|
||||
Ds5 = 622,
|
||||
Eb5 = Ds5,
|
||||
E5 = 659,
|
||||
F5 = 698,
|
||||
Fs5 = 739,
|
||||
Gb5 = Fs5,
|
||||
G5 = 783,
|
||||
Gs5 = 830,
|
||||
Ab5 = Gs5,
|
||||
A5 = 880,
|
||||
As5 = 932,
|
||||
Hb5 = As5,
|
||||
H5 = 987,
|
||||
} note_t;
|
||||
|
||||
typedef enum {
|
||||
WHOLE = 1,
|
||||
HALF = 2,
|
||||
QUARTER = 4,
|
||||
EIGHT = 8,
|
||||
SIXTEENTH = 16,
|
||||
THIRTYSECONDTH = 32,
|
||||
} beatType_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SOUND_PCSPK_H
|
||||
#define SOUND_PCSPK_H
|
||||
|
||||
#include <sound/notes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PC_SPEAKER 0x61
|
||||
|
||||
void enableSpeaker();
|
||||
void disableSpeaker();
|
||||
void playNote(note_t note, uint32_t ms);
|
||||
void rest(uint32_t ms);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef TERMINAL_TERMINAL_H
|
||||
#define TERMINAL_TERMINAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t x; // X Position of cursor in characters
|
||||
uint32_t y; // Y Position of cursor in characters
|
||||
uint32_t bg; // Printed character background
|
||||
uint32_t fg; // Printed character foreground
|
||||
uint32_t width; // Width in characters
|
||||
uint32_t height; // Height in characters
|
||||
char cursorChar; // Character to use as a cursor
|
||||
bool hideCursor; // Should we display the cursor
|
||||
} terminal_t;
|
||||
|
||||
extern terminal_t* terminal;
|
||||
|
||||
int32_t terminalWrite(const void* buf, uint32_t len);
|
||||
void toggleCursor();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user