osdev

Error while creating a bootable floppy that contains a bootloader and a kernel

北城余情 提交于 2019-12-02 04:23:06
I'm trying to create a bootable floppy drive for my boot.bin and kernel.bin files. My boot.asm code is: bits 16 section .text start: JMP MAIN WAIT_FOR_KEY: MOV AH, 00H INT 16H RET CLEAR: MOV AH, 0H ;CHANGING THE VIDEO MODE TO CLEAR THE SCREEN MOV AL, 03H ;VIDEO MODE COD INT 10H RET LOG_TO_HTS: PUSH BX PUSH AX MOV BX, AX MOV DX, 0 DIV WORD[ALL_SECTORS] ADD DL, 01H MOV CL, DL MOV AX, BX MOV DX, 0 DIV WORD [ALL_SECTORS] MOV DX, 0 DIV WORD[FACES] MOV DH, DL MOV CH, AL POP AX POP BX MOV DL, BYTE [BOOT_DEVICE] RET ECHO: ;-=-=-=PRINTING FUNCTION =-=-=-; LODSB ;MOV ONE CHAR FROM SI TO AL AND DELETE IT

Keyboard interrupt in x86 protected mode causes processor error

点点圈 提交于 2019-12-02 01:35:20
I'm working on a simple kernel and I've been trying to implement a keyboard interrupt handler to get rid of port polling. I've been using QEMU in -kernel mode (to reduce compile time, because generating the iso using grub-mkrescue takes quite some time) and it worked just fine, but when I wanted to switch to -cdrom mode it suddenly started crashing. I had no idea why. Eventually I've realized that when it boots from an iso it also runs a GRUB bootloader before booting the kernel itself. I've figured out GRUB probably switches the processor into protected mode and that causes the problem . the

INT 13, 2 hanging on x86 real mode when trying to read sectors from floppy drive

好久不见. 提交于 2019-12-02 00:21:44
问题 I'm writing a DOS clone for a school project and I'm trying to read some sectors from a floppy drive (mainly the root directory of a FAT12 file system, sector 19) using BIOS INT 13, 2. I set the parameters right - or at least I think I do so - and then call INT 0x13 with AH = 2. Then, though, the system hangs. I can't figure why. I'm using the following code to call the interrupt: mov ah, 0x2 ;Read sectors function mov al, 1 ;I want to read one sector mov ch, 0 ;From track 0 mov cl, 2 ;Sector

Rustc/LLVM generates faulty code for aarch64 with opt-level=0

孤人 提交于 2019-12-01 18:14:59
I have two files which are assembled/compiled/linked into minimalistic kernel. start.s: .set CPACR_EL1_FPEN, 0b11 << 20 .set BOOT_STACK_SIZE, 8 * 1024 .global __boot_stack .global __start .global __halt .bss .align 16 __boot_stack: .fill BOOT_STACK_SIZE .text __start: /* disable FP and SIMD traps */ mov x0, #CPACR_EL1_FPEN msr cpacr_el1, x0 /* set stack */ adr x0, __boot_stack add sp, x0, #BOOT_STACK_SIZE /* call the Rust entry point */ bl __boot __halt: /* halt CPU */ wfi b __halt boot.rs: #[no_mangle] pub extern fn __boot() { unsafe { let ptr = 0x9000000 as *mut u8; *ptr = '!' as u8; } } For

Rustc/LLVM generates faulty code for aarch64 with opt-level=0

爷,独闯天下 提交于 2019-12-01 17:57:28
问题 I have two files which are assembled/compiled/linked into minimalistic kernel. start.s: .set CPACR_EL1_FPEN, 0b11 << 20 .set BOOT_STACK_SIZE, 8 * 1024 .global __boot_stack .global __start .global __halt .bss .align 16 __boot_stack: .fill BOOT_STACK_SIZE .text __start: /* disable FP and SIMD traps */ mov x0, #CPACR_EL1_FPEN msr cpacr_el1, x0 /* set stack */ adr x0, __boot_stack add sp, x0, #BOOT_STACK_SIZE /* call the Rust entry point */ bl __boot __halt: /* halt CPU */ wfi b __halt boot.rs: #

Call a raw address from Rust

穿精又带淫゛_ 提交于 2019-12-01 17:56:27
I am writing an OS in Rust and need to directly call into a virtual address that I'm calculating (of type u32 ). I expected this to be relatively simple: let code = virtual_address as (extern "C" fn ()); (code)(); However, this complains that the cast is non-primitive. It suggests I use the From trait, but I don't see how this could help (although I am relatively new to Rust and so could be missing something). error[E0605]: non-primitive cast: `u32` as `extern "C" fn()` --> src/main.rs:3:16 | 3 | let code = virtual_address as (extern "C" fn ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note

Problem switching to v8086 mode from 32-bit protected mode by setting EFLAGS.VM to 1

我只是一个虾纸丫 提交于 2019-12-01 15:00:57
问题 I'm in 32-bit protected mode running at current privilege level (CPL=0). I'm trying to enter v8086 mode by setting EFLAGS.VM (Bit 17) flag to 1 (and IOPL to 0) and doing a FAR JMP to my 16-bit real mode code. I get the current flags using PUSHF; set EFLAGS.VM (bit 17) to 1; set EFLAGS.IOPL (bit 22 and bit 23) to 0; set the new EFLAGS with POPF. The code for this looks like: bits 32 cli [snip] pushf ; Get current EFLAGS pop eax or eax, 1<<EFLAGS_VM_BIT ; Set VM flag to enter v8086 mode and eax

Moving text mode cursor not working

大憨熊 提交于 2019-12-01 09:26:01
问题 I have been working on moving the text mode cursor in the operating system I am currently developing. I am having trouble getting it to show up at all. Here is the code that I use to update the cursor: void update_cursor() { unsigned char cursor_loc = (y_pos*Cols)+x_pos; // cursor LOW port to vga INDEX register outb(0x3D4, 0x0F); outb(0x3D5, (unsigned char)(cursor_loc)); // cursor HIGH port to vga INDEX register outb(0x3D4, 0x0E); outb(0x3D5, (unsigned char)((cursor_loc>>8))); } static inline

Booting a non-multiboot kernel with GRUB2 [closed]

馋奶兔 提交于 2019-12-01 08:18:56
I want to boot a custom kernel (non-multiboot) with GRUB2, I've read that I need grub.cfg like this: menuentry "custom kernel" { set root=(hd0,0) chainloader +1 } So, I have some questions: How grub detect kernel? (with multiboot spec I used kernel /boot/kernel.bin ) How my kernel must look like (sorry for my bad english)? Must it be 512 bytes at all (like custom bootloader, which loaded into 0x7c00)? (hd0,0) is hard drive partition and what I must put if I use CD? Maybe (cdrom0,0) ? To boot Linux kernel we can use linux command, can I use it to boot my custom kernel (with some changes)? Will

VirtualBox - No bootable medium found

天涯浪子 提交于 2019-12-01 07:47:58
There are a lot of question on stackoverflow with the similar title. I read all of them, but none of them answers my problem. This is why I opened this question. I am creating an operating system in assembler and C. I found that I must compile C code to binary format, extract text section and save it as a file, then convert it to ISO, then mount it to virtual optical dive of diskete and then load my OS in VirtualBox. So, that is a lot of work I want to avoid. I don't want to convert my binary file to ISO every time. So, I decided to put the binary machine code of my OS to virtual hard drive (