Skip to content

Commit

Permalink
Add kernel RNG and refactor boot
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevault committed Sep 14, 2014
1 parent 1b4fa9f commit ec7c844
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 334 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,7 @@ TI84pCSE: BOOT := 3FC000
TI84pCSE: LENGTH := 0x400000
TI84pCSE: kernel $(OUTDIR)

SKIPON:=NO

ifeq ($(SKIPON),YES)
DEFINES=--define $(PLATFORM) --define SKIPON
else
DEFINES=--define $(PLATFORM)
endif
BINDIR=$(OUTDIR)$(PLATFORM)/
INCLUDE=include/;$(BINDIR)

Expand Down
8 changes: 2 additions & 6 deletions include/kernelmem.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ clip_mask .equ currentContrast + 2 ; 1 byte

color_mode .equ clip_mask + 1 ; 1 byte

random_seed .equ color_mode + 1 ; 8 bytes

flashFunctions .equ stateMemory + stateMemorySize
kernelGarbage .equ flashFunctions + flashFunctionSize

#ifdef DEBUG
debugBuffer .equ kernelGarbage + kernelGarbageSize
userMemory .equ debugBuffer + 0x300
userMemorySize .equ 0xFFFF - userMemory ; user memory extends to 0xFFFF
#else
userMemory .equ kernelGarbage + kernelGarbageSize
userMemorySize .equ 0xFFFF - userMemory ; user memory extends to 0xFFFF
#endif
6 changes: 1 addition & 5 deletions src/00/base.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; Base file for KnightOS kernel
#define DEBUG

#include "platforms.inc"
#include "defines.inc"
Expand Down Expand Up @@ -44,13 +43,10 @@ drawHexHL .equ 0x0D01
#include "keyboard.asm"

#include "math.asm"
#include "random.asm"
#include "strings.asm"
#include "util.asm"

#ifdef DEBUG
#include "debug.asm"
#endif

.echo "Assigned kernel memory:"
.echo "threadTable: 0x{0:X4}" threadTable
.echo "libraryTable: 0x{0:X4}" libraryTable
Expand Down
110 changes: 7 additions & 103 deletions src/00/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ _: di

ld sp, kernelGarbage + kernelGarbageSize

#ifndef SKIPON
call suspendDevice
#endif
;; reboot [System]
;; Restarts the device.
reboot:
Expand All @@ -63,118 +61,24 @@ reboot:
out (PORT_BANKB), a
#endif

; Manipulate protection states
#ifdef CPU15 ; TI-83+ SE, TI-84+, TI-84+ SE, TI-84+ CSE
call unlockFlash
; Remove RAM Execution Protection
xor a
out (PORT_RAMEXEC_LOWLIMIT), a ; RAM Lower Limit ; out (25), 0
dec a
out (PORT_RAMEXEC_UPLIMIT), a ; RAM Upper Limit ; out (26), $FF

; Remove Flash Execution Protection
out (PORT_FLASHEXEC_LOWLIMIT), a ; Flash Lower Limit ; out (22), $FF
out (PORT_FLASHEXEC_UPLIMIT), a ; Flash Upper Limit ; out (23), $FF
call unprotectRAM
call unprotectFlash
call lockFlash

; Set CPU speed to 15 MHz
#ifdef CPU15
ld a, BIT_CPUSPEED_15MHZ
out (PORT_CPUSPEED), a

#else ; TI-73, TI-83+
#ifndef TI73 ; RAM does not have protection on the TI-73

; Remove RAM/Flash protection
call unlockFlash
xor a
out (PORT_RAM_PAGING), a
out (PORT_FLASHEXCLUSION), a

ld a, 0b000000001
out (PORT_RAM_PAGING), a
xor a
out (PORT_FLASHEXCLUSION), a

ld a, 0b000000010
out (PORT_RAM_PAGING), a
xor a
out (PORT_FLASHEXCLUSION), a

ld a, 0b000000111
out (PORT_RAM_PAGING), a
xor a
out (PORT_FLASHEXCLUSION), a
call lockFlash
#endif
#endif

; Set interrupt mode
ld a, INT_ON | INT_TIMER1 | INT_LINK
out (PORT_INT_MASK), a
; Set timer frequency (TODO)

; Clear RAM
ld hl, 0x8000
ld (hl), 0
ld de, 0x8001
ld bc, 0x7FFF
ldir

call formatMem

; Set all file handles to unused
ld hl, fileHandleTable
ld (hl), 0xFF
ld de, fileHandleTable + 1
ld bc, 8 * maxFileStreams
ldir

ld a, threadRangeMask ; When the first thread is allocated, this will wrap to 0
ld (lastThreadId), a

#ifdef COLOR
; Set GPIO config
ld a, 0xE0
out (PORT_GPIO_CONFIG), a
ld a, 1
ld (color_mode), a
#else
; Initialize LCD
ld a, 1 + LCD_CMD_AUTOINCDEC_SETX
call lcdDelay
out (PORT_LCD_CMD), a ; X-Increment Mode

ld a, 1 + LCD_CMD_SETOUTPUTMODE
call lcdDelay
out (PORT_LCD_CMD), a ; 8-bit mode

ld a, 1 + LCD_CMD_SETDISPLAY
call lcdDelay
out (PORT_LCD_CMD), a ; Enable screen

ld a, 7 + LCD_CMD_POWERSUPPLY_SETLEVEL ; versus +3? TIOS uses +7, and that's the only value that works (the datasheet says go with +3)
call lcdDelay
out (PORT_LCD_CMD), a ; Op-amp control (OPA1) set to max (with DB1 set for some reason)

ld a, 3 + LCD_CMD_POWERSUPPLY_SETENHANCEMENT ; B
call lcdDelay
out (PORT_LCD_CMD), a ; Op-amp control (OPA2) set to max

; Different amounts of contrast look better on different models
#ifdef USB
ld a, 0x2F + LCD_CMD_SETCONTRAST
#else
#ifdef TI73
ld a, 0x3B + LCD_CMD_SETCONTRAST
#else
ld a, 0x34 + LCD_CMD_SETCONTRAST
#endif
#endif

ld (currentContrast), a
call lcdDelay
out (PORT_LCD_CMD), a ; Contrast
#endif
call initRandom
call initFilesystem
call initMultitasking
call initDisplay

ld de, init
call fileExists
Expand Down
210 changes: 0 additions & 210 deletions src/00/debug.asm

This file was deleted.

Loading

0 comments on commit ec7c844

Please sign in to comment.