#Nyaux

1 messages · Page 6 of 1

thorn bramble
#

there is more data in the table after the acpi sdt header

#

so you're reading out of bounds

surreal path
#

OKAY NOW

kind root
#

Wait acpi_entry_header is a thing?

thorn bramble
#

in uacpi? yes, acpi_entry_hdr

kind root
#

Oh right lol

thorn bramble
#

lmaoo

kind root
#

Im tripping

#

I frogt it wasn't madt specific

#

Iirc srat uses it too

surreal path
surreal path
#

me trying to read acpi spec trying to understand what iso's are nooo

thorn bramble
#

yeah SRAT seems to reference that as well

kind root
#

Now add more CPUs

thorn bramble
#

what is SRAT anyway?

kind root
#

NUMA affinity table

thorn bramble
#

oh

#

boring stuff

kind root
#

What memory belongs to what domain etc

kind root
surreal path
kind root
#

Yup

surreal path
#

and thats what global system interrupts are? interrupts that came from the ioapic i suppose?

#

is that correct?

kind root
#

Yeah

surreal path
#

okay

#

okay so what do i need to do next ?

#

after parsing the entires

#

like

unkempt relic
surreal path
#

do i need to parse something or what

unkempt relic
#

these overrides tell you what a traditional IRQ's corresponding GSI is

surreal path
surreal path
kind root
surreal path
#

what is bus?

#

isa?

#

what is isa?

unkempt relic
surreal path
unkempt relic
#

isa is a traditional bus of PCs

#

the legacy IRQ concept springs from it

surreal path
#

oh so anything coming from the isa bus is legacy irqs

#

okay

kind root
#

Bro

surreal path
#

wait its 2 uint8s

#

whoopsie

kind root
#

The header has structs for these as well

#

U dont need to type pun anything

unkempt relic
#

i shouldn't worry about the bus, i don't even remember that being a field

surreal path
unkempt relic
kind root
kind root
unkempt relic
#

obscene sounding things but what can you do

kind root
#

I wanna support those from the get go in my os

surreal path
kind root
#

Will be interesting to design allocators with those in mind

surreal path
#

okay so 5 isos coming from the legacy isa bus

#

lets read that irq number and gsi number!

kind root
surreal path
#

i love uacpi even more

#

whats the enum called

unkempt relic
#

i would be using them already but i decided to not be too radical as i've only just, i think, acquired a complete enough understanding of working set model based vmm design to implement a not overly impressive one - but proper NUMA support with per-domain VM management is something i want to do

kind root
surreal path
#

these are what the isos look like btw

#

😎

kind root
surreal path
kind root
surreal path
#

legacy irq 5 goes to 5?

#

tf?

#

why would u override that

kind root
#

It overrides polarity and or triggering

surreal path
#

polarity?

#

triggering?

kind root
surreal path
#

😭

tawdry mirage
#

polarity says whether the irq line has to be high or low for the irq to happen

#

triggering says whether the irq is triggered by a transition from low to high (or high to low), or whether it's triggered by the line just being in the high (or low) state

surreal path
#

ah okay

#

anyways

#

now that i've parsed the isos

#

uhhh

unkempt relic
#

that will become relevant when you want to handle traditional IRQs

surreal path
#

ah okay

#

oooo what is this

#

👀

#

global system interrupt base? is this like a table that describes which gsi's go to which vectors?

#

or smthin

tawdry mirage
#

every ioapic serves gsis [gsi base, gsi base + ioapic pin count)

surreal path
#

oh so its memory mapped to the actual gsi pins

#

okay

#

what do i do with that lmao

#

can i like trigger a gsi if i write to gsi base or smthin

thorn bramble
#

you can use this information to route interrupts to LAPICs

#

interrupts are triggered externally

#

you cannot trigger them yourself

surreal path
#

oh

thorn bramble
#

that's the sole purpose of the IOAPIC

surreal path
#

and its routed?

thorn bramble
#

no, you write to the IOAPIC's redirection table

kind root
#

Read the ioapic spec

surreal path
#

bruh

thorn bramble
#

yeah

#

do it

surreal path
#

okay wait

kind root
#

Its tiny

#

Its two registers

surreal path
kind root
#

Yes

surreal path
#

looks more modern

kind root
#

Thats x2apic

#

Its unrelated to ioapic

surreal path
#

oh okay

surreal path
#

okay so its a register

#

i need to select a register in the REGISTER SELECT REGISTER

#

and then i can write or read from a register with the

#

WINDOW REGISTER

#

okay

#

to access these registers im guessing its ioapic address + FEC0 for the select register

#

correct?

#

i think thats correct

#

can there be multiple io apics?

#

or is there like only one

#

?

ionic jetty
#

Indeed halfmemeright

ionic jetty
surreal path
#

so i need to keep track of all of them im guessing

ionic jetty
#

I have tested on 16 and 24 core cpus and they’ve only had one i think

surreal path
#

oh so its really rare for multiple ioapics?

#

or smth

ionic jetty
#

I can’t comfortably approve you that

#

But my guess would be that especially high core server cpus are more likely to have multiple

surreal path
#

im not writing a kernel for server cpus

#

☠️

#

maybe if i was linux sure but im not linux

#

im mr nyaux kernel for poo poo hobbyist os

#

so the moment i find an ioapic im gonna store the ioapic address as a global variable

#

and just assume theres only 1

ionic jetty
#

That works too ig

surreal path
kind root
surreal path
ionic jetty
#

I remeber the ioapic having less regs

surreal path
#

is what intel says

ionic jetty
#

I get the ioapic base from acpi

surreal path
#

yep

ionic jetty
#

And then IOREGSEL has offset 0

surreal path
#

oh

#

so wtf is FEC0

#

what is intel blud trying to say

ionic jetty
#

Maybe the base address for the first apic

surreal path
#

idk 🤷‍♂️

kind root
#

Not always

ionic jetty
#

So like first ioapic is at FEC0 0000

kind root
#

So read it

ionic jetty
#

The next one at this + 0x1000

#

And so on

#

Thats the xy

#

And then the 00 at the end is what i said

#

Offset 0

surreal path
#

oh yeah must add the hhdm offset so i dont cause funny page fault

#

sec

ionic jetty
#

Volatile may not hurt

#

But otherwise yeah

surreal path
ionic jetty
#

Yes

#

Is that bad

surreal path
#

no

ionic jetty
#

Then command it around halfmemeright

#

Are you reading the ioapic spec

surreal path
surreal path
ionic jetty
#

Nice

surreal path
#

☠️

ionic jetty
#

h

#

You put a h

#

Because you copied from intels manual

surreal path
#

how am i supposed to put it then

ionic jetty
#

The h means its in hex 🤣

#

Its like 0x

#

In C

surreal path
#

i did 0x10h

#

?

ionic jetty
#

Yes remove the h

surreal path
#

ok

#

OH HHHH

#

LMAO

ionic jetty
#

Its intels way of saying this number is hex

surreal path
#

😭

#

intel moment

ionic jetty
surreal path
#

okay i made my cool functions for writing to and reading from the ioapic registers

#

okay uhhhhhh

kind root
#

Now lapic

surreal path
#

do i eat it

ionic jetty
#

Lapic is the per cpu controller

surreal path
#

yes i know

ionic jetty
#

You can do ipis

#

For example

finite summit
#

and get SMP

surreal path
#

what am i supposed to do to the lapic

#

im so confused

ionic jetty
#

And a high precision low overhead per core timer

ionic jetty
surreal path
#

lapic spec sheet where?

kind root
kind root
surreal path
#

sec

#

the sdm just crashed my firefox

#

😭

ionic jetty
#

Thats a rare achievement

kind root
#

Type dmesg

#

It was probably an oom

surreal path
#

okay i see a bunch of registers

kind root
#

Yup

surreal path
#

im guessing its different to ioapic where you can just directly read and write the registers?

kind root
#

Wdym

surreal path
#

as in instead of selecting your register in like a register

#

and writing to a rw register

#

like the io apic

ionic jetty
#

No select here

surreal path
#

you can just directly read or write the register

#

yea no selection here

kind root
#

Yes

surreal path
#

okay so the madt has the local apic address

#

okay

ionic jetty
#

Theres an msr for it too

#

And the address is most likely to be fixed if i remember correctly

surreal path
#

okay made some functions that can read and write to a lapic register

#

okay

#

uhhhh

#

whats exactly next?

kind root
#

Start other cores

tawdry mirage
kind root
#

Or do something else

tawdry mirage
#

also re multiple ioapics ```
qookie@selenium ~ λ dmesg | grep -i ioapic
[ 0.035325] IOAPIC[0]: apic_id 7, version 33, address 0xfec00000, GSI 0-23
[ 0.035330] IOAPIC[1]: apic_id 8, version 33, address 0xfec01000, GSI 24-55
[ 0.970713] ACPI: Using IOAPIC for interrupt routing

#

on my laptop

surreal path
#

only got one

#

😎

#

from gsis 0-119

tawdry mirage
ionic jetty
#

2 ioapics with 6 cores? Okay

surreal path
#

how do i start getting things like irqs or smthin

tawdry mirage
kind root
#

Yup

ionic jetty
kind root
surreal path
surreal path
ionic jetty
#

or mask them i forgot

surreal path
#

okay so lapic_base + 0xf0

#

ima write to it

#

okay i need to set bit 8 to 1

#

to enable it?

#

okay im writing 0x80 to it

#

which should just be the 8-eith bit that is on

tawdry mirage
#

try again

surreal path
#

wdym?

tawdry mirage
#

you got it wrong

surreal path
#

oh wait

#

wrong bit

#

thats the 7th bit

#

sec

#

0x100

#

no idea whats gonna happen but we will see?

tawdry mirage
#

you probably want a different vector than 0

surreal path
#

what

tawdry mirage
#

the spurious vector?

surreal path
#

oh i gotta select a vector

#

uhhhh

#

0x33 yea!

#

page faults

#

bruh

#

this should be right?

#

why is bro page faulting

#

☠️

tawdry mirage
#

why cast the address to a volatile uint32

surreal path
#

idk i felt like it

#

oh wait

#

whoops

#

still page fault 😔

tawdry mirage
#

you're ignoring lapic_base and adding ioapic->address?

tawdry mirage
#

please turn on -Wall -Wextra -Werror

surreal path
#

whoopsie

tawdry mirage
#

-Wpedantic if you're not using gnu extensions

surreal path
#

still causing a page fault

#

grrr

#

😠

tawdry mirage
#

what's cr2?

surreal path
#

sec

#

CR2=ffff8000fee000f0

tawdry mirage
#

oh ig the lapic isn't mapped into the hhdm

#

or wait

surreal path
#

huh ??? angr

tawdry mirage
#

hm the first 4GB should be mapped unconditionally

tawdry mirage
#

what does info tlb say in the qemu monitor

#

when it panics

surreal path
#

okay sec

ionic jetty
#

Why is that

#

I mean yes most devices are there

#

But like why not map them whenever u need them

tawdry mirage
#

idk i wasn't there in the room when the limine spec was being written

finite summit
ionic jetty
#

Oh you meant its a limine thing

surreal path
finite summit
#

then the first 4 gib isn't mapped

tawdry mirage
ionic jetty
#

I thought you meant like „everyone should do it because i dont know“

#

mb

surreal path
#

im using revision 1

#

im so confused

#

why isnt the hhdm working nooo

#

i mapped like pretty much everything

wicked loom
#

Limine broke, ask for replacement

surreal path
#

wheres limine 2 mintsuki

#

i need it now

wicked loom
#

already existed

surreal path
#

when???

wicked loom
#

we're at Limine 7.x

surreal path
#

no we need limine uhhh

#

20.x

#

uhhh does this look like the end of the hhdm mappings to yall

#

FFFF8000D0788000 is calculated as the limit of the hhdm

tawdry mirage
#

sounds broken

#

or well

#

your recreated hhdm doesn't match limine's hhdm if you don't map the first 4GB unconditionally

surreal path
#

and calculate the hhdm limit through every entry

tawdry mirage
#

yes and on top of all memory map entries, limine also maps the first 4GB unconditionally into the hhdm

tawdry mirage
wicked loom
#

oh yeah it does

#

sorry i misread what you said

wicked loom
#

yes

kind root
wicked loom
#

it does

tawdry mirage
#

rev 1 gets rid of the identity mapping

kind root
#

Oh

tawdry mirage
#

not the first 4GB in the hhdm

surreal path
#

im confused

kind root
#

Ultra just has a higher-half-exclusive mode in the proto

surreal path
tawdry mirage
#

idk how else to word it

#

limine unconditionally maps [0, 0x100000000) into the hhdm, and on top of that whatever the memory map says

surreal path
#

correct?

tawdry mirage
#

if you want to end up with the same hhdm as limine gave you

surreal path
#

okay

kind root
surreal path
tawdry mirage
#

alternatively you could just allocate some vm space and map the lapic in yourself, without relying on the hhdm

surreal path
#

the memmap represents physical memory yes?

#

and like wait

#

what if a memmap entry represents like

#

something in that range

#

0 to 0x100000000

#

what am i supposed to do in that case

#

cause currently how i calculate the hhdm limit is like

#

add 0x1000 to hhdm_limit as i map, looping through each page

tawdry mirage
#

why do you need the hhdm limit

surreal path
unreal hill
#

limine basically does max(what you did, 0x1_0000_0000)

surreal path
#

what

unreal hill
#

always mapping at least 4gb for this exact reason, mmio devices that aren't "real" memory with "real" memmap entries, which live around 4gb on pcs

kind root
#

So what's the problem exactly

surreal path
#

okay so i need to calculate the END of the hhdm

kind root
#

Why dont u have that memory mapped on the higher half

thorn bramble
tawdry mirage
#

you don't need to repeat the body a million times

surreal path
#

okay i know what to do

#

it may be stupid but

#

🤷‍♂️

#

i think itll work

#

😎

#

and then i can just unconditionally map the lower 4gib

#

easily and add the hhdm pages

#

as normal

#

yea i think this'll work

#

THIS SHOULD WORK LETS SEE CHAT 😎

#

oh

#

okay

#

um

#

this did NOT work!

#

uhhhh

#

oh wait

#

lOL ITS ZERO?

#

WHAT??

#

😭

#

wait nvm

#

okay i think im doing this wrong

#

i dont know what to do

#

how tf am i gonna calculate the hhdm limit and map all of this ughhhh

surreal path
thorn bramble
#

it's that simple

surreal path
#

literarly

#

but it didnt work like?

thorn bramble
#

show code

#

like

#

full code

surreal path
kind root
#

Im detecting big presence of a skill issue

surreal path
#

😠

surreal path
thorn bramble
#

perchance..

surreal path
tawdry mirage
#

please invent a printf ```c
serial_print_color("Region Information!: Base: ", 0);
serial_print(itoah(buffer, cur_node->base));
serial_print(", Length: ");
serial_print(itoah(buffer, cur_node->length));
serial_print("\n");

surreal path
#

wait no it works now?

#

it worked?

kind root
#

He literally has one

#

Since uACPI uses it

surreal path
#

cause it didnt page fault and now it works?

tawdry mirage
#

you are winrar

surreal path
#

winrar?

#

i am winrar??

#

wowie !!!!

#

im winrar guys

#

😎

#

okay so it enabled the lapic!

#

i wrote to the spurcious vector register thingy

#

and it worked

#

tho nothing interesting happened

#

what do i do next now that i've enabled the lapic 😎

#

uhhh

#

is there anything else i need to configure or?

tawdry mirage
#

you want to configure lints as the madt lapic nmi entries say

tawdry mirage
surreal path
#

This structure describes the Local APIC interrupt input (LINTn) that NMI is connected to for each of the processors in the system where such a connection exists. This information is needed by OSPM to enable the appropriate local APIC entry.

#

okay

surreal path
tawdry mirage
#

yes

surreal path
#

okay so each lapic has 2 lint pins

#

lint0 and lint 1

#

so a nmi can be connected to multiple processors as well and stuff

#

okay

#

okay so im confused

#

lol what

#

oh wait

#

wrong struct

#

oh wow

#

an nmi connected to lint 1

#

!!

#

whatever will i do with this information

#

LOCAL APIC LINT THIS NMI IS CONNECTED TO: 1 FOR PROCESSER ID: FF

#

this is an nmi for all processors

#

according to acpi spec

#

okay

#

i dont get what im supposed to do with this information? 😭

#

yes a non maskable interrupt is connected to lapic pin 1 for all processors okay? 😭

#

i dont get what i have to configure

#

like huh?

unreal hill
#

generally it's more useful to start assuming you don't need to care until you do; there's a lot of highly specific information in these tables that won't matter to you at this stage. I'm sure it's possible to generate an NMI in qemu, but I would argue it's almost completely irrelevant to you

unreal hill
#

tl;dr: "what do I have to configure?" -> nothing

surreal path
#

so what do i do now ig

#

i've enabled the lapic

#

parsed the heckin madt entries ig

#

set surprious interrupts to vector 33

#

whats next?

#

to do?

unreal hill
#

what was the original goal of this excursion?

surreal path
#

to have a apic driver

#

so i can get like

#

a lapic timer

#

and get irqs

#

and stuff

unreal hill
#

well then I'd look at the apic timer

#

there are registers available to you

surreal path
#

okay im reading the sdm

#

says i need to access lapic base + 0x320 register to setup a timer?

#

okay so i need to set bits 0-7 to my isr handler for a timer ig?

#

seemingly

#

now to configure the timer

#

and try it out

#

and see if we get an irq

#

and it handles it

#

and prints out "tick"

#

what should i set inital count to?

#

nothing happened 😔

#

i think cause its masked?

#

i dont know how to unmask it tho

#

sdm doesnt say which bit to set

#

ok bit 16 is the mask bit

#

WHY ISNT IT DOING ANYTHING

#

COME ON DO SOMETHIN

#

TRIGGER ME INTERRUPT

#

this should BE riight

#

😭

ionic jetty
surreal path
#

Why isn’t the lapic timer doing anything like at all

finite summit
#

Try sending a self ipi to test it via the ICR

#

Registers

#

You get to choose the vector

#

If that doesn't work your LAPIC is initialized incorrectly (maybe check the msr?)

surreal path
surreal path
finite summit
#

What is the mode thing

#

Is it periodic or single shot

surreal path
#

uhhhh, I believe it’s not set to anything

#

But all zero means single shot so

finite summit
#

You misconfigured

#

Line 71

#

Where you write to offset 0x320

#

That isn't how bit logic works

surreal path
#

Oh wait

#

I did an or operation instead of and

finite summit
#

The bit isn't set though

#

Whatever bit is the value you were noting isn't set in 0x34

surreal path
#

oh right

finite summit
#

Yeah

#

And you're setting the value

#

So it doesn't matter

#

Ths initial count should be set last btw

#

That's what starts the timer

surreal path
#

Oh

#

Lmao it probs went too fast before I set my vector

finite summit
#

Yeah then it errored out because vector was likely zero initialized

#

and it's illegal to send an IRQ to vectors < 32

#

And it's probably also giving an error when you set all those bits (a lot reserved) in the timer vector register

surreal path
finite summit
#

Before when you orred those bits

#

Did rearranging the code and not setting the bits fix anything

#

?

surreal path
#

nope

finite summit
#

Try setting the initial count to 1000

#

1 is quite fast especially considering you're using an emulator

surreal path
#

okay sec

#

Setting to 1000 doesn’t do anything

#

nothing happens still

finite summit
#

Check eflags

#

See if IRQs are enabled via bit 9

surreal path
#

ok

finite summit
#

Dumb autocorrect

#

How are gets autocorrected to Arabia will forever be unknown

surreal path
finite summit
#

If they are, check if cr8 is zero (should be if you never touch it)

surreal path
#

like wait i gotta do som rq for like 30 minutes

#

be back in a bit

surreal path
#

i cant do this??

#

undefined reference to rflags

#

huh

haughty kite
#

no thats not how x86 works

surreal path
#

why am i not allowed to put the value of rflags into i

haughty kite
#

because thats not how x86 works

surreal path
#

your not telling me why

haughty kite
#

and also thats not how at&t syntax works

#

and if you are using -Mintel.. just no

surreal path
haughty kite
#

yes

#

literally just use google

rigid fable
finite summit
#

He wants to set if

#

Use sti

rigid fable
rigid fable
surreal path
#

And nothing happens still

#

Sorry I was at school

#

Executing sti does nothing

#

before setting up apic

#

and cr8 is 0xe

finite summit
#

uhhh

#

that should mask out irq 34

#

Set cr8 to zero

surreal path
#

All of it?

surreal path
#

okay im back

#

from school

#

yea uhhh

#

BRO CR8 IS ZERO WTF

#

😭

#

WORK U DAMN STUPID TIMER

#

GRRR

#

the lapic timer is a meanie

#

wtf

thorn bramble
#

what do you expect to be in cr8?

#

also you are moving to cr8

#

of course it's gonna be 0

surreal path
#

yea as expected

#

it should work the lapic timer

#

why isnt anything happening

thorn bramble
#

what significance does cr8 have here??

#

type info lapic into qemu monitor

#

see if it's configured correctly

surreal path
#

which masks out irq 34

#

so i have to set it to zero

thorn bramble
#

weird

surreal path
#

tf

#

WHY IS THE TIMER MASKED AND WHY IS IT SET PERIODIC AND WHY IS IT VECTOR 5😠

thorn bramble
surreal path
surreal path
thorn bramble
#

IRR is not set

surreal path
thorn bramble
#

interrupt request register

#

how do you configure the timer?

surreal path
#

then i set the vector of the lvt timer to vector 34

thorn bramble
#

show the values

surreal path
#

okay

thorn bramble
#

you write to the lapic registers

surreal path
#
write_lapic_register(madt->local_interrupt_controller_address, 0xf0, 0x100 | 33);
    serial_print("enabled lapic?\n");
    // enable lapic timer?
    // divide by 1
    write_lapic_register(madt->local_interrupt_controller_address, 0x3e0, 7);
    // set vector to 34 
    write_lapic_register(madt->local_interrupt_controller_address, 0x320, 34);
    // set inital count?
    lapic_addr = madt->local_interrupt_controller_address;
    write_lapic_register(madt->local_interrupt_controller_address, 0x380, 1);
surreal path
#

yea i do

thorn bramble
#

no no it was part of my previous message

surreal path
#

what im confused

thorn bramble
#

show the values...
...you write to the lapic registers

thorn bramble
#

you are configuring lapic timer to be one-shot btw

surreal path
#

yea ik

thorn bramble
#

and it's going very slow

surreal path
#

okay but

thorn bramble
#

configure the divider to be a little bit higher

#

it should fire quicker

surreal path
thorn bramble
#

oh right, i totally forgot about that

#

i have no idea if it's significant or not

#

but for me it's set to what i believe is my timer interrupt vector

#

¯_(ツ)_/¯

surreal path
#

why tho?

#

sdm doesnt say much about this register

#

what is it for

thorn bramble
#

i have no idea but that value is put there if i write to the LVT timer register

surreal path
#

weird

thorn bramble
#
writeRegister(.LvtDivide, 3);
writeRegister(.LvtTimer, @as(u32, timer_vector.?));
writeRegister(.LvtInitialCount, 0x5000);```
#

i write those values

#

LvtDivide being 0x3e0, LvtTimer being 0x320 and LvtInitialCount being 0x380

#

can you show your write_lapic_register?

surreal path
#

writing those values did nothing

#

sure

#
volatile void write_lapic_register(uint32_t lapic_base, uint8_t reg_offset, uint32_t data)
{
    *(volatile uint32_t*)(lapic_base + reg_offset + hhdm_request.response->offset) = data;
}
thorn bramble
#

get the lapic address from the msr

#

not the madt

#

first of all

surreal path
#

why?

thorn bramble
#

rdmsr(0x1b) & ~0xfffUL

#

because it's the actual address

#

that the cpu uses

surreal path
#

and then whats the address in the madt for

#

the lapic address in the madt

thorn bramble
#

idk, ask someone who knows more than i do

surreal path
thorn bramble
#

all i know is that you should use the msr, but it should be the same

surreal path
thorn bramble
#

can you print the address?

#

it should be 0xfee00000

surreal path
#

of the madt lapic address?

#

okay

surreal path
#

yea it is

thorn bramble
#

well that's good at least

surreal path
#

okay so then it should work

#

like huh

#

???

thorn bramble
#

can you add -trace apic_mem_write* to your qemu command line

thorn bramble
#
apic_mem_writel 0xf0 = 0x000001ff
apic_mem_writel 0x3e0 = 0x00000003
apic_mem_writel 0x320 = 0x00000020
apic_mem_writel 0x380 = 0x00005000```
#

i get this when configuring my lapic + lapic timer

surreal path
#
apic_mem_writel 0xf0 = 0x00000121
enabled lapic?
apic_mem_writel 0xe0 = 0x00000003
apic_mem_writel 0x20 = 0x00000022
apic_mem_writel 0x80 = 0x00005000
thorn bramble
#

which is writing to the spurious vector register, lvt divide, lvt timer and lvt initial count

#

well

#

that's not looking good

surreal path
#

tf

thorn bramble
#

0xe0 0x20 0x80

#

missing a whole ass 0x300

surreal path
#

OH

#

☠️

#

OH

#

uint16

#
apic_mem_writel 0xf0 = 0x00000121
enabled lapic?
apic_mem_writel 0x3e0 = 0x00000003
apic_mem_writel 0x320 = 0x00000022
apic_mem_writel 0x380 = 0x00005000

well um

thorn bramble
#

that's a little better

surreal path
#

seems configured?

#

so why did nothing happen

thorn bramble
#

you can -trace apic_local_deliver*

surreal path
#

kk

thorn bramble
#

to figure out if its firing any interrupts

surreal path
#
apic_local_deliver vector 0 delivery mode 
#

um

thorn bramble
#

i get a bunch of apic_local_deliver vector 0 delivery mode 0 apic_local_deliver vector 0 delivery mode 0 apic_local_deliver vector 0 delivery mode 0 apic_local_deliver vector 0 delivery mode 0

#

so yeah the same for you

#

-d int then

surreal path
#

kk

thorn bramble
#

maybe you're not registering an interrupt handler properly?

#

lol

#

idk at this point

#

but it seems to be firing

#

oh

#

its one shot

surreal path
#

yea its one shot?

thorn bramble
#

maybe it fires before you get a chance to unmask it

#

but i think if you set cr8 to 0 and there's any pending interrupts they should fire anyway

surreal path
thorn bramble
#

if they were pending due to the cr8 masking them that is

surreal path
#

the last thing i do is set inital count

thorn bramble
#

try a periodic timer

surreal path
#

kk

thorn bramble
#

or the lvt timer register with 0x20000

#

setting bit 17

surreal path
#

nothings happenin still

#

its set to periodic qemu monitor says

thorn bramble
#

anything when you use -d int?

surreal path
#

sec

#

nope

#

nothing

thorn bramble
#

interesting

surreal path
#

yea doing -trace apic_local_deliver*

#

shows

#

its sending interrupts

