mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Include file restructure!
- include/ now has subdirs - standard C headers will be in 'include/c'. Any program can include these - all other header shall only be used by the kernel
This commit is contained in:
@@ -3,7 +3,7 @@ CC = i386-elf-gcc
|
|||||||
LD = i386-elf-ld
|
LD = i386-elf-ld
|
||||||
AS = nasm
|
AS = nasm
|
||||||
|
|
||||||
CFLAGS = -ffreestanding -fno-builtin -fno-stack-protector -nostdinc -mgeneral-regs-only -m32 -march=i386 -Iinclude -Wall
|
CFLAGS = -ffreestanding -fno-builtin -fno-stack-protector -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall -Iinclude/c
|
||||||
|
|
||||||
SRC = ./src
|
SRC = ./src
|
||||||
BUILD = ./build
|
BUILD = ./build
|
||||||
@@ -47,7 +47,7 @@ kernel: $(SRC)/kernel.c $(SRC)/entry.asm
|
|||||||
@echo "Assembling $(SRC)/entry.asm..."
|
@echo "Assembling $(SRC)/entry.asm..."
|
||||||
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
|
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
|
||||||
@echo "Compiling $(SRC)/kernel.c..."
|
@echo "Compiling $(SRC)/kernel.c..."
|
||||||
@$(CC) $(CFLAGS) -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
|
@$(CC) $(CFLAGS) -Iinclude -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
|
||||||
@$(LD) -T$(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o
|
@$(LD) -T$(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o
|
||||||
@rm $(BUILD)/*.o
|
@rm $(BUILD)/*.o
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef TIME_H
|
#ifndef TIME_H
|
||||||
#define TIME_H
|
#define TIME_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void sleep(uint32_t ms) {
|
void sleep(uint32_t ms) {
|
||||||
__asm__ volatile ("int $0x80" : : "a"(0), "b"(ms));
|
__asm__ volatile ("int $0x80" : : "a"(0), "b"(ms));
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#define DRIVE_H
|
#define DRIVE_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <system.h>
|
#include <ports/io.h>
|
||||||
|
|
||||||
#define PIO_PORT 0x1f0
|
#define PIO_PORT 0x1f0
|
||||||
#define READ_COMMAND 0x20
|
#define READ_COMMAND 0x20
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef ISRS_H
|
#ifndef ISRS_H
|
||||||
#define ISRS_H
|
#define ISRS_H
|
||||||
|
|
||||||
#include <idt.h>
|
#include <interrupt/idt.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
|
|
||||||
// Exception handlers
|
// Exception handlers
|
||||||
__attribute__ ((interrupt))
|
__attribute__ ((interrupt))
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#define IDT_H
|
#define IDT_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
|
|
||||||
#define TRAP_GATE_FLAGS 0x8f // P = 1, DPL = 00, S = 0, Type = 1111 (32-bit Trap gate)
|
#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 INT_GATE_FLAGS 0x8e // P = 1, DPL = 00, S = 0, Type = 1110 (32-bit Int gate)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef PIC_H
|
#ifndef PIC_H
|
||||||
#define PIC_H
|
#define PIC_H
|
||||||
|
|
||||||
#include <system.h>
|
#include <ports/io.h>
|
||||||
|
|
||||||
// PIC I/O Ports
|
// PIC I/O Ports
|
||||||
#define PIC_1_CMD 0x20
|
#define PIC_1_CMD 0x20
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
#define TIMER_H
|
#define TIMER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <idt.h>
|
#include <interrupt/idt.h>
|
||||||
#include <pic.h>
|
#include <interrupt/pic.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
|
|
||||||
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
|
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
|
||||||
#define COMMAND 0x43
|
#define COMMAND 0x43
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef SYSCALL_H
|
#ifndef SYSCALL_H
|
||||||
#define SYSCALL_H
|
#define SYSCALL_H
|
||||||
|
|
||||||
#include <pit.h>
|
#include <interrupt/pit.h>
|
||||||
|
|
||||||
// System call count
|
// System call count
|
||||||
#define MAX_SYSCALLS 2
|
#define MAX_SYSCALLS 2
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef KEYBOARD_H
|
#ifndef KEYBOARD_H
|
||||||
#define KEYBOARD_H
|
#define KEYBOARD_H
|
||||||
|
|
||||||
#include <idt.h>
|
#include <interrupt/idt.h>
|
||||||
#include <pic.h>
|
#include <interrupt/pic.h>
|
||||||
#include <system.h>
|
#include <ports/io.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#define GRAPHICS_H
|
#define GRAPHICS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff )
|
#define rgb(r,g,b) ( ((r) << 16 | (g) << 8 | (b)) & 0x00ffffff )
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
#ifndef TIMER_H
|
|
||||||
#define TIMER_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <idt.h>
|
|
||||||
#include <pic.h>
|
|
||||||
#include <screen.h>
|
|
||||||
|
|
||||||
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
|
|
||||||
#define COMMAND 0x43
|
|
||||||
#define INPUT_CLK 1193182
|
|
||||||
|
|
||||||
static uint32_t* timerTicks = (uint32_t*)0x1000;
|
|
||||||
|
|
||||||
__attribute__ ((interrupt))
|
|
||||||
void timerHandler(intFrame_t* iframe) {
|
|
||||||
*timerTicks += 1;
|
|
||||||
|
|
||||||
// TODO: Improve the cursor rendering
|
|
||||||
if (*timerTicks % 500 == 0) putcAt(' ', cursor.x, cursor.y);
|
|
||||||
else if (*timerTicks % 250 == 0) putcAt(127, cursor.x, cursor.y);
|
|
||||||
|
|
||||||
sendPicEOI(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPitPhase(uint8_t channel, uint8_t opMode, uint16_t hz) {
|
|
||||||
if (channel > 2 || opMode > 7) { return; }
|
|
||||||
__asm__ volatile ("cli");
|
|
||||||
|
|
||||||
// Send command - bits 7-6 channel, 5-4 Access mode, 3-1 operating mode, 0 - Should be zero in x86
|
|
||||||
outb(COMMAND, ((channel << 6) | (3 << 4) | (opMode << 1)));
|
|
||||||
|
|
||||||
// Send frequency
|
|
||||||
uint16_t freq = INPUT_CLK / hz; // I solved an equation to figure this out
|
|
||||||
outb(CHANNEL_0 + channel, (uint8_t)freq);
|
|
||||||
outb(CHANNEL_0 + channel, (uint8_t)(freq >> 8));
|
|
||||||
|
|
||||||
__asm__ volatile ("sti");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupTimer() { // Sets up IRQ 0 - PIT
|
|
||||||
idtSetGate(0x20, timerHandler, INT_GATE_FLAGS);
|
|
||||||
unsetIrqMask(0);
|
|
||||||
setPitPhase(0, 2, 1000); // Default setup: 1000Hz - 1 tick per 1ms
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+2
-7
@@ -1,13 +1,8 @@
|
|||||||
#include "stdint.h"
|
#include <time.h>
|
||||||
#include "screen.h"
|
|
||||||
|
|
||||||
__attribute__ ((section ("entry")))
|
__attribute__ ((section ("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
uint32_t wait = 0x1fffffff;
|
sleep(4500); // Wait 4.5 seconds
|
||||||
|
|
||||||
print("kern.\n\n");
|
|
||||||
|
|
||||||
while (wait--);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -1,16 +1,16 @@
|
|||||||
#include <physicalMemManager.h> // TODO: Name this better
|
#include <memory/physical.h>
|
||||||
#include <disk.h>
|
#include <disk/disk.h>
|
||||||
#include <screen.h>
|
#include <screen/text.h>
|
||||||
#include <idt.h>
|
#include <interrupt/idt.h>
|
||||||
#include <exceptions.h>
|
#include <interrupt/exceptions.h>
|
||||||
#include <syscall.h>
|
#include <interrupt/syscall.h>
|
||||||
#include <pic.h>
|
#include <interrupt/pic.h>
|
||||||
#include <system.h>
|
#include <ports/io.h>
|
||||||
#include <string.h>
|
#include <c/string.h>
|
||||||
#include <graphics.h>
|
#include <screen/graphics.h>
|
||||||
#include <keyboard.h>
|
#include <keyboard/keyboard.h>
|
||||||
#include <pit.h>
|
#include <interrupt/pit.h>
|
||||||
#include <time.h>
|
#include <c/time.h>
|
||||||
|
|
||||||
#define PROMPT "#> "
|
#define PROMPT "#> "
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user