osdev

Linking 32- and 64-bit code together into a single binary

廉价感情. 提交于 2019-12-10 20:53:55
问题 In a comment to this question, Unexpected behaviour in simple pointer arithmetics in kernel space C code, Michael Petch wrote, "The 64-bit ELF format supports 32-bit code sections." I have a working program that includes both 32- and 64-bit code and switches between them. I have never been able to figure out how to link compiler-generated 32- and 64-bit code together without a linker error, so all the 32-bit code is written in assembly. As the project has become more complex, maintenance of

What happens to a Startup IPI sent to an Active AP that is not in a Wait-for-SIPI state

别说谁变了你拦得住时间么 提交于 2019-12-10 19:24:07
问题 In a previous Stackoverflow answer Margaret Bloom says: Waking the APs This is achieved by inssuing a INIT-SIPI-SIPI (ISS) sequence to the all the APs. The BSP that will send the ISS sequence using as destination the shorthand All excluding self, thereby targeting all the APs. A SIPI (Startup Inter Processor Interrupt) is ignored by all the CPUs that are waked by the time they receive it, thus the second SIPI is ignored if the first one suffices to wake up the target processors. It is advised

Why does passing a char to a function change it's value in c?

為{幸葍}努か 提交于 2019-12-10 18:15:47
问题 I am currently following this workbook on build an operating system. My intention is to write a 64-bit kernel. I have got as far as loading the "kernel" code and writing individual characters to the frame buffer while in text mode. My problem appears when I add a level of indirection to writing a single character to the frame buffer by wrapping the code in a function. It would appear that the char value passed into the function is being corrupted in some way. I have three files: bootloader

Confused with CMPSB instruction

非 Y 不嫁゛ 提交于 2019-12-10 14:20:15
问题 I have been looking at this code and I'm confused about the rep cmpsb line. .LOOP: push cx mov cx, 0x000B ; eleven character name mov si, ImageName ; image name to find push di rep cmpsb ; test for entry match pop di je LOAD_FAT pop cx add di, 0x0020 ; queue next directory entry loop .LOOP jmp FAILURE I understand that it repeats cmpsb cx times but how does this compare the two strings? Say for example was comparing "Hey\0" and "hey\0" and this loop was comparing 4 character strings. The

Why do interrupts need to be disabled before switching to protected mode from real mode?

為{幸葍}努か 提交于 2019-12-10 13:36:59
问题 I saw in many many oses (and some bootloader), they all disable interrupt ( cli ) before switch to protected mode from real mode. Why we need do that? 回答1: BIOSes use PIT interrupt (IRQ0) to track time. As soon as you enter protected mode, real mode interrupt handling is no longer valid; CPU in protected mode requires protected mode IDT (Interrupt Descriptor Table). Upon entering protected mode, IDT limit in IDTR (IDT Register) is set to 0 (any interrupt number makes CPU generate an exception

Loading elf-i386 from my boot loader

▼魔方 西西 提交于 2019-12-10 12:00:42
问题 I am doing operating system project, until now I have my bootloader running. I can load binary file using bios interuppt, but I am unable to load and call C function from ELF file format: Here is my C program that I want to finally execute: //build :: cc -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -c -o kmain.o kmain.c void kmain(){ int a = 5; for(;;); } Here is assembly code to call kmain() ; build :: nasm -f elf loader.asm [BITS 32] [GLOBAL start] [EXTERN kmain] section .text

How can CAS simulators like PTLsim achieve cycle accurate simulation of x86 hardware?

混江龙づ霸主 提交于 2019-12-09 03:42:14
问题 Can somebody enlighten me how does CAS software like http://www.ptlsim.org/ work? How do they achieve cycle accuracy if there is neither information how many cycles are used per instruction nor CPU branch prediction logic is known? Or is everything available over NDAs? I suppose they probably can be pretty accurate with caches being hit or missed (maybe I'm wrong but I think it's easier to predict the internal algorithm), but without knowledge how pipelining and superscalarity are implemented

LD errors while linking 16-bit real mode code into a Multiboot compliant ELF executable

百般思念 提交于 2019-12-09 00:57:09
问题 I'm writing a Multiboot compliant ELF executable containing my 32-bit kernel. My primary problem is that I'm receiving a series of linker errors while producing my executable: relocation truncated to fit: R_386_16 against `.text' Linker Script, Code and Build script below I have decided to try implementing VESA VBE graphics in my OS. I found an existing VESA driver in the OSDev forum and I tried to integrate it into my own OS. I tried adding it to my source directory, assembled it with NASM

BIOS Interrupts in protected mode

*爱你&永不变心* 提交于 2019-12-08 17:20:47
问题 I'm working on an operating system project, using isolinux (syslinux 4.5) as bootloader, loading my kernel with multiboot header organised at 0x200000. As I know the kernel is already in 32-bit protected mode. My question: Is there any easier way to get access to BIOS Interrupts? (Basically I want 0x10 :D) After loading, my kernel sets up its own GDT and IDT entries and further remaps IRQs. So, is it possible to jump into real mode just after the kernel is loaded and set up VGA/SVGA modes

%sp register doesn't point to stack

有些话、适合烂在心里 提交于 2019-12-08 07:40:58
问题 I'm writing on a very basic kernel. I tried to write a function, with parameters passed through the stack. The kernel is compiled with nasm (like described in this question) and run with QEMU. I'm using gdb for debugging. After a long while having problems I wrote this to test some basic stack operations: BITS 16 global start start: mov ax, 0x7C00 add ax, 288 mov ss, ax mov sp, 4096 mov ax, 0x7C00 mov ds, ax test: push 42 push 43 push "T" pop ax pop ax push 44 pop ax pop ax jmp $ Going