forked from CHatingPython/towos
chore: init project
This commit is contained in:
+177
@@ -0,0 +1,177 @@
|
||||
.section .multiboot
|
||||
.align 8
|
||||
|
||||
multiboot_header:
|
||||
.long 0xE85250D6
|
||||
.long 0
|
||||
.long multiboot_header_end - multiboot_header
|
||||
.long -(0xE85250D6 + 0 + (multiboot_header_end - multiboot_header))
|
||||
|
||||
.short 0
|
||||
.short 0
|
||||
.long 8
|
||||
multiboot_header_end:
|
||||
|
||||
.section .text
|
||||
.code32
|
||||
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
.extern kmain
|
||||
|
||||
_start:
|
||||
cli
|
||||
cld
|
||||
|
||||
movl %eax, multiboot_magic
|
||||
movl %ebx, multiboot_info
|
||||
|
||||
movl $stack_top, %esp
|
||||
|
||||
movl $pdpt_table, %eax
|
||||
orl $0x3, %eax
|
||||
movl %eax, pml4_table
|
||||
|
||||
movl $pd_table, %eax
|
||||
orl $0x3, %eax
|
||||
movl %eax, pdpt_table
|
||||
|
||||
xorl %ecx, %ecx
|
||||
movl $pd_table, %edi
|
||||
|
||||
.fill_pd:
|
||||
movl %ecx, %eax
|
||||
|
||||
shll $21, %eax
|
||||
|
||||
orl $0x83, %eax
|
||||
|
||||
movl %eax, (%edi)
|
||||
|
||||
addl $8, %edi
|
||||
incl %ecx
|
||||
|
||||
cmpl $512, %ecx
|
||||
jne .fill_pd
|
||||
|
||||
movl $pml4_table, %eax
|
||||
movl %eax, %cr3
|
||||
|
||||
movl %cr4, %eax
|
||||
orl $0x20, %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
movl $0xC0000080, %ecx
|
||||
rdmsr
|
||||
|
||||
orl $0x100, %eax
|
||||
|
||||
wrmsr
|
||||
|
||||
movl %cr0, %eax
|
||||
orl $0x80000001, %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
lgdt gdt_descriptor
|
||||
|
||||
ljmp $0x08, $long_mode_entry
|
||||
|
||||
|
||||
.code64
|
||||
|
||||
long_mode_entry:
|
||||
movw $0x10, %ax
|
||||
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
movw %ax, %ss
|
||||
movw %ax, %fs
|
||||
movw %ax, %gs
|
||||
|
||||
movq $stack_top, %rsp
|
||||
|
||||
andq $-16, %rsp
|
||||
|
||||
xorq %rbp, %rbp
|
||||
|
||||
call run_global_constructors
|
||||
|
||||
call kmain
|
||||
.hang:
|
||||
cli
|
||||
hlt
|
||||
jmp .hang
|
||||
|
||||
|
||||
.extern __init_array_start
|
||||
.extern __init_array_end
|
||||
|
||||
run_global_constructors:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
|
||||
movq $__init_array_start, %rax
|
||||
|
||||
.constructor_loop:
|
||||
cmpq $__init_array_end, %rax
|
||||
jae .constructors_done
|
||||
|
||||
movq (%rax), %rdx
|
||||
call *%rdx
|
||||
|
||||
addq $8, %rax
|
||||
jmp .constructor_loop
|
||||
|
||||
.constructors_done:
|
||||
popq %rbp
|
||||
ret
|
||||
|
||||
|
||||
.align 8
|
||||
|
||||
gdt:
|
||||
.quad 0x0000000000000000
|
||||
.quad 0x00AF9A000000FFFF
|
||||
.quad 0x00AF92000000FFFF
|
||||
gdt_end:
|
||||
|
||||
gdt_descriptor:
|
||||
.word gdt_end - gdt - 1
|
||||
.long gdt
|
||||
|
||||
|
||||
.section .bss
|
||||
|
||||
.align 8
|
||||
|
||||
.global multiboot_magic
|
||||
multiboot_magic:
|
||||
.quad 0
|
||||
|
||||
.global multiboot_info
|
||||
multiboot_info:
|
||||
.quad 0
|
||||
|
||||
|
||||
.align 4096
|
||||
|
||||
pml4_table:
|
||||
.skip 4096
|
||||
|
||||
.align 4096
|
||||
|
||||
pdpt_table:
|
||||
.skip 4096
|
||||
|
||||
.align 4096
|
||||
|
||||
pd_table:
|
||||
.skip 4096
|
||||
|
||||
|
||||
.align 16
|
||||
|
||||
stack_bottom:
|
||||
.skip 16384
|
||||
stack_top:
|
||||
@@ -0,0 +1,16 @@
|
||||
using u8 = unsigned char;
|
||||
using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
|
||||
static volatile u16* const s_vga = reinterpret_cast<volatile u16*>(0xB8000);
|
||||
|
||||
extern "C" void kmain() {
|
||||
const char* msg = "Zdravstvuyte, tovorisch!";
|
||||
|
||||
for (int i = 0; msg[i] != '\0'; i++)
|
||||
s_vga[i] = 0x0700 | msg[i];
|
||||
|
||||
for (;;)
|
||||
__asm__ volatile("hlt");
|
||||
}
|
||||
Reference in New Issue
Block a user