Major libk restructuring, also rewrote drivers/serial.h

This commit is contained in:
2024-10-27 10:23:56 +01:00
parent 4079049242
commit e8a55d72a5
62 changed files with 334 additions and 380 deletions
+59 -3
View File
@@ -3,11 +3,12 @@
#include <memory/addresses.h>
#include <screen/gfxmode.h>
#include <screen/text.h>
#include <error/bigerr.h>
#include <disk/disk.h>
#include <fs/impl.h>
#include <drivers/disk.h>
#include <fs/kernfs.h>
#include <fs/fs.h>
void bigError(uint32_t err);
__attribute__ ((section("entry")))
void main() {
// Physical memory manager setup
@@ -80,3 +81,58 @@ void main() {
bigError(0xffffffff);
}
void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
uint8_t bytesPerPx = gfxMode->bpp / 8;
uint32_t convColor = convertColor(c);
for (uint32_t dx = 0; dx < w; dx++) {
for (uint32_t dy = 0; dy < h; dy++) {
uint32_t offset = (((y + dy) * gfxMode->xRes) + (x + dx)) * bytesPerPx;
for (uint8_t i = 0; i < gfxMode->bpp; i++) {
vidmem[offset + i] = (uint8_t)(convColor >> (i*8));
}
}
}
}
void bigError(uint32_t err) {
// Red BG
rect(0x00ff0000, 0, 0, gfxMode->xRes, gfxMode->yRes);
// E
rect(0x00ffffff, 20, 10, 10, 50);
rect(0x00ffffff, 30, 10, 30, 10);
rect(0x00ffffff, 30, 30, 30, 10);
rect(0x00ffffff, 30, 50, 30, 10);
// R
rect(0x00ffffff, 70, 10, 10, 50);
rect(0x00ffffff, 70, 10, 30, 10);
rect(0x00ffffff, 70, 30, 30, 10);
rect(0x00ffffff, 90, 10, 10, 30);
rect(0x00ffffff, 80, 40, 10, 10);
rect(0x00ffffff, 90, 50, 10, 10);
// R
rect(0x00ffffff, 110, 10, 10, 50);
rect(0x00ffffff, 110, 10, 30, 10);
rect(0x00ffffff, 110, 30, 30, 10);
rect(0x00ffffff, 130, 10, 10, 30);
rect(0x00ffffff, 120, 40, 10, 10);
rect(0x00ffffff, 130, 50, 10, 10);
// O
rect(0x00ffffff, 150, 10, 10, 50);
rect(0x00ffffff, 170, 10, 10, 50);
rect(0x00ffffff, 150, 10, 30, 10);
rect(0x00ffffff, 150, 50, 30, 10);
// R
rect(0x00ffffff, 190, 10, 10, 50);
rect(0x00ffffff, 190, 10, 30, 10);
rect(0x00ffffff, 190, 30, 30, 10);
rect(0x00ffffff, 210, 10, 10, 30);
rect(0x00ffffff, 200, 40, 10, 10);
rect(0x00ffffff, 210, 50, 10, 10);
__asm__ volatile ("cli; hlt" :: "a"(err));
}
BIN
View File
Binary file not shown.
+19 -19
View File
@@ -1,29 +1,29 @@
#include <interrupt/isr.h>
#include <interrupt/pit.h>
#include <interrupt/rtc.h>
#include <syscalls/syscalls.h>
#include <keyboard/keyboard.h>
#include <memory/addresses.h>
#include <memory/physical.h>
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <memory/malloc.h>
#include <fs/fs.h>
#include <fs/impl.h>
#include <disk/disk.h>
#include <screen/text.h>
#include <drivers/keyboard.h>
#include <drivers/serial.h>
#include <drivers/timer.h>
#include <drivers/pcspk.h>
#include <drivers/disk.h>
#include <drivers/rtc.h>
#include <screen/graphics.h>
#include <screen/gfxmode.h>
#include <tty/tty.h>
#include <sound/pcspk.h>
#include <sound/notes.h>
#include <ports/io.h>
#include <ports/serial.h>
#include <stdio.h>
#include <screen/text.h>
#include <screen/tty.h>
#include <cpu/system.h>
#include <cpu/isr.h>
#include <fs/kernfs.h>
#include <fs/fs.h>
#include <sys/notes.h>
#include <sys/gfx.h>
#include <syscall.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <syscall.h>
#include <sys/gfx.h>
/* Little teaser
#include <math.h>
@@ -64,8 +64,8 @@ void main() {
// Setup serial output for debugf()
if (setupSerial(PORT_COM1) != 0) { printf("\x1b[1MFailed to initialize serial interface\x1b[8M\n"); }
else {
serialPrint(PORT_COM1, "\x1b[H\x1b[J"); // Clear
serialPrint(PORT_COM1, "kern. \x1b[36m(Serial console)\x1b[0m\n\n");
debugf("\x1b[H\x1b[J"); // Clear
debugf("kern. \x1b[36m(Serial console)\x1b[0m\n\n");
}
// Interrupt setup
+1 -3
View File
@@ -1,8 +1,6 @@
#include <interrupt/idt.h>
#include <cpu/idt.h>
#include <stdint.h>
#define IDT_ENTRIES 256
__attribute__ ((aligned(0x10))) // For performance
idtEntry_t idt[IDT_ENTRIES] = { 0 };
idtp_t idtp;
+5 -6
View File
@@ -1,11 +1,10 @@
#include <interrupt/isr.h>
#include <interrupt/idt.h>
#include <syscalls/syscalls.h>
#include <error/panic.h>
#include <error/debug.h>
#include <ports/io.h>
#include <drivers/serial.h>
#include <cpu/system.h>
#include <cpu/idt.h>
#include <cpu/isr.h>
const char* format = "\x1b[31mPanic: %s!\n";
const char* format = "\x1b[31m[kernel] %s!\n\x1b[0m";
const char* exceptions[] = {
"Division By Zero",
"Debug",
+49
View File
@@ -0,0 +1,49 @@
#include <cpu/system.h>
#include <drivers/serial.h>
#include <stdint.h>
void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) {
__asm__ volatile (
"cpuid"
: "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
: "a"(*eax)
);
}
uint8_t inb(uint16_t port) {
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outb(uint16_t port, uint8_t data) {
__asm__ volatile("outb %0, %1" :: "a"(data), "Nd"(port));
}
uint16_t inw(uint16_t port) {
uint16_t result;
__asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outw(uint16_t port, uint16_t data) {
__asm__ volatile("outw %0, %1" :: "a"(data), "Nd"(port));
}
uint32_t inl(uint16_t port) {
uint32_t result;
__asm__ volatile("inl %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outl(uint16_t port, uint32_t data) {
__asm__ volatile("outl %0, %1" :: "a"(data), "Nd"(port));
}
void ioWait() {
// Waits ~1 I/O Cycle (Linux uses this so it should be good)
__asm__ volatile("outb %%al, $0x80" : : "a"(0));
}
void panic() {
debugf("\x1b[31m[kernel] Kern panic!\x1b[0m\n");
while (1) { __asm__ volatile ("cli; hlt"); }
}
+2 -2
View File
@@ -1,6 +1,6 @@
#include <disk/disk.h>
#include <drivers/disk.h>
#include <cpu/system.h>
#include <stdint.h>
#include <ports/io.h>
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst) {
outb(PIO_PORT + 6, ((lbaAddress >> 24) & 0x0f) | 0xe0); // 6 - Use LBA; 4 - Drive number; 3-0 - Highest lba address nibble
@@ -1,27 +1,23 @@
#include <keyboard/keyboard.h>
#include <interrupt/isr.h>
#include <keyboard/keys.h>
#include <drivers/keyboard.h>
#include <memory/addresses.h>
#include <ports/io.h>
#include <stdio.h>
#include <stdbool.h>
#include <cpu/system.h>
#include <cpu/isr.h>
static const uint8_t US_Keyboard[2][128] = US_KEYBOARD;
keyboardState_t* keyboard = (keyboardState_t*)KEYBOARD_STATE_LOC;
void keyboardHandler(intFrame_t*) { // TODO: Make this better and be able to read multi-byte scancode
// TODO: Make this better and be able to read multi-byte scancode
void keyboardHandler(intFrame_t*) {
uint8_t scancode = inb(0x60);
char c = US_Keyboard[keyboard->shift][scancode];
if (scancode == LEFT_SHIFT_PRESS || scancode == RIGHT_SHIFT_PRESS) {
keyboard->shift = true;
keyboard->shift = 1;
} else if (scancode == LEFT_SHIFT_RELEASE || scancode == RIGHT_SHIFT_RELEASE) {
keyboard->shift = false;
keyboard->shift = 0;
}
if (scancode & 0x80) { // Keyup
} else if (c != '\0') {
keyboard->character = c;
}
} else if (c != '\0') { keyboard->character = c; }
}
+4 -4
View File
@@ -1,7 +1,7 @@
#include <sound/pcspk.h>
#include <sound/notes.h>
#include <interrupt/pit.h>
#include <ports/io.h>
#include <drivers/pcspk.h>
#include <drivers/timer.h>
#include <cpu/system.h>
#include <sys/notes.h>
#include <stdint.h>
#include <time.h>
+7 -8
View File
@@ -1,15 +1,14 @@
#include <interrupt/rtc.h>
#include <interrupt/isr.h>
#include <screen/text.h>
#include <drivers/rtc.h>
#include <screen/gfxmode.h>
#include <tty/tty.h>
#include <ports/io.h>
#include <stdbool.h>
#include <screen/text.h>
#include <screen/tty.h>
#include <cpu/system.h>
#include <cpu/isr.h>
#include <string.h>
static datetime_t* datetime = (datetime_t*)DATETIME_LOC;
bool cmosUpdateProgress() {
int cmosUpdateProgress() {
outb(CMOS_ADDRESS, 0x8a); // Read status reg A, disable NMI
return inb(CMOS_DATA) & 0x80;
}
@@ -97,7 +96,7 @@ void rtcHandler(intFrame_t* iframe) {
datetime->month = newDatetime.month;
datetime->year = newDatetime.year;
if (true) { // TODO: Probably get rid of this idk
if (1) { // TODO: Probably get rid of this idk
char buf[20] = { 0 }; // "12/12 2012 12:12:12" - Max string 20 chars with null byte
strcat(buf, itoa(datetime->day, 10));
+50
View File
@@ -0,0 +1,50 @@
#include <drivers/serial.h>
#include <cpu/system.h>
#include <stdio.h>
#include <stdarg.h>
int serialEnable(int port) {
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(port + 0, 0x03); // Set divisor to 3 (low byte) 38400 baud
outb(port + 1, 0x00); // (high byte)
outb(port + 3, 0x03); // 8 bits, no parity, one stop bit
outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14 byte threshold
outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if it returns)
if (inb(port + 0) != 0xAE) return 1;
outb(port + 4, 0x0F); // non-loopback, IRQs enabled, OUT#1 and OUT#2 bits enabled
return 0;
}
int setupSerial() {
if (serialEnable(PORT_COM1) != 0) { return 1; }
outb(PORT_COM1 + 1, 0x01);
return 0;
}
static int serialTransimitEmpty(int port) { return inb(port + 5) & 0x20; }
static int serialRecieved(int port) { return inb(port + 5) & 0x01; }
void serialWrite(int port, char c) { while (!serialTransimitEmpty(port)); outb(port, c); }
char serialRead(int port) { while (!serialRecieved(port)); return inb(port); }
char serialReadAsync(int port) { return inb(port); }
void _dbgPutc(char c, void* arg) {
(void)arg;
serialWrite(PORT_COM1, c);
if (c == '\n') serialWrite(PORT_COM1, '\r');
}
int vdebugf(const char* fmt, va_list va) { return vpprintf(_dbgPutc, NULL, fmt, va); }
int debugf(const char* fmt, ...) {
va_list va;
va_start(va, fmt);
int ret = vdebugf(fmt, va);
va_end(va);
return ret;
}
@@ -1,8 +1,8 @@
#include <interrupt/pit.h>
#include <interrupt/isr.h>
#include <tty/tty.h>
#include <drivers/timer.h>
#include <memory/addresses.h>
#include <ports/io.h>
#include <screen/tty.h>
#include <cpu/system.h>
#include <cpu/isr.h>
#include <stdint.h>
void timerHandler(intFrame_t*) {
-58
View File
@@ -1,58 +0,0 @@
#include <error/bigerr.h>
#include <stdint.h>
#include <screen/gfxmode.h>
void rect(uint32_t c, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
uint8_t bytesPerPx = gfxMode->bpp / 8;
uint32_t convColor = convertColor(c);
for (uint32_t dx = 0; dx < w; dx++) {
for (uint32_t dy = 0; dy < h; dy++) {
uint32_t offset = (((y + dy) * gfxMode->xRes) + (x + dx)) * bytesPerPx;
for (uint8_t i = 0; i < gfxMode->bpp; i++) {
vidmem[offset + i] = (uint8_t)(convColor >> (i*8));
}
}
}
}
void bigError(uint32_t err) {
// Red BG
rect(0x00ff0000, 0, 0, gfxMode->xRes, gfxMode->yRes);
// E
rect(0x00ffffff, 20, 10, 10, 50);
rect(0x00ffffff, 30, 10, 30, 10);
rect(0x00ffffff, 30, 30, 30, 10);
rect(0x00ffffff, 30, 50, 30, 10);
// R
rect(0x00ffffff, 70, 10, 10, 50);
rect(0x00ffffff, 70, 10, 30, 10);
rect(0x00ffffff, 70, 30, 30, 10);
rect(0x00ffffff, 90, 10, 10, 30);
rect(0x00ffffff, 80, 40, 10, 10);
rect(0x00ffffff, 90, 50, 10, 10);
// R
rect(0x00ffffff, 110, 10, 10, 50);
rect(0x00ffffff, 110, 10, 30, 10);
rect(0x00ffffff, 110, 30, 30, 10);
rect(0x00ffffff, 130, 10, 10, 30);
rect(0x00ffffff, 120, 40, 10, 10);
rect(0x00ffffff, 130, 50, 10, 10);
// O
rect(0x00ffffff, 150, 10, 10, 50);
rect(0x00ffffff, 170, 10, 10, 50);
rect(0x00ffffff, 150, 10, 30, 10);
rect(0x00ffffff, 150, 50, 30, 10);
// R
rect(0x00ffffff, 190, 10, 10, 50);
rect(0x00ffffff, 190, 10, 30, 10);
rect(0x00ffffff, 190, 30, 30, 10);
rect(0x00ffffff, 210, 10, 10, 30);
rect(0x00ffffff, 200, 40, 10, 10);
rect(0x00ffffff, 210, 50, 10, 10);
__asm__ volatile ("cli; hlt" :: "a"(err));
}
-19
View File
@@ -1,19 +0,0 @@
#include <error/debug.h>
#include <ports/serial.h>
#include <stdio.h>
#include <stdarg.h>
static void _dbgPutc(char c, void* arg) {
(void)arg;
serialWrite(PORT_COM1, c);
if (c == '\n') { serialWrite(PORT_COM1, '\r'); }
}
int debugf(const char* fmt, ...) {
va_list va;
va_start(va, fmt);
int res = vpprintf(_dbgPutc, NULL, fmt, va);
va_end(va);
return res;
}
-7
View File
@@ -1,7 +0,0 @@
#include <error/panic.h>
void panic() {
// TODO: print a message
while (1) { __asm__ volatile ("cli; hlt"); }
}
+3 -3
View File
@@ -1,7 +1,7 @@
#include <fs/impl.h>
#include <fs/fs.h>
#include <fs/kernfs.h>
#include <memory/addresses.h>
#include <disk/disk.h>
#include <drivers/disk.h>
#include <fs/fs.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
@@ -1,8 +1,10 @@
#ifndef INTERRUPT_IDT_H
#define INTERRUPT_IDT_H
#ifndef _CPU_IDT_H
#define _CPU_IDT_H
#include <stdint.h>
#define IDT_ENTRIES 256
#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_GATE_FLAGS 0xee // P = 1, DPL = 11, S = 0, Type = 1110 (32-bit Int gate)
@@ -24,4 +26,3 @@ void idtSetGate(uint8_t i, void* handler, uint8_t flags);
void setupIdt();
#endif
@@ -1,5 +1,5 @@
#ifndef INTERRUPT_ISR_H
#define INTERRUPT_ISR_H
#ifndef _CPU_ISR_H
#define _CPU_ISR_H
#include <stdint.h>
@@ -15,8 +15,8 @@ typedef struct {
typedef void (*HandlerPtr)(intFrame_t* iframe);
void setupIsrs();
int handleInterrupt(intFrame_t iframe);
void registerIrq(uint8_t id, HandlerPtr handler);
int handleInterrupt(intFrame_t iframe);
// ISR Table
extern void* asm_isrRedirectTable[48];
+19
View File
@@ -0,0 +1,19 @@
#ifndef _CPU_SYSTEM_H
#define _CPU_SYSTEM_H
#include <stdint.h>
void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx);
void outb(uint16_t port, uint8_t data);
void outw(uint16_t port, uint16_t data);
void outl(uint16_t port, uint32_t data);
uint8_t inb(uint16_t port);
uint16_t inw(uint16_t port);
uint32_t inl(uint16_t port);
void ioWait();
void panic();
#endif
@@ -1,5 +1,5 @@
#ifndef DISK_DISK_H
#define DISK_DISK_H
#ifndef _DRIVERS_DISK_H
#define _DRIVERS_DISK_H
#include <stdint.h>
@@ -1,6 +1,9 @@
#ifndef KEYBOARD_KEYS_H
#define KEYBOARD_KEYS_H
#ifndef _DRIVERS_KEYBOARD_H
#define _DRIVERS_KEYBOARD_H
#include <cpu/isr.h>
// Special keys
#define LEFT_SHIFT_PRESS 0x2a
#define LEFT_SHIFT_RELEASE (LEFT_SHIFT_PRESS | 0x80)
#define RIGHT_SHIFT_PRESS 0x36
@@ -35,4 +38,11 @@
}\
}
typedef struct {
char character;
int shift;
} keyboardState_t;
void keyboardHandler(intFrame_t*);
#endif
@@ -1,7 +1,7 @@
#ifndef SOUND_PCSPK_H
#define SOUND_PCSPK_H
#ifndef _DRIVERS_PCSPK_H
#define _DRIVERS_PCSPK_H
#include <sound/notes.h>
#include <sys/notes.h>
#include <stdint.h>
#define PC_SPEAKER 0x61
@@ -1,9 +1,8 @@
#ifndef INTERRUPT_RTC_H
#define INTERRUPT_RTC_H
#ifndef _DRIVERS_RTC_H
#define _DRIVERS_RTC_H
#include <interrupt/isr.h>
#include <cpu/isr.h>
#include <stdint.h>
#include <stdbool.h>
#define CMOS_ADDRESS 0x70
#define CMOS_DATA 0x71
@@ -18,7 +17,7 @@ typedef struct {
} __attribute__ ((packed)) datetime_t;
void rtcHandler(intFrame_t*);
bool cmosUpdateProgress();
int cmosUpdateProgress();
uint8_t getRtcRegister(uint8_t reg);
void enableRtc();
void disableRtc();
+23
View File
@@ -0,0 +1,23 @@
#ifndef _DRIVERS_SERIAL_H
#define _DRIVERS_SERIAL_H
#include <stdarg.h>
#define PORT_COM1 0x3f8
#define PORT_COM2 0x2f8
#define PORT_COM3 0x3e8
#define PORT_COM4 0x2e8
// IRQ4 -> COM1, IRQ3 -> COM2
#define SERIAL_IRQ 4
int serialEnable(int port);
int setupSerial();
void serialWrite(int port, char c);
char serialRead(int port);
char serialReadAsync(int port);
int debugf(const char* fmt, ...);
int vdebugf(const char* fmt, va_list va);
#endif
@@ -1,7 +1,7 @@
#ifndef INTERRUPT_PIT_H
#define INTERRUPT_PIT_H
#ifndef _DRIVERS_TIMER_H
#define _DRIVERS_TIMER_H
#include <interrupt/isr.h>
#include <cpu/isr.h>
#include <stdint.h>
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
-14
View File
@@ -1,14 +0,0 @@
#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
-6
View File
@@ -1,6 +0,0 @@
#ifndef ERROR_DEBUG_H
#define ERROR_DEBUG_H
int debugf(const char* fmt, ...);
#endif
-6
View File
@@ -1,6 +0,0 @@
#ifndef ERROR_PANIC_H
#define ERROR_PANIC_H
void panic();
#endif
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef FS_FS_H
#define FS_FS_H
#ifndef _FS_FS_H
#define _FS_FS_H
/*
* For info, read the fs-spec.txt document inside of docs/
@@ -1,5 +1,5 @@
#ifndef FS_IMPL_H
#define FS_IMPL_H
#ifndef _FS_KERNFS_H
#define _FS_KERNFS_H
#include <fs/fs.h>
#include <stdint.h>
@@ -17,5 +17,6 @@ extern fsInfo_t* fsInfo;
inode_t* getInode(char* path, dirEntry_t* dentries);
uint8_t loadFile(inode_t* inode, void* dest);
void initOpenFileTable();
#endif
-6
View File
@@ -1,6 +0,0 @@
#ifndef INTERRUPT_EXCEPTIONS_H
#define INTERRUPT_EXCEPTIONS_H
void setupExceptions();
#endif
-14
View File
@@ -1,14 +0,0 @@
#ifndef KEYBOARD_KEYBOARD_H
#define KEYBOARD_KEYBOARD_H
#include <interrupt/isr.h>
#include <stdbool.h>
typedef struct {
char character;
bool shift;
} keyboardState_t;
void keyboardHandler(intFrame_t*);
#endif
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef MEMORY_ADDRESSES_H
#define MEMORY_ADDRESSES_H
#ifndef _MEMORY_ADDRESSES_H
#define _MEMORY_ADDRESSES_H
/*
* Memory layout of addresses 0x0000 - 0x12000
@@ -25,7 +25,7 @@
#define PHYS_MEM_USED_BLOCKS 0x180C
// Some structs 0x2000-0x2fff
#define TERMINAL_INFO_LOC 0x2000
#define CONSOLE_INFO_LOC 0x2000
#define KEYBOARD_STATE_LOC 0x2100
#define DATETIME_LOC 0x2200
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MEMORY_MALLOC_H
#define MEMORY_MALLOC_H
#ifndef _MEMORY_MALLOC_H
#define _MEMORY_MALLOC_H
#include <memory/virtual.h>
#include <memory/physical.h>
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MEMORY_PHYSICAL_H
#define MEMORY_PHYSICAL_H
#ifndef _MEMORY_PHYSICAL_H
#define _MEMORY_PHYSICAL_H
#include <memory/addresses.h>
#include <string.h>
+3 -3
View File
@@ -1,8 +1,8 @@
#ifndef MEMORY_VIRTUAL_H
#define MEMORY_VIRTUAL_H
#ifndef _MEMORY_VIRTUAL_H
#define _MEMORY_VIRTUAL_H
#include <stdint.h>
#include <memory/physical.h>
#include <stdint.h>
#define PAGES_PER_TABLE 1024
#define TABLES_PER_DIRECTORY 1024
-13
View File
@@ -1,13 +0,0 @@
#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
-24
View File
@@ -1,24 +0,0 @@
#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, const char* s);
char serialRead(uint32_t port);
#endif
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef SCREEN_GFXMODE_H
#define SCREEN_GFXMODE_H
#ifndef _SCREEN_GFXMODE_H
#define _SCREEN_GFXMODE_H
#include <memory/addresses.h>
#include <stdint.h>
+3 -3
View File
@@ -1,9 +1,9 @@
#ifndef SCREEN_GRAPHICS_H
#define SCREEN_GRAPHICS_H
#ifndef _SCREEN_GRAPHICS_H
#define _SCREEN_GRAPHICS_H
#include <stdint.h>
#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff )
#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);
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef SCREEN_TEXT_H
#define SCREEN_TEXT_H
#ifndef _SCREEN_TEXT_H
#define _SCREEN_TEXT_H
#include <stdint.h>
@@ -1,5 +1,5 @@
#ifndef TERMINAL_TERMINAL_H
#define TERMINAL_TERMINAL_H
#ifndef _SCREEN_TTY_H
#define _SCREEN_TTY_H
#include <stdint.h>
#include <stdbool.h>
+3 -3
View File
@@ -1,7 +1,7 @@
#ifndef INTERRUPT_SYSCALLS_H
#define INTERRUPT_SYSCALLS_H
#ifndef _SYSCALLS_SYSCALLS_H
#define _SYSCALLS_SYSCALLS_H
#include <interrupt/isr.h>
#include <cpu/isr.h>
int sys_exit (intFrame_t* iframe);
int sys_read (intFrame_t* iframe);
+1 -1
View File
@@ -4,7 +4,7 @@
include make.defaults
LIBK_ASM=$(LIBK_DIR)/interrupt/isr.s
LIBK_ASM=$(LIBK_DIR)/cpu/isr.s
$(LIBK): $(LIBK_SRC) $(LIBK_ASM) $(LIBC)
@echo "Building $(LIBK)..."
-29
View File
@@ -1,29 +0,0 @@
#include <ports/io.h>
#include <stdint.h>
// Port functions
uint8_t inb(uint16_t port) {
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outb(uint16_t port, uint8_t data) {
__asm__ volatile("outb %0, %1" :: "a"(data), "Nd"(port));
}
uint16_t inw(uint16_t port) {
uint16_t result;
__asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
return result;
}
void outw(uint16_t port, uint16_t data) {
__asm__ volatile("outw %0, %1" :: "a"(data), "Nd"(port));
}
void ioWait() {
// Waits ~1 I/O Cycle (Linux uses this so it should be good)
__asm__ volatile("outb %%al, $0x80" : : "a"(0));
}
-46
View File
@@ -1,46 +0,0 @@
#include <ports/serial.h>
#include <ports/io.h>
#include <stdint.h>
int setupSerial(uint32_t port) {
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(port + 0, 0x03); // Set divisor to 3 (low byte) 38400 baud
outb(port + 1, 0x00); // (high byte)
outb(port + 3, 0x03); // 8 bits, no parity, one stop bit
outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14 byte threshold
outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if it returns)
if (inb(port + 0) != 0xAE) return 1;
outb(port + 4, 0x0F); // non-loopback, IRQs enabled, OUT#1 and OUT#2 bits enabled
return 0;
}
int serialTransmitEmpty(uint32_t port) {
return inb(port + 5) & 0x20;
}
int serialRecieved(uint32_t port) {
return inb(port + 5) & 0x01;
}
void serialWrite(uint32_t port, char c) {
while (serialTransmitEmpty(port) == 0);
outb(port, c);
}
void serialPrint(uint32_t port, const char* s) {
while (*s != '\0') {
if (*s == '\n') serialWrite(port, '\r');
serialWrite(port, *s++);
}
}
char serialRead(uint32_t port) {
while (serialRecieved(port));
return inb(port);
}
+2 -2
View File
@@ -1,7 +1,7 @@
#include <screen/text.h>
#include <tty/tty.h>
#include <memory/addresses.h>
#include <screen/gfxmode.h>
#include <screen/tty.h>
#include <memory/addresses.h>
#include <stdint.h>
#include <string.h>
+2 -2
View File
@@ -1,4 +1,4 @@
#include <tty/tty.h>
#include <screen/tty.h>
#include <screen/gfxmode.h>
#include <screen/text.h>
#include <memory/addresses.h>
@@ -7,7 +7,7 @@
#include <stdbool.h>
#include <sys/gfx.h>
console_t* console = (console_t*)TERMINAL_INFO_LOC;
console_t* console = (console_t*)CONSOLE_INFO_LOC;
int32_t consoleWrite(const void* buf, uint32_t len) { // TODO fix font size
console->width = gfxMode->xRes / 8;//*(uint8_t*)(FONT_LOC);
+1 -1
View File
@@ -1,5 +1,5 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_close(intFrame_t* iframe) {
+2 -2
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <error/debug.h>
#include <drivers/serial.h>
#include <cpu/isr.h>
int sys_exit(intFrame_t* iframe) {
debugf("Tried to exit with %d", iframe->eax);
+1 -1
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <memory/malloc.h>
#include <cpu/isr.h>
int sys_free(intFrame_t* iframe) {
void* ptr = (void*)iframe->ebx;
+1 -1
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <memory/malloc.h>
#include <cpu/isr.h>
#include <stddef.h>
int sys_malloc(intFrame_t* iframe) {
+1 -1
View File
@@ -1,5 +1,5 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_open(intFrame_t* iframe) {
+1 -1
View File
@@ -1,5 +1,5 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <cpu/isr.h>
#include <stdio.h>
int sys_read(intFrame_t* iframe) {
+1 -1
View File
@@ -1,5 +1,5 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <cpu/isr.h>
int sys_seek(intFrame_t* iframe) {
// TODO
+1 -1
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <memory/addresses.h>
#include <cpu/isr.h>
#include <stdint.h>
int sys_sleep(intFrame_t* iframe) {
+2 -2
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <tty/tty.h>
#include <interrupt/isr.h>
#include <screen/tty.h>
#include <cpu/isr.h>
#include <stddef.h>
int sys_write(intFrame_t* iframe) {
+2 -2
View File
@@ -1,6 +1,6 @@
#include <syscalls/syscalls.h>
#include <interrupt/isr.h>
#include <error/debug.h>
#include <drivers/serial.h>
#include <cpu/isr.h>
#include <syscall.h>
// System call table
+1 -1
View File
@@ -2,7 +2,7 @@
# Main kern makefile
#
export VERSION = 0.2.1
export VERSION = 0.2.2
# Configurable variables (eg. CC, CFLAGS, ...)
include make.defaults
+4 -8
View File
@@ -58,18 +58,14 @@ Legend:
- [ ] types.h (syscall types)
- [ ] gfx.h (basic graphics lib)
- [ ] LIBK
- [x] disk - disk r/w
- [ ] error - error handling (bigerr is not enough :( )
- [ ] fs - filesystem
- [x] LIBK
- [x] drivers - everything that works with hardware
- [x] error - error handling (bigerr is not enough :( )
- [x] fs - filesystem
- [x] interrupt - handling and registering interupts
- [ ] input - handle ALL input devices (currently implemented as the keyboard dir)
- [x] memory - memory managing (physical and virtual)
- [x] ports - handles IO ports (eg. serial console)
- [x] screen - everything that displays on the screen
- [x] sound - handles everything related to sound
- [x] syscall - system calls
- [x] tty - handles terminal output
- [x] Multistage Bootloader
- [x] Bootloader reads filesystem to find files