]> git.lizzy.rs Git - nyax.git/commitdiff
Initial commit
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 22 Aug 2022 18:17:29 +0000 (20:17 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 22 Aug 2022 18:17:29 +0000 (20:17 +0200)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
bochsrc [new file with mode: 0644]
boot.asm [new file with mode: 0644]
colors.asm [new file with mode: 0644]
framebuffer.asm [new file with mode: 0644]
main.asm [new file with mode: 0644]
memory.asm [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..cfbe830
--- /dev/null
@@ -0,0 +1,3 @@
+*.out
+*.o
+*.img
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..af1e7af
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+OBJS = main.o framebuffer.o memory.o
+
+nyax.img: boot.out main.out
+       cat boot.out main.out > nyax.img
+
+boot.out: boot.asm main.out
+       nasm -f bin boot.asm -o boot.out -dMAIN_SIZE=$$(stat -c%s main.out)
+
+main.out: $(OBJS)
+       ld -o main.out -Ttext 0xD000 --oformat binary $(OBJS)
+
+%.o: %.asm
+       nasm -f elf64 $< -o $@
+
+.PHONY: run
+run: nyax.img
+       bochs -q
diff --git a/bochsrc b/bochsrc
new file mode 100644 (file)
index 0000000..c9f7bab
--- /dev/null
+++ b/bochsrc
@@ -0,0 +1,2 @@
+floppya: 1_44=nyax.img, status=inserted
+boot: a
diff --git a/boot.asm b/boot.asm
new file mode 100644 (file)
index 0000000..bb147bb
--- /dev/null
+++ b/boot.asm
@@ -0,0 +1,140 @@
+[org 0x7C00]
+
+boot:
+       xor ax, ax
+       mov ds, ax
+       mov es, ax
+       mov fs, ax
+       mov gs, ax
+       mov ss, ax
+
+       mov bp, 0x9000
+       mov sp, bp
+
+       mov ax, booting_msg
+       call print_str
+
+       mov bx, 0xD000
+       mov cl, 2
+       mov al, (MAIN_SIZE + 511) / 512
+       call load_disk
+
+       ;mov cl, 3
+       ;mov al, [es:bx]
+       ;call load_disk
+
+       mov di, 0x9000
+.clr_buf:
+       mov byte[di], 0
+       inc di
+       cmp di, 0xD000
+       jne .clr_buf
+
+       mov dword[0x9000], 0xA003
+       mov dword[0xA000], 0xB003
+       mov dword[0xB000], 0xC003
+
+       mov eax, 3
+       mov di, 0xC000
+.build_pt:
+       mov [di], eax
+       add eax, 0x1000
+       add di, 8
+       cmp eax, 0x100000
+       jb .build_pt
+
+       mov di, 0x9000
+
+       mov al, 0xFF
+       out 0xA1, al
+       out 0x21, al
+
+       nop
+       nop
+
+       lidt [IDT]
+
+       mov eax, 0b10100000
+       mov cr4, eax
+
+       mov edx, edi
+       mov cr3, edx
+
+       mov ecx, 0xC0000080
+       rdmsr
+
+       or eax, 0x00000100
+       wrmsr
+
+       mov ebx, cr0
+       or ebx, 0x80000001
+       mov cr0, ebx
+
+       lgdt [GDT.pointer]
+
+       jmp 0x0008:long_mode
+
+load_disk:
+       push ax
+       mov ah, 0x02
+       xor ch, ch
+       xor dh, dh
+       int 0x13
+       jc disk_error
+       pop cx
+       cmp al, cl
+       jne disk_error
+       ret
+
+disk_error:
+       mov ax, disk_error_msg
+       call print_str
+       jmp $
+
+print_str:
+       push ax
+       push bx
+       mov bx, ax
+       mov ah, 0x0E
+.print:
+       mov al, [bx]
+       cmp al, 0
+       je .return
+       int 0x10
+       inc bx
+       jmp .print
+.return:
+       pop bx
+       pop ax
+       ret
+
+booting_msg: db 10, 13, "Booting NyaX...", 10, 10, 13, 0
+disk_error_msg: db "Disk is bwoken, cant boot ;-;", 10, 13, 0
+
+GDT:
+       dq 0
+       dq 0x00209A0000000000
+       dq 0x0000920000000000
+       dw 0
+.pointer:
+       dw $ - GDT - 1
+       dd GDT
+
+IDT:
+       dw 0
+       dd 0
+
+[bits 64]
+
+long_mode:
+       mov ax, 0x0010
+       mov ds, ax
+       mov es, ax
+       mov fs, ax
+       mov gs, ax
+       mov ss, ax
+
+       jmp 0xD000
+
+times 510-($-$$) db 0
+dw 0xAA55
diff --git a/colors.asm b/colors.asm
new file mode 100644 (file)
index 0000000..a53efff
--- /dev/null
@@ -0,0 +1,16 @@
+%define COLOR_BLACK 0
+%define COLOR_BLUE 1
+%define COLOR_GREEN 2
+%define COLOR_CYAN 3
+%define COLOR_RED 4
+%define COLOR_MAGENTA 5
+%define COLOR_BROWN 6
+%define COLOR_LIGHT_GREY 7
+%define COLOR_DARK_GREY 8
+%define COLOR_LIGHT_BLUE 9
+%define COLOR_LIGHT_GREEN 10
+%define COLOR_LIGHT_CYAN 11
+%define COLOR_LIGHT_RED 12
+%define COLOR_LIGHT_MAGENTA 13
+%define COLOR_LIGHT_BROWN 14
+%define COLOR_WHITE 15
diff --git a/framebuffer.asm b/framebuffer.asm
new file mode 100644 (file)
index 0000000..4b73998
--- /dev/null
@@ -0,0 +1,153 @@
+%include "colors.asm"
+global print_chr, print_str, print_num, clear_screen
+extern memcpy
+
+section .data
+
+pos:
+.row: db 0
+.col: db 0
+
+cursor: dq 0xB8000
+color: db COLOR_WHITE | (COLOR_BLACK << 4)
+
+section .text
+
+set_color:
+       shl sil, 4
+       add dil, sil
+       mov [color], dil
+
+update_cursor:
+       mov rbx, [cursor]
+       sub rbx, 0xB8000
+       shr rbx, 1
+
+       mov dx, 0x3D4
+       mov al, 14
+       out dx, al
+
+       mov dx, 0x3D5
+       mov al, bh
+       out dx, al
+
+       mov dx, 0x3D4
+       mov al, 15
+       out dx, al
+
+       mov dx, 0x3D5
+       mov al, bl
+       out dx, al
+
+       ret
+
+set_chr:
+       mov rax, [cursor]
+       mov byte[rax], dil
+       inc rax
+       mov dil, [color]
+       mov [rax], dil
+       inc rax
+       mov [cursor], rax
+       jmp update_cursor
+
+vertical_tab:
+       mov al, [pos.row]
+       inc al
+       cmp al, 25
+       je .scroll
+       mov [pos.row], al
+       mov rax, [cursor]
+       add rax, 160
+       mov [cursor], rax
+       jmp update_cursor
+.scroll:
+       mov rdi, 0xB8000
+       mov rsi, 0xB80A0
+       mov rdx, 0xF00
+       jmp memcpy
+
+carriage_return:
+       mov rax, [cursor]
+       xor rbx, rbx
+       mov bl, [pos.col]
+       shl bl, 1
+       sub rax, rbx
+       mov [cursor], rax
+       mov byte[pos.col], 0
+       jmp update_cursor
+
+newline:
+       call vertical_tab
+       jmp carriage_return
+
+print_chr:
+       cmp dil, 10
+       je newline
+       cmp dil, 11
+       je vertical_tab
+       cmp dil, 13
+       je carriage_return
+       mov al, [pos.col]
+       inc al
+       cmp al, 80
+       je .newline
+       mov [pos.col], al
+       jmp set_chr
+.newline:
+       push rdi
+       call newline
+       pop rdi
+       jmp set_chr
+
+print_str:
+       mov rax, rdi
+.print:
+       mov dil, [rax]
+       cmp dil, 0
+       je .return
+       push rax
+       call print_chr
+       pop rax
+       inc rax
+       jmp .print
+.return:
+       ret
+
+print_num:
+       mov rax, rdi
+       mov r10, 10
+       xor rcx, rcx
+.convert:
+       inc rcx
+       xor rdx, rdx
+       div r10
+       add dl, '0'
+       push rdx
+       cmp rax, 0
+       jne .convert
+.print:
+       cmp rcx, 0
+       je .return
+       dec rcx
+       pop rdi
+       push rcx
+       call print_chr
+       pop rcx
+       jmp .print
+.return:
+       ret
+
+clear_screen:
+       mov qword[cursor], 0xB8000
+.clr:
+       cmp qword[cursor], 0xB8FA0
+       je .return
+       mov dil, ' '
+       call set_chr
+       jmp .clr
+.return:
+       mov qword[cursor], 0xB8000
+       mov byte[pos.row], 0
+       mov byte[pos.col], 0
+       jmp update_cursor
diff --git a/main.asm b/main.asm
new file mode 100644 (file)
index 0000000..64b9dd1
--- /dev/null
+++ b/main.asm
@@ -0,0 +1,31 @@
+global main
+extern print_str, print_num, print_chr, clear_screen
+
+section .data
+
+disclaimer: db \
+       "NyanX", 10, \
+       "(C) 2022 Flecken-chan", 10, \
+       "Dis progwam comes with ABSOLUTELY NO WAWWANTY", 10, \
+       "Dis iz fwee software, and your'e welcome to redistwibute it", 10, "  under certain conditions", 10, 0
+
+greeting: db "Good morning Senpai UwU", 10, 0
+
+section .text
+
+main:
+       call clear_screen
+       mov rdi, disclaimer
+       call print_str
+       mov rdi, greeting
+       call print_str
+       xor rdi, rdi
+       .loop:
+       push rdi
+       mov dil, 13
+       call print_chr
+       mov rdi, [rsp]
+       call print_num
+       pop rdi
+       inc rdi
+       jmp .loop
diff --git a/memory.asm b/memory.asm
new file mode 100644 (file)
index 0000000..b4410a3
--- /dev/null
@@ -0,0 +1,59 @@
+global memcpy, memmove
+
+section .text
+
+memcpy:
+.bulk_copy:
+       cmp rdx, 8
+       jl .bytewise_copy
+       mov rax, qword[rsi]
+       mov qword[rdi], rax
+       sub rdx, 8
+       add rdi, 8
+       add rsi, 8
+.bytewise_copy:
+       cmp rdx, 0
+       je .return
+       mov al, byte[rsi]
+       mov byte[rdi], al
+       dec rdx
+       inc rdi
+       inc rsi
+       jmp .bytewise_copy
+.return:
+       ret
+
+memmove:
+       mov rcx, rdx
+.bulk_read:
+       cmp rdx, 8
+       jl .bytewise_read
+       push qword[rsi]
+       add rsi, 8
+       sub rdx, 8
+       jmp .bulk_read
+.bytewise_read:
+       cmp rdx, 0
+       je .bulk_write
+       dec rsp
+       mov al, byte[rsi]
+       mov byte[rsp], al
+       inc rsi
+       dec rdx
+       jmp .bytewise_read
+.bulk_write:
+       cmp rcx, 8
+       jl .bytewise_write
+       pop qword[rdi]
+       add rdi, 8
+       sub rcx, 8
+.bytewise_write:
+       cmp rcx, 0
+       je .return
+       mov al, byte[rsp]
+       mov byte[rdi], al
+       inc rsp
+       inc rdi
+       dec rcx
+.return:
+       ret