clang-format shouldn't choke on assembly files.

This commit is contained in:
Morten Delenk 2017-04-29 11:35:43 +00:00
parent e63320f97c
commit d994c70468

View file

@ -1,89 +1,181 @@
#define ASM_FILE 1 #define ASM_FILE 1
#include <config.h> #include <config.h>
#include <multiboot.h> #include <multiboot.h>
.code32.section.text.boot.global _start _start : jmp _start2.align MULTIBOOT_HEADER_ALIGN .code32
.section .text.boot
.global _start
_start:
jmp _start2
.align MULTIBOOT_HEADER_ALIGN
.int MULTIBOOT_HEADER_MAGIC .int MULTIBOOT_HEADER_MAGIC
#ifndef ENABLE_FRAMEBUFFER #ifndef ENABLE_FRAMEBUFFER
.int 0x0.int - .int 0x0
(MULTIBOOT_HEADER_MAGIC) .int -(MULTIBOOT_HEADER_MAGIC)
#else #else
.int 0x7.int - .int 0x7
(MULTIBOOT_HEADER_MAGIC + 0x7).int 0, .int -(MULTIBOOT_HEADER_MAGIC+0x7)
0, 0, 0, 0.int 0.int 1024, 768, .int 0,0,0,0,0
24 .int 0
.int 1024, 768, 24
#endif #endif
.align MULTIBOOT_HEADER_ALIGN.extern start _start2 : mov $mb_ptr, .align MULTIBOOT_HEADER_ALIGN
% edi stosl mov % ebx, .extern start
% eax stosl // Store mb stuff _start2:
mov $mb_ptr, %edi
stosl
mov %ebx, %eax
stosl // Store mb stuff
#ifdef ENABLE_FPU #ifdef ENABLE_FPU
finit //Enable FPU finit //Enable FPU
#endif #endif
#ifdef ENABLE_SSE #ifdef ENABLE_SSE
//No check for SSE as SSE2+ is always present on x86_64 //No check for SSE as SSE2+ is always present on x86_64
mov mov %cr0, %eax
% cr0, and $0xFFFB, %ax
% eax and $0xFFFB, % ax or $0x2, % ax mov % eax, % cr0 mov % cr4, % eax or $3 << 9, % ax mov % eax, or $0x2, %ax
% cr4 mov %eax, %cr0
mov %cr4, %eax
or $3<<9, %ax
mov %eax, %cr4
#endif #endif
mov $kernel_stack, mov $kernel_stack, %esp
% esp mov $0x80000001, % eax cpuid and $0x20000000, mov $0x80000001, %eax
% edx // Check if long mode is supported cpuid
jz x86_64_err jmp x86_64_OK x86_64_err : cli hlt jmp x86_64_err x86_64_OK : and $0x20000000, %edx //Check if long mode is supported
jz x86_64_err
jmp x86_64_OK
x86_64_err:
cli
hlt
jmp x86_64_err
x86_64_OK:
//Assume PAE is supported //Assume PAE is supported
mov $pmfill, mov $pmfill, %esi
% esi mov $pagemapL4, % edi movsl movsl mov $pagedirPT, % edi mov $0x87, % eax xor % ebx, % ebx mov $1023, mov $pagemapL4, %edi
% ecx.ptloop : stosl xchg % eax, % ebx stosl xchg % eax, % ebx add $0x40000000, movsl
% eax jnc.ptloop_nc inc % ebx.ptloop_nc : loop.ptloop mov % cr4, % eax or $0x20, % eax mov % eax, movsl
% cr4 // Activate PAE mov $pagedirPT, %edi
mov $0xC0000080, mov $0x87, %eax
% ecx rdmsr or $0x00000100, xor %ebx, %ebx
% eax wrmsr // Activate x86_64 mov $1023, %ecx
mov $pagemapL4, .ptloop:
% eax mov % eax, stosl
% cr3 // Load page table xchg %eax, %ebx
mov stosl
% cr0, xchg %eax, %ebx
% eax bswap % eax or $0x80, % eax bswap % eax mov % eax, add $0x40000000, %eax
% cr0 // Activate paging jnc .ptloop_nc
lgdt gdtr mov $0x30, inc %ebx
% ax ljmp $0x28, .ptloop_nc:
$_start3 // Jump into long mode loop .ptloop
.code64 _start3 : mov mov %cr4, %eax
% ax, or $0x20, %eax
% ds mov % ax, % es mov % ax, % fs mov % ax, % gs mov % ax, mov %eax, %cr4 //Activate PAE
% ss // Load 64-bit data mov $0xC0000080, %ecx
mov $mb_ptr, rdmsr
% rsi lodsl mov % rax, % rdi lodsl mov % rax, or $0x00000100, %eax
% wrmsr //Activate x86_64
rsi call start _stop : cli hlt jmp _stop mov $pagemapL4, %eax
mov %eax, %cr3 //Load page table
mov %cr0, %eax
bswap %eax
or $0x80, %eax
bswap %eax
mov %eax, %cr0 //Activate paging
lgdt gdtr
mov $0x30, %ax
ljmp $0x28, $_start3 //Jump into long mode
.code64
_start3:
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss //Load 64-bit data
mov $mb_ptr, %rsi
lodsl
mov %rax, %rdi
lodsl
mov %rax, %rsi
call start
_stop:
cli
hlt
jmp _stop
.section.data gdtr :.word 9 *
8.int gdt gdt : .section .data
gdtr:
.word 9 * 8
.int gdt
gdt:
.quad 0 //NULL .quad 0 //NULL
//32-bit kernel code //32-bit kernel code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0x9A.byte .word 0xFFFF
0xCF.byte 0x00 .word 0x0000
.byte 0x00
.byte 0x9A
.byte 0xCF
.byte 0x00
//32-bit kernel code //32-bit kernel code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0x92.byte .word 0xFFFF
0xCF.byte 00 .word 0x0000
.byte 0x00
.byte 0x92
.byte 0xCF
.byte 00
//32-bit user code //32-bit user code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0xFA.byte .word 0xFFFF
0xCF.byte 0x00 .word 0x0000
.byte 0x00
.byte 0xFA
.byte 0xCF
.byte 0x00
//32-bit user data //32-bit user data
.word 0xFFFF.word 0x0000.byte 0x00.byte 0xF2.byte .word 0xFFFF
0xCF.byte 00 .word 0x0000
.byte 0x00
.byte 0xF2
.byte 0xCF
.byte 00
//64-bit kernel code //64-bit kernel code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0x9B.byte .word 0xFFFF
0xAF.byte 0x00 .word 0x0000
.byte 0x00
.byte 0x9B
.byte 0xAF
.byte 0x00
//64-bit kernel code //64-bit kernel code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0x93.byte .word 0xFFFF
0xCF.byte 00 .word 0x0000
.byte 0x00
.byte 0x93
.byte 0xCF
.byte 00
//64-bit user code //64-bit user code
.word 0xFFFF.word 0x0000.byte 0x00.byte 0xFB.byte .word 0xFFFF
0xAF.byte 0x00 .word 0x0000
.byte 0x00
.byte 0xFB
.byte 0xAF
.byte 0x00
//64-bit user data //64-bit user data
.word 0xFFFF.word 0x0000.byte 0x00.byte 0xF3.byte 0xCF.byte 00 pmfill :.int pagedirPT .word 0xFFFF
+ .word 0x0000
0x7.int 0.section.bss mb_ptr :.space 16384 kernel_stack :.align 4096 pagemapL4 :.space 4096 pagedirPT : .byte 0x00
.byte 0xF3
.byte 0xCF
.byte 00
pmfill:
.int pagedirPT + 0x7
.int 0
.section .bss
mb_ptr:
.space 16384
kernel_stack:
.align 4096
pagemapL4:
.space 4096
pagedirPT:
.space 4096 .space 4096