This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from lvntky/conflict/master-v2.1-conflict
Conflict/master v2.1 conflict
- Loading branch information
Showing
38 changed files
with
413 additions
and
517 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,50 @@ | ||
# Toolchain prefix | ||
CC_PREFIX = i686-elf- | ||
NASM_PREFIX = nasm | ||
FILES = ./build/kernel.asm.o ./build/kernel.o ./build/tty.o ./build/stdio.o ./build/string.o ./build/idt.asm.o ./build/idt.o ./build/cpu_info.o ./build/io_port.o | ||
INCLUDES = -I./src | ||
FLAGS = -g -ffreestanding -falign-jumps -falign-functions -falign-labels -falign-loops -fstrength-reduce -fomit-frame-pointer -finline-functions -Wno-unused-function -fno-builtin -Werror -Wno-unused-label -Wno-cpp -Wno-unused-parameter -nostdlib -nostartfiles -nodefaultlibs -Wall -O0 -Iinc | ||
|
||
# Compiler and linker options | ||
CC = $(CC_PREFIX)gcc | ||
LD = $(CC_PREFIX)ld | ||
GAS = $(CC_PREFIX)as | ||
CFLAGS = -std=c11 -g -ffreestanding -O2 -Wall -Wextra -I./kernel/include | ||
LDFLAGS = -nostdlib -T linker.ld | ||
all: ./bin/boot.bin ./bin/kernel.bin | ||
rm -rf ./bin/artilleryos.bin | ||
dd if=./bin/boot.bin >> ./bin/artilleryos.bin | ||
dd if=./bin/kernel.bin >> ./bin/artilleryos.bin | ||
dd if=/dev/zero bs=512 count=100 >> ./bin/artilleryos.bin | ||
|
||
# NASM assembler options | ||
NASM = $(NASM_PREFIX) | ||
NASMFLAGS = -f elf32 | ||
./bin/kernel.bin: $(FILES) | ||
i686-elf-ld -g -relocatable $(FILES) -o ./build/kernel_bootloader_combined.o | ||
i686-elf-gcc $(FLAGS) -T ./kernel/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib ./build/kernel_bootloader_combined.o | ||
|
||
# Source files | ||
KERNEL_SRCS = $(wildcard kernel/src/*.c) | ||
LIBC_SRCS = $(wildcard kernel/libc/*.c) | ||
SRCS = $(KERNEL_SRCS) $(LIBC_SRCS) | ||
./bin/boot.bin: ./boot/boot.asm | ||
nasm -f bin ./boot/boot.asm -o ./bin/boot.bin | ||
|
||
OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(SRCS:.c=.o))) | ||
OBJS += $(OBJ_DIR)/interruptstubs.o # Include interruptstubs.asm | ||
LOADER_ASM = bootloader/loader.asm | ||
LOADER_OBJ = $(OBJ_DIR)/loader.o | ||
./build/kernel.asm.o: ./boot/kernel_entry.asm | ||
nasm -f elf -g ./boot/kernel_entry.asm -o ./build/kernel.asm.o | ||
|
||
# Output directories | ||
OBJ_DIR = build | ||
BIN_DIR = bin | ||
ISO_DIR = isodir | ||
./build/kernel.o: ./kernel/src/kernel.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/src/kernel.c -o ./build/kernel.o | ||
|
||
# Target executables | ||
KERNEL = $(BIN_DIR)/artilleryos.bin | ||
ISO = $(BIN_DIR)/artilleryos.iso | ||
./build/tty.o: ./kernel/src/tty.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/src/tty.c -o ./build/tty.o | ||
|
||
.PHONY: all clean | ||
./build/stdio.o: ./kernel/libc/stdio.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/libc/stdio.c -o ./build/stdio.o | ||
|
||
all: $(ISO) | ||
./build/string.o: ./kernel/libc/string.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/libc/string.c -o ./build/string.o | ||
|
||
$(KERNEL): $(OBJS) $(LOADER_OBJ) | ||
$(LD) $(LDFLAGS) -o $@ $^ | ||
./build/idt.asm.o: ./kernel/idt/idt.asm | ||
nasm -f elf -g ./kernel/idt/idt.asm -o ./build/idt.asm.o | ||
|
||
$(OBJ_DIR)/%.o: kernel/src/%.c | $(OBJ_DIR) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
./build/idt.o: ./kernel/idt/idt.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/idt/idt.c -o ./build/idt.o | ||
|
||
$(OBJ_DIR)/%.o: kernel/libc/%.c | $(OBJ_DIR) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
./build/cpu_info.o: ./kernel/src/cpu_info.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/src/cpu_info.c -o ./build/cpu_info.o | ||
|
||
$(OBJ_DIR)/%.o: kernel/arch-86_64/interruptstubs.asm | $(OBJ_DIR) | ||
$(NASM) $(NASMFLAGS) $< -o $@ | ||
|
||
$(LOADER_OBJ): $(LOADER_ASM) | $(OBJ_DIR) | ||
$(NASM) $(NASMFLAGS) $< -o $@ | ||
|
||
$(ISO): $(KERNEL) | ||
mkdir -p $(ISO_DIR)/boot/grub | ||
cp $< $(ISO_DIR)/boot/artilleryos.bin | ||
cp ./boot/grub.cfg $(ISO_DIR)/boot/grub | ||
grub-mkrescue -o $@ $(ISO_DIR) | ||
|
||
$(OBJ_DIR): | ||
mkdir -p $(OBJ_DIR) | ||
./build/io_port.o: ./kernel/src/io_port.c | ||
i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./kernel/src/io_port.c -o ./build/io_port.o | ||
|
||
clean: | ||
rm -rf $(OBJ_DIR)/* $(BIN_DIR)/* $(ISO) | ||
rm -rf ./bin/boot.bin | ||
rm -rf ./bin/kernel.bin | ||
rm -rf ./bin/artilleryos.bin | ||
rm -rf ${FILES} | ||
rm -rf ./build/kernel_bootloader_combined.o |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
ORG 0x7c00 | ||
BITS 16 | ||
|
||
CODE_SEG equ gdt_code - gdt_start | ||
DATA_SEG equ gdt_data - gdt_start | ||
|
||
_start: | ||
jmp short start | ||
nop | ||
|
||
times 33 db 0 | ||
start: | ||
jmp 0:step2 | ||
|
||
step2: | ||
cli ; Clear Interrupts | ||
mov ax, 0x00 | ||
mov ds, ax | ||
mov es, ax | ||
mov ss, ax | ||
mov sp, 0x7c00 | ||
sti ; Enables Interrupts | ||
|
||
.load_protected: | ||
cli | ||
lgdt[gdt_descriptor] | ||
mov eax, cr0 | ||
or eax, 0x1 | ||
mov cr0, eax | ||
jmp CODE_SEG:load32 | ||
; GDT | ||
gdt_start: | ||
gdt_null: | ||
dd 0x0 | ||
dd 0x0 | ||
|
||
; offset 0x8 | ||
gdt_code: ; CS SHOULD POINT TO THIS | ||
dw 0xffff ; Segment limit first 0-15 bits | ||
dw 0 ; Base first 0-15 bits | ||
db 0 ; Base 16-23 bits | ||
db 0x9a ; Access byte | ||
db 11001111b ; High 4 bit flags and the low 4 bit flags | ||
db 0 ; Base 24-31 bits | ||
|
||
; offset 0x10 | ||
gdt_data: ; DS, SS, ES, FS, GS | ||
dw 0xffff ; Segment limit first 0-15 bits | ||
dw 0 ; Base first 0-15 bits | ||
db 0 ; Base 16-23 bits | ||
db 0x92 ; Access byte | ||
db 11001111b ; High 4 bit flags and the low 4 bit flags | ||
db 0 ; Base 24-31 bits | ||
|
||
gdt_end: | ||
|
||
gdt_descriptor: | ||
dw gdt_end - gdt_start-1 | ||
dd gdt_start | ||
[BITS 32] | ||
load32: | ||
mov eax, 1 | ||
mov ecx, 100 | ||
mov edi, 0x0100000 | ||
call ata_lba_read | ||
jmp CODE_SEG:0x0100000 | ||
|
||
ata_lba_read: | ||
mov ebx, eax, ; Backup the LBA | ||
; Send the highest 8 bits of the lba to hard disk controller | ||
shr eax, 24 | ||
or eax, 0xE0 ; Select the master drive | ||
mov dx, 0x1F6 | ||
out dx, al | ||
; Finished sending the highest 8 bits of the lba | ||
|
||
; Send the total sectors to read | ||
mov eax, ecx | ||
mov dx, 0x1F2 | ||
out dx, al | ||
; Finished sending the total sectors to read | ||
|
||
; Send more bits of the LBA | ||
mov eax, ebx ; Restore the backup LBA | ||
mov dx, 0x1F3 | ||
out dx, al | ||
; Finished sending more bits of the LBA | ||
|
||
; Send more bits of the LBA | ||
mov dx, 0x1F4 | ||
mov eax, ebx ; Restore the backup LBA | ||
shr eax, 8 | ||
out dx, al | ||
; Finished sending more bits of the LBA | ||
|
||
; Send upper 16 bits of the LBA | ||
mov dx, 0x1F5 | ||
mov eax, ebx ; Restore the backup LBA | ||
shr eax, 16 | ||
out dx, al | ||
; Finished sending upper 16 bits of the LBA | ||
|
||
mov dx, 0x1f7 | ||
mov al, 0x20 | ||
out dx, al | ||
|
||
; Read all sectors into memory | ||
.next_sector: | ||
push ecx | ||
|
||
; Checking if we need to read | ||
.try_again: | ||
mov dx, 0x1f7 | ||
in al, dx | ||
test al, 8 | ||
jz .try_again | ||
|
||
; We need to read 256 words at a time | ||
mov ecx, 256 | ||
mov dx, 0x1F0 | ||
rep insw | ||
pop ecx | ||
loop .next_sector | ||
; End of reading sectors into memory | ||
ret | ||
|
||
times 510-($ - $$) db 0 | ||
dw 0xAA55 |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[BITS 32] | ||
|
||
global _start | ||
extern kernel_main | ||
|
||
CODE_SEG equ 0x08 | ||
DATA_SEG equ 0x10 | ||
|
||
_start: | ||
mov ax, DATA_SEG | ||
mov ds, ax | ||
mov es, ax | ||
mov fs, ax | ||
mov gs, ax | ||
mov ss, ax | ||
mov ebp, 0x00200000 | ||
mov esp, ebp | ||
|
||
; Enable the A20 line | ||
in al, 0x92 | ||
or al, 2 | ||
out 0x92, al | ||
|
||
call kernel_main | ||
|
||
jmp $ | ||
|
||
times 512-($ - $$) db 0 |
Oops, something went wrong.