forked from Bananymous/banan-os
Kernel: Use local labels in assembly
This commit is contained in:
@@ -63,7 +63,7 @@ sys_fork_trampoline:
|
|||||||
|
|
||||||
call read_ip
|
call read_ip
|
||||||
testl %eax, %eax
|
testl %eax, %eax
|
||||||
jz .done
|
jz .Lsys_fork_trampoline_done
|
||||||
|
|
||||||
movl %esp, %ebx
|
movl %esp, %ebx
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ sys_fork_trampoline:
|
|||||||
call sys_fork
|
call sys_fork
|
||||||
addl $16, %esp
|
addl $16, %esp
|
||||||
|
|
||||||
.done:
|
.Lsys_fork_trampoline_done:
|
||||||
popl %edi
|
popl %edi
|
||||||
popl %esi
|
popl %esi
|
||||||
popl %ebx
|
popl %ebx
|
||||||
|
|||||||
@@ -28,27 +28,26 @@ safe_user_strncpy:
|
|||||||
testl %ecx, %ecx
|
testl %ecx, %ecx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.safe_user_strncpy_loop:
|
.Lsafe_user_strncpy_loop:
|
||||||
movb (%esi), %al
|
movb (%esi), %al
|
||||||
movb %al, (%edi)
|
movb %al, (%edi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .safe_user_strncpy_done
|
jz .Lsafe_user_strncpy_done
|
||||||
|
|
||||||
incl %edi
|
incl %edi
|
||||||
incl %esi
|
incl %esi
|
||||||
decl %ecx
|
decl %ecx
|
||||||
jnz .safe_user_strncpy_loop
|
jnz .Lsafe_user_strncpy_loop
|
||||||
|
|
||||||
safe_user_strncpy_fault:
|
safe_user_strncpy_fault:
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
jmp .safe_user_strncpy_return
|
jmp .Lsafe_user_strncpy_return
|
||||||
|
|
||||||
.safe_user_strncpy_done:
|
.Lsafe_user_strncpy_done:
|
||||||
movl $1, %eax
|
movl $1, %eax
|
||||||
|
|
||||||
.safe_user_strncpy_return:
|
.Lsafe_user_strncpy_return:
|
||||||
movl 4(%esp), %edi
|
movl 4(%esp), %edi
|
||||||
movl 8(%esp), %esi
|
movl 8(%esp), %esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
safe_user_strncpy_end:
|
safe_user_strncpy_end:
|
||||||
|
|||||||
+15
-17
@@ -168,14 +168,12 @@ has_sse:
|
|||||||
|
|
||||||
check_requirements:
|
check_requirements:
|
||||||
call has_cpuid
|
call has_cpuid
|
||||||
jz .exit
|
jz system_halt
|
||||||
call has_pae
|
call has_pae
|
||||||
jz .exit
|
jz system_halt
|
||||||
call has_sse
|
call has_sse
|
||||||
jz .exit
|
jz system_halt
|
||||||
ret
|
ret
|
||||||
.exit:
|
|
||||||
jmp system_halt
|
|
||||||
|
|
||||||
enable_sse:
|
enable_sse:
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
@@ -225,8 +223,8 @@ _start:
|
|||||||
|
|
||||||
# load boot GDT
|
# load boot GDT
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $V2P(gdt_flush)
|
ljmpl $0x08, $V2P(.Lgdt_flush)
|
||||||
gdt_flush:
|
.Lgdt_flush:
|
||||||
# set correct segment registers
|
# set correct segment registers
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
@@ -243,10 +241,10 @@ gdt_flush:
|
|||||||
movl $g_boot_stack_top, %esp
|
movl $g_boot_stack_top, %esp
|
||||||
|
|
||||||
# jump to higher half
|
# jump to higher half
|
||||||
leal higher_half, %ecx
|
leal .Lhigher_half, %ecx
|
||||||
jmp *%ecx
|
jmp *%ecx
|
||||||
|
|
||||||
higher_half:
|
.Lhigher_half:
|
||||||
# call global constuctors
|
# call global constuctors
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
@@ -298,18 +296,18 @@ ap_ready:
|
|||||||
.skip 4
|
.skip 4
|
||||||
|
|
||||||
1: cli; cld
|
1: cli; cld
|
||||||
ljmpl $0x00, $AP_REL(ap_cs_clear)
|
ljmpl $0x00, $AP_REL(.Lap_cs_clear)
|
||||||
|
|
||||||
ap_cs_clear:
|
.Lap_cs_clear:
|
||||||
# load ap gdt and enter protected mode
|
# load ap gdt and enter protected mode
|
||||||
lgdt AP_REL(ap_gdtr)
|
lgdt AP_REL(ap_gdtr)
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
orb $1, %al
|
orb $1, %al
|
||||||
movl %eax, %cr0
|
movl %eax, %cr0
|
||||||
ljmpl $0x08, $AP_REL(ap_protected_mode)
|
ljmpl $0x08, $AP_REL(.Lap_protected_mode)
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
ap_protected_mode:
|
.Lap_protected_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -323,13 +321,13 @@ ap_protected_mode:
|
|||||||
|
|
||||||
# load boot gdt and enter long mode
|
# load boot gdt and enter long mode
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $AP_REL(ap_flush_gdt)
|
ljmpl $0x08, $AP_REL(.Lap_flush_gdt)
|
||||||
|
|
||||||
ap_flush_gdt:
|
.Lap_flush_gdt:
|
||||||
movl $ap_higher_half, %ecx
|
movl $.Lap_higher_half, %ecx
|
||||||
jmp *%ecx
|
jmp *%ecx
|
||||||
|
|
||||||
ap_higher_half:
|
.Lap_higher_half:
|
||||||
movl AP_REL(ap_prepare_paging), %eax
|
movl AP_REL(ap_prepare_paging), %eax
|
||||||
call *%eax
|
call *%eax
|
||||||
|
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ sys_fork_trampoline:
|
|||||||
|
|
||||||
call read_ip
|
call read_ip
|
||||||
testq %rax, %rax
|
testq %rax, %rax
|
||||||
jz .done
|
jz .Lsys_fork_trampoline_done
|
||||||
|
|
||||||
movq %rax, %rsi
|
movq %rax, %rsi
|
||||||
movq %rsp, %rdi
|
movq %rsp, %rdi
|
||||||
call sys_fork
|
call sys_fork
|
||||||
|
|
||||||
.done:
|
.Lsys_fork_trampoline_done:
|
||||||
popq %r15
|
popq %r15
|
||||||
popq %r14
|
popq %r14
|
||||||
popq %r13
|
popq %r13
|
||||||
|
|||||||
+14
-14
@@ -20,28 +20,28 @@ safe_user_strncpy:
|
|||||||
testq %rcx, %rcx
|
testq %rcx, %rcx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.safe_user_strncpy_align_loop:
|
.Lsafe_user_strncpy_align_loop:
|
||||||
testb $0x7, %sil
|
testb $0x7, %sil
|
||||||
jz .safe_user_strncpy_align_done
|
jz .Lsafe_user_strncpy_align_done
|
||||||
|
|
||||||
movb (%rsi), %al
|
movb (%rsi), %al
|
||||||
movb %al, (%rdi)
|
movb %al, (%rdi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .safe_user_strncpy_done
|
jz .Lsafe_user_strncpy_done
|
||||||
|
|
||||||
incq %rdi
|
incq %rdi
|
||||||
incq %rsi
|
incq %rsi
|
||||||
decq %rcx
|
decq %rcx
|
||||||
jnz .safe_user_strncpy_align_loop
|
jnz .Lsafe_user_strncpy_align_loop
|
||||||
jmp safe_user_strncpy_fault
|
jmp safe_user_strncpy_fault
|
||||||
|
|
||||||
.safe_user_strncpy_align_done:
|
.Lsafe_user_strncpy_align_done:
|
||||||
movq $0x0101010101010101, %r8
|
movq $0x0101010101010101, %r8
|
||||||
movq $0x8080808080808080, %r9
|
movq $0x8080808080808080, %r9
|
||||||
|
|
||||||
.safe_user_strncpy_qword_loop:
|
.Lsafe_user_strncpy_qword_loop:
|
||||||
cmpq $8, %rcx
|
cmpq $8, %rcx
|
||||||
jb .safe_user_strncpy_qword_done
|
jb .Lsafe_user_strncpy_qword_done
|
||||||
|
|
||||||
movq (%rsi), %rax
|
movq (%rsi), %rax
|
||||||
movq %rax, %r10
|
movq %rax, %r10
|
||||||
@@ -52,36 +52,36 @@ safe_user_strncpy:
|
|||||||
notq %r11
|
notq %r11
|
||||||
andq %r11, %r10
|
andq %r11, %r10
|
||||||
andq %r9, %r10
|
andq %r9, %r10
|
||||||
jnz .safe_user_strncpy_byte_loop
|
jnz .Lsafe_user_strncpy_byte_loop
|
||||||
|
|
||||||
movq %rax, (%rdi)
|
movq %rax, (%rdi)
|
||||||
|
|
||||||
addq $8, %rdi
|
addq $8, %rdi
|
||||||
addq $8, %rsi
|
addq $8, %rsi
|
||||||
subq $8, %rcx
|
subq $8, %rcx
|
||||||
jnz .safe_user_strncpy_qword_loop
|
jnz .Lsafe_user_strncpy_qword_loop
|
||||||
jmp safe_user_strncpy_fault
|
jmp safe_user_strncpy_fault
|
||||||
|
|
||||||
.safe_user_strncpy_qword_done:
|
.Lsafe_user_strncpy_qword_done:
|
||||||
testq %rcx, %rcx
|
testq %rcx, %rcx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.safe_user_strncpy_byte_loop:
|
.Lsafe_user_strncpy_byte_loop:
|
||||||
movb (%rsi), %al
|
movb (%rsi), %al
|
||||||
movb %al, (%rdi)
|
movb %al, (%rdi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .safe_user_strncpy_done
|
jz .Lsafe_user_strncpy_done
|
||||||
|
|
||||||
incq %rdi
|
incq %rdi
|
||||||
incq %rsi
|
incq %rsi
|
||||||
decq %rcx
|
decq %rcx
|
||||||
jnz .safe_user_strncpy_byte_loop
|
jnz .Lsafe_user_strncpy_byte_loop
|
||||||
|
|
||||||
safe_user_strncpy_fault:
|
safe_user_strncpy_fault:
|
||||||
xorq %rax, %rax
|
xorq %rax, %rax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.safe_user_strncpy_done:
|
.Lsafe_user_strncpy_done:
|
||||||
movb $1, %al
|
movb $1, %al
|
||||||
ret
|
ret
|
||||||
safe_user_strncpy_end:
|
safe_user_strncpy_end:
|
||||||
|
|||||||
+14
-16
@@ -161,12 +161,10 @@ is_64_bit:
|
|||||||
|
|
||||||
check_requirements:
|
check_requirements:
|
||||||
call has_cpuid
|
call has_cpuid
|
||||||
jz .exit
|
jz system_halt
|
||||||
call is_64_bit
|
call is_64_bit
|
||||||
jz .exit
|
jz system_halt
|
||||||
ret
|
ret
|
||||||
.exit:
|
|
||||||
jmp system_halt
|
|
||||||
|
|
||||||
enable_sse:
|
enable_sse:
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
@@ -226,10 +224,10 @@ _start:
|
|||||||
|
|
||||||
# flush gdt and jump to 64 bit
|
# flush gdt and jump to 64 bit
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $V2P(long_mode)
|
ljmpl $0x08, $V2P(.Llong_mode)
|
||||||
|
|
||||||
.code64
|
.code64
|
||||||
long_mode:
|
.Llong_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -240,10 +238,10 @@ long_mode:
|
|||||||
addq $KERNEL_OFFSET, %rsp
|
addq $KERNEL_OFFSET, %rsp
|
||||||
|
|
||||||
# jump to higher half
|
# jump to higher half
|
||||||
movabsq $higher_half, %rcx
|
movabsq $.Lhigher_half, %rcx
|
||||||
jmp *%rcx
|
jmp *%rcx
|
||||||
|
|
||||||
higher_half:
|
.Lhigher_half:
|
||||||
# call global constuctors
|
# call global constuctors
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
@@ -293,18 +291,18 @@ ap_ready:
|
|||||||
.skip 8
|
.skip 8
|
||||||
|
|
||||||
1: cli; cld
|
1: cli; cld
|
||||||
ljmpl $0x00, $AP_REL(ap_cs_clear)
|
ljmpl $0x00, $AP_REL(.Lap_cs_clear)
|
||||||
|
|
||||||
ap_cs_clear:
|
.Lap_cs_clear:
|
||||||
# load ap gdt and enter protected mode
|
# load ap gdt and enter protected mode
|
||||||
lgdt AP_REL(ap_gdtr)
|
lgdt AP_REL(ap_gdtr)
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
orb $1, %al
|
orb $1, %al
|
||||||
movl %eax, %cr0
|
movl %eax, %cr0
|
||||||
ljmpl $0x08, $AP_REL(ap_protected_mode)
|
ljmpl $0x08, $AP_REL(.Lap_protected_mode)
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
ap_protected_mode:
|
.Lap_protected_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -318,14 +316,14 @@ ap_protected_mode:
|
|||||||
|
|
||||||
# load boot gdt and enter long mode
|
# load boot gdt and enter long mode
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $AP_REL(ap_long_mode)
|
ljmpl $0x08, $AP_REL(.Lap_long_mode)
|
||||||
|
|
||||||
.code64
|
.code64
|
||||||
ap_long_mode:
|
.Lap_long_mode:
|
||||||
movq $ap_higher_half, %rax
|
movq $.Lap_higher_half, %rax
|
||||||
jmp *%rax
|
jmp *%rax
|
||||||
|
|
||||||
ap_higher_half:
|
.Lap_higher_half:
|
||||||
movq AP_REL(ap_prepare_paging), %rax
|
movq AP_REL(ap_prepare_paging), %rax
|
||||||
call *%rax
|
call *%rax
|
||||||
|
|
||||||
|
|||||||
@@ -19,20 +19,20 @@ memmove:
|
|||||||
movl 12(%esp), %ecx
|
movl 12(%esp), %ecx
|
||||||
movl %edi, %edx
|
movl %edi, %edx
|
||||||
cmpl %edi, %esi
|
cmpl %edi, %esi
|
||||||
jb .memmove_slow
|
jb .Lmemmove_slow
|
||||||
rep movsb
|
rep movsb
|
||||||
.memmove_done:
|
.Lmemmove_done:
|
||||||
movl 4(%esp), %edi
|
movl 4(%esp), %edi
|
||||||
movl 8(%esp), %esi
|
movl 8(%esp), %esi
|
||||||
movl %edx, %eax
|
movl %edx, %eax
|
||||||
ret
|
ret
|
||||||
.memmove_slow:
|
.Lmemmove_slow:
|
||||||
leal -1(%edi, %ecx), %edi
|
leal -1(%edi, %ecx), %edi
|
||||||
leal -1(%esi, %ecx), %esi
|
leal -1(%esi, %ecx), %esi
|
||||||
std
|
std
|
||||||
rep movsb
|
rep movsb
|
||||||
cld
|
cld
|
||||||
jmp .memmove_done
|
jmp .Lmemmove_done
|
||||||
|
|
||||||
.align 16
|
.align 16
|
||||||
.global memset
|
.global memset
|
||||||
|
|||||||
Reference in New Issue
Block a user