forked from PoliEcho-holding-org/kern
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
|
||||
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
|
||||
BUILD = ./build
|
||||
@@ -43,18 +44,16 @@ bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
||||
@cat $(BUILD)/stage1.bin $(BUILD)/stage2.bin > $(BUILD)/boot.bin
|
||||
|
||||
# Kernel: This target is responsible for creating kernel.bin
|
||||
kernel: $(SRC)/kernel.c $(SRC)/entry.asm
|
||||
@echo "Assembling $(SRC)/entry.asm..."
|
||||
@$(AS) -felf32 -o $(BUILD)/entry.o $(SRC)/entry.asm
|
||||
kernel: $(SRC)/kernel.c
|
||||
@echo "Compiling $(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
|
||||
|
||||
$(C_FILES):
|
||||
@echo "Compiling $(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
|
||||
|
||||
$(FONTS):
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#define WRITE_COMMAND 0x30
|
||||
#define CACHE_FLUSH 0xE7
|
||||
|
||||
extern uint8_t driveNum;
|
||||
|
||||
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 + 2, sectorCount); // Sector count register
|
||||
|
||||
+5
-5
@@ -6,27 +6,27 @@
|
||||
// Port functions
|
||||
uint8_t inb(uint16_t port) {
|
||||
uint8_t result;
|
||||
asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
|
||||
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
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 result;
|
||||
asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
|
||||
__asm__ volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
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() {
|
||||
// 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
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__ ((section("entry")))
|
||||
void main() {
|
||||
char msg[8] = { 'H','e','l','l','o','!','\n',0 };
|
||||
print(msg);
|
||||
print("Hello, World!\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
ENTRY("main");
|
||||
SECTIONS {
|
||||
.text : {
|
||||
*(entry);
|
||||
*(.text*);
|
||||
}
|
||||
.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
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <memory/virtual.h>
|
||||
#include <memory/addresses.h>
|
||||
#include <memory/malloc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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 printPhysicalMemmap();
|
||||
|
||||
__attribute__ ((section("entry")))
|
||||
void main() {
|
||||
// Interrupt setup
|
||||
setupIdt();
|
||||
@@ -260,6 +262,10 @@ void main() {
|
||||
} else {
|
||||
print("[ FAIL ]\n");
|
||||
}
|
||||
print("Malloc Test ........ ");
|
||||
void* buffer = malloc(100);
|
||||
free(buffer);
|
||||
print("[ DONE ]\n");
|
||||
|
||||
print("\nTests Finished!\n");
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
SECTIONS {
|
||||
.text 0x50000 : {
|
||||
*(entry);
|
||||
*(.text*);
|
||||
}
|
||||
.data : {
|
||||
|
||||
@@ -324,9 +324,6 @@ protected_start:
|
||||
rep movsd
|
||||
|
||||
; Perform The far jump
|
||||
mov al, [driveNum]
|
||||
push ax
|
||||
|
||||
jmp CODE_SEG:KERNEL_LOC
|
||||
|
||||
;; Data
|
||||
|
||||
Reference in New Issue
Block a user