Its simply the same as master was posting apart from i have had to change a few of the printf statements because the compiler is supplying negative values on output (signed values instead of unsigned)
Code:typedef unsigned char BYTE; typedef short int WORD; typedef long DWORD; typedef struct _BOOT_SECTOR { BYTE jumpCode[3]; BYTE oemName[8]; WORD bytes_Sector; BYTE sec_Cluster; WORD size_Sector_Reserved; BYTE fatCount; WORD Max_Root_Entry; WORD Total_Sector_FS; BYTE Media_Type; WORD sectors_per_fat; WORD sectors_per_track; WORD total_Head_Count; WORD no_Sectors_Before_Part; WORD no_Sector_FS32; BYTE BIOS_13h_Drive_No; BYTE reserved; BYTE ext_Boot_Part_Signature; WORD vol_Serial_Number; BYTE vol_Label_Name[11]; BYTE FS_Type[8]; BYTE boot_Code[448]; WORD signature; } BS; BS _boot; unsigned char* memsectptr = (unsigned char *)0x10000000; cyl = 0; /*first cylinder*/ hd = 0; /* first head*/ sect = 1; /*sector 1*/ asm { mov bx, 0x1000; mov es,bx; mov bx,0; mov ah,02; /* BIOS read command */ mov al,1; /*read 1 sector */ mov ch,cyl; /*cylinder */ mov cl,sect; /*start @ sector 1 */ mov dh,hd; /*head */ mov dl,dr; /*drive */ int 0x13; /*run code*/ mov status,ah; } memcpy(&_boot, memsectptr, 512); printf("Floppy Disk Information: \n"); printf("===========================\n"); printf("Assembly Instruction to jump to Boot code: 0x%x\n", _boot.jumpCode); printf("OEM Name: %s\n",&_boot.oemName); printf("Bytes per sector: %u\n",_boot.bytes_Sector); printf("Sector per cluster: %d\n", _boot.sec_Cluster); printf("Size in sector for reserved area(Boot Sector): %d\n",_boot.size_Sector_Reserved); printf("Number of FATs(File Allocation Table): %d\n",_boot.fatCount); printf("Number of files for root directory: %d\n", _boot.Max_Root_Entry); printf("Number of Sectors in File System: %d\n", _boot.Total_Sector_FS); printf("Media Type\n(According to Microsoft,0xF8 == fixed disk and 0xF0 == Removable disk):0x%x\n", _boot.Media_Type); printf("Number of Sectors for each FAT: %d\n", _boot.sectors_per_fat); printf("Sectors per track: %u\n", _boot.sectors_per_track); printf("Number of head in storage device: %d\n", _boot.total_Head_Count); printf("BIOS INT13h Drive number: 0x%x\n", _boot.BIOS_13h_Drive_No); printf("Volume Serial Number: %lu\n", _boot.vol_Serial_Number); printf("Volume label Name: %s\n", &_boot.vol_Label_Name); printf("Boot Sector Signature: 0x%x\n", _boot.signature);
Change
toCode:printf("OEM Name: %s\n",&_boot.oemName);
The OEM name is not guaranteed to be null-padded.Code:printf("OEM Name: %8c\n",_boot.oemName);
Thanks for getting back to me on this dargueta. This is now restricting the length of the string (have done the same for the volume label as well) but now it isn't displaying the text which was previously being displayed (MSDOS 5.0 for OEM NAME and FAT12... for VolLabel) The hex output on the jumpcode etc is also not being displayed correctly. I know what the values of these fields should be as i'm running winHex to display the bootsector to me but really need this coded solution to work!
Thanks,
Dinklebaga
I didn't see that, actually. The boot code isn't a single number, but actually three individual bytes. Display it as such:
The same should be done with the boot sector signature, since the code is 55AAH and not AA55H as a little-endian machine would display it. A shortcut: instead of putting "0x%x" in your printf strings, just put "%#x". It should do the same thing, and will work for any base, including octal and decimal.Code:printf("Boot code: %02X %02X %02X\n",_boot.jumpCode[0],_boot.jumpCode[1],_boot.jumpCode[2]);
Also, several things wrong with the way you're retrieving the boot sector:
1) You don't save ES. That's potentially disastrous. Stick in push es as the first line, and pop es as the last line in that block.
2) Hard-coded pointers: BAD. Each program runs in its own address space, and you have no idea what you're overwriting. You're better off using the address operator and loading the data directly into your BS structure.
3) Interrupts - NO! This will crash in 32-bit Windows for sure, it's slow, and not guaranteed to work on all computers, even ones with the same OS. Use operating system API. I can show you how to do this on a Windows machine, and you can probably find docs on how to do it on other OSes. If you want an explanation of why this'll crash, I'll be more than happy to write a detailed explanation for you.
So what exactly are you getting for the OEM and volume label, then?
Thanks dargueta,
now when i run the code instead of getting 'EB 3C 90' i am getting 'FFEB 3C FF90'. You mentioned something about little endian machines, i know the difference between the two and their importance in a computer system but it appears to me that the code i have is outputting the data into little endian format when the 'big endian' should be the one taking precedence. This maybe why i am getting 258 for the number of bytes in the sector instead of 512 (which is the correct value and stored at offset 0B in the bootsector)?
You're probably not zeroing everything before you read into the struct. Try this before you read anything into the boot sector:
Could you post your current code?Code:memset(&_boot,NULL,sizeof(BS));
I'm still getting the same result with the leading FF's.
I had to replace the NULL value with this to get it through the compiler:
Could it be something to do with the memory model i'm using? I'm using a large model but when i use the small memory model i get: 45 52 52Code:memset(&_boot,'\0',sizeof(BS));
This is really bizarre. I did exactly the same thing a while ago (with this exact thread, actually), and I didn't have this sort of problem. I take it you're using a Borland compiler?
EDIT: Try changing "%8c" to "%8s". Doubt it'll do anything, but it might.
I'm using the digital mars compiler with the 16bit DOS extender.
Chagin the code back from "%8c" to "%8c" brings back the "MSDOS 5.0" and the "NO NAME" but i dont think the 11 or 8 (character limitation) is making a difference as extra characters are being added to the label name
So you're still having a problem with extra characters for the jump code?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks