diff --git a/build.sh b/build.sh index 804f66e..ff53c33 100644 --- a/build.sh +++ b/build.sh @@ -1,10 +1,11 @@ bcc -S main.c echo -e "push bp mov bp,sp +push 10[bp] push 8[bp] push 6[bp] call _main -add sp, #0x4 +add sp, #0x6 pop bp retf\n $(cat main.s)" > main.s sed -i '/.globl ___mkargv/d' ./main.s diff --git a/disk.out b/disk.out index b708737..7a1836e 100644 Binary files a/disk.out and b/disk.out differ diff --git a/main.c b/main.c index 7f550b2..76be239 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ // #include "std_singos/string.h" +#include "std_singos/stdio.h" #include "driver/disk.h" #define SPACE_MBR_RECORD 2048 // Sectors @@ -28,6 +29,7 @@ typedef struct File_System_Control_Information FSCI; typedef struct meta_information_format mif; typedef struct tag_record tag_record; typedef struct lsfs_file lsfs_file; +typedef struct Parameter_Struct Parameter_Struct; typedef enum Table_Entry_Kind { @@ -46,9 +48,6 @@ typedef enum Service_Action } Service_Action; -int number_low; -int selector; - struct Struct_Table_Entry { char filename[256]; @@ -86,12 +85,22 @@ typedef struct Directory_Table }; +struct Parameter_Struct +{ + char* path; + char* new_path; + int buffer_segment; + int buffer_address; + int buffer_size; + int data_length; + int byte_offset_into_file; + Table_Entry_Kind entry_kind; +}; -void print(string); - -int main(selector, parameter_struct) +int main(selector, pointer_parameter_segment, pointer_parameter_struct) int selector; -void* parameter_struct; +void* pointer_parameter_segment; +void* pointer_parameter_struct; { // selectot should be a "selector" for which disk service // one wnats to use. @@ -99,6 +108,7 @@ void* parameter_struct; FSCI fsci; Service_Action service_action; Directory_Table current_table; + Parameter_Struct parameter_struct; int local_segment = 0x7e0; int stack_segment = 0x8fc0; long index_as_long; @@ -114,7 +124,7 @@ void* parameter_struct; What do we need to know: Index of FSCI */ - index_as_long = parameter_struct; + index_as_long = pointer_parameter_struct; disk_service_read_data_from_disk(index_as_long, 1, &fsci, stack_segment); print("File System has been loaded: "); print_newline(); @@ -123,6 +133,9 @@ void* parameter_struct; } break; case SERVICE_FIND_ENTRY: { + memcpy(¶meter_struct, stack_segment, pointer_parameter_struct, pointer_parameter_segment, sizeof(Parameter_Struct)); + dump_ax(parameter_struct.buffer_size); + print_newline(); disk_service_read_data_from_disk(fsci.master_table_index[0], DEFAULT_TABLE_SIZE, ¤t_table, stack_segment); print("Current table: "); print_newline(); @@ -141,6 +154,8 @@ void* parameter_struct; // Buffer: destination_segment destination_address + buffer_size + offset_into_file */ print("Hit READ case"); } break; @@ -159,67 +174,3 @@ void* parameter_struct; } //void load_ - - -void print(string) -char* string; -{ -#asm - push bp - mov bp,sp - mov si,4[bp] - call 0x0000:0x7C47 - pop bp -#endasm -} - -void print_stack(argument) -{ -#asm - 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 -#endasm -} - -dump_ax_return(input) -void* input; -{ - return input; -} - -void dump_ax(input) -void* input; -{ - // Force the variable in ax - dump_ax_return(input) -#asm - push bp - mov bp,sp - call 0x000:0x7C2A - pop bp -#endasm -} - -void print_newline() -{ - #asm - printCRLF: - mov ah, #0xE - mov al, #13 - int #0x10 - mov al, #10 - int #0x10 - ret - #endasm -} \ No newline at end of file diff --git a/main.s b/main.s index 6faba84..bba2e6e 100644 --- a/main.s +++ b/main.s @@ -1,9 +1,10 @@ push bp mov bp,sp +push 10[bp] push 8[bp] push 6[bp] call _main -add sp, #0x4 +add sp, #0x6 pop bp retf ! 1 @@ -11,20 +12,22 @@ retf ! 1 # 1 "std_singos/string.h" ! 1 void strcpy (destination, destination_segment, source, source_segment ); !BCC_EOS -! 2 -! 3 void strcpy (destination, destination_segment, source, source_segment ) -! 4 char *destination; +! 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 -! 5 int destination_segment; +! 6 int destination_segment; !BCC_EOS -! 6 char *source; +! 7 char *source; !BCC_EOS -! 7 int source_segment; +! 8 int source_segment; !BCC_EOS -! 8 { -! 9 #asm +! 9 { +! 10 #asm !BCC_ASM _strcpy.source set 6 _strcpy.destination set 2 @@ -35,7 +38,7 @@ _strcpy.destination_segment set 4 ; IN di: the second (zero terminated) string ; OUT SF and ZF (same semantics as cmp) -! 15 19 +! 16 20 push bp mov bp,sp @@ -70,11 +73,202 @@ _strcpy.destination_segment set 4 pop ax pop bp -! 53 endasm +! 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 -! 54 } +! 64 } ret -! 55 # 1 "driver/disk.h" +! 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); @@ -142,212 +336,231 @@ _disk_service_read_data_from_disk.index set 2 !BCC_ENDASM ! 52 } ret -! 53 # 10 "main.c" -! 10 #define SPACE_VBR_RECORD 2048 -! 11 -! 12 #define DEFAULT_ENTRY_SIZE 1 -! 13 -! 14 #define NUMBER_OF_MBR_PARTITIONS 4 -! 15 -! 16 #define DEFAULT_DATA_POINTER_SIZE 4 -! 17 +! 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 void dump_ax(input); +! 20 +! 21 void dump_ax(input); !BCC_EOS -! 21 void print_stack(argument); +! 22 void print_stack(argument); !BCC_EOS -! 22 void print_newline(); +! 23 void print_newline(); !BCC_EOS -! 23 -! 24 typedef struct Directory_Table Directory_Table; +! 24 +! 25 typedef struct Directory_Table Directory_Table; !BCC_EOS -! 25 typedef struct Struct_Table_Entry Table_Entry; +! 26 typedef struct Struct_Table_Entry Table_Entry; !BCC_EOS -! 26 typedef struct struct_partition_control partition_control; +! 27 typedef struct struct_partition_control partition_control; !BCC_EOS -! 27 typedef struct File_System_Control_Information FSCI; +! 28 typedef struct File_System_Control_Information FSCI; !BCC_EOS -! 28 typedef struct meta_information_format mif; +! 29 typedef struct meta_information_format mif; !BCC_EOS -! 29 typedef struct tag_record tag_record; +! 30 typedef struct tag_record tag_record; !BCC_EOS -! 30 typedef struct lsfs_file lsfs_file; +! 31 typedef struct lsfs_file lsfs_file; !BCC_EOS -! 31 -! 32 typedef enum Table_Entry_Kind -! 33 { -! 34 -! 35 ENTRY_EMPTY = 0, -! 36 ENTRY_FILE = 1, -! 37 ENTRY_DIRECTORY = 2, -! 38 } Table_Entry_Kind; +! 32 typedef struct Parameter_Struct Parameter_Struct; !BCC_EOS -! 39 -! 40 typedef enum Service_Action -! 41 { -! 42 SERIVCE_LOAD_DISK = 1, -! 43 SERVICE_FIND_ENTRY = 2, -! 44 SERIVCE_READ_DATA = 3, -! 45 SERIVCE_WRITE_DATA = 4, -! 46 -! 47 } Service_Action; +! 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 int number_low; +! 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 -! 50 int selector; +! 58 long number_sector_s; !BCC_EOS -! 51 -! 52 struct Struct_Table_Entry -! 53 { -! 54 char filename[256]; +! 59 short entry_kind; !BCC_EOS -! 55 long file_id[2]; +! 60 short extra_control_bits1; !BCC_EOS -! 56 long file_size[2]; +! 61 short extra_control_bits2; !BCC_EOS -! 57 void* ext_file_data_low; +! 62 short extra_control_bits3; !BCC_EOS -! 58 void* ext_file_data_high; +! 63 long table_entry_sector_index[2]; !BCC_EOS -! 59 long number_sector_s; +! 64 long data_pointer[27 * 2]; !BCC_EOS -! 60 short entry_kind; +! 65 }; !BCC_EOS -! 61 short extra_control_bits1; +! 66 +! 67 struct File_System_Control_Information +! 68 { +! 69 char filesystem_information[256]; !BCC_EOS -! 62 short extra_control_bits2; +! 70 long master_table_index[2]; !BCC_EOS -! 63 short extra_control_bits3; +! 71 long this_partition_offset_on_disk[2]; !BCC_EOS -! 64 long table_entry_sector_index[2]; +! 72 long next_free_sector[2]; !BCC_EOS -! 65 long data_pointer[27 * 2]; +! 73 long next_uniqe_id[2]; !BCC_EOS -! 66 }; +! 74 long next_sector_reuse_pointer[2]; !BCC_EOS -! 67 -! 68 struct File_System_Control_Information -! 69 { -! 70 char filesystem_information[256]; +! 75 long last_sector_index_on_partition[2]; !BCC_EOS -! 71 long master_table_index[2]; +! 76 long maximum_sectors_on_disk[2]; !BCC_EOS -! 72 long this_partition_offset_on_disk[2]; +! 77 long sector_size_on_disk[2]; !BCC_EOS -! 73 long next_free_sector[2]; +! 78 long not_used[48]; !BCC_EOS -! 74 long next_uniqe_id[2]; +! 79 +! 80 }; !BCC_EOS -! 75 long next_sector_reuse_pointer[2]; +! 81 +! 82 typedef struct Directory_Table +! 83 { +! 84 Table_Entry entries[16 ]; !BCC_EOS -! 76 long last_sector_index_on_partition[2]; +! 85 +! 86 }; !BCC_EOS -! 77 long maximum_sectors_on_disk[2]; +! 87 +! 88 struct Parameter_Struct +! 89 { +! 90 char* path; !BCC_EOS -! 78 long sector_size_on_disk[2]; +! 91 char* new_path; !BCC_EOS -! 79 long not_used[48]; +! 92 int buffer_segment; !BCC_EOS -! 80 -! 81 }; +! 93 int buffer_address; !BCC_EOS -! 82 -! 83 typedef struct Directory_Table -! 84 { -! 85 Table_Entry entries[16 ]; +! 94 int buffer_size; !BCC_EOS -! 86 -! 87 }; +! 95 int data_length; !BCC_EOS -! 88 -! 89 -! 90 void print(string); +! 96 int byte_offset_into_file; !BCC_EOS -! 91 -! 92 int main(selector, parameter_struct) -! 93 int selector; +! 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 -! 94 void* parameter -! 94 _struct; +! 102 void* pointer_parameter_segment; +!BCC_EOS +! 103 void* pointer_parameter_struct +! 103 ; +!BCC_EOS +! 104 { +! 105 +! 106 +! 107 +! 108 FSCI fsci; !BCC_EOS -! 95 { -! 96 -! 97 -! 98 -! 99 FSCI fsci; +! 109 Service_Action service_action; !BCC_EOS -! 100 Service_Action service_action; +! 110 Directory_Table current_table; !BCC_EOS -! 101 Directory_Table current_table; +! 111 Parameter_Struct parameter_struct; !BCC_EOS -! 102 int local_segment = 0x7e0; +! 112 int local_segment = 0x7e0; push bp mov bp,sp push di push si -add sp,#-$2204 -! Debug: eq int = const $7E0 to int local_segment = [S+$220A-$220A] (used reg = ) +add sp,#-$2214 +! Debug: eq int = const $7E0 to int local_segment = [S+$221A-$221A] (used reg = ) mov ax,#$7E0 -mov -$2208[bp],ax +mov -$2218[bp],ax !BCC_EOS -! 103 int stack_segment = 0x8fc0; +! 113 int stack_segment = 0x8fc0; dec sp dec sp -! Debug: eq unsigned int = const $8FC0 to int stack_segment = [S+$220C-$220C] (used reg = ) +! Debug: eq unsigned int = const $8FC0 to int stack_segment = [S+$221C-$221C] (used reg = ) mov ax,#$8FC0 -mov -$220A[bp],ax +mov -$221A[bp],ax !BCC_EOS -! 104 long index_as_long; +! 114 long index_as_long; !BCC_EOS -! 105 -! 106 char local_path[256]; +! 115 +! 116 char local_path[256]; !BCC_EOS -! 107 service_action = selector; +! 117 service_action = selector; add sp,#-$104 -! Debug: eq int selector = [S+$2310+2] to int service_action = [S+$2310-$208] (used reg = ) +! 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 -! 108 -! 109 switch (service_action) +! 118 +! 119 switch (service_action) mov ax,-$206[bp] -! 110 { +! 120 { br .3 -! 111 case SERIVCE_LOAD_DISK: -! 112 { +! 121 case SERIVCE_LOAD_DISK: +! 122 { .4: -! 113 -! 114 -! 115 -! 116 -! 117 index_as_long = parameter_struct; -! Debug: eq * void parameter_struct = [S+$2310+4] to long index_as_long = [S+$2310-$2210] (used reg = ) -mov ax,6[bp] +! 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 -$220E[bp],ax -mov -$220C[bp],bx +mov -$221E[bp],ax +mov -$221C[bp],bx !BCC_EOS -! 118 disk_service_read_data_from_disk(index_as_long, 1, &fsci, stack_segment); -! Debug: list int stack_segment = [S+$2310-$220C] (used reg = ) -push -$220A[bp] -! Debug: list * struct File_System_Control_Information fsci = S+$2312-$206 (used reg = ) +! 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+$2316-$2210] (used reg = ) -push -$220C[bp] -push -$220E[bp] +! 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 -! 119 print("File System has been loaded: "); +! 129 print("File System has been loaded: "); ! Debug: list * char = .5+0 (used reg = ) mov bx,#.5 push bx @@ -356,12 +569,12 @@ call _print inc sp inc sp !BCC_EOS -! 120 print_newline(); +! 130 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 121 print_stack(fsci.filesystem_information); -! Debug: list * char fsci = S+$2310-$206 (used reg = ) +! 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 = ) @@ -369,33 +582,62 @@ call _print_stack inc sp inc sp !BCC_EOS -! 122 print_newline(); +! 132 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 123 } break; +! 133 } break; br .1 !BCC_EOS -! 124 case SERVICE_FIND_ENTRY: -! 125 { +! 134 case SERVICE_FIND_ENTRY: +! 135 { .6: -! 126 disk_service_read_data_from_disk(fsci.master_table_index[0], 16 , ¤t_table, stack_segment); -! Debug: list int stack_segment = [S+$2310-$220C] (used reg = ) -push -$220A[bp] -! Debug: list * struct Directory_Table current_table = S+$2312-$2208 (used reg = ) +! 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+$2316-$106] (used reg = ) +! 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 -! 127 print("Current table: "); +! 140 print("Current table: "); ! Debug: list * char = .7+0 (used reg = ) mov bx,#.7 push bx @@ -404,12 +646,12 @@ call _print inc sp inc sp !BCC_EOS -! 128 print_newline(); +! 141 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 129 print_stack(current_table.entries[0].filename); -! Debug: list * char current_table = S+$2310-$2208 (used reg = ) +! 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 = ) @@ -417,12 +659,12 @@ call _print_stack inc sp inc sp !BCC_EOS -! 130 print_newline(); +! 143 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 131 print_stack(current_table.entries[1].filename); -! Debug: list * char current_table = S+$2310-$2008 (used reg = ) +! 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 = ) @@ -430,12 +672,12 @@ call _print_stack inc sp inc sp !BCC_EOS -! 132 print_newline(); +! 145 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 133 print_stack(current_table.entries[2].filename); -! Debug: list * char current_table = S+$2310-$1E08 (used reg = ) +! 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 = ) @@ -443,17 +685,19 @@ call _print_stack inc sp inc sp !BCC_EOS -! 134 print_newline(); +! 147 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 135 } break; +! 148 } break; jmp .1 !BCC_EOS -! 136 case SERIVCE_READ_DATA: -! 137 { +! 149 case SERIVCE_READ_DATA: +! 150 { .8: -! 138 print("Hit READ case"); +! 151 # 159 +! 159 +! 160 print("Hit READ case"); ! Debug: list * char = .9+0 (used reg = ) mov bx,#.9 push bx @@ -462,13 +706,13 @@ call _print inc sp inc sp !BCC_EOS -! 139 } break; +! 161 } break; jmp .1 !BCC_EOS -! 140 case SERIVCE_WRITE_DATA: -! 141 { +! 162 case SERIVCE_WRITE_DATA: +! 163 { .A: -! 142 print("Hit WRITE case"); +! 164 print("Hit WRITE case"); ! Debug: list * char = .B+0 (used reg = ) mov bx,#.B push bx @@ -477,13 +721,13 @@ call _print inc sp inc sp !BCC_EOS -! 143 } break; +! 165 } break; jmp .1 !BCC_EOS -! 144 default: -! 145 { +! 166 default: +! 167 { .C: -! 146 print("Default case"); +! 168 print("Default case"); ! Debug: list * char = .D+0 (used reg = ) mov bx,#.D push bx @@ -492,10 +736,10 @@ call _print inc sp inc sp !BCC_EOS -! 147 } -! 148 } -! 149 -! 150 return 0; +! 169 } +! 170 } +! 171 +! 172 return 0; jmp .1 .3: sub ax,*1 @@ -508,7 +752,7 @@ sub ax,*1 je .A jmp .C .1: -..FFFF = -$2310 +..FFFF = -$2320 xor ax,ax lea sp,-4[bp] pop si @@ -516,131 +760,10 @@ pop di pop bp ret !BCC_EOS -! 151 -! 152 } -! 153 # 157 -! 157 void print(string) +! 173 +! 174 } +! 175 ! Register BX used in function main -! 158 char* string; -export _print -_print: -!BCC_EOS -! 159 { -! 160 #asm -!BCC_ASM -_print.string set 2 - - push bp - mov bp,sp - mov si,4[bp] - call 0x0000:0x7C47 - pop bp -! 166 endasm -!BCC_ENDASM -! 167 } -ret -! 168 -! 169 void print_stack(argument) -! 170 { -export _print_stack -_print_stack: -! 171 #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 -! 185 endasm -!BCC_ENDASM -! 186 } -ret -! 187 -! 188 dump_ax_return(input) -! 189 void* input; -export _dump_ax_return -_dump_ax_return: -!BCC_EOS -! 190 { -! 191 return input; -push bp -mov bp,sp -push di -push si -mov ax,4[bp] -pop si -pop di -pop bp -ret -!BCC_EOS -! 192 } -! 193 -! 194 void dump_ax(input) -! 195 void* input; -export _dump_ax -_dump_ax: -!BCC_EOS -! 196 { -! 197 -! 198 dump_ax_return(input) -push bp -mov bp,sp -push di -push si -! 199 #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 -! 204 endasm -!BCC_ENDASM -!BCC_EOS -! 205 } -pop si -pop di -pop bp -ret -! 206 -! 207 void print_newline() -! 208 { -export _print_newline -_print_newline: -! 209 #asm -!BCC_ASM - - printCRLF: - mov ah, #0xE - mov al, #13 - int #0x10 - mov al, #10 - int #0x10 - ret -! 217 endasm -!BCC_ENDASM -! 218 # 217 -! 217 } -ret -! 218 .D: .E: .ascii "Default case" @@ -662,7 +785,5 @@ ret .ascii "File System has been loaded: " .byte 0 .bss -.comm _selector,2 -.comm _number_low,2 ! 0 errors detected diff --git a/std_singos/stdio.h b/std_singos/stdio.h new file mode 100644 index 0000000..92f21fe --- /dev/null +++ b/std_singos/stdio.h @@ -0,0 +1,64 @@ +void print(string); + +void print(string) +char* string; +{ +#asm + push bp + mov bp,sp + mov si,4[bp] + call 0x0000:0x7C47 + pop bp +#endasm +} + +void print_stack(argument) +{ +#asm + 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 +#endasm +} + +dump_ax_return(input) +void* input; +{ + return input; +} + +void dump_ax(input) +void* input; +{ + // Force the variable in ax + dump_ax_return(input) +#asm + push bp + mov bp,sp + call 0x000:0x7C2A + pop bp +#endasm +} + +void print_newline() +{ + #asm + printCRLF: + mov ah, #0xE + mov al, #13 + int #0x10 + mov al, #10 + int #0x10 + ret + #endasm +} diff --git a/std_singos/string.h b/std_singos/string.h index e9b8a22..f08a4ba 100644 --- a/std_singos/string.h +++ b/std_singos/string.h @@ -1,4 +1,5 @@ void strcpy (destination, destination_segment, source, source_segment ); +void memcpy (destination, destination_segment, source, source_segment, num_bytes ); void strcpy (destination, destination_segment, source, source_segment ) char *destination; @@ -52,3 +53,58 @@ int source_segment; #endasm } + +void memcpy (destination, destination_segment, source, source_segment, num_bytes) +void *destination; +int destination_segment; +void *source; +int source_segment; +int num_bytes; +{ + #asm + ; 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) + + #define DESTINATION 4[bp]; + #define DESTINATION_SEGMENT 6[bp]; + #define SOURCE 8[bp]; + #define SOURCE_SEGMENT 10[bp]; + #define NUM_BYTES 12[bp]; + + push bp + mov bp,sp + memcpy: + push ax + push bx + push di + push es + push si + push ds + mov ax, DESTINATION; + mov di, ax + mov ax, DESTINATION_SEGMENT; + mov es, ax + mov ax, SOURCE; + mov si, ax + mov ax, SOURCE_SEGMENT; + mov ds, ax + mov cx, NUM_BYTES + .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 + + #endasm +} \ No newline at end of file