Subversion Repositories Kolibri OS

Rev

Rev 3 | Rev 5 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 48... Line 48...
48
 
48
 
49
tss0i_l:
49
tss0i_l:
Line 50... Line 50...
50
      times 0x41 dq 0 ;(256+10) dd 0,0
50
      times 0x41 dq 0 ;(256+10) dd 0,0
-
 
51
 
-
 
52
app_code_l:
-
 
53
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
-
 
54
      dw 0
51
 
55
      db 0
Line 52... Line 56...
52
app_code_l:
56
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
-
 
57
      db std_application_base_address shr 24
-
 
58
 
-
 
59
app_data_l:
-
 
60
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
53
      times (max_processes+10) dd 0,0
61
      dw 0
Line 54... Line -...
54
 
-
 
55
app_data_l:
-
 
Line 56... Line 62...
56
      times (max_processes+10) dd 0,0
62
      db 0
Line 101... Line 107...
101
        cmp    edi,8*(max_processes+5)
107
        cmp    edi,8*(max_processes+5)
102
        jbe    setgdtl2
108
        jbe    setgdtl2
Line 103... Line 109...
103
 
109
 
Line 104... Line -...
104
        ret
-
 
105
 
-
 
106
;build_process_gdt_gate_pointer:
-
 
107
 
-
 
108
;        mov    edi,0
-
 
109
;        mov    dx,tss0
-
 
110
;      setidtl1:
-
 
111
;        mov    ecx,[esi]
-
 
112
;        mov    [edi+gdts+ tss0t +0], word 0
-
 
113
;        mov    [edi+gdts+ tss0t +2], dx
-
 
114
;        mov    [edi+gdts+ tss0t +4], word 11100101b*256
-
 
115
;        mov    [edi+gdts+ tss0t +6], word 0
-
 
116
;        add    dx,8
-
 
117
;        add    edi,8
-
 
118
;        cmp    edi,8*(max_processes+5)
-
 
119
;        jb     setidtl1
-
 
Line 120... Line 110...
120
 
110
        ret
Line 121... Line 111...
121
;        ret
111
 
122
 
112
 
Line 228... Line 218...
228
 
218
 
Line 229... Line 219...
229
        ret
219
        ret
Line 230... Line -...
230
 
-
 
231
build_syscall_interrupt_table:
-
 
232
 
-
 
233
        mov  [l.eflags],dword 0x11002
-
 
234
        mov  [l.ss0], int_data   ;code
-
 
235
        ;mov  [l.ss1], ring1_data ;code
-
 
236
        ;mov  [l.ss2], ring2_data ;code
-
 
237
        mov  [l.esp0], 0x52000
-
 
238
        mov  [l.esp1], 0x53000
-
 
239
        mov  [l.esp2], 0x54000
-
 
240
 
-
 
241
        mov  eax,cr3
-
 
242
        mov  [l.cr3],eax
-
 
243
        mov  [l.cs],int_code
-
 
244
        mov  [l.ss],int_data
-
 
245
        mov  [l.ds],int_data
-
 
246
        mov  [l.es],int_data
-
 
247
        mov  [l.fs],int_data
-
 
248
        mov  [l.gs],int_data
-
 
249
 
-
 
250
        mov  [l.esp],sysint_stack_data
-
 
251
        mov  edi,0x298000
-
 
252
 
-
 
253
     newint2:
-
 
254
        push edi
-
 
255
        mov  ebx,i40
-
 
256
        mov  [l.eip],ebx
-
 
257
        mov  esi,tss_sceleton
-
 
258
        mov  ecx,120/4
-
 
259
        cld
-
 
260
        rep  movsd
-
 
261
        pop  edi
-
 
262
 
-
 
263
        add  [l.esp],4096
-
 
264
        add  edi,128
-
 
265
        ;add  eax,4
-
 
266
 
-
 
267
        cmp  edi,0x298000+128*(max_processes+5)
-
 
268
        jb   newint2
-
 
269
 
-
 
270
;;
-
 
271
 
-
 
272
        mov    ecx,0x298000
-
 
273
        mov    edi,0
-
 
274
      setgdtl2i2:
-
 
275
        mov    [edi+gdts+ tss0sys +0], word 128
-
 
276
        mov    [edi+gdts+ tss0sys +2], cx
-
 
277
        mov    eax,ecx
-
 
278
        shr    eax,16
-
 
279
        mov    [edi+gdts+ tss0sys +4], al
-
 
280
        mov    [edi+gdts+ tss0sys +7], ah
-
 
281
        mov    [edi+gdts+ tss0sys +5], word 01010000b *256 +11101001b
-
 
282
        add    ecx,128
-
 
283
        add    edi,8
-
 
284
        cmp    edi,8*(max_processes+5)
-
 
285
        jbe    setgdtl2i2
-
 
286
 
220
 
287
;;
221
build_syscall_interrupt_table:
288
 
222
 
289
        ;mov    dx,tss0sys
223
        ;mov    dx,tss0sys
290
        mov    edi,8*0x40+idts+8
224
        mov    edi,8*0x40+idts+8
291
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
225
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
Line 292... Line -...
292
        mov    [edi + 2], word os_code
-
 
293
        mov    [edi + 4], word 11101110b*256
-
 
294
        mov    [edi + 6], word (i40 shr 16)
-
 
295
 
-
 
296
        mov    edi,8*0x38+idts+8
-
 
297
        mov    eax, i38
-
 
298
        mov    [edi],   ax           ; lower part of offset
-
 
299
        mov    [edi+2], word os_code ; segment selector
-
 
300
        shr    eax, 16
226
        mov    [edi + 2], word os_code
Line 301... Line 227...
301
        mov    [edi+4], word 11101110b shl 8 ; 32-bit interrupt gate, DPL 3
227
        mov    [edi + 4], word 11101110b*256
302
        mov    [edi+6], ax
228
        mov    [edi + 6], word (i40 shr 16)
Line 1057... Line 983...
1057
 @@: call   change_task
983
 @@: call   change_task
1058
     jmp    @b
984
     jmp    @b
Line 1059... Line -...
1059
 
-
 
1060
 
-
 
1061
 
-
 
1062
compare_to_thread:
-
 
1063
 
-
 
1064
         push ebx
-
 
1065
 
-
 
1066
         mov  eax,edx
-
 
1067
         shl  eax, 3
-
 
1068
         add  eax,gdts+ app_code-3
-
 
1069
         mov  ebx,[eax]
-
 
1070
         cmp  ebx,[old_code_0]
-
 
1071
         jne  ctt0
-
 
1072
         mov  ebx,[eax+4]
-
 
1073
         cmp  ebx,[old_code_1]
-
 
1074
         jne  ctt0
-
 
1075
 
-
 
1076
         pop  ebx
-
 
1077
         mov  eax,1
-
 
1078
         ret
-
 
1079
 
-
 
1080
       ctt0:
-
 
1081
 
-
 
1082
         pop  ebx
-
 
1083
         mov  eax,0
-
 
1084
         ret
-
 
1085
 
-
 
1086
 
-
 
1087
 
-
 
1088
check_for_thread_mem:
-
 
1089
 
-
 
1090
         pusha
-
 
1091
 
-
 
1092
         mov  ecx,[0x3004]
-
 
1093
       cftm0:
-
 
1094
         mov  eax,ecx
-
 
1095
         shl  eax, 8
-
 
1096
         add  eax,gdts+ app_code-3
-
 
1097
         mov  ebx,[eax]
-
 
1098
         cmp  ebx,[old_code_0]
-
 
1099
         jne  cftm1
-
 
1100
         mov  ebx,[eax+4]
-
 
1101
         cmp  ebx,[old_code_1]
-
 
1102
         jne  cftm1
-
 
1103
 
-
 
1104
         mov  eax,ecx  ; new code segments
-
 
1105
         shl  eax, 3 ;imul eax,8
-
 
1106
         add  eax,gdts+ app_code-3
-
 
1107
 
-
 
1108
         mov  ebx,[new_code_0]
-
 
1109
         mov  [eax],ebx
-
 
1110
         mov  ebx,[new_code_1]
-
 
1111
         mov  [eax+4],ebx
-
 
1112
 
-
 
1113
         mov  eax,ecx  ; new data segments
-
 
1114
         shl  eax, 3
-
 
1115
 
-
 
1116
         add  eax,gdts+ app_data-3
-
 
1117
 
-
 
1118
         mov  ebx,[new_data_0]
-
 
1119
         mov  [eax],ebx
-
 
1120
         mov  ebx,[new_data_1]
-
 
1121
         mov  [eax+4],ebx
-
 
1122
 
-
 
1123
         cmp  [new_pos],0   ; new memory position segments
-
 
1124
         je   no_new_postition_for_thread
-
 
1125
         mov  eax,ecx
-
 
1126
         shl  eax, 5
-
 
1127
         add  eax,0x3000
-
 
1128
         mov  ebx,[new_pos]
-
 
1129
         mov  [eax+0x10],ebx
-
 
1130
       no_new_postition_for_thread:
-
 
1131
 
-
 
1132
         mov  eax,ecx       ; new amount of memory
-
 
1133
         shl  eax, 8
-
 
1134
         add  eax,0x80000
-
 
1135
         mov  ebx,[new_amount]
-
 
1136
         mov  [eax+0x8C],ebx
-
 
1137
 
-
 
1138
       cftm1:
-
 
1139
 
-
 
1140
         dec  ecx
-
 
1141
         jnz  cftm0
-
 
1142
 
-
 
1143
         popa
-
 
1144
 
-
 
1145
         ret
-
 
1146
 
-
 
1147
 
-
 
1148
save_for_thread_check:
-
 
1149
 
-
 
1150
        ; save for thread check
-
 
1151
 
-
 
1152
        pusha
-
 
1153
        mov    esi,[0x3000]
-
 
1154
        ;imul   esi,8
-
 
1155
        shl    esi, 3
-
 
1156
        add    esi,gdts+ app_code-3 +0
-
 
1157
        mov    edi,old_code_0
-
 
1158
        mov    ecx,8
-
 
1159
        cld
-
 
1160
        rep    movsb
-
 
1161
        popa
-
 
1162
 
-
 
1163
        ret
-
 
1164
 
-
 
1165
 
-
 
1166
save_new_position_for_threads:
-
 
1167
 
-
 
1168
        ; new code segment for thread check
-
 
1169
        pusha
-
 
1170
        mov    esi,[0x3000]
-
 
1171
        ;imul   esi,8
-
 
1172
        shl    esi, 3
-
 
1173
        add    esi,gdts+ app_code-3 +0
-
 
1174
        mov    edi,new_code_0
-
 
1175
        mov    ecx,8
-
 
1176
        cld
-
 
1177
        rep    movsb
-
 
1178
        popa
-
 
1179
 
-
 
1180
        ; new data segment for thread check
-
 
1181
        pusha
-
 
1182
        mov    esi,[0x3000]
-
 
1183
        ;imul   esi,8
-
 
1184
        shl    esi, 3
-
 
1185
        add    esi,gdts+ app_data-3 +0
-
 
1186
        mov    edi,new_data_0
-
 
1187
        mov    ecx,8
-
 
1188
        cld
-
 
1189
        rep    movsb
-
 
Line 1190... Line 985...
1190
        popa
985
 
1191
 
986
 
Line 1192... Line 987...
1192
        ret
987
 
Line 1245... Line 1040...
1245
sys_resize_app_memory:
1040
sys_resize_app_memory:
1246
        ; eax = 1 - resize
1041
        ; eax = 1 - resize
1247
        ;     ebx = new amount of memory
1042
        ;     ebx = new amount of memory
Line 1248... Line 1043...
1248
 
1043
 
1249
        cmp    eax,1
1044
        cmp    eax,1
1250
        jne    no_application_mem_resize
-
 
1251
        
-
 
1252
        mov    eax,[0x3010]
-
 
1253
        cmp    dword [eax+0x10],std_application_base_address
-
 
1254
        jz     new_mem_resize ;resize for new type of processes
-
 
1255
 
-
 
1256
        add    ebx,4095
-
 
1257
        shr    ebx,12
-
 
1258
        shl    ebx,12
-
 
1259
        mov    ebp,ebx
-
 
1260
 
-
 
1261
        ; wait for process table to be free
-
 
1262
 
-
 
1263
      rsm0:
-
 
1264
 
-
 
1265
        cli
-
 
1266
        cmp   [application_table_status],0
-
 
1267
        je    rsm1
-
 
1268
        sti
-
 
1269
        call  change_task
-
 
1270
        jmp   rsm0
-
 
1271
 
-
 
1272
      rsm1:
-
 
1273
 
-
 
1274
        call  set_application_table_status
-
 
1275
        sti
-
 
1276
 
-
 
1277
        cmp    ebx,0 ; other than zero
-
 
1278
        je     mem_resize_unsuccess
-
 
1279
 
-
 
1280
        call   save_for_thread_check
-
 
1281
 
-
 
1282
        ; find a free place
-
 
1283
 
-
 
1284
        mov    esi,[0xfe84]  ; application memory start
-
 
1285
        mov    edi,ebp
-
 
1286
        add    edi,esi
-
 
1287
        dec    edi
-
 
1288
 
-
 
1289
      rfgdt:
-
 
1290
 
-
 
1291
        mov    edx,2
-
 
1292
 
-
 
1293
      rfindgdtl1:
-
 
1294
 
-
 
1295
        call   compare_to_thread
-
 
1296
        cmp    eax,1
-
 
1297
        je     rfindfl3
-
 
1298
 
-
 
1299
        mov    ecx,edx
-
 
Line 1300... Line -...
1300
        shl    ecx,3
-
 
1301
 
-
 
1302
        ; eax run base -> ebx limit
-
 
1303
 
-
 
1304
        mov    al,[ecx+gdts+ app_code-3 +4]
-
 
1305
        mov    ah,[ecx+gdts+ app_code-3 +7]
-
 
1306
        shl    eax,16
-
 
1307
        mov    ax,[ecx+gdts+ app_code-3 +2]
-
 
1308
        
-
 
1309
;!!mem
-
 
1310
        cmp    eax,std_application_base_address
-
 
1311
        jz     rfindfl3
-
 
1312
;!!mem
-
 
1313
 
-
 
1314
        movzx  ebx,word [ecx+gdts+ app_code-3 +0]
-
 
1315
        shl    ebx,12
-
 
1316
        add    ebx,eax
-
 
1317
 
-
 
1318
        cmp    eax,edi
-
 
1319
        jg     rfindfl3
-
 
1320
        cmp    ebx,esi
-
 
1321
        jb     rfindfl3
-
 
1322
 
-
 
1323
        add    esi,4096
-
 
1324
        add    edi,4096
-
 
1325
 
-
 
1326
        cmp    edi,[0xfe8c]        ; < c_memory
-
 
1327
        jbe    rfgdt
1045
        jne    .no_application_mem_resize
1328
 
-
 
1329
        jmp    rfind_free_ret_2   ;; not enough memory
-
 
1330
 
-
 
1331
      rfindfl3:
-
 
1332
 
-
 
1333
        inc    edx
-
 
Line 1334... Line -...
1334
        cmp    edx,[0x3004]
-
 
1335
        jbe    rfindgdtl1
-
 
Line 1336... Line -...
1336
 
-
 
1337
     rfindfl1:
-
 
1338
     rthread_c:
-
 
1339
 
-
 
1340
        mov    ecx,[0x3000]
-
 
1341
        shl    ecx,3
-
 
1342
 
-
 
1343
        inc    edi
-
 
1344
        sub    edi,esi
-
 
1345
        add    edi,4095
-
 
1346
        shr    edi,12
-
 
1347
        dec    edi
-
 
1348
 
-
 
1349
        ; code
-
 
1350
 
-
 
1351
        mov    eax,esi
-
 
1352
        mov    ebx,edi
-
 
1353
 
-
 
1354
        mov    [ecx+gdts+ app_code-3 +2], ax              ;  base  0:15
-
 
1355
        shr    eax,16
-
 
1356
        mov    [ecx+gdts+ app_code-3 +4], al              ;  base  23:16
-
 
1357
        mov    [ecx+gdts+ app_code-3 +7], ah              ;  base  31:24
-
 
1358
        mov    [ecx+gdts+ app_code-3 +0], bx              ;  limit
-
 
1359
 
-
 
1360
        ; data
-
 
1361
 
-
 
1362
        mov    eax,esi
-
 
1363
        mov    [ecx+gdts+ app_data-3 +2], ax              ;  base  0:15
-
 
1364
        shr    eax,16
-
 
1365
        mov    [ecx+gdts+ app_data-3 +4], al              ;  base  23:16
-
 
1366
        mov    [ecx+gdts+ app_data-3 +7], ah              ;  base  31:24
-
 
1367
 
-
 
1368
        movzx  edx,word [ecx+gdts+ app_code-3 +0]         ;  save limit
-
 
1369
 
-
 
1370
        mov    [ecx+gdts+ app_data-3 +0], bx              ;  limit
-
 
1371
 
-
 
1372
        and    ebx,0xffff
-
 
1373
 
-
 
1374
        cmp    ebx,edx  ; copy smaller from memory sizes
-
 
1375
        jge    noedxebxxchg
-
 
1376
        mov    edx,ebx
-
 
1377
      noedxebxxchg:
-
 
1378
 
-
 
1379
        movzx  ecx,dx
-
 
1380
        shl    ecx,12
-
 
1381
        add    ecx,4096
-
 
1382
 
-
 
1383
        mov    edi,esi
-
 
1384
 
-
 
1385
        mov    eax,[0x3010]
-
 
1386
        mov    esi,[eax+0x10]
-
 
1387
 
-
 
1388
        mov    [eax+0x10],edi  ; new memory position
-
 
1389
 
-
 
1390
        mov    eax,[0x3000]    ; new memory size
-
 
1391
        shl    eax,8
-
 
1392
        add    eax,0x80000
-
 
1393
        mov    [eax+0x8c],ebp
-
 
1394
 
-
 
1395
        mov    [new_pos],edi    ; new position for threads
-
 
1396
        mov    [new_amount],ebp ; new amount of mem for threads
-
 
1397
 
-
 
1398
        cmp    esi,edi
-
 
1399
        je     no_app_move
-
 
1400
 
-
 
1401
        cld
-
 
1402
        rep    movsb           ; move the app image to the new position
-
 
1403
 
-
 
1404
      no_app_move:
-
 
1405
 
1046
        
1406
        call   save_new_position_for_threads
-
 
1407
        call   check_for_thread_mem
-
 
Line 1408... Line 1047...
1408
 
1047
        jmp    new_mem_resize ;resize for new type of processes
Line 1409... Line -...
1409
        mov    [application_table_status],0
-
 
1410
 
-
 
1411
        mov    [esp+36],dword 0 ; eax <- 0 ; successfull
-
 
1412
 
-
 
1413
        ret
-
 
1414
 
-
 
1415
     rfind_free_ret_2:
-
 
1416
 
-
 
1417
     mem_resize_unsuccess:
-
 
1418
 
-
 
1419
        mov    [application_table_status],0
-
 
1420
 
-
 
1421
        mov    [esp+36],dword 1 ; eax <- 1 ; unsuccessfull
-
 
1422
 
-
 
1423
        ret
-
 
1424
 
-
 
1425
     no_application_mem_resize:
-
 
1426
 
-
 
1427
 
-
 
1428
        ret
-
 
1429
 
-
 
1430
 
-
 
1431
align 4
-
 
1432
find_free_mem:
-
 
1433
 
-
 
1434
        push   eax
-
 
1435
        push   ebx
-
 
1436
        push   ecx
-
 
1437
        push   edx
-
 
1438
        push   edi
-
 
1439
 
-
 
1440
        call   find_free_process_slot
-
 
1441
        mov    eax,[new_process_place]
-
 
1442
 
-
 
1443
        cmp    eax,max_processes
-
 
1444
        jg     find_free_ret_2
-
 
1445
 
-
 
1446
        cmp    [thread_create],1
-
 
1447
        je     thread_c
-
 
1448
 
-
 
1449
        mov    esi,[0xfe84]
-
 
1450
        add    edi,esi
-
 
1451
        dec    edi
-
 
1452
 
-
 
1453
        mov    eax,2
-
 
1454
        cmp    dword [0x3004],1
-
 
1455
        je     findf4
-
 
1456
 
-
 
1457
     fgdt:
-
 
1458
 
-
 
1459
        mov    edx,2
-
 
1460
 
-
 
1461
      findgdtl1:
-
 
1462
 
-
 
1463
        mov    ecx,edx
-
 
1464
        shl    ecx,3
-
 
1465
 
-
 
1466
        ; eax run base -> ebx limit
-
 
1467
 
-
 
1468
        mov    al,[ecx+gdts+ app_code-3 +4]
-
 
1469
        mov    ah,[ecx+gdts+ app_code-3 +7]
-
 
1470
        shl    eax,16
-
 
1471
        mov    ax,[ecx+gdts+ app_code-3 +2]
-
 
1472
;!!mem
-
 
1473
        cmp    eax,std_application_base_address
-
 
1474
        jz     findfl3
-
 
1475
;!!mem
-
 
1476
 
-
 
1477
        movzx  ebx,word [ecx+gdts+ app_code-3 +0]
-
 
1478
        shl    ebx,12
-
 
1479
        add    ebx,eax
-
 
1480
 
-
 
1481
        cmp    eax,edi
-
 
1482
        jg     findfl3
-
 
1483
        cmp    ebx,esi
-
 
1484
        jb     findfl3
-
 
1485
 
-
 
1486
        add    esi,4096
-
 
1487
        add    edi,4096
-
 
1488
 
-
 
1489
        cmp    edi,[0xfe8c]        ; < c_memory
-
 
1490
        jbe    fgdt
-
 
1491
 
-
 
1492
        jmp    find_free_ret_2
-
 
1493
 
-
 
1494
      findfl3:
-
 
1495
 
-
 
1496
        inc    edx
-
 
1497
        cmp    edx,[check_processes]
-
 
1498
        jbe    findgdtl1
-
 
1499
 
-
 
1500
     findfl1:
-
 
1501
     thread_c:
-
 
1502
 
-
 
1503
         mov    eax,[new_process_place]
-
 
1504
 
-
 
1505
     findf4:
-
 
1506
 
-
 
1507
        mov    [first_gdt_search],eax
-
 
1508
        mov    [gdt_place],eax
-
 
1509
 
-
 
1510
        mov    ecx,eax
-
 
1511
        shl    ecx,3
-
 
1512
 
-
 
1513
        inc    edi
-
 
1514
        sub    edi,esi
-
 
1515
        add    edi,4095
-
 
1516
        shr    edi,12
-
 
1517
        dec    edi
-
 
1518
 
-
 
1519
        ; code
-
 
1520
 
-
 
1521
        mov    eax,esi
-
 
1522
        mov    ebx,edi
-
 
1523
 
-
 
1524
        mov    [ecx+gdts+ app_code-3 +2], ax                   ;  base  0:15
-
 
1525
        shr    eax,16
-
 
1526
        mov    [ecx+gdts+ app_code-3 +4], al                   ;  base  23:16
-
 
1527
        mov    [ecx+gdts+ app_code-3 +7], ah                   ;  base  31:24
-
 
1528
        mov    [ecx+gdts+ app_code-3 +0], bx                   ;  limit
-
 
1529
        mov    [ecx+gdts+ app_code-3 +5], word 11010000b *256 +11111010b
-
 
1530
 
-
 
1531
        ; data
-
 
1532
 
-
 
1533
        mov    eax,esi
-
 
1534
        mov    [ecx+gdts+ app_data-3 +2], ax                   ;  base  0:15
-
 
1535
        shr    eax,16
-
 
1536
        mov    [ecx+gdts+ app_data-3 +4], al                   ;  base  23:16
-
 
1537
        mov    [ecx+gdts+ app_data-3 +7], ah                   ;  base  31:24
-
 
1538
        mov    [ecx+gdts+ app_data-3 +0], bx                   ;  limit
-
 
1539
        mov    [ecx+gdts+ app_data-3 +5], word 11010000b *256 +11110010b
-
 
1540
 
-
 
1541
        push   esi
-
 
1542
        mov    esi,process_loading
-
 
1543
        call   sys_msg_board_str
-
 
1544
        pop    esi
-
 
1545
 
-
 
1546
      find_free_ret:
-
 
1547
 
-
 
1548
        pop    edi
-
 
1549
        pop    edx
-
 
1550
        pop    ecx
-
 
1551
        pop    ebx
-
 
1552
        pop    eax
-
 
1553
        ret
-
 
1554
 
-
 
1555
      find_free_ret_2:
-
 
1556
 
-
 
1557
        cmp    [dec3004],0
-
 
1558
        je     no3004inc
-
 
1559
        dec    dword [0x3004]
-
 
1560
      no3004inc:
-
 
1561
 
-
 
1562
        pop    edi
-
 
Line 1563... Line 1048...
1563
        pop    edx
1048
 
Line 1564... Line 1049...
1564
        pop    ecx
1049
 
Line 1634... Line 1119...
1634
 
1119
 
1635
start_application_hd:
1120
start_application_hd:
Line 1636... Line 1121...
1636
    jmp   new_start_application_hd
1121
    jmp   new_start_application_hd
1637
 
1122
 
1638
uglobal
1123
uglobal
1639
  threadstring       dd  0x0
1124
  ;threadstring       dd  0x0
1640
  new_process_place  dd  0x0
1125
  new_process_place  dd  0x0
1641
  check_processes    dd  0x0
1126
  ;check_processes    dd  0x0
1642
  dec3004            db  0x0
1127
  ;dec3004            db  0x0
1643
  app_start    dd  0x0
1128
  app_start    dd  0x0
1644
  app_i_end    dd  0x0
1129
  app_i_end    dd  0x0
1645
  app_mem      dd  0x0
1130
  app_mem      dd  0x0
1646
  app_esp      dd  0x0
1131
  app_esp      dd  0x0
1647
  app_i_param  dd  0x0
1132
  app_i_param  dd  0x0
1648
  app_i_icon   dd  0x0
1133
  app_i_icon   dd  0x0
1649
  app_mem_pos  dd  0x0
1134
  app_mem_pos  dd  0x0
1650
  thread_create    dd 0x0
1135
  ;thread_create    dd 0x0
Line 1651... Line 1136...
1651
  gdt_place        dd 0x0
1136
  ;gdt_place        dd 0x0
1652
endg
1137
endg
1653
 
1138
 
Line 1666... Line 1151...
1666
;   ebx=thread start
1151
;   ebx=thread start
1667
;   ecx=thread stack value
1152
;   ecx=thread stack value
1668
;
1153
;
1669
; on return : eax = pid
1154
; on return : eax = pid
1670
jmp new_sys_threads
1155
jmp new_sys_threads
1671
    cli
-
 
1672
    cmp   [application_table_status],0
-
 
1673
    je    stth9
-
 
1674
    sti
-
 
1675
    call  change_task
-
 
1676
    jmp   sys_threads
-
 
1677
  stth9:
-
 
1678
 
-
 
1679
    call  set_application_table_status
-
 
1680
 
-
 
1681
    sti
-
 
1682
 
-
 
1683
    cmp  eax,1
-
 
1684
    jne  no_sys_thread_create
-
 
1685
    cli
-
 
1686
 
-
 
1687
    mov  eax,[0x3010]
-
 
1688
    mov  eax,[eax+0x10]
-
 
1689
    mov  [app_mem_pos],eax
-
 
1690
 
-
 
1691
    mov  [app_i_param],0
-
 
1692
    mov  [app_i_icon],0
-
 
1693
 
-
 
1694
    mov  [app_start],ebx
-
 
1695
    mov  [app_esp],ecx
-
 
1696
 
-
 
1697
    mov  ebx,[0x3000]
-
 
1698
    shl  ebx,8
-
 
1699
    add  ebx,0x80000
-
 
1700
    mov  [threadstring],ebx
-
 
1701
    mov  ebx,[ebx+0x8c]
-
 
1702
    mov  [app_mem],ebx
-
 
1703
 
-
 
1704
    mov  esi,[app_mem_pos]
-
 
1705
    mov  edi,[app_mem]
-
 
1706
    add  edi,esi
-
 
1707
    dec  edi
-
 
1708
    mov  [thread_create],1
-
 
1709
    call find_free_mem
-
 
1710
    cmp  esi,0
-
 
1711
    jne  th_cr1
-
 
1712
    mov  [application_table_status],0
-
 
1713
    mov  eax,1   ; no free memory
-
 
1714
    sti
-
 
1715
    ret
-
 
1716
  th_cr1:
-
 
1717
    push dword 0
-
 
1718
    push dword [threadstring]
-
 
1719
    jmp  add_app_parameters
-
 
1720
  no_sys_thread_create:
-
 
1721
 
-
 
1722
    mov  eax,-1
-
 
1723
    mov  [application_table_status],0
-
 
1724
    ret
-
 
1725
 
-
 
1726
 
-
 
1727
find_free_process_slot:
-
 
1728
 
-
 
1729
    pusha
-
 
1730
 
-
 
1731
    mov   ebx,[0x3004]
-
 
1732
    mov   [check_processes],ebx
-
 
1733
    inc   ebx
-
 
1734
    mov   [new_process_place],ebx
-
 
Line 1735... Line -...
1735
 
-
 
Line 1736... Line -...
1736
    mov   ebx,2
-
 
1737
 
-
 
1738
  newfps:
-
 
1739
 
-
 
1740
    mov   eax,ebx
-
 
1741
    ;imul  eax,0x20
-
 
1742
    shl   eax, 5
-
 
1743
    add   eax,0x3000+0xa
-
 
1744
    cmp   [eax],byte 9
-
 
1745
    je    ffpl
-
 
1746
 
-
 
1747
    inc   ebx
-
 
1748
    cmp   ebx,[0x3004]
-
 
1749
    jbe   newfps
-
 
1750
 
-
 
1751
    ;mov   [dec3004],0
-
 
1752
    mov   [dec3004],1
-
 
1753
    shl   ebx,5
-
 
1754
    mov   [0x3000+0xa+ebx],byte 9
-
 
1755
    inc   dword [0x3004]
-
 
1756
 
-
 
1757
    popa
-
 
1758
    ret
-
 
1759
 
-
 
1760
  ffpl:
-
 
1761
 
-
 
1762
    ;mov   [dec3004],1
-
 
1763
    ;dec   dword [0x3004]
-
 
1764
    mov   [dec3004],0
-
 
1765
    mov   [new_process_place],ebx
-
 
1766
 
-
 
1767
    popa
-
 
1768
    ret
-
 
1769
 
-
 
1770
 
-
 
1771
add_app_parameters:
-
 
1772
; returns:  eax = pid or -1 if unsuccesfull
-
 
1773
    cmp   [app_i_param],dword 0     ; parameter
-
 
1774
    jz    no_app_params
-
 
1775
    xor   eax, eax
-
 
1776
    mov   edi,[app_i_param]
-
 
1777
    add   edi,[app_mem_pos]
-
 
1778
    mov   ecx,256/4
-
 
1779
    cld
-
 
1780
    rep   stosd
-
 
1781
    mov   esi,[esp+4]
-
 
1782
    test  esi, esi
-
 
1783
    jz    no_app_params
-
 
1784
    mov   eax,[app_i_param]
-
 
1785
    add   eax,[app_mem_pos]
-
 
1786
    mov   edi,eax
-
 
1787
    mov   ecx,256
-
 
1788
    cld
-
 
1789
  app_new_param:
-
 
1790
    cmp   [esi],byte 0
-
 
1791
    jz    no_app_params
-
 
1792
    movsb
-
 
1793
    loop  app_new_param
-
 
1794
  no_app_params:
-
 
1795
 
-
 
1796
    ;inc   dword [0x3004]            ; increase number of processes
-
 
1797
    mov   ebx,[new_process_place]
-
 
1798
 
-
 
1799
    mov   edi,ebx                   ; clear 0x80000 (256 bytes)
-
 
1800
    shl   edi,8
-
 
1801
    add   edi,0x80000
-
 
1802
    mov   ecx,256 / 4
-
 
1803
    mov   eax,0
-
 
1804
    cld
-
 
1805
    rep   stosd
-
 
1806
 
-
 
1807
    shl   ebx,5                     ; * 32 +0x3000
-
 
1808
    add   ebx,0x3000
-
 
1809
 
-
 
1810
    mov   al,byte [new_process_place] ; screen id ?
-
 
1811
    mov   [ebx+0xe],al
-
 
1812
 
-
 
1813
    mov   [ebx],dword 1+2+4         ; report events: windowdraw, key, button
-
 
1814
 
-
 
1815
    inc   dword [process_number]    ; process id number
-
 
1816
    mov   eax,[process_number]
-
 
1817
    mov   [ebx+4],eax
-
 
1818
 
-
 
1819
    mov   ecx,ebx                   ; set draw limits
-
 
1820
    add   ecx,draw_data-0x3000
-
 
1821
    mov   [ecx+0],dword 0
-
 
1822
    mov   [ecx+4],dword 0
-
 
1823
    mov   eax,[0xfe00]
-
 
1824
    mov   [ecx+8],eax
-
 
1825
    mov   eax,[0xfe04]
-
 
1826
    mov   [ecx+12],eax
-
 
1827
 
-
 
1828
    mov   eax,[app_mem_pos]        ; position in memory
-
 
1829
    mov   [ebx+0x10],eax
-
 
1830
 
-
 
1831
    ; TSS
-
 
1832
    xor   ebx,ebx
-
 
1833
    cmp   [thread_create],ebx
-
 
1834
    jnz   clone_cr3_table
-
 
1835
    mov   eax,[new_process_place]
-
 
1836
    call  create_app_cr3_table
-
 
1837
    jmp   set_cr3
-
 
1838
clone_cr3_table:
-
 
1839
;    mov   eax,[new_process_place]
-
 
1840
;    mov   ebx,[0x3000]
-
 
1841
;    call  addreference_app_cr3_table
-
 
1842
    mov   eax,[0x3000]
-
 
1843
    call  get_cr3_table
-
 
1844
set_cr3:
-
 
1845
    add   eax,8+16
-
 
1846
    mov   [l.cr3],eax
-
 
1847
    
-
 
1848
    mov   eax,[app_start]
-
 
1849
    mov   [l.eip],eax
-
 
1850
    mov   eax,[app_esp]
-
 
1851
    mov   [l.esp],eax
-
 
1852
 
-
 
1853
    mov   ebx,[new_process_place]              ; gdt's
-
 
1854
    shl   ebx,3
-
 
1855
 
-
 
1856
    mov   ax,app_code
-
 
1857
    add   ax,bx
-
 
1858
    mov   [l.cs],ax
-
 
1859
    mov   ax,app_data
-
 
1860
    add   ax,bx
-
 
1861
    mov   [l.ss],ax
-
 
1862
    mov   [l.ds],ax
-
 
1863
    mov   [l.es],ax
-
 
1864
    mov   [l.fs],ax
-
 
1865
    mov   ax,graph_data
-
 
1866
    mov   [l.gs],ax
-
 
1867
    mov   [l.io],word 128
-
 
1868
    mov   [l.eflags],dword 0x11202
-
 
1869
    mov   [l.ss0], os_data
-
 
1870
    ;mov   [l.ss1], ring1_data
-
 
1871
    ;mov   [l.ss2], ring2_data
-
 
1872
    ; [Ivan 07.03.2005]
-
 
1873
    mov   [l.esp0], 0x8000 ;0x55000 ; used by i38 handler
-
 
1874
    ; [/Ivan 07.03.2005]
-
 
1875
    mov   [l.esp1], 0x56000
-
 
1876
    mov   [l.esp2], 0x57000
-
 
1877
 
-
 
1878
    mov   eax,tss_sceleton          ; move tss to tss_data+
-
 
1879
    mov   ebx,[new_process_place]
-
 
1880
    imul  ebx,tss_step
-
 
1881
    add   ebx,tss_data
-
 
1882
    mov   ecx,120
-
 
1883
    call  memmove
-
 
1884
 
-
 
1885
 
-
 
1886
    ; Add IO access table
-
 
1887
 
-
 
1888
    or   eax, -1
-
 
1889
    mov  edi, [new_process_place]
-
 
1890
    imul edi, tss_step
-
 
1891
    add  edi, tss_data + 128
-
 
1892
    mov  ecx, 2048 ; for 2048 * 4 * 8 bits = 65536 ports
-
 
1893
    cld
-
 
1894
    rep  stosd
-
 
1895
 
-
 
1896
    ; make sure gdt is pointing to the process
-
 
1897
    ; and not to i40 handler
-
 
1898
 
-
 
1899
    mov   ecx,ebx
-
 
1900
    mov   edi,[new_process_place]
-
 
1901
;    imul  edi,8
-
 
1902
    shl   edi, 3
-
 
1903
 
-
 
1904
    mov   [edi+gdts+ tss0 +0], word tss_step     ; limit 0:15
-
 
1905
    mov   [edi+gdts+ tss0 +2], cx                ; base  0:15
-
 
1906
    mov   eax,ecx
-
 
1907
    shr   eax,16
-
 
1908
    mov   [edi+gdts+ tss0 +4], al                ; base  23:16
-
 
1909
    mov   [edi+gdts+ tss0 +7], ah                ; base  31:24
-
 
1910
    mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
-
 
1911
 
-
 
1912
    pop   eax
-
 
1913
    pop   ebx
-
 
1914
 
-
 
1915
    mov   ebx,[new_process_place]              ; save name of the process
-
 
1916
    shl   ebx,8
-
 
1917
    add   ebx,0x80000
-
 
1918
    mov   ecx,11
-
 
1919
    call  memmove
-
 
1920
 
-
 
1921
    mov   ebx,[new_process_place]              ; save image size
-
 
1922
    shl   ebx,8
-
 
1923
    add   ebx,0x80000+0x8C
-
 
1924
    mov   eax,[app_mem]
-
 
1925
    mov   [ebx],eax
-
 
1926
 
-
 
1927
    mov   [0xf400],byte 0           ; empty keyboard buffer
-
 
1928
    mov   [0xf500],byte 0           ; empty button buffer
-
 
1929
 
-
 
1930
    mov   [application_table_status],0
-
 
1931
    mov   eax,[process_number]
-
 
1932
 
-
 
1933
    mov   ebx,[new_process_place]
-
 
1934
    shl   ebx, 5 ;imul  ebx,0x20
-
 
1935
    mov   [0x3000+ebx+0xa],byte 0
-
 
1936
 
-
 
1937
    mov   edi,[new_process_place]
-
 
1938
    shl   edi,5
-
 
1939
    add   edi,window_data
-
 
1940
 
-
 
1941
    mov   ebx,[new_process_place]
-
 
1942
    movzx  esi, word [0xC000 + ebx*2]
-
 
1943
    lea    esi, [0xC400 + esi*2]
-
 
1944
    call   windowactivate
-
 
1945
 
-
 
1946
    sti
-
 
1947
 
-
 
1948
    push   esi
-
 
1949
    mov    esi,process_running
-
 
1950
    call   sys_msg_board_str
-
 
1951
    pop    esi
-
 
Line 1952... Line 1156...
1952
 
1156
 
1953
    ret
1157
 
1954
 
1158
 
1955
iglobal
1159
iglobal
Line 1990... Line 1194...
1990
  fpu_ok_1:
1194
  fpu_ok_1:
Line 1991... Line 1195...
1991
 
1195
 
1992
    mov   [0xf400],byte 0           ; empty keyboard buffer
1196
    mov   [0xf400],byte 0           ; empty keyboard buffer
Line 1993... Line 1197...
1993
    mov   [0xf500],byte 0           ; empty button buffer
1197
    mov   [0xf500],byte 0           ; empty button buffer
1994
 
1198
 
1995
    mov   ecx,esi                               ; clear memory reserv.
1199
;    mov   ecx,esi                               ; clear memory reserv.
1996
    shl   ecx,3
1200
;    shl   ecx,3
1997
    mov   [ecx+gdts+ app_code-3 +0],dword 0
1201
;    mov   [ecx+gdts+ app_code-3 +0],dword 0
1998
    mov   [ecx+gdts+ app_code-3 +4],dword 0
1202
;    mov   [ecx+gdts+ app_code-3 +4],dword 0
Line 1999... Line 1203...
1999
    mov   [ecx+gdts+ app_data-3 +0],dword 0
1203
;    mov   [ecx+gdts+ app_data-3 +0],dword 0
2000
    mov   [ecx+gdts+ app_data-3 +4],dword 0
-
 
2001
 
-
 
2002
    mov   edi, esi
-
 
2003
;    shl   edi, 5
-
 
2004
;    add   edi, 0x3000
-
 
2005
;    cmp   [edi+0xa],byte 3  ; if normal terminate then clear int40 handler
-
 
2006
;    jne   nocl40
-
 
2007
 
-
 
Line 2008... Line -...
2008
;    mov   edi,esi   ; free the used interrupt 0x40 handler
-
 
2009
;    shl   edi, 8 ;imul  edi,256
-
 
Line 2010... Line 1204...
2010
;    mov   eax,[edi+0x80000+0xb0]
1204
;    mov   [ecx+gdts+ app_data-3 +4],dword 0
Line 2011... Line -...
2011
 
-
 
2012
;    cmp   eax,0     ; is application using a systemcall interrupt  ?
-
 
2013
;    je    nocl40
-
 
2014
 
-
 
2015
    mov   [usedi40+eax],byte 0
-
 
2016
 
-
 
2017
;    mov   edi,8
-
 
2018
;    imul  edi,eax
-
 
2019
    mov   edi, eax
-
 
2020
    shl   edi, 3
-
 
2021
    mov   [edi+tss0sys_l +5], word 01010000b *256 +11101001b
-
 
2022
 
-
 
2023
;    mov   edi,128
-
 
2024
;    imul  edi,eax
-
 
2025
    mov   edi, eax
-
 
2026
    shl   edi, 7
-
 
2027
    mov   [edi+0x298000+l.eip-tss_sceleton],dword i40
-
 
2028
    mov   [edi+0x298000+l.eflags-tss_sceleton],dword 0x11002
-
 
2029
 
-
 
Line 2030... Line 1205...
2030
    mov   ebx,eax
1205
 
2031
    shl   ebx, 12 ;imul  ebx,4096
1206
    mov   edi, esi
2032
    add   ebx,sysint_stack_data
1207
 
2033
    mov   [edi+0x298000+l.esp-tss_sceleton],ebx
1208
 
Line 2144... Line 1319...
2144
    jae   nlc41
1319
    jae   nlc41
2145
    movzx ecx, word [eax]
1320
    movzx ecx, word [eax]
2146
    mov   [0xC400 + ecx*2], si
1321
    mov   [0xC400 + ecx*2], si
2147
    jmp   nlc40
1322
    jmp   nlc40
2148
  nlc41:
1323
  nlc41:
2149
 ; ivan 08.12.2004 begin
-
 
2150
    ;mov   ebx, [0x3004]
-
 
2151
    ;dec   ebx
-
 
2152
    ;lea   esi, [0xC400 + ebx*2]
-
 
2153
    ;call  windowactivate
-
 
2154
 ; ivan 08.12.2004 end
-
 
2155
    popa
1324
    popa
Line 2156... Line 1325...
2156
 
1325
 
2157
    pusha ; remove hd1 reservation
1326
    pusha ; remove hd1 reservation
2158
    mov   edx,esi
1327
    mov   edx,esi