mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Slighly changed everything :)
- Makefile changes - Linker script updates - Made it comply with C17 - Removed entry.asm (finally)
This commit is contained in:
@@ -3,7 +3,8 @@ CC = i386-elf-gcc
|
|||||||
LD = i386-elf-ld
|
LD = i386-elf-ld
|
||||||
AS = nasm
|
AS = nasm
|
||||||
|
|
||||||
CFLAGS = -ffreestanding -fno-builtin -fno-stack-protector -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall -Iinclude/c
|
CFLAGS = -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
||||||
|
-Os -nostdinc -mgeneral-regs-only -m32 -march=i386 -Wall -Iinclude/c
|
||||||
|
|
||||||
SRC = ./src
|
SRC = ./src
|
||||||
BUILD = ./build
|
BUILD = ./build
|
||||||
@@ -43,18 +44,16 @@ bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
|||||||
@cat $(BUILD)/stage1.bin $(BUILD)/stage2.bin > $(BUILD)/boot.bin
|
@cat $(BUILD)/stage1.bin $(BUILD)/stage2.bin > $(BUILD)/boot.bin
|
||||||
|
|
||||||
# Kernel: This target is responsible for creating kernel.bin
|
# Kernel: This target is responsible for creating kernel.bin
|
||||||
kernel: $(SRC)/kernel.c $(SRC)/entry.asm
|
kernel: $(SRC)/kernel.c
|
||||||
@echo "Assembling $(SRC)/entry.asm..."
|
|
||||||
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
|
|
||||||
@echo "Compiling $(SRC)/kernel.c..."
|
@echo "Compiling $(SRC)/kernel.c..."
|
||||||
@$(CC) $(CFLAGS) -Iinclude -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
|
@$(CC) $(CFLAGS) -Iinclude -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
|
||||||
@$(LD) -T$(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o
|
@$(LD) -T$(SRC)/kernel.ld -z notext --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/kernel.o
|
||||||
@rm $(BUILD)/*.o
|
@rm $(BUILD)/*.o
|
||||||
|
|
||||||
$(C_FILES):
|
$(C_FILES):
|
||||||
@echo "Compiling $(SRC)/$@.c..."
|
@echo "Compiling $(SRC)/$@.c..."
|
||||||
@$(CC) $(CFLAGS) -o $(BUILD)/$@.o -c $(SRC)/$@.c
|
@$(CC) $(CFLAGS) -o $(BUILD)/$@.o -c $(SRC)/$@.c
|
||||||
@$(LD) -T$(SRC)/$@.ld --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o
|
@$(LD) -T$(SRC)/$@.ld -z notext --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o
|
||||||
@rm $(BUILD)/$@.o
|
@rm $(BUILD)/$@.o
|
||||||
|
|
||||||
$(FONTS):
|
$(FONTS):
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
#define WRITE_COMMAND 0x30
|
#define WRITE_COMMAND 0x30
|
||||||
#define CACHE_FLUSH 0xE7
|
#define CACHE_FLUSH 0xE7
|
||||||
|
|
||||||
extern uint8_t driveNum;
|
|
||||||
|
|
||||||
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst) {
|
void diskRead(uint32_t lbaAddress, uint8_t sectorCount, char* dst) {
|
||||||
outb(PIO_PORT + 6, ((lbaAddress >> 24) & 0x0f) | 0xe0); // 6 - Use LBA; 4 - Drive number; 3-0 - Highest lba address nibble
|
outb(PIO_PORT + 6, ((lbaAddress >> 24) & 0x0f) | 0xe0); // 6 - Use LBA; 4 - Drive number; 3-0 - Highest lba address nibble
|
||||||
outb(PIO_PORT + 2, sectorCount); // Sector count register
|
outb(PIO_PORT + 2, sectorCount); // Sector count register
|
||||||
|
|||||||
+5
-5
@@ -6,27 +6,27 @@
|
|||||||
// Port functions
|
// Port functions
|
||||||
uint8_t inb(uint16_t port) {
|
uint8_t inb(uint16_t port) {
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
|
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void outb(uint16_t port, uint8_t data) {
|
void outb(uint16_t port, uint8_t data) {
|
||||||
asm volatile("outb %0, %1" :: "a"(data), "Nd"(port));
|
__asm__ volatile("outb %0, %1" :: "a"(data), "Nd"(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t inw(uint16_t port) {
|
uint16_t inw(uint16_t port) {
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
|
__asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void outw(uint16_t port, uint16_t data) {
|
void outw(uint16_t port, uint16_t data) {
|
||||||
asm volatile("outw %0, %1" :: "a"(data), "Nd"(port));
|
__asm__ volatile("outw %0, %1" :: "a"(data), "Nd"(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioWait() {
|
void ioWait() {
|
||||||
// Waits ~1 I/O Cycle (Linux uses this so it should be good)
|
// Waits ~1 I/O Cycle (Linux uses this so it should be good)
|
||||||
asm volatile("outb %%al, $0x80" : : "a"(0));
|
__asm__ volatile("outb %%al, $0x80" : : "a"(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
__attribute__ ((section("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
char msg[8] = { 'H','e','l','l','o','!','\n',0 };
|
print("Hello, World!\n");
|
||||||
print(msg);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
ENTRY("main");
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
.text : {
|
.text : {
|
||||||
|
*(entry);
|
||||||
*(.text*);
|
*(.text*);
|
||||||
}
|
}
|
||||||
.data : {
|
.data : {
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
[bits 32]
|
|
||||||
[global _start]
|
|
||||||
[global driveNum]
|
|
||||||
|
|
||||||
[extern main]
|
|
||||||
|
|
||||||
;; Calls the main function in 'main.c'
|
|
||||||
_start:
|
|
||||||
pop ax
|
|
||||||
mov [driveNum], al
|
|
||||||
|
|
||||||
call main
|
|
||||||
|
|
||||||
; Exit QEMU
|
|
||||||
mov ax, 0x2000
|
|
||||||
mov dx, 0x0604
|
|
||||||
out dx, ax
|
|
||||||
|
|
||||||
jmp $ ;; If we used cli, hlt we wouldn't have interrupts :/
|
|
||||||
|
|
||||||
driveNum: db 0
|
|
||||||
|
|
||||||
+7
-1
@@ -17,6 +17,7 @@
|
|||||||
#include <memory/virtual.h>
|
#include <memory/virtual.h>
|
||||||
#include <memory/addresses.h>
|
#include <memory/addresses.h>
|
||||||
#include <memory/malloc.h>
|
#include <memory/malloc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define PROMPT "#> "
|
#define PROMPT "#> "
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ char* filetable = (char*)FILETABLE_LOC; // Pretty sure we don't have to care abo
|
|||||||
void printFiletable(char* ft);
|
void printFiletable(char* ft);
|
||||||
void printPhysicalMemmap();
|
void printPhysicalMemmap();
|
||||||
|
|
||||||
|
__attribute__ ((section("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
// Interrupt setup
|
// Interrupt setup
|
||||||
setupIdt();
|
setupIdt();
|
||||||
@@ -248,7 +250,7 @@ void main() {
|
|||||||
diskRead(0, 1, (char*)buf);
|
diskRead(0, 1, (char*)buf);
|
||||||
if (buf[510] == 0x55 && buf[511] == 0xaa) {
|
if (buf[510] == 0x55 && buf[511] == 0xaa) {
|
||||||
print("[ DONE ]\n");
|
print("[ DONE ]\n");
|
||||||
} else {
|
} else {
|
||||||
print("[ FAIL ]\n");
|
print("[ FAIL ]\n");
|
||||||
}
|
}
|
||||||
print("Write Test ......... ");
|
print("Write Test ......... ");
|
||||||
@@ -260,6 +262,10 @@ void main() {
|
|||||||
} else {
|
} else {
|
||||||
print("[ FAIL ]\n");
|
print("[ FAIL ]\n");
|
||||||
}
|
}
|
||||||
|
print("Malloc Test ........ ");
|
||||||
|
void* buffer = malloc(100);
|
||||||
|
free(buffer);
|
||||||
|
print("[ DONE ]\n");
|
||||||
|
|
||||||
print("\nTests Finished!\n");
|
print("\nTests Finished!\n");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
SECTIONS {
|
SECTIONS {
|
||||||
.text 0x50000 : {
|
.text 0x50000 : {
|
||||||
|
*(entry);
|
||||||
*(.text*);
|
*(.text*);
|
||||||
}
|
}
|
||||||
.data : {
|
.data : {
|
||||||
|
|||||||
@@ -324,9 +324,6 @@ protected_start:
|
|||||||
rep movsd
|
rep movsd
|
||||||
|
|
||||||
; Perform The far jump
|
; Perform The far jump
|
||||||
mov al, [driveNum]
|
|
||||||
push ax
|
|
||||||
|
|
||||||
jmp CODE_SEG:KERNEL_LOC
|
jmp CODE_SEG:KERNEL_LOC
|
||||||
|
|
||||||
;; Data
|
;; Data
|
||||||
|
|||||||
Reference in New Issue
Block a user