Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ColumnLimit: 100
IndentWidth: 4
UseTab: ForIndentation
TabWidth: 4
SpacesBeforeTrailingComments: 1
NamespaceIndentation: None
AlignConsecutiveAssignments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: true
IndentCaseLabels: true
KeepEmptyLinesAtTheStartOfBlocks: false
PointerAlignment: Right
ContinuationIndentWidth: 4
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: true
IndentPPDirectives: None
IncludeBlocks: Preserve
Cpp11BracedListStyle: false
Standard: Cpp11
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $(shell mkdir -p $(dir $(OBJS)))
CFLAGS = -m64 -Wall -Werror -std=gnu11 -Ikernel/include -ffreestanding -O0 -fno-stack-protector
ASFLAGS = -64

.PHONY: all run test clean
.PHONY: all run test clean format

all: cis-os.iso

Expand All @@ -18,7 +18,7 @@ cis-os.iso: kernel/kernel.elf boot/grub.cfg
grub-mkrescue -o cis-os.iso isodir

kernel/kernel.elf: $(OBJS)
ld -nostdlib -o $@ -T scripts/linker.ld $(OBJS)
ld -z noexecstack -nostdlib -o $@ -T scripts/linker.ld $(OBJS)

%.o: %.c
gcc $(CFLAGS) -c -o $@ $<
Expand All @@ -27,7 +27,7 @@ kernel/kernel.elf: $(OBJS)
as $(ASFLAGS) -o $@ $<

serial.log: cis-os.iso
timeout 10s qemu-system-x86_64 -nographic -m 256 -cdrom $< -d guest_errors -serial file:$@ --no-reboot -no-shutdown || true
timeout 10s qemu-system-x86_64 -display none -m 256 -cdrom $< -d guest_errors -serial file:$@ --no-reboot -no-shutdown || true

test: serial.log
cat $<
Expand All @@ -42,3 +42,6 @@ clean:
rm -rf kernel/kernel.elf cis-os.iso
find kernel/ -name "*.o" -delete
rm -f serial.log

format:
find . -type d -name "3rd" -prune -o -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 clang-format -i -style=file
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Users: 0

1. Установите необходимые инструменты:
```bash
sudo apt install gcc build-essential grub2-common qemu-system-x86 xorriso mtools
sudo apt install gcc build-essential grub2-common qemu-system-x86 xorriso mtools clang-format
```

2. Соберите проект:
Expand Down
1 change: 1 addition & 0 deletions boot/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ set default=0

menuentry "CIS-OS" {
multiboot /boot/kernel.elf
module /initrd.cpio
}
2 changes: 1 addition & 1 deletion kernel/arch/amd64/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ amd64:
halt:
cli
hlt
jmp halt
jmp halt
12 changes: 12 additions & 0 deletions kernel/arch/amd64/idt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <kstdint.h>

// From https://wiki.osdev.org/Interrupt_Descriptor_Table#Structure_on_x86-64
struct idt_64 {
uint16_t offset_1; // offset bits 0..15
uint16_t selector; // a code segment selector in GDT or LDT
uint8_t ist; // bits 0..2 holds Interrupt Stack Table offset, rest of bits zero.
uint8_t type_attributes; // gate type, dpl, and p fields
uint16_t offset_2; // offset bits 16..31
uint32_t offset_3; // offset bits 32..63
uint32_t zero; // reserved
};
7 changes: 7 additions & 0 deletions kernel/arch/amd64/paging.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <kstdint.h>

uint64_t paging_main[3][512] __attribute__((aligned(4096))) = { 0 };

int paging_init( ) {
return -1;
}
35 changes: 35 additions & 0 deletions kernel/arch/amd64/serial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <kasm.h>
#include <kstdint.h>

void serial_write_byte(uint8_t byte) {
// Wait until the transmit holding register is empty
while ((inb(0x3f8 + 5) & 0x20) == 0)
;
outb(0x3f8, byte);
}

int serial_init( ) {
// Disable all interrupts
outb(0x3f8 + 1, 0x00);

// Set divisor latch access bit (DLAB) to set baud rate
outb(0x3f8 + 3, 0x80);

// Set divisor to 12 for 9600 baud (115200 / 9600 = 12)
outb(0x3f8, 0x0C); // Low byte of divisor
outb(0x3f8 + 1, 0x00); // High byte of divisor (0 for divisor < 256)

// Disable DLAB and set communication parameters: 8n1 (8 bits, no parity, 1 stop bit)
outb(0x3f8 + 3, 0x03);

// Enable FIFOs
outb(0x3f8 + 2, 0xC7); // Enable FIFO, clear Rx and Tx FIFOs

// Set default line control
outb(0x3f8 + 4, 0x0B); // Enable FIFO, RTS, DTR

// Read Line Status Register to clear any pending errors
inb(0x3f8 + 5);

return 0;
}
Loading
Loading