Renaming, folder layout change

This commit is contained in:
Furkan Mudanyali 2022-07-20 02:23:23 +03:00
parent 5b2b4d05f1
commit cbc66a5cdb
20 changed files with 96 additions and 90 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.iso
isodir
sysroot

View File

@ -29,7 +29,8 @@ LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
KERNEL_OBJS=\
$(KERNEL_ARCH_OBJS) \
kernel/kernel.o \
rockos/kernel.o \
rockos/paging.o \
OBJS=\
$(ARCHDIR)/boot/crti.o \

View File

@ -31,6 +31,7 @@ _start:
call idt_init # initialize the IDT
call PIC_remap
sti
call paging_init
call kernel_main # transfer control to main kernel
# Hang if kernel_main unexpectedly returns
1: hlt

View File

@ -1,4 +1,4 @@
#include <kernel/gdt.h>
#include <rockos/gdt.h>
#include <stdio.h>
#include <stdint.h>

View File

@ -1,8 +1,16 @@
#include <kernel/idt.h>
#include <rockos/idt.h>
#include <rockos/pic.h>
#include <stdio.h>
static unsigned char key;
__attribute__((interrupt)) void keyboard_handler(void* frame) {
return;
key = inb(0x60);
outb(0x20, 0x20);
}
unsigned char readkey() {
return key;
}
__attribute__((interrupt)) void int_handler(void* frame, unsigned int number) {

View File

@ -1,13 +1,8 @@
#include <kernel/pic.h>
#include <rockos/pic.h>
#include <stdio.h>
void PIC_remap() {
printf("Beginning PIC initialization.\n");
unsigned char a1, a2;
a1 = inb(PIC1_DATA); // save masks
a2 = inb(PIC2_DATA);
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // Start init sequence in cascade mode
io_wait();
@ -32,5 +27,4 @@ void PIC_remap() {
outb(PIC2_DATA, 0xFF);
outb(PIC1_DATA, 0xFD); // Keyboard IRQ
//outb(PIC2_DATA, 0xFF);
}

View File

@ -7,6 +7,5 @@ KERNEL_ARCH_OBJS=\
$(ARCHDIR)/boot/boot.o \
$(ARCHDIR)/vga/tty.o \
$(ARCHDIR)/boot/gdt.o \
$(ARCHDIR)/paging/paging.o \
$(ARCHDIR)/boot/idt.o \
$(ARCHDIR)/boot/pic.o

View File

@ -1,22 +0,0 @@
.text
.globl load_page_dir
load_page_dir:
push %ebp
mov %esp, %ebp
mov 8(%esp), %eax
mov %eax, %cr3
mov %ebp, %esp
pop %ebp
ret
.text
.globl enable_paging
enable_paging:
push %ebp
mov %esp, %ebp
mov %cr0, %eax
or $0x80000000, %eax
mov %eax, %cr0
mov %ebp, %esp
pop %ebp
ret

View File

@ -3,7 +3,7 @@
#include <stdint.h>
#include <string.h>
#include <kernel/tty.h>
#include <rockos/tty.h>
#include "vga.h"

View File

@ -1,7 +0,0 @@
#ifndef _KERNEL_PAGING_H
#define _KERNEL_PAGING_H
extern void load_page_dir(uint32_t*);
extern void enable_paging();
#endif

View File

@ -1,5 +1,5 @@
#ifndef _KERNEL_GDT_H
#define _KERNEL_GDT_H
#ifndef _ROCKOS_GDT_H
#define _ROCKOS_GDT_H
#include <stdint.h>

View File

@ -0,0 +1,16 @@
#ifndef _ROCKOS_HAL_H
#define _ROCKOS_HAL_H
#include <stdint.h>
static inline void outb(uint16_t port, uint8_t val) {
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
#endif

View File

@ -1,5 +1,5 @@
#ifndef _KERNEL_IDT_H
#define _KERNEL_IDT_H
#ifndef _ROCKOS_IDT_H
#define _ROCKOS_IDT_H
#include <stdint.h>
@ -44,4 +44,6 @@ static char* err_msg[] = {
"#CP Control Protection Exception!"
};
unsigned char readkey();
#endif

View File

View File

@ -0,0 +1,7 @@
#ifndef _ROCKOS_PAGING_H
#define _ROCKOS_PAGING_H
#define PAGE_ENTRIES 1024
#define PAGE_SIZE 4 * PAGE_ENTRIES
#endif

View File

@ -1,7 +1,8 @@
#ifndef _KERNEL_PIC_H
#define _KERNEL_PIC_H
#ifndef _ROCKOS_PIC_H
#define _ROCKOS_PIC_H
#include <stdint.h>
#include <rockos/hal.h>
#define PIC1 0x20
#define PIC1_COMMAND 0x20
@ -27,16 +28,6 @@
#define ICW4_BUF_MASTER 0x0C // Buffered mode/master
#define ICW4_SFNM 0x10 // Special fully nested (not)
static inline void outb(uint16_t port, uint8_t val) {
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline void io_wait() {
outb(0x80, 0);
}

View File

@ -1,5 +1,5 @@
#ifndef _KERNEL_TTY_H
#define _KERNEL_TTY_H
#ifndef _ROCKOS_TTY_H
#define _ROCKOS_TTY_H
#include <stddef.h>

24
kernel/rockos/kernel.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <rockos/tty.h>
#include <rockos/gdt.h>
void kernel_main(void) {
printf("Hello, kernel World!\n");
printf("String test: %s\n", "HELLOOOOO");
printf("Float test: %.10f\n", 0.123456789);
printf("Int test: %d\n", 747474);
printf("Hex test: 0x%x\n", 0xDEADBEEF);
printf("And now for 0.1 + 0.2...... which is: %.17f\n", 0.1 + 0.2);
unsigned char oldkey;
unsigned char key = readkey();
for(;;){
oldkey = key;
key = readkey();
if (key != oldkey)
putchar(key);
}
asm("cli; hlt");
}

View File

@ -1,12 +1,22 @@
#include <stdio.h>
#include <rockos/paging.h>
#include <stdint.h>
#include <kernel/tty.h>
#include <kernel/gdt.h>
#include <kernel/paging.h>
#include <kernel/pic.h>
void load_page_dir(uint32_t page_dir) {
asm volatile (
"mov %%eax, %%cr3"
:
: "a"(page_dir)
: "memory"
);
}
#define PAGE_ENTRIES 1024
#define PAGE_SIZE 4 * PAGE_ENTRIES
void enable_paging() {
asm volatile (
"mov %cr0, %eax\n"
"or $0x80000000, %eax\n"
"mov %eax, %cr0"
);
}
void paging_init() {
uint32_t page_dir[PAGE_ENTRIES] __attribute__((aligned(PAGE_SIZE)));
@ -28,25 +38,4 @@ void paging_init() {
load_page_dir(page_dir);
enable_paging();
}
void kernel_main(void) {
paging_init();
printf("Hello, kernel World!\n");
printf("String test: %s\n", "HELLOOOOO");
printf("Float test: %.10f\n", 0.123456789);
printf("Int test: %d\n", 747474);
printf("Hex test: 0x%x\n", 0xDEADBEEF);
printf("And now for 0.1 + 0.2...... which is: %.17f\n", 0.1 + 0.2);
unsigned char c, cold;
for(;;){
cold = c;
c = inb(0x60);
if (cold != c)
putchar(c);
outb(0x20, 0x20);
}
asm("cli; hlt");
}
}

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#if defined(__is_libk)
#include <kernel/tty.h>
#include <rockos/tty.h>
#endif
int putchar(int ic) {