A better nasm highlight USB boot code

So this the product with some code cleanup. I also set file extension to be .nasm and mime as "nasm". The decimal is odd color, but I like to see that decimal is different so I don't think I am doing hex when it compiles as decimal and bites me in the rear. And here is another useful link for kate syntax highlighting.


;building this file ;nasm -f bin -o boot2.img boot2.nasm ;Next line just included for reference ;cat boot2.img > /dev/sdg1 ? USB? IDK ;How to put only the boot sector on a device ;sudo dd if=boot2.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 NoExtBios cmp bx,0xaa55 jnz NoExtBios shr cx,1 ;Packet jnc NoExtBios ;Patch ah=42 extended read mov dword [BootCodeSwitch-$$+0x600],0x15eb42b4 NoExtBios: 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: 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 InstallDiskTable: call LoadBootSector mov si,0x7dbe mov di,0x7be mov cx,0x20 rep movsw ret PartitionLevel: pushad mov bp,sp mov bx,PartTable-$$+600h 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 LoadAndRun 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 InstallDiskTable jc BootErr2 call PartitionLevel BootErr2: mov eax,[bp+0x1c] LocalB2: call InstallDiskTable NextPartition: add bx,byte +0x10 loop PartitionLoop popad ret Error_Multiple_Partitions: call StringPrint db "Multiple active partitions.",13,10 LoadAndRun: 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 times (01b8h - ($ - $$)) db 0h ;Zerofill up to signature ;Disk signature db 0x98,0x93,8,0 db 0,0 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 (1FE) 510 bytes dw 0xaa55

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen