Code:
int init_com1(int rate)
{
short *_coms = ((short *)0x400);
short _com1 = _coms[0];
if(_com1 == 0)
{
// There is no COM1 for us, Report this
return 2;
}
uint8_t LOW_RATE = (uint8_t)((115200 / rate) & 0xFF);
uint8_t HIGH_RATE = (uint8_t)((115200 / rate) >> 8);
outb(_com1 + 1, 0x00);
outb(_com1 + 2, 0x04);
outb(_com1 + 3, 0x80);
outb(_com1 + 0, LOW_RATE);
outb(_com1 + 0, HIGH_RATE);
outb(_com1 + 3, 0x08 | 0x00 | 0x00); // Which is ineffective (the result is still 8), compiler will optimize it
outb(_com1 + 2, 1 | 4 | 0);
outb(_com1 + 4, (1 | 2 | 4));
outb(_com1 + 1, 0xF);
inb(_com1 + 9); // Taken from the Linux kernel
return 0;
}
This is the way i call it:
Code:
(void)init_com1(1);
I haven't done anything fancy for inb and outb, the "usual" implementation of them.
I tried passing other rates to it, (i tried 2 and 3), When the above code runs, Nothing is received on the other side, But if I just don't call it, 534 of 0x18 is received (I checked, That's exactly the same count of my "logs"),
On qemu, It returns 2 (as it finds _com1 is 0, which tells us there is no COM1), But in vmware, it initializes but again, the problem i told above^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^