summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2022-01-21 21:44:28 +0100
committerAleksa Vučković <aleksav013@gmail.com>2022-01-21 23:24:55 +0100
commita914c37365967afaf3148293a857c36af6f94ecb (patch)
treeb7086b0b0b6e4bf427210fcfd31c7745920a73a5 /src
parented84017353c6fc9421b223ff6ec62f8d881d8098 (diff)
Separating assembly, moving #defines to .h & cleaning Makefile
Diffstat (limited to 'src')
-rw-r--r--src/as/boot.s30
-rw-r--r--src/as/gdt.s6
-rw-r--r--src/as/idt.s7
-rw-r--r--src/as/ioport.s13
-rw-r--r--src/c/idt.c1
-rw-r--r--src/c/irq_handler.c10
-rw-r--r--src/c/kernel.c12
-rw-r--r--src/c/keyboard.c24
-rw-r--r--src/c/timer.c10
-rw-r--r--src/crt/crt0.s31
-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.h7
-rw-r--r--src/include/source/irq_handler.h6
-rw-r--r--src/include/source/keyboard.h6
-rw-r--r--src/include/source/keymap.h5
16 files changed, 91 insertions, 77 deletions
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[]);