Permalink
Browse files

PCI, mouse fixes

  • Loading branch information...
vialamo committed Mar 20, 2017
1 parent 11b0e26 commit f2d85c6595c828bb625cacbe92bb0f2641cadca3
Showing with 364 additions and 60 deletions.
  1. +1 −1 Makefile
  2. +2 −2 README.md
  3. +1 −1 qemu.bat
  4. +5 −2 source/Makefile
  5. +8 −0 source/hw86.h
  6. +73 −22 source/hw86.s
  7. +20 −8 source/kernel.c
  8. +1 −1 source/kernel.h
  9. +49 −20 source/net.c
  10. +123 −0 source/pci.c
  11. +77 −0 source/pci.h
  12. +4 −3 source/video.c
View
@@ -31,7 +31,7 @@ QEMU = qemu-system-i386
QEMUOPTS = -drive file=$(IMAGEDIR)os-fd.img,if=floppy,media=disk,format=raw \
-drive file=$(IMAGEDIR)os-hd.img,media=disk,format=raw \
-boot menu=on -serial mon:stdio -m 2 -vga std -monitor vc \
-net nic,model=ne2k_isa -net tap,ifname=tap
-net nic,model=ne2k_pci -net tap,ifname=tap
qemu: all
$(QEMU) $(QEMUOPTS)
View
@@ -16,7 +16,7 @@ System requirements:
A ne2000 compatible nic is required if the network module must be enabled.
##Building
The building process is expected to be executed in a Linux system. In Windows 10 it can be built using Windows Subsystem for Linux.
The building process is expected to be executed in a Linux system. In Windows 10 or greater it can be built using Windows Subsystem for Linux.
1. Install required software:
* make, gcc, bcc, nasm and ld86 to build the operating system and user programs
@@ -37,7 +37,7 @@ The building process is expected to be executed in a Linux system. In Windows 10
##Testing
After building, run `make qemu` (linux) or `qemu.bat` (windows) from the root directory to test the operating system in qemu. Other virtual machines have been successfully tested. To test the system using VirtualBox, create a new `Other/DOS` machine and start it with `images/os_fd.img` as floppy image.
The network system has been only tested in qemu under Windows, using the Tap-windows driver provided in https://openvpn.net/index.php/download/community-downloads.html. This virtual device must be renamed to `tap` and bridged to the actual nic in order to make the default `qemu.bat` script work as expected.
The network system has been only tested in qemu under Windows, using the Tap-windows driver provided [here](https://openvpn.net/index.php/download/community-downloads.html). This virtual device must be renamed to `tap` and bridged to the actual nic in order to make the default `qemu.bat` script work as expected.
If debug mode is activated in the operating system configuration, it will output debug information through the first serial port in real time. This can be useful for system and user application developers. This serial port is configured to work at 2400 bauds, 8 data bits, odd parity and 1 stop bit.
View
@@ -1 +1 @@
"c:\Program Files\qemu\qemu-system-i386" -drive file=images\os-fd.img,if=floppy,media=disk,format=raw -drive file=images\os-hd.img,media=disk,format=raw -boot menu=off -serial mon:stdio -m 2 -vga std -net nic,model=ne2k_isa -net tap,ifname=tap -monitor vc
"c:\Program Files\qemu\qemu-system-i386" -drive file=images\os-fd.img,if=floppy,media=disk,format=raw -drive file=images\os-hd.img,media=disk,format=raw -boot menu=on -serial mon:stdio -m 2 -vga std -net nic,model=ne2k_pci -net tap,ifname=tap -monitor vc
View
@@ -24,8 +24,8 @@ $(PROGDIR)%.bin: $(PROGDIR)%.c $(ULIBDIR)ulib.o $(ULIBDIR)x86.o
$(BOOTDIR)boot.bin: $(BOOTDIR)boot.s
$(NASM) -O0 -w+orphan-labels -f bin -o $@ $(BOOTDIR)boot.s
kernel.n16: load.o hw86.o kernel.o $(ULIBDIR)ulib.o $(ULIBDIR)x86.o fs.o video.o net.o
$(LD86) $(LDFLAGS) -o $@ load.o hw86.o kernel.o $(ULIBDIR)ulib.o $(ULIBDIR)x86.o fs.o video.o net.o
kernel.n16: load.o hw86.o kernel.o $(ULIBDIR)ulib.o $(ULIBDIR)x86.o fs.o video.o net.o pci.o
$(LD86) $(LDFLAGS) -o $@ load.o hw86.o kernel.o $(ULIBDIR)ulib.o $(ULIBDIR)x86.o fs.o video.o net.o pci.o
load.o: load.s
$(NASM) $(NFLAGS) -o $@ load.s
@@ -51,6 +51,9 @@ fs.o: fs.h fs.c types.h kernel.h $(ULIBDIR)ulib.h
net.o: net.h net.c
$(CC86) $(CFLAGS) -o $@ -c net.c
pci.o: pci.h pci.c
$(CC86) $(CFLAGS) -o $@ -c pci.c
clean:
@find . -name "*.o" -type f -delete
@find . -name "*.bin" -type f -delete
View
@@ -122,6 +122,14 @@ extern void outw(uint value, uint port);
* Read word from port
*/
extern uint inw(uint port);
/*
* Write long to port
*/
extern void outl(ul_t value, uint port);
/*
* Read long from port
*/
extern ul_t inl(uint port);
/*
* Power off system using APM
*/
View
@@ -6,7 +6,7 @@
;
; void dump_regs()
;
; Dump register values through debug output
;
global _dump_regs
_dump_regs:
@@ -181,7 +181,7 @@ _io_get_bios_font:
;
; void io_clear_screen()
; Clears the screen
; Clear the screen
;
global _io_clear_screen
_io_clear_screen:
@@ -422,7 +422,7 @@ _io_set_cursor_pos:
;
; uint io_in_key()
;
; Get key press
;
global _io_in_key
_io_in_key:
@@ -516,7 +516,7 @@ _get_time:
;
; uint read_disk_sector(uint disk, uint sector, uint n, uchar* buff)
;
; Read a disk sector
;
global _read_disk_sector
_read_disk_sector:
@@ -535,7 +535,7 @@ _read_disk_sector:
call disk_lba_to_hts
mov ah, 2 ; Params for int 13h: read disk sectors
mov ah, 2 ; Params for int 0x13: read disk sectors
mov al, [bx+22] ; Number of sectors to read
mov si, [bx+24] ; Set ES:BX to point the buffer
mov bx, ds
@@ -586,7 +586,7 @@ _read_disk_sector:
;
; void turn_off_floppy_motors()
; Since IRQ0 is overwritten, this must be done manually
; Since IRQ0 is used for timer, this must be done manually
;
global _turn_off_fd_motors
_turn_off_fd_motors:
@@ -604,7 +604,7 @@ _turn_off_fd_motors:
;
; uint write_disk_sector(uint disk, uint sector, uint n, uchar* buff)
;
; Write disk sector
;
global _write_disk_sector
_write_disk_sector:
@@ -623,7 +623,7 @@ _write_disk_sector:
call disk_lba_to_hts
mov ah, 3 ; Params for int 13h: write disk sectors
mov ah, 3 ; Params for int 0x13: write disk sectors
mov al, [bx+22] ; Number of sectors to read
mov si, [bx+24] ; Set ES:BX to point the buffer
mov bx, ds
@@ -674,8 +674,8 @@ disk_reset:
;
; disk_lba_to_hts -- Calculate head, track and sector for int 13h
; IN: logical sector in AX; OUT: correct registers for int 13h
; disk_lba_to_hts -- Calculate head, track and sector for int 0x13
; IN: logical sector in AX; OUT: correct registers for int 0x13
;
disk_lba_to_hts:
push bx
@@ -686,7 +686,7 @@ disk_lba_to_hts:
mov dx, 0 ; First the sector
div word [dsects] ; Sectors per track
add dl, 01 ; Physical sectors start at 1
mov cl, dl ; Sectors belong in CL for int 13h
mov cl, dl ; Sectors belong in CL for int 0x13
mov ax, bx
mov dx, 0 ; Now calculate the head
@@ -850,7 +850,7 @@ _inb:
;
; void outb(uint value, uint port)
; void outw(uint value, uint port)
; write word to port
;
global _outw
@@ -871,7 +871,7 @@ _outw:
;
; uint inb(uint port)
; uint inw(uint port)
; Read word from port
;
global _inw
@@ -889,6 +889,46 @@ _inw:
ret
;
; void outl(ul_t value, uint port)
; write long to port
;
global _outl
_outl:
push eax
push bx
push dx
mov bx, sp
mov eax, [bx+10]
mov dx, [bx+14]
out dx, eax
pop dx
pop bx
pop eax
ret
;
; ul_t inl(uint port)
; Read long from port
;
global _inl
_inl:
push bx
mov eax, 0
mov bx, sp
mov dx, [bx+4]
in eax, dx
mov edx, eax
shr edx, 16
pop bx
ret
;
; void apm_shutdown()
; Power off system using APM
@@ -1309,12 +1349,11 @@ IRQ12_handler:
extern _mouse_handler
;
; Handler for the IRQ9
; Handler for the net IRQ
; Used by network
;
IRQ9_handler:
IRQNET_handler:
pushad
call _enter_kernel
@@ -1438,7 +1477,7 @@ _install_mouse_IRQ_handler:
;
; void install_net_IRQ_handler()
; Add routine to interrupt vector table (IRQ9)
; Add routine to interrupt vector table
;
global _install_net_IRQ_handler
_install_net_IRQ_handler:
@@ -1447,16 +1486,27 @@ _install_net_IRQ_handler:
cli
; Install handler
mov bx, [_net_irq]
sub bl, 8
add bl, INT_CODE_SPIC_BASE
mov al, 4
mul bl
mov bx, ax
mov ax, 0
mov es, ax
mov dx, IRQ9_handler
mov [es:(INT_CODE_SPIC_BASE+1)*4], dx
mov dx, IRQNET_handler
mov [es:bx], dx
mov ax, cs
mov [es:(INT_CODE_SPIC_BASE+1)*4+2], ax
mov [es:bx+2], ax
; Set IRQ unmasked
mov cx, [_net_irq]
sub cl, 8
in al, PORT_SPIC_DATA
and al, 11111101b
mov bl, 1
shl bl, cl
not bl
and al, bl
out PORT_SPIC_DATA, al
sti
@@ -1465,6 +1515,7 @@ _install_net_IRQ_handler:
ret
extern _net_irq ; netword IRQ number, assumed > 8
;
; Install IRS
@@ -1580,7 +1631,7 @@ SYS_ISR:
iret
.result dw 0 ; Result of ISR
.arg0 dw 0
.arg0 dw 0 ; Args
.arg1 dw 0
.arg2 dw 0
.arg3 dw 0
Oops, something went wrong.

0 comments on commit f2d85c6

Please sign in to comment.