USB boot diagnostics continued

I disassembled the boot sector of my 4g USB drive with Ubuntu 10.04 LTS on it. The code below is a WIP so don't take it too literally, though it does match using "cmp" and "diff" though I used "hexdump≫ascii.txt" to use "diff" on the hex ascii output. I suppose eventually I will flash the BIOS to make a custom boot to my OS in ROM. It has a boot time of 1 second when running from BIOS ROM. I downloaded the XML file for "kate" which had the nasm highlighting and used that when generating the html for this post. I haven't really cleaned up the code well, but it seemed okay until I posted it and looked at all the vestigial progress mistakes of interpretation. In addition the code highlighting isn't perfect and I notice it highlighted ch at the end of CodeSwitch and ch in CheckBootable label , which seems an easy mistake to make, and "ndisasm" did something very odd with that code switch also and added a line with just -15 on it, which I suppose is some code glitch. I suppose the information at 0x1b8 is what the machine that wouldn't recognize my custom loader wanted or perhaps the partition table with a bootable partition, but I would suspect it is just the disk signature that it looks for, but I could be wrong and I will eventually discover what it really wants, even if I have to pull the BIOS code flash chip. I have written boot loaders about 100 times and I have done them for RISC and CISC as well as various other CPUs from the 70's, 80's and 90's. I also looked at the BIOS with


sudo dd if=/dev/mem of=bios.bin bs=65536 skip=15 count=1

;nasm -f bin -o mbr.img ipl.asm ;cat mbr.img > /dev/sdg1 ? USB? ;sudo dd if=mbr2.img of=/dev/sdg bs=512 count=1 org 7C00h Start: cli xor ax,ax mov ds,ax mov ss,ax mov sp,0x7c00 mov si,sp push es push di push dx mov es,ax sti cld mov di,0x600 mov cx,0x100 rep movsw ;Move to 0:600 then jump there jmp word 0:ReEntry-$$+0x600 ReEntry: push dx mov ah,0x41 mov bx,0x55aa xor cx,cx xor dh,dh stc int 0x13 jc BiosOk cmp bx,0xaa55 jnz BiosOk shr cx,1 jnc BiosOk mov dword [BootCodeSwitch-$$+0x600],0x15eb42b4 ;-15?? nasm BiosOk: pop dx mov ah,0x8 int 0x13 and cx,byte +0x3f push cx movzx ax,dh inc ax mul cx push dx push ax xor eax,eax cdq call PartitionLevel Step5b: call StringPrint db "Missing operating system.",13,10 LoadBootSector: pushad xor edx,edx mov bx,0x7c00 push edx push eax push es push bx push byte +0x1 push byte +0x10 mov si,sp BootCodeSwitch: ;mov ah,0x42 ;jmp short $+0x17 ;jmp short Alternate div dword [0x7bf4] shl ah,0x6 mov cl,ah mov ch,al xchg ax,dx div byte [0x7bf8] mov dh,al or cl,ah inc cx Alternate: mov ax,0x201 mov dl,[0x7bfa] int 0x13 add sp,byte +0x10 popad ret FunctionB2: call LoadBootSector mov si,0x7dbe mov di,0x7be mov cx,0x20 rep movsw ret PartitionLevel: pushad mov bp,sp mov bx,PartTable-$$+600h ;0x7be mov cx,0x4 IdentifyBootPartition: xor ax,ax push bx push cx CheckBootable: test byte [bx],0x80 jz NotBoot inc ax mov si,bx NotBoot: add bx,byte +0x10 loop CheckBootable dec ax jz double jns Error_Multiple_Partitions pop cx pop bx PartitionLoop: mov al,[bx+0x4] cmp al,0xf jz TypeF and al,0x7f cmp al,0x5 jnz NextPartition TypeF: mov eax,[bx+0x8] mov edx,[bp+0x14] add eax,edx and edx,edx jnz Recurse mov edx,eax Recurse: call FunctionB2 jc BootErr2 call PartitionLevel BootErr2: mov eax,[bp+0x1c] LocalB2: call FunctionB2 NextPartition: add bx,byte +0x10 loop PartitionLoop popad ret Error_Multiple_Partitions: call StringPrint db "Multiple active partitions.",13,10 double: mov eax,[si+0x8] add eax,[bp+0x1c] mov [si+0x8],eax call LoadBootSector jc Error3 cmp word [0x7dfe],0xaa55 jnz Step5b mov sp,0x7bfa pop dx pop di pop es cli jmp sp Error3: call StringPrint Message1 db "Operating system load error.",13,10 StringPrint: pop si CharOutLoop: lodsb mov ah,0xe mov bh,[0x462] mov bl,0x7 int 0x10 cmp al,0xa jnz CharOutLoop int 0x18 Stop: hlt jmp short Stop ;Disk signature? times (01b8h - ($ - $$)) db 0h ;Zerofill up to 510 bytes db 0x98,0x93,8,0,0,0 ;mov ah,0x42 ;jmp short $+0x17 bootable equ 0x80 linuxPart equ 0x0c start_sector equ 0x01f80 total_sectors equ 0x0ef4080 PartTable db bootable db 1 ;Head db 0xc ;Sector and Cyl mixed db 0xf ;0-7 cylinder CHS start db linuxPart db 0x4,0xe0,0xa0 ;CHS last same dd start_sector dd total_sectors times (01feh - ($ - $$)) db 0h ;Zerofill up to 510 bytes dw 0xaa55 ;Sector2: ; db "Now is the time",13,10

0 comments:

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen