I'm new in this forum so please correct me if I'm wrong . I'm actually game programmer and I believe I'm coding quite well in C++ with around 3 years of non-stop coding(no social life). However I have no solid knowledge of x86 assembly(though I've played some time with dissassemblers and have made small things in it)
So... I decided to learn how my pc work. I need to write a bootloader. I've been trying to do it for 1 week.(reading ebooks, forums articles, etc)
I'm using nasm and managed to run some code in VirtualBox.
First of all, this is part of the virtual machine's log:
This is the master boot record of my virtual hard disk. (You can ingore my code, as I'll post it in a second, just to see the parameters which were generated when I formatted it with a third party software through ubuntu). Its the modern MBR standart00:00:04.968130 PIIX3 ATA: Ctl#0: RESET, DevSel=1 AIOIf=1 CmdIf0=0xa1 (-1 usec ago) CmdIf1=0xc4 (-1 usec ago)
00:00:04.968161 PIIX3 ATA: Ctl#0: finished processing RESET
00:00:04.968732 Guest Log: BIOS: int13_harddisk: function 02, disk 80, parameters out of range 0000/0020/0021!
and this is my code:EB 00 FA B8 00 00 8E D8 8E C0 8E E0 8E E8 B8 00 04 8E D0 BC 00 00 FB BE 2E 7D E8 F9 00 B2 80 E8 E1 00 BE 41 7D E8 EE 00 B0 01 8A 0E C0 7D 8A 2E C1 7D 8A 36 BF 7D B2 80 E8 CF 00 BE 2E 7D E8 D5 00 E9 BC 85 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 D2 5B F7 37 FE C2 88 16 28 7D 31 D2 5B F7 37 88 16 2A 7D A2 2C 7D C3 83 E8 02 31 C9 5B 8A 0F F7 E1 C3 B4 00 CD 13 72 FA C3 B4 02 CD 13 72 01 C3 E8 EF FF EB F4 AC 08 C0 74 06 B4 0E CD 10 EB F5 C3 00 00 00 00 00 00 00 00 00 00 00 00 4C 61 75 6E 63 68 20 53 75 63 63 65 73 73 66 75 6C 21 00 4F 4B 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8E 55 08 00 00 00 00 20 21 00 0B 28 20 08 00 08 00 00 00 F8 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA
Code: Select all
[BITS 16]
[ORG 0x0000]
jmp loader
;db 0x00
;Function:*****************************************************************
;NAME: loader
;Parameters:***************
;NO
;**************************************************************************
loader:
cli ; clear interrupts
mov ax, 0x07C0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x800
mov ss, ax
mov sp, 0
sti ; enable interrupts
mov si, msg
call Print
;Reset the hard disk
mov dl, 80h
call Reset
mov si, succ
call Print
;set read params
mov al, 1
mov cl, [SSector1]
mov ch, [STrack1]
mov dh, [SHead1]
mov bx, 0x400
mov dl, 80h
call Read
mov si, msg
call Print
jmp 0x400
times 218 - ($-$$) db 0
;End of a function*********************************************************
;**************************************************************************
;Parameter Block:**********************************************************
;NAME: Disk Timestamp
;Size:***************
;6 bytes
;**************************************************************************
dw 0xFFFF ; reserved
HardDrive: db 0xEE ; not mapped in the hard drive. In other words, not used and I don't need it
db 0xCC ; not used
db 0xBB ; not used
db 0xAA ; not used
;End of a param block******************************************************
;**************************************************************************
;Parameters:***************
;Input: dl -> DriveNumber
;**************************
Reset:
;first reset the reader
mov ah, 0x00
int 0x13
jc Reset
ret
;Parameters:***************
;ax - address to read in, dl - drive number
;al - sectors to read(count), ch - track, cl - sector
;dh - head
;**************************
Read:
;now read in the file
mov ah, 0x02 ; what are we doing?
int 0x13 ; call bios
jc GoToReset
ret
GoToReset:
call Reset
jmp Read
;Parameters:***************
;0
;**************************
Print:
lodsb
or al, al
jz PrintDone
mov ah, 0eh
int 10h
jmp Print
PrintDone:
ret
;Variables:****************
;NOT USED; JUST COPIED FROM ONE TUTORIAL
;**************************
first_data_sector: dw 0x0000
working_lba: dd 0x00000000
absoluteSector: dw 0x0000
absoluteHead: dw 0x0000
absoluteTrack: dw 0x0000
msg db "Launch Successful!", 0 ; had some problems with the segments, so I used this to test if its going ok for now.
succ db "OK!",0 ; printing it from time to time to check where the problem is
;**************************
times 440 - ($-$$) db 0
;Parameter Block:**********************************************************
;NAME: Partition Tables
;Size:***************
;72 bytes
;**************************************************************************
DiskSignature: dd 0x00000000
dw 0x0000 ; not used
;Partition Table 1
DiskDrive1: db 0xFF
SHead1: db 0x00
SSector1: db 0x00
STrack1: db 0x00
PartitionType1: db 0x00
EHead1: db 0x00
ESectorTack1: dw 0x0000
StartSector1: dd 0x00000000
SectorCount1: dd 0x00000000
;Partition Table 2
;Partition Table 3
;Partition Table 4
;End of partition tables
times 510 - ($-$$) db 0
dw 0x55AA
;End of a param block******************************************************
;**************************************************************************
So my question is: how do I read the sector at SSector1, STrack1 and SHead1 to 7C00:0x400?
If I haven't given information you need, please ask and I'll answer as soon as I can