diff --git a/src/sys/boot/bootsec.asm b/src/sys/boot/bootsec.asm index 81a911a..d57fdc7 100755 --- a/src/sys/boot/bootsec.asm +++ b/src/sys/boot/bootsec.asm @@ -99,54 +99,56 @@ dec cx ; Next section push cx ; Save cx on the stack while we load ; the section into memory + mov bx, 0x600 ; access image location - mov eax,[0x600+2ah] ; Get the program header entry size + mov ax,[bx+2ah] ; Get the program header entry size mul cx ; Calculate the offset from the start - ; of the program header table - mov ebx,[0x600+1ch] ; Get the PHT offset in ebx - add ebx,eax ; Add it to our PHT entry offset - add ebx,0x600 ; Calculate the address of the entry + ; of the program header table + add ax,[bx+1ch] ; ax <= PHT offset + PHT entry offset + add bx,ax ; bx <= ax(PHT offset + PHT entry offset) + ; + image location of ELF file (0x600) cmp dword [bx],1 ; Does this section have to be ; loaded into memory ? jne nextsect ; No, next section - mov dword ecx,[bx+4h] ; Get the offset of the segment in - ; the ELF file - - mov dword ebp,[bx+10h] ; Get the size of the segment in the + mov dword ecx,[bx+10h] ; Get the size of the segment in the ; ELF file mov dword edi,[bx+8h] ; Get the memory address of the sect. - mov dword eax,[bx+14h] ; Get the size of the section in - mov ebx,eax ; the memory into ebx -; ds:dx = Address of ASCIIZ filename -; es:edi = Where in memory to put it -; ecx = Offset in file to start reading (bytes) -; ebp = Length of segment to read (bytes) -; -; Returns: -; eax = Length of file that was loaded -; eax = 0 if an error occured + mov dword eax,[bx+14h] ; eax <= the size of the section + mov dword ebx,[bx+4h] ; Get the offset of the segment in + ; the ELF file + add ebx, 0x600 ; - push ebp - pusha - mov esi, 0x600 - add esi, ecx - mov ecx, ebp - call memcopy - popa - pop eax + ; set up for memcopy - sub ebx,eax ; This amount needs to be zeroed - jz nextsect ; It's ok, next section + mov edx, edi ; edx <- set dest addr + add edi, ecx ; move past part which will be copied + sub eax, ecx ; eax <- store zero fill size + ; ebx is already source addr + ; ecx is already count + + ; set up for memcopy + ;mov esi, 0x600 + ;add esi, ecx + ;mov ecx, edx - add edi,eax ; Zero the memory from this address - xor ax,ax ; edi is an absolute address - mov ecx,ebx - call zero_memblock ; Zero the rest of the section + ;call memcopy + call nonmajicmemcpy + + ; warnng, ,assume zero-fill < 64K + ;test ax,ax ; This amount needs to be zeroed + ;jz nextsect ; It's ok, next section + + ; store zero fill size + ;mov ecx, eax + ;add edi,edx ; Zero the memory from this address + ;xor ax,ax ; edi is an absolute address + ;mov ecx,ebx + ;call zero_memblock ; Zero the rest of the section nextsect: pop cx ; Restore our section count @@ -156,30 +158,9 @@ ; Re-enter protected mode ! A20 is already enabled -;mov ax,0x4F01 -;mov cx,0x4020 -;mov bx,0x100 -;mov es,bx -;xor di,di +;mov ax, 0x4f0a ;xor bx,bx ;int 0x10 - - -;mov ax,0x4F02 -;mov bx,0x4020 -;int 0x10 - -;mov ax,0x4F00 -;mov bx,0x100 -;mov es,bx -;xor di,di -;xor bx,bx -;mov byte [es:0],'V' -;mov byte [es:1],'E' -;mov byte [es:2],'S' -;mov byte [es:3],'A' -;int 0x10 - ;xor eax,eax ;mov ax,es ;mov bx,di @@ -286,16 +267,102 @@ ; DS:ESI = Source ; DS:EDI = Destination ; CX = length -memcopy: +;memcopy: +; pusha +;memcopy_loop: +; mov al, [esi] +; mov [edi], al +; inc edi +; inc esi +; loop memcopy_loop +; popa +; ret + +; edx = dest +; ebx = source +; ecx = count +; +; all other registers maintained +nonmajicmemcpy: pusha -memcopy_loop: - mov al, [esi] - mov [edi], al - inc edi - inc esi - loop memcopy_loop + + ; preserve segments + push ds + push es + + push cx ; [stack] <- 'left-over' after full 256 byte copies + + + xor ax, ax + + ; break size into 256 byte chuunks + shr ecx, 8 ; cx <- number of 256 byte copies to perform + mov bp, cx ; bp <- number of 256 byte copies to perform + + mov cl, 4 + + ; break destination into 256 byte chuunks + xchg al, dl ; al <- initial 'offset' of destination + ; edx <- 16 X initial 'segment' of destination + shr edx, cl ; dx <- initial 'segment' of destination + + ; break source into 256 byte chuunks + xchg ah, bl ; ah <- initial 'offset' of source + ; ebx <- 16 X initial 'segment' of source + shr ebx, cl ; bx <- initial 'segment' of source + + cld ; clear direction flag + inc bp ; pre-increment 256 section count + +nonmajicmemcpy_loop256: + movzx si, ah ; restore initial source addr + movzx di, al ; restore initial dest addr + + ; restore/set segment addrs + mov ds, bx + mov es, dx + + ; done? + dec bp + jz nonmajicmemcpy_rest + + ; copy one 256 byte run + mov cx, 0100h + a16 rep movsb + + ; move 'segments' 256 bytes forwards + ; (eax = [es:ds]) + add bx, 0010h + add dx, 0010h + + ; continue + jmp nonmajicmemcpy_loop256 + +nonmajicmemcpy_rest: + pop cx ; restore 'left-over' after full 256 byte copies + inc cl ; pre increment count + +nonmajicmemcpy_restloop: + dec cl + jz nonmajicmemcpy_done + + movsb + jmp nonmajicmemcpy_restloop + +nonmajicmemcpy_done: + + ; restore segments + pop es + pop ds + popa - ret + ret + + + + + + gdtinfo: