Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for GOARCH=mips64 #8

Merged
merged 45 commits into from
Jul 11, 2024
Merged

Conversation

clktmr
Copy link

@clktmr clktmr commented Jun 23, 2024

Follow up to #6

Changes since last push:

  • Rebase to master-embedded
  • Removed all MIPS-III related "Revert ..." commits
  • Fixed all errors in all.bash
  • Removed dependency to n64 module, use go:linkname instead
  • Implemented cachemaint and irqctl syscalls

Tested with latest n64 module (cd8534ed58561a61701f3305f5ea2644b795eb31) (c0dccb15ff67961f321c5ebeae119359c9e33521)

clktmr added 20 commits June 23, 2024 07:19
Saving, restoring context and switching to the ISR goroutine (cpu0.gh)
seems to work so far.  Only syscalls and interrupts are handled so far.
See TODOs for next steps.
The COMPARE register was only used because of a bug in MAME which
doesn't exist anymore in newer versions.  Moreover this implementation
could result in a deadlock because the scheduler also sets this
register.
Don't call the scheduler and enable exceptions in the user handler, it
might call the scheduler.
This commit breaks external interrupt handling.  Will be fixed in the
next one.
Copy link
Collaborator

@michalderkacz michalderkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR7 "Fixes from n64 branch" can be probably removed because this one contains the
same fixes.

first, last = 1, 5
// runtime.unhandledExternalInterrupt is also a handler.
// Must be called somewhere in the code, otherwise it
// gets removed without error and relocs point to 0x0.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you add the "runtime.unhandledExternalInterrupt" to the names here to avoid this "calling somewhere" need? Maybe it's not enough but it's definitely handled somehow for the two other architectures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as you recommended. Not sure about the other GOARCHs. It's probably safe because it is called in externalInterruptHandler anyways, but while I was implementing this I ran into this error so I added the comment.

src/runtime/const_noos_n64.go Outdated Show resolved Hide resolved
noosNumStackOrders = 3
noosHeapAddrBits = 23 // enough for 8 MiB K210 SRAM
noosLogHeapArenaBytes = 17 // 128 KiB
noosArenaBaseOffset = 0x0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does TLB is configured to start RAM at 0x0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does

src/runtime/mksizeclasses_mcu.go Outdated Show resolved Hide resolved
src/runtime/rt0_noos_mips64.go Outdated Show resolved Hide resolved
src/runtime/tasker_noos.go Outdated Show resolved Hide resolved
src/runtime/tasker_noos_mips64.go Outdated Show resolved Hide resolved
clktmr added a commit to clktmr/go that referenced this pull request Jun 25, 2024
clktmr added a commit to clktmr/go that referenced this pull request Jun 25, 2024
Copy link
Collaborator

@michalderkacz michalderkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I found bugs in meminit.

  2. I thought a bit the concept of the default timer and think that we should stay with stopped time until proper timer is initialized (see comments).

src/embedded/rtos/irq_noos_mips64.go Outdated Show resolved Hide resolved
src/runtime/mem_noos.go Outdated Show resolved Hide resolved
// the non-DMA memory, properly align the arena
arenaSize := freeSize - uintptr(pallocInFree)
arenaSize &= ^(uintptr(heapArenaBytes) - 1)
arenaStart := freeEnd - arenaSize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look good to me.

You should probably start from: arenaStart = freeStart + pallocInFree
and next align the arenaStart address up to uintptr(heapArenaBytes)-1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have another look.

src/runtime/mem_noos.go Outdated Show resolved Hide resolved
src/runtime/tasker_noos.go Outdated Show resolved Hide resolved
Before clearing the memory via uncached access, all cache must be
invalidated before.  Otherwise a cache writeback could happen after
clearing the memory.
@clktmr
Copy link
Author

clktmr commented Jun 30, 2024

PR7 "Fixes from n64 branch" can be probably removed because this one contains the same fixes.

I removed these commits from this branch. I think it's worth having the eventual merge only contain mips64 related changes.

To get mips64 support on the same level as the other archs, support for setprivlevel syscall and noostest need to be added. Anything else that I missed?

@michalderkacz
Copy link
Collaborator

To get mips64 support on the same level as the other archs, support for setprivlevel syscall and noostest need to be added. Anything else that I missed?

Hmm... I'm unsure. It will come out in the wash.

Just merged this PR locally and want to test it against emulated linux/mips64. I did some research and it looks like there is no easy to find any big-endian MIPS64 Linux distro that may run on Qemu. I ended up building the openwrt-malta-be64-vmlinux-initramfs.elf image right now, hoping that it will start with qemu-system-mips64 -cpu R4000. What should I try next if the R4000 will be incompatible with this OpenWRT image?

MIPS '4Kc'
MIPS '4Km'
MIPS '4KEcR1'
MIPS '4KEmR1'
MIPS '4KEc'
MIPS '4KEm'
MIPS '24Kc'
MIPS '24KEc'
MIPS '24Kf'
MIPS '34Kf'
MIPS '74Kf'
MIPS 'M14K'
MIPS 'M14Kc'
MIPS 'P5600'
MIPS 'mips32r6-generic'
MIPS 'I7200'
MIPS 'R4000'
MIPS 'VR5432'
MIPS '5Kc'
MIPS '5Kf'
MIPS '20Kc'
MIPS 'MIPS64R2-generic'
MIPS '5KEc'
MIPS '5KEf'
MIPS 'I6400'
MIPS 'I6500'
MIPS 'Loongson-2E'
MIPS 'Loongson-2F'
MIPS 'Loongson-3A1000'
MIPS 'Loongson-3A4000'
MIPS 'mips64dspr2'
MIPS 'Octeon68XX'

@michalderkacz
Copy link
Collaborator

Some files in this PR have no standard Go copyright header. Please add it.

Anything else that I missed?

MMIO intrinsics came to my mind but they are just optimization. Should have their own PR.

@michalderkacz michalderkacz merged commit c6aa1a2 into embeddedgo:master-embedded Jul 11, 2024
@michalderkacz
Copy link
Collaborator

Go tests pass on linux/mips64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants