assembly - Having Trouble Saving Boot Sector On Disk And OS On Disk Then Loading It In Memory -


background information

i developing simple dos os. not planning enter in protected mode anytime soon. os written in assembly; nasm syntax way. boot sector supposed save boot sector on first sector of hard disk, , os' code on second sector. can boot hard disk, , not cd image.

the issue

the problem boot sector seems save on hard disk. when restart vmware player, , eject virtual cd-rom. boots background green color (figure 1.1). can mean boot sector isn't loading second sector @ address 0x7e00, , fails jump. weird thing carry flag not being set, assuming no error has occurred. when boot cd-rom image, shows fine in (figure 1.2). when restart , boot hard disk fails jump os should have been loaded @ 0x7e00. boot sector loaded @ 0x7c00. assuming segment address correct, maybe offset address incorrect, or maybe disk writing , reading totally wrong?

things os has accomplished

  • basic system calls in form of software interrupts. modified ivt (interrupt vector table)

  • load boot sector on primary hard disk, , bios can load boot sector hard disk memory location 0x7c00

the code might causing issue

here boot.asm code:

[org 0x7c00] ; bios loads @ 0x7c00 in memory  jmp start  %include "c:\users\osdev\os-src\monsteros\source\syscalls\syscalls.inc"  start:  xor ax, ax ; make 0 mov ds, ax ; data segment 0  ;set desired video mode (graphics mode) mov ah, 0 mov al, 12h int 10h  call init_int  ;set desired background color (green) mov ah, 0x0b  mov bh, 0 mov bl, 2 int 10h   ; display box shaped cursor  mov ch, 0 mov cl, 7 mov ah, 1 int 10h   ;save bootloader on disk   xor ax, ax mov es, ax    ; es <- 0 mov cx, 1    ; cylinder 0, sector 1 mov dx, 0080h ; dh = 0 (head), drive = 80h (0th hard disk) mov bx, 7c00h ; segment offset of buffer mov ax, 0301h ; ah = 03 (disk write), al = 01 (number of sectors write) int 13h  ;save os on disk   xor ax, ax mov es, ax    ; es <- 0 mov cx, 2     ; cylinder 0, sector 2 mov dx, 0080h ; dh = 0 (head), drive = 80h (0th hard disk) mov bx, 7e00h ; segment offset of buffer mov ax, 0301h ; ah = 03 (disk write), al = 01 (number of sectors write) int 13h  ;load os disk @ 0x7e00  xor ax, ax mov es, ax    ; es <- 0 mov cx, 2     ; cylinder 0, sector 2 mov dx, 0080h ; dh = 0 (head), drive = 80h (0th hard disk) mov bx, 7e00h ; segment offset of buffer mov ax, 0201h ; ah = 02 (disk read), al = 01 (number of sectors read) int 13h jc err   jmp 0h:0x7e00 ; jump os  err:  mov ax, err_msg mov bh, 0 mov bl, 0xf int 21h ; print error message  err_msg: db 'error failed load os disk!', 0  times 510-($-$$) db 0    db 0x55    db 0xaa 

here os.asm:

[org 0x7e00]    xor ax, ax ; make 0 mov ds, ax ; data segment 0 mov es, ax    ; clear screen  int 27h  ;set desired background color (green) mov ah, 0x0b  mov bh, 0 mov bl, 2 int 0x10      ; display box shaped cursor  mov cx, 0607h  mov ah, 1 int 10h  ; print desired message  mov ax, msg mov bh, 0 mov bl, 0xf int 21h   int 23h ; print newline    hang:      mov ax, buffer     int 25h ; size(buffer)      mov ax, buffer     int 24h ;zero(buffer)      ; print desired message      mov ax, cli_msg     mov bh, 0     mov bl, 0xf      int 21h ; print ax=msg bl=blue      ; input     mov bx, buffer     int 22h ; read keyboard , print string line feed      ; echo string stored @ address buffer      mov ax, buffer     mov bh, 0     mov bl, 0xf     int 21h ;       int 23h ; print newline      jmp hang  msg: db 'welcome monsteros!', 0 cli_msg: db 'monsteros> ', 0 buffer: times 64 db 0 

here script build.bat code:

nasm -f bin c:\users\osdev\os-src\monsteros\source\boot.asm -o c:\users\osdev\os-src\monsteros\bin\boot.bin  nasm -f bin c:\users\osdev\os-src\monsteros\source\os.asm -o c:\users\osdev\os-src\monsteros\bin\os.bin  copy /b c:\users\osdev\os-src\monsteros\bin\boot.bin + c:\users\osdev\os-src\monsteros\bin\os.bin c:\users\osdev\os-src\monsteros\bin\img.bin miso c:\users\osdev\os-src\monsteros\bin\os.iso -ab c:\users\osdev\os-src\monsteros\bin\img.bin 

post script

the interrupt 21h, 22h, 23h,24h,25h,26h, custom software interrupts wrote os. if have more question or need more code or info, here provide more information.

the solution

for care, solved writing img.bin in vhd created virtualbox , booted vhd. works charm. used hex editor way.

figure 1.1 figure 1.1

figure 1.2 figure 1.2

okay, you're excused. nobody born knowing stuff!

going when worked (your figure 1.2), "must have" read sector 2 cd image 0x7e00 - similar @ end of bootsector, different drive (dl). i'm guessing bios thinks cd image drive 0. boot drive number should in dl, might able leave alone (make dh 0, though). after doing this, can write 0x7c00 hard drive (drive 80h) sector 1 , 0x7e00 drive 80h sector 2 - you're doing. want every time boot?

what do, after copying boot.bin , os.bin img.bin, write img.bin hard drive using... john fine's partcopy if can find that, or rawwrite, or port of dd (a unix utility). or can debug. or isn't hard write little program it. should able boot hard drive, skipping iso , cd image entirely.

bios loads sector 1 0x7c00, after it's boot code load sector 2 0x7e00 , jump it... or write hard drive, read , jump it, seems pointless on every boot.

as os grows, it'll take more 1 sector, you'll need read more 1 sector. if code working, crashes when add 1 more function, what's happening. fixed - keep eye on size of os.bin, , read more sectors if/when exceeds 512 bytes.

minor nit: if error message gets printed, you'll "fall through" trying execute message , on "into woods". put hang: jmp hang after printing catch it. you're not getting error (carry flag) because code happily writing 0x7e00 disk , reading back, though there's no "code" there. think that's what's happening...

one thing watch out for: bios thinks hard drive booted "drive 80h". if boot other drive, drive want write bootsector , os may drive 81h or 82h or ???. careful!


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -