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 # 1 "std_singos/string.h" ! 1 void strcpy (destination, destination_segment, source, source_segment ); !BCC_EOS ! 2 void memcpy (destination, destination_segment, source, source_segment, num_bytes ); !BCC_EOS ! 3 ! 4 void strcpy (destination, destination_segment, source, source_segment ) ! 5 char *destination; export _strcpy _strcpy: !BCC_EOS ! 6 int destination_segment; !BCC_EOS ! 7 char *source; !BCC_EOS ! 8 int source_segment; !BCC_EOS ! 9 { ! 10 #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) ! 16 20 push bp mov bp,sp stringcompare: 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 .loop: movsb cmp cx, 0x0 je .end dec cx jmp .loop .end: pop ds pop si pop es pop di pop bx pop ax pop bp ! 54 endasm !BCC_ENDASM ! 55 } ret ! 56 ! 57 void memcpy (destination, destination_segment, source, source_segment, num_bytes) ! 58 void *destination; export _memcpy _memcpy: !BCC_EOS ! 59 int destination_segment; !BCC_EOS ! 60 void *source; !BCC_EOS ! 61 int source_segment; !BCC_EOS ! 62 int num_bytes; !BCC_EOS ! 63 { ! 64 #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) ! 70 75 push bp mov bp,sp 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]; .memcpy_loop: movsb cmp cx, 0x0 je .end dec cx jmp .loop .memcpy_end: pop ds pop si pop es pop di pop bx pop ax pop bp ! 109 endasm !BCC_ENDASM ! 110 # 6 "main.c" ! 6 } ret ! 7 # 1 "std_ ! 0 singos/stdio.h" ! 1 void print(string); !BCC_EOS ! 2 ! 3 void print(string) ! 4 char* string; export _print _print: !BCC_EOS ! 5 { ! 6 #asm !BCC_ASM _print.string set 2 push bp mov bp,sp mov si,4[bp] call 0x0000:0x7C47 pop bp ! 12 endasm !BCC_ENDASM ! 13 } ret ! 14 ! 15 void print_stack(argument) ! 16 { export _print_stack _print_stack: ! 17 #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 ! 31 endasm !BCC_ENDASM ! 32 } ret ! 33 ! 34 dump_ax_return(input) ! 35 void* input; export _dump_ax_return _dump_ax_return: !BCC_EOS ! 36 { ! 37 return input; push bp mov bp,sp push di push si mov ax,4[bp] pop si pop di pop bp ret !BCC_EOS ! 38 } ! 39 ! 40 void dump_ax(input) ! 41 void* input; export _dump_ax _dump_ax: !BCC_EOS ! 42 { ! 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 () int = 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 # 1 "driver/disk.h" ! 1 int data_from_disk(index, number_sectors, data_buffer, data_buffer_segment); !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 # 11 "main.c" ! 11 #define SPACE_VBR_RECORD 2048 ! 12 ! 13 #define DEFAULT_ENTRY_SIZE 1 ! 14 ! 15 #def ! 15 ine NUMBER_OF_MBR_PARTITIONS 4 ! 16 ! 17 #define DEFAULT_DATA_POINTER_SIZE 4 ! 18 ! 19 ! 20 ! 21 void dump_ax(input); !BCC_EOS ! 22 void print_stack(argument); !BCC_EOS ! 23 void print_newline(); !BCC_EOS ! 24 ! 25 typedef struct Directory_Table Directory_Table; !BCC_EOS ! 26 typedef struct Struct_Table_Entry Table_Entry; !BCC_EOS ! 27 typedef struct struct_partition_control partition_control; !BCC_EOS ! 28 typedef struct File_System_Control_Information FSCI; !BCC_EOS ! 29 typedef struct meta_information_format mif; !BCC_EOS ! 30 typedef struct tag_record tag_record; !BCC_EOS ! 31 typedef struct lsfs_file lsfs_file; !BCC_EOS ! 32 typedef struct Parameter_Struct Parameter_Struct; !BCC_EOS ! 33 ! 34 typedef enum Table_Entry_Kind ! 35 { ! 36 ! 37 ENTRY_EMPTY = 0, ! 38 ENTRY_FILE = 1, ! 39 ENTRY_DIRECTORY = 2, ! 40 } Table_Entry_Kind; !BCC_EOS ! 41 ! 42 typedef enum Service_Action ! 43 { ! 44 SERIVCE_LOAD_DISK = 1, ! 45 SERVICE_FIND_ENTRY = 2, ! 46 SERIVCE_READ_DATA = 3, ! 47 SERIVCE_WRITE_DATA = 4, ! 48 ! 49 } Service_Action; !BCC_EOS ! 50 ! 51 struct Struct_Table_Entry ! 52 { ! 53 char filename[256]; !BCC_EOS ! 54 long file_id[2]; !BCC_EOS ! 55 long file_size[2]; !BCC_EOS ! 56 void* ext_file_data_low; !BCC_EOS ! 57 void* ext_file_data_high; !BCC_EOS ! 58 long number_sector_s; !BCC_EOS ! 59 short entry_kind; !BCC_EOS ! 60 short extra_control_bits1; !BCC_EOS ! 61 short extra_control_bits2; !BCC_EOS ! 62 short extra_control_bits3; !BCC_EOS ! 63 long table_entry_sector_index[2]; !BCC_EOS ! 64 long data_pointer[27 * 2]; !BCC_EOS ! 65 }; !BCC_EOS ! 66 ! 67 struct File_System_Control_Information ! 68 { ! 69 char filesystem_information[256]; !BCC_EOS ! 70 long master_table_index[2]; !BCC_EOS ! 71 long this_partition_offset_on_disk[2]; !BCC_EOS ! 72 long next_free_sector[2]; !BCC_EOS ! 73 long next_uniqe_id[2]; !BCC_EOS ! 74 long next_sector_reuse_pointer[2]; !BCC_EOS ! 75 long last_sector_index_on_partition[2]; !BCC_EOS ! 76 long maximum_sectors_on_disk[2]; !BCC_EOS ! 77 long sector_size_on_disk[2]; !BCC_EOS ! 78 long not_used[48]; !BCC_EOS ! 79 ! 80 }; !BCC_EOS ! 81 ! 82 typedef struct Directory_Table ! 83 { ! 84 Table_Entry entries[16 ]; !BCC_EOS ! 85 ! 86 }; !BCC_EOS ! 87 ! 88 struct Parameter_Struct ! 89 { ! 90 char* path; !BCC_EOS ! 91 char* new_path; !BCC_EOS ! 92 int buffer_segment; !BCC_EOS ! 93 int buffer_address; !BCC_EOS ! 94 int buffer_size; !BCC_EOS ! 95 int data_length; !BCC_EOS ! 96 int byte_offset_into_file; !BCC_EOS ! 97 Table_Entry_Kind entry_kind; !BCC_EOS ! 98 }; !BCC_EOS ! 99 ! 100 int main(selector, pointer_parameter_segment, pointer_parameter_struct) ! 101 int selector; export _main _main: !BCC_EOS ! 102 void* pointer_parameter_segment; !BCC_EOS ! 103 void* pointer_parameter_struct ! 103 ; !BCC_EOS ! 104 { ! 105 ! 106 ! 107 ! 108 FSCI fsci; !BCC_EOS ! 109 Service_Action service_action; !BCC_EOS ! 110 Directory_Table current_table; !BCC_EOS ! 111 Parameter_Struct parameter_struct; !BCC_EOS ! 112 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 ! 113 int stack_segment = 0x8fc0; dec sp dec sp ! Debug: eq unsigned int = const $8FC0 to int stack_segment = [S+$221C-$221C] (used reg = ) mov ax,#$8FC0 mov -$221A[bp],ax !BCC_EOS ! 114 long index_as_long; !BCC_EOS ! 115 ! 116 char local_path[256]; !BCC_EOS ! 117 service_action = selector; add sp,#-$104 ! Debug: eq int selector = [S+$2320+2] to int service_action = [S+$2320-$208] (used reg = ) mov ax,4[bp] mov -$206[bp],ax !BCC_EOS ! 118 ! 119 switch (service_action) mov ax,-$206[bp] ! 120 { br .3 ! 121 case SERIVCE_LOAD_DISK: ! 122 { .4: ! 123 ! 124 ! 125 ! 126 ! 127 index_as_long = pointer_parameter_struct; ! Debug: eq * void pointer_parameter_struct = [S+$2320+6] to long index_as_long = [S+$2320-$2220] (used reg = ) mov ax,8[bp] xor bx,bx mov -$221E[bp],ax mov -$221C[bp],bx !BCC_EOS ! 128 disk_service_read_data_from_disk(index_as_long, 1, &fsci, stack_segment); ! Debug: list int stack_segment = [S+$2320-$221C] (used reg = ) push -$221A[bp] ! Debug: list * struct File_System_Control_Information fsci = S+$2322-$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+$2326-$2220] (used reg = ) push -$221C[bp] push -$221E[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 ! 129 print("File System has been loaded: "); ! Debug: list * char = .5+0 (used reg = ) mov bx,#.5 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 130 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 131 print_stack(fsci.filesystem_information); ! Debug: list * char fsci = S+$2320-$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 ! 132 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 133 } break; br .1 !BCC_EOS ! 134 case SERVICE_FIND_ENTRY: ! 135 { .6: ! 136 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+$2322+4] (used reg = ) push 6[bp] ! Debug: list * void pointer_parameter_struct = [S+$2324+6] (used reg = ) push 8[bp] ! Debug: list int stack_segment = [S+$2326-$221C] (used reg = ) push -$221A[bp] ! Debug: list * struct Parameter_Struct parameter_struct = S+$2328-$2218 (used reg = ) lea bx,-$2216[bp] push bx ! Debug: func () void = memcpy+0 (used reg = ) call _memcpy add sp,*$A !BCC_EOS ! 137 dump_ax(parameter_struct.buffer_size); ! Debug: list int parameter_struct = [S+$2320-$2210] (used reg = ) push -$220E[bp] ! Debug: func () void = dump_ax+0 (used reg = ) call _dump_ax inc sp inc sp !BCC_EOS ! 138 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 139 disk_service_read_data_from_disk(fsci.master_table_index[0], 16 , ¤t_table, stack_segment); ! Debug: list int stack_segment = [S+$2320-$221C] (used reg = ) push -$221A[bp] ! Debug: list * struct Directory_Table current_table = S+$2322-$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+$2326-$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 ! 140 print("Current table: "); ! Debug: list * char = .7+0 (used reg = ) mov bx,#.7 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 141 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 142 print_stack(current_table.entries[0].filename); ! Debug: list * char current_table = S+$2320-$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 ! 143 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 144 print_stack(current_table.entries[1].filename); ! Debug: list * char current_table = S+$2320-$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 ! 145 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 146 print_stack(current_table.entries[2].filename); ! Debug: list * char current_table = S+$2320-$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 ! 147 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS ! 148 } break; jmp .1 !BCC_EOS ! 149 case SERIVCE_READ_DATA: ! 150 { .8: ! 151 # 159 ! 159 ! 160 print("Hit READ case"); ! Debug: list * char = .9+0 (used reg = ) mov bx,#.9 push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 161 } break; jmp .1 !BCC_EOS ! 162 case SERIVCE_WRITE_DATA: ! 163 { .A: ! 164 print("Hit WRITE case"); ! Debug: list * char = .B+0 (used reg = ) mov bx,#.B push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 165 } break; jmp .1 !BCC_EOS ! 166 default: ! 167 { .C: ! 168 print("Default case"); ! Debug: list * char = .D+0 (used reg = ) mov bx,#.D push bx ! Debug: func () void = print+0 (used reg = ) call _print inc sp inc sp !BCC_EOS ! 169 } ! 170 } ! 171 ! 172 return 0; jmp .1 .3: sub ax,*1 beq .4 sub ax,*1 beq .6 sub ax,*1 je .8 sub ax,*1 je .A jmp .C .1: ..FFFF = -$2320 xor ax,ax lea sp,-4[bp] pop si pop di pop bp ret !BCC_EOS ! 173 ! 174 } ! 175 ! Register BX used in function main .D: .E: .ascii "Default case" .byte 0 .B: .F: .ascii "Hit WRITE case" .byte 0 .9: .10: .ascii "Hit READ case" .byte 0 .7: .11: .ascii "Current table: " .byte 0 .5: .12: .ascii "File System has been loaded: " .byte 0 .bss ! 0 errors detected