From: Christoffer Bubach Date: Sun, 11 Jan 2015 21:14:51 +0000 (+0100) Subject: More cleaning. Now runs error-free. IMG added to repo. X-Git-Url: https://git.wirehaze.ovh/BOS.git/commitdiff_plain/359bb65a0ed9dbb75a208db4675db689877a85b9?hp=9eee6999d9d27301b73f604c9978677c9794d717 More cleaning. Now runs error-free. IMG added to repo. --- diff --git a/bos.img b/bos.img new file mode 100755 index 0000000..113e9fe Binary files /dev/null and b/bos.img differ diff --git a/doc/bochsrc-osx.txt b/doc/bochsrc-osx.txt index 32aeabe..9ea686c 100644 --- a/doc/bochsrc-osx.txt +++ b/doc/bochsrc-osx.txt @@ -7,7 +7,7 @@ #display_library: term romimage: file=/usr/local/Cellar/bochs/2.6.2/share/bochs/BIOS-bochs-latest megs: 32 -vgaromimage: file=/usr/local/Cellar/bochs/2.6.2/share/bochs/VGABIOS-elpin-2.40 +vgaromimage: file=/usr/local/Cellar/bochs/2.6.2/share/bochs/VGABIOS-lgpl-latest floppya: 1_44=../bos.img, status=inserted boot: a floppy_bootsig_check: disabled=0 diff --git a/kernel/fdc/fdc.asm b/kernel/fdc/fdc.asm index 5048e43..ac3cf00 100755 --- a/kernel/fdc/fdc.asm +++ b/kernel/fdc/fdc.asm @@ -77,21 +77,21 @@ fdc_init: ; ; ;------------------------------------------------------; floppy_irq: - push ds - push eax - push ebx + push ds + push eax + push ebx - mov ax, 0x10 - mov ds, ax + mov ax, 0x10 + mov ds, ax - mov [fdd_int_done], 1 - mov al, 0x20 - out 0x20, al + mov [fdd_int_done], 1 + mov al, 0x20 + out 0x20, al - pop ebx - pop eax - pop ds - iret + pop ebx + pop eax + pop ds + iret @@ -128,18 +128,18 @@ wait_int: ; out: nothing ; ;------------------------------------------------------; fdd_off: - cmp [fdd_motor_on], 0 - je .end - push eax - push edx - - mov dx, 0x3F2 - mov al, 0x0c ; motor off - out dx, al - mov [fdd_motor_on], 0 - - pop edx - pop eax + cmp [fdd_motor_on], 0 + je .end + push eax + push edx + + mov dx, 0x3F2 + mov al, 0x0c ; motor off + out dx, al + mov [fdd_motor_on], 0 + + pop edx + pop eax .end: ret @@ -150,21 +150,21 @@ fdd_off: ; out: nothing ; ;------------------------------------------------------; fdd_on: - cmp [fdd_motor_on], 1 - je .end - push eax - push edx + cmp [fdd_motor_on], 1 + je .end + push eax + push edx - mov dx, 0x3F2 ; motor 0 on.. - mov al, 0x1C - out dx, al + mov dx, 0x3F2 ; motor 0 on.. + mov al, 0x1C + out dx, al - mov ecx, 20 ; 1/5 of a sec. to speed up - call delay ; in timer.inc - mov [fdd_motor_on], 1 + mov ecx, 20 ; 1/5 of a sec. to speed up + call delay ; in timer.inc + mov [fdd_motor_on], 1 - pop edx - pop eax + pop edx + pop eax .end: ret @@ -176,34 +176,34 @@ fdd_on: ; in: al = data byte ; ;------------------------------------------------------; fdc_sendbyte: - push edx - push ecx - push eax + push edx + push ecx + push eax - mov ecx, 50 ; 50 = 0.5 seconds. - call active_delay ; timer.inc + mov ecx, 50 ; 50 = 0.5 seconds. + call active_delay ; timer.inc .l1: - cmp dword [ecx], 0 ; timeup? - je .error - mov dx, 0x3f4 ; check status reg - in al, dx - and al, 0xC0 - cmp al, 0x80 ; ok to write? - jnz .l1 - - pop eax - pop ecx - mov dx, 0x3F5 ; send byte - out dx, al - pop edx - clc - ret + cmp dword [ecx], 0 ; timeup? + je .error + mov dx, 0x3f4 ; check status reg + in al, dx + and al, 0xC0 + cmp al, 0x80 ; ok to write? + jnz .l1 + + pop eax + pop ecx + mov dx, 0x3F5 ; send byte + out dx, al + pop edx + clc + ret .error: - pop eax - pop ecx - pop edx - stc - ret + pop eax + pop ecx + pop edx + stc + ret @@ -213,34 +213,34 @@ fdc_sendbyte: ; out: al = data byte ; ;------------------------------------------------------; fdc_getbyte: - push edx - push ecx - push eax + push edx + push ecx + push eax - mov ecx, 50 ; 50 = 0.5 seconds. - call active_delay ; timer.inc + mov ecx, 50 ; 50 = 0.5 seconds. + call active_delay ; timer.inc .l1: - cmp dword [ecx], 0 ; timeup? - je .error - mov dx, 0x3f4 ; check status reg - in al, dx - and al, 0xD0 - cmp al, 0xD0 ; ok to read? - jnz .l1 - - pop eax - pop ecx - mov dx, 0x3F5 ; get the byte - in al, dx - pop edx - clc - ret + cmp dword [ecx], 0 ; timeup? + je .error + mov dx, 0x3f4 ; check status reg + in al, dx + and al, 0xD0 + cmp al, 0xD0 ; ok to read? + jnz .l1 + + pop eax + pop ecx + mov dx, 0x3F5 ; get the byte + in al, dx + pop edx + clc + ret .error: - pop eax - pop ecx - pop edx - stc - ret + pop eax + pop ecx + pop edx + stc + ret @@ -249,20 +249,20 @@ fdc_getbyte: ; ; ;------------------------------------------------------; sensei: - push eax - - mov al, 0x08 ; fdc command - call fdc_sendbyte - call fdc_getbyte - mov ah, al ; save ST0 in ah - call fdc_getbyte ; read PCN - clc - test ah, 0x80 ; test for error: - jz .end ; "invalid command" - stc + push eax + + mov al, 0x08 ; fdc command + call fdc_sendbyte + call fdc_getbyte + mov ah, al ; save ST0 in ah + call fdc_getbyte ; read PCN + clc + test ah, 0x80 ; test for error: + jz .end ; "invalid command" + stc .end: - pop eax - ret + pop eax + ret @@ -271,57 +271,57 @@ sensei: ; ; ;------------------------------------------------------; fdd_reset: - push eax - push ecx - push edx + push eax + push ecx + push edx - mov byte [fdd_motor_on], 0 + mov byte [fdd_motor_on], 0 - mov dx, 0x3f2 - mov al, 8 ; off with all motors, - out dx, al ; dma,irq etc.. + mov dx, 0x3f2 + mov al, 8 ; off with all motors, + out dx, al ; dma,irq etc.. - mov ecx, 5 - call delay ; in timer.inc + mov ecx, 5 + call delay ; in timer.inc - mov dx, 0x3f7 - mov al, 0 - out dx, al ; work at 500 kbit/s + mov dx, 0x3f7 + mov al, 0 + out dx, al ; work at 500 kbit/s - mov dx, 0x3f2 - mov al, 0x0c - out dx, al ; reenable interrupts + mov dx, 0x3f2 + mov al, 0x0c + out dx, al ; reenable interrupts - mov [fdd_int_done], 0 - call wait_int ; wait for floppy int. - jc .error ; timeout? + mov [fdd_int_done], 0 + call wait_int ; wait for floppy int. + jc .error ; timeout? - mov cx, 0x04 + mov cx, 0x04 .status: ; 4 dummy-reads. - call sensei - loop .status - - mov al, 0x03 ; specify command - call fdc_sendbyte - mov al, 0xDF ; SRT, HUT - call fdc_sendbyte - mov al, 0x02 ; HLT, ND - call fdc_sendbyte - - mov al, 1 - call fdd_recal_seek - jc .error - call fdd_off - clc - jmp .end + call sensei + loop .status + + mov al, 0x03 ; specify command + call fdc_sendbyte + mov al, 0xDF ; SRT, HUT + call fdc_sendbyte + mov al, 0x02 ; HLT, ND + call fdc_sendbyte + + mov al, 1 + call fdd_recal_seek + jc .error + call fdd_off + clc + jmp .end .error: - call fdd_off - stc + call fdd_off + stc .end: - pop edx - pop ecx - pop eax - ret + pop edx + pop ecx + pop eax + ret @@ -335,38 +335,38 @@ fdd_reset: ; ; ;------------------------------------------------------; fdd_recal_seek: - push eax - - call fdd_on ; turn motor on - cmp al, 0 - jne .recalibrate - clc - cmp bl, [result_C] ; are we there yet? :D - je .ok - mov al, 0x0F ; seek command - call fdc_sendbyte - mov al, bh ; ((head*4)|drive) - call fdc_sendbyte - mov al, bl ; track - call fdc_sendbyte - mov [result_C], bl ; now on..? - jmp .get_int + push eax + + call fdd_on ; turn motor on + cmp al, 0 + jne .recalibrate + clc + cmp bl, [result_C] ; are we there yet? :D + je .ok + mov al, 0x0F ; seek command + call fdc_sendbyte + mov al, bh ; ((head*4)|drive) + call fdc_sendbyte + mov al, bl ; track + call fdc_sendbyte + mov [result_C], bl ; now on..? + jmp .get_int .recalibrate: - mov al, 0x07 ; recalibrate command - call fdc_sendbyte - mov al, 0 ; drive number - call fdc_sendbyte - mov [result_C], 0 ; now on track 0 + mov al, 0x07 ; recalibrate command + call fdc_sendbyte + mov al, 0 ; drive number + call fdc_sendbyte + mov [result_C], 0 ; now on track 0 .get_int: - mov [fdd_int_done], 0 - call wait_int - jc .error + mov [fdd_int_done], 0 + call wait_int + jc .error - call sensei ; sense interrupt status - jc .error + call sensei ; sense interrupt status + jc .error .ok: - clc - jmp .end + clc + jmp .end .error: stc .end: @@ -387,136 +387,136 @@ fdd_recal_seek: ; cf = 0 if ok, 1 if error ; ;------------------------------------------------------; fdd_read_write: - pushad - - and dh, 1 ; head 0 or 1? - mov [fdd_head], dh ; store it. - shl dh, 2 - or dh, 0 ; drive 0, fd0 - mov [fdd_drivehead], dh ; dh = ((head*4)|drive) - mov [fdd_errorcode], 0x04 ; basic error code - cmp ch, 0x51 ; check for allowed - jae .error ; track number. - mov [fdd_track], ch - cmp cl, 0x13 ; check for allowed - jae .error ; sector number. - mov [fdd_sector], cl - - cmp [fdd_error], 1 - jne .no_previous_error - mov al, 1 - call fdd_recal_seek + pushad + + and dh, 1 ; head 0 or 1? + mov [fdd_head], dh ; store it. + shl dh, 2 + or dh, 0 ; drive 0, fd0 + mov [fdd_drivehead], dh ; dh = ((head*4)|drive) + mov [fdd_errorcode], 0x04 ; basic error code + cmp ch, 0x51 ; check for allowed + jae .error ; track number. + mov [fdd_track], ch + cmp cl, 0x13 ; check for allowed + jae .error ; sector number. + mov [fdd_sector], cl + + cmp [fdd_error], 1 + jne .no_previous_error + mov al, 1 + call fdd_recal_seek .no_previous_error: - call fdd_on + call fdd_on - mov dx, 0x3F7 - mov al, 0 ; 500Kb/sec mode - out dx, al - mov [fdd_errorcode], 0x80 ; error code + mov dx, 0x3F7 + mov al, 0 ; 500Kb/sec mode + out dx, al + mov [fdd_errorcode], 0x80 ; error code - xor ecx, ecx - mov cx, 3 ; try seek 3 times + xor ecx, ecx + mov cx, 3 ; try seek 3 times .l2: - mov al, 0 - push ebx - mov bl, [fdd_track] - mov bh, [fdd_drivehead] ; ((head*4)|drive) - call fdd_recal_seek - pop ebx - jnc .l3 ; ok, continue. - loop .l2 - jmp .error ; timeout. + mov al, 0 + push ebx + mov bl, [fdd_track] + mov bh, [fdd_drivehead] ; ((head*4)|drive) + call fdd_recal_seek + pop ebx + jnc .l3 ; ok, continue. + loop .l2 + jmp .error ; timeout. .l3: - push ebx - cmp bl, 0 - je .read_fdd + push ebx + cmp bl, 0 + je .read_fdd .write_fdd: - push edi - mov esi, edi - mov edi, 0x80000 ; copy the stuff we will - mov ecx, 128 ; write to the DMA buffer - rep movsd ; 128*4=512 - pop edi - - mov bl, 2 ; channel 2 - mov esi, 512 ; bytes to write - mov ecx, 0x80000 ; page & offset - mov bh, 1 ; write floppy, read DMA - call dma_transfer - - mov al, 0xC5 ; write sector command - call fdc_sendbyte - jmp .cont + push edi + mov esi, edi + mov edi, 0x80000 ; copy the stuff we will + mov ecx, 128 ; write to the DMA buffer + rep movsd ; 128*4=512 + pop edi + + mov bl, 2 ; channel 2 + mov esi, 512 ; bytes to write + mov ecx, 0x80000 ; page & offset + mov bh, 1 ; write floppy, read DMA + call dma_transfer + + mov al, 0xC5 ; write sector command + call fdc_sendbyte + jmp .cont .read_fdd: - mov bl, 2 ; channel 2 - mov esi, 512 ; bytes to read - mov ecx, 0x80000 ; page & offset - mov bh, 0 ; read floppy, write DMA - call dma_transfer + mov bl, 2 ; channel 2 + mov esi, 512 ; bytes to read + mov ecx, 0x80000 ; page & offset + mov bh, 0 ; read floppy, write DMA + call dma_transfer - mov al, 0xE6 ; read sector command - call fdc_sendbyte + mov al, 0xE6 ; read sector command + call fdc_sendbyte .cont: - pop ebx - mov al, [fdd_drivehead] ; ((head*4)|drive) - call fdc_sendbyte - mov al, [fdd_track] ; track/cylinder - call fdc_sendbyte - - mov al, [fdd_head] ; head/side 0 or 1 - call fdc_sendbyte - mov al, [fdd_sector] ; sector number - call fdc_sendbyte - mov al, 0x02 ; sector size, 512 bytes - call fdc_sendbyte - - mov al, 0x12 ; sectors to a track - call fdc_sendbyte - mov al, 0x1B ; gap length - call fdc_sendbyte - mov al, 0xFF ; data length - call fdc_sendbyte - - mov [fdd_int_done], 0 - call wait_int - jc .error - - call fdc_getbyte - mov [result_ST0], al ; ST0 - call fdc_getbyte - mov [result_ST1], al ; ST1 - call fdc_getbyte - mov [result_ST2], al ; ST2 - call fdc_getbyte - mov [result_C], al ; cylinder - call fdc_getbyte - mov [result_H], al ; head - call fdc_getbyte - mov [result_R], al ; sector number. - call fdc_getbyte - mov [result_N], al ; sector size - - test [result_ST0], 0xc0 ; test if sr0 is 0xC0 - jnz .error - cmp bl, 1 ; did we write the disk? - je .ok - - mov ecx, 512 ; sector size in bytes - mov esi, 0x80000 ; copy to dest. in edi - rep movsb + pop ebx + mov al, [fdd_drivehead] ; ((head*4)|drive) + call fdc_sendbyte + mov al, [fdd_track] ; track/cylinder + call fdc_sendbyte + + mov al, [fdd_head] ; head/side 0 or 1 + call fdc_sendbyte + mov al, [fdd_sector] ; sector number + call fdc_sendbyte + mov al, 0x02 ; sector size, 512 bytes + call fdc_sendbyte + + mov al, 0x12 ; sectors to a track + call fdc_sendbyte + mov al, 0x1B ; gap length + call fdc_sendbyte + mov al, 0xFF ; data length + call fdc_sendbyte + + mov [fdd_int_done], 0 + call wait_int + jc .error + + call fdc_getbyte + mov [result_ST0], al ; ST0 + call fdc_getbyte + mov [result_ST1], al ; ST1 + call fdc_getbyte + mov [result_ST2], al ; ST2 + call fdc_getbyte + mov [result_C], al ; cylinder + call fdc_getbyte + mov [result_H], al ; head + call fdc_getbyte + mov [result_R], al ; sector number. + call fdc_getbyte + mov [result_N], al ; sector size + + test [result_ST0], 0xc0 ; test if sr0 is 0xC0 + jnz .error + cmp bl, 1 ; did we write the disk? + je .ok + + mov ecx, 512 ; sector size in bytes + mov esi, 0x80000 ; copy to dest. in edi + rep movsb .ok: - mov [fdd_errorcode], 0 ; no error.. :D - mov [fdd_error], 0 ; no recal. next time - clc - jmp .end + mov [fdd_errorcode], 0 ; no error.. :D + mov [fdd_error], 0 ; no recal. next time + clc + jmp .end .error: - mov [fdd_error], 1 ; recalibrate next time - stc + mov [fdd_error], 1 ; recalibrate next time + stc .end: - call fdd_off ; floppy motor off - popad - mov al, [fdd_errorcode] ; error status - ret \ No newline at end of file + call fdd_off ; floppy motor off + popad + mov al, [fdd_errorcode] ; error status + ret \ No newline at end of file diff --git a/kernel/init/bios.asm b/kernel/init/bios.asm index ed5716d..8ecad9f 100755 --- a/kernel/init/bios.asm +++ b/kernel/init/bios.asm @@ -8,100 +8,99 @@ rmode_int: - pushad - push eax - shr eax, 16 ; move high bits to ax - mov word [realmode_ax], ax ; save new ax value - pop eax ; restore - - push ebx - shr ebx, 16 ; move high bits to bx - mov byte [int_number], bl ; save int number to call - pop ebx - - mov byte [realmode_error], 0 ; all variables is in the - mov word [realmode_bx], bx ; realmode/variables.inc file - mov word [realmode_cx], cx - mov word [realmode_dx], dx - call disable_irqs - jmp pword 0x18:do_16pmode ; must substract 0x10000 from - ; data addresses becasue of - ; fasm strict "org" behavior + pushad + push eax + shr eax, 16 ; move high bits to ax + mov word [realmode_ax], ax ; save new ax value + pop eax ; restore + + push ebx + shr ebx, 16 ; move high bits to bx + mov byte [int_number], bl ; save int number to call + pop ebx + + mov byte [realmode_error], 0 ; all variables is in the + mov word [realmode_bx], bx ; realmode/variables.inc file + mov word [realmode_cx], cx + mov word [realmode_dx], dx + call disable_irqs + jmp pword 0x18:do_16pmode ; begin our dark journey into 16bit-land + use16 do_16pmode: - mov ax, 0x20 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax + mov ax, 0x20 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax - cli - mov eax, cr0 - and al, 0xFE - mov cr0, eax + cli + mov eax, cr0 + and al, 0xFE + mov cr0, eax - jmp 0x1000:(do_realm) + jmp 0x0000:(do_realm) ; this should be triple checked! do_realm: - mov ax, cs - mov ds, ax + mov ax, cs + mov ds, ax - xor ax, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax + xor ax, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax - lidt [ridtr] ; realmode/variables.inc - sti + lidt [ridtr] ; realmode/variables.inc + sti - mov ax, word [realmode_ax] - mov bx, word [realmode_bx] - mov cx, word [realmode_cx] - mov dx, word [realmode_dx] + mov ax, word [realmode_ax] + mov bx, word [realmode_bx] + mov cx, word [realmode_cx] + mov dx, word [realmode_dx] - push ax ; this is some cool shit.. ;) - mov al, [int_number] ; interrupt to preform - mov [$+5], al ; move it to right pos. - pop ax - db 0xCD ; opcode for int. - db 0x00 ; move int_number here + push ax ; this is some cool shit.. ;) + mov al, [int_number] ; interrupt to preform + mov [$+5], al ; move it to right pos. + pop ax + db 0xCD ; opcode for int. + db 0x00 ; move int_number here - jnc .no_error - mov byte [realmode_error], 1 + jnc .no_error + mov byte [realmode_error], 1 - .no_error: - mov word [realmode_ax], ax - mov word [realmode_bx], bx - mov word [realmode_cx], cx - mov word [realmode_dx], dx + .no_error: + mov word [realmode_ax], ax + mov word [realmode_bx], bx + mov word [realmode_cx], cx + mov word [realmode_dx], dx - cli + cli - lgdt [gdtr] - lidt [idtr] - mov eax, cr0 - or al, 1 - mov cr0, eax + lgdt [gdtr] + lidt [idtr] + mov eax, cr0 + or al, 1 + mov cr0, eax - jmp pword 0x08:gobackto_pm + jmp pword 0x08:gobackto_pm use32 gobackto_pm: - mov ax, 0x10 ; refresh all segment registers - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - call enable_irqs - sti - popad - clc ; clear carry. - cmp [realmode_error], 1 ; if error, then - jne .end - stc ; set carry. - .end: - ret \ No newline at end of file + mov ax, 0x10 ; refresh all segment registers + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + call enable_irqs + sti + popad + clc ; clear carry. + cmp [realmode_error], 1 ; if error, then + jne .end + stc ; set carry. + .end: + ret \ No newline at end of file diff --git a/kernel/init/cmos.asm b/kernel/init/cmos.asm index 032a95c..b047c86 100755 --- a/kernel/init/cmos.asm +++ b/kernel/init/cmos.asm @@ -10,58 +10,58 @@ ;-----------------------------------; ; variables containing CMOS data ; ;-----------------------------------; - century db 0 ; latest century, - year db 0 ; year, - month db 0 ; month, - day db 0 ; day (1 = sunday), - hour db 0 ; hour, - minute db 0 ; minute and - second db 0 ; second read in from CMOS. + century db 0 ; latest century, + year db 0 ; year, + month db 0 ; month, + day db 0 ; day (1 = sunday), + hour db 0 ; hour, + minute db 0 ; minute and + second db 0 ; second read in from CMOS. ;-------------------------; ; save info from CMOS ; ;-------------------------; get_cmos_data: - push ax + push ax - mov al, 0x00 ; get the "second" byte - out 0x70, al - in al, 0x71 - mov [second], al ; save it. + mov al, 0x00 ; get the "second" byte + out 0x70, al + in al, 0x71 + mov [second], al ; save it. - mov al, 0x02 ; get the "minute" byte - out 0x70, al - in al, 0x71 - mov [minute], al + mov al, 0x02 ; get the "minute" byte + out 0x70, al + in al, 0x71 + mov [minute], al - mov al, 0x04 ; get the "hour" byte - out 0x70, al - in al, 0x71 - mov [hour], al + mov al, 0x04 ; get the "hour" byte + out 0x70, al + in al, 0x71 + mov [hour], al - mov al, 0x07 ; get the "day" byte - out 0x70, al - in al, 0x71 - mov [day], al + mov al, 0x07 ; get the "day" byte + out 0x70, al + in al, 0x71 + mov [day], al - mov al, 0x08 ; get the "month" byte - out 0x70, al - in al, 0x71 - mov [month], al + mov al, 0x08 ; get the "month" byte + out 0x70, al + in al, 0x71 + mov [month], al - mov al, 0x09 ; get the "year" byte - out 0x70, al - in al, 0x71 - mov [year], al + mov al, 0x09 ; get the "year" byte + out 0x70, al + in al, 0x71 + mov [year], al - mov al, 0x32 ; get the "century" byte - out 0x70, al - in al, 0x71 - mov [century], al + mov al, 0x32 ; get the "century" byte + out 0x70, al + in al, 0x71 + mov [century], al - pop ax - ret + pop ax + ret ;------------------------------------------------; ; calculate binary from BCD ; @@ -69,15 +69,15 @@ get_cmos_data: ; out: al = bin ; ;------------------------------------------------; BCD2bin: - push ebx - mov bl, al ; bl = al mod 16 - and bl, 0x0F - shr al, 4 ; al = al / 16 - mov bh, 10 - mul bh ; multiply by 10 - add al, bl ; add in low nib - pop ebx - ret + push ebx + mov bl, al ; bl = al mod 16 + and bl, 0x0F + shr al, 4 ; al = al / 16 + mov bh, 10 + mul bh ; multiply by 10 + add al, bl ; add in low nib + pop ebx + ret ;------------------------------------------------; @@ -86,11 +86,11 @@ BCD2bin: ; out: ax = ASCII ; ;------------------------------------------------; BCD2ascii: - push ecx - mov ah, al - and ax, 0xF00F ; mask bits - shr ah, 4 ; right shift ah to get unpacked BCD - or ax, 0x3030 ; combine with 30 to get ASCII - xchg ah, al ; swap for ASCII storage convention - pop ecx - ret \ No newline at end of file + push ecx + mov ah, al + and ax, 0xF00F ; mask bits + shr ah, 4 ; right shift ah to get unpacked BCD + or ax, 0x3030 ; combine with 30 to get ASCII + xchg ah, al ; swap for ASCII storage convention + pop ecx + ret \ No newline at end of file diff --git a/kernel/init/init32b.asm b/kernel/init/init32b.asm index 01bb358..3d2319e 100755 --- a/kernel/init/init32b.asm +++ b/kernel/init/init32b.asm @@ -62,7 +62,7 @@ bos_init: ;--------------; ; setup IDT ; ;--------------; - mov edi, u_isr ; isr.inc + mov esi, u_isr ; isr.inc call init_idt ; idt.inc mov esi, idt_list ; idt.inc call set_idt_list ; idt.inc diff --git a/kernel/init/pic.asm b/kernel/init/pic.asm index 6076213..9e6bb61 100755 --- a/kernel/init/pic.asm +++ b/kernel/init/pic.asm @@ -8,128 +8,131 @@ ;-------------------------------------------; -; remap PICs to: cl = pic1 ch = pic2 ; +; remap PICs ; +; in: cl = pic1 ; +; ch = pic2 ; ;-------------------------------------------; remap_pics: - push ax - push dx + push ax + push dx - mov al, 0x11 ; IWC1 - out 0x20, al - out 0xA0, al + mov al, 0x11 ; IWC1 + out 0x20, al + out 0xA0, al - mov al, cl ; IWC2 - out 0x21, al - mov al, ch - out 0xA1, al + mov al, cl ; IWC2 + out 0x21, al + mov al, ch + out 0xA1, al - mov al, 0x04 ; IWC3 - out 0x21, al - mov al, 0x02 - out 0xA1, al + mov al, 0x04 ; IWC3 + out 0x21, al + mov al, 0x02 + out 0xA1, al - mov al, 0x01 ; IWC4 - out 0x21, al - out 0xA1, al + mov al, 0x01 ; IWC4 + out 0x21, al + out 0xA1, al - pop dx - pop ax - ret + pop dx + pop ax + ret ;----------------------; ; disable all IRQs. ; ;----------------------; disable_irqs: - push ax + push ax - mov al, 0xFF - out 0x21, al - out 0xA1, al + mov al, 0xFF + out 0x21, al + out 0xA1, al - pop ax - ret + pop ax + ret ;---------------------; ; enable all IRQs. ; ;---------------------; enable_irqs: - push ax + push ax - mov al, 0x00 - out 0x21, al - out 0xA1, al + mov al, 0x00 + out 0x21, al + out 0xA1, al - pop ax - ret + pop ax + ret ;-----------------------------; ; enable an IRQ. cl = irq ; ;-----------------------------; enable_irq: - push ax - push cx + push ax + push cx - cmp cl, 8 - jb .master + cmp cl, 8 + jb .master - sub cl, 8 - mov ah, 1 - shl ah, cl - xor ah, 0xFF + sub cl, 8 + mov ah, 1 + shl ah, cl + xor ah, 0xFF - in al, 0xA1 - and al, ah - out 0xA1, al + in al, 0xA1 + and al, ah + out 0xA1, al - pop cx - pop ax - ret - .master: - mov ah, 1 - shl ah, cl - xor ah, 0xFF + pop cx + pop ax + ret + .master: + mov ah, 1 + shl ah, cl + xor ah, 0xFF - in al, 0x21 - and al, ah - out 0x21, al + in al, 0x21 + and al, ah + out 0x21, al - pop cx - pop ax - ret + pop cx + pop ax + ret ;------------------------------; -; disable an IRQ. cl = irq ; +; disable an IRQ. ; +; in: cl = irq ; ;------------------------------; disable_irq: - push ax - push cx - - cmp cl, 8 - jb .master - - sub cl, 8 - mov ah, 1 - shl ah, cl - - in al, 0xA1 - or al, ah - out 0xA1, al - - pop cx - pop ax - ret - .master: - mov ah, 1 - shl ah, cl - - in al, 0x21 - or al, ah - out 0x21, al - - pop cx - pop ax - ret \ No newline at end of file + push ax + push cx + + cmp cl, 8 + jb .master + + sub cl, 8 + mov ah, 1 + shl ah, cl + + in al, 0xA1 + or al, ah + out 0xA1, al + + pop cx + pop ax + ret + .master: + mov ah, 1 + shl ah, cl + + in al, 0x21 + or al, ah + out 0x21, al + + pop cx + pop ax + ret \ No newline at end of file diff --git a/kernel/init/timer.asm b/kernel/init/timer.asm index 29088eb..aa2a335 100755 --- a/kernel/init/timer.asm +++ b/kernel/init/timer.asm @@ -9,47 +9,47 @@ ;-----------------; ; variables ; ;-----------------; - timer_wait dd 0 ; time to wait - timer_counter dd 0, 0 ; time since BOS started - call_list dd 0, 0, 0, 0, 0 ; functions to call + timer_wait dd 0 ; time to wait + timer_counter dd 0, 0 ; time since BOS started + call_list dd 0, 0, 0, 0, 0 ; functions to call ;---------------------------; ; Timer IRQ(0) ; ;---------------------------; timer: - add dword [timer_counter], 1 ; it's just a 64-bit - adc dword [timer_counter+4], 0 ; counter since boot. - - cmp [timer_wait], 0 ; "delay" countdown. - je .test1 - dec [timer_wait] - - .test1: ; checks for calls to - cmp [call_list], dword 0 ; do before we quit. - je .test2 - call dword [call_list] - .test2: - cmp [call_list+4], dword 0 - je .test3 - call dword [call_list+4] - .test3: - cmp [call_list+8], dword 0 - je .test4 - call dword [call_list+8] - .test4: - cmp [call_list+12], dword 0 - je .test5 - call dword [call_list+12] - .test5: - cmp [call_list+16], dword 0 - je .end - call dword [call_list+16] - - .end: - mov al, 0x20 - out 0x20, al - ret + add dword [timer_counter], 1 ; it's just a 64-bit + adc dword [timer_counter+4], 0 ; counter since boot. + + cmp [timer_wait], 0 ; "delay" countdown. + je .test1 + dec [timer_wait] + + .test1: ; checks for calls to + cmp [call_list], dword 0 ; do before we quit. + je .test2 + call dword [call_list] + .test2: + cmp [call_list+4], dword 0 + je .test3 + call dword [call_list+4] + .test3: + cmp [call_list+8], dword 0 + je .test4 + call dword [call_list+8] + .test4: + cmp [call_list+12], dword 0 + je .test5 + call dword [call_list+12] + .test5: + cmp [call_list+16], dword 0 + je .end + call dword [call_list+16] + + .end: + mov al, 0x20 + out 0x20, al + ret @@ -59,35 +59,35 @@ timer: ; out: eax = 0 if OK ; ;------------------------------------------------; add_timercall: - cmp [call_list], 0 - jne .test2 - mov [call_list], ebx - jmp .end - .error: - mov eax, 1 - ret - .test2: - cmp [call_list+4], 0 ; since i am so lazy - jne .test3 ; and a loop can be - mov [call_list+4], ebx ; rather complicated - jmp .end ; for this stuff, i - .test3: ; check for each one.. - cmp [call_list+8], 0 ; after all, it's only 5. - jne .test4 - mov [call_list+8], ebx - jmp .end - .test4: - cmp [call_list+12], 0 - jne .test5 - mov [call_list+12], ebx - jmp .end - .test5: - cmp [call_list+16], 0 - jne .error - mov [call_list+16], ebx - .end: - xor eax, eax - ret + cmp [call_list], 0 + jne .test2 + mov [call_list], ebx + jmp .end + .error: + mov eax, 1 + ret + .test2: + cmp [call_list+4], 0 ; since i am so lazy + jne .test3 ; and a loop can be + mov [call_list+4], ebx ; rather complicated + jmp .end ; for this stuff, i + .test3: ; check for each one.. + cmp [call_list+8], 0 ; after all, it's only 5. + jne .test4 + mov [call_list+8], ebx + jmp .end + .test4: + cmp [call_list+12], 0 + jne .test5 + mov [call_list+12], ebx + jmp .end + .test5: + cmp [call_list+16], 0 + jne .error + mov [call_list+16], ebx + .end: + xor eax, eax + ret @@ -97,35 +97,35 @@ add_timercall: ; out: eax = 0 if OK ; ;-------------------------------------------------; remove_timercall: - cmp [call_list], ebx - jne .test2 - mov [call_list], dword 0 - jmp .end - .error: - mov eax, 1 - ret - .test2: - cmp [call_list+4], ebx - jne .test3 - mov [call_list+4], dword 0 - jmp .end - .test3: - cmp [call_list+8], ebx - jne .test4 - mov [call_list+8], dword 0 - jmp .end - .test4: - cmp [call_list+12], ebx - jne .test5 - mov [call_list+12], dword 0 - jmp .end - .test5: - cmp [call_list+16], ebx - jne .error - mov [call_list+16], dword 0 - .end: - xor eax, eax - ret + cmp [call_list], ebx + jne .test2 + mov [call_list], dword 0 + jmp .end + .error: + mov eax, 1 + ret + .test2: + cmp [call_list+4], ebx + jne .test3 + mov [call_list+4], dword 0 + jmp .end + .test3: + cmp [call_list+8], ebx + jne .test4 + mov [call_list+8], dword 0 + jmp .end + .test4: + cmp [call_list+12], ebx + jne .test5 + mov [call_list+12], dword 0 + jmp .end + .test5: + cmp [call_list+16], ebx + jne .error + mov [call_list+16], dword 0 + .end: + xor eax, eax + ret @@ -135,11 +135,11 @@ remove_timercall: ; out: nothing ; ;--------------------------------------------; delay: - mov [timer_wait], ecx ; mov value to "timer" - .loop: - cmp [timer_wait], 0 - jne .loop - ret + mov [timer_wait], ecx ; mov value to "timer" + .loop: + cmp [timer_wait], 0 + jne .loop + ret @@ -153,9 +153,9 @@ delay: ; out: ecx = pointer to counter ; ;--------------------------------------------; active_delay: - mov [timer_wait], ecx ; mov value to "timer" - mov ecx, timer_wait ; let caller check value - ret + mov [timer_wait], ecx ; mov value to "timer" + mov ecx, timer_wait ; let caller check value + ret @@ -163,12 +163,12 @@ active_delay: ; set PIT to 100Hz ; ;------------------------------; set_pit_freq: - push eax - mov al, 0x34 ; set to 100Hz, 0x34 = 00110100b - out 0x43, al - mov al, 0x9B ; lsb 1193180 / 1193 - out 0x40, al - mov al, 0x2E ; msb - out 0x40, al - pop eax - ret \ No newline at end of file + push eax + mov al, 0x34 ; set to 100Hz, 0x34 = 00110100b + out 0x43, al + mov al, 0x9B ; lsb 1193180 / 1193 + out 0x40, al + mov al, 0x2E ; msb + out 0x40, al + pop eax + ret \ No newline at end of file diff --git a/kernel/int/idt.asm b/kernel/int/idt.asm index 5b4a8d8..c6b2841 100644 --- a/kernel/int/idt.asm +++ b/kernel/int/idt.asm @@ -1,11 +1,25 @@ ;----------------------------------------------------------; -; BOS kernel Christoffer Bubach, 2003-2005. ; +; BOS kernel Christoffer Bubach, 2003-2015. ; ;----------------------------------------------------------; ; ; -; set/modify IDT entries ; +; Set/modify IDT entries ; ; ; ;----------------------------------------------------------; +;-----------------------------------------------------; +; ; +; IDT entry structure ; +; ; +; 16bit - entry offset bits 0..15 ; +; 16bit - code segment selector in GDT or LDT ; +; 8bit - unused, set to 0 ; +; 8bit - type and attributes ; +; - 0xE = 32bit intterrupt ; +; - 0x8 = Present bit = 1 ; +; 16bit - entry offset bits 16..31 ; +; ; +; middle section for code segment 08 = 0x8E000008 ; +;-----------------------------------------------------; ;--------------------------------------------------; @@ -15,24 +29,29 @@ init_idt: push eax push ecx + push edi + xor edi, edi xor ecx, ecx - .l1: - mov eax, esi ; loop full IDT and - mov [(0x6c00+ecx)], ax ; set to one ISR - add ecx, 2 + add edi, [idtr.address] + .l1: ; loop full IDT table + mov eax, esi + mov word [edi], ax ; set handler lower offset + add edi, 2 - mov dword [(0x6c00+ecx)], 0x8E000008 ; 0x6c00 is where - add ecx, 4 ; we put the IDT + mov dword [edi], 0x8E000008 ; set IDT segment and attributes + add edi, 4 mov eax, esi shr eax, 16 - mov [(0x6c00+ecx)], ax - add ecx, 2 + mov word [edi], ax ; set handler high offset + add edi, 2 - cmp ecx, 0x800 ; 256 ints - jb .l1 ; * 8 bytes each + add cx, 8 ; 8byte * + cmp cx, word [idtr.size] ; 256 ints + jb .l1 ; = done? + pop edi pop ecx pop eax ret @@ -45,30 +64,30 @@ init_idt: ; edi = int function pointer ; ;--------------------------------------; set_int: - push eax - push ecx + push eax + push ecx - mov al, 8 ; 8 bytes for each int - mul cl ; cl * al = ax - movzx ecx, ax ; ecx = IDT offset - shr ecx, 1 ; 1/2 for dword list - mov dword [(idt_list+ecx)], edi ; add to dword int list - movzx ecx, ax ; ecx = IDT offset + mov al, 8 ; 8 bytes for each int + mul cl ; cl * al = ax + movzx ecx, ax ; ecx = IDT offset + shr ecx, 1 ; 1/2 for dword list + mov dword [(idt_list+ecx)], edi ; add to dword int list + movzx ecx, ax ; ecx = IDT offset - mov eax, edi - mov [(0x6c00+ecx)], ax - add ecx, 2 + mov eax, edi + mov [(0x6c00+ecx)], ax + add ecx, 2 - mov dword [(0x6c00+ecx)], 0x8E000008 - add ecx, 4 + mov dword [(0x6c00+ecx)], 0x8E000008 + add ecx, 4 - mov eax, edi - shr eax, 16 - mov [(0x6c00+ecx)], ax + mov eax, edi + shr eax, 16 + mov [(0x6c00+ecx)], ax - pop ecx - pop eax - ret + pop ecx + pop eax + ret @@ -78,15 +97,15 @@ set_int: ; out: esi = address or 0 if none present ; ;------------------------------------------------; get_int: - push eax + push eax - mov eax, 4 ; 4 bytes for each address - mul cl ; cl * al = ax - mov esi, idt_list - add esi, eax + mov eax, 4 ; 4 bytes for each address + mul cl ; cl * al = ax + mov esi, idt_list + add esi, eax - pop eax - ret + pop eax + ret @@ -96,24 +115,24 @@ get_int: ; in: esi = pointer to int list ; ;----------------------------------------; set_idt_list: - push eax - push edi - - xor ecx, ecx - .l1: - lodsd - or eax, eax - jz .next - mov edi, eax - call set_int - .next: - inc ecx - cmp ecx, 0x100 - jb .l1 - - pop edi - pop eax - ret + push eax + push edi + + xor ecx, ecx + .l1: + lodsd + or eax, eax + jz .next + mov edi, eax + call set_int + .next: + inc ecx + cmp ecx, 0x100 + jb .l1 + + pop edi + pop eax + ret diff --git a/kernel/kernel.sys b/kernel/kernel.sys index b8bafea..eaa01f5 100755 Binary files a/kernel/kernel.sys and b/kernel/kernel.sys differ