push bp mov bp,sp push 10[bp] push 8[bp] push 6[bp] call _main add sp, #0x6 pop bp retf ! 1 ! 1 # 1 "main.c" ! 1 # 5 ! 5 #include "std_singos/stdio.h" ! 1 ! 1 void print(string); !BCC_EOS ! 2 void* dump_ax_return(input); !BCC_EOS ! 3 ! 4 void print(string) ! 5 char* string; export _print _print: !BCC_EOS ! 6 { ! 7 #asm !BCC_ASM _print.string set 2 push bp mov bp,sp mov si,4[bp] call 0x0000:0x7C47 pop bp ! 13 endasm !BCC_ENDASM ! 14 } ret ! 15 ! 16 void print_stack(argument) ! 17 { export _print_stack _print_stack: ! 18 #asm !BCC_ASM _print_stack.argument set 2 push bp mov bp,sp push ds push ax mov ax, ss mov ds, ax mov si,4[bp] call 0x0000:0x7C47 pop ax pop ds pop bp ! 32 endasm !BCC_ENDASM ! 33 } ret ! 34 ! 35 void* dump_ax_return(input) ! 36 void* input; export _dump_ax_return _dump_ax_return: !BCC_EOS ! 37 { ! 38 return input; push bp mov bp,sp push di push si mov ax,4[bp] pop si pop di pop bp ret !BCC_EOS ! 39 } ! 40 ! 41 void dump_ax(input) ! 42 void* input; export _dump_ax _dump_ax: !BCC_EOS ! 43 { ! 44 dump_ax_return(input) push bp mov bp,sp push di push si ! 45 #asm ! Debug: list * void input = [S+6+2] (used reg = ) push 4[bp] ! Debug: func () * void = dump_ax_return+0 (used reg = ) call _dump_ax_return inc sp inc sp !BCC_EOS !BCC_ASM _dump_ax.input set 8 .dump_ax.input set 4 push bp mov bp,sp call 0x000:0x7C2A pop bp ! 50 endasm !BCC_ENDASM !BCC_EOS ! 51 } pop si pop di pop bp ret ! 52 ! 53 void print_newline() ! 54 { export _print_newline _print_newline: ! 55 #asm !BCC_ASM printCRLF: mov ah, #0xE mov al, #13 int #0x10 mov al, #10 int #0x10 ret ! 63 endasm !BCC_ENDASM ! 64 } ret ! 65 ! 6 # 1 "std_singos/stdlib.h" ! 1 unsigned int global_heap_start = 0; export _global_heap_start _global_heap_start: .word 0 !BCC_EOS ! 2 unsigned int global_heap_end = 0; export _global_heap_end _global_heap_end: .word 0 !BCC_EOS ! 3 unsigned int global_heap_next = 0; export _global_heap_next _global_heap_next: .word 0 !BCC_EOS ! 4 ! 5 void* malloc(num_bytes); !BCC_EOS ! 6 int set_heap_settings(param_start, param_end); !BCC_EOS ! 7 unsigned int get_heap_next(); !BCC_EOS ! 8 ! 9 void* malloc(num_bytes) ! 10 int num_bytes; .text export _malloc _malloc: !BCC_EOS ! 11 { ! 12 unsigned int allocated_pointer = global_heap_next; push bp mov bp,sp push di push si dec sp dec sp ! Debug: eq unsigned int = [global_heap_next+0] to unsigned int allocated_pointer = [S+8-8] (used reg = ) mov ax,[_global_heap_next] mov -6[bp],ax !BCC_EOS ! 13 global_heap_next = global_heap_next + num_bytes; ! Debug: add int num_bytes = [S+8+2] to unsigned int = [global_heap_next+0] (used reg = ) mov ax,[_global_heap_next] add ax,4[bp] ! Debug: eq unsigned int = ax+0 to unsigned int = [global_heap_next+0] (used reg = ) mov [_global_heap_next],ax !BCC_EOS ! 14 if (global_heap_next > global_heap_end) ! Debug: gt unsigned int = [global_heap_end+0] to unsigned int = [global_heap_next+0] (used reg = ) mov ax,[_global_heap_next] cmp ax,[_global_heap_end] jbe .1 .2: ! 15 { ! 16 return 0; xor ax,ax inc sp inc sp pop si pop di pop bp ret !BCC_EOS ! 17 } ! 18 ! 19 return allocated_pointer; .1: mov ax,-6[bp] inc sp inc sp pop si pop di pop bp ret !BCC_EOS ! 20 } ! 21 ! 22 int set_heap_settings(param_start, param_end) ! 23 unsigned int param_start; export _set_heap_settings _set_heap_settings: !BCC_EOS ! 24 unsigned int param_end; !BCC_EOS ! 25 { ! 26 global_heap_start = param_start; push bp mov bp,sp push di push si ! Debug: eq unsigned int param_start = [S+6+2] to unsigned int = [global_heap_start+0] (used reg = ) mov ax,4[bp] mov [_global_heap_start],ax !BCC_EOS ! 27 global_heap_next = param_start; ! Debug: eq unsigned int param_start = [S+6+2] to unsigned int = [global_heap_next+0] (used reg = ) mov ax,4[bp] mov [_global_heap_next],ax !BCC_EOS ! 28 global_heap_end = param_end; ! Debug: eq unsigned int param_end = [S+6+4] to unsigned int = [global_heap_end+0] (used reg = ) mov ax,6[bp] mov [_global_heap_end],ax !BCC_EOS ! 29 return 0; xor ax,ax pop si pop di pop bp ret !BCC_EOS ! 30 } ! 31 ! 32 unsigned int get_heap_next() ! 33 { export _get_heap_next _get_heap_next: ! 34 return global_heap_next; push bp mov bp,sp push di push si mov ax,[_global_heap_next] pop si pop di pop bp ret !BCC_EOS ! 35 # 6 "main.c" ! 6 } ! 7 # 3 "std_singos/string.h" ! 3 typedef struct Length_String { ! 4 short dynamic; !BCC_EOS ! 5 unsigned int length; !BCC_EOS ! 6 char *chars; !BCC_EOS ! 7 } Length_String; !BCC_EOS ! 8 ! 9 typedef struct String_Array { ! 10 unsigned int length; !BCC_EOS ! 11 Length_String **strings; !BCC_EOS ! 12 } String_Array; !BCC_EOS ! 13 ! 14 void strcpy (destination, destination_segment, source, source_segment ); !BCC_EOS ! 15 int strlen (source, source_segment); !BCC_EOS ! 16 void memcpy (destination, destination_segment, source, source_segment, num_bytes ); !BCC_EOS ! 17 ! 18 ! 19 String_Array *string_split_c(string, delim, keep_delim); !BCC_EOS ! 20 Length_String *make_length_string(length, chars); !BCC_EOS ! 21 Length_String *make_length_string_c(cstring); !BCC_EOS ! 22 String_Array *length_string_split(string, delim, keep_delim); !BCC_EOS ! 23 String_Array *create_length_string_array(array_size); !BCC_EOS ! 24 Length_String *create_length_string(length, chars); !BCC_EOS ! 25 ! 26 ! 27 ! 28 int strlen (source, source_segment) ! 29 { export _strlen _strlen: ! 30 #asm !BCC_ASM _strlen.source set 2 _strlen.source_segment set 4 push bp mov bp,sp push ds push bx mov ax, 6[bp]; mov ds, ax mov bx, 4[bp]; label_strlen: mov cx, #0x0 ; Set counte to zero .label_strlen_loop: mov BYTE al, [bx] cmp al, #0x0 je .label_strlen_done inc cx ; Count 1 inc bx ; Look at next char jmp .label_strlen_loop .label_strlen_done: mov ax, cx pop bx pop ds pop bp ! 58 endasm !BCC_ENDASM ! 59 } ret ! 60 ! 61 void strcpy (destination, destination_segment, source, source_segment ) ! 62 char *destination; export _strcpy _strcpy: !BCC_EOS ! 63 int destination_segment; !BCC_EOS ! 64 char *source; !BCC_EOS ! 65 int source_segment; !BCC_EOS ! 66 { ! 67 #asm !BCC_ASM _strcpy.source set 6 _strcpy.destination set 2 _strcpy.source_segment set 8 _strcpy.destination_segment set 4 ; copy two strings ; IN si: the first (zero terminated) string ; IN di: the second (zero terminated) string ; OUT SF and ZF (same semantics as cmp) ! 73 77 push bp mov bp,sp label_strcpy: push ax push bx push di push es push si push ds mov ax, 4[bp]; ; mov di, ax mov ax, 6[bp]; ; mov es, ax mov ax, 8[bp]; ; mov si, ax mov ax, 10[bp]; ; mov ds, ax mov cx, 0x050 .label_strcpy_loop: movsb cmp cx, 0x0 je .label_strcpy_end dec cx jmp .label_strcpy_loop .label_strcpy_end: pop ds pop si pop es pop di pop bx pop ax pop bp ! 111 endasm !BCC_ENDASM ! 112 } ret ! 113 ! 114 void memcpy (destination, destination_segment, source, source_segment, num_bytes) ! 115 void *destination; export _memcpy _memcpy: !BCC_EOS ! 116 int destination_segment; !BCC_EOS ! 117 void *source; !BCC_EOS ! 118 int source_segment; !BCC_EOS ! 119 int num_bytes; !BCC_EOS ! 120 { ! 121 #asm !BCC_ASM _memcpy.source set 6 _memcpy.destination set 2 _memcpy.num_bytes set $A _memcpy.source_segment set 8 _memcpy.destination_segment set 4 ; copy two strings ; IN si: the first (zero terminated) string ; IN di: the second (zero terminated) string ; OUT SF and ZF (same semantics as cmp) ! 127 132 push bp mov bp,sp label_memcpy: push ax push bx push di push es push si push ds mov ax, 4[bp]; ; mov di, ax mov ax, 6[bp]; ; mov es, ax mov ax, 8[bp]; ; mov si, ax mov ax, 10[bp]; ; mov ds, ax mov cx, 12[bp]; .label_memcpy_loop: movsb cmp cx, 0x0 je .label_memcpy_end dec cx jmp .label_memcpy_loop .label_memcpy_end: pop ds pop si pop es pop di pop bx pop ax pop bp ! 166 endasm !BCC_ENDASM ! 167 } ret ! 168 ! 169 String_Array *string_split_c(string, delim, keep_delim) ! 170 char *string; export _string_split_c _string_split_c: !BCC_EOS ! 171 char delim ! 171 ; !BCC_EOS ! 172 short keep_delim; !BCC_EOS ! 173 { ! 174 return length_string_split(make_length_string_c(string), delim, keep_delim); push bp mov bp,sp push di push si ! Debug: list short keep_delim = [S+6+6] (used reg = ) push 8[bp] ! Debug: list char delim = [S+8+4] (used reg = ) mov al,6[bp] xor ah,ah push ax ! Debug: list * char string = [S+$A+2] (used reg = ) push 4[bp] ! Debug: func () * struct Length_String = make_length_string_c+0 (used reg = ) call _make_length_string_c inc sp inc sp ! Debug: list * struct Length_String = ax+0 (used reg = ) push ax ! Debug: func () * struct String_Array = length_string_split+0 (used reg = ) call _length_string_split add sp,*6 ! Debug: cast * struct String_Array = const 0 to * struct String_Array = ax+0 (used reg = ) pop si pop di pop bp ret !BCC_EOS ! 175 } ! 176 ! 177 Length_String *make_length_string_c(cstring) ! 178 char *cstring; export _make_length_string_c _make_length_string_c: !BCC_EOS ! 179 { ! 180 return make_length_string(strlen(cstring, 0x7e0), cstring); push bp mov bp,sp push di push si ! Debug: list * char cstring = [S+6+2] (used reg = ) push 4[bp] ! Debug: list int = const $7E0 (used reg = ) mov ax,#$7E0 push ax ! Debug: list * char cstring = [S+$A+2] (used reg = ) push 4[bp] ! Debug: func () int = strlen+0 (used reg = ) call _strlen add sp,*4 ! Debug: list int = ax+0 (used reg = ) push ax ! Debug: func () * struct Length_String = make_length_string+0 (used reg = ) call _make_length_string add sp,*4 ! Debug: cast * struct Length_String = const 0 to * struct Length_String = ax+0 (used reg = ) pop si pop di pop bp ret !BCC_EOS ! 181 } ! 182 ! 183 Length_String *make_length_string(length, chars) ! 184 unsigned int length; export _make_length_string _make_length_string: !BCC_EOS ! 185 char *chars; !BCC_EOS ! 186 { ! 187 ! 188 Length_String *legth_string = malloc(sizeof(Length_String)); push bp mov bp,sp push di push si dec sp dec sp ! Debug: list int = const 6 (used reg = ) mov ax,*6 push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * struct Length_String legth_string = [S+8-8] (used reg = ) mov -6[bp],ax !BCC_EOS ! 189 ! 190 char *copy = malloc(length + 1); dec sp dec sp ! Debug: add int = const 1 to unsigned int length = [S+$A+2] (used reg = ) mov ax,4[bp] ! Debug: list unsigned int = ax+1 (used reg = ) inc ax push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * char copy = [S+$A-$A] (used reg = ) mov -8[bp],ax !BCC_EOS ! 191 memcpy(copy, 0x7e0, chars, 0x7e0, length); ! Debug: list unsigned int length = [S+$A+2] (used reg = ) push 4[bp] ! Debug: list int = const $7E0 (used reg = ) mov ax,#$7E0 push ax ! Debug: list * char chars = [S+$E+4] (used reg = ) push 6[bp] ! Debug: list int = const $7E0 (used reg = ) mov ax,#$7E0 push ax ! Debug: list * char copy = [S+$12-$A] (used reg = ) push -8[bp] ! Debug: func () void = memcpy+0 (used reg = ) call _memcpy add sp,*$A !BCC_EOS ! 192 copy[length] = ''; ! Debug: ptradd unsigned int length = [S+$A+2] to * char copy = [S+$A-$A] (used reg = ) mov ax,4[bp] add ax,-8[bp] mov bx,ax ! Debug: eq int = const 0 to char = [bx+0] (used reg = ) xor al,al mov [bx],al !BCC_EOS ! 193 ! 194 legth_string->dynamic = 0; mov bx,-6[bp] ! Debug: eq int = const 0 to short = [bx+0] (used reg = ) xor ax,ax mov [bx],ax !BCC_EOS ! 195 legth_string->length = length; mov bx,-6[bp] ! Debug: eq unsigned int length = [S+$A+2] to unsigned int = [bx+2] (used reg = ) mov ax,4[bp] mov 2[bx],ax !BCC_EOS ! 196 legth_string->chars = (char *)chars; mov bx,-6[bp] ! Debug: eq * char chars = [S+$A+4] to * char = [bx+4] (used reg = ) mov si,6[bp] mov 4[bx],si !BCC_EOS ! 197 ! 198 return legth_string; mov ax,-6[bp] add sp,*4 pop si pop di pop bp ret !BCC_EOS ! 199 } ! 200 ! 201 String_Array *length_string_split(string, delim, keep_delim) ! Register BX SI used in function make_length_string ! 202 Length_String *string; export _length_string_split _length_string_split: !BCC_EOS ! 203 char delim; !BCC_EOS ! 204 short keep_delim; !BCC_EOS ! 205 { ! 206 unsigned int i; !BCC_EOS ! 207 unsigned int last; !BCC_EOS ! 208 ! 209 unsigned int count = 0; push bp mov bp,sp push di push si add sp,*-6 ! Debug: eq int = const 0 to unsigned int count = [S+$C-$C] (used reg = ) xor ax,ax mov -$A[bp],ax !BCC_EOS ! 210 unsigned int insert_index = 0; dec sp dec sp ! Debug: eq int = const 0 to unsigned int insert_index = [S+$E-$E] (used reg = ) xor ax,ax mov -$C[bp],ax !BCC_EOS ! 211 String_Array *result; !BCC_EOS ! 212 int k; !BCC_EOS ! 213 ! 214 i = 0; add sp,*-4 ! Debug: eq int = const 0 to unsigned int i = [S+$12-8] (used reg = ) xor ax,ax mov -6[bp],ax !BCC_EOS ! 215 last = 0; ! Debug: eq int = const 0 to unsigned int last = [S+$12-$A] (used reg = ) xor ax,ax mov -8[bp],ax !BCC_EOS ! 216 while(i < string->length) { jmp .4 .5: ! 217 if (string->chars[i] == delim) { mov bx,4[bp] ! Debug: ptradd unsigned int i = [S+$12-8] to * char = [bx+4] (used reg = ) mov ax,-6[bp] add ax,4[bx] mov bx,ax ! Debug: logeq char delim = [S+$12+4] to char = [bx+0] (used reg = ) mov al,[bx] cmp al,6[bp] jne .6 .7: ! 218 if (i > last+1) { ! Debug: add int = const 1 to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] ! Debug: gt unsigned int = ax+1 to unsigned int i = [S+$12-8] (used reg = ) inc ax cmp ax,-6[bp] jae .8 .9: ! 219 ++count; ! Debug: preinc unsigned int count = [S+$12-$C] (used reg = ) mov ax,-$A[bp] inc ax mov -$A[bp],ax !BCC_EOS ! 220 } ! 221 last = i; .8: ! Debug: eq unsigned int i = [S+$12-8] to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-6[bp] mov -8[bp],ax !BCC_EOS ! 222 } ! 223 ++i; .6: ! Debug: preinc unsigned int i = [S+$12-8] (used reg = ) mov ax,-6[bp] inc ax mov -6[bp],ax !BCC_EOS ! 224 } ! 225 if (i > last+1) { .4: mov bx,4[bp] ! Debug: lt unsigned int = [bx+2] to unsigned int i = [S+$12-8] (used reg = ) mov ax,-6[bp] cmp ax,2[bx] jb .5 .A: .3: ! Debug: add int = const 1 to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] ! Debug: gt unsigned int = ax+1 to unsigned int i = [S+$12-8] (used reg = ) inc ax cmp ax,-6[bp] jae .B .C: ! 226 ++count; ! Debug: preinc unsigned int count = [S+$12-$C] (used reg = ) mov ax,-$A[bp] inc ax mov -$A[bp],ax !BCC_EOS ! 227 } ! 228 ! 229 result = create_length_string_array(count); .B: ! Debug: list unsigned int count = [S+$12-$C] (used reg = ) push -$A[bp] ! Debug: func () * struct String_Array = create_length_string_array+0 (used reg = ) call _create_length_string_array inc sp inc sp ! Debug: eq * struct String_Array = ax+0 to * struct String_Array result = [S+$12-$10] (used reg = ) mov -$E[bp],ax !BCC_EOS ! 230 ! 231 if (keep_delim) mov ax,8[bp] test ax,ax je .D .E: ! 232 { ! 233 k = 0; ! Debug: eq int = const 0 to int k = [S+$12-$12] (used reg = ) xor ax,ax mov -$10[bp],ax !BCC_EOS ! 234 } ! 235 else ! 236 { jmp .F .D: ! 237 k = 1; ! Debug: eq int = const 1 to int k = [S+$12-$12] (used reg = ) mov ax,*1 mov -$10[bp],ax !BCC_EOS ! 238 } ! 239 ! 240 i = 0; .F: ! Debug: eq int = const 0 to unsigned int i = [S+$12-8] (used reg = ) xor ax,ax mov -6[bp],ax !BCC_EOS ! 241 last = 0; ! Debug: eq int = const 0 to unsigned int last = [S+$12-$A] (used reg = ) xor ax,ax mov -8[bp],ax !BCC_EOS ! 242 while(i < string->length) { jmp .11 .12: ! 243 if (string->chars[i] == delim) { mov bx,4[bp] ! Debug: ptradd unsigned int i = [S+$12-8] to * char = [bx+4] (used reg = ) mov ax,-6[bp] add ax,4[bx] mov bx,ax ! Debug: logeq char delim = [S+$12+4] to char = [bx+0] (used reg = ) mov al,[bx] cmp al,6[bp] jne .13 .14: ! 244 if (i > last+1) { ! Debug: add int = const 1 to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] ! Debug: gt unsigned int = ax+1 to unsigned int i = [S+$12-8] (used reg = ) inc ax cmp ax,-6[bp] jae .15 .16: ! 245 result->strings[insert_index++] = create_length_string(i-(last+k), string->chars+(last+k)); ! Debug: add int k = [S+$12-$12] to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] add ax,-$10[bp] mov bx,4[bp] ! Debug: ptradd unsigned int = ax+0 to * char = [bx+4] (used reg = ) add ax,4[bx] ! Debug: list * char = ax+0 (used reg = ) push ax ! Debug: add int k = [S+$14-$12] to unsigned int last = [S+$14-$A] (used reg = ) mov ax,-8[bp] add ax,-$10[bp] ! Debug: sub unsigned int = ax+0 to unsigned int i = [S+$14-8] (used reg = ) push ax mov ax,-6[bp] sub ax,-$14[bp] inc sp inc sp ! Debug: list unsigned int = ax+0 (used reg = ) push ax ! Debug: func () * struct Length_String = create_length_string+0 (used reg = ) call _create_length_string add sp,*4 push ax ! Debug: postinc unsigned int insert_index = [S+$14-$E] (used reg = ) mov ax,-$C[bp] inc ax mov -$C[bp],ax mov bx,-$E[bp] ! Debug: ptradd unsigned int = ax-1 to * * struct Length_String = [bx+2] (used reg = ) dec ax shl ax,*1 add ax,2[bx] mov bx,ax ! Debug: eq * struct Length_String (temp) = [S+$14-$14] to * struct Length_String = [bx+0] (used reg = ) mov si,-$12[bp] mov [bx],si inc sp inc sp !BCC_EOS ! 246 } ! 247 last = i; .15: ! Debug: eq unsigned int i = [S+$12-8] to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-6[bp] mov -8[bp],ax !BCC_EOS ! 248 } ! 249 ++i; .13: ! Debug: preinc unsigned int i = [S+$12-8] (used reg = ) mov ax,-6[bp] inc ax mov -6[bp],ax !BCC_EOS ! 250 } ! 251 if (i > last+1) { .11: mov bx,4[bp] ! Debug: lt unsigned int = [bx+2] to unsigned int i = [S+$12-8] (used reg = ) mov ax,-6[bp] cmp ax,2[bx] jb .12 .17: .10: ! Debug: add int = const 1 to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] ! Debug: gt unsigned int = ax+1 to unsigned int i = [S+$12-8] (used reg = ) inc ax cmp ax,-6[bp] jae .18 .19: ! 252 result->strings[insert_index++] = create_length_string(i-(last+k), ((string->chars)+(last+k))); ! Debug: add int k = [S+$12-$12] to unsigned int last = [S+$12-$A] (used reg = ) mov ax,-8[bp] add ax,-$10[bp] mov bx,4[bp] ! Debug: ptradd unsigned int = ax+0 to * char = [bx+4] (used reg = ) add ax,4[bx] ! Debug: list * char = ax+0 (used reg = ) push ax ! Debug: add int k = [S+$14-$12] to unsigned int last = [S+$14-$A] (used reg = ) mov ax,-8[bp] add ax,-$10[bp] ! Debug: sub unsigned int = ax+0 to unsigned int i = [S+$14-8] (used reg = ) push ax mov ax,-6[bp] sub ax,-$14[bp] inc sp inc sp ! Debug: list unsigned int = ax+0 (used reg = ) push ax ! Debug: func () * struct Length_String = create_length_string+0 (used reg = ) call _create_length_string add sp,*4 push ax ! Debug: postinc unsigned int insert_index = [S+$14-$E] (used reg = ) mov ax,-$C[bp] inc ax mov -$C[bp],ax mov bx,-$E[bp] ! Debug: ptradd unsigned int = ax-1 to * * struct Length_String = [bx+2] (used reg = ) dec ax shl ax,*1 add ax,2[bx] mov bx,ax ! Debug: eq * struct Length_String (temp) = [S+$14-$14] to * struct Length_String = [bx+0] (used reg = ) mov si,-$12[bp] mov [bx],si inc sp inc sp !BCC_EOS ! 253 } ! 254 ! 255 return result; .18: mov ax,-$E[bp] add sp,*$C pop si pop di pop bp ret !BCC_EOS ! 256 ! 257 } ! 258 ! 259 String_Array *create_length_string_array(array_size) ! Register BX SI used in function length_string_split ! 260 int array_size; export _create_length_string_array _create_length_string_array: !BCC_EOS ! 261 { ! 262 String_Array *result = malloc(sizeof(String_Array)); push bp mov bp,sp push di push si dec sp dec sp ! Debug: list int = const 4 (used reg = ) mov ax,*4 push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * struct String_Array result = [S+8-8] (used reg = ) mov -6[bp],ax !BCC_EOS ! 263 result->length = array_size; mov bx,-6[bp] ! Debug: eq int array_size = [S+8+2] to unsigned int = [bx+0] (used reg = ) mov ax,4[bp] mov [bx],ax !BCC_EOS ! 264 result->strings = malloc(array_size * sizeof(Length_String)); ! Debug: mul int = const 6 to int array_size = [S+8+2] (used reg = ) mov ax,4[bp] mov dx,ax shl ax,*1 add ax,dx shl ax,*1 ! Debug: list int = ax+0 (used reg = ) push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp mov bx,-6[bp] ! Debug: eq * void = ax+0 to * * struct Length_String = [bx+2] (used reg = ) mov 2[bx],ax !BCC_EOS ! 265 return result; mov ax,-6[bp] inc sp inc sp pop si pop di pop bp ret !BCC_EOS ! 266 } ! 267 ! 268 ! 269 Length_String *create_length_str ! Register BX used in function create_length_string_array ! 269 ing(length, chars) ! 270 unsigned int length; export _create_length_string _create_length_string: !BCC_EOS ! 271 char *chars; !BCC_EOS ! 272 { ! 273 ! 274 Length_String *legth_string = malloc(sizeof(Length_String)); push bp mov bp,sp push di push si dec sp dec sp ! Debug: list int = const 6 (used reg = ) mov ax,*6 push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * struct Length_String legth_string = [S+8-8] (used reg = ) mov -6[bp],ax !BCC_EOS ! 275 char *copy = malloc(length + 1); dec sp dec sp ! Debug: add int = const 1 to unsigned int length = [S+$A+2] (used reg = ) mov ax,4[bp] ! Debug: list unsigned int = ax+1 (used reg = ) inc ax push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * char copy = [S+$A-$A] (used reg = ) mov -8[bp],ax !BCC_EOS ! 276 memcpy(copy, 0x7e0, chars, 0x7e0, length); ! Debug: list unsigned int length = [S+$A+2] (used reg = ) push 4[bp] ! Debug: list int = const $7E0 (used reg = ) mov ax,#$7E0 push ax ! Debug: list * char chars = [S+$E+4] (used reg = ) push 6[bp] ! Debug: list int = const $7E0 (used reg = ) mov ax,#$7E0 push ax ! Debug: list * char copy = [S+$12-$A] (used reg = ) push -8[bp] ! Debug: func () void = memcpy+0 (used reg = ) call _memcpy add sp,*$A !BCC_EOS ! 277 copy[length] = ''; ! Debug: ptradd unsigned int length = [S+$A+2] to * char copy = [S+$A-$A] (used reg = ) mov ax,4[bp] add ax,-8[bp] mov bx,ax ! Debug: eq int = const 0 to char = [bx+0] (used reg = ) xor al,al mov [bx],al !BCC_EOS ! 278 ! 279 legth_string->dynamic = 1; mov bx,-6[bp] ! Debug: eq int = const 1 to short = [bx+0] (used reg = ) mov ax,*1 mov [bx],ax !BCC_EOS ! 280 legth_string->length = length; mov bx,-6[bp] ! Debug: eq unsigned int length = [S+$A+2] to unsigned int = [bx+2] (used reg = ) mov ax,4[bp] mov 2[bx],ax !BCC_EOS ! 281 legth_string->chars = copy; mov bx,-6[bp] ! Debug: eq * char copy = [S+$A-$A] to * char = [bx+4] (used reg = ) mov si,-8[bp] mov 4[bx],si !BCC_EOS ! 282 ! 283 return legth_string; mov ax,-6[bp] add sp,*4 pop si pop di pop bp ret !BCC_EOS ! 284 # 8 "main.c" ! 8 } ! 9 # 1 "driver/disk.h" ! 1 int data_from_disk(index, number_sectors, data_buffer, data_buffer_segment); ! Register BX SI used in function create_length_string !BCC_EOS ! 2 int disk_service_read_data_from_disk(index, number_sectors, data_buffer, data_buffer_segment); !BCC_EOS ! 3 ! 4 int disk_service_read_data_from_disk(index, number_sectors, data_buffer, data_buffer_segment) ! 5 long* index; export _disk_service_read_data_from_disk _disk_service_read_data_from_disk: !BCC_EOS ! 6 long number_sectors; !BCC_EOS ! 7 void* data_buffer; !BCC_EOS ! 8 int data_buffer_segment; !BCC_EOS ! 9 { ! 10 ! 11 #asm !BCC_ASM _disk_service_read_data_from_disk.data_buffer set 8 _disk_service_read_data_from_disk.number_sectors set 4 _disk_service_read_data_from_disk.data_buffer_segment set $A _disk_service_read_data_from_disk.index set 2 ! 13 define number_sectors 8[bp]; push bp mov bp,sp pusha lsfs_load_data: mov ax, 4[bp]; mov WORD [DAPACK.lba_addr_dw_low], ax mov bx, 8[bp]; mov WORD [DAPACK.blkcnt], bx mov cx, 12[bp]; mov WORD [DAPACK.db_addr_segment], cx mov dx, 10[bp]; ; mov WORD [DAPACK.db_addr_offset], dx mov si, #DAPACK ; address of mov ah, #0x42 ; READ mov dl, [global_disk_identifier] int #0x13 ;call 0x0000:0x7C2A popa pop bp ret DAPACK: DAPACK.dap_Size: db 0x10 DAPACK.rev_byte: db 0x0 DAPACK.blkcnt: dw 0x0 DAPACK.db_addr_offset: dw 0x0 DAPACK.db_addr_segment: dw 0x0 DAPACK.lba_addr_dw_low: dd 0x0 DAPACK.lba_addr_dw_high: dd 0x0 global_disk_identifier: db 0x80 ! 51 endasm !BCC_ENDASM ! 52 } ret ! 53 # 12 "main.c" ! 12 #define SPACE_VBR_RECORD 2048 ! 13 ! 14 #define DEFAULT_ENTRY_SIZE 1 ! 15 ! 16 #define NUMBER_OF_MBR_PARTITIONS 4 ! 17 ! 18 #define DEFAULT_DATA_POINTER_SIZE 4 ! 19 ! 20 ! 21 ! 22 void dump_ax(input); !BCC_EOS ! 23 void print_stack(argument); !BCC_EOS ! 24 void print_newline(); !BCC_EOS ! 25 ! 26 typedef struct Directory_Table Directory_Table; !BCC_EOS ! 27 typedef struct Struct_Table_Entry Table_Entry; !BCC_EOS ! 28 typedef struct struct_partition_control partition_control; !BCC_EOS ! 29 typedef struct File_System_Control_ ! 29 Information FSCI; !BCC_EOS ! 30 typedef struct meta_information_format mif; !BCC_EOS ! 31 typedef struct tag_record tag_record; !BCC_EOS ! 32 typedef struct lsfs_file lsfs_file; !BCC_EOS ! 33 typedef struct Parameter_Struct Parameter_Struct; !BCC_EOS ! 34 ! 35 typedef enum Table_Entry_Kind ! 36 { ! 37 ! 38 ENTRY_EMPTY = 0, ! 39 ENTRY_FILE = 1, ! 40 ENTRY_DIRECTORY = 2, ! 41 } Table_Entry_Kind; !BCC_EOS ! 42 ! 43 typedef enum Service_Action ! 44 { ! 45 SERIVCE_LOAD_DISK = 1, ! 46 SERVICE_FIND_ENTRY = 2, ! 47 SERIVCE_READ_DATA = 3, ! 48 SERIVCE_WRITE_DATA = 4, ! 49 ! 50 } Service_Action; !BCC_EOS ! 51 ! 52 struct Struct_Table_Entry ! 53 { ! 54 char filename[256]; !BCC_EOS ! 55 long file_id[2]; !BCC_EOS ! 56 long file_size[2]; !BCC_EOS ! 57 void* ext_file_data_low; !BCC_EOS ! 58 void* ext_file_data_high; !BCC_EOS ! 59 long number_sector_s; !BCC_EOS ! 60 short entry_kind; !BCC_EOS ! 61 short extra_control_bits1; !BCC_EOS ! 62 short extra_control_bits2; !BCC_EOS ! 63 short extra_control_bits3; !BCC_EOS ! 64 long table_entry_sector_index[2]; !BCC_EOS ! 65 long data_pointer[27 * 2]; !BCC_EOS ! 66 }; !BCC_EOS ! 67 ! 68 struct File_System_Control_Information ! 69 { ! 70 char filesystem_information[256]; !BCC_EOS ! 71 long master_table_index[2]; !BCC_EOS ! 72 long this_partition_offset_on_disk[2]; !BCC_EOS ! 73 long next_free_sector[2]; !BCC_EOS ! 74 long next_uniqe_id[2]; !BCC_EOS ! 75 long next_sector_reuse_pointer[2]; !BCC_EOS ! 76 long last_sector_index_on_partition[2]; !BCC_EOS ! 77 long maximum_sectors_on_disk[2]; !BCC_EOS ! 78 long sector_size_on_disk[2]; !BCC_EOS ! 79 long not_used[48]; !BCC_EOS ! 80 ! 81 }; !BCC_EOS ! 82 ! 83 typedef struct Directory_Table ! 84 { ! 85 Table_Entry entries[16 ]; !BCC_EOS ! 86 ! 87 }; !BCC_EOS ! 88 ! 89 struct Parameter_Struct ! 90 { ! 91 char* path; !BCC_EOS ! 92 char* new_path; !BCC_EOS ! 93 int buffer_segment; !BCC_EOS ! 94 int buffer_address; !BCC_EOS ! 95 int buffer_size; !BCC_EOS ! 96 int data_length; !BCC_EOS ! 97 int byte_offset_into_file; !BCC_EOS ! 98 Table_Entry_Kind entry_kind; !BCC_EOS ! 99 }; !BCC_EOS ! 100 ! 101 int main(selector, pointer_parameter_segment, pointer_parameter_struct) ! 102 int selector; export _main _main: !BCC_EOS ! 103 void* pointer_parameter_segment; !BCC_EOS ! 104 void* pointer_parameter_struct; !BCC_EOS ! 105 { ! 106 ! 107 ! 108 ! 109 FSCI fsci; !BCC_EOS ! 110 ! 111 Service_Action service_action; !BCC_EOS ! 112 Directory_Table current_table; !BCC_EOS ! 113 Parameter_Struct parameter_struct; !BCC_EOS ! 114 int local_segment = 0x7e0; push bp mov bp,sp push di push si add sp,#-$2214 ! Debug: eq int = const $7E0 to int local_segment = [S+$221A-$221A] (used reg = ) mov ax,#$7E0 mov -$2218[bp],ax !BCC_EOS ! 115 unsigned int heap_start = 0x2000; dec sp dec sp ! Debug: eq int = const $2000 to unsigned int heap_start = [S+$221C-$221C] (used reg = ) mov ax,#$2000 mov -$221A[bp],ax !BCC_EOS ! 116 unsigned int heap_end = 0xffff; dec sp dec sp ! Debug: eq unsigned int = const $FFFF to unsigned int heap_end = [S+$221E-$221E] (used reg = ) mov ax,#$FFFF mov -$221C[bp],ax !BCC_EOS ! 117 int stack_segment = 0x8fc0; dec sp dec sp ! Debug: eq unsigned int = const $8FC0 to int stack_segment = [S+$2220-$2220] (used reg = ) mov ax,#$8FC0 mov -$221E[bp],ax !BCC_EOS ! 118 int path_length; !BCC_EOS ! 119 long index_as_long; !BCC_EOS ! 120 ! 121 ! 121 char *local_path = 0; add sp,*-8 ! Debug: eq int = const 0 to * char local_path = [S+$2228-$2228] (used reg = ) xor ax,ax mov -$2226[bp],ax !BCC_EOS ! 122 service_action = selector; ! Debug: eq int selector = [S+$2228+2] to int service_action = [S+$2228-$208] (used reg = ) mov ax,4[bp] mov -$206[bp],ax !BCC_EOS ! 123 ! 124 switch (service_action) mov ax,-$206[bp] ! 125 { br .1C ! 126 case SERIVCE_LOAD_DISK: ! 127 { .1D: ! 128 ! 129 ! 130 ! 131 ! 132 index_as_long = pointer_parameter_struct; ! Debug: eq * void pointer_parameter_struct = [S+$2228+6] to long index_as_long = [S+$2228-$2226] (used reg = ) mov ax,8[bp] xor bx,bx mov -$2224[bp],ax mov -$2222[bp],bx !BCC_EOS ! 133 disk_service_read_data_from_disk(index_as_long, 1, &fsci, stack_segment); ! Debug: list int stack_segment = [S+$2228-$2220] (used reg = ) push -$221E[bp] ! Debug: list * struct File_System_Control_Information fsci = S+$222A-$206 (used reg = ) lea bx,-$204[bp] push bx ! Debug: list int = const 1 (used reg = ) mov ax,*1 push ax ! Debug: list long index_as_long = [S+$222E-$2226] (used reg = ) push -$2222[bp] push -$2224[bp] ! Debug: func () int = disk_service_read_data_from_disk+0 (used reg = ) call _disk_service_read_data_from_disk add sp,*$A !BCC_EOS ! 134 print("File System has been loaded: "); ! Debug: list * char = .1E+0 (used reg = ) mov bx,#.1E push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 135 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 136 set_heap_settings(heap_start, heap_end); ! Debug: list unsigned int heap_end = [S+$2228-$221E] (used reg = ) push -$221C[bp] ! Debug: list unsigned int heap_start = [S+$222A-$221C] (used reg = ) push -$221A[bp] ! Debug: func () int = set_heap_settings+0 (used reg = ) call _set_heap_settings add sp,*4 !BCC_EOS ! 137 print_stack(fsci.filesystem_information); ! Debug: list * char fsci = S+$2228-$206 (used reg = ) lea bx,-$204[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) call _print_stack inc sp inc sp !BCC_EOS ! 138 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 139 } break; br .1A !BCC_EOS ! 140 case SERVICE_FIND_ENTRY: ! 141 { .1F: ! 142 String_Array *path_array; !BCC_EOS ! 143 int i; !BCC_EOS ! 144 memcpy(¶meter_struct, stack_segment, pointer_parameter_struct, pointer_parameter_segment, sizeof(Parameter_Struct)); ! Debug: list int = const $10 (used reg = ) mov ax,*$10 push ax ! Debug: list * void pointer_parameter_segment = [S+$222E+4] (used reg = ) push 6[bp] ! Debug: list * void pointer_parameter_struct = [S+$2230+6] (used reg = ) push 8[bp] ! Debug: list int stack_segment = [S+$2232-$2220] (used reg = ) push -$221E[bp] ! Debug: list * struct Parameter_Struct parameter_struct = S+$2234-$2218 (used reg = ) lea bx,-$2216[bp] push bx ! Debug: func () void = memcpy+0 (used reg = ) call _memcpy add sp,*$A !BCC_EOS ! 145 path_length = strlen(parameter_struct.path, pointer_parameter_segment); ! Debug: list * void pointer_parameter_segment = [S+$222C+4] (used reg = ) push 6[bp] ! Debug: list * char parameter_struct = [S+$222E-$2218] (used reg = ) push -$2216[bp] ! Debug: func () int = strlen+0 (used reg = ) call _strlen add sp,*4 ! Debug: eq int = ax+0 to int path_length = [S+$222C-$2222] (used reg = ) mov -$2220[bp],ax !BCC_EOS ! 146 local_path = malloc(256); ! Debug: list int = const $100 (used reg = ) mov ax,#$100 push ax ! Debug: func () * void = malloc+0 (used reg = ) call _malloc inc sp inc sp ! Debug: eq * void = ax+0 to * char local_path = [S+$222C-$2228] (used reg = ) mov -$2226[bp],ax !BCC_EOS ! 147 memcpy(local_path, local_segment, parameter_struct.path, pointer_parameter_segment, path_length); ! Debug: list int path_length = [S+$222C-$2222] (used reg = ) push -$2220[bp] ! Debug: list * void pointer_parameter_segment = [S+$222E+4] (used reg = ) push 6[bp] ! Debug: list * char parameter_struct = [S+$2230-$2218] (used reg = ) push -$2216[bp] ! Debug: list int local_segment = [S+$2232-$221A] (used reg = ) push -$2218[bp] ! Debug: list * char local_path = [S+$2234-$2228] (used reg = ) push -$2226[bp] ! Debug: func () void = memcpy+0 (used reg = ) call _memcpy add sp,*$A !BCC_EOS ! 148 local_path[path_length] = 0; ! Debug: ptradd int path_length = [S+$222C-$2222] to * char local_path = [S+$222C-$2228] (used reg = ) mov ax,-$2220[bp] add ax,-$2226[bp] mov bx,ax ! Debug: eq int = const 0 to char = [bx+0] (used reg = ) xor al,al mov [bx],al !BCC_EOS ! 149 print(local_path); ! Debug: list * char local_path = [S+$222C-$2228] (used reg = ) push -$2226[bp] ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 150 ! 151 path_array = string_split_c(local_path, '/', 0); ! Debug: list int = const 0 (used reg = ) xor ax,ax push ax ! Debug: list int = const $2F (used reg = ) mov ax,*$2F push ax ! Debug: list * char local_path = [S+$2230-$2228] (used reg = ) push -$2226[bp] ! Debug: func () * struct String_Array = string_split_c+0 (used reg = ) call _string_split_c add sp,*6 ! Debug: eq * struct String_Array = ax+0 to * struct String_Array path_array = [S+$222C-$222A] (used reg = ) mov -$2228[bp],ax !BCC_EOS ! 152 ! 153 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 154 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 155 for (i = 0; i < path_array->length; ++i) ! Debug: eq int = const 0 to int i = [S+$222C-$222C] (used reg = ) xor ax,ax mov -$222A[bp],ax !BCC_EOS !BCC_EOS ! 156 { jmp .22 .23: ! 157 print(path_array->strings[i]->chars); mov bx,-$2228[bp] ! Debug: ptradd int i = [S+$222C-$222C] to * * struct Length_String = [bx+2] (used reg = ) mov ax,-$222A[bp] shl ax,*1 add ax,2[bx] mov bx,ax mov bx,[bx] ! Debug: list * char = [bx+4] (used reg = ) push 4[bx] ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 158 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 159 } ! 160 print_newline(); .21: ! Debug: preinc int i = [S+$222C-$222C] (used reg = ) mov ax,-$222A[bp] inc ax mov -$222A[bp],ax .22: mov bx,-$2228[bp] ! Debug: lt unsigned int = [bx+0] to int i = [S+$222C-$222C] (used reg = ) mov ax,-$222A[bp] cmp ax,[bx] jb .23 .24: .20: ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 161 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 162 ! 163 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 164 disk_service_read_data_from_disk(fsci.master_table_index[0], 16 , ¤t_table, stack_segment); ! Debug: list int stack_segment = [S+$222C-$2220] (used reg = ) push -$221E[bp] ! Debug: list * struct Directory_Table current_table = S+$222E-$2208 (used reg = ) lea bx,-$2206[bp] push bx ! Debug: list int = const $10 (used reg = ) mov ax,*$10 push ax ! Debug: list long fsci = [S+$2232-$106] (used reg = ) push -$102[bp] push -$104[bp] ! Debug: func () int = disk_service_read_data_from_disk+0 (used reg = ) call _disk_service_read_data_from_disk add sp,*$A !BCC_EOS ! 165 print("Current table: "); ! Debug: list * char = .25+0 (used reg = ) mov bx,#.25 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 166 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 167 print_stack(current_table.entries[0].filename); ! Debug: list * char current_table = S+$222C-$2208 (used reg = ) lea bx,-$2206[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) call _print_stack inc sp inc sp !BCC_EOS ! 168 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 169 print_stack(current_table.entries[1].filename); ! Debug: list * char current_table = S+$222C-$2008 (used reg = ) lea bx,-$2006[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) call _print_stack inc sp inc sp !BCC_EOS ! 170 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 171 print_stack(current_table.entries[2].filename); ! Debug: list * char current_table = S+$222C-$1E08 (used reg = ) lea bx,-$1E06[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) call _print_stack inc sp inc sp !BCC_EOS ! 172 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 173 ! 174 } break; jmp .1A !BCC_EOS ! 175 case SERIVCE_READ_DATA: ! 176 { .26: ! 177 # 185 ! 185 ! 186 print("Hit READ case"); ! Debug: list * char = .27+0 (used reg = ) mov bx,#.27 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 187 } break; jmp .1A !BCC_EOS ! 188 case SERI ! 188 VCE_WRITE_DATA: ! 189 { .28: ! 190 print("Hit WRITE case"); ! Debug: list * char = .29+0 (used reg = ) mov bx,#.29 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 191 } break; jmp .1A !BCC_EOS ! 192 default: ! 193 { .2A: ! 194 print("Default case"); ! Debug: list * char = .2B+0 (used reg = ) mov bx,#.2B push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 195 } ! 196 } ! 197 ! 198 return 0; jmp .1A .1C: add sp,*-4 sub ax,*1 beq .1D sub ax,*1 beq .1F sub ax,*1 je .26 sub ax,*1 je .28 jmp .2A .1A: ..FFFF = -$222C add sp,*4 xor ax,ax lea sp,-4[bp] pop si pop di pop bp ret !BCC_EOS ! 199 ! 200 } ! 201 ! Register BX used in function main .2B: .2C: .ascii "Default case" .byte 0 .29: .2D: .ascii "Hit WRITE case" .byte 0 .27: .2E: .ascii "Hit READ case" .byte 0 .25: .2F: .ascii "Current table: " .byte 0 .1E: .30: .ascii "File System has been loaded: " .byte 0 .bss ! 0 errors detected