Skip to content

Commit e82ccc2

Browse files
committed
barebones kernel.cpp complete
1 parent 0ece80f commit e82ccc2

3 files changed

Lines changed: 52 additions & 130 deletions

File tree

Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Use g++ i686 Cross Compiler
1+
# Use the i686 Cross Compiler
22
GCC_FOLDER = ~/GCC_SRC
33
C = $(GCC_FOLDER)/bin/i686-elf-gcc
4+
CXX = $(GCC_FOLDER)/bin/i686-elf-g++
45
AS = $(GCC_FOLDER)/bin/i686-elf-as
5-
LD = $(C)
6+
LD = $(CXX)
67

78
# Compiler flags
89
C_FLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -v
10+
CXX_FLAGS = -ffreestanding -O2 -Wall -Wextra -fno-exceptions -fno-rtti
911
LD_FLAGS = -ffreestanding -O2 -nostdlib -lgcc
1012

1113
# Objects
@@ -18,24 +20,26 @@ objects = boot.o kernel.o
1820
%.o : %.c
1921
$(C) -o $@ -c $< $(C_FLAGS)
2022

21-
myos.bin: linker.ld $(objects)
23+
%.o : %.cpp
24+
$(CXX) -o $@ -c $< $(CXX_FLAGS)
25+
26+
custom-os.bin: linker.ld $(objects)
2227
$(LD) -T $< -o $@ $(LD_FLAGS) $(objects)
23-
# i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
2428

25-
install: myos.bin
29+
install: custom-os.bin
2630
mkdir -p isodir/boot/grub
27-
cp myos.bin isodir/boot/myos.bin
31+
cp custom-os.bin isodir/boot/custom-os.bin
2832
echo 'set timeout=0' > isodir/boot/grub/grub.cfg
2933
echo 'set default=0' >> isodir/boot/grub/grub.cfg
3034
echo '' >> isodir/boot/grub/grub.cfg
3135
echo 'menuentry "My Operating System" {' >> isodir/boot/grub/grub.cfg
32-
echo ' multiboot /boot/myos.bin' >> isodir/boot/grub/grub.cfg
36+
echo ' multiboot /boot/custom-os.bin' >> isodir/boot/grub/grub.cfg
3337
echo '}' >> isodir/boot/grub/grub.cfg
34-
grub-mkrescue -o myos.iso isodir
38+
grub-mkrescue -o custom-os.iso isodir
3539
rm -rf isodir
3640

3741
clean:
38-
rm -f $(objects) myos.bin myos.iso isodir
42+
rm -f $(objects) custom-os.bin custom-os.iso isodir
3943

4044
run:
41-
qemu-system-i386 -cdrom myos.iso
45+
qemu-system-i386 -cdrom custom-os.iso

kernel.c

Lines changed: 0 additions & 120 deletions
This file was deleted.

kernel.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,44 @@ void terminal_initialize(void)
8181
}
8282
}
8383

84+
void terminal_setcolor(uint8_t color)
85+
{
86+
terminal_color = color;
87+
}
88+
89+
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
90+
{
91+
const size_t index = y * VGA_WIDTH + x;
92+
terminal_buffer[index] = vga_entry(c, color);
93+
}
94+
95+
void terminal_putchar(char c)
96+
{
97+
if (c == '\n') {
98+
terminal_row++;
99+
terminal_column = 0;
100+
}
101+
else {
102+
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
103+
if (++terminal_column == VGA_WIDTH) {
104+
terminal_column = 0;
105+
if (++terminal_row == VGA_HEIGHT)
106+
terminal_row = 0;
107+
}
108+
}
109+
}
110+
111+
void terminal_write(const char* data, size_t size)
112+
{
113+
for (size_t i = 0; i < size; i++)
114+
terminal_putchar(data[i]);
115+
}
116+
117+
void terminal_writestring(const char* data)
118+
{
119+
terminal_write(data, strlen(data));
120+
}
121+
84122
// kernel main function called by loader.s
85123
extern "C" void kernel_main(void)
86124
{

0 commit comments

Comments
 (0)