Kernel: Fix 32 bit target
Rewrite some assembly and add some required casts
This commit is contained in:
parent
46f9a9053f
commit
09175d1799
|
|
@ -1,12 +1,6 @@
|
||||||
// arguments in EAX, EBX, ECX, EDX, ESI, EDI
|
// arguments in EAX, EBX, ECX, EDX, ESI, EDI
|
||||||
.global asm_syscall_handler
|
.global asm_syscall_handler
|
||||||
asm_syscall_handler:
|
asm_syscall_handler:
|
||||||
# save segment registers
|
|
||||||
pushw %ds
|
|
||||||
pushw %es
|
|
||||||
pushw %fs
|
|
||||||
pushw %gs
|
|
||||||
|
|
||||||
# save general purpose registers
|
# save general purpose registers
|
||||||
pushl %ebx
|
pushl %ebx
|
||||||
pushl %ecx
|
pushl %ecx
|
||||||
|
|
@ -18,13 +12,12 @@ asm_syscall_handler:
|
||||||
|
|
||||||
# align stack
|
# align stack
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
subl $15, %esp
|
andl $-16, %esp
|
||||||
andl $0xFFFFFFF0, %esp
|
|
||||||
|
|
||||||
# push arguments
|
# push arguments
|
||||||
subl $4, %esp
|
subl $4, %esp
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
addl $32, (%esp)
|
addl $24, (%esp)
|
||||||
pushl %edi
|
pushl %edi
|
||||||
pushl %esi
|
pushl %esi
|
||||||
pushl %edx
|
pushl %edx
|
||||||
|
|
@ -44,6 +37,15 @@ asm_syscall_handler:
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
|
|
||||||
|
# restore userspace segments
|
||||||
|
movw $(0x20 | 3), %bx
|
||||||
|
movw %bx, %ds
|
||||||
|
movw %bx, %es
|
||||||
|
movw $(0x30 | 3), %bx
|
||||||
|
movw %bx, %fs
|
||||||
|
movw $(0x38 | 3), %bx
|
||||||
|
movw %bx, %gs
|
||||||
|
|
||||||
# restore general purpose registers
|
# restore general purpose registers
|
||||||
popl %ebp
|
popl %ebp
|
||||||
popl %esi
|
popl %esi
|
||||||
|
|
@ -52,12 +54,6 @@ asm_syscall_handler:
|
||||||
popl %ecx
|
popl %ecx
|
||||||
popl %ebx
|
popl %ebx
|
||||||
|
|
||||||
# restore segment registers
|
|
||||||
popw %gs
|
|
||||||
popw %fs
|
|
||||||
popw %es
|
|
||||||
popw %ds
|
|
||||||
|
|
||||||
iret
|
iret
|
||||||
|
|
||||||
.global sys_fork_trampoline
|
.global sys_fork_trampoline
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ start_kernel_thread:
|
||||||
subl $12, %esp
|
subl $12, %esp
|
||||||
pushl %edi
|
pushl %edi
|
||||||
call *%esi
|
call *%esi
|
||||||
addl $16, %esp
|
|
||||||
|
|
||||||
|
|
||||||
.global start_userspace_thread
|
.global start_userspace_thread
|
||||||
start_userspace_thread:
|
start_userspace_thread:
|
||||||
|
|
@ -41,14 +39,11 @@ start_userspace_thread:
|
||||||
call get_thread_start_sp
|
call get_thread_start_sp
|
||||||
movl %eax, %esp
|
movl %eax, %esp
|
||||||
|
|
||||||
# ds, es = user data
|
|
||||||
movw $(0x20 | 3), %bx
|
movw $(0x20 | 3), %bx
|
||||||
movw %bx, %ds
|
movw %bx, %ds
|
||||||
movw %bx, %es
|
movw %bx, %es
|
||||||
# fs
|
|
||||||
movw $(0x30 | 3), %bx
|
movw $(0x30 | 3), %bx
|
||||||
movw %bx, %fs
|
movw %bx, %fs
|
||||||
# gs
|
|
||||||
movw $(0x38 | 3), %bx
|
movw $(0x38 | 3), %bx
|
||||||
movw %bx, %gs
|
movw %bx, %gs
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,7 @@
|
||||||
.macro push_userspace
|
.macro maybe_load_kernel_segments, n
|
||||||
pushw %gs
|
cmpb $0x08, \n(%esp)
|
||||||
pushw %fs
|
je 1f
|
||||||
pushw %es
|
|
||||||
pushw %ds
|
|
||||||
pushal
|
|
||||||
.endm
|
|
||||||
|
|
||||||
.macro load_kernel_segments
|
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %es
|
movw %ax, %es
|
||||||
|
|
@ -14,19 +9,26 @@
|
||||||
|
|
||||||
movw $0x28, %ax
|
movw $0x28, %ax
|
||||||
movw %ax, %gs
|
movw %ax, %gs
|
||||||
|
1:
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro pop_userspace
|
.macro maybe_load_userspace_segments, n
|
||||||
popal
|
cmpb $0x08, \n(%esp)
|
||||||
popw %ds
|
je 1f
|
||||||
popw %es
|
|
||||||
popw %fs
|
movw $(0x20 | 3), %bx
|
||||||
popw %gs
|
movw %bx, %ds
|
||||||
|
movw %bx, %es
|
||||||
|
movw $(0x30 | 3), %bx
|
||||||
|
movw %bx, %fs
|
||||||
|
movw $(0x38 | 3), %bx
|
||||||
|
movw %bx, %gs
|
||||||
|
1:
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
isr_stub:
|
isr_stub:
|
||||||
push_userspace
|
pushal
|
||||||
load_kernel_segments
|
maybe_load_kernel_segments 44
|
||||||
cld
|
cld
|
||||||
|
|
||||||
movl %cr0, %eax; pushl %eax
|
movl %cr0, %eax; pushl %eax
|
||||||
|
|
@ -34,33 +36,39 @@ isr_stub:
|
||||||
movl %cr3, %eax; pushl %eax
|
movl %cr3, %eax; pushl %eax
|
||||||
movl %cr4, %eax; pushl %eax
|
movl %cr4, %eax; pushl %eax
|
||||||
|
|
||||||
movl %esp, %eax // register ptr
|
movl 48(%esp), %edi // isr number
|
||||||
leal 64(%esp), %ebx // interrupt stack ptr
|
movl 52(%esp), %esi // error code
|
||||||
movl 60(%esp), %ecx // error code
|
leal 56(%esp), %edx // interrupt stack ptr
|
||||||
movl 56(%esp), %edx // isr number
|
movl %esp, %ecx // register ptr
|
||||||
|
|
||||||
|
# stack frame for stack trace
|
||||||
|
leal 56(%esp), %eax
|
||||||
|
pushl (%eax)
|
||||||
|
pushl %ebp
|
||||||
|
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
andl $-16, %esp
|
andl $-16, %esp
|
||||||
|
|
||||||
pushl %eax
|
|
||||||
pushl %ebx
|
|
||||||
pushl %ecx
|
pushl %ecx
|
||||||
pushl %edx
|
pushl %edx
|
||||||
|
pushl %esi
|
||||||
|
pushl %edi
|
||||||
call cpp_isr_handler
|
call cpp_isr_handler
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
addl $16, %esp
|
addl $24, %esp
|
||||||
|
|
||||||
pop_userspace
|
maybe_load_userspace_segments 44
|
||||||
|
popal
|
||||||
addl $8, %esp
|
addl $8, %esp
|
||||||
iret
|
iret
|
||||||
|
|
||||||
irq_stub:
|
irq_stub:
|
||||||
push_userspace
|
pushal
|
||||||
load_kernel_segments
|
maybe_load_kernel_segments 44
|
||||||
cld
|
cld
|
||||||
|
|
||||||
movl 40(%esp), %edi # interrupt number
|
movl 32(%esp), %edi # interrupt number
|
||||||
|
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
andl $-16, %esp
|
andl $-16, %esp
|
||||||
|
|
@ -71,7 +79,8 @@ irq_stub:
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
|
|
||||||
pop_userspace
|
maybe_load_userspace_segments 44
|
||||||
|
popal
|
||||||
addl $8, %esp
|
addl $8, %esp
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
|
@ -99,8 +108,8 @@ asm_yield_handler:
|
||||||
|
|
||||||
.global asm_ipi_handler
|
.global asm_ipi_handler
|
||||||
asm_ipi_handler:
|
asm_ipi_handler:
|
||||||
push_userspace
|
pushal
|
||||||
load_kernel_segments
|
maybe_load_kernel_segments 36
|
||||||
cld
|
cld
|
||||||
|
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
|
|
@ -110,13 +119,14 @@ asm_ipi_handler:
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
|
|
||||||
pop_userspace
|
maybe_load_userspace_segments 36
|
||||||
|
popal
|
||||||
iret
|
iret
|
||||||
|
|
||||||
.global asm_timer_handler
|
.global asm_timer_handler
|
||||||
asm_timer_handler:
|
asm_timer_handler:
|
||||||
push_userspace
|
pushal
|
||||||
load_kernel_segments
|
maybe_load_kernel_segments 36
|
||||||
cld
|
cld
|
||||||
|
|
||||||
movl %esp, %ebp
|
movl %esp, %ebp
|
||||||
|
|
@ -126,7 +136,8 @@ asm_timer_handler:
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
|
|
||||||
pop_userspace
|
maybe_load_userspace_segments 36
|
||||||
|
popal
|
||||||
iret
|
iret
|
||||||
|
|
||||||
.macro isr n
|
.macro isr n
|
||||||
|
|
|
||||||
|
|
@ -856,7 +856,7 @@ acpi_release_global_lock:
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: EC can also reside in memory space
|
// TODO: EC can also reside in memory space
|
||||||
auto crs_buffer = BAN::ConstByteSpan { crs.as.str_buf->bytes, crs.as.str_buf->size };
|
auto crs_buffer = BAN::ConstByteSpan { crs.as.str_buf->bytes, static_cast<size_t>(crs.as.str_buf->size) };
|
||||||
const auto data_port = TRY(extract_io_port(crs_buffer));
|
const auto data_port = TRY(extract_io_port(crs_buffer));
|
||||||
const auto command_port = TRY(extract_io_port(crs_buffer));
|
const auto command_port = TRY(extract_io_port(crs_buffer));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ namespace Kernel
|
||||||
gdt->write_entry(0x20, 0x00000000, 0xFFFFF, 0xF2, data_flags); // user data
|
gdt->write_entry(0x20, 0x00000000, 0xFFFFF, 0xF2, data_flags); // user data
|
||||||
#if ARCH(i686)
|
#if ARCH(i686)
|
||||||
gdt->write_entry(0x28, reinterpret_cast<uint32_t>(processor), sizeof(Processor), 0x92, 0x4); // processor data
|
gdt->write_entry(0x28, reinterpret_cast<uint32_t>(processor), sizeof(Processor), 0x92, 0x4); // processor data
|
||||||
gdt->write_entry(0x30, 0x00000000, 0x00000, 0x00, 0x0); // fsbase
|
gdt->write_entry(0x30, 0x00000000, 0x00000, 0xF2, data_flags); // fsbase
|
||||||
gdt->write_entry(0x38, 0x00000000, 0x00000, 0x00, 0x0); // gsbase
|
gdt->write_entry(0x38, 0x00000000, 0x00000, 0xF2, data_flags); // gsbase
|
||||||
#endif
|
#endif
|
||||||
gdt->write_tss();
|
gdt->write_tss();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ namespace Kernel::Input
|
||||||
result.type = type;
|
result.type = type;
|
||||||
|
|
||||||
BAN::Optional<ACPI::ResourceData> data;
|
BAN::Optional<ACPI::ResourceData> data;
|
||||||
ACPI::ResourceParser parser({ crs_obj->node.as.str_buf->bytes, crs_obj->node.as.str_buf->size });
|
ACPI::ResourceParser parser({ crs_obj->node.as.str_buf->bytes, static_cast<size_t>(crs_obj->node.as.str_buf->size) });
|
||||||
while ((data = parser.get_next()).has_value())
|
while ((data = parser.get_next()).has_value())
|
||||||
{
|
{
|
||||||
switch (data->type)
|
switch (data->type)
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ namespace Kernel
|
||||||
|
|
||||||
vaddr_t vaddr = userspace_stack_top() - needed_size;
|
vaddr_t vaddr = userspace_stack_top() - needed_size;
|
||||||
|
|
||||||
const size_t page_count = BAN::Math::div_round_up(needed_size, PAGE_SIZE);
|
const size_t page_count = BAN::Math::div_round_up<size_t>(needed_size, PAGE_SIZE);
|
||||||
for (size_t i = 0; i < page_count; i++)
|
for (size_t i = 0; i < page_count; i++)
|
||||||
TRY(m_userspace_stack->allocate_page_for_demand_paging(vaddr + i * PAGE_SIZE));
|
TRY(m_userspace_stack->allocate_page_for_demand_paging(vaddr + i * PAGE_SIZE));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue