Page 1 of 1
dWrite() function does not seem to write to port
Posted: Tue Jul 06, 2010 6:10 pm
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.
Re: dWrite() function does not seem to write to port
Posted: Tue Jul 06, 2010 7:23 pm
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)
Re: dWrite() function does not seem to write to port
Posted: Tue Jul 06, 2010 11:33 pm
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.
Re: dWrite() function does not seem to write to port
Posted: Wed Jul 07, 2010 4:29 am
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.
Re: dWrite() function does not seem to write to port
Posted: Wed Jul 07, 2010 11:22 am
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 = .;
}
Re: dWrite() function does not seem to write to port
Posted: Wed Jul 07, 2010 4:42 pm
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?
Re: dWrite() function does not seem to write to port
Posted: Wed Jul 07, 2010 9:32 pm
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.