dWrite() function does not seem to write to port

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

dWrite() function does not seem to write to port

Post by kfreezen »

Hello,

I cannot seem to write anything to a port with the dWrite() function. Its code is as follows

Code: Select all

void dWrite(Device* d, uint val) {
	switch(d->portSize) {
		case 8 : dWritePort8 (d, val);
				 break;
		case 16: dWritePort16(d, val);
				 break;
		case 32: dWritePort32(d, val);
				 break;
		default: dWritePort8 (d, val); // Presume that the port is 8 bits // TODO: Print warning message
	};
}
dWritePort8(), dWritePort16(), and dWritePort32() are your basic outb, outw, and outl functions.

Code: Select all

void dWritePort8 (Device* d, uchar value) {
    asm volatile ("outb %1, %0" : : "dN" (d->outPort), "a" (value));
}
Thanks in advance.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: dWrite() function does not seem to write to port

Post by thepowersgang »

Have you put debug printf statements in it to check if the code receives the correct values?
I can't see any errors in the linked code (on a quick look)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: dWrite() function does not seem to write to port

Post by kfreezen »

I added one to dWrite(). everything is passed correctly to dWrite().
I don't know about dReadPort8() because, when I add a debug printf to that function, qemu crashes with the following error:

Code: Select all

qemu: fatal: Trying to execute code outside RAM or ROM at 0x8b66670c
Any ideas?
outb() seems to work, and it is identical to dWritePort8.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: dWrite() function does not seem to write to port

Post by thepowersgang »

Ok, you have some serious linker/compiler issues, I suggest you try to iron those out first.
Most likely that qemu error was caused by a bad jump somewhere in your code.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: dWrite() function does not seem to write to port

Post by kfreezen »

In that case, before, it was touchy. Now I can't even get the first line of my OS's output onto the screen
It freezes at the GRUB menu.
I will post the makefile and see if anyone can see what's wrong.

Code: Select all

FILES:=

PROGRAM:=occ
LIBRARIES:=libstd.a

CFLAGS:= -m32 -c -nostdinc -nostdlib -fno-stack-protector -Iincludes -Iincludes/stdlib
CC:=@gcc

ASFLAGS:= -felf
AS:=@nasm

OSPROJDIRS := main stdlib

OSCFILES := $(shell find $(OSPROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c")
OSASMFILES:= $(shell find $(OSPROJDIRS) -mindepth 1 -maxdepth 3 -name "*.s")
OSHDRFILES := $(shell find $(OSPROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h")

OSCOBJS:=$(patsubst %.c, %.o, $(OSCFILES))
OSASMOBJS:=$(patsubst %.s, %.o, $(OSASMFILES))

OBJFILES := $(OSASMOBJS) $(OSCOBJS)

all: kernel32.elf

kernel32.elf: $(OBJFILES)
	@echo $(OBJFILES)
	@ld -o $@ $(OBJFILES) -Tlink.ld -melf_i386
	@cp kernel32.elf /media/OSDEV_15/kernel32.elf
	@rm $(OBJFILES) kernel32.elf
	umount /media/OSDEV_15
I also had a piece of code reserving 16384 dword's in the text section of start.s.
It was getting past the GRUB boot menu at that point, but not far.
also of use may be my linker script.

Code: Select all



ENTRY(start)
SECTIONS
{
  .text 0x100000 :
  {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data :
  {
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
     . = ALIGN(4096);
  }

  .bss :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .; _end = .; __end = .;
} 
kfreezen
Member
Member
Posts: 46
Joined: Tue Jul 21, 2009 11:36 am

Re: dWrite() function does not seem to write to port

Post by kfreezen »

I have run into a problem with a function not writing to port before ( this isn't the first time ).
Is there anybody that's run into the same problem here?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: dWrite() function does not seem to write to port

Post by thepowersgang »

1. Don't double post
2. Your makefile looks ok.
3. I'd suggest running your kernel in the bochs debugger with instruction tracing turned on, that will help you find where your code is failing.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply