diff options
| author | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-21 21:44:28 +0100 |
|---|---|---|
| committer | Aleksa Vučković <aleksav013@gmail.com> | 2022-01-21 23:24:55 +0100 |
| commit | a914c37365967afaf3148293a857c36af6f94ecb (patch) | |
| tree | b7086b0b0b6e4bf427210fcfd31c7745920a73a5 | |
| parent | ed84017353c6fc9421b223ff6ec62f8d881d8098 (diff) | |
Separating assembly, moving #defines to .h & cleaning Makefile
| -rw-r--r-- | Makefile | 27 | ||||
| -rwxr-xr-x | scripts/setup_compiler.sh | 9 | ||||
| -rw-r--r-- | src/as/boot.s | 30 | ||||
| -rw-r--r-- | src/as/gdt.s | 6 | ||||
| -rw-r--r-- | src/as/idt.s | 7 | ||||
| -rw-r--r-- | src/as/ioport.s | 13 | ||||
| -rw-r--r-- | src/c/idt.c | 1 | ||||
| -rw-r--r-- | src/c/irq_handler.c | 10 | ||||
| -rw-r--r-- | src/c/kernel.c | 12 | ||||
| -rw-r--r-- | src/c/keyboard.c | 24 | ||||
| -rw-r--r-- | src/c/timer.c | 10 | ||||
| -rw-r--r-- | src/crt/crt0.s | 31 | ||||
| -rw-r--r-- | src/crt/crti.s (renamed from src/as/crti.s) | 0 | ||||
| -rw-r--r-- | src/crt/crtn.s (renamed from src/as/crtn.s) | 0 | ||||
| -rw-r--r-- | src/include/asm.h | 7 | ||||
| -rw-r--r-- | src/include/source/irq_handler.h | 6 | ||||
| -rw-r--r-- | src/include/source/keyboard.h | 6 | ||||
| -rw-r--r-- | src/include/source/keymap.h | 5 |
18 files changed, 104 insertions, 100 deletions
@@ -18,7 +18,7 @@ export CFLAGS=-std=gnu99 -O3 $(WARNINGS) -ffreestanding -fstack-protector-all export MKDIR=mkdir -p export RM=rm -rf export CP=cp -r -QEMU=qemu-system-x86_64 +QEMU=qemu-system-i386 @@ -26,9 +26,6 @@ QEMU=qemu-system-x86_64 ## SOURCE SOURCE_DIR=src -AS_SOURCE_DIR=$(SOURCE_DIR)/as -C_SOURCE_DIR=$(SOURCE_DIR)/c -INCLUDE_DIR=$(SOURCE_DIR)/include ## BUILD ISO_DIR=isodir @@ -36,14 +33,8 @@ BUILD_DIR=${CURDIR}/build export AS_OBJECT_DIR=$(BUILD_DIR)/as export C_OBJECT_DIR=$(BUILD_DIR)/c -## SYSROOT -SYSROOT_DIR=/opt/aleksa -SYSROOT_USR_DIR=$(SYSROOT_DIR)/usr -SYSROOT_INCLUDE_DIR=$(SYSROOT_USR_DIR)/include - ## GCC USR GCC_USR_DIR=$(shell $(CC) -print-file-name=) -GCC_INCLUDE_DIR=$(GCC_USR_DIR)/include @@ -57,25 +48,15 @@ ISO=$(TARGET).iso # OBJECTS ## AS OBJECTS -CRTI_OBJ=crti.o -CRTN_OBJ=crtn.o -AS_OBJ=boot.o irq.o paging.o - -AS_OBJECT=$(patsubst %,$(AS_OBJECT_DIR)/%,$(AS_OBJ)) -CRTI_OBJECT=$(patsubst %,$(AS_OBJECT_DIR)/%,$(CRTI_OBJ)) -CRTN_OBJECT=$(patsubst %,$(AS_OBJECT_DIR)/%,$(CRTN_OBJ)) -export AS_OBJECTS=$(AS_OBJECT) $(CRTI_OBJECT) $(CRTN_OBJECT) - -CRTBEGIN_OBJECT=$(GCC_USR_DIR)/crtbegin.o -CRTEND_OBJECT=$(GCC_USR_DIR)/crtend.o +AS_OBJ=boot.o ioport.o gdt.o idt.o irq.o paging.o +export AS_OBJECTS=$(patsubst %,$(AS_OBJECT_DIR)/%,$(AS_OBJ)) ## C OBJECTS C_OBJ=gdt.o heap.o idt.o kernel.o keyboard.o keymap.o stdio.o string.o tty.o vga.o irq_handler.o stack_protector.o timer.o paging.o - export C_OBJECTS=$(patsubst %,$(C_OBJECT_DIR)/%,$(C_OBJ)) ## ALL OBJECTS IN ORDER -OBJ=$(CRTI_OBJECT) $(CRTBEGIN_OBJECT) $(AS_OBJECT) $(C_OBJECTS) $(CRTEND_OBJECT) $(CRTN_OBJECT) +OBJ=$(GCC_USR_DIR)crti.o $(GCC_USR_DIR)crtbegin.o $(AS_OBJECTS) $(C_OBJECTS) $(GCC_USR_DIR)crtend.o $(GCC_USR_DIR)crtn.o diff --git a/scripts/setup_compiler.sh b/scripts/setup_compiler.sh new file mode 100755 index 0000000..46870fd --- /dev/null +++ b/scripts/setup_compiler.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +GCC_INCLUDE=$(i686-aleksa-gcc --print-file-name= || exit) + +i686-aleksa-as "src/crt/crt0.s" -o "${GCC_INCLUDE}crt0.o" +i686-aleksa-as "src/crt/crti.s" -o "${GCC_INCLUDE}crti.o" +i686-aleksa-as "src/crt/crtn.s" -o "${GCC_INCLUDE}crtn.o" + +#touch "${GCC_INCLUDE}libc.a" diff --git a/src/as/boot.s b/src/as/boot.s index 907cd3c..f65cc72 100644 --- a/src/as/boot.s +++ b/src/as/boot.s @@ -10,35 +10,6 @@ .long FLAGS .long CHECKSUM -.global _start -.global load_gdt -.global load_idt -.global enable_interrupts -.global ioport_in -.global ioport_out - -load_gdt: - movl 4(%esp), %edx - lgdt (%edx) - ret - -load_idt: - movl 4(%esp), %edx - lidt (%edx) - sti - ret - -ioport_in: - movl 4(%esp),%edx - in %dx,%al - ret - -ioport_out: - movl 4(%esp),%edx - movl 8(%esp),%eax - outb %al,%dx - ret - .set CODE_SEGMENT, 0x08 .set DATA_SEGMENT, 0x10 @@ -49,6 +20,7 @@ stack_bottom: stack_top: .section .text +.global _start .type _start, @function _start: call init_gdt_table diff --git a/src/as/gdt.s b/src/as/gdt.s new file mode 100644 index 0000000..632bd3e --- /dev/null +++ b/src/as/gdt.s @@ -0,0 +1,6 @@ +.global load_gdt + +load_gdt: + movl 4(%esp), %edx + lgdt (%edx) + ret diff --git a/src/as/idt.s b/src/as/idt.s new file mode 100644 index 0000000..e95b42b --- /dev/null +++ b/src/as/idt.s @@ -0,0 +1,7 @@ +.global load_idt + +load_idt: + movl 4(%esp), %edx + lidt (%edx) + sti + ret diff --git a/src/as/ioport.s b/src/as/ioport.s new file mode 100644 index 0000000..f4b4dbd --- /dev/null +++ b/src/as/ioport.s @@ -0,0 +1,13 @@ +.global ioport_in +.global ioport_out + +ioport_in: + movl 4(%esp),%edx + in %dx,%al + ret + +ioport_out: + movl 4(%esp),%edx + movl 8(%esp),%eax + outb %al,%dx + ret diff --git a/src/c/idt.c b/src/c/idt.c index c27743f..5a84791 100644 --- a/src/c/idt.c +++ b/src/c/idt.c @@ -3,7 +3,6 @@ #include<source/irq.h> #include<asm.h> - extern void load_idt(struct idt_pointer *idtp); struct idt_entry idt[256]; diff --git a/src/c/irq_handler.c b/src/c/irq_handler.c index 797639d..b687148 100644 --- a/src/c/irq_handler.c +++ b/src/c/irq_handler.c @@ -2,16 +2,6 @@ #include<source/stdio.h> #include<asm.h> -#define INTERRUPT_GATE_32 0x8e - -#define KERNEL_CODE 0x08 -#define KERNEL_DATA 0x10 - -#define PIC1_COMMAND_PORT 0x20 -#define PIC1_DATA_PORT 0x21 -#define PIC2_COMMAND_PORT 0xA0 -#define PIC2_DATA_PORT 0xA1 - void irq0_handler(void) { ioport_out(PIC1_COMMAND_PORT, 0x20); diff --git a/src/c/kernel.c b/src/c/kernel.c index 1142a23..72b2516 100644 --- a/src/c/kernel.c +++ b/src/c/kernel.c @@ -1,12 +1,12 @@ #include<source/kernel.h> +#include<source/paging.h> +#include<source/idt.h> +#include<source/timer.h> +#include<source/keyboard.h> #include<source/heap.h> +#include<source/vga.h> +#include<source/tty.h> -void terminal_initialize(void); -void init_idt_table(void); -void init_keyboard(void); -void init_timer(uint32_t frequency); -void prompt(void); -void set_paging(void); void kernel_main(void) { diff --git a/src/c/keyboard.c b/src/c/keyboard.c index 8af463b..a95d399 100644 --- a/src/c/keyboard.c +++ b/src/c/keyboard.c @@ -2,37 +2,19 @@ #include<types.h> #include<asm.h> #include<source/stdio.h> +#include<source/keymap.h> +#include<source/vga.h> +#include<source/tty.h> -#define BUFFER_SIZE 200 -#define BUFFER_LOG 200 char buffer[BUFFER_LOG][BUFFER_SIZE]; size_t buffer_size[BUFFER_LOG]; size_t buffer_current=0; size_t buffer_all=0; size_t buffer_index=0; -#define PIC1_COMMAND_PORT 0x20 -#define PIC1_DATA_PORT 0x21 -#define PIC2_COMMAND_PORT 0xA0 -#define PIC2_DATA_PORT 0xA1 -// IO Ports for Keyboard -#define KEYBOARD_DATA_PORT 0x60 -#define KEYBOARD_STATUS_PORT 0x64 - -void previous_field(void); -void tty(char *buffer); -void prompt(void); -void clear(void); -void us_en(char keymap[]); -void us_en_shift(char keymap[]); - char charcode[256]; char shift_charcode[256]; bool ispressed[128]; -#define lshift 0x2A -#define rshift 0x36 -#define lctrl 0x1D -#define rctrl 0x1D void init_keyboard() { diff --git a/src/c/timer.c b/src/c/timer.c index 412e443..3a8f159 100644 --- a/src/c/timer.c +++ b/src/c/timer.c @@ -13,7 +13,6 @@ void timer_handler(void) tick++; if(tick==TICKS_PER_SECOND) { - //printf("%d seconds passed\n",time); tick=0; time++; } @@ -24,21 +23,12 @@ void timer_handler(void) void init_timer(uint32_t frequency) { - // Firstly, register our timer callback. - - // The value we send to the PIT is the value to divide it's input clock - // (1193180 Hz) by, to get our required frequency. Important to note is - // that the divisor must be small enough to fit into 16-bits. uint32_t divisor = 1193180 / frequency; - - // Send the command byte. ioport_out(0x43, 0x36); - // Divisor has to be sent byte-wise, so split here into upper/lower bytes. uint8_t l = (uint8_t)(divisor & 0xFF); uint8_t h = (uint8_t)( (divisor>>8) & 0xFF ); - // Send the frequency divisor. ioport_out(0x40, l); ioport_out(0x40, h); } diff --git a/src/crt/crt0.s b/src/crt/crt0.s new file mode 100644 index 0000000..8c735f1 --- /dev/null +++ b/src/crt/crt0.s @@ -0,0 +1,31 @@ +.section .text + +.global _start +_start: + # Set up end of the stack frame linked list. + movl $0, %ebp + pushl %ebp # rip=0 + pushl %ebp # rbp=0 + movl %esp, %ebp + + # We need those in a moment when we call main. + pushl %esi + pushl %edi + + # Prepare signals, memory allocation, stdio and such. +# call initialize_standard_library + + # Run the global constructors. + call _init + + # Restore argc and argv. + popl %edi + popl %esi + + # Run main + call main + + # Terminate the process with the exit code. + movl %eax, %edi +# call exit +.size _start, . - _start diff --git a/src/as/crti.s b/src/crt/crti.s index 5894e2d..5894e2d 100644 --- a/src/as/crti.s +++ b/src/crt/crti.s diff --git a/src/as/crtn.s b/src/crt/crtn.s index 0e1c314..0e1c314 100644 --- a/src/as/crtn.s +++ b/src/crt/crtn.s diff --git a/src/include/asm.h b/src/include/asm.h index e57c35b..ee15f00 100644 --- a/src/include/asm.h +++ b/src/include/asm.h @@ -3,7 +3,14 @@ #include<types.h> +#define PIC1_COMMAND_PORT 0x20 +#define PIC1_DATA_PORT 0x21 +#define PIC2_COMMAND_PORT 0xA0 +#define PIC2_DATA_PORT 0xA1 + + extern uint8_t ioport_in(uint8_t port); extern void ioport_out(uint8_t port, int data); + #endif diff --git a/src/include/source/irq_handler.h b/src/include/source/irq_handler.h index 41b4f8c..a20ed70 100644 --- a/src/include/source/irq_handler.h +++ b/src/include/source/irq_handler.h @@ -1,6 +1,12 @@ #ifndef SOURCE_IRQ_HANDLER_H #define SOURCE_IRQ_HANDLER_H +#define INTERRUPT_GATE_32 0x8e + +#define KERNEL_CODE 0x08 +#define KERNEL_DATA 0x10 + + void irq0_handler(void); void irq1_handler(void); void irq2_handler(void); diff --git a/src/include/source/keyboard.h b/src/include/source/keyboard.h index 28fa104..a023e66 100644 --- a/src/include/source/keyboard.h +++ b/src/include/source/keyboard.h @@ -1,6 +1,12 @@ #ifndef SOURCE_KEYBOARD_H #define SOURCE_KEYBOARD_H +#define BUFFER_SIZE 200 +#define BUFFER_LOG 200 + +#define KEYBOARD_DATA_PORT 0x60 +#define KEYBOARD_STATUS_PORT 0x64 + void init_keyboard(void); void deletelast(void); void backspace(void); diff --git a/src/include/source/keymap.h b/src/include/source/keymap.h index 1c474ae..7d01291 100644 --- a/src/include/source/keymap.h +++ b/src/include/source/keymap.h @@ -3,6 +3,11 @@ #include<types.h> +#define lshift 0x2A +#define rshift 0x36 +#define lctrl 0x1D +#define rctrl 0x1D + void us_en(char keymap[]); void us_en_shift(char keymap[]); |
