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
3 changes: 3 additions & 0 deletions .gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set osabi none
target remote 127.0.0.1:1234
symbol-file ./src/kitty.elf
22 changes: 16 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o}
CFLAGS = -ffreestanding -fno-stack-protector -z execstack -no-pie -fno-pic

ifeq ($(OS),Windows_NT)
host_os = windows
SHELL = cmd
CC = x86_64-elf-gcc
GDB = x86_64-elf-gdb
LD = x86_64-elf-ld
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),MSYS_NT-10.0-22631)
$(info MSYS2 detected)
host_os = linux
CC = gcc
GDB = gdb
LD = ld
else
$(info Windows detected)
host_os = windows
SHELL = cmd
CC = x86_64-elf-gcc
GDB = x86_64-elf-gdb
LD = x86_64-elf-ld
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
Expand Down Expand Up @@ -84,7 +94,7 @@ endif

debug: os-image.bin kitty.elf # TODO needs work, change it so that a variable is added for break points
#ifeq ($(host_os),windows)
qemu-system-x86_64 -s -S -fda os-image.bin
qemu-system-x86_64 -s -S -d int -fda os-image.bin
#else ifeq ($(host_os),linux)
# qemu-system-x86_64 -s -S -fda os-image.bin &
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* Other defined variables in this file are for use with processor-specific compilation.
*
* All other CPU preprocessor definitions (for use in cpu cpu code) should be put in its corresponding header file.
* All other CPU preprocessor definitions (for use in cpu code) should be put in its corresponding header file.
*/

#if CPU == 1 // x86_64 Processors
Expand Down
47 changes: 47 additions & 0 deletions src/cpu/x86_64/gdt.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; Access bits
PRESENT equ 1 << 7
USER equ 3 << 5
NOT_SYS equ 1 << 4
EXEC equ 1 << 3
DC equ 1 << 2
RW equ 1 << 1
ACCESSED equ 1 << 0

; Flags bits
GRAN_4K equ 1 << 7
SZ_32 equ 1 << 6
LONG_MODE equ 1 << 5
global GDT
GDT: ; 64 bit GDT, taken from https://wiki.osdev.org/Setting_Up_Long_Mode ; CC0 Licensing (Public Domain)
.Null: equ $ - GDT
dq 0
.Code: equ $ - GDT
dd 0xFFFF ; Limit & Base (low, bits 0-15)
db 0 ; Base (mid, bits 16-23)
db PRESENT | NOT_SYS | EXEC | RW ; Access
db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19)
db 0 ; Base (high, bits 24-31)
.Data: equ $ - GDT
dd 0xFFFF ; Limit & Base (low, bits 0-15)
db 0 ; Base (mid, bits 16-23)
db PRESENT | NOT_SYS | RW ; Access
db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19)
db 0 ; Base (high, bits 24-31)
.UserCode: equ $ - GDT
dd 0xFFFF ; Limit & Base (low, bits 0-15)
db 0 ; Base (mid, bits 16-23)
db PRESENT | USER | NOT_SYS | EXEC | RW ; 0xFA ; Access
db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19)
db 0 ; Base (high, bits 24-31)
.UserData: equ $ - GDT
dd 0xFFFF ; Limit & Base (low, bits 0-15)
db 0 ; Base (mid, bits 16-23)
db PRESENT | USER | NOT_SYS | RW ;0xF2 ; ; Access
db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19)
db 0 ; Base (high, bits 24-31)
.TSS: equ $ - GDT
dq 0x0000000000000000
dq 0x0000000000000000
.Pointer:
dw $ - GDT - 1
dq GDT
26 changes: 26 additions & 0 deletions src/cpu/x86_64/gdt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by AIDAN on 9/26/2024.
//

#ifndef KITTY_GDT_H
#define KITTY_GDT_H

#include "stdint.h"

struct global_descriptor_table {
uint64_t null;
uint64_t code;
uint64_t data;
uint64_t user_code;
uint64_t user_data;
uint32_t tss_0;
uint32_t tss_1;
uint32_t tss_2;
uint32_t tss_3;
uint16_t size;
uint64_t offset;
}__attribute__ ((packed));

extern struct global_descriptor_table GDT;

#endif //KITTY_GDT_H
Loading
Loading