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
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: configure
run: |
sudo apt update
sudo apt install gcc build-essential grub2-common qemu-system-x86 xorriso mtools
sudo apt install gcc build-essential grub2-common grub-pc xorriso qemu-system-x86 xorriso mtools cpio
- name: make
run: make
- name: run and test
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SRCS := $(shell find kernel/ -name "*.c" -o -name "*.s")
OBJS := $(patsubst %.c, %.o, $(patsubst %.s, %.o, $(SRCS)))
$(shell mkdir -p $(dir $(OBJS)))

CFLAGS = -m64 -Wall -Werror -std=gnu11 -Ikernel/include -ffreestanding -O0 -fno-stack-protector
CFLAGS = -m64 -Wall -Werror -std=gnu2x -Ikernel/include -ffreestanding -O0 -fno-stack-protector
ASFLAGS = -64

.PHONY: all run test clean format
Expand All @@ -27,15 +27,15 @@ kernel/kernel.elf: $(OBJS)
as $(ASFLAGS) -o $@ $<

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

test: serial.log
cat $<
ls
grep -q '\[OK\]' $< && echo "Test passed." || (echo "Test failed." && exit 1)

run: cis-os.iso
qemu-system-x86_64 -m 256 -cdrom $< -d guest_errors -serial file:serial.log --no-reboot -no-shutdown
qemu-system-x86_64 -vga vmware -m 256 -cdrom $< -d guest_errors -serial file:serial.log --no-reboot -no-shutdown

clean:
rm -rf isodir
Expand Down
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 clang-format
sudo apt install gcc build-essential grub2-common grub-pc xorriso qemu-system-x86 xorriso mtools clang-format cpio
```

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

insmod gfxterm
insmod vbe
insmod vga
set gfxmode=1280x800x32
menuentry "CIS-OS" {
multiboot /boot/kernel.elf
module /initrd.cpio
module /initrd.cpio initrd
boot
}
7 changes: 6 additions & 1 deletion kernel/arch/amd64/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
.set MULTIBOOT_MAGIC, 0x1BADB002
.set MULTIBOOT_FLAG_PAGE_ALIGN, 1 << 0
.set MULTIBOOT_FLAG_MEMORY_INFO, 1 << 1
.set MULTIBOOT_FLAGS, MULTIBOOT_FLAG_PAGE_ALIGN | MULTIBOOT_FLAG_MEMORY_INFO
.set MULTIBOOT_VIDEO_MODE, 1 << 2
.set MULTIBOOT_FLAGS, MULTIBOOT_FLAG_PAGE_ALIGN | MULTIBOOT_FLAG_MEMORY_INFO | MULTIBOOT_VIDEO_MODE
.set MULTIBOOT_CHECKSUM, -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)

.align 4
Expand All @@ -21,6 +22,10 @@ multiboot_header:
.long bss_start
.long end
.long _start
.long 0
.long 1280
.long 800
.long 32

.section .stack, "aw", @nobits
stack_bottom:
Expand Down
23 changes: 18 additions & 5 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ int multiboot_init(uint64_t *addr, uint32_t magic);

void kernel_main64(uint64_t *multiboot, uint32_t magic, void *esp, uint64_t base) {
serial_init( );
multiboot_init(multiboot, magic);
serial_write_byte('[');
serial_write_byte('O');
serial_write_byte('K');
serial_write_byte(']');
serial_write_byte(':');
serial_write_byte('D');
serial_write_byte('\n');
int status = multiboot_init(multiboot, magic);
serial_write_byte('\n');

if (status) {
serial_write_byte('[');
serial_write_byte('O');
serial_write_byte('K');
serial_write_byte(']');
} else {
serial_write_byte('[');
serial_write_byte('E');
serial_write_byte('R');
serial_write_byte('R');
serial_write_byte(']');
}
for (;;) {}
}
9 changes: 9 additions & 0 deletions kernel/multiboot.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <3rd/multiboot.h>
#include <khal.h>
#include <kstdint.h>

#define CHECK_FLAG(flags, bit) ((flags) & (1 << (bit)))
Expand All @@ -7,18 +8,21 @@
int multiboot_init(uint64_t *addr, uint32_t magic) {
multiboot_info_t *mbi;

serial_write_byte('1' + __COUNTER__);
/* Am I booted by a Multiboot-compliant boot loader? */
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
printf("Invalid magic number: 0x%x\n", (unsigned)magic);
return -1;
}

serial_write_byte('1' + __COUNTER__);
/* Set MBI to the address of the Multiboot information structure. */
mbi = (multiboot_info_t *)addr;

/* Print out the flags. */
printf("flags = 0x%x\n", (unsigned)mbi->flags);

serial_write_byte('1' + __COUNTER__);
/* Are mem_* valid? */
if (CHECK_FLAG(mbi->flags, 0))
printf("mem_lower = %uKB, mem_upper = %uKB\n", (unsigned)mbi->mem_lower,
Expand All @@ -30,6 +34,7 @@ int multiboot_init(uint64_t *addr, uint32_t magic) {
/* Is the command line passed? */
if (CHECK_FLAG(mbi->flags, 2)) printf("cmdline = %s\n", (char *)mbi->cmdline);

serial_write_byte('1' + __COUNTER__);
/* Are mods_* valid? */
if (CHECK_FLAG(mbi->flags, 3)) {
multiboot_module_t *mod = (multiboot_module_t *)(uint64_t)mbi->mods_addr;
Expand All @@ -45,6 +50,7 @@ int multiboot_init(uint64_t *addr, uint32_t magic) {
return -1;
}

serial_write_byte('1' + __COUNTER__);
/* Is the symbol table of a.out valid? */
if (CHECK_FLAG(mbi->flags, 4)) {
multiboot_aout_symbol_table_t *multiboot_aout_sym __attribute__((unused)) =
Expand All @@ -67,6 +73,7 @@ int multiboot_init(uint64_t *addr, uint32_t magic) {
(unsigned)multiboot_elf_sec->addr, (unsigned)multiboot_elf_sec->shndx);
}

serial_write_byte('1' + __COUNTER__);
/* Are mmap_* valid? */
if (CHECK_FLAG(mbi->flags, 6)) {
multiboot_memory_map_t *mmap;
Expand All @@ -84,6 +91,7 @@ int multiboot_init(uint64_t *addr, uint32_t magic) {
(unsigned)(mmap->len & 0xffffffff), (unsigned)mmap->type);
}

serial_write_byte('1' + __COUNTER__);
/* Draw diagonal blue line. */
if (CHECK_FLAG(mbi->flags, 12)) {
multiboot_uint32_t color;
Expand Down Expand Up @@ -143,5 +151,6 @@ int multiboot_init(uint64_t *addr, uint32_t magic) {
}
}
}
serial_write_byte('1' + __COUNTER__);
return 1;
}
Loading