Changeset 516 for Whitix/branches/hybrid

Show
Ignore:
Timestamp:
05/24/08 09:45:02 (3 months ago)
Author:
mwhitworth
Message:

Add support for loading modules in at boot time.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/arch/i386/boot/iso/isoboot.asm

    r462 r516  
    138138        mov si,dapa 
    139139        mov [si+4],bx 
    140         mov bx,es 
     140        mov bx, es 
    141141        mov [si+6],bx 
    142142        mov [si+8],eax 
     
    151151        push si 
    152152        mov dl,[drive] 
    153         mov ah,42h 
     153        mov ah, 0x42 
    154154        call Int13WithRetry 
    155155        pop si 
    156156        pop bp 
    157         movzx eax,word[si+2] 
    158         add [si+8],eax 
    159         sub bp,ax 
    160         shl ax,7 
    161         add [si+6],ax 
    162         and bp,bp 
     157        movzx eax, word[si+2] 
     158        add [si+8], eax 
     159        sub bp, ax 
     160        shl ax, 7 
     161        add [si+6], ax 
     162        and bp, bp 
    163163        jnz .loop 
    164164        mov eax,[si+8] 
     
    166166         
    167167Int13WithRetry: 
    168 mov byte [retryCount],6 
     168        mov byte [retryCount],6 
    169169.try: 
    170170        pushad 
     
    203203 
    204204.realError: 
    205 mov si,ErrorStr 
    206 jmp fail 
     205        mov si,ErrorStr 
     206        jmp fail 
    207207 
    208208;Include library routines such as PrintStr 
     
    220220ImageDwords dd 0 
    221221ImageSectors dw 0 
    222 maxTransfer db 0 
     222maxTransfer dw 32 
    223223 
    224224section .bss 
     
    308308section .text 
    309309AllRead: 
    310         ;Read the primary volume descriptor into memory. 
    311         mov eax,[iso_pvd] 
    312         mov bx,trackBuf 
    313         call GetOneSec 
    314  
    315         ;Get the start sector of the root directory 
    316         mov eax,[trackBuf+156+2] 
    317         mov [dirStart],eax 
    318  
    319         ;Get the length (converted to sectors) of the root directory 
    320         mov eax, [trackBuf+156+10] 
    321         add eax, 2047 
    322         shr eax, 11 ;Round up to the nearest sector 
    323         mov [dirLength], eax 
     310        call DirGetRoot 
    324311 
    325312        ;Find /Boot. 
     
    343330        mov di, kernName 
    344331        call ReadInFile 
     332 
     333        ;Read in Boot.modules 
     334        mov ax, 0x3000 
     335        mov es, ax 
     336        xor bx, bx 
     337        mov di, bootModsName 
     338        call ReadInFile 
     339 
     340        push dword [fileLength] 
     341        pop dword [modulesLength] 
     342 
     343        ;Change to /System/Modules/Core to load in the boot modules. 
     344        call DirGetRoot 
     345 
     346        mov di, systemName 
     347        call FindDir 
     348 
     349        mov di, modulesName 
     350        call FindDir 
     351 
     352        mov di, coreName 
     353        call FindDir 
     354 
     355        ;Now load the modules into memory and construct an information table. 
     356        mov ax, 0x3000 
     357        mov es, ax 
     358        xor bx, bx 
     359        call ModulesLoad 
     360 
     361        mov ax, 0x2000 
     362        mov es, ax 
     363        mov bx, 0xFFFF 
     364        mov cl, [numModules] 
     365        mov [es:bx], cl 
    345366 
    346367        ;setup.asm puts in the kernel data area 
     
    456477        mov [fileStartSector],eax 
    457478        push eax 
    458         mov eax,[si+10] 
     479        mov eax, [si+10] 
     480        mov [fileLength], eax 
    459481        add eax,2047 
    460482        shr eax,11 
     
    509531        ret 
    510532 
     533DirGetRoot: 
     534        ;Read the primary volume descriptor into memory. 
     535        xor ax, ax 
     536        mov es, ax 
     537        mov eax, [iso_pvd] 
     538        mov bx, trackBuf 
     539        call GetOneSec 
     540 
     541        ;Get the start sector of the root directory 
     542        mov eax, [trackBuf+156+2] 
     543        mov [dirStart],eax 
     544 
     545        ;Get the length (converted to sectors) of the root directory 
     546        mov eax, [trackBuf+156+10] 
     547        add eax, 2047 
     548        shr eax, 11 ;Round up to the nearest sector 
     549        mov [dirLength], eax 
     550 
     551        ret 
     552 
     553; TODO: Use ds instead of es. Makes for simpler code. 
     554 
     555ModulesLoad: 
     556startAgain: 
     557        mov ax, bx 
     558        ;Parse the file 
     559parseLoop: 
     560        mov cl, [es:bx] 
     561        cmp cl, byte 10 
     562        jz newName 
     563        cmp bx, [modulesLength] 
     564        jge newName 
     565        inc bx 
     566        jmp parseLoop 
     567 
     568newName: 
     569        push bx 
     570        mov cx, ax 
     571        sub bx, ax 
     572 
     573        call ModuleDoLoad 
     574 
     575        pop bx 
     576        inc bx 
     577        cmp bx, [modulesLength] 
     578        jl startAgain 
     579        ret 
     580 
     581;TODO: Optimize this function. 
     582ModuleDoLoad: 
     583        push es 
     584        mov ax, es 
     585        mov ds, ax 
     586 
     587        xor ax, ax 
     588        mov es, ax 
     589 
     590        ;cx contains start of string, bx contains length. Copy over to a buffer and load the file into memory. 
     591        mov di, moduleName 
     592        mov si, cx 
     593        mov cx, bx 
     594        rep movsb 
     595 
     596        ;Add .sys to the end of the filename 
     597        xor ax, ax 
     598        mov ds, ax 
     599 
     600        mov si, modSuffix 
     601        mov cx, 5 
     602        rep movsb 
     603 
     604        ;Read in the file. 
     605        mov ax, [modSegment] 
     606        mov es, ax 
     607        mov bx, [modOffset] 
     608        add bx, 4 
     609        mov di, moduleName 
     610 
     611        call ReadInFile 
     612 
     613        mov ax, [fileLength] 
     614        mov bx, [modOffset] 
     615        add ax, 3 ;Length + 3 to round up 
     616        and ax, ~3 
     617        mov [es:bx], eax 
     618 
     619        add ax, 4 
     620        add [modOffset], ax 
     621        mov ax, [modOffset] 
     622        xor dx ,dx 
     623        mov cx, 16 
     624        div cx ;Get quotient and remainder. Use shift and and soon. 
     625 
     626        add [modSegment], ax 
     627        mov [modOffset], dx 
     628 
     629        inc byte [numModules] 
     630 
     631        pop es 
     632        ret 
     633 
    511634notFound db "Could not find ", 0 
    512635loaderName db "KeLoader", 0 
    513636kernName db "Kernel", 0 
    514637bootName db "Boot", 0 
     638bootModsName db "Boot.modules", 0 
     639systemName db "System", 0 
     640modulesName db "Modules", 0 
     641coreName db "Core", 0 
     642modSuffix db ".sys", 0 
    515643 
    516644dirStart dd 0 
     
    518646fileStartSector dd 0 
    519647fileSectorLength dd 0 
     648fileLength dd 0 
     649modulesLength dd 0 
     650numModules db 0 
     651modSegment dw 0x4000 
     652modOffset dw 0 
    520653 
    521654section .bss 
     
    524657IsoFileName resb 64 
    525658IsoFileNameEnd equ $ 
     659moduleName resb 16 
    526660 
    527661;Track buffer at the end of the bootloader