diff --git a/reactos/loaders/dos/loadros.asm b/reactos/loaders/dos/loadros.asm index fca0336610d..44bc10ab30c 100644 --- a/reactos/loaders/dos/loadros.asm +++ b/reactos/loaders/dos/loadros.asm @@ -1,693 +1,694 @@ -; -; Pmode setup stub -; (A20 enable code and PIC reprogram from linux bootsector) -; - -; -; Base address of the kernel -; -KERNEL_BASE equ 0c0000000h - -; -; Segment selectors -; -USER_CS equ 08h -USER_DS equ 010h -KERNEL_CS equ 020h -KERNEL_DS equ 028h - -; -; Space reserved in the gdt for tss descriptors -; -NR_TASKS equ 128 - -; -; We are a .com program -; -org 100h - -; -; 16 bit code -; -BITS 16 - -entry: - ; - ; Load stack - ; - cli - push ds - pop ss - mov sp,real_stack_end - sti - - ; - ; Setup the loader space - ; - mov ebx,0 - mov eax,0 - mov ecx,0 - mov edx,0 - mov esi,0 - mov edi,0 - - ; - ; Calculate the end of this module - ; - mov ax,ds - movzx ebx,ax - shl ebx,4 - add ebx,_end - - ; - ; Round up to the nearest page - ; - and ebx,~0xfff - add ebx,01000h - - ; - ; Set the start of the page directory - ; - mov [kernel_page_directory_base],ebx - - ; - ; Set the start of the continuous range of physical memory - ; occupied by the kernel - ; - mov [_start_mem],ebx - add ebx,01000h - - ; - ; Calculate the start of the system page table (0xc0000000 upwards) - ; - mov [system_page_table_base],ebx - add ebx,01000h - - ; - ; Calculate the start of the page table to map the first 4mb - ; - mov [lowmem_page_table_base],ebx - add ebx,01000h - - ; - ; Set the position for the first module to be loaded - ; - mov [next_load_base],ebx - - ; - ; Set the address of the start of kernel code - ; - mov [_start_kernel],ebx - - ; - ; Make the argument list into a c string - ; - mov di,081h -l1: - cmp byte [di],0dh - je l2 - cmp byte [di],' ' - jne l12 - mov byte [di],0 -l12: - inc di - jmp l1 -l2: - mov byte [di],0 - mov [end_cmd_line],di - - mov dx,082h -l14: - mov bx,dx - cmp byte [bx],0 - je l16 - - ; - ; Process the arguments - ; - mov di,loading_msg - call _print_string - mov di,dx - call _print_string - mov ah,02h - mov dl,0dh - int 021h - mov ah,02h - mov dl,0ah - int 021h - - ; - ; Load the file - ; - push di - mov dx,di - call _load_file - pop di - - ; - ; Move onto the next module name in the command line - ; -l15: - cmp di,[end_cmd_line] - je l16 - cmp byte [di],0 - je l17 - inc di - jmp l15 -l17: - inc di - mov dx,di - jmp l14 -l16: - - ; - ; Set the end of kernel memory - ; - mov eax,[next_load_base] - mov [_end_mem],eax - - ; - ; Begin the pmode initalization - ; - jmp _to_pmode - -exit: - mov ax,04c00h - int 21h - - ; - ; Any errors detected jump here - ; -_error: - mov di,err_msg - call _print_string - jmp exit - -end_cmd_line dw 0 - - -; -; Read in a file to kernel_base, set kernel base to the end of the file in -; memory rounded up to the nearest page -; -; In: -; DI = filename -; -_load_file: - inc dword [_nr_files] - - ; - ; Open the file - ; - mov ah,03dh - mov al,0 - mov dx,di - int 021h - jc _error - mov [file_handle],ax - - ; - ; Find filelength - ; - mov ah,042h - mov al,2 - mov bx,[file_handle] - mov cx,0 - mov dx,0 - int 021h - - ; - ; Convert the filelength in DX:AX to a dword in EBX - ; - movzx ebx,dx - shl ebx,16 - mov bx,ax - - ; - ; Record the length of the module in boot parameter table - ; - mov esi,[_nr_files] - dec esi - mov [_module_lengths+esi*4],ebx - - ; - ; Convert the length into - ; - mov [size_mod_4k],bx - and word [size_mod_4k],0fffh - - shr ebx,12 - mov [size_div_4k],ebx - - - ; - ; Seek to beginning of file - ; - mov ah,042h - mov al,0 - mov bx,[file_handle] - mov cx,0 - mov dx,0 - int 021h - jc _error - - ; - ; Read in the module - ; - push ds - - ; - ; Convert the linear point to the load address into a seg:off - ; - mov edi,[next_load_base] - call convert_to_seg - mov dx,di - - ; - ; Move onto the next position in prepartion for a future read - ; - mov eax,[size_div_4k] - mov bx,[size_mod_4k] - cmp bx,0 - je l20 - inc eax -l20: - shl eax,0ch - add [next_load_base],eax - - push fs - pop ds - - ; - ; We read the kernel in 4k chunks (because) - ; -l6: - ; - ; Check if we have read it all - ; - mov ax,[es:size_div_4k] - cmp ax,0 - je l5 - - ; - ; Make the call (dx was loaded above) - ; - mov ah,3fh - mov bx,[es:file_handle] - mov cx,01000h - int 21h - - ; - ; We move onto the next pointer by altering ds - ; - mov ax,ds - add ax,0100h - mov ds,ax - dec word [es:size_div_4k] - jmp l6 - -l5: - ; - ; Read the last section - ; - mov ah,3fh - mov bx,[es:file_handle] - mov cx,[es:size_mod_4k] - int 21h - pop ds - jnc _no_error - jmp _error - -_no_error: - ret - -; -; In: EDI = address -; Out: FS = segment -; DI = base -; -convert_to_seg: - push eax - - mov eax,edi - shr eax,16 - shl eax,12 - mov fs,ax - - and edi,0ffffh - - pop eax - ret - -; -; Print string in DS:DI -; -_print_string: - push ax - push dx - push di - mov ah,02h -l3: - mov dl,[di] - cmp dl,0 - je l4 - int 021h - inc di - jmp l3 -l4: - pop di - pop dx - pop ax - ret - -; -; Handle of the currently open file -; -file_handle dw 0 - -; -; Size of the current file mod 4k -; -size_mod_4k dw 0 - -; -; Size of the current file divided by 4k -; -size_div_4k dd 0 - -; -; -; -last_addr dw 0 - -; -; Generic error message -; -err_msg db 'Error during operation',0 - -; -; -; -loading_msg db 'Loading: ',0 - -filelength_lo dw 0 -filelength_hi dw 0 - -kernel_page_directory_base dd 0 -system_page_table_base dd 0 -lowmem_page_table_base dd 0 -next_load_base dd 0 -_start_kernel dd 0 - -boot_param_struct_base dd 0 - -; -; These variables are passed to the kernel (as a structure) -; -align 4 -_boot_param_struct: -_magic: - dd 0 -_cursorx: - dd 0 -_cursory: - dd 0 -_nr_files: - dd 0 -_start_mem: - dd 0 -_end_mem: - dd 0 -_module_lengths: - times 64 dd 0 -_end_boot_param_struct - -; -; Needed for enabling the a20 address line -; -empty_8042: - jmp $+3 - jmp $+3 - in al,064h - test al,02h - jnz empty_8042 - ret - -; -; GDT descriptor -; -align 8 -gdt_descr: -gdt_limit: - dw (((6+NR_TASKS)*8)-1) -gdt_base: - dd gdt - - -_to_pmode: - ; - ; Setup kernel parameters - ; - mov dword [_magic],0xdeadbeef - - ; - ; Save cursor position - ; - mov ah,03h - mov bh,0h - int 010h - movzx eax,dl - mov [_cursorx],eax - movzx eax,dh - mov [_cursory],eax - - - mov bx,ds - movzx eax,bx - shl eax,4 - add eax,_boot_param_struct - mov [boot_param_struct_base],eax - - cli - - ; - ; Zero out the kernel page directory - ; - ; - mov edi,[kernel_page_directory_base] - call convert_to_seg - - mov cx,1024 -l10: - mov dword [fs:di],0 - add di,4 - loop l10 - - ; - ; Map in the lowmem page table (and reuse it for the identity map) - ; - mov edi,[kernel_page_directory_base] - call convert_to_seg - - mov eax,[lowmem_page_table_base] - add eax,07h - mov [fs:di],eax - mov [fs:di+(0xd0000000/(1024*1024))],eax - - ; - ; Map in the kernel page table - ; - mov eax,[system_page_table_base] - add eax,07h - mov [fs:di+3072],eax - - ; - ; Setup the lowmem page table - ; - mov edi,[lowmem_page_table_base] - call convert_to_seg - - mov ebx,0 -l9: - mov eax,ebx - shl eax,12 ; ebx = ebx * 4096 - add eax,07h ; user, rw, present - mov [fs:edi+ebx*4],eax - inc ebx - cmp ebx,1024 - jl l9 - - ; - ; Setup the system page table - ; - mov edi,[system_page_table_base] - call convert_to_seg - - mov eax,07h -l8: - mov edx,eax - add edx,[_start_kernel] - mov [fs:edi],edx - add edi,4 - add eax,1000h - cmp eax,100007h - jl l8 - - ; - ; Load the page directory into cr3 - ; - mov eax,[kernel_page_directory_base] - mov cr3,eax - - ; - ; Setup various variables - ; - mov bx,ds - movzx eax,bx - shl eax,4 - add [gdt_base],eax - - ; - ; Enable the A20 address line (to allow access to over 1mb) - ; - call empty_8042 - mov al,0D1h ; command write - out 064h,al - call empty_8042 - mov al,0DFh ; A20 on - out 060h,al - call empty_8042 - - ; - ; Reprogram the PIC because they overlap the Intel defined - ; exceptions - ; - mov al,011h ; initialization sequence - out 020h,al ; send it to 8259A-1 - dw 0x00eb,0x00eb ; jmp $+2, jmp $+2 - out 0A0h,al ; and to 8259A-2 - dw 0x00eb,0x00eb - mov al,020h ; start of hardware int's (0x20) - out 021h,al - dw 0x00eb,0x00eb - mov al,028h ; start of hardware int's 2 (0x28) - out 0A1h,al - dw 0x00eb,0x00eb - mov al,04h ; 8259-1 is master - out 021h,al - dw 0x00eb,0x00eb - mov al,002h ; 8259-2 is slave - out 0A1h,al - dw 0x00eb,0x00eb - mov al,01h ; 8086 mode for both - out 021h,al - dw 0x00eb,0x00eb - out 0A1h,al - dw 0x00eb,0x00eb - mov al,0FFh ; mask off all interrupts for now - out 021h,al - dw 0x00eb,0x00eb - out 0A1h,al - - ; - ; Load stack - ; - mov bx,ds - movzx eax,bx - shl eax,4 - add eax,real_stack_end - mov [real_stack_base],eax - mov esp,[real_stack_base] - mov edx,[boot_param_struct_base] - - ; - ; load gdt - ; - lgdt [gdt_descr] - - ; - ; Enter pmode and clear prefetch queue - ; - mov eax,cr0 - or eax,0x80000001 - mov cr0,eax - jmp next -next: - ; - ; NOTE: This must be position independant (no references to - ; non absolute variables) - ; - - ; - ; Initalize segment registers - ; - mov ax,KERNEL_DS - mov ds,ax - mov ss,ax - mov es,ax - mov fs,ax - - ; - ; Initalize eflags - ; - push dword 0 - popf - - ; - ; Jump to start of 32 bit code at c0000000 - ; - push edx - push dword 0 - jmp dword KERNEL_CS:KERNEL_BASE - - -; -; Our initial stack -; -real_stack times 1024 db 0 -real_stack_end: - -real_stack_base dd 0 - - -; -; Global descriptor table -; -align 8 -gdt: - dw 0 ; Zero descriptor - dw 0 - dw 0 - dw 0 - - dw 00000h ; User code descriptor - dw 00000h ; base: 0h limit: 3gb - dw 0fa00h - dw 000cch - - dw 00000h ; User data descriptor - dw 00000h ; base: 0h limit: 3gb - dw 0f200h - dw 000cch - - dw 00000h - dw 00000h - dw 00000h - dw 00000h - - dw 0ffffh ; Kernel code descriptor - dw 00000h ; - dw 09a00h ; base 0h limit 4gb - dw 000cfh - - dw 0ffffh ; Kernel data descriptor - dw 00000h ; - dw 09200h ; base 0h limit 4gb - dw 000cfh - - - times NR_TASKS*8 db 0 - -_end: - - +; +; Pmode setup stub +; (A20 enable code and PIC reprogram from linux bootsector) +; + +; +; Base address of the kernel +; +KERNEL_BASE equ 0c0000000h + +; +; Segment selectors +; +USER_CS equ 08h +USER_DS equ 010h +KERNEL_CS equ 020h +KERNEL_DS equ 028h + +; +; Space reserved in the gdt for tss descriptors +; +NR_TASKS equ 128 + +; +; We are a .com program +; +org 100h + +; +; 16 bit code +; +BITS 16 + +entry: + ; + ; Load stack + ; + cli + push ds + pop ss + mov sp,real_stack_end + sti + + ; + ; Setup the loader space + ; + mov ebx,0 + mov eax,0 + mov ecx,0 + mov edx,0 + mov esi,0 + mov edi,0 + + ; + ; Calculate the end of this module + ; + mov ax,ds + movzx ebx,ax + shl ebx,4 + add ebx,_end + + ; + ; Round up to the nearest page + ; + and ebx,~0xfff + add ebx,01000h + + ; + ; Set the start of the page directory + ; + mov [kernel_page_directory_base],ebx + + ; + ; Set the start of the continuous range of physical memory + ; occupied by the kernel + ; + mov [_start_mem],ebx + add ebx,01000h + + ; + ; Calculate the start of the system page table (0xc0000000 upwards) + ; + mov [system_page_table_base],ebx + add ebx,01000h + + ; + ; Calculate the start of the page table to map the first 4mb + ; + mov [lowmem_page_table_base],ebx + add ebx,01000h + + ; + ; Set the position for the first module to be loaded + ; + mov [next_load_base],ebx + + ; + ; Set the address of the start of kernel code + ; + mov [_start_kernel],ebx + + ; + ; Make the argument list into a c string + ; + mov di,081h +l1: + cmp byte [di],0dh + je l2 + cmp byte [di],' ' + jne l12 + mov byte [di],0 +l12: + inc di + jmp l1 +l2: + mov byte [di],0 + mov [end_cmd_line],di + + mov dx,082h +l14: + mov bx,dx + cmp byte [bx],0 + je l16 + + ; + ; Process the arguments + ; + mov di,loading_msg + call _print_string + mov di,dx + call _print_string + mov ah,02h + mov dl,0dh + int 021h + mov ah,02h + mov dl,0ah + int 021h + + ; + ; Load the file + ; + push di + mov dx,di + call _load_file + pop di + + ; + ; Move onto the next module name in the command line + ; +l15: + cmp di,[end_cmd_line] + je l16 + cmp byte [di],0 + je l17 + inc di + jmp l15 +l17: + inc di + mov dx,di + jmp l14 +l16: + + ; + ; Set the end of kernel memory + ; + mov eax,[next_load_base] + mov [_end_mem],eax + + ; + ; Begin the pmode initalization + ; + jmp _to_pmode + +exit: + mov ax,04c00h + int 21h + + ; + ; Any errors detected jump here + ; +_error: + mov di,err_msg + call _print_string + jmp exit + +end_cmd_line dw 0 + + +; +; Read in a file to kernel_base, set kernel base to the end of the file in +; memory rounded up to the nearest page +; +; In: +; DI = filename +; +_load_file: + inc dword [_nr_files] + + ; + ; Open the file + ; + mov ah,03dh + mov al,0 + mov dx,di + int 021h + jc _error + mov [file_handle],ax + + ; + ; Find filelength + ; + mov ah,042h + mov al,2 + mov bx,[file_handle] + mov cx,0 + mov dx,0 + int 021h + + ; + ; Convert the filelength in DX:AX to a dword in EBX + ; + movzx ebx,dx + shl ebx,16 + mov bx,ax + + ; + ; Record the length of the module in boot parameter table + ; + mov esi,[_nr_files] + dec esi + mov [_module_lengths+esi*4],ebx + + ; + ; Convert the length into + ; + mov [size_mod_4k],bx + and word [size_mod_4k],0fffh + + shr ebx,12 + mov [size_div_4k],ebx + + + ; + ; Seek to beginning of file + ; + mov ah,042h + mov al,0 + mov bx,[file_handle] + mov cx,0 + mov dx,0 + int 021h + jc _error + + ; + ; Read in the module + ; + push ds + + ; + ; Convert the linear point to the load address into a seg:off + ; + mov edi,[next_load_base] + call convert_to_seg + mov dx,di + + ; + ; Move onto the next position in prepartion for a future read + ; + mov eax,[size_div_4k] + mov bx,[size_mod_4k] + cmp bx,0 + je l20 + inc eax +l20: + shl eax,0ch + add [next_load_base],eax + + push fs + pop ds + + ; + ; We read the kernel in 4k chunks (because) + ; +l6: + ; + ; Check if we have read it all + ; + mov ax,[es:size_div_4k] + cmp ax,0 + je l5 + + ; + ; Make the call (dx was loaded above) + ; + mov ah,3fh + mov bx,[es:file_handle] + mov cx,01000h + int 21h + + ; + ; We move onto the next pointer by altering ds + ; + mov ax,ds + add ax,0100h + mov ds,ax + dec word [es:size_div_4k] + jmp l6 + +l5: + ; + ; Read the last section + ; + mov ah,3fh + mov bx,[es:file_handle] + mov cx,[es:size_mod_4k] + int 21h + pop ds + jnc _no_error + jmp _error + +_no_error: + ret + +; +; In: EDI = address +; Out: FS = segment +; DI = base +; +convert_to_seg: + push eax + + mov eax,edi + shr eax,16 + shl eax,12 + mov fs,ax + + and edi,0ffffh + + pop eax + ret + +; +; Print string in DS:DI +; +_print_string: + push ax + push dx + push di + mov ah,02h +l3: + mov dl,[di] + cmp dl,0 + je l4 + int 021h + inc di + jmp l3 +l4: + pop di + pop dx + pop ax + ret + +; +; Handle of the currently open file +; +file_handle dw 0 + +; +; Size of the current file mod 4k +; +size_mod_4k dw 0 + +; +; Size of the current file divided by 4k +; +size_div_4k dd 0 + +; +; +; +last_addr dw 0 + +; +; Generic error message +; +err_msg db 'Error during operation',0 + +; +; +; +loading_msg db 'Loading: ',0 + +filelength_lo dw 0 +filelength_hi dw 0 + +kernel_page_directory_base dd 0 +system_page_table_base dd 0 +lowmem_page_table_base dd 0 +next_load_base dd 0 +_start_kernel dd 0 + +boot_param_struct_base dd 0 + +; +; These variables are passed to the kernel (as a structure) +; +align 4 +_boot_param_struct: +_magic: + dd 0 +_cursorx: + dd 0 +_cursory: + dd 0 +_nr_files: + dd 0 +_start_mem: + dd 0 +_end_mem: + dd 0 +_module_lengths: + times 64 dd 0 +_end_boot_param_struct + +; +; Needed for enabling the a20 address line +; +empty_8042: + jmp $+3 + jmp $+3 + in al,064h + test al,02h + jnz empty_8042 + ret + +; +; GDT descriptor +; +align 8 +gdt_descr: +gdt_limit: + dw (((6+NR_TASKS)*8)-1) +gdt_base: + dd gdt + + +_to_pmode: + ; + ; Setup kernel parameters + ; + mov dword [_magic],0xdeadbeef + + ; + ; Save cursor position + ; + mov ah,03h + mov bh,0h + int 010h + movzx eax,dl + mov [_cursorx],eax + movzx eax,dh + mov [_cursory],eax + + + mov bx,ds + movzx eax,bx + shl eax,4 + add eax,_boot_param_struct + mov [boot_param_struct_base],eax + + cli + + ; + ; Zero out the kernel page directory + ; + ; + mov edi,[kernel_page_directory_base] + call convert_to_seg + + mov cx,1024 +l10: + mov dword [fs:di],0 + add di,4 + loop l10 + + ; + ; Map in the lowmem page table (and reuse it for the identity map) + ; + mov edi,[kernel_page_directory_base] + call convert_to_seg + + mov eax,[lowmem_page_table_base] + add eax,07h + mov [fs:di],eax + mov [fs:di+(0xd0000000/(1024*1024))],eax + + ; + ; Map in the kernel page table + ; + mov eax,[system_page_table_base] + add eax,07h + mov [fs:di+3072],eax + + ; + ; Setup the lowmem page table + ; + mov edi,[lowmem_page_table_base] + call convert_to_seg + + mov ebx,0 +l9: + mov eax,ebx + shl eax,12 ; ebx = ebx * 4096 + add eax,07h ; user, rw, present + mov [fs:edi+ebx*4],eax + inc ebx + cmp ebx,1024 + jl l9 + + ; + ; Setup the system page table + ; + mov edi,[system_page_table_base] + call convert_to_seg + + mov eax,07h +l8: + mov edx,eax + add edx,[_start_kernel] + mov [fs:edi],edx + add edi,4 + add eax,1000h + cmp eax,100007h + jl l8 + + ; + ; Load the page directory into cr3 + ; + mov eax,[kernel_page_directory_base] + mov cr3,eax + + ; + ; Setup various variables + ; + mov bx,ds + movzx eax,bx + shl eax,4 + add [gdt_base],eax + + ; + ; Enable the A20 address line (to allow access to over 1mb) + ; + call empty_8042 + mov al,0D1h ; command write + out 064h,al + call empty_8042 + mov al,0DFh ; A20 on + out 060h,al + call empty_8042 + + ; + ; Reprogram the PIC because they overlap the Intel defined + ; exceptions + ; + mov al,011h ; initialization sequence + out 020h,al ; send it to 8259A-1 + dw 0x00eb,0x00eb ; jmp $+2, jmp $+2 + out 0A0h,al ; and to 8259A-2 + dw 0x00eb,0x00eb + mov al,020h ; start of hardware int's (0x20) + out 021h,al + dw 0x00eb,0x00eb + mov al,028h ; start of hardware int's 2 (0x28) + out 0A1h,al + dw 0x00eb,0x00eb + mov al,04h ; 8259-1 is master + out 021h,al + dw 0x00eb,0x00eb + mov al,002h ; 8259-2 is slave + out 0A1h,al + dw 0x00eb,0x00eb + mov al,01h ; 8086 mode for both + out 021h,al + dw 0x00eb,0x00eb + out 0A1h,al + dw 0x00eb,0x00eb + mov al,0FFh ; mask off all interrupts for now + out 021h,al + dw 0x00eb,0x00eb + out 0A1h,al + + ; + ; Load stack + ; + mov bx,ds + movzx eax,bx + shl eax,4 + add eax,real_stack_end + mov [real_stack_base],eax + mov esp,[real_stack_base] + mov edx,[boot_param_struct_base] + + ; + ; load gdt + ; + lgdt [gdt_descr] + + ; + ; Enter pmode and clear prefetch queue + ; + mov eax,cr0 + or eax,0x80000001 + mov cr0,eax + jmp next +next: + ; + ; NOTE: This must be position independant (no references to + ; non absolute variables) + ; + + ; + ; Initalize segment registers + ; + mov ax,KERNEL_DS + mov ds,ax + mov ss,ax + mov es,ax + mov fs,ax + + ; + ; Initalize eflags + ; + push dword 0 + popf + + ; + ; Jump to start of 32 bit code at c0000000 + ; + push edx + push dword 0 + jmp dword KERNEL_CS:KERNEL_BASE + + +; +; Our initial stack +; +real_stack times 1024 db 0 +real_stack_end: + +real_stack_base dd 0 + + +; +; Global descriptor table +; +align 8 +gdt: + dw 0 ; Zero descriptor + dw 0 + dw 0 + dw 0 + + dw 00000h ; User code descriptor + dw 00000h ; base: 0h limit: 3gb + dw 0fa00h + dw 000cch + + dw 00000h ; User data descriptor + dw 00000h ; base: 0h limit: 3gb + dw 0f200h + dw 000cch + + dw 00000h + dw 00000h + dw 00000h + dw 00000h + + dw 0ffffh ; Kernel code descriptor + dw 00000h ; + dw 09a00h ; base 0h limit 4gb + dw 000cfh + + dw 0ffffh ; Kernel data descriptor + dw 00000h ; + dw 09200h ; base 0h limit 4gb + dw 000cfh + + + times NR_TASKS*8 db 0 + +_end: + + + diff --git a/reactos/makefile_rex b/reactos/makefile_rex index 01e5d8b93ff..16333df71d9 100644 --- a/reactos/makefile_rex +++ b/reactos/makefile_rex @@ -30,13 +30,20 @@ LOADERS = dos # # Select the device drivers and filesystems you want # -KERNEL_SERVICES = parallel keyboard null mouse serial sound test ide ide-test +KERNEL_SERVICES = parallel keyboard null mouse serial sound ide test minix all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES) # # Device driver rules # +sdisk: dummy + make -C services/sdisk + +minix: dummy + make -C services/fs/minix + + ide-test: dummy make -C services/ide-test diff --git a/reactos/ntoskrnl/io/irp.c b/reactos/ntoskrnl/io/irp.c index 693bcb45bdc..013568856c9 100644 --- a/reactos/ntoskrnl/io/irp.c +++ b/reactos/ntoskrnl/io/irp.c @@ -82,177 +82,6 @@ VOID IoMarkIrpPending(PIRP Irp) IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED; } -PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction, - PDEVICE_OBJECT DeviceObject, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER StartingOffset, - PIO_STATUS_BLOCK IoStatusBlock) -/* - * FUNCTION: Allocates and sets up an IRP to be sent to lower level drivers - * ARGUMENTS: - * MajorFunction = One of IRP_MJ_READ, IRP_MJ_WRITE, - * IRP_MJ_FLUSH_BUFFERS or IRP_MJ_SHUTDOWN - * DeviceObject = Device object to send the irp to - * Buffer = Buffer into which data will be read or written - * Length = Length in bytes of the irp to be allocated - * StartingOffset = Starting offset on the device - * IoStatusBlock (OUT) = Storage for the result of the operation - * RETURNS: The IRP allocated on success, or - * NULL on failure - */ -{ - PIRP Irp; - PIO_STACK_LOCATION StackPtr; - - Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE); - if (Irp==NULL) - { - return(NULL); - } - - Irp->UserBuffer = (LPVOID)Buffer; - if (DeviceObject->Flags&DO_BUFFERED_IO) - { - DPRINT("Doing buffer i/o\n",0); - Irp->AssociatedIrp.SystemBuffer = (PVOID) - ExAllocatePool(NonPagedPool,Length); - if (Irp->AssociatedIrp.SystemBuffer==NULL) - { - return(NULL); - } - Irp->UserBuffer = NULL; - } - if (DeviceObject->Flags&DO_DIRECT_IO) - { - DPRINT("Doing direct i/o\n",0); - - Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); - MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess); - Irp->UserBuffer = NULL; - Irp->AssociatedIrp.SystemBuffer = NULL; - } - - Irp->UserIosb = IoStatusBlock; - - StackPtr = IoGetNextIrpStackLocation(Irp); - StackPtr->MajorFunction = MajorFunction; - StackPtr->MinorFunction = 0; - StackPtr->Flags = 0; - StackPtr->Control = 0; - StackPtr->DeviceObject = DeviceObject; - StackPtr->FileObject = NULL; - StackPtr->Parameters.Write.Length = Length; - if (StartingOffset!=NULL) - { - StackPtr->Parameters.Write.ByteOffset.LowPart = - StartingOffset->LowPart; - StackPtr->Parameters.Write.ByteOffset.HighPart = - StartingOffset->HighPart; - } - else - { - StackPtr->Parameters.Write.ByteOffset.LowPart = 0; - StackPtr->Parameters.Write.ByteOffset.HighPart = 0; - } - - return(Irp); -} - -PIRP IoBuildDeviceIoControlRequest(ULONG IoControlCode, - PDEVICE_OBJECT DeviceObject, - PVOID InputBuffer, - ULONG InputBufferLength, - PVOID OutputBuffer, - ULONG OutputBufferLength, - BOOLEAN InternalDeviceIoControl, - PKEVENT Event, - PIO_STATUS_BLOCK IoStatusBlock) -{ - UNIMPLEMENTED; -} - -PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction, - PDEVICE_OBJECT DeviceObject, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER StartingOffset, - PKEVENT Event, - PIO_STATUS_BLOCK IoStatusBlock) -/* - * FUNCTION: Allocates and builds an IRP to be sent synchronously to lower - * level driver(s) - * ARGUMENTS: - * MajorFunction = Major function code, one of IRP_MJ_READ, - * IRP_MJ_WRITE, IRP_MJ_FLUSH_BUFFERS, IRP_MJ_SHUTDOWN - * DeviceObject = Target device object - * Buffer = Buffer containing data for a read or write - * Length = Length in bytes of the information to be transferred - * StartingOffset = Offset to begin the read/write from - * Event (OUT) = Will be set when the operation is complete - * IoStatusBlock (OUT) = Set to the status of the operation - * RETURNS: The IRP allocated on success, or - * NULL on failure - */ -{ - PIRP Irp; - PIO_STACK_LOCATION StackPtr; - - Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE); - if (Irp==NULL) - { - return(NULL); - } - - Irp->UserBuffer = (LPVOID)Buffer; - if (DeviceObject->Flags&DO_BUFFERED_IO) - { - DPRINT("Doing buffer i/o\n",0); - Irp->AssociatedIrp.SystemBuffer = (PVOID) - ExAllocatePool(NonPagedPool,Length); - if (Irp->AssociatedIrp.SystemBuffer==NULL) - { - return(NULL); - } - Irp->UserBuffer = NULL; - } - if (DeviceObject->Flags&DO_DIRECT_IO) - { - DPRINT("Doing direct i/o\n",0); - - Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); - MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess); - Irp->UserBuffer = NULL; - Irp->AssociatedIrp.SystemBuffer = NULL; - } - - Irp->UserIosb = IoStatusBlock; - Irp->UserEvent = Event; - - StackPtr = IoGetNextIrpStackLocation(Irp); - StackPtr->MajorFunction = MajorFunction; - StackPtr->MinorFunction = 0; - StackPtr->Flags = 0; - StackPtr->Control = 0; - StackPtr->DeviceObject = DeviceObject; - StackPtr->FileObject = NULL; - StackPtr->Parameters.Write.Length = Length; - if (StartingOffset!=NULL) - { - StackPtr->Parameters.Write.ByteOffset.LowPart = - StartingOffset->LowPart; - StackPtr->Parameters.Write.ByteOffset.HighPart = - StartingOffset->HighPart; - } - else - { - StackPtr->Parameters.Write.ByteOffset.LowPart = 0; - StackPtr->Parameters.Write.ByteOffset.HighPart = 0; - } - - return(Irp); -} - USHORT IoSizeOfIrp(CCHAR StackSize) /* * FUNCTION: Determines the size of an IRP @@ -275,6 +104,7 @@ VOID IoInitializeIrp(PIRP Irp, USHORT PacketSize, CCHAR StackSize) { assert(Irp!=NULL); memset(Irp,0,PacketSize); + Irp->StackCount=StackSize; Irp->CurrentLocation=StackSize; Irp->Tail.Overlay.CurrentStackLocation=IoGetCurrentIrpStackLocation(Irp); } @@ -358,6 +188,7 @@ PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota) return(NULL); } + Irp->StackCount=StackSize; Irp->CurrentLocation=StackSize; DPRINT("Irp %x Irp->StackPtr %d\n",Irp,Irp->CurrentLocation); @@ -399,15 +230,11 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost) * thread making the request */ { - unsigned int i=0; - unsigned int stack_size; + unsigned int i; DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n", Irp,PriorityBoost); - DPRINT("Irp->Stack[i].DeviceObject->StackSize %x\n", - Irp->Stack[i].DeviceObject->StackSize); - stack_size = Irp->Stack[i].DeviceObject->StackSize; - for (i=0;iStackCount;i++) { if (Irp->Stack[i].CompletionRoutine!=NULL) { @@ -420,12 +247,4 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost) { KeSetEvent(Irp->UserEvent,PriorityBoost,FALSE); } - if (Irp->UserIosb!=NULL) - { - *Irp->UserIosb=Irp->IoStatus; - } - - /* - * If the - */ } diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index 48a37b991e9..fbc4d0da46e 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -12,21 +12,50 @@ #include #include -#include +#include #include -#include +#include #define NDEBUG #include -#ifndef NDEBUG -#define DPRINT1(x) printk(x) -#else -#define DPRINT1(x) -#endif - /* FUNCTIONS ***************************************************************/ +static VOID IoSecondStageCompletion(PIRP Irp, + BOOLEAN FromDevice, + PDEVICE_OBJECT DeviceObject, + ULONG Length, + PVOID Buffer) +/* + * FUNCTION: Performs the second stage of irp completion for read/write irps + * ARGUMENTS: + * Irp = Irp to completion + * FromDevice = True if the operation transfered data from the device + */ +{ + if (Irp->UserIosb!=NULL) + { + *Irp->UserIosb=Irp->IoStatus; + } + + if (DeviceObject->Flags & DO_BUFFERED_IO && FromDevice) + { + memcpy(Buffer,Irp->AssociatedIrp.SystemBuffer,Length); + } + if (DeviceObject->Flags & DO_DIRECT_IO) + { + if (Irp->MdlAddress->MappedSystemVa!=NULL) + { + MmUnmapLockedPages(Irp->MdlAddress->MappedSystemVa, + Irp->MdlAddress); + } + MmUnlockPages(Irp->MdlAddress); + ExFreePool(Irp->MdlAddress); + } + + IoFreeIrp(Irp); +} + NTSTATUS ZwReadFile(HANDLE FileHandle, HANDLE EventHandle, PIO_APC_ROUTINE ApcRoutine, @@ -43,49 +72,33 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, PIRP Irp; PIO_STACK_LOCATION StackPtr; KEVENT Event; - + NTSTATUS Status; + + DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, " + "IoStatusBlock %x)\n", + FileHandle,Buffer,Length,ByteOffset,IoStatusBlock); + if (hdr==NULL) { + DPRINT("%s() = STATUS_INVALID_HANDLE\n",__FUNCTION__); return(STATUS_INVALID_HANDLE); } - Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize,TRUE); - if (Irp==NULL) + if (ByteOffset==NULL) { - return(STATUS_UNSUCCESSFUL); + ByteOffset = &(FileObject->CurrentByteOffset); } - Irp->UserBuffer = (LPVOID)Buffer; - if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO) - { - DPRINT1("Doing buffer i/o\n"); - Irp->AssociatedIrp.SystemBuffer = (PVOID) - ExAllocatePool(NonPagedPool,Length); - if (Irp->AssociatedIrp.SystemBuffer==NULL) - { - return(STATUS_UNSUCCESSFUL); - } - Irp->UserBuffer = NULL; - } - if (FileObject->DeviceObject->Flags&DO_DIRECT_IO) - { - DPRINT1("Doing direct i/o\n"); - - Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); - MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess); - Irp->UserBuffer = NULL; - Irp->AssociatedIrp.SystemBuffer = NULL; - } KeInitializeEvent(&Event,NotificationEvent,FALSE); - Irp->UserEvent=&Event; + Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, + FileObject->DeviceObject, + Buffer, + Length, + ByteOffset, + &Event, + IoStatusBlock); StackPtr = IoGetNextIrpStackLocation(Irp); - DPRINT("StackPtr %x\n",StackPtr); - StackPtr->MajorFunction = IRP_MJ_READ; - StackPtr->MinorFunction = 0; - StackPtr->Flags = 0; - StackPtr->Control = 0; - StackPtr->DeviceObject = FileObject->DeviceObject; StackPtr->FileObject = FileObject; StackPtr->Parameters.Read.Length = Length; if (ByteOffset!=NULL) @@ -139,6 +152,7 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle, PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr; PIRP Irp; PIO_STACK_LOCATION StackPtr; + NTSTATUS Status; if (hdr==NULL) { @@ -204,6 +218,11 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle, DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject); Status = IoCallDriver(FileObject->DeviceObject,Irp); + if (Status==STATUS_PENDING) + { + KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL); + Status = IoStatusBlock->Status; + } return(Status); } diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 1ad71e6e3ba..3901a667c61 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -122,16 +122,21 @@ asmlinkage void _main(boot_param* _bp) /* * Copy the parameters to a local buffer because lowmem will go away */ - memcpy(&bp,_bp,sizeof(bp)); + memcpy(&bp,_bp,sizeof(boot_param)); /* * Initalize the console (before printing anything) */ - InitConsole(&bp); + HalInitConsole(&bp); + + DbgPrint("Starting ReactOS "KERNEL_VERSION"\n"); - printk("Starting ReactOS "KERNEL_VERSION"\n"); - start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]); + if (start <= ((int)&end)) + { + DbgPrint("Kernel booted incorrectly, aborting\n"); + for(;;); + } DPRINT("MmGetPhysicalAddress(start) = %x\n",MmGetPhysicalAddress(start)); DPRINT("bp.module_length[0] %x PAGE_ROUND_UP(bp.module_length[0]) %x\n", bp.module_length[0],PAGE_ROUND_UP(bp.module_length[0])); @@ -147,7 +152,6 @@ asmlinkage void _main(boot_param* _bp) * Initalize various critical subsystems */ HalInit(&bp); -// set_breakpoint(0,start,HBP_READWRITE,HBP_DWORD); MmInitalize(&bp); CHECKPOINT; KeInit(); @@ -165,12 +169,12 @@ asmlinkage void _main(boot_param* _bp) DPRINT("%d files loaded\n",bp.nr_files); start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]); + start1 = start+PAGE_ROUND_UP(bp.module_length[1]); +// DbgPrint("start1 %x *start1 %x\n",start1,*((unsigned int *)start1)); for (i=1;i -#include +#include #include #include #include @@ -67,6 +67,27 @@ static void get_symbol_name(module* mod, unsigned int i, char* name) } } +static unsigned int get_symbol_value_by_name(module* mod, char* sname, + unsigned int idx) +{ + unsigned int i; + char name[255]; + + DPRINT("get_symbol_value_by_name(sname %s, idx %x)\n",sname,idx); + + for (i=0; insyms; i++) + { + get_symbol_name(mod,i,name); +// DPRINT("Scanning %s Value %x\n",name,mod->sym_list[i].e_value); + if (strcmp(name,sname)==0) + { + DPRINT("Returning %x\n",mod->sym_list[i].e_value); + return(mod->sym_list[i].e_value); + } + } + return(0); +} + static unsigned int get_symbol_value(module* mod, unsigned int i) /* * FUNCTION: Get the value of a module defined symbol @@ -119,17 +140,32 @@ static int do_reloc32_reloc(module* mod, SCNHDR* scn, RELOC* reloc) val = get_kernel_symbol_addr(name); if (val==0) { - DbgPrint("Undefined symbol %s in module\n",name); - return(0); + val = get_symbol_value_by_name(mod,name,reloc->r_symndx); + if (val==0) + { + DbgPrint("Undefined symbol %s in module\n",name); + return(0); + } + loc=(unsigned int *)(mod->base+reloc->r_vaddr); + DPRINT("old %x ",*loc); +// (*loc) = (*loc) + val + mod->base - scn->s_vaddr; + (*loc) = (*loc); + DPRINT("mod->base %x scn->s_vaddr %x\n",mod->base,scn->s_vaddr); + + DPRINT("new %x\n",*loc); + } - // DPRINT("REL32 value %x name %s\n",val,name); - // printk("value %x\n",val); + else + { + DPRINT("REL32 value %x name %s\n",val,name); + DPRINT("value %x\n",val); loc=(unsigned int *)(mod->base+reloc->r_vaddr); - // printk("old %x ",*loc); + DPRINT("old %x ",*loc); + DPRINT("mod->base %x scn->s_vaddr %x\n",mod->base,scn->s_vaddr); (*loc) = (*loc) + val - mod->base + scn->s_vaddr; - // printk("new %x\n",*loc); - + DPRINT("new %x\n",*loc); + } return(1); } @@ -238,6 +274,7 @@ BOOLEAN process_boot_module(unsigned int start) mod=(module *)ExAllocatePool(NonPagedPool,sizeof(module)); DPRINT("magic %x\n",((FILHDR *)start)->f_magic); +// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000)); memcpy(&hdr,(void *)start,FILHSZ); @@ -258,6 +295,7 @@ BOOLEAN process_boot_module(unsigned int start) mod->scn_list = (SCNHDR *)(start+FILHSZ+hdr.f_opthdr); mod->size=0; mod->raw_data_off = start; + mod->nsyms = hdr.f_nsyms; /* * Determine the length of the module @@ -288,7 +326,9 @@ BOOLEAN process_boot_module(unsigned int start) } CHECKPOINT; +// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000)); mod->base = (unsigned int)MmAllocateSection(mod->size); +// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000)); if (mod->base == 0) { DbgPrint("Failed to alloc section for module\n"); diff --git a/reactos/ntoskrnl/makefile_rex b/reactos/ntoskrnl/makefile_rex index af715405746..41bab3fd40c 100644 --- a/reactos/ntoskrnl/makefile_rex +++ b/reactos/ntoskrnl/makefile_rex @@ -26,7 +26,7 @@ IO_OBJECTS = io/iomgr.o io/create.o io/irp.o io/device.o io/rw.o \ io/shutdown.o io/fdisk.o io/cancel.o io/error.o io/arc.o \ io/dpc.o io/symlink.o io/adapter.o io/cntrller.o io/mdl.o \ io/resource.o io/event.o io/process.o io/file.o io/ioctrl.o \ - io/fs.o + io/fs.o io/vpb.o io/buildirp.o OB_OBJECTS = ob/object.o ob/handle.o ob/namespc.o @@ -39,7 +39,7 @@ SE_OBJECTS = se/semgr.o CFG_OBJECTS = cfg/registry.o -TST_OBJECTS = tst/test.o +TST_OBJECTS = tst/test.o tst/sshell.o tst/readline.o DBG_OBJECTS = dbg/brkpoint.o diff --git a/reactos/ntoskrnl/mm/marea.c b/reactos/ntoskrnl/mm/marea.c index dc0d80378b2..7d2174e25e5 100644 --- a/reactos/ntoskrnl/mm/marea.c +++ b/reactos/ntoskrnl/mm/marea.c @@ -32,7 +32,6 @@ VOID MmDumpMemoryAreas(VOID) ULONG i; current_entry = ListHead->Flink; - i=0; while (current_entry!=ListHead) { current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); @@ -41,14 +40,7 @@ VOID MmDumpMemoryAreas(VOID) current->BaseAddress+current->Length,current->Attributes, current->Entry.Flink); current_entry = current_entry->Flink; - i++; - if (i>6) - { - CHECKPOINT; - for(;;); - } } - CHECKPOINT; } VOID MmLockMemoryAreaList(ULONG Address, PKIRQL oldlvl) @@ -88,8 +80,12 @@ static PLIST_ENTRY MmGetRelatedListHead(ULONG BaseAddress) } else { - PKPROCESS CurrentProcess = KeGetCurrentProcess(); - return(&(CurrentProcess->MemoryAreaList)); + PEPROCESS CurrentProcess = PsGetCurrentProcess(); + if (CurrentProcess==NULL) + { + return(NULL); + } + return(&(CurrentProcess->Pcb.MemoryAreaList)); } } @@ -99,6 +95,16 @@ static MEMORY_AREA* MmInternalOpenMemoryAreaByAddress(PLIST_ENTRY ListHead, PLIST_ENTRY current_entry; MEMORY_AREA* current; + MmDumpMemoryAreas(); + + DPRINT("MmInternalOpenMemoryAreaByAddress(ListHead %x, Address %x)\n", + ListHead,Address); + + if (ListHead==NULL) + { + return(NULL); + } + current_entry = ListHead->Flink; while (current_entry!=ListHead) { @@ -307,14 +313,14 @@ static ULONG MmFindGapWithoutLock(KPROCESSOR_MODE Mode, ULONG Length) DPRINT("Base %x Gap %x\n",current->BaseAddress,Gap); if (Gap >= Length) { - return(current->BaseAddress + current->Length); + return(current->BaseAddress + PAGE_ROUND_UP(current->Length)); } current_entry = current_entry->Flink; } current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); //DbgPrint("current %x returning %x\n",current,current->BaseAddress+ // current->Length); - return(current->BaseAddress + current->Length); + return(current->BaseAddress + PAGE_ROUND_UP(current->Length)); } NTSTATUS MmInitMemoryAreas(VOID) diff --git a/reactos/ntoskrnl/tst/test.c b/reactos/ntoskrnl/tst/test.c index 5ac3209c3d3..922694aeb06 100644 --- a/reactos/ntoskrnl/tst/test.c +++ b/reactos/ntoskrnl/tst/test.c @@ -14,7 +14,7 @@ #include #include -#define NDEBUG +//#define NDEBUG #include #include @@ -23,10 +23,10 @@ static KEVENT event = {}; //static KEVENT event2; +NTSTATUS TstShell(VOID); /* FUNCTIONS ****************************************************************/ -/* -NTSTATUS TstPlaySound(void) +NTSTATUS TstPlaySound(VOID) { HANDLE hfile; @@ -45,23 +45,31 @@ NTSTATUS TstPlaySound(void) NTSTATUS TstFirstThread(PVOID start) { + int i; + printk("Beginning Thread A\n"); for (;;) +// for (i=0;i<10;i++) { KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); printk("AAA "); - KeSetEvent(&event,IO_NO_INCREMENT,FALSE); + KeSetEvent(&event,IO_NO_INCREMENT,FALSE); + for (i=0;i<10000;i++); } } NTSTATUS TstSecondThread(PVOID start) { + int i; + printk("Beginning Thread B\n"); - for (;;) + for(;;) +// for (i=0;i<10;i++) { - KeSetEvent(&event,IO_NO_INCREMENT,FALSE); KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); printk("BBB "); + KeSetEvent(&event,IO_NO_INCREMENT,FALSE); + for (i=0;i<100000;i++); } } @@ -69,23 +77,23 @@ NTSTATUS TstThreadSupport() { HANDLE th1, th2; - KeInitializeEvent(&event,SynchronizationEvent,FALSE); + KeInitializeEvent(&event,SynchronizationEvent,TRUE); PsCreateSystemThread(&th1,0,NULL,NULL,NULL,TstFirstThread,NULL); PsCreateSystemThread(&th2,0,NULL,NULL,NULL,TstSecondThread,NULL); printk("Ending main thread\n"); for(;;); } -void TstGeneralWrite() +void TstGeneralWrite(VOID) { OBJECT_ATTRIBUTES attr; HANDLE hfile; - char buf[256]; + char buf[512]; ANSI_STRING afilename; UNICODE_STRING ufilename; DbgPrint("Opening test device\n"); - RtlInitAnsiString(&afilename,"\\Device\\Test"); + RtlInitAnsiString(&afilename,"\\Device\\SDisk"); RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE); InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL); ZwOpenFile(&hfile,0,&attr,NULL,0,0); @@ -94,19 +102,19 @@ void TstGeneralWrite() DbgPrint("Failed to open test device\n"); return; } - strcpy(buf,"hello world"); - ZwWriteFile(hfile, + ZwReadFile(hfile, NULL, NULL, NULL, NULL, buf, - strlen(buf), + 512, 0, 0); + DbgPrint("buf %s\n",buf); } -/* -void TstParallelPortWrite() + +void TstParallelPortWrite(VOID) { HANDLE hfile; @@ -119,7 +127,7 @@ void TstParallelPortWrite() // WriteFile(hfile,"hello world",strlen("hello world"),NULL,NULL); } -void TstKeyboardRead() +void TstKeyboardRead(VOID) { OBJECT_ATTRIBUTES attr; HANDLE hfile; @@ -152,7 +160,7 @@ void TstKeyboardRead() // DbgPrint("%c",key[1].AsciiChar); } } -*/ + /* IDE TEST STUFF ***********************************************************/ typedef struct _BOOT_PARAMETERS { @@ -196,6 +204,43 @@ typedef struct _ROOT_DIR_ENTRY { #define ENTRIES_PER_BLOCK (512 / sizeof(ROOT_DIR_ENTRY)) +void TstFileRead(VOID) +{ + OBJECT_ATTRIBUTES attr; + HANDLE hfile; + ANSI_STRING afilename; + UNICODE_STRING ufilename; + char ch; + IO_STATUS_BLOCK IoStatusBlock; + + DbgPrint("Opening file\n"); + RtlInitAnsiString(&afilename,"\\??\\C:\\my_other_directory\\..\\" + "my_valid_directory\\apc.txt"); + RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE); + InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL); + ZwOpenFile(&hfile,0,&attr,NULL,0,0); + if (hfile==NULL) + { + DbgPrint("Failed to open file\n"); + return; + } + while (1) + { +// CHECKPOINT; + ZwReadFile(hfile, + NULL, + NULL, + NULL, + &IoStatusBlock, + &ch, + 1, + NULL, + NULL); + DbgPrint("%c",ch); + } + CHECKPOINT; + } + void TstIDERead(void) { BOOLEAN TestFailed; @@ -371,9 +416,12 @@ for(;;); void TstBegin() { +// TstFileRead(); // TstGeneralWrite(); // TstThreadSupport(); // TstKeyboardRead(); TstIDERead(); +// TstKeyboardRead(); +// TstShell(); }