osdev

Doing a indirect far jump/call in protected mode

梦想的初衷 提交于 2019-12-06 01:14:59
How do I perform an indirect far jump/call in protected mode? First I was thinking that doing this is allowable: jmp 0x10:eax; (Don't worry about the segment selector..the 2nd entry of my GDT is a valid code segment) But when nasm assembled it, it was a syntax error. Looking at the Book 2a of the Intel (instruction set reference) manual, it can only be done using jmp ptr16:32 , where the ptr16:32 is an immediate value, or using jmp m16:32 , where the m16:32 is a memory location containing the 48-bit jump address (the 16:32). Now I tried to encode it this way: mov dword[ds:jumpaddress_offset]

Triple fault when jumping into protected mode

折月煮酒 提交于 2019-12-05 14:41:38
I'm developing a boot loader, which will boot into a simple kernel after switching into protected mode. I used this paper as a tutorial, somewhere in chapter four or five. In theory it is supposed to start in 16-bit real mode, load the kernel into memory, switch to 32-bit protected mode and start executing the kernel code. However, when I switch into protected mode and far jump or jump to another segment, it triple faults. Here is the main boot sector code: [org 0x7c00] KERNEL_OFFSET equ 0x1000 mov [BOOT_DRIVE], dl ;Get the current boot drive from the BIOS mov bp, 0x9000 ;Set up stack, with

How can I JMP to relocated code in my MBR?

不想你离开。 提交于 2019-12-05 13:41:45
I'm trying to write an extremely simple MBR to start learning how to write an MBR/Kernel. This is what I have so far (created from pieces of other MBRs). The binary I get from using nasm and then ld to link is a bit different from just using nasm for both, but that doesn't appear to be the problem. I first started with jmp 0:continue but that appears to jump to 0000:7c22 (or 001d with nasm alone... i believe i didnt specify that it starts at 7c00 ) but im looking to jump to :7a22 or :7a1d , the address of the relocated code. I tried using just jmp continue and then as seen uncommented below,

GCC code that seems to break inline assembly rules but an expert believes otherwise

一个人想着一个人 提交于 2019-12-05 08:01:59
I was engaged with an expert who allegedly has vastly superior coding skills than myself who understands inline assembly far better than I ever could. One of the claims is that as long as an operand appears as an input constraint, you don't need to list it as a clobber or specify that the register has been potentially modified by the inline assembly. The conversation came about when someone else was trying to get assistance on a memset implementation that was effectively coded this way: void *memset(void *dest, int value, size_t count) { asm volatile ("cld; rep stosb" :: "D"(dest), "c"(count),

Return value of a C function to ASM

淺唱寂寞╮ 提交于 2019-12-04 17:48:05
问题 I'm trying to call a function from within ASM. I know how to call it, but i'm having trouble finding how to get the return value of this function. An example follows: C code: int dummy() { return 5; } (N)ASM code: dummyFunction: call dummy ;grab return into eax inc eax ; eax should be 6 now ret Any ideas? 回答1: The return value is in eax . If you've called a C function from asm, you can read the return value from eax . If you're trying to return from an asm function to C, store the intended

Keyboard interrupt handler for own kernel (C)

孤街浪徒 提交于 2019-12-04 13:15:04
I am writing a tiny OS as part of an assigment for school,but I got stuck when it comes to get keyboard input (press a key -> display it on screen). I am using the Bare Bones tutorial from osdev.org (gcc cross-compiler, GRUB bootloader, ld linker) and since I am in protected mode I can not use BIOS interrupts for input, that's why I have to write my own interrupt handler (?) but I'm not sure how to do that even after I read some osdev articles and forum discussions. Very similar problem ( http://forum.osdev.org/viewtopic.php?f=1&t=9746 ) except that I don't know how to "set up the interrupts".

Linking a file using ld to output a binary file gives error in OS development

吃可爱长大的小学妹 提交于 2019-12-04 13:09:40
I am learning Operating system tutorials. I created 2 files. boot.asm kernel.c The kernel.c is as follows : int main() { char *src = (char *)0xB8000000L; *src = 'M'; src += 2; *src = 'D'; return 0; } The kernel is used to write a character to the text mode video display area. The kernel was compiled using Windows version of GCC with: gcc -ffreestanding -c -m16 kernel.c -o kernel.o I link the kernel object to a binary file using LD : ld -Ttext 0x10000 --oformat binary -o kernel.bin kernel.o The error I get is: ld : cannot link the file which is not PE executable type Can anybody solve this

Toy OS Filesystem [closed]

懵懂的女人 提交于 2019-12-04 11:43:42
I have developed a basic kernel in assembly/c that runs a basic terminal. I have set it up to run off of an iso with grub. I would like to continue this OS, but without a file system, I feel as if there's really nothing else I could do. After much time on the internet, I have come up with really nothing I can do to implement this. People have said implement FAT or make a VFS, but nothing any further, nor tutorials, nor any references to anywhere. Could someone explain how a file system works, where I can get started/where I can connect a pre-made system, and how to use it? Also, I do not have

Simple C Kernel char Pointers Aren't Working

泄露秘密 提交于 2019-12-04 11:03:18
I am trying to make a simple kernel using C. Everything loads and works fine, and I can access the video memory and display characters, but when i try to implement a simple puts function for some reason it doesn't work. I've tried my own code and other's. Also, when I try to use a variable which is declared outside a function it doesn't seem to work. This is my own code: #define PUTCH(C, X) pos = putc(C, X, pos) #define PUTSTR(C, X) pos = puts(C, X, pos) int putc(char c, char color, int spos) { volatile char *vidmem = (volatile char*)(0xB8000); if (c == '\n') { spos += (160-(spos % 160)); }

How can I build a small operating system on an old desktop computer? [closed]

江枫思渺然 提交于 2019-12-04 07:17:42
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . This might be in vain, as I know writing an operating system is unbearably complicated (especially by oneself). I don't expect to build the next linux, or windows. I know it will be horrible, and buggy, and won't work, but that's fine. I want to write everything myself, in