diff --git a/plat/msdos386/boot.s b/plat/msdos386/boot.s index 282dcb866..b30b6594c 100644 --- a/plat/msdos386/boot.s +++ b/plat/msdos386/boot.s @@ -36,7 +36,7 @@ begtext: cseg mov (interrupt_ptr+0), esi cseg o16 mov (transfer_buffer_ptr), di - mov eax, endbss + mov eax, __end cseg callf (realloc_ptr) ! Clear BSS. @@ -161,7 +161,7 @@ empty_environment: add esp, 5*4 ! Bail out if something went wrong. - test ax, ax + test eax, eax jnz no_room ! argc, argv, and envp are now at the stack top. Now go. @@ -197,6 +197,7 @@ rmode: .space 2 pmode_cs: .space 2 pmode_ds: .space 2 +.define realloc_ptr .define interrupt_ptr .define rmode .define pmode_cs diff --git a/plat/msdos386/libsys/brk.s b/plat/msdos386/libsys/brk.s new file mode 100644 index 000000000..0e3170467 --- /dev/null +++ b/plat/msdos386/libsys/brk.s @@ -0,0 +1,23 @@ +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +.extern realloc_ptr + +.define _brk +_brk: + enter 0, 0 +newsize = 2*4 + + mov eax, newsize(ebp) + callf (realloc_ptr) + xor eax, eax + leave + ret + + diff --git a/plat/msdos386/libsys/build.lua b/plat/msdos386/libsys/build.lua index 4d349eb0f..71ac521b8 100644 --- a/plat/msdos386/libsys/build.lua +++ b/plat/msdos386/libsys/build.lua @@ -1,13 +1,14 @@ acklibrary { name = "lib", srcs = { - "./brk.c", + "./_hol0.s", + "./brk.s", "./close.s", "./errno.s", "./getpid.s", - "./_hol0.s", "./isatty.s", "./rename.s", + "./sbrk.c", "./sys_exists.s", "./sys_getdate.s", "./sys_gettime.s", diff --git a/plat/msdos386/libsys/brk.c b/plat/msdos386/libsys/sbrk.c similarity index 61% rename from plat/msdos386/libsys/brk.c rename to plat/msdos386/libsys/sbrk.c index ab333e550..988d406f3 100644 --- a/plat/msdos386/libsys/brk.c +++ b/plat/msdos386/libsys/sbrk.c @@ -8,29 +8,9 @@ #include #include "libsys.h" -#define STACK_BUFFER 128 /* number of bytes to leave for stack */ - extern char _end[1]; static char* current = _end; -int brk(void* newend) -{ - /* This variable is used to figure out the current stack pointer, - * by taking its address. */ - char dummy; - char* p = newend; - - if ((p > (&dummy - STACK_BUFFER)) || - (p < _end)) - { - errno = ENOMEM; - return -1; - } - - current = p; - return 0; -} - void* sbrk(int increment) { char* old; diff --git a/plat/msdos386/libsys/sys_isreadyr.s b/plat/msdos386/libsys/sys_isreadyr.s index 9a400859d..ff3960b27 100644 --- a/plat/msdos386/libsys/sys_isreadyr.s +++ b/plat/msdos386/libsys/sys_isreadyr.s @@ -17,13 +17,13 @@ .define __sys_isreadyr __sys_isreadyr: - int 3 - mov bx, sp - mov ax, 0x4406 - mov bx, 2(bx) + mov ebx, sp + mov eax, 0x4406 + mov ebx, 4(ebx) int 0x21 jnc ok movb al, 0 ok: cbw + cwd ret diff --git a/plat/msdos386/libsys/sys_rawread.s b/plat/msdos386/libsys/sys_rawread.s index d7c14aa54..c8ba4bea0 100644 --- a/plat/msdos386/libsys/sys_rawread.s +++ b/plat/msdos386/libsys/sys_rawread.s @@ -26,5 +26,60 @@ .define __sys_rawread __sys_rawread: - int 3 + enter 4, 0 +amount_transferred = -1*4 +file_handle = 2*4 +write_buffer = 3*4 +amount_to_read = 4*4 + + mov amount_transferred(ebp), 0 + +mainloop: + mov eax, amount_to_read(ebp) + test eax, eax + jz exit + + mov ecx, 32*1024 + cmp eax, ecx + jge 2f + mov ecx, eax +2: + + ! Read from DOS into the transfer buffer. + + movb ah, 0x3f + o16 mov dx, (transfer_buffer_ptr) + o16 mov bx, file_handle(ebp) + mov ecx, 0x80 + or ebx, 0x210000 + callf (interrupt_ptr) + jc exit + test eax, eax + jz exit + + ! Copy eax bytes out of the transfer buffer. + + mov ecx, eax + push eax + movzx esi, (transfer_buffer_ptr) + mov edi, write_buffer(ebp) + mov es, (pmode_ds) + cld +1: + eseg lods + movb (edi), al + add edi, 4 + loop 1b + pop eax + + add write_buffer(ebp), eax + add amount_transferred(ebp), eax + sub amount_to_read(ebp), eax + jmp mainloop + +exit: + mov eax, amount_transferred(ebp) + leave + ret + diff --git a/plat/msdos386/libsys/sys_rawwrite.s b/plat/msdos386/libsys/sys_rawwrite.s index e13e5e52c..bef6481b2 100644 --- a/plat/msdos386/libsys/sys_rawwrite.s +++ b/plat/msdos386/libsys/sys_rawwrite.s @@ -32,31 +32,39 @@ file_handle = 2*4 read_buffer = 3*4 amount_to_write = 4*4 - mov es, (pmode_ds) mov amount_transferred(ebp), 0 mainloop: - mov ecx, 32*1024 - cmp amount_to_write(ebp), ecx - jge 2f - mov ecx, amount_to_write(ebp) - test ecx, ecx + mov eax, amount_to_write(ebp) + test eax, eax jz exit + + mov ecx, 32*1024 + cmp eax, ecx + jge 2f + mov ecx, eax 2: + ! Copy ecx bytes into the transfer buffer. push ecx mov esi, read_buffer(ebp) movzx edi, (transfer_buffer_ptr) + mov es, (pmode_ds) + cld rep movsb pop ecx + ! Write from the transfer buffer to DOS. + movb ah, 0x40 o16 mov dx, (transfer_buffer_ptr) o16 mov bx, file_handle(ebp) or ebx, 0x210000 callf (interrupt_ptr) - movzx eax, ax + jc exit + + ! Update counters and go again. add read_buffer(ebp), eax add amount_transferred(ebp), eax @@ -64,7 +72,7 @@ mainloop: jmp mainloop exit: - mov eax, amount_to_write(ebp) + mov eax, amount_transferred(ebp) leave ret diff --git a/plat/msdos386/stub.s b/plat/msdos386/stub.s index 03887ec5d..725d3431e 100644 --- a/plat/msdos386/stub.s +++ b/plat/msdos386/stub.s @@ -337,12 +337,12 @@ interrupt: pop ds pop es pushf - mov ax, (dpmi_eax) - mov bx, (dpmi_ebx) - mov cx, (dpmi_ecx) - mov dx, (dpmi_edx) - mov si, (dpmi_esi) - mov di, (dpmi_edi) + o32 movzx eax, (dpmi_eax) + o32 movzx ebx, (dpmi_ebx) + o32 movzx ecx, (dpmi_ecx) + o32 movzx edx, (dpmi_edx) + o32 movzx esi, (dpmi_esi) + o32 movzx edi, (dpmi_edi) popf ret