osdev

Should using MOV instruction to set SS to 0x0000 cause fault #GP(0) in 64-bit mode?

血红的双手。 提交于 2021-01-19 21:17:51
问题 This question is inspired by a Reddit question in r/osdev except that this question focuses on the SS register. One may say RTFM (ISA entry for MOV), but when this question comes up it can get varying answers even among OS developers. Question : Should using the MOV instruction to set SS to 0x0000 cause a general protection fault #GP(0) in 64-bit mode? For example: If I am in 64-bit mode with a Current Privilege level (CPL) of 0, should I expect to see a #GP(0) with this code snippet: NULL

General Protection Fault when trying to `sti`

微笑、不失礼 提交于 2021-01-05 09:23:22
问题 Trying to implement hardware interrupts on a test bootloader. Exceptions are working(thus found it is GPF). When trying to sti , a GPF is occured. Here is my main code: cli lgdt [gdt_desc] lidt [idt_desc] mov eax, cr0 or eax, 1 mov cr0, eax jmp 0x8:bit_32 bit_32: [bits 32] mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax mov eax, 0x8000 mov esp, eax mov ebp, esp sti ; exception raised This is how my GDT looks like: start_gdt: null: dd 0x0 dd 0x0 code: dw 0xffff dw 0x0 db

General Protection Fault when trying to `sti`

蹲街弑〆低调 提交于 2021-01-05 09:23:18
问题 Trying to implement hardware interrupts on a test bootloader. Exceptions are working(thus found it is GPF). When trying to sti , a GPF is occured. Here is my main code: cli lgdt [gdt_desc] lidt [idt_desc] mov eax, cr0 or eax, 1 mov cr0, eax jmp 0x8:bit_32 bit_32: [bits 32] mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax mov eax, 0x8000 mov esp, eax mov ebp, esp sti ; exception raised This is how my GDT looks like: start_gdt: null: dd 0x0 dd 0x0 code: dw 0xffff dw 0x0 db

Why did ld turn my 5 lines of library-less C into a 100MB binary?

两盒软妹~` 提交于 2020-08-05 06:15:35
问题 I'm trying to develop some very low-level x86 code following this document. I wrote the following C program: void main() { char* video_memory = (char*) 0xb8000; *video_memory = 'X'; } I compile and link it like so: gcc -m32 -fno-pie -c main.c -o main.o ld -m elf_i386 -o main.bin -Ttext 513 --oformat binary main.o This produces a binary called main.bin which is over a hundred megabytes . I disassembled that binary and it's basically my code (ten or so lines), then a hundred meg of zeros, and

Why did ld turn my 5 lines of library-less C into a 100MB binary?

自闭症网瘾萝莉.ら 提交于 2020-08-05 06:15:31
问题 I'm trying to develop some very low-level x86 code following this document. I wrote the following C program: void main() { char* video_memory = (char*) 0xb8000; *video_memory = 'X'; } I compile and link it like so: gcc -m32 -fno-pie -c main.c -o main.o ld -m elf_i386 -o main.bin -Ttext 513 --oformat binary main.o This produces a binary called main.bin which is over a hundred megabytes . I disassembled that binary and it's basically my code (ten or so lines), then a hundred meg of zeros, and

ARM, VFP, floating-point, lazy context switching

℡╲_俬逩灬. 提交于 2020-07-21 06:37:04
问题 I am writing an operating system for an ARM processor (Cortex-A9). I am trying to implement lazy context switching of the floating-point registers. The idea behind this is that the floating-point extension is initially disabled for a thread and so there is no need to save floating-point context on a task-switch. When a thread attempts to use a floating-point instruction, it triggers an exception. The operating system then enables floating-point extension and knows that floating-point context

What happens when you lose the virtual address of the page directory?

流过昼夜 提交于 2020-06-01 01:40:29
问题 I'm writing a memory manager for my kernel (32 bit x86) In the course of this... I'm facing a bit of a dilemma.... Description of virtual memory map: Identity map of first 4 Mb Virtual address 0xC0000000 mapped to physical address 0x100000 (Also a 4 Mb map) My page directory is at physical address 0x9c000. My page table 1 is at physical address 0x9d000. My page table 2 is at physical addres 0x9e000. (I need only two page tables here :) ... These correspond to the identity map and higher