NOTE 1:
if you want to change any kernel structure (eg:base addrs,gdt,idt etc)
make sure u change all these files(if the change is common)

1.asm\boot\boot1.asm
2.asm\boot\boot2.asm
3.asm\kstart\kstart.asm
4.include\jazmyn\kernel.h

NOTE 2:
if kernel increases in size change the macro KERNEL_SECTORS in boot2.asm

NOTE 3:
make sure that PIC initialization & ISR`s are compatible

NOTE 4:
fs\drvmgr.cpp -> register_driver must be improved	

NOTE 5:
in TC char,uchar:1 byte, int,short,uint,ushort:2 bytes, lone,ulong:4 bytes.

'c' -> char
num < 32768 -> int
num > 32768 && num < 2^4 -> long
num > 2^4 -> unsigned long

in gcc char:1 byte  short:2 bytes   int,long: 4bytes

'c' -> char
num >= -(2^31 - 1) && num <= (2^31 - 1) -> int
num < -(2^31 - 1) -> converted to ulong
num >  (2^31 - 1) -> ulong

NOTE 6:
all inline functions are expanded in compilation time so they should be defined in .h files
use option -finline to expand inline functions	

NOTE 7:
for task switch it is suffiecient to load tss selector in cs	

NOTE 8:
Linux gdt entries:
Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
4-TSS0, 5-LDT0, 6-TSS1 etc ...
ldt,tss descriptors are at DPL0

NOTE 8:
process in jazmyn:
class process{ ctor,dtor,operator=}
class process_list{process *head,add_to_list(process*p),delete(process*p)}

process_list l;
process *curr;

fs_main()
{
case fork:	
	process child = curr;
	process_list = process_list+child;
}

NOTE 9:
on sys_call kernel stack- ss,esp,eflag,cs,eip	

NOTE 10:
In jazmyn all 4GB memory is mapped , with only physical memory present & rest of kernel memory   (256 MB - physical mem) not present.All usr process start at VA 256 mb so corresponding entries in page tables are set according to their physical load address.

NOTE 11:
note when kernel size changes to get  the sector map of user program

NOTE 12:
All user progs begin at virtual address 0x10000000 (256MB boundary) they get virtual address space of 4 GB (including kernel space,bcoz kernel is part of user process) .
kernel stack page is with in the kernel & user paging mechanism will map the virtual address of kernel stack to physical address of kernel stack

on sys_call or intr,

1. in library routine: save ds,save offset of arg in some registers,int 0xsys_call.
2. sys_call: mov cr3,kernel_page_dir
	     save regs of usr process to ksp
             ...
             ...
	     call handler -> in handler obtain the physical addrs of arg with the help of saved               ldt_sel & paging part (cr3,page tables) of user process in process table.
             ...
             ...
             pop all regs
             mov cr3,user_page_dir
             iretd 	  	 

NOTE 13: 
be very very careful while performing arithmatic operations on pointers.
if you want to add an offset to a pointer,first convert that pointer into uint & add offset. otherwise the address obtained will be ptr + offset*sizeof(*ptr)
c allows arithmatic ops on void ptrs.
eg: void *ptr = 100; ptr = ptr + 10; now ptr= 110;
c++ does not allow arithmatic ops on void ptrs.

NOTE 14:
gcc produces code with an organization of cs=ds=ss=es=fs=gs.

layout:   cs:
             ....
             ....
             ....
          ds:
             ....
             ....
             ....
          bss:
             ....
             ....
             ....
the above code organization is according to linker script of jazmyn. 

1.All uninitialized global vars are placed in BSS. BSS will not be in binary file. so it is necessary to leave space for it above ds.
2.All local string constants will be in cs.
3.All initialized global vars will be in ds
4.All global string constants will be in cs, but pointer will be in ds
  eg: char *str = "hello";
      main()
      {
      }
      here, "hello" will be in cs. but str will be in ds

eg: virtual addrs : 0x00100000.

    int i = 10;
    int j;

    int main()
    {
          char * str = "hello";
          int k = i;
          j = k; 
          return 0;
    }

    cs:     0x00100000
       ...
       ...
       "hello"
       ...
       mov [ebp-4],[1010] --> int k = i;
       mov [2010],[ebp-4] --> j = k;
       ...
    ds:     0x00101000 
[10]   int i
       ...
       ...
    bss:    0x00102000
[10]   int j   
  
jazmyn process map:
   cs :  virtual base = 0x00100000 limit = size of cs
   ds :  virtual base = 0x00100000 limit = size of cs + size of ds + size of bss
   ss :  virtual base = 0x00100000 limit = size of cs + size of ds + size of bss + 4k

NOTE 15:
alloc_pages should allocate pages above kernel heap.


NOTE 16:
LBA to CHS: sector = (LBA % SECT_PER_TRACK) + 1;
            cylinder = (LBA / SECT_PER_TRACK) / NUMHEADS;
            head = (LBA / SECT_PER_TRACK) % NUMHEADS;

			or
	    
            cylinder = LBA / (heads_per_cylinder * sectors_per_track)
            temp = LBA % (heads_per_cylinder * sectors_per_track)
            head = temp / sectors_per_track
            sector = temp % sectors_per_track + 1

CHS to LBA:
	    LBA = ( (cylinder * heads_per_cylinder + heads )
            	     * sectors_per_track ) + sector - 1


NOTE 17:
	to get actual partition info.
	read MBR:
		get start of primary partition -- Start_primary;
		end_primary = start_primary + num_sect - 1;
                
                start_ext1_part = end_primary + 1;
                end_ext1_part = start_ext1_part + num_sect - 1;

                read MBR of above extended partition.

                start_1st_log_drv = start_ext_part + 63;
                end_1st_log_drv = start_1st_log_drv + num_sect - 1;
                
                start_ext2_part =  end_1st_log_drv + 1;
                end_ext2_part = start_ext2_part + num_sect - 1;

		read MBR of above ext partition
               
                start_2nd_log_drv = start_ext2_part + 63;
                end_2st_log_drv = start_2st_log_drv + num_sect - 1;               

		.......
		.......
		until end; 
		end is determined by end_ext1_part or no extended partition.


NOTE 18:
On any request to file or dir,

char name[255];
path = get_next_name(path,name)
if(name[1] == ':')	//path is absolute
{
	start_clus = 2;
	while(path = get_next_name(path,name))
	{
		mem = read_clus(start_clus,_Fvi[i]);
		scan that 'mem' to get entry for 'name';
		start_clus = get_start_clus(name);
	}
}

else	//path is relative
{
	start_clus = get_start_clus(pwd);
	while(path = get_next_name(path,name)
	{
		mem = read_clus(start_clus,_Fvi[i]);
		scan that 'mem' to get entry for 'name';
		start_clus = get_start_clus(name);
	}
}
	
at the end the 'mem' contains the sequence of DIR entries or the complete file.

NOTE 19:
in fun call, the rightmost arg is pushed first.
eg:
push ax
push bx
call _fun

fun(int bx,int ax)
{
...
}

NOTE 20:
for disk drivers:

1. A process issues a request to fs - open a file
2. fs after performing logical operations, issues a request to driver_main
3. in driver_main , a driver::fun is called to append the request to the queue
	in fun()
	{
		append to queue;
		if it is the first req in the queue, then 
		a. issue the hard ware req
		b. curr_proc->block();
		return to driver main;
	}
4.in driver main wait until the request is serviced by checking a shared variable
5.in interrupt handler, the queue head is removed, proc is unblocked & shared var is
  updated;if it is the last req, do nothing else issue the next request.
6.in driver main the loop gets broken due to updation of the shared var.the driver main returns
  to the caller,ie fs.
7.that shared var should be part of the queue ds. ie struct req{...,...,var serviced,..};

NOTE 21:
	for atomic execution of a portion of code,
	cli();
	...
	...
	sti();
	
	b/w cli() & sti() dont include a code which may generate a interrupt;



	