forked from PoliEcho-holding-org/kern
Major libk restructuring, also rewrote drivers/serial.h
This commit is contained in:
@@ -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];
|
||||
@@ -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();
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef ERROR_DEBUG_H
|
||||
#define ERROR_DEBUG_H
|
||||
|
||||
int debugf(const char* fmt, ...);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef ERROR_PANIC_H
|
||||
#define ERROR_PANIC_H
|
||||
|
||||
void panic();
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef INTERRUPT_EXCEPTIONS_H
|
||||
#define INTERRUPT_EXCEPTIONS_H
|
||||
|
||||
void setupExceptions();
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
@@ -1,108 +0,0 @@
|
||||
#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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user