Skip to content

Commit

Permalink
[REFACTOR] Auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Nov 30, 2024
1 parent 08e4216 commit 6c7cdf4
Show file tree
Hide file tree
Showing 34 changed files with 260 additions and 261 deletions.
6 changes: 3 additions & 3 deletions boot/amd64/amd64initialPaging.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ fun mapP2Huge(pd ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalA
}

fun mapPD(pd ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed UInt8, global Bool) Void {
writeAllowed UInt8, global Bool) Void {
let view = getPageAddressView(virtualAddr)
let pt = referOrCreatePage(pd, view.ref.pd, writeAllowed, global: false)
// TODO var pt = referOrCreatePage(pd, getPageAddressView(virtualAddr).ref.pd, writeAllowed)
mapPT(pt, virtualAddr, physicalAddr, writeAllowed, global)
}

fun mapPDPT(pdpt ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed UInt8, global Bool) Void {
writeAllowed UInt8, global Bool) Void {
let view = getPageAddressView(virtualAddr)
var pd = referOrCreatePage(pdpt, view.ref.pdpt, writeAllowed, global: false)
// TODO var pd = referOrCreatePage(pdpt, getPageAddressView(virtualAddr).ref.pdpt, writeAllowed)
mapPD(pd, virtualAddr, physicalAddr, writeAllowed, global)
}

fun mapPML4(pml4 ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed UInt8, global Bool) Void {
writeAllowed UInt8, global Bool) Void {
let view = getPageAddressView(virtualAddr)
let pdpt = referOrCreatePage(pml4, view.ref.pml4, writeAllowed, global: false)
mapPDPT(pdpt, virtualAddr, physicalAddr, writeAllowed, global)
Expand Down
2 changes: 1 addition & 1 deletion boot/shared/paging.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun mapEfiRuntime(memoryMap UefiMemoryMap) {

@struct class Buffa {
let value UInt64 = 0
new () {}
new () { }
}
let buffaStorage = new Buffa()
let buffa = buffaStorage as! ArrayPointer<UInt8>
Expand Down
8 changes: 4 additions & 4 deletions boot/shared/params.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let pageSize UInt16 = 4096u16 // 4 KiB

// Helpers
@struct
//@sizeOf(8)
// TODO @sizeOf(8)
// TODO separate UserVirtual
class Virtual<T> {

Expand Down Expand Up @@ -74,7 +74,7 @@ class UefiMemoryMap {
var mapKey UInt64
var descriptorSize UInt64
var descriptorVersion UInt32
new () {}
new () { }
}

@struct
Expand All @@ -91,7 +91,7 @@ class FrameBuffer {
var width UInt32
var height UInt32
var pixelsPerScanLine UInt32
new () {}
new () { }
}

@struct
Expand All @@ -103,7 +103,7 @@ class RamDisk {
var physical UInt64
/// Bytes for mapping
var size UInt64
new () {}
new () { }
}

@struct
Expand Down
10 changes: 5 additions & 5 deletions boot/uefi/ramdiskLoader.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun loadRamDiskFromVolume(
var address ArrayByValue<UInt64, 1> = [0]
let status = uefiAllocate(bootsvc, sizeAlloc.ref, address.ref)
serialPrintf("[[[uefi.loadRamDiskFromVolume]]] status: uefiAllocate %d, size %d at %d\n", status,
size[0], address)
size[0], address)

if status != EFI_STATUS.EFI_SUCCESS {
return status
Expand Down Expand Up @@ -133,7 +133,7 @@ fun findAndLoadRamDisk(bootsvc EFI_BOOT_SERVICES, ramdisk RamDisk) EFI_STATUS {
serialPrintf("[[[uefi.findAndLoadRamDisk]]] <ERROR> failed LocateHandleBuffer %d\n", status)
} else {
serialPrintf("[[[uefi.findAndLoadRamDisk]]] success LocateHandleBuffer, got %d handles\n",
handleCount)
handleCount)
}

for i in handleCount {
Expand Down Expand Up @@ -165,9 +165,9 @@ fun findAndLoadRamDisk(bootsvc EFI_BOOT_SERVICES, ramdisk RamDisk) EFI_STATUS {
var root = rootStorage[0] as! EFI_FILE_PROTOCOL
if status != EFI_STATUS.EFI_SUCCESS {
serialPrintf("[[[uefi.findAndLoadRamDisk]]] failed OpenVolume with status %d, continue to "
+
"the next one\n",
status)
+
"the next one\n",
status)
continue
}

Expand Down
8 changes: 4 additions & 4 deletions devices/amd64/amd64paging.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ fun mapPT(pt ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr
}

fun mapPD(pd ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed Bool, accessibleByUser Bool) Void {
writeAllowed Bool, accessibleByUser Bool) Void {
let view = getPageAddressView(virtualAddr)
let pt = referOrCreatePage(pd, view.ref.pd, writeAllowed, accessibleByUser)
mapPT(pt, virtualAddr, physicalAddr, writeAllowed, accessibleByUser)
}

fun mapPDPT(pdpt ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed Bool, accessibleByUser Bool) Void {
writeAllowed Bool, accessibleByUser Bool) Void {
let view = getPageAddressView(virtualAddr)
let pd = referOrCreatePage(pdpt, view.ref.pdpt, writeAllowed, accessibleByUser)
mapPD(pd, virtualAddr, physicalAddr, writeAllowed, accessibleByUser)
}

// TODO `private` all those functions
fun mapPML4(pml4 ArrayPointer<ByValue<PageEntry>>, virtualAddr UInt64, physicalAddr UInt64,
writeAllowed Bool, accessibleByUser Bool) Void {
writeAllowed Bool, accessibleByUser Bool) Void {
let view = getPageAddressView(virtualAddr)
let pdpt = referOrCreatePage(pml4, view.ref.pml4, writeAllowed, accessibleByUser)
mapPDPT(pdpt, virtualAddr, physicalAddr, writeAllowed, accessibleByUser)
Expand Down Expand Up @@ -219,7 +219,7 @@ fun freeCR3(pml4 PageEntry) Void {
// TODO protection ring
// TODO lower half limit bounds check (it is less than upper starting range)
fun mapUserspaceMemory(pml4entries PageEntry, virtualAddr UInt64, physicalAddr UInt64,
pageCount UInt32) {
pageCount UInt32) {
// TODO
}

Expand Down
2 changes: 1 addition & 1 deletion devices/cpu/cpuid.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class CPUID {
var brandName ArrayByValue<UInt8, 48> = [0]
var data ArrayByValue<UInt32, 1> = [0]
var extras ArrayByValue<UInt32, 1> = [0]
new () {}
var extendedECX ArrayByValue<UInt32, 1 > = [0]
var extendedEDX ArrayByValue<UInt32, 1 > = [0]
var nxBitSupported = false
new () { }
}

let cpuidExtendedLevels UInt32 = 0x80000000u32 // TODO valid values u/i8/16/32/64
Expand Down
6 changes: 3 additions & 3 deletions devices/cpu/interrupts.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let pic1_command_0x20 = 0x20u16
let pic1_data = (pic1 + 1)
let pic2_command = pic2
let pic2_data = (pic2 + 1)
let pic_eoi = 0x20u8 // end-of-interrupt command code
let pic_eoi = 0x20u8 // end-of-interrupt command code
let pic_eoi_0x20 = 0x20u8 // end-of-interrupt command code

@rename('vmemcpy')
Expand Down Expand Up @@ -221,7 +221,7 @@ class TssEntry {
var reserved2 UInt16
var ioMapOffset UInt16

new () {}
new () { }
}

@aligned(64) @volatile var globalGdtr TablePtr = new TablePtr()
Expand Down Expand Up @@ -433,7 +433,7 @@ fun setupInterruptsAndExceptions() {
serialPrintHex(idt.ref as! UInt64)
serialPrint("\n")
serialPrintf("[cpu] IDT size is %u of %u elements of %u==16 size\n", cacheIdtr.limit, idt_size,
sizeOf<IdtEntry>())
sizeOf<IdtEntry>())
// Before you implement the IDT, make sure you have a working GDT
remapPic()
loadIdt(cacheIdtr)
Expand Down
28 changes: 14 additions & 14 deletions devices/cpu/physical.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class PhysicalAllocator {
// TODO those fields must have ` = default`

// TODO does make sense at all?
//static fun virtualToPhysical(virtual UInt64) UInt64 {
// return 0
//}
// static fun virtualToPhysical(virtual UInt64) UInt64 {
// return 0
// }

static fun physicalToVirtual(physical UInt64) UInt64 {
return physical + wholePhysicalStart
Expand Down Expand Up @@ -109,7 +109,7 @@ class PhysicalAllocator {
{
var physical UInt64 = params.physicalBuffer
serialPrintf("[physical] Reserve %u bytes at %u of bootloader buffer\n", params.physicalBytes,
physical)
physical)
var i UInt64 = down_bytes_to_pages(params.physicalBytes) + 1u64
while i > 0 {
i--
Expand Down Expand Up @@ -218,16 +218,16 @@ class PhysicalAllocator {
// TODO probably UInt32 is completely enough to represent pages
while i < steps {
// if buffer[i] != PAGE_FREE {
// if current > largest {
// largest = current
// largestAt = currentAt
// if largest >= pages { break }
// }
// current = 0
//} else {
// if current == 0 { currentAt = i }
// current++
//}
// if current > largest {
// largest = current
// largestAt = currentAt
// if largest >= pages { break }
// }
// current = 0
// } else {
// if current == 0 { currentAt = i }
// current++
// }

if buffer[i] == page_free {
if current == 0u64 {
Expand Down
8 changes: 4 additions & 4 deletions devices/cpu/seh.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ fun probeForWriteOkay(@volatile at UInt64, @volatile bytes UInt64) Bool /*{
return true
}*/

//@volatile Bool (*@volatile const probeForWriteOkay)(@volatile at UInt64,
// @volatile bytes UInt64) = _probeForWriteOkay
// @volatile Bool (*@volatile const probeForWriteOkay)(@volatile at UInt64,
// @volatile bytes UInt64) = _probeForWriteOkay
// This is a fascinating way to not allow compiler to optimize return value
//let probeForReadOkay = _probeForReadOkay
//let probeForWriteOkay = _probeForWriteOkay
// let probeForReadOkay = _probeForReadOkay
// let probeForWriteOkay = _probeForWriteOkay

/// Use this to determine if RIP is within SEH-probing function
/// This is thread-safe
Expand Down
2 changes: 1 addition & 1 deletion devices/serial/init.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

fun initSerial() UInt8 {
// Calculate divisor for baud generator
// Ref_Clk_Rate / Baud_Rate / 16
var divisor UInt32 = serial_clock_rate / (serial_baud_rate * 16u32)
if (serial_clock_rate % (serial_baud_rate * 16)) >= serial_baud_rate * 8 {
// Ref_Clk_Rate / Baud_Rate / 16
divisor++
}
// See if the serial port is already initialized
Expand Down
30 changes: 15 additions & 15 deletions devices/serial/log.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fun serialPortWritable() Bool {
// 1 0 Cable connected, but not clear to send. Wait
// 1 1 Cable connected, and clar to send. Transmit
return ((readSerialRegister(r_uart_msr) & (b_uart_msr_dsr | b_uart_msr_cts)) !=
(b_uart_msr_dsr)) as! Bool
(b_uart_msr_dsr)) as! Bool
}
}
return true
Expand Down Expand Up @@ -293,12 +293,12 @@ fun comItoA(i Int64, b ArrayPointer<UInt8>) {
return b
}

//@rename('va_list') @struct
//@byValue
//declare class VA_List {}
//@rename('va_start')
// @rename('va_list') @struct
// @byValue
// declare class VA_List {}
// @rename('va_start')
// TODO firstArgument Any
//declare fun va_start(lst VA_List, firstArgument String) Void
// declare fun va_start(lst VA_List, firstArgument String) Void
@rename('va_start_') @customHeader('
#define va_start_(arg) va_list va_list__; va_start(va_list__, arg)
')
Expand Down Expand Up @@ -354,17 +354,17 @@ fun serialPrintf(c String, ...rest) {
switch c[i] { // TODO ClangWideChar
// TODO some way to put ascii `case 's': {` // ASCII of UTF-8
case 115: { // ASCII of UTF-8 `s`
let string = va_arg_uint64() as! ArrayPointer<UInt8> // TODO va_arg<ArrayPointer<UInt8> >(lst)
if string != null {
// TODO probeForReadOkay((uint64_t)string, 1)
// TODO actually should sehReadUInt8 for every char
puts(string)
} else {
serialPrintf("<STRING IS NULL>")
let string = va_arg_uint64() as! ArrayPointer<UInt8> // TODO va_arg<ArrayPointer<UInt8> >(lst)
if string != null {
// TODO probeForReadOkay((uint64_t)string, 1)
// TODO actually should sehReadUInt8 for every char
puts(string)
} else {
serialPrintf("<STRING IS NULL>")
}
}
// TODO `break` here converts switch to chain of `if`s, ensure this is correct and document
// ^ probably UInt16 is not recognized as switch-able
// TODO `break` here converts switch to chain of `if`s, ensure this is correct and document
// ^ probably UInt16 is not recognized as switch-able
case 83: { // ASCII of UTF-16 `S`
var string = va_arg_uint64() as! ArrayPointer<UInt16> // TODO va_arg<ArrayPointer<UInt16> >(lst)
var i UInt32 = 0u32
Expand Down
2 changes: 1 addition & 1 deletion dlls/tofita32/tofita32.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fun tofitaCreateWindowEx(payload CreateWindowExPayload) UInt64 {

@dllExport('tofitaShowWindow')
fun tofitaShowWindow(windowId UInt64, nCmdShow CmdShow) Void {
let payload = new ShowWindowPayload()
let payload = ShowWindowPayload()
payload.windowId = windowId
payload.nCmdShow = nCmdShow
tofitaFastSystemCall(TofitaSyscalls.ShowWindow, payload as! Payload)
Expand Down
Loading

0 comments on commit 6c7cdf4

Please sign in to comment.