From e12768398d676acdacf23af2efc1955cdb023352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Guldberg?= Date: Thu, 27 Jun 2019 23:10:09 +0000 Subject: [PATCH] Save work --- disk.out | Bin 652 -> 742 bytes main.c | 8 +- main.s | 318 +++++++++++++++++++++++++++----------------- std_singos/string.h | 54 ++++++-- 4 files changed, 249 insertions(+), 131 deletions(-) diff --git a/disk.out b/disk.out index 7a1836e92e5668e71afade2e62f481268e16a8be..d02cc43c97e6e14e11df2722fc980799e11173b9 100644 GIT binary patch delta 356 zcmeBSea31O+WGW<8Q1?Zj{jwBFJu{;kFdp_28ziAce}Cm-RO>E*~!4r#csn;!s6)s z`djCTX!(h*3KNa2S(rUvf16mCBCo{Q9mmlrC&Sq7$J5EDz}Owe)hQ;&xKE04i&K}F z*2FKyR=@sryRme({rcMt#4kk{yWKbpZ+EsmxZ64J(cS;sp55)8_vdf$4n~H6|Jy(U z5AMDw{NH?pYxjxCiHs7AuO?S9O1qY^{onTL?u)R0%}0P{Jpn2MVu&EbhzECqUvvXy zxw?U}ov#@W8yx6pe{iRF9!O&2KNpu5&;Lzcz$lh+8>DFW4yNE2wII<0|9a>Bx(nrO z2665OzbF97ECX>K2ERxKac2H|ZM}OHP?HCc_u63hY#`GX#8lng2V@$7m{Pio4E!xm M|A8r`$#P7204a#NxBvhE delta 287 zcmaFH+QTXm+WGW<8Q1?Zj{jwBFa9z#A7P6>X-k-n0I~W-P{%->bJi7a$@PG3WuHAW)8yO`SH%y+zC|$qp)7=+5 z|6N>ODE^0N`E@sVhX6>+zkmO?{rUGo6s#qVDfq?qe?Vow{`JlSDuHm`f;jhsU#tSj zJOFVX2EUjK;#~gs+In{YP*W3-_u62$Bam4RVyf;o0WxzyOetMP1}^><`Tszgza?gJ H1yddXLok_; diff --git a/main.c b/main.c index 76be239..32b45a6 100644 --- a/main.c +++ b/main.c @@ -111,9 +111,10 @@ void* pointer_parameter_struct; Parameter_Struct parameter_struct; int local_segment = 0x7e0; int stack_segment = 0x8fc0; + int path_length; long index_as_long; - char local_path[256]; //= "Hello world\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + char local_path[256]; service_action = selector; switch (service_action) @@ -134,7 +135,10 @@ void* pointer_parameter_struct; case SERVICE_FIND_ENTRY: { memcpy(¶meter_struct, stack_segment, pointer_parameter_struct, pointer_parameter_segment, sizeof(Parameter_Struct)); - dump_ax(parameter_struct.buffer_size); + path_length = strlen(parameter_struct.path, pointer_parameter_segment); + memcpy(local_path, stack_segment, parameter_struct.path, pointer_parameter_segment, path_length); + local_path[path_length] = 0; + print_stack(local_path); print_newline(); disk_service_read_data_from_disk(fsci.master_table_index[0], DEFAULT_TABLE_SIZE, ¤t_table, stack_segment); print("Current table: "); diff --git a/main.s b/main.s index bba2e6e..467662c 100644 --- a/main.s +++ b/main.s @@ -12,22 +12,64 @@ retf ! 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 ); +! 2 int strlen (source, source_segment); !BCC_EOS -! 3 -! 4 void strcpy (destination, destination_segment, source, source_segment ) -! 5 char *destination; +! 3 void memcpy (destination, destination_segment, source, source_segment, num_bytes ); +!BCC_EOS +! 4 +! 5 int strlen (source, source_segment) +! 6 { +export _strlen +_strlen: +! 7 #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 +! 35 endasm +!BCC_ENDASM +! 36 } +ret +! 37 +! 38 void strcpy (destination, destination_segment, source, source_segment ) +! 39 char *destination; export _strcpy _strcpy: !BCC_EOS -! 6 int destination_segment; +! 40 int destination_segment; !BCC_EOS -! 7 char *source; +! 41 char *source; !BCC_EOS -! 8 int source_segment; +! 42 int source_segment; !BCC_EOS -! 9 { -! 10 #asm +! 43 { +! 44 #asm !BCC_ASM _strcpy.source set 6 _strcpy.destination set 2 @@ -38,11 +80,11 @@ _strcpy.destination_segment set 4 ; IN di: the second (zero terminated) string ; OUT SF and ZF (same semantics as cmp) -! 16 20 +! 50 54 push bp mov bp,sp - stringcompare: + label_strcpy: push ax push bx push di @@ -58,13 +100,13 @@ _strcpy.destination_segment set 4 mov ax, 10[bp]; ; mov ds, ax mov cx, 0x050 - .loop: + .label_strcpy_loop: movsb cmp cx, 0x0 - je .end + je .label_strcpy_end dec cx - jmp .loop - .end: + jmp .label_strcpy_loop + .label_strcpy_end: pop ds pop si pop es @@ -73,26 +115,26 @@ _strcpy.destination_segment set 4 pop ax pop bp -! 54 endasm +! 88 endasm !BCC_ENDASM -! 55 } +! 89 } ret -! 56 -! 57 void memcpy (destination, destination_segment, source, source_segment, num_bytes) -! 58 void *destination; +! 90 +! 91 void memcpy (destination, destination_segment, source, source_segment, num_bytes) +! 92 void *destination; export _memcpy _memcpy: !BCC_EOS -! 59 int destination_segment; +! 93 int destination_segment; !BCC_EOS -! 60 void *source; +! 94 void *source; !BCC_EOS -! 61 int source_segment; +! 95 int source_segment; !BCC_EOS -! 62 int num_bytes; +! 96 int num_bytes; !BCC_EOS -! 63 { -! 64 #asm +! 97 { +! 98 #asm !BCC_ASM _memcpy.source set 6 _memcpy.destination set 2 @@ -104,11 +146,11 @@ _memcpy.destination_segment set 4 ; IN di: the second (zero terminated) string ; OUT SF and ZF (same semantics as cmp) -! 70 75 +! 104 109 push bp mov bp,sp - memcpy: + label_memcpy: push ax push bx push di @@ -124,13 +166,13 @@ _memcpy.destination_segment set 4 mov ax, 10[bp]; ; mov ds, ax mov cx, 12[bp]; - .memcpy_loop: + .label_memcpy_loop: movsb cmp cx, 0x0 - je .end + je .label_memcpy_end dec cx - jmp .loop - .memcpy_end: + jmp .label_memcpy_loop + .label_memcpy_end: pop ds pop si pop es @@ -139,13 +181,12 @@ _memcpy.destination_segment set 4 pop ax pop bp -! 109 endasm +! 143 endasm !BCC_ENDASM -! 110 # 6 "main.c" +! 144 # 6 "main.c" ! 6 } ret -! 7 # 1 "std_ -! 0 singos/stdio.h" +! 7 # 1 "std_singos/stdio.h" ! 1 void print(string); !BCC_EOS ! 2 @@ -341,8 +382,7 @@ ret ! 12 ! 13 #define DEFAULT_ENTRY_SIZE 1 ! 14 -! 15 #def -! 15 ine NUMBER_OF_MBR_PARTITIONS 4 +! 15 #define NUMBER_OF_MBR_PARTITIONS 4 ! 16 ! 17 #define DEFAULT_DATA_POINTER_SIZE 4 ! 18 @@ -428,7 +468,8 @@ ret !BCC_EOS ! 71 long this_partition_offset_on_disk[2]; !BCC_EOS -! 72 long next_free_sector[2]; +! 72 long next +! 72 _free_sector[2]; !BCC_EOS ! 73 long next_uniqe_id[2]; !BCC_EOS @@ -482,8 +523,7 @@ _main: !BCC_EOS ! 102 void* pointer_parameter_segment; !BCC_EOS -! 103 void* pointer_parameter_struct -! 103 ; +! 103 void* pointer_parameter_struct; !BCC_EOS ! 104 { ! 105 @@ -514,53 +554,55 @@ dec sp mov ax,#$8FC0 mov -$221A[bp],ax !BCC_EOS -! 114 long index_as_long; +! 114 int path_length; !BCC_EOS -! 115 -! 116 char local_path[256]; +! 115 long index_as_long; !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 = ) +! 116 +! 117 char local_path[256]; +!BCC_EOS +! 118 service_action = selector; +add sp,#-$106 +! Debug: eq int selector = [S+$2322+2] to int service_action = [S+$2322-$208] (used reg = ) mov ax,4[bp] mov -$206[bp],ax !BCC_EOS -! 118 -! 119 switch (service_action) +! 119 +! 120 switch (service_action) mov ax,-$206[bp] -! 120 { +! 121 { br .3 -! 121 case SERIVCE_LOAD_DISK: -! 122 { +! 122 case SERIVCE_LOAD_DISK: +! 123 { .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 = ) +! 126 +! 127 +! 128 index_as_long = pointer_parameter_struct; +! Debug: eq * void pointer_parameter_struct = [S+$2322+6] to long index_as_long = [S+$2322-$2222] (used reg = ) mov ax,8[bp] xor bx,bx -mov -$221E[bp],ax -mov -$221C[bp],bx +mov -$2220[bp],ax +mov -$221E[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 = ) +! 129 disk_service_read_data_from_disk(index_as_long, 1, &fsci, stack_segment); +! Debug: list int stack_segment = [S+$2322-$221C] (used reg = ) push -$221A[bp] -! Debug: list * struct File_System_Control_Information fsci = S+$2322-$206 (used reg = ) +! Debug: list * struct File_System_Control_Information fsci = S+$2324-$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] +! Debug: list long index_as_long = [S+$2328-$2222] (used reg = ) push -$221E[bp] +push -$2220[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: "); +! 130 print("File System has been loaded: "); ! Debug: list * char = .5+0 (used reg = ) mov bx,#.5 push bx @@ -569,12 +611,12 @@ call _print inc sp inc sp !BCC_EOS -! 130 print_newline(); +! 131 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 = ) +! 132 print_stack(fsci.filesystem_information); +! Debug: list * char fsci = S+$2322-$206 (used reg = ) lea bx,-$204[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) @@ -582,62 +624,99 @@ call _print_stack inc sp inc sp !BCC_EOS -! 132 print_newline(); +! 133 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 133 } break; +! 134 } break; br .1 !BCC_EOS -! 134 case SERVICE_FIND_ENTRY: -! 135 { +! 135 case SERVICE_FIND_ENTRY: +! 136 { .6: -! 136 memcpy(¶meter_struct, stack_segment, pointer_parameter_struct, pointer_parameter_segment, sizeof(Parameter_Struct)); +! 137 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 = ) +! Debug: list * void pointer_parameter_segment = [S+$2324+4] (used reg = ) push 6[bp] -! Debug: list * void pointer_parameter_struct = [S+$2324+6] (used reg = ) +! Debug: list * void pointer_parameter_struct = [S+$2326+6] (used reg = ) push 8[bp] -! Debug: list int stack_segment = [S+$2326-$221C] (used reg = ) +! Debug: list int stack_segment = [S+$2328-$221C] (used reg = ) push -$221A[bp] -! Debug: list * struct Parameter_Struct parameter_struct = S+$2328-$2218 (used reg = ) +! Debug: list * struct Parameter_Struct parameter_struct = S+$232A-$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 +! 138 path_length = strlen(parameter_struct.path, pointer_parameter_segment); +! Debug: list * void pointer_parameter_segment = [S+$2322+4] (used reg = ) +push 6[bp] +! Debug: list * char parameter_struct = [S+$2324-$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+$2322-$221E] (used reg = ) +mov -$221C[bp],ax +!BCC_EOS +! 139 memcpy(local_path, stack_segment, parameter_struct.path, pointer_parameter_segment, path_length); +! Debug: list int path_length = [S+$2322-$221E] (used reg = ) +push -$221C[bp] +! Debug: list * void pointer_parameter_segment = [S+$2324+4] (used reg = ) +push 6[bp] +! Debug: list * char parameter_struct = [S+$2326-$2218] (used reg = ) +push -$2216[bp] +! Debug: list int stack_segment = [S+$2328-$221C] (used reg = ) +push -$221A[bp] +! Debug: list * char local_path = S+$232A-$2322 (used reg = ) +lea bx,-$2320[bp] +push bx +! Debug: func () void = memcpy+0 (used reg = ) +call _memcpy +add sp,*$A +!BCC_EOS +! 140 local_path[path_length] = 0; +! Debug: ptradd int path_length = [S+$2322-$221E] to [$100] char local_path = S+$2322-$2322 (used reg = ) +mov ax,-$221C[bp] +mov bx,bp +add bx,ax +! Debug: eq int = const 0 to char = [bx-$2320] (used reg = ) +xor al,al +mov -$2320[bx],al +!BCC_EOS +! 141 print_stack(local_path); +! Debug: list * char local_path = S+$2322-$2322 (used reg = ) +lea bx,-$2320[bp] +push bx +! Debug: func () void = print_stack+0 (used reg = ) +call _print_stack inc sp inc sp !BCC_EOS -! 138 print_newline(); +! 142 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 = ) +! 143 disk_service_read_data_from_disk(fsci.master_table_index[0], 16 , ¤t_table, stack_segment); +! Debug: list int stack_segment = [S+$2322-$221C] (used reg = ) push -$221A[bp] -! Debug: list * struct Directory_Table current_table = S+$2322-$2208 (used reg = ) +! Debug: list * struct Directory_Table current_table = S+$2324-$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 = ) +! Debug: list long fsci = [S+$2328-$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: "); +! 144 print("Current table: "); ! Debug: list * char = .7+0 (used reg = ) mov bx,#.7 push bx @@ -646,12 +725,13 @@ call _print inc sp inc sp !BCC_EOS -! 141 print_newline(); +! 145 print_newline( +! 145 ); ! 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 = ) +! 146 print_stack(current_table.entries[0].filename); +! Debug: list * char current_table = S+$2322-$2208 (used reg = ) lea bx,-$2206[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) @@ -659,12 +739,12 @@ call _print_stack inc sp inc sp !BCC_EOS -! 143 print_newline(); +! 147 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 = ) +! 148 print_stack(current_table.entries[1].filename); +! Debug: list * char current_table = S+$2322-$2008 (used reg = ) lea bx,-$2006[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) @@ -672,12 +752,12 @@ call _print_stack inc sp inc sp !BCC_EOS -! 145 print_newline(); +! 149 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 = ) +! 150 print_stack(current_table.entries[2].filename); +! Debug: list * char current_table = S+$2322-$1E08 (used reg = ) lea bx,-$1E06[bp] push bx ! Debug: func () void = print_stack+0 (used reg = ) @@ -685,19 +765,19 @@ call _print_stack inc sp inc sp !BCC_EOS -! 147 print_newline(); +! 151 print_newline(); ! Debug: func () void = print_newline+0 (used reg = ) call _print_newline !BCC_EOS -! 148 } break; +! 152 } break; jmp .1 !BCC_EOS -! 149 case SERIVCE_READ_DATA: -! 150 { +! 153 case SERIVCE_READ_DATA: +! 154 { .8: -! 151 # 159 -! 159 -! 160 print("Hit READ case"); +! 155 # 163 +! 163 +! 164 print("Hit READ case"); ! Debug: list * char = .9+0 (used reg = ) mov bx,#.9 push bx @@ -706,13 +786,13 @@ call _print inc sp inc sp !BCC_EOS -! 161 } break; +! 165 } break; jmp .1 !BCC_EOS -! 162 case SERIVCE_WRITE_DATA: -! 163 { +! 166 case SERIVCE_WRITE_DATA: +! 167 { .A: -! 164 print("Hit WRITE case"); +! 168 print("Hit WRITE case"); ! Debug: list * char = .B+0 (used reg = ) mov bx,#.B push bx @@ -721,13 +801,13 @@ call _print inc sp inc sp !BCC_EOS -! 165 } break; +! 169 } break; jmp .1 !BCC_EOS -! 166 default: -! 167 { +! 170 default: +! 171 { .C: -! 168 print("Default case"); +! 172 print("Default case"); ! Debug: list * char = .D+0 (used reg = ) mov bx,#.D push bx @@ -736,10 +816,10 @@ call _print inc sp inc sp !BCC_EOS -! 169 } -! 170 } -! 171 -! 172 return 0; +! 173 } +! 174 } +! 175 +! 176 return 0; jmp .1 .3: sub ax,*1 @@ -752,7 +832,7 @@ sub ax,*1 je .A jmp .C .1: -..FFFF = -$2320 +..FFFF = -$2322 xor ax,ax lea sp,-4[bp] pop si @@ -760,9 +840,9 @@ pop di pop bp ret !BCC_EOS -! 173 -! 174 } -! 175 +! 177 +! 178 } +! 179 ! Register BX used in function main .D: .E: diff --git a/std_singos/string.h b/std_singos/string.h index f08a4ba..4fb57ba 100644 --- a/std_singos/string.h +++ b/std_singos/string.h @@ -1,6 +1,40 @@ void strcpy (destination, destination_segment, source, source_segment ); +int strlen (source, source_segment); void memcpy (destination, destination_segment, source, source_segment, num_bytes ); +int strlen (source, source_segment) +{ + #asm + #define strlen_SOURCE 4[bp]; + #define strlen_SOURCE_SEGMENT 6[bp]; + push bp + mov bp,sp + push ds + push bx + + mov ax, strlen_SOURCE_SEGMENT + mov ds, ax + + mov bx, strlen_SOURCE + + 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 + #endasm +} + void strcpy (destination, destination_segment, source, source_segment ) char *destination; int destination_segment; @@ -20,7 +54,7 @@ int source_segment; push bp mov bp,sp - stringcompare: + label_strcpy: push ax push bx push di @@ -36,13 +70,13 @@ int source_segment; mov ax, SOURCE_SEGMENT; mov ds, ax mov cx, 0x050 // TODO(Jørn) Hardcded number of bytes to copy - .loop: + .label_strcpy_loop: movsb cmp cx, 0x0 - je .end + je .label_strcpy_end dec cx - jmp .loop - .end: + jmp .label_strcpy_loop + .label_strcpy_end: pop ds pop si pop es @@ -75,7 +109,7 @@ int num_bytes; push bp mov bp,sp - memcpy: + label_memcpy: push ax push bx push di @@ -91,13 +125,13 @@ int num_bytes; mov ax, SOURCE_SEGMENT; mov ds, ax mov cx, NUM_BYTES - .memcpy_loop: + .label_memcpy_loop: movsb cmp cx, 0x0 - je .end + je .label_memcpy_end dec cx - jmp .loop - .memcpy_end: + jmp .label_memcpy_loop + .label_memcpy_end: pop ds pop si pop es