Last active
March 16, 2019 23:01
-
-
Save slendidev/e01f26f7b7d759f2f6bc67db67ecba7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
. ./headers.sh | |
for PROJECT in $PROJECTS; do | |
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install) | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
. ./config.sh | |
for PROJECT in $PROJECTS; do | |
(cd $PROJECT && $MAKE clean) | |
done | |
rm -rf sysroot | |
rm -rf isodir | |
rm -rf radukern.iso |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SYSTEM_HEADER_PROJECTS="libc kernel" | |
PROJECTS="libc kernel" | |
export MAKE=${MAKE:-make} | |
export HOST=${HOST:-$(./default-host.sh)} | |
export AR=${HOST}-ar | |
export AS=${HOST}-as | |
export CC=${HOST}-gcc | |
export PREFIX=/usr | |
export EXEC_PREFIX=$PREFIX | |
export BOOTDIR=/boot | |
export LIBDIR=$EXEC_PREFIX/lib | |
export INCLUDEDIR=$PREFIX/include | |
export CFLAGS='-O2 -g' | |
export CPPFLAGS='' | |
# Configure the cross-compiler to use the desired system root. | |
export SYSROOT="$(pwd)/sysroot" | |
export CC="$CC --sysroot=$SYSROOT" | |
# Work around that the -elf gcc targets doesn't have a system include directory | |
# because it was configured with --without-headers rather than --with-sysroot. | |
if echo "$HOST" | grep -Eq -- '-elf($|-)'; then | |
export CC="$CC -isystem=$INCLUDEDIR -masm=intel --warn-return-type" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
. ./config.sh | |
mkdir -p "$SYSROOT" | |
for PROJECT in $SYSTEM_HEADER_PROJECTS; do | |
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers) | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <ioaccess.h> | |
#include "kernel/keyboard.h" | |
volatile char character = 0; | |
void send_eoi(int irq) | |
{ | |
if (irq > 7) | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); | |
} | |
uint8_t inb(uint16_t port) | |
{ | |
uint8_t ret; | |
asm volatile ( "inb %0, %1" | |
: "=a"(ret) | |
: "Nd"(port) ); | |
return ret; | |
} | |
void irq0_handler(void) { | |
// TODO: Add timer handler | |
outb(0x20, 0x20); | |
} | |
void irq1_handler(void) { | |
// TODO: Use pointers to add later a getch() function in stdio | |
uint8_t keycode; | |
keycode = inb(0x60); | |
character = keyboard_to_ascii(keycode); | |
printf("%c", character); | |
outb(0x20, 0x20); | |
} | |
void irq2_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq3_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq4_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq5_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq6_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq7_handler(void) { | |
outb(0x20, 0x20); //EOI | |
} | |
void irq8_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq9_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq10_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq11_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq12_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq13_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq14_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} | |
void irq15_handler(void) { | |
outb(0xA0, 0x20); | |
outb(0x20, 0x20); //EOI | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You better go do something else because this is HELL | |
#include "kernel/keyboard.h" | |
#include <stdint.h> | |
#include <stdbool.h> | |
volatile char character; | |
enum KEYCODE { | |
NULL_KEY = 0, | |
Q_PRESSED = 0x10, | |
Q_RELEASED = 0x90, | |
W_PRESSED = 0x11, | |
W_RELEASED = 0x91, | |
E_PRESSED = 0x12, | |
E_RELEASED = 0x92, | |
R_PRESSED = 0x13, | |
R_RELEASED = 0x93, | |
T_PRESSED = 0x14, | |
T_RELEASED = 0x94, | |
Y_PRESSED = 0x15, | |
Y_RELEASED = 0x95, | |
U_PRESSED = 0x16, | |
U_RELEASED = 0x96, | |
I_PRESSED = 0x17, | |
I_RELEASED = 0x97, | |
O_PRESSED = 0x18, | |
O_RELEASED = 0x98, | |
P_PRESSED = 0x19, | |
P_RELEASED = 0x99, | |
A_PRESSED = 0x1E, | |
A_RELEASED = 0x9E, | |
S_PRESSED = 0x1F, | |
S_RELEASED = 0x9F, | |
D_PRESSED = 0x20, | |
D_RELEASED = 0xA0, | |
F_PRESSED = 0x21, | |
F_RELEASED = 0xA1, | |
G_PRESSED = 0x22, | |
G_RELEASED = 0xA2, | |
H_PRESSED = 0x23, | |
H_RELEASED = 0xA3, | |
J_PRESSED = 0x24, | |
J_RELEASED = 0xA4, | |
K_PRESSED = 0x25, | |
K_RELEASED = 0xA5, | |
L_PRESSED = 0x26, | |
L_RELEASED = 0xA6, | |
Z_PRESSED = 0x2C, | |
Z_RELEASED = 0xAC, | |
X_PRESSED = 0x2D, | |
X_RELEASED = 0xAD, | |
C_PRESSED = 0x2E, | |
C_RELEASED = 0xAE, | |
V_PRESSED = 0x2F, | |
V_RELEASED = 0xAF, | |
B_PRESSED = 0x30, | |
B_RELEASED = 0xB0, | |
N_PRESSED = 0x31, | |
N_RELEASED = 0xB1, | |
M_PRESSED = 0x32, | |
M_RELEASED = 0xB2, | |
ZERO_PRESSED = 0x0B, | |
ZERO_RELEASED = 0x8B, | |
ONE_PRESSED = 0x2, | |
ONE_RELEASED = 0x82, | |
NINE_PRESSED = 0xA, | |
NINE_RELEASED = 0x8A, | |
POINT_PRESSED = 0x34, | |
POINT_RELEASED = 0xB4, | |
SLASH_RELEASED = 0xB5, | |
BACKSPACE_PRESSED = 0xE, | |
BACKSPACE_RELEASED = 0x8E, | |
SPACE_PRESSED = 0x39, | |
SPACE_RELEASED = 0xB9, | |
ENTER_PRESSED = 0x1C, | |
ENTER_RELEASED = 0x9C, | |
LSHIFT_PRESSED = 0x2A, | |
LSHIFT_RELEASED = 0xAA, | |
RSHIFT_PRESSED = 0x36, | |
RSHIFT_RELEASED = 0xB6, | |
MINUS_PRESSED = 0x0C, | |
MINUS_RELEASED = 0x8C, | |
EQUALS_PRESSED = 0x0D, | |
EQUALS_RELEASED = 0x8D, | |
}; | |
bool shiftPressed = false; | |
static char* _qwertzuiop = "qwertyuiop[]"; | |
static char* _asdfghjkl = "asdfghjkl;'"; | |
static char* _yxcvbnm = "zxcvbnm,./"; | |
static char* _num = "1234567890-="; | |
static char* _caps_qwertzuiop = "QWERTYUIOP{}"; | |
static char* _caps_asdfghjkl = "ASDFGHJKL:\""; | |
static char* _caps_yxcvbnm = "ZXCVBNM<>?"; | |
static char* _caps_num = "!@#$%^&*()_+"; | |
uint8_t keyboard_to_ascii(uint8_t key) { | |
if(key == ENTER_PRESSED) return '\n'; | |
if(key == SPACE_PRESSED) return ' '; | |
if(key == ENTER_PRESSED) return '\r'; | |
if(key == BACKSPACE_PRESSED) return '\b'; | |
if(key >= ONE_PRESSED && key <= EQUALS_PRESSED) | |
if (shiftPressed) { | |
return _caps_num[key - ONE_PRESSED]; | |
} else { | |
return _num[key - ONE_PRESSED]; | |
} | |
if(key >= Q_PRESSED && key <= ENTER_PRESSED+1) | |
{ | |
if (shiftPressed) { | |
return _caps_qwertzuiop[key - Q_PRESSED]; | |
} else { | |
return _qwertzuiop[key - Q_PRESSED]; | |
} | |
} else if(key == 0x2B) { | |
if (shiftPressed) { | |
return '|'; | |
} else { | |
return '\\'; | |
} | |
} else if(key == 0x29) { | |
if (shiftPressed) { | |
return '~'; | |
} else { | |
return '`'; | |
} | |
} else if(key >= A_PRESSED && key <= L_PRESSED+2) | |
{ | |
if (shiftPressed) { | |
return _caps_asdfghjkl[key - A_PRESSED]; | |
} else { | |
return _asdfghjkl[key - A_PRESSED]; | |
} | |
} else if(key >= Z_PRESSED && key <= 0x35) | |
{ | |
if (shiftPressed) { | |
return _caps_yxcvbnm[key - Z_PRESSED]; | |
} else { | |
return _yxcvbnm[key - Z_PRESSED]; | |
} | |
} | |
if (key == LSHIFT_PRESSED || key == RSHIFT_PRESSED) { | |
shiftPressed = true; | |
} else if (key == LSHIFT_RELEASED || key == RSHIFT_RELEASED) { | |
shiftPressed = false; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern volatile char character; | |
#include <stdint.h> | |
uint8_t keyboard_to_ascii(uint8_t key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
#include <interrupts.h> | |
#include <ioaccess.h> | |
#include <pic.h> | |
#include <kernel/tty.h> | |
#define PIC_MASTER_COMMAND 0x20 | |
#define PIC_MASTER_DATA 0x21 | |
#define PIC_MASTER_IMR 0x21 | |
#define PIC_SLAVE_COMMAND 0xA0 | |
#define PIC_SLAVE_DATA 0xA1 | |
#define PIC_SLAVE_IMR 0xA1 | |
#define EOI 0x20 | |
void pic_remap(int interrupt_num) { | |
char buffer[20]; | |
itoa(interrupt_num, buffer, 10); | |
printf ("Interrupt number: %s\n", buffer); | |
outb (PIC_MASTER_COMMAND, 0x11); | |
outb (PIC_SLAVE_COMMAND, 0x11); | |
outb (PIC_MASTER_DATA, interrupt_num); | |
outb (PIC_SLAVE_DATA, interrupt_num + 8); | |
outb (PIC_MASTER_DATA, 0x04); | |
outb (PIC_SLAVE_DATA, 2); | |
outb (PIC_MASTER_DATA, 0x01); | |
outb (PIC_SLAVE_DATA, 0x01); | |
} | |
void pic_masc_irqs (uint16_t mask) { | |
outb (PIC_MASTER_IMR, (uint8_t) mask); | |
outb (PIC_SLAVE_IMR, (uint8_t) (mask >> 8)); | |
} | |
void pic_send_eoi (int irq_num) { | |
outb (PIC_MASTER_COMMAND, EOI); | |
if (irq_num > 7) { // If the IRQs are over 7 years old, we must send an EOI both to the master and slave | |
outb (PIC_SLAVE_COMMAND, EOI); | |
} | |
} | |
// IDT Table | |
struct IDT_entry{ | |
unsigned short int offset_lowerbits; | |
unsigned short int selector; | |
unsigned char zero; | |
unsigned char type_attr; | |
unsigned short int offset_higherbits; | |
}; | |
struct IDT_entry IDT[256]; | |
// Im too lazy so stfu | |
void idt_init(void) { | |
extern int load_idt(); | |
extern int irq0(); | |
extern int irq1(); | |
extern int irq2(); | |
extern int irq3(); | |
extern int irq4(); | |
extern int irq5(); | |
extern int irq6(); | |
extern int irq7(); | |
extern int irq8(); | |
extern int irq9(); | |
extern int irq10(); | |
extern int irq11(); | |
extern int irq12(); | |
extern int irq13(); | |
extern int irq14(); | |
extern int irq15(); | |
unsigned long irq0_address; | |
unsigned long irq1_address; | |
unsigned long irq2_address; | |
unsigned long irq3_address; | |
unsigned long irq4_address; | |
unsigned long irq5_address; | |
unsigned long irq6_address; | |
unsigned long irq7_address; | |
unsigned long irq8_address; | |
unsigned long irq9_address; | |
unsigned long irq10_address; | |
unsigned long irq11_address; | |
unsigned long irq12_address; | |
unsigned long irq13_address; | |
unsigned long irq14_address; | |
unsigned long irq15_address; | |
unsigned long idt_address; | |
unsigned long idt_ptr[2]; | |
/* remapping the PIC */ | |
outb(0x20, 0x11); | |
outb(0xA0, 0x11); | |
outb(0x21, 0x20); | |
outb(0xA1, 40); | |
outb(0x21, 0x04); | |
outb(0xA1, 0x02); | |
outb(0x21, 0x01); | |
outb(0xA1, 0x01); | |
outb(0x21, 0x0); | |
outb(0xA1, 0x0); | |
irq0_address = (unsigned long)irq0; | |
IDT[32].offset_lowerbits = irq0_address & 0xffff; | |
IDT[32].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[32].zero = 0; | |
IDT[32].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[32].offset_higherbits = (irq0_address & 0xffff0000) >> 16; | |
irq1_address = (unsigned long)irq1; | |
IDT[33].offset_lowerbits = irq1_address & 0xffff; | |
IDT[33].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[33].zero = 0; | |
IDT[33].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[33].offset_higherbits = (irq1_address & 0xffff0000) >> 16; | |
irq2_address = (unsigned long)irq2; | |
IDT[34].offset_lowerbits = irq2_address & 0xffff; | |
IDT[34].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[34].zero = 0; | |
IDT[34].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[34].offset_higherbits = (irq2_address & 0xffff0000) >> 16; | |
irq3_address = (unsigned long)irq3; | |
IDT[35].offset_lowerbits = irq3_address & 0xffff; | |
IDT[35].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[35].zero = 0; | |
IDT[35].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[35].offset_higherbits = (irq3_address & 0xffff0000) >> 16; | |
irq4_address = (unsigned long)irq4; | |
IDT[36].offset_lowerbits = irq4_address & 0xffff; | |
IDT[36].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[36].zero = 0; | |
IDT[36].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[36].offset_higherbits = (irq4_address & 0xffff0000) >> 16; | |
irq5_address = (unsigned long)irq5; | |
IDT[37].offset_lowerbits = irq5_address & 0xffff; | |
IDT[37].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[37].zero = 0; | |
IDT[37].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[37].offset_higherbits = (irq5_address & 0xffff0000) >> 16; | |
irq6_address = (unsigned long)irq6; | |
IDT[38].offset_lowerbits = irq6_address & 0xffff; | |
IDT[38].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[38].zero = 0; | |
IDT[38].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[38].offset_higherbits = (irq6_address & 0xffff0000) >> 16; | |
irq7_address = (unsigned long)irq7; | |
IDT[39].offset_lowerbits = irq7_address & 0xffff; | |
IDT[39].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[39].zero = 0; | |
IDT[39].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[39].offset_higherbits = (irq7_address & 0xffff0000) >> 16; | |
irq8_address = (unsigned long)irq8; | |
IDT[40].offset_lowerbits = irq8_address & 0xffff; | |
IDT[40].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[40].zero = 0; | |
IDT[40].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[40].offset_higherbits = (irq8_address & 0xffff0000) >> 16; | |
irq9_address = (unsigned long)irq9; | |
IDT[41].offset_lowerbits = irq9_address & 0xffff; | |
IDT[41].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[41].zero = 0; | |
IDT[41].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[41].offset_higherbits = (irq9_address & 0xffff0000) >> 16; | |
irq10_address = (unsigned long)irq10; | |
IDT[42].offset_lowerbits = irq10_address & 0xffff; | |
IDT[42].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[42].zero = 0; | |
IDT[42].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[42].offset_higherbits = (irq10_address & 0xffff0000) >> 16; | |
irq11_address = (unsigned long)irq11; | |
IDT[43].offset_lowerbits = irq11_address & 0xffff; | |
IDT[43].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[43].zero = 0; | |
IDT[43].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[43].offset_higherbits = (irq11_address & 0xffff0000) >> 16; | |
irq12_address = (unsigned long)irq12; | |
IDT[44].offset_lowerbits = irq12_address & 0xffff; | |
IDT[44].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[44].zero = 0; | |
IDT[44].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[44].offset_higherbits = (irq12_address & 0xffff0000) >> 16; | |
irq13_address = (unsigned long)irq13; | |
IDT[45].offset_lowerbits = irq13_address & 0xffff; | |
IDT[45].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[45].zero = 0; | |
IDT[45].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[45].offset_higherbits = (irq13_address & 0xffff0000) >> 16; | |
irq14_address = (unsigned long)irq14; | |
IDT[46].offset_lowerbits = irq14_address & 0xffff; | |
IDT[46].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[46].zero = 0; | |
IDT[46].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[46].offset_higherbits = (irq14_address & 0xffff0000) >> 16; | |
irq15_address = (unsigned long)irq15; | |
IDT[47].offset_lowerbits = irq15_address & 0xffff; | |
IDT[47].selector = 0x08; /* KERNEL_CODE_SEGMENT_OFFSET */ | |
IDT[47].zero = 0; | |
IDT[47].type_attr = 0x8e; /* INTERRUPT_GATE */ | |
IDT[47].offset_higherbits = (irq15_address & 0xffff0000) >> 16; | |
/* fill the IDT descriptor */ | |
idt_address = (unsigned long)IDT ; | |
idt_ptr[0] = (sizeof (struct IDT_entry) * 256) + ((idt_address & 0xffff) << 16); | |
idt_ptr[1] = idt_address >> 16 ; | |
load_idt(idt_ptr); | |
} | |
void kernel_main(void) { | |
terminal_initialize(); | |
// outb('a', 0xE9); | |
puts("Kernel joined the game."); | |
// puts("Remapping PIC: IRQ=1 (Keyboard interrupt)"); | |
// pic_remap(1); | |
puts("Remaping the PIC and initializing idt"); | |
idt_init(); | |
puts ("Checking if interrupts are enabled."); | |
bool a = are_interrupts_enabled(); | |
if (a == true) { | |
puts("Interrups are enabled"); | |
} else { | |
puts("Interrupts are disabled"); | |
} | |
puts ("Using keyboard layout US QWERTY - Scan Code set 1."); | |
puts ("Nothing left to do. The kernel is now sleeping."); | |
char i = getch(); | |
printf("%s\n", i); | |
while (1) { | |
asm ("hlt"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEFAULT_HOST!=../default-host.sh | |
HOST?=DEFAULT_HOST | |
HOSTARCH!=../target-triplet-to-arch.sh $(HOST) | |
CFLAGS?=-O2 -g | |
CPPFLAGS?= | |
LDFLAGS?= | |
LIBS?= | |
DESTDIR?= | |
PREFIX?=/usr/local | |
EXEC_PREFIX?=$(PREFIX) | |
BOOTDIR?=$(EXEC_PREFIX)/boot | |
INCLUDEDIR?=$(PREFIX)/include | |
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra | |
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude | |
LDFLAGS:=$(LDFLAGS) | |
LIBS:=$(LIBS) -nostdlib -lk -lgcc | |
ARCHDIR=arch/$(HOSTARCH) | |
include $(ARCHDIR)/make.config | |
CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS) | |
CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) | |
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS) | |
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS) | |
KERNEL_OBJS=\ | |
$(KERNEL_ARCH_OBJS) \ | |
kernel/kernel.o \ | |
OBJS=\ | |
$(ARCHDIR)/crti.o \ | |
$(ARCHDIR)/crtbegin.o \ | |
$(KERNEL_OBJS) \ | |
$(ARCHDIR)/crtend.o \ | |
$(ARCHDIR)/keyboard.o \ | |
$(ARCHDIR)/crtn.o \ | |
$(ARCHDIR)/irq.o \ | |
$(ARCHDIR)/irqc.o \ | |
LINK_LIST=\ | |
$(LDFLAGS) \ | |
$(ARCHDIR)/crti.o \ | |
$(ARCHDIR)/crtbegin.o \ | |
$(KERNEL_OBJS) \ | |
$(LIBS) \ | |
$(ARCHDIR)/crtend.o \ | |
$(ARCHDIR)/keyboard.o \ | |
$(ARCHDIR)/crtn.o \ | |
$(ARCHDIR)/irq.o \ | |
$(ARCHDIR)/irqc.o \ | |
.PHONY: all clean install install-headers install-kernel | |
.SUFFIXES: .o .c .S | |
all: raduos.kernel | |
raduos.kernel: $(OBJS) $(ARCHDIR)/linker.ld | |
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST) | |
grub-file --is-x86-multiboot raduos.kernel | |
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o: | |
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@ | |
.c.o: | |
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) | |
.S.o: | |
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) | |
clean: | |
rm -f raduos.kernel | |
rm -f $(OBJS) *.o */*.o */*/*.o | |
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d | |
install: install-headers install-kernel | |
install-headers: | |
mkdir -p $(DESTDIR)$(INCLUDEDIR) | |
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. | |
install-kernel: raduos.kernel | |
mkdir -p $(DESTDIR)$(BOOTDIR) | |
cp raduos.kernel $(DESTDIR)$(BOOTDIR) | |
-include $(OBJS:.o=.d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _STDIO_H | |
#define _STDIO_H 1 | |
#include <sys/cdefs.h> | |
#define EOF (-1) | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
char getch(); | |
int printf(const char* __restrict, ...); | |
int putchar(int); | |
int puts(const char*); | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEFAULT_HOST!=../default-host.sh | |
HOST?=DEFAULT_HOST | |
HOSTARCH!=../target-triplet-to-arch.sh $(HOST) | |
CFLAGS?=-O2 -g | |
CPPFLAGS?= | |
LDFLAGS?= | |
LIBS?= | |
DESTDIR?= | |
PREFIX?=/usr/local | |
EXEC_PREFIX?=$(PREFIX) | |
INCLUDEDIR?=$(PREFIX)/include | |
LIBDIR?=$(EXEC_PREFIX)/lib | |
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra | |
CPPFLAGS:=$(CPPFLAGS) -D__is_libc -Iinclude | |
LIBK_CFLAGS:=$(CFLAGS) | |
LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_libk | |
ARCHDIR=arch/$(HOSTARCH) | |
include $(ARCHDIR)/make.config | |
CFLAGS:=$(CFLAGS) $(ARCH_CFLAGS) | |
CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS) | |
LIBK_CFLAGS:=$(LIBK_CFLAGS) $(KERNEL_ARCH_CFLAGS) | |
LIBK_CPPFLAGS:=$(LIBK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) | |
FREEOBJS=\ | |
$(ARCH_FREEOBJS) \ | |
stdio/getch.o \ | |
stdio/printf.o \ | |
stdio/putchar.o \ | |
stdio/puts.o \ | |
stdlib/abort.o \ | |
stdlib/swap.o \ | |
stdlib/reverse.o \ | |
stdlib/itoa.o \ | |
string/memcmp.o \ | |
string/memcpy.o \ | |
string/memmove.o \ | |
string/memset.o \ | |
string/strlen.o \ | |
interrupts/are_interrupts_enabled.o \ | |
interrupts/irqrestore.o \ | |
interrupts/save_irqdisable.o \ | |
ioaccess/inb.o \ | |
ioaccess/outb.o \ | |
ioaccess/io_wait.o \ | |
pic/pic_get_isr.o \ | |
pic/PIC_sendEOI.o \ | |
pic/PIC_remap.o \ | |
pic/pic_get_irr.o \ | |
pic/IRQ_set_mask.o \ | |
pic/IRQ_clear_mask.o \ | |
HOSTEDOBJS=\ | |
$(ARCH_HOSTEDOBJS) \ | |
OBJS=\ | |
$(FREEOBJS) \ | |
$(HOSTEDOBJS) \ | |
LIBK_OBJS=$(FREEOBJS:.o=.libk.o) | |
#BINARIES=libc.a libk.a # Not ready for libc yet. | |
BINARIES=libk.a | |
.PHONY: all clean install install-headers install-libs | |
.SUFFIXES: .o .libk.o .c .S | |
all: $(BINARIES) | |
libc.a: $(OBJS) | |
$(AR) rcs $@ $(OBJS) | |
libk.a: $(LIBK_OBJS) | |
$(AR) rcs $@ $(LIBK_OBJS) | |
.c.o: | |
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) | |
.c.S: | |
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) | |
.c.libk.o: | |
$(CC) -MD -c $< -o $@ -std=gnu11 $(LIBK_CFLAGS) $(LIBK_CPPFLAGS) | |
.S.libk.o: | |
$(CC) -MD -c $< -o $@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS) | |
clean: | |
rm -f $(BINARIES) *.a | |
rm -f $(OBJS) $(LIBK_OBJS) *.o */*.o */*/*.o | |
rm -f $(OBJS:.o=.d) $(LIBK_OBJS:.o=.d) *.d */*.d */*/*.d | |
install: install-headers install-libs | |
install-headers: | |
mkdir -p $(DESTDIR)$(INCLUDEDIR) | |
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. | |
install-libs: $(BINARIES) | |
mkdir -p $(DESTDIR)$(LIBDIR) | |
cp $(BINARIES) $(DESTDIR)$(LIBDIR) | |
-include $(OBJS:.o=.d) | |
-include $(LIBK_OBJS:.o=.d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "kernel/keyboard.h" | |
volatile char character; | |
char getch() { | |
while (character == 0) { | |
return character; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment