Skip to content

Commit 6d0abc2

Browse files
code cleanup and optimization
1 parent f7cce9c commit 6d0abc2

10 files changed

Lines changed: 24 additions & 27 deletions

File tree

filesystem/bin/terminal

80 Bytes
Binary file not shown.

filesystem/kernel/kernel.sys

0 Bytes
Binary file not shown.

src/asm/asmisr.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
global temp
22
extern screen_print_int
33

4-
; NOTE: All I can only handle one interrupt at a time (for now) because
5-
; I have one global ISR stack and not ISR stack per task because
4+
; NOTE: The syscall manager handles only one interrupt at a time (for now)
5+
; because I have one global ISR stack and not ISR stack per task because
66
; I didn't have enough time to debug that.
77

88
; ISR definition for interrupts without an err code

src/drivers/atapio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void ata_read_sectors(unsigned int lba, char sector_count, char *buffer) {
4040
out_byte(ATA_COMMAND_REGISTER_PORT, ATA_READ); //read command
4141
unsigned int offset = 0, i = 0;
4242
while(sector_count--) {
43-
ata_wait_for_rdy(ATA_REGULAR_STATUS_REGISTER_PORT);
44-
ata_wait_for_drq(ATA_REGULAR_STATUS_REGISTER_PORT);
43+
ata_wait_for_rdy(ATA_REGULAR_STATUS_REGISTER_PORT); // Spun up
44+
ata_wait_for_drq(ATA_REGULAR_STATUS_REGISTER_PORT); // Ready for transfer
4545
for(i = 0;i < 256;i++) {
4646
*( (unsigned short *)buffer + offset + i ) = in_word(ATA_DATA_REGISTER_PORT);
4747
}

src/drivers/ext2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int path_to_inode(char * partial_path) {
297297
}
298298
i++;
299299
}
300-
300+
free((void *)full_path);
301301
i = 0;
302302
return inode;
303303
}

src/kernel/elf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static int elf_load_stage1(Elf32_Ehdr_t *hdr) {
205205
puts("Allocated memory for a section ");
206206
screen_print_int(section->sh_size, 10);
207207
puts("\n");
208+
free(mem);
208209
}
209210
}
210211
}
@@ -296,6 +297,9 @@ static void elf_init_exec(Elf32_Ehdr_t * hdr, int argc, char ** argv) {
296297
swapPageDirectoryAsm((unsigned int *)pdpt_bk);
297298
elf_task->regs.ebx = argc;
298299
elf_task->regs.ecx = (unsigned int)argv_ptr2;
300+
free(data);
301+
free((void *)argv_mem_ptr);
302+
free((void *)argv_ptr);
299303
}
300304

301305
void *elf_load_file(void *file, int argc, char ** argv) {

src/kernel/heap.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ void *malloc(unsigned int size) {
1919
while((ptr != 0) && (ptr->used || ptr->length < size ) ){
2020
ptr = ptr->next;
2121
}
22+
if((unsigned int)ptr > heap_end || (unsigned int)ptr < heap_start)
23+
{
24+
puts("Kernel out of memory.\n");
25+
puts("[KERNEL PANIC] System halted :(");
26+
while(1);
27+
}
2228
if(ptr->length == -1) {
2329
ptr->length = size;
2430
ptr->used = 1;
2531
ptr->next = ptr + size + sizeof(memory_block_header_t);
32+
if((unsigned int)ptr->next > heap_end || (unsigned int)ptr->next < heap_start)
33+
{
34+
puts("Kernel out of memory.\n");
35+
puts("[KERNEL PANIC] System halted :(");
36+
while(1);
37+
}
2638
ptr->next->length = -1;
2739
ptr->next->used = 0;
2840
ptr->next->next = 0;
2941
}
3042
else {
3143
ptr->used = 1;
3244
}
33-
if((unsigned int)ptr > heap_end)
34-
return 0;
3545
retaddr = (void *)((unsigned int)ptr + sizeof(memory_block_header_t));
3646
memset(retaddr, 0, size);
3747
return retaddr;

src/kernel/isr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void isr_handler(registers_t regs)
9292
}
9393
else {
9494
puts("[KERNEL PANIC] System halted :(");
95-
getc();
95+
while(1);
9696
}
9797
}
9898
}

src/kernel/isr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct registers
88
unsigned int edi, esi, ebp, kesp, ebx, edx, ecx, eax;//
99
unsigned int int_no, err_code; // Pushed by ISRs in asmisr.asm
1010
unsigned int eip, cs, eflags, useresp, ss; // Pushed by int opcode
11-
};
11+
}__attribute__((packed));
1212

1313
typedef struct registers registers_t;
1414

src/kernel/memory.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ void init_memory(multiboot_info_t * mymbd) {
2929
page_dir[i].page_table_address = (i*0x200000)>>12;
3030
page_dir[i].kernel_user = 0;
3131
}
32-
////////////////////////////////////////////////////////////////////////////
33-
// An unsuccessful attempt at making a Higher Half Kernel
34-
// unsigned int i, address = 0xB0000000;
35-
// puts("\n");
36-
// for(i = 388; i < 475; i++){
37-
// screen_print_int(address>>12, 16);
38-
// puts(" ");
39-
// page_dir[i].present = 1;
40-
// page_dir[i].ro_rw = 1;
41-
// page_dir[i].size = 1;
42-
// page_dir[i].page_table_address = (unsigned int)address>>12;
43-
// screen_print_int(page_dir[i].page_table_address, 16);
44-
// puts("\n");
45-
// getc();
46-
// page_dir[i].kernel_user = 0;
47-
// address = (unsigned int)((unsigned int)address + (unsigned int)0x200000);
48-
// }
4932
puts("Enabaling PAE paging...\n");
5033
enablePaePagingAsm();
5134
swapPageDirectoryAsm((unsigned int *)&page_dir_ptr_tab);
@@ -206,7 +189,7 @@ unsigned int kalloc_frame()
206189
pframe++;
207190
// asmcli();
208191
disablePagingAsm();
209-
memset((void *)ret, '\0', 0x1000);
192+
memset((void *)ret, 0, 0x1000);
210193
enablePagingAsm();
211194
// asmsti();
212195
return(ret);

0 commit comments

Comments
 (0)