Compare commits

..

No commits in common. "723f064975de920d456a781c9bbf4181f31a8393" and "94422ecf81f3e1a0588640f6a33a1a3374c33983" have entirely different histories.

14 changed files with 51 additions and 272 deletions

View file

@ -6,93 +6,25 @@
.set CHECKSUM, -(MAGIC + FLAGS) # checksum to prove we're multiboot
# Declare header for multiboot
.section .multiboot.data, "aw"
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
# Reserve stack for initial thread
.section .bootstrap_stack, "aw", @nobits
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16K
stack_top:
# Preallocate pages for paging
.section .bss, "aw", @nobits
.align 4096
boot_page_directory:
.skip 4096
boot_page_table1:
.skip 4096
# May need additional page for kernel > 3 MiB
# Kernel entry
.section .multiboot.text, "a"
.section .text
.global _start
.type _start, @function
_start:
# Physical address of boot_page_table 1
movl $(boot_page_table1 - 0xC0000000), %edi
# Map address 0
movl $0, %esi
# Map first 1023 pages
movl $1023, %ecx
1:
# Only map the kernel
cmpl $_kernel_start, %esi
jl 2f
cmpl $(_kernel_end - 0xC0000000), %esi
jge 3f
# Map physical address as "present, writable"
# TODO: map .text and .rodata as non-writable
movl %esi, %edx
orl $0x003, %edx
movl %edx, (%edi)
2:
# Size of page is 4KiB
addl $4096, %esi
# Size of entries in boot_page_table1 is 4 bytes
addl $4, %edi
# Loop to next if not done
loop 1b
3:
# Map VGA memory to 0xC03FF000 as "present, writable"
movl $(0x000B8000 | 0x003), boot_page_table1 - 0xC0000000 + 1023 * 4
# Map page table to 0x0 and 0xC0000000
movl $(boot_page_table1 - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 0
movl $(boot_page_table1 - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 768 * 4
# Set cr3 to address of boot page directory
movl $(boot_page_directory - 0xC0000000), %ecx
movl %ecx, %cr3
# Enable paging and write-protect
movl %cr0, %ecx
orl $0x80010000, %ecx
movl %ecx, %cr0
# Jump to higher half
lea 4f, %ecx
jmp *%ecx
.section .text
4:
# Unmap identity mapping
movl $0, boot_page_directory + 0
# Reload cr3 to force TLB flush
movl %cr3, %ecx
movl %ecx, %cr3
# Set up stack
mov $stack_top, %esp
movl $stack_top, %esp
# Call global constructors
call _init
@ -104,3 +36,4 @@ _start:
cli
1: hlt
jmp 1b
.size _start, . - _start

View file

@ -3,7 +3,6 @@
#include <string.h>
#include <sys/io.h>
#include "gdt.h"
#include "ps2_kbd.h"
int tss[16][2];
@ -43,84 +42,11 @@ void setup_gdt(void) {
extern void enter_pmode(void);
int initialize_ps2_kbd() {
/* Should really make sure PS/2 controller exists here: */
/* Disable devices */
outb(0xAD, 0x64);
outb(0xA7, 0xAD);
/* Flush output buffer */
get_ps2_inbyte();
/* Set config byte */
outb(0x20, 0x64);
unsigned char config_byte = get_ps2_inbyte();
int is_dual_ch = (config_byte & 020) != 0 ? 1 : 0;
config_byte &= 0274;
outb(0x60, 0x64);
outb(config_byte, 0x60);
/* Quick self-test */
outb(0xAA, 0x64);
unsigned char test_response = get_ps2_inbyte();
if(test_response != 0x55) {
printf("error: PS/2 self-test failed\n");
return 1;
}
outb(0x60, 0x64);
outb(config_byte, 0x60);
/* Double check dual channel stuff */
if(is_dual_ch) {
outb(0xA8, 0x64);
outb(0x20, 0x64);
unsigned char new_config_byte = get_ps2_inbyte();
is_dual_ch = (new_config_byte & 020) == 0 ? 1 : 0;
if(is_dual_ch) {
outb(0xA7, 0x64);
}
}
/* Interface tests */
outb(0xAB, 0x64);
test_response = get_ps2_inbyte();
int working_ports = test_response == 0x00 ? 01 : 00;
if(test_response != 0x00 && !is_dual_ch) {
printf("error: could not initialize PS/2 device\n");
return 2;
}
if(is_dual_ch) {
outb(0xA9, 0x64);
test_response = get_ps2_inbyte();
working_ports |= test_response == 0x00 ? 02 : 00;
if(test_response != 0x00 && working_ports != 01) {
printf("error: could not initialize PS/2 device\n");
return 2;
}
}
/* Enable devices */
if(working_ports & 01) {
outb(0xAE, 0x64);
config_byte |= 01;
}
if(working_ports & 02) {
outb(0xA8, 0x64);
config_byte |= 02;
}
outb(0x60, 0x64);
outb(config_byte, 0x60);
return 0;
}
int init(void) {
printf("Setting up GDT...\n");
setup_gdt();
printf("Enabling interrupts...\n");
idt_init();
printf("Initializing PS/2 controller...\n");
initialize_ps2_kbd();
printf("Fenix Dev Pre-release v0.0.3\n");
return 0;
}

View file

@ -69,100 +69,99 @@
.extern irq15_handler
irq0:
pushal
pusha
call irq0_handler
popal
popa
iret
irq1:
pushal
cld
pusha
call irq1_handler
popal
popa
iret
irq2:
pushal
pusha
call irq2_handler
popal
popa
iret
irq3:
pushal
pusha
call irq3_handler
popal
popa
iret
irq4:
pushal
pusha
call irq4_handler
popal
popa
iret
irq5:
pushal
pusha
call irq5_handler
popal
popa
iret
irq6:
pushal
pusha
call irq6_handler
popal
popa
iret
irq7:
pushal
pusha
call irq7_handler
popal
popa
iret
irq8:
pushal
pusha
call irq8_handler
popal
popa
iret
irq9:
pushal
pusha
call irq9_handler
popal
popa
iret
irq10:
pushal
pusha
call irq10_handler
popal
popa
iret
irq11:
pushal
pusha
call irq11_handler
popal
popa
iret
irq12:
pushal
pusha
call irq12_handler
popal
popa
iret
irq13:
pushal
pusha
call irq13_handler
popal
popa
iret
irq14:
pushal
pusha
call irq14_handler
popal
popa
iret
irq15:
pushal
pusha
call irq15_handler
popal
popa
iret
load_idt:

View file

@ -1,7 +1,5 @@
#include <kernel/interrupt.h>
#include <sys/io.h>
#include <stdio.h>
#include "ps2_kbd.h"
void idt_init(void) {
extern int load_idt();
@ -194,7 +192,6 @@ void irq0_handler(void) {
/* Keyboard Interrupt */
void irq1_handler(void) {
printf("owo\n");
outb(0x20, 0x20);
}

View file

@ -4,33 +4,21 @@ SECTIONS
{
. = 1M;
_kernel_start = .;
.multiboot.data : {
*(.multiboot.data)
}
.multiboot.text : {
*(.multiboot.text)
}
. += 0xC0000000;
.text ALIGN (4K) : AT (ADDR (.text) - 0xC0000000) {
*(.text)
.text BLOCK (4K) : ALIGN (4K) {
*(.multiboot)
*(.text)
}
.rodata ALIGN (4K) : AT (ADDR (.rodata) - 0xC0000000) {
.rodata BLOCK (4K) : ALIGN (4K) {
*(.rodata)
}
.data ALIGN (4K) : AT (ADDR(.data) - 0xC0000000) {
*(.data)
.data BLOCK (4K) : ALIGN (4K) {
*(.data)
}
.bss ALIGN (4K) : AT (ADDR (.bss) - 0xC0000000) {
*(COMMON)
.bss BLOCK (4K) : ALIGN (4K) {
*(COMMON)
*(.bss)
*(.bootstrap_stack)
}
_kernel_end = .;
}

View file

@ -10,6 +10,4 @@ $(ARCHDIR)/cmos.o \
$(ARCHDIR)/gdt.o \
$(ARCHDIR)/gdt_load.o \
$(ARCHDIR)/interrupt.o \
$(ARCHDIR)/inter.o \
$(ARCHDIR)/ps2_kbd.o \
$(ARCHDIR)/syscall_uname.o
$(ARCHDIR)/inter.o

View file

@ -1,15 +0,0 @@
#include "ps2_kbd.h"
#include <sys/io.h>
unsigned char get_ps2_inbyte() {
return inb(0x60);
}
unsigned char* identify_device() {
unsigned char ret_val[2]; int j = 0;
outb(0xF2, 0x64);
for(unsigned char i; i != 0xFA; i = inb(0x60)) {
ret_val[j++] = i;
}
return ret_val;
}

View file

@ -1,10 +0,0 @@
#ifndef _ARCH_I386_PS2_KBD_H
#define _ARCH_I386_PS2_KBD_H
int scan_set;
unsigned char get_ps2_inbyte();
unsigned char* identify_device();
#endif

View file

@ -1,13 +0,0 @@
#include <sys/utsname.h>
#include <string.h>
#define PTR ((struct utsname *) v)
int __syscall_uname(void * v) {
strcpy(PTR->sysname, "FENIX");
strcpy(PTR->release, "PRE-ALPHA");
strcpy(PTR->version, "20220726_1700");
strcpy(PTR->machine, "i386");
return 0;
}

View file

@ -9,7 +9,7 @@
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 24;
static uint16_t* const VGA_MEMORY = (uint16_t*) 0xC03FF000 ;
static uint16_t* const VGA_MEMORY = (uint16_t*) 0xB8000 ;
static size_t term_row;
static size_t term_col;

View file

@ -2,7 +2,7 @@
#define _KERNEL_CMOS
/* This is kinda important, and has to be changed each year. */
#define RELEASE_YEAR 2022
#define RELEASE_YEAR 2020
struct _rtc_val {
unsigned char second;

View file

@ -1,15 +1,6 @@
#ifndef _KERNEL_INTERRUPT
#define _KERNEL_INTERRUPT
#ifdef __GNUC__
struct IDT_entry {
unsigned short int offset_lowerbits;
unsigned short int selector;
unsigned char zero;
unsigned char type_attr;
unsigned short int offset_higherbits;
} __attribute__((packed));
#else
struct IDT_entry {
unsigned short int offset_lowerbits;
unsigned short int selector;
@ -17,11 +8,7 @@ struct IDT_entry {
unsigned char type_attr;
unsigned short int offset_higherbits;
};
#endif
#ifdef __GNUC__
__attribute((aligned(0x10)))
#endif
struct IDT_entry IDT[256];
void idt_init(void);

View file

@ -1,6 +0,0 @@
#ifndef _KERNEL_SYSCALL
#define _KERNEL_SYSCALL
int __syscall_uname(void *);
#endif

View file

@ -1,12 +1,7 @@
#include <kernel/tty.h>
#include <kernel/init.h>
#include <sys/utsname.h>
#include <stdio.h>
void kern_main(void) {
term_init();
init();
struct utsname u;
uname(&u);
printf("%s %s %s\n", u.sysname, u.release, u.machine);
init();
}