#

spamming my stdio

#

oh

thorn bramble
#

oh?

surreal path
#

there was a misconfiguration in my idt but

#

still didnt solve anything

thorn bramble
#

oh rip

surreal path
#

lemees ee what -d int shows

#

still nothing

thorn bramble
#

well the idt shouldn't have anything to do with the interrupts not arriving

surreal path
#

yea

thorn bramble
#

are you messing with the PIC/PIT/IOAPIC?

surreal path
thorn bramble
#

the first two shouldn't matter

#

what exactly are you doing with the ioapic?

surreal path
#

no wait no im not doing anything with the ioapic

thorn bramble
#

hm ok then

surreal path
#

so like wtf

thorn bramble
#

confused

surreal path
#

will i post my code onto github or smth

#

cause idk

#

why the interrupts

#

arent arriving

#

its sending interrupts

#

the lapic looks configured correctly

#

whats going on

thorn bramble
#

i am not able to help even

#

qemu trace clearly tells you that the apic is trying to deliver interrupts

surreal path
#

my kernel is cursed

thorn bramble
#

but something is preventing them from reaching the cpu

surreal path
#

is it a limine thing idk

#

about

thorn bramble
#

can you try using 0xff as the spurious interrupt vector?

surreal path
#

or smthin

thorn bramble
#

no its not

thorn bramble
#

or it shouldn't be

thorn bramble
#

hm ok well it was worth a try

surreal path
#

i told u the lapic wants to eat me

thorn bramble
#

one more difference is that your lvt0 is configured as edge triggered and for me it's configured as level triggered

#

idk how it all works, but i can see that it's a difference

surreal path
#

i should still be getting an interrupt

#

at the very least

#

😭

#

idk what to do

surreal path
#

im banging my head againist the wall with this issue angr

#

like bro

#

why wont bro just

#

receive the heckin interrupt

#

😭

finite summit
#

show eflags

#

and cr8

surreal path
surreal path
#

9th bit is off

#

001001000110 is the binary of 0x246

#

@finite summit

#

triggering the timer irq interrupt i have setup in my idt manually works fine

#

meaning that idt is configured correctly

thorn bramble
#

bit 9 is IF, bit 6 is ZF, bit 2 is PF and bit 1 is always 1

#

so that looks okay

surreal path
#

yea

finite summit
#

send an EOI

#

to the LAPIC before turning it on

surreal path
finite summit
#

if that fixes it, someone forgets to send an EOI

tawdry mirage
surreal path
surreal path
#

before enabling the lapic

#

nothing happened

thorn bramble
#

you are supposed to send one on every lapic interrupt

#

not before it's enabled

surreal path
#

yea but i dont even get a lapic interrupt in the first place

#

so like

surreal path
unreal hill
#

do you have the vector set up as an interrupt or trap gate? you could be getting so many interrupts it never gets to print anything. You could also up the interval so you get fewer interrupts

thorn bramble
#

iirc he's not getting any interrupts from the lapic

#

according to -d int

surreal path
#

yea

#

cpu aint seeing shit

thorn bramble
#

are you using kvm?

surreal path
#

no

thorn bramble
#

welp

surreal path
#

-accel tcg

thorn bramble
#

just making sure

#

anything !tcg would make it so -d int doesnt print anything

#

or at least kvm, cant say for sure for other

surreal path
#

this makes zero sense

#

in why the cpu

#

isnt getting any interrupts at all

#

from the apic

#
@sudo qemu-system-x86_64 $(IMAGE_NAME).iso -M q35 -bios /usr/share/edk2-ovmf/OVMF_CODE.fd -m 3G -accel tcg -serial stdio 

my qemu command

thorn bramble
#

can you try with seabios?

#

just curious

surreal path
#

ok sure

#

still nothing

thorn bramble
#

hm ok

#

i was curious whether edk does some weird shit

surreal path
tawdry mirage
surreal path
#

?

finite summit
#

That means the LAPIC has that irq in it's queue

#

but something is blocking it from getting sent

surreal path
#

yea but what????

#

😭

surreal path
#

so i can get interrupts

#

what other thing could possibly block it???

#

is it something with limine?

finite summit
#

TPR in the LAPIC

surreal path
#

tpr?

finite summit
#

Task Priority Register

thorn bramble
#

cr8

#

he's zeroing it out

finite summit
#

also if the LAPIC is waiting for an EOI

thorn bramble
#

he's not getting an interrupt to begin with

surreal path
#

i mean i can try reading the tpr and see the value

tawdry mirage
#

asm("mov %0, %%cr8" : "=r"(i)); this is wrong

#

this loads garbage into cr8

thorn bramble
#

it is definitely broken, but if he compiles in debug it's probably moving 0 to cr8 anyway

#

you are moving from reg to cr8

#

but you are telling gcc you are reading to the register

#

asm("mov %%cr8, %0" : "=r"(i));

#

this is how you read out of cr8 to i

thorn bramble
#

oh nvm if it's debug then it's probably on the stack and the register will contain garbage

tawdry mirage
#

also you configure the divide value wrong

#

not that it'd prevent irqs but still

thorn bramble
#

yea he adopted the same garbage values i use in zigux

#

i even have a big ass troll face in the source code right above it

tawdry mirage
#

you want 0xB not 0x3, because the value is _X__ not ___

surreal path
#

it worked? i think

#

YEA IT WORKED

#

i need to send an eoi

#

wait

thorn bramble
#

i used 0x3 with initial count of 5000 because it gave me roughly what i was looking for, apparently setting lvt divide to 0x3 gives you a divisor of 16

#

professional lapic timer calibration

surreal path
#

uhhh weird results

#

oh yeah cause we end at _start and disable interrupts and just hlt

#

BUT IT WORKS!!!!

thorn bramble
#

life could've been easier

#

also you're supposed to write 0 to the eoi register

#

not 1

thorn bramble
#

i think so at least, i remember reading about this somewhere

surreal path
#

011

tawdry mirage
#

and yet the comment says divide by 1

surreal path
#

oh yeah

tawdry mirage
#

make up your mind

surreal path
#

i changed it

#

lol

#

well now this epic gamer timer is working

#

do i hook it up to my scheduler for funny shanngains or what trl

#

wait ill need to like "calibrate" the timer

#

lol

#

uhhhh

#

how do i make the timer "calibrated" so the timer ticks at like

#

a proper value

#

that is quantifiable and not just random number 1000 divide by 1

tawdry mirage
#

you compare how fast it ticks against a different timer :^)

surreal path
#

bruh

#

☠️

#

i remember someone talking about the hpet

#

uhhh

#

i guess ill try and use that?

#

(i have absolutely no idea how im gonna "calibrate")

thorn bramble
#

hpet tells you how fast it ticks

#

you can measure how many lapic ticks elapse in a certain amount of time by polling the hpet

#

you pick that amount of time, the longer the better (more accuracy)

#

but you also dont want it to be too long for obvious reasons

surreal path
thorn bramble
#

no, you mask the lapic timer and read it's counter value

surreal path
#

oh

thorn bramble
#

interrupts will throw your calculations off

#

they take time to handle

surreal path
#

okay so mask lapic timer, set to what mode?

#

periodic? one shot?

thorn bramble
#

doesnt matter

#

it's not gonna fire anyway

#

so one shot is better

surreal path
#

kk

thorn bramble
#

so it doesn't wrap around

#

i guess

surreal path
#

what should i set the divider to?

thorn bramble
#

you set the lapic timer up as one shot, mask it, mark starting hpet tick count, set lapic timer ticks very high (0xffffffff or something, idk) wait for a certain amount of time to pass, mark current lapic counter, check how many ticks elapsed (0xffffffff - current) and save that somewhere so you can accurately configure it in the future

thorn bramble
surreal path
#

okay

thorn bramble
#

it's your choice

surreal path
#
// set vector to 34 , ONE SHOT, MASK IT
    write_lapic_register(lapic_addr, 0x320, 34 | (1 << 15));

okay

#

ill set inital count to somthin like

#

uhhh

#

0xffffffff

#

okay ill use trusty handy dandy uacpi to scan for the hpet table

#

btw i love u copyobject abuser for making uacpi

#

its SO much better then lai

thorn bramble
#

The APIC timer frequency will be the processor’s bus clock or core crystal clock frequency (when TSC/core crystal
clock ratio is enumerated in CPUID leaf 0x15) divided by the value specified in the divide configuration register

#

you might want to set the divide to 2/4, depending on how fast the clock actually is meme

surreal path
#

wha

plush hearth
#

I noticed that divide by 1 can be very inconsistent on QEMU

thorn bramble
#

yeah you probably want to use a higher divisor then

surreal path
thorn bramble
#

the apic timer ticks at the speed of the bus clock divided by what you configure

surreal path
#

oh that’s makes more sense lmao

thorn bramble
#

i said the exact same thing but in lowercase

#

:^)

surreal path
#

But intel uses big boy language

#

😡

#

okay so i have the hpet table

#

right?

thorn bramble
#

right

surreal path
#

now i need to check the hpet tick count

#

but all i have is the address TO the hpet

thorn bramble
#

yeah

surreal path
#

is it like a register thing with hpet as well