summaryrefslogtreecommitdiff
path: root/src/as
diff options
context:
space:
mode:
Diffstat (limited to 'src/as')
-rw-r--r--src/as/Makefile5
-rw-r--r--src/as/boot.s82
-rw-r--r--src/as/crti.s16
-rw-r--r--src/as/crtn.s10
4 files changed, 113 insertions, 0 deletions
diff --git a/src/as/Makefile b/src/as/Makefile
new file mode 100644
index 0000000..e2c476d
--- /dev/null
+++ b/src/as/Makefile
@@ -0,0 +1,5 @@
+.PHONY: all
+all: $(AS_OBJECTS)
+
+$(BUILD_DIR)/%.o: %.s
+ $(AS) $< -o $@
diff --git a/src/as/boot.s b/src/as/boot.s
new file mode 100644
index 0000000..6fe5ab8
--- /dev/null
+++ b/src/as/boot.s
@@ -0,0 +1,82 @@
+.set ALIGN, 1<<0
+.set MEMINFO, 1<<1
+.set FLAGS, ALIGN | MEMINFO
+.set MAGIC, 0x1BADB002
+.set CHECKSUM, -(MAGIC + FLAGS)
+
+.section .multiboot
+.align 4
+.long MAGIC
+.long FLAGS
+.long CHECKSUM
+
+.global _start
+.global load_gdt
+.global load_idt
+.global enable_interrupts
+.global keyboard_handler
+.global ioport_in
+.global ioport_out
+
+.extern init_gdt_table
+.extern handle_keyboard_interrupt
+.extern kernel_main
+
+load_gdt:
+ movl 4(%esp), %edx
+ lgdt (%edx)
+ ret
+
+load_idt:
+ movl 4(%esp), %edx
+ lidt (%edx)
+ sti
+ ret
+
+keyboard_handler:
+ pushal
+ cld
+ call handle_keyboard_interrupt
+ popal
+ iretl
+
+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
+
+.section .bss
+.align 16
+stack_bottom:
+.skip 16384
+stack_top:
+
+.section .text
+.type _start, @function
+_start:
+ call init_gdt_table
+ ljmp $CODE_SEGMENT, $code
+
+code:
+ movw $DATA_SEGMENT, %ax
+ movw %ax, %ds
+ movw %ax, %es
+ movw %ax, %fs
+ movw %ax, %gs
+ movw %ax, %ss
+ movl $stack_top, %esp
+ cli
+ call _init
+ call kernel_main
+ hlt
+
+.size _start, . - _start
diff --git a/src/as/crti.s b/src/as/crti.s
new file mode 100644
index 0000000..30dd4ea
--- /dev/null
+++ b/src/as/crti.s
@@ -0,0 +1,16 @@
+/* x86 crti.s */
+.section .init
+.global _init
+.type _init, @function
+_init:
+ push %ebp
+ movl %esp, %ebp
+ /* gcc will nicely put the contents of crtbegin.o's .init section here. */
+
+.section .fini
+.global _fini
+.type _fini, @function
+_fini:
+ push %ebp
+ movl %esp, %ebp
+ /* gcc will nicely put the contents of crtbegin.o's .fini section here. */
diff --git a/src/as/crtn.s b/src/as/crtn.s
new file mode 100644
index 0000000..1da795d
--- /dev/null
+++ b/src/as/crtn.s
@@ -0,0 +1,10 @@
+/* x86 crtn.s */
+.section .init
+ /* gcc will nicely put the contents of crtend.o's .init section here. */
+ popl %ebp
+ ret
+
+.section .fini
+ /* gcc will nicely put the contents of crtend.o's .fini section here. */
+ popl %ebp
+ ret