summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Gavrilov <rebovas@yahoo.com>2023-08-20 20:13:59 +0700
committerAlexey Gavrilov <rebovas@yahoo.com>2023-08-20 20:13:59 +0700
commit47844a0db257264e7f8c5c38e07745601c884a7e (patch)
tree60642b3e3876c3d1e48bc19ee2026a5ec39e4e65
parentb82ccebd3a0cce28177b5fac046139e2de7737fa (diff)
Edit README, Makefile, ld conf
-rw-r--r--README.md3
-rw-r--r--kernel/boot.s6
-rw-r--r--kernel/kernel.c22
-rw-r--r--kernel/linker.ld6
-rw-r--r--makefile13
5 files changed, 38 insertions, 12 deletions
diff --git a/README.md b/README.md
index 3d6f699..b7d31cf 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ sudo apt -y install build-essential binutils nasm xorriso grub-common qemu-syste
```sh
# Build and create iso image
make install
+# Run emulator
make run
```
@@ -31,6 +32,7 @@ make run
- [Multiboot specification][6]
- [GCC compiler documentation][7]
- [Using NASM in a Hello World kernel][8]
+- [Addres of video memory][9]
[1]:https://habr.com/ru/companies/neobit/articles/173263/
[2]:https://www.gnu.org/software/grub/manual/grub/grub.pdf
@@ -40,3 +42,4 @@ make run
[6]:https://www.gnu.org/software/grub/manual/multiboot/multiboot.pdf
[7]:https://gcc.gnu.org/onlinedocs/gcc.pdf
[8]:https://wiki.osdev.org/Bare_Bones_with_NASM
+[9]:https://stackoverflow.com/questions/17367618/address-of-video-memory
diff --git a/kernel/boot.s b/kernel/boot.s
index 2fd1c55..987cb48 100644
--- a/kernel/boot.s
+++ b/kernel/boot.s
@@ -1,6 +1,4 @@
-MBALIGN equ 1 << 0
-MEMINFO equ 1 << 1
-MBFLAGS equ MBALIGN | MEMINFO
+MBFLAGS equ 0
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + MBFLAGS)
@@ -17,10 +15,10 @@ resb 16384
stack_top:
section .text
+extern main
global _start:function (_start.end - _start)
_start:
mov esp, stack_top
- extern main
call main
cli
.hang: hlt
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 1d734c9..9a901b1 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,4 +1,22 @@
-int main()
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../arch/x86/io/GlobalObj.h"
+#include "../arch/x86/inc/TypeConverter.h"
+
+void main()
{
- return 0;
+ VGADisplay d;
+ IntConverter conv;
+
+ unsigned int i = 124;
+
+ d << conv.intToChar(i);
+ d << "Hello, world!\tHello, world!";
+ for(int i = 0; i < 10; i++)d << "\tHello!";
};
+
+#ifdef __cplusplus
+};
+#endif
diff --git a/kernel/linker.ld b/kernel/linker.ld
index e490e6a..d5ee742 100644
--- a/kernel/linker.ld
+++ b/kernel/linker.ld
@@ -4,10 +4,14 @@ SECTIONS
{
. = 1M;
+ .multiboot :
+ {
+ *(.multiboot)
+ }
.text BLOCK(4K) : ALIGN(4K)
{
- *.(.multiboot)
*(.text)
+ *(.eh_frame)
}
.rodata BLOCK(4K) : ALIGN(4k)
diff --git a/makefile b/makefile
index 1e07743..67ef81b 100644
--- a/makefile
+++ b/makefile
@@ -1,10 +1,10 @@
-CC = gcc# compiler
+CC = i686-elf-g++# compiler
LD = ld# linker
ASM = nasm# assembler
-# what is the flag -O2
-CFLAGS = -c -Wall -ffreestanding -nostdinc -nostdlib -lgcc# c compiler flags
+# test -O2 flag
+CFLAGS = -c -m32 -Wall -ffreestanding -nostdinc -nostdlib -lgcc# c compiler flags
# flag elf32 allow decrease object file size
-AFLAGS = -f elf64# asm compiler flags
+AFLAGS = -f elf32# asm compiler flags
BDIR = build# build directory
.PHONY: install
@@ -18,9 +18,12 @@ build:
mkdir $(BDIR)
@echo "Compile source files..."
$(CC) $(CFLAGS) -o ./$(BDIR)/kernel.o ./kernel/kernel.c
+ $(CC) $(CFLAGS) -o ./$(BDIR)/VGADisplay.o ./arch/x86/io/VGADisplay.cpp
+ $(CC) $(CFLAGS) -o ./$(BDIR)/TypeConverter.o ./arch/x86/inc/TypeConverter.cpp
+ $(CC) $(CFLAGS) -o ./$(BDIR)/GlobalObj.o ./arch/x86/io/GlobalObj.cpp
$(ASM) $(AFLAGS) -o ./$(BDIR)/boot.o ./kernel/boot.s
@echo "Link object files..."
- $(LD) -m elf_x86_64 -o ./$(BDIR)/kernel.bin -T ./kernel/linker.ld ./$(BDIR)/*.o
+ $(LD) -m elf_i386 -o ./$(BDIR)/kernel.bin -T ./kernel/linker.ld ./$(BDIR)/*.o
@echo "Project was built"
clean